Fix PDF setting not applying bug
This commit is contained in:
+3
@@ -1,7 +1,10 @@
|
||||
package com.adityachandel.booklore.config.security;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.entity.EpubViewerPreferencesEntity;
|
||||
import com.adityachandel.booklore.repository.PdfViewerPreferencesRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
+2
@@ -92,6 +92,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
bookLoreUser.setEmail(userEntity.getEmail());
|
||||
bookLoreUser.setPermissions(permissions);
|
||||
|
||||
bookLoreUser.setBookPreferences(userEntity.getBookPreferences());
|
||||
|
||||
return bookLoreUser;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -19,6 +19,12 @@ public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
|
||||
@GetMapping("/me")
|
||||
public ResponseEntity<BookLoreUser> getMyself() {
|
||||
return ResponseEntity.ok(userService.getMyself());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.canViewUserProfile(#id)")
|
||||
public ResponseEntity<BookLoreUser> getUser(@PathVariable Long id) {
|
||||
|
||||
@@ -40,12 +40,6 @@ public class BookEntity {
|
||||
@JoinColumn(name = "library_path_id", nullable = false)
|
||||
private LibraryPathEntity libraryPath;
|
||||
|
||||
@OneToOne(mappedBy = "book", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private PdfViewerPreferencesEntity pdfViewerPrefs;
|
||||
|
||||
@OneToOne(mappedBy = "book", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private EpubViewerPreferencesEntity epubViewerPrefs;
|
||||
|
||||
@Column(name = "added_on")
|
||||
private Instant addedOn;
|
||||
|
||||
|
||||
+12
-9
@@ -1,6 +1,5 @@
|
||||
package com.adityachandel.booklore.model.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@@ -10,16 +9,20 @@ import lombok.*;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "epub_viewer_preference")
|
||||
@Table(name = "epub_viewer_preference", uniqueConstraints = {
|
||||
@UniqueConstraint(columnNames = {"user_id", "book_id"})
|
||||
})
|
||||
public class EpubViewerPreferencesEntity {
|
||||
@Id
|
||||
private Long bookId;
|
||||
|
||||
@OneToOne
|
||||
@MapsId
|
||||
@JoinColumn(name = "book_id")
|
||||
@JsonIgnore
|
||||
private BookEntity book;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "book_id", nullable = false)
|
||||
private Long bookId;
|
||||
|
||||
@Column(name = "theme")
|
||||
private String theme;
|
||||
|
||||
+12
-9
@@ -1,6 +1,5 @@
|
||||
package com.adityachandel.booklore.model.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@@ -10,16 +9,20 @@ import lombok.*;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "pdf_viewer_preference")
|
||||
@Table(name = "pdf_viewer_preference", uniqueConstraints = {
|
||||
@UniqueConstraint(columnNames = {"user_id", "book_id"})
|
||||
})
|
||||
public class PdfViewerPreferencesEntity {
|
||||
@Id
|
||||
private Long bookId;
|
||||
|
||||
@OneToOne
|
||||
@MapsId
|
||||
@JoinColumn(name = "book_id")
|
||||
@JsonIgnore
|
||||
private BookEntity book;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "book_id", nullable = false)
|
||||
private Long bookId;
|
||||
|
||||
@Column(name = "zoom")
|
||||
private String zoom;
|
||||
|
||||
+4
@@ -4,7 +4,11 @@ import com.adityachandel.booklore.model.entity.EpubViewerPreferencesEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface EpubViewerPreferencesRepository extends JpaRepository<EpubViewerPreferencesEntity, Long> {
|
||||
|
||||
Optional<EpubViewerPreferencesEntity> findByBookIdAndUserId(Long bookId, Long userId);
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -4,7 +4,10 @@ import com.adityachandel.booklore.model.entity.PdfViewerPreferencesEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PdfViewerPreferencesRepository extends JpaRepository<PdfViewerPreferencesEntity, Long> {
|
||||
|
||||
Optional<PdfViewerPreferencesEntity> findByBookIdAndUserId(long bookId, Long id);
|
||||
}
|
||||
|
||||
@@ -34,19 +34,6 @@ public class BookCreatorService {
|
||||
.addedOn(Instant.now())
|
||||
.build();
|
||||
BookMetadataEntity bookMetadataEntity = BookMetadataEntity.builder().build();
|
||||
if (bookFileType == BookFileType.PDF) {
|
||||
PdfViewerPreferencesEntity pdfViewerPreferencesEntity = PdfViewerPreferencesEntity.builder()
|
||||
.book(bookEntity)
|
||||
.bookId(bookEntity.getId())
|
||||
.build();
|
||||
bookEntity.setPdfViewerPrefs(pdfViewerPreferencesEntity);
|
||||
} else if (bookFileType == BookFileType.EPUB) {
|
||||
EpubViewerPreferencesEntity epubViewerPreferencesEntity = EpubViewerPreferencesEntity.builder()
|
||||
.book(bookEntity)
|
||||
.bookId(bookEntity.getId())
|
||||
.build();
|
||||
bookEntity.setEpubViewerPrefs(epubViewerPreferencesEntity);
|
||||
}
|
||||
bookEntity.setMetadata(bookMetadataEntity);
|
||||
bookEntity = bookRepository.saveAndFlush(bookEntity);
|
||||
|
||||
@@ -97,10 +84,5 @@ public class BookCreatorService {
|
||||
}
|
||||
bookRepository.save(bookEntity);
|
||||
bookMetadataRepository.save(bookEntity.getMetadata());
|
||||
if (bookEntity.getBookType() == BookFileType.EPUB) {
|
||||
epubViewerPreferencesRepository.save(bookEntity.getEpubViewerPrefs());
|
||||
} else if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
pdfViewerPreferencesRepository.save(bookEntity.getPdfViewerPrefs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.config.security.SecurityUtil;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.mapper.EpubViewerPreferencesMapper;
|
||||
import com.adityachandel.booklore.mapper.PdfViewerPreferencesMapper;
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.*;
|
||||
import com.adityachandel.booklore.model.dto.request.ReadProgressRequest;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
@@ -30,6 +32,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -47,36 +50,71 @@ public class BooksService {
|
||||
private final UserRepository userRepository;
|
||||
private final UserBookProgressRepository userBookProgressRepository;
|
||||
private final AuthenticationService authenticationService;
|
||||
private final PdfViewerPreferencesMapper pdfViewerPreferencesMapper;
|
||||
private final EpubViewerPreferencesMapper epubViewerPreferencesMapper;
|
||||
|
||||
public BookViewerSettings getBookViewerSetting(long bookId) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
return BookViewerSettings.builder().pdfSettings(pdfViewerPreferencesMapper.toModel(bookEntity.getPdfViewerPrefs())).build();
|
||||
} else if (bookEntity.getBookType() == BookFileType.EPUB) {
|
||||
return BookViewerSettings.builder().epubSettings(epubViewerPreferencesMapper.toModel(bookEntity.getEpubViewerPrefs())).build();
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
BookViewerSettings.BookViewerSettingsBuilder settingsBuilder = BookViewerSettings.builder();
|
||||
if (bookEntity.getBookType() == BookFileType.EPUB) {
|
||||
epubViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
||||
.ifPresent(epubPref -> settingsBuilder.epubSettings(EpubViewerPreferences.builder()
|
||||
.bookId(bookId)
|
||||
.font(epubPref.getFont())
|
||||
.fontSize(epubPref.getFontSize())
|
||||
.theme(epubPref.getTheme())
|
||||
.build()));
|
||||
} else if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
pdfViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
||||
.ifPresent(pdfPref -> settingsBuilder.pdfSettings(PdfViewerPreferences.builder()
|
||||
.bookId(bookId)
|
||||
.zoom(pdfPref.getZoom())
|
||||
.sidebarVisible(pdfPref.getSidebarVisible())
|
||||
.spread(pdfPref.getSpread())
|
||||
.build()));
|
||||
} else {
|
||||
throw ApiError.UNSUPPORTED_BOOK_TYPE.createException();
|
||||
}
|
||||
return settingsBuilder.build();
|
||||
}
|
||||
|
||||
public void updateBookViewerSetting(long bookId, BookViewerSettings bookViewerSettings) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
|
||||
if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
PdfViewerPreferencesEntity pdfPrefs = pdfViewerPreferencesRepository
|
||||
.findByBookIdAndUserId(bookId, user.getId())
|
||||
.orElseGet(() -> {
|
||||
PdfViewerPreferencesEntity newPrefs = PdfViewerPreferencesEntity.builder()
|
||||
.bookId(bookId)
|
||||
.userId(user.getId())
|
||||
.build();
|
||||
return pdfViewerPreferencesRepository.save(newPrefs);
|
||||
});
|
||||
|
||||
PdfViewerPreferences pdfSettings = bookViewerSettings.getPdfSettings();
|
||||
PdfViewerPreferencesEntity viewerPrefs = bookEntity.getPdfViewerPrefs();
|
||||
viewerPrefs.setZoom(pdfSettings.getZoom());
|
||||
viewerPrefs.setSpread(pdfSettings.getSpread());
|
||||
viewerPrefs.setSidebarVisible(pdfSettings.getSidebarVisible());
|
||||
pdfViewerPreferencesRepository.save(viewerPrefs);
|
||||
pdfPrefs.setZoom(pdfSettings.getZoom());
|
||||
pdfPrefs.setSpread(pdfSettings.getSpread());
|
||||
pdfPrefs.setSidebarVisible(pdfSettings.getSidebarVisible());
|
||||
pdfViewerPreferencesRepository.save(pdfPrefs);
|
||||
|
||||
} else if (bookEntity.getBookType() == BookFileType.EPUB) {
|
||||
EpubViewerPreferencesEntity epubPrefs = epubViewerPreferencesRepository
|
||||
.findByBookIdAndUserId(bookId, user.getId())
|
||||
.orElseGet(() -> {
|
||||
EpubViewerPreferencesEntity newPrefs = EpubViewerPreferencesEntity.builder()
|
||||
.bookId(bookId)
|
||||
.userId(user.getId())
|
||||
.build();
|
||||
return epubViewerPreferencesRepository.save(newPrefs);
|
||||
});
|
||||
|
||||
EpubViewerPreferences epubSettings = bookViewerSettings.getEpubSettings();
|
||||
EpubViewerPreferencesEntity viewerPrefs = bookEntity.getEpubViewerPrefs();
|
||||
viewerPrefs.setFont(epubSettings.getFont());
|
||||
viewerPrefs.setFontSize(epubSettings.getFontSize());
|
||||
viewerPrefs.setTheme(epubSettings.getTheme());
|
||||
epubViewerPreferencesRepository.save(viewerPrefs);
|
||||
epubPrefs.setFont(epubSettings.getFont());
|
||||
epubPrefs.setFontSize(epubSettings.getFontSize());
|
||||
epubPrefs.setTheme(epubSettings.getTheme());
|
||||
epubViewerPreferencesRepository.save(epubPrefs);
|
||||
|
||||
} else {
|
||||
throw ApiError.UNSUPPORTED_BOOK_TYPE.createException();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.adityachandel.booklore.service.user;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.config.security.JwtUtils;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookLoreUserMapper;
|
||||
@@ -31,6 +32,7 @@ public class UserService {
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final LibraryRepository libraryRepository;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
public ResponseEntity<Map<String, String>> loginUser(UserLoginRequest loginRequest) {
|
||||
BookLoreUserEntity user = userRepository.findByUsername(loginRequest.getUsername()).orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(loginRequest.getUsername()));
|
||||
@@ -98,4 +100,8 @@ public class UserService {
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
public BookLoreUser getMyself() {
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,20 +101,24 @@ CREATE TABLE IF NOT EXISTS category
|
||||
|
||||
CREATE TABLE IF NOT EXISTS pdf_viewer_preference
|
||||
(
|
||||
book_id BIGINT PRIMARY KEY,
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
book_id BIGINT NOT NULL,
|
||||
zoom VARCHAR(16) NULL,
|
||||
sidebar_visible BOOLEAN NULL,
|
||||
spread VARCHAR(16) NULL,
|
||||
CONSTRAINT fk_pdf_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
|
||||
UNIQUE (user_id, book_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS epub_viewer_preference
|
||||
(
|
||||
book_id BIGINT PRIMARY KEY,
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
book_id BIGINT NOT NULL,
|
||||
theme VARCHAR(128) NULL,
|
||||
font VARCHAR(128) NULL,
|
||||
font_size INT NULL,
|
||||
CONSTRAINT fk_epub_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
|
||||
UNIQUE (user_id, book_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book_metadata_category_mapping
|
||||
|
||||
@@ -11,6 +11,5 @@
|
||||
(pageChange)="onPageChange($event)"
|
||||
(zoomChange)="onZoomChange($event)"
|
||||
(sidebarVisibleChange)="onSidebarVisibleChange($event)"
|
||||
(pdfLoaded)="onPdfLoaded($event)"
|
||||
(spreadChange)="onSpreadChange($event)">
|
||||
</ngx-extended-pdf-viewer>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {filter, forkJoin, Subscription, take} from 'rxjs';
|
||||
import {BookSetting, PdfViewerSetting} from '../../model/book.model';
|
||||
import {PdfSettings} from '../../../core/model/app-settings.model';
|
||||
import {UserService} from '../../../user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-viewer',
|
||||
@@ -23,48 +24,46 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
spread!: 'off' | 'even' | 'odd';
|
||||
zoom!: number | string;
|
||||
|
||||
private pdfLoaded = false;
|
||||
bookData!: string | Blob;
|
||||
bookId!: number;
|
||||
private appSettingsSubscription!: Subscription;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private userService = inject(UserService);
|
||||
private route = inject(ActivatedRoute);
|
||||
|
||||
private individualPdfSettings: PdfViewerSetting | undefined;
|
||||
private globalPdfSettings: PdfSettings | undefined;
|
||||
private pdfScope: 'global' | 'individual' | undefined;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
this.bookId = +params.get('bookId')!;
|
||||
|
||||
this.appSettingsService.appSettings$
|
||||
.pipe(
|
||||
filter((appSettings) => appSettings !== null),
|
||||
take(1)
|
||||
)
|
||||
.subscribe((appSettings) => {
|
||||
const book$ = this.bookService.getBookByIdFromAPI(this.bookId, false);
|
||||
const pdf$ = this.bookService.getFileContent(this.bookId);
|
||||
const bookSetting$ = this.bookService.getBookSetting(this.bookId);
|
||||
const myself$ = this.userService.getMyself();
|
||||
const book$ = this.bookService.getBookByIdFromAPI(this.bookId, false);
|
||||
const bookSetting$ = this.bookService.getBookSetting(this.bookId);
|
||||
const pdfData$ = this.bookService.getFileContent(this.bookId);
|
||||
|
||||
forkJoin([book$, pdf$, bookSetting$]).subscribe((results) => {
|
||||
const pdf = results[0];
|
||||
const pdfData = results[1];
|
||||
this.individualPdfSettings = results[2]?.pdfSettings;
|
||||
this.globalPdfSettings = appSettings.pdf;
|
||||
this.pdfScope = appSettings?.readerSettings?.pdfScope;
|
||||
this.page = pdf.pdfProgress || 1;
|
||||
this.bookData = pdfData;
|
||||
});
|
||||
});
|
||||
forkJoin([book$, bookSetting$, pdfData$, myself$]).subscribe((results) => {
|
||||
const pdfMeta = results[0];
|
||||
const pdfPrefs = results[1];
|
||||
const pdfData = results[2];
|
||||
const myself = results[3];
|
||||
|
||||
let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf;
|
||||
if (globalOrIndividual === 'Global') {
|
||||
this.zoom = myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.sidebarVisible = myself.bookPreferences.pdfReaderSetting.showSidebar ?? true;
|
||||
this.spread = myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
|
||||
} else {
|
||||
this.zoom = pdfPrefs.pdfSettings?.zoom || myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.sidebarVisible = pdfPrefs.pdfSettings?.sidebarVisible ?? myself.bookPreferences.pdfReaderSetting.showSidebar ?? true;
|
||||
this.spread = pdfPrefs.pdfSettings?.spread || myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
|
||||
}
|
||||
this.page = pdfMeta.pdfProgress || 1;
|
||||
this.bookData = pdfData;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onPageChange(page: number): void {
|
||||
if (!this.pdfLoaded) return;
|
||||
if (page !== this.page) {
|
||||
this.page = page;
|
||||
}
|
||||
@@ -72,7 +71,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onZoomChange(zoom: string | number): void {
|
||||
if (!this.pdfLoaded) return;
|
||||
if (zoom !== this.zoom) {
|
||||
this.zoom = zoom;
|
||||
this.updateViewerSetting();
|
||||
@@ -80,7 +78,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onSidebarVisibleChange(visible: boolean): void {
|
||||
if (!this.pdfLoaded) return;
|
||||
if (visible !== this.sidebarVisible) {
|
||||
this.sidebarVisible = visible;
|
||||
this.updateViewerSetting();
|
||||
@@ -88,7 +85,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onSpreadChange(spread: 'off' | 'even' | 'odd'): void {
|
||||
if (!this.pdfLoaded) return;
|
||||
if (spread !== this.spread) {
|
||||
this.spread = spread;
|
||||
this.updateViewerSetting();
|
||||
@@ -96,7 +92,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private updateViewerSetting(): void {
|
||||
if (!this.pdfLoaded) return;
|
||||
const bookSetting: BookSetting = {
|
||||
pdfSettings: {
|
||||
sidebarVisible: this.sidebarVisible,
|
||||
@@ -117,18 +112,4 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
this.updateProgress();
|
||||
}
|
||||
|
||||
onPdfLoaded($event: PdfLoadedEvent) {
|
||||
this.pdfLoaded = true;
|
||||
this.updateProgress();
|
||||
if (this.pdfScope === 'global') {
|
||||
this.zoom = this.globalPdfSettings?.zoom || 'page-fit';
|
||||
this.sidebarVisible = this.globalPdfSettings?.sidebar ?? true;
|
||||
this.spread = this.globalPdfSettings?.spread || 'odd';
|
||||
} else {
|
||||
this.zoom = this.individualPdfSettings?.zoom || this.globalPdfSettings?.zoom || 'page-fit';
|
||||
this.sidebarVisible = this.individualPdfSettings?.sidebarVisible ?? this.globalPdfSettings?.sidebar ?? true;
|
||||
this.spread = this.individualPdfSettings?.spread || this.globalPdfSettings?.spread || 'odd';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ export class BookPreferences implements OnInit {
|
||||
|
||||
readonly individualOrGlobal = ['Global', 'Individual'];
|
||||
|
||||
selectedSpread!: string;
|
||||
selectedSpread!: 'off' | 'even' | 'odd';
|
||||
selectedZoom!: string;
|
||||
showSidebar = false;
|
||||
selectedTheme!: string;
|
||||
|
||||
@@ -15,8 +15,8 @@ export interface PdfSettings {
|
||||
}
|
||||
|
||||
export interface ReaderSettings {
|
||||
pdfScope: 'global' | 'individual';
|
||||
epubScope: 'global' | 'individual';
|
||||
pdfScope: 'Global' | 'Individual';
|
||||
epubScope: 'Global' | 'Individual';
|
||||
}
|
||||
|
||||
export interface AppSettings {
|
||||
|
||||
@@ -111,7 +111,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
this.rendition.themes.register(name, theme);
|
||||
});
|
||||
|
||||
if (epubScope === 'global') {
|
||||
if (epubScope === 'Global') {
|
||||
this.selectedTheme = globalSetting?.theme || FALLBACK_EPUB_SETTINGS.theme;
|
||||
this.selectedFontType = globalSetting?.font || FALLBACK_EPUB_SETTINGS.fontType;
|
||||
this.fontSize = globalSetting?.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {inject, Injectable, Injector} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {BehaviorSubject, Observable, of} from 'rxjs';
|
||||
import {API_CONFIG} from './config/api-config';
|
||||
import {jwtDecode} from 'jwt-decode';
|
||||
import {RxStompService} from './shared/websocket/rx-stomp.service';
|
||||
@@ -28,7 +28,7 @@ export interface UserBookPreferences {
|
||||
epub: string;
|
||||
};
|
||||
pdfReaderSetting: {
|
||||
pageSpread: string;
|
||||
pageSpread: 'off' | 'even' | 'odd';
|
||||
pageZoom: string;
|
||||
showSidebar: boolean;
|
||||
};
|
||||
@@ -78,6 +78,21 @@ export class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
getMyself(): Observable<User> {
|
||||
return this.http.get<User>(`${this.userUrl}/me`);
|
||||
}
|
||||
|
||||
getUserFromAPI(): Observable<User> {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
const decoded: JwtPayload & { userId?: string } = jwtDecode(token);
|
||||
if (decoded.userId) {
|
||||
return this.http.get<User>(`${this.userUrl}/${decoded.userId}`);
|
||||
}
|
||||
}
|
||||
return of(null as unknown as User);
|
||||
}
|
||||
|
||||
getLocalUser(): User | null {
|
||||
return this.userDataSubject.getValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user