Merge pull request #382 from adityachandelgit/develop
Merge Develop into Master for Release
This commit is contained in:
+4
@@ -72,6 +72,10 @@ public class BookLoreUserTransformer {
|
|||||||
var value = objectMapper.readValue(jsonValue, SidebarSortOption.class);
|
var value = objectMapper.readValue(jsonValue, SidebarSortOption.class);
|
||||||
userSettings.setSidebarShelfSorting(value);
|
userSettings.setSidebarShelfSorting(value);
|
||||||
}
|
}
|
||||||
|
case ENTITY_VIEW_PREFERENCES -> {
|
||||||
|
var value = objectMapper.readValue(jsonValue, BookLoreUser.UserSettings.EntityViewPreferences.class);
|
||||||
|
userSettings.setEntityViewPreferences(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -41,6 +41,46 @@ public class BookLoreUser {
|
|||||||
public CbxReaderSetting cbxReaderSetting;
|
public CbxReaderSetting cbxReaderSetting;
|
||||||
public SidebarSortOption sidebarLibrarySorting;
|
public SidebarSortOption sidebarLibrarySorting;
|
||||||
public SidebarSortOption sidebarShelfSorting;
|
public SidebarSortOption sidebarShelfSorting;
|
||||||
|
public EntityViewPreferences entityViewPreferences;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class EntityViewPreferences {
|
||||||
|
private GlobalPreferences global;
|
||||||
|
private List<OverridePreference> overrides;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class GlobalPreferences {
|
||||||
|
private String sortKey;
|
||||||
|
private String sortDir;
|
||||||
|
private String view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class OverridePreference {
|
||||||
|
private String entityType;
|
||||||
|
private Long entityId;
|
||||||
|
private OverrideDetails preferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class OverrideDetails {
|
||||||
|
private String sortKey;
|
||||||
|
private String sortDir;
|
||||||
|
private String view;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
|||||||
+2
-1
@@ -9,7 +9,8 @@ public enum UserSettingKey {
|
|||||||
EPUB_READER_SETTING("epubReaderSetting", true),
|
EPUB_READER_SETTING("epubReaderSetting", true),
|
||||||
CBX_READER_SETTING("cbxReaderSetting", true),
|
CBX_READER_SETTING("cbxReaderSetting", true),
|
||||||
SIDEBAR_LIBRARY_SORTING("sidebarLibrarySorting", true),
|
SIDEBAR_LIBRARY_SORTING("sidebarLibrarySorting", true),
|
||||||
SIDEBAR_SHELF_SORTING("sidebarShelfSorting", true);
|
SIDEBAR_SHELF_SORTING("sidebarShelfSorting", true),
|
||||||
|
ENTITY_VIEW_PREFERENCES("entityViewPreferences", true);
|
||||||
|
|
||||||
private final String dbKey;
|
private final String dbKey;
|
||||||
private final boolean isJson;
|
private final boolean isJson;
|
||||||
|
|||||||
-3
@@ -22,9 +22,6 @@ public class LibraryPathEntity {
|
|||||||
@JoinColumn(name = "library_id", nullable = false)
|
@JoinColumn(name = "library_id", nullable = false)
|
||||||
private LibraryEntity library;
|
private LibraryEntity library;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "libraryPath", fetch = FetchType.LAZY)
|
|
||||||
private List<BookEntity> books;
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String path;
|
private String path;
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-26
@@ -25,6 +25,7 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
@@ -36,6 +37,11 @@ public class FileUploadService {
|
|||||||
private static final String CBZ_MIME_TYPE = "application/x-cbz";
|
private static final String CBZ_MIME_TYPE = "application/x-cbz";
|
||||||
private static final String CBR_MIME_TYPE = "application/x-cbr";
|
private static final String CBR_MIME_TYPE = "application/x-cbr";
|
||||||
private static final String CB7_MIME_TYPE = "application/x-cb7";
|
private static final String CB7_MIME_TYPE = "application/x-cb7";
|
||||||
|
private static final Set<String> SUPPORTED_MIME_TYPES = Set.of(
|
||||||
|
PDF_MIME_TYPE, EPUB_MIME_TYPE,
|
||||||
|
CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE,
|
||||||
|
"application/octet-stream"
|
||||||
|
);
|
||||||
|
|
||||||
private final LibraryRepository libraryRepository;
|
private final LibraryRepository libraryRepository;
|
||||||
private final PdfProcessor pdfProcessor;
|
private final PdfProcessor pdfProcessor;
|
||||||
@@ -47,8 +53,7 @@ public class FileUploadService {
|
|||||||
private final EpubMetadataExtractor epubMetadataExtractor;
|
private final EpubMetadataExtractor epubMetadataExtractor;
|
||||||
|
|
||||||
public Book uploadFile(MultipartFile file, long libraryId, long pathId) throws IOException {
|
public Book uploadFile(MultipartFile file, long libraryId, long pathId) throws IOException {
|
||||||
Integer uploadSizeInMb = appSettingService.getAppSettings().getMaxFileUploadSizeInMb();
|
validateFile(file);
|
||||||
validateFile(file, uploadSizeInMb);
|
|
||||||
|
|
||||||
LibraryEntity libraryEntity = libraryRepository.findById(libraryId)
|
LibraryEntity libraryEntity = libraryRepository.findById(libraryId)
|
||||||
.orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
.orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||||
@@ -60,12 +65,10 @@ public class FileUploadService {
|
|||||||
.orElseThrow(() -> ApiError.INVALID_LIBRARY_PATH.createException(libraryId));
|
.orElseThrow(() -> ApiError.INVALID_LIBRARY_PATH.createException(libraryId));
|
||||||
|
|
||||||
Path tempPath = Files.createTempFile("upload-", Objects.requireNonNull(file.getOriginalFilename()));
|
Path tempPath = Files.createTempFile("upload-", Objects.requireNonNull(file.getOriginalFilename()));
|
||||||
UploadedFileMetadata metadata;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file.transferTo(tempPath);
|
file.transferTo(tempPath);
|
||||||
|
|
||||||
metadata = extractMetadata(file, tempPath);
|
UploadedFileMetadata metadata = extractMetadata(file.getContentType(), tempPath);
|
||||||
|
|
||||||
String title = Optional.ofNullable(metadata.getTitle()).orElse("").trim();
|
String title = Optional.ofNullable(metadata.getTitle()).orElse("").trim();
|
||||||
String authors = metadata.getAuthors() != null ? String.join(", ", metadata.getAuthors()) : "";
|
String authors = metadata.getAuthors() != null ? String.join(", ", metadata.getAuthors()) : "";
|
||||||
@@ -97,35 +100,26 @@ public class FileUploadService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UploadedFileMetadata extractMetadata(MultipartFile file, Path tempPath) throws IOException {
|
private UploadedFileMetadata extractMetadata(String contentType, Path tempPath) throws IOException {
|
||||||
String fileType = Objects.requireNonNull(file.getContentType());
|
if (contentType == null) {
|
||||||
return switch (fileType.toLowerCase()) {
|
throw ApiError.INVALID_FILE_FORMAT.createException("Content type is null.");
|
||||||
|
}
|
||||||
|
return switch (contentType.toLowerCase()) {
|
||||||
case PDF_MIME_TYPE -> pdfMetadataExtractor.extractMetadata(tempPath.toString());
|
case PDF_MIME_TYPE -> pdfMetadataExtractor.extractMetadata(tempPath.toString());
|
||||||
case EPUB_MIME_TYPE -> epubMetadataExtractor.extractMetadata(tempPath.toString());
|
case EPUB_MIME_TYPE -> epubMetadataExtractor.extractMetadata(tempPath.toString());
|
||||||
case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE -> new UploadedFileMetadata();
|
case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE, "application/octet-stream" -> new UploadedFileMetadata();
|
||||||
default -> throw ApiError.INVALID_FILE_FORMAT.createException("Unsupported file type.");
|
default -> throw ApiError.INVALID_FILE_FORMAT.createException("Unsupported file type.");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSupportedContentType(String fileType) {
|
private void validateFile(MultipartFile file) {
|
||||||
return PDF_MIME_TYPE.equals(fileType)
|
|
||||||
|| EPUB_MIME_TYPE.equals(fileType)
|
|
||||||
|| CBZ_MIME_TYPE.equals(fileType)
|
|
||||||
|| CBR_MIME_TYPE.equals(fileType)
|
|
||||||
|| CB7_MIME_TYPE.equals(fileType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isFileTooLarge(MultipartFile file, int uploadSizeInMb) {
|
|
||||||
return file.getSize() > uploadSizeInMb * 1024L * 1024L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateFile(MultipartFile file, int uploadSizeInMb) {
|
|
||||||
String fileType = file.getContentType();
|
String fileType = file.getContentType();
|
||||||
if (!isSupportedContentType(fileType)) {
|
if (!SUPPORTED_MIME_TYPES.contains(fileType)) {
|
||||||
throw ApiError.INVALID_FILE_FORMAT.createException();
|
throw ApiError.INVALID_FILE_FORMAT.createException();
|
||||||
}
|
}
|
||||||
if (isFileTooLarge(file, uploadSizeInMb)) {
|
int maxSizeMb = appSettingService.getAppSettings().getMaxFileUploadSizeInMb();
|
||||||
throw ApiError.FILE_TOO_LARGE.createException(uploadSizeInMb);
|
if (file.getSize() > maxSizeMb * 1024L * 1024L) {
|
||||||
|
throw ApiError.FILE_TOO_LARGE.createException(maxSizeMb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +174,7 @@ public class FileUploadService {
|
|||||||
return switch (fileType.toLowerCase()) {
|
return switch (fileType.toLowerCase()) {
|
||||||
case PDF_MIME_TYPE -> BookFileType.PDF;
|
case PDF_MIME_TYPE -> BookFileType.PDF;
|
||||||
case EPUB_MIME_TYPE -> BookFileType.EPUB;
|
case EPUB_MIME_TYPE -> BookFileType.EPUB;
|
||||||
case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE -> BookFileType.CBX;
|
case CBZ_MIME_TYPE, CBR_MIME_TYPE, CB7_MIME_TYPE, "application/octet-stream" -> BookFileType.CBX;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<p *ngIf="entityType === EntityType.UNSHELVED" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
<p *ngIf="entityType === EntityType.UNSHELVED" class="text-2xl whitespace-nowrap overflow-hidden text-ellipsis">
|
||||||
Unshelved Books
|
Unshelved Books
|
||||||
</p>
|
</p>
|
||||||
<div *ngIf="userService.userData$ | async as userData">
|
<div *ngIf="userService.userState$ | async as userData">
|
||||||
<div *ngIf="entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && (userData.permissions.admin || userData.permissions.canManipulateLibrary) ">
|
<div *ngIf="entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && (userData.permissions.admin || userData.permissions.canManipulateLibrary) ">
|
||||||
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
|
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"></p-button>
|
||||||
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
||||||
@@ -149,7 +149,7 @@
|
|||||||
pTooltip="Remove from shelf"
|
pTooltip="Remove from shelf"
|
||||||
tooltipPosition="top">
|
tooltipPosition="top">
|
||||||
</p-button>
|
</p-button>
|
||||||
<div *ngIf="userService.userData$ | async as userData">
|
<div *ngIf="userService.userState$ | async as userData">
|
||||||
<p-button
|
<p-button
|
||||||
*ngIf="userData.permissions.canEditMetadata"
|
*ngIf="userData.permissions.canEditMetadata"
|
||||||
icon="pi pi-database"
|
icon="pi pi-database"
|
||||||
|
|||||||
@@ -550,55 +550,70 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
|
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
|
||||||
const filterParam = paramMap.get(QUERY_PARAMS.FILTER);
|
const filterParam = paramMap.get(QUERY_PARAMS.FILTER);
|
||||||
|
|
||||||
this.currentViewMode = viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID ? viewParam : VIEW_MODES.GRID;
|
this.userService.getMyself().subscribe(user => {
|
||||||
|
const prefs = user.userSettings?.entityViewPreferences;
|
||||||
|
const globalPrefs = prefs?.global;
|
||||||
|
const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined;
|
||||||
|
|
||||||
const matchingSort = this.sortOptions.find(opt => opt.field === sortParam);
|
const override = prefs?.overrides?.find(o =>
|
||||||
const direction = directionParam === SORT_DIRECTION.DESCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING;
|
o.entityType?.toUpperCase() === currentEntityTypeStr &&
|
||||||
this.bookFilterComponent.showFilters = filterParam === 'true' || (filterParam === null && this.filterVisibility);
|
o.entityId === this.entity?.id
|
||||||
|
);
|
||||||
|
|
||||||
if (matchingSort) {
|
const effectivePrefs = override?.preferences ?? globalPrefs ?? {
|
||||||
this.selectedSort = {
|
sortKey: 'addedOn',
|
||||||
label: matchingSort.label,
|
sortDir: 'ASC',
|
||||||
field: matchingSort.field,
|
view: VIEW_MODES.GRID
|
||||||
direction
|
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
this.selectedSort = {
|
const userSortKey = effectivePrefs.sortKey;
|
||||||
|
const userSortDir = effectivePrefs.sortDir?.toUpperCase() === 'DESC' ? SortDirection.DESCENDING : SortDirection.ASCENDING;
|
||||||
|
|
||||||
|
const matchedSort = this.sortOptions.find(opt => opt.field === sortParam) || this.sortOptions.find(opt => opt.field === userSortKey);
|
||||||
|
|
||||||
|
this.selectedSort = matchedSort ? {
|
||||||
|
label: matchedSort.label,
|
||||||
|
field: matchedSort.field,
|
||||||
|
direction: directionParam ? (directionParam === SORT_DIRECTION.DESCENDING ? SortDirection.DESCENDING : SortDirection.ASCENDING) : userSortDir
|
||||||
|
} : {
|
||||||
label: 'Added On',
|
label: 'Added On',
|
||||||
field: 'addedOn',
|
field: 'addedOn',
|
||||||
direction: SortDirection.DESCENDING
|
direction: SortDirection.DESCENDING
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lastAppliedSort?.field !== this.selectedSort.field ||
|
this.currentViewMode = (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID) ? viewParam : effectivePrefs.view?.toLowerCase() ?? VIEW_MODES.GRID;
|
||||||
this.lastAppliedSort?.direction !== this.selectedSort.direction) {
|
this.bookFilterComponent.showFilters = filterParam === 'true' || (filterParam === null && this.filterVisibility);
|
||||||
this.lastAppliedSort = {...this.selectedSort};
|
this.updateSortOptions();
|
||||||
this.applySortOption(this.selectedSort);
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryParams: any = {
|
if (this.lastAppliedSort?.field !== this.selectedSort.field || this.lastAppliedSort?.direction !== this.selectedSort.direction) {
|
||||||
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
this.lastAppliedSort = {...this.selectedSort};
|
||||||
[QUERY_PARAMS.SORT]: this.selectedSort.field,
|
this.applySortOption(this.selectedSort);
|
||||||
[QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
}
|
||||||
[QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
|
|
||||||
};
|
|
||||||
|
|
||||||
const currentParams = this.activatedRoute.snapshot.queryParams;
|
const queryParams: any = {
|
||||||
|
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
||||||
|
[QUERY_PARAMS.SORT]: this.selectedSort.field,
|
||||||
|
[QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
||||||
|
[QUERY_PARAMS.FILTER]: this.bookFilterComponent.showFilters.toString()
|
||||||
|
};
|
||||||
|
|
||||||
if (
|
const currentParams = this.activatedRoute.snapshot.queryParams;
|
||||||
currentParams[QUERY_PARAMS.VIEW] !== queryParams[QUERY_PARAMS.VIEW] ||
|
|
||||||
currentParams[QUERY_PARAMS.SORT] !== queryParams[QUERY_PARAMS.SORT] ||
|
if (
|
||||||
currentParams[QUERY_PARAMS.DIRECTION] !== queryParams[QUERY_PARAMS.DIRECTION] ||
|
currentParams[QUERY_PARAMS.VIEW] !== queryParams[QUERY_PARAMS.VIEW] ||
|
||||||
currentParams[QUERY_PARAMS.FILTER] !== queryParams[QUERY_PARAMS.FILTER]
|
currentParams[QUERY_PARAMS.SORT] !== queryParams[QUERY_PARAMS.SORT] ||
|
||||||
) {
|
currentParams[QUERY_PARAMS.DIRECTION] !== queryParams[QUERY_PARAMS.DIRECTION] ||
|
||||||
this.router.navigate([], {
|
currentParams[QUERY_PARAMS.FILTER] !== queryParams[QUERY_PARAMS.FILTER]
|
||||||
queryParams,
|
) {
|
||||||
replaceUrl: true
|
this.router.navigate([], {
|
||||||
});
|
queryParams,
|
||||||
}
|
replaceUrl: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cdr.detectChanges();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.cdr.detectChanges();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lockUnlockMetadata() {
|
lockUnlockMetadata() {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class BookCardComponent implements OnInit {
|
|||||||
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.userService.userData$
|
this.userService.userState$
|
||||||
.pipe(filter(userData => !!userData))
|
.pipe(filter(userData => !!userData))
|
||||||
.subscribe((userData) => {
|
.subscribe((userData) => {
|
||||||
this.userPermissions = userData.permissions;
|
this.userPermissions = userData.permissions;
|
||||||
|
|||||||
@@ -98,17 +98,13 @@ export class BookFilterComponent implements OnInit {
|
|||||||
|
|
||||||
const index = this.activeFilters[filterType].indexOf(value);
|
const index = this.activeFilters[filterType].indexOf(value);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
// Deselect
|
|
||||||
this.activeFilters[filterType].splice(index, 1);
|
this.activeFilters[filterType].splice(index, 1);
|
||||||
if (this.activeFilters[filterType].length === 0) {
|
if (this.activeFilters[filterType].length === 0) {
|
||||||
delete this.activeFilters[filterType];
|
delete this.activeFilters[filterType];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Select
|
|
||||||
this.activeFilters[filterType].push(value);
|
this.activeFilters[filterType].push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit updated filter state
|
|
||||||
this.filterSelected.emit({ ...this.activeFilters });
|
this.filterSelected.emit({ ...this.activeFilters });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ export class BookMetadataCenterComponent implements OnInit, OnDestroy {
|
|||||||
this.fetchBookRecommendationsIfNeeded(book.metadata!.bookId);
|
this.fetchBookRecommendationsIfNeeded(book.metadata!.bookId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.userSubscription = this.userService.userData$.subscribe(userData => {
|
this.userSubscription = this.userService.userState$.subscribe(userData => {
|
||||||
const userPermissions = userData?.permissions;
|
const userPermissions = userData?.permissions;
|
||||||
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
|
this.canEditMetadata = userPermissions?.canEditMetadata ?? false;
|
||||||
this.admin = userPermissions?.admin ?? false;
|
this.admin = userPermissions?.admin ?? false;
|
||||||
|
|||||||
+6
-21
@@ -119,7 +119,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
|
||||||
|
|
||||||
<div class="flex flex-col gap-1 basis-2/6">
|
<div class="flex flex-col gap-1 basis-3/6">
|
||||||
<label for="seriesName">Series Name</label>
|
<label for="seriesName">Series Name</label>
|
||||||
<div class="flex justify-between items-center gap-2">
|
<div class="flex justify-between items-center gap-2">
|
||||||
<input pInputText id="seriesName" formControlName="seriesName" class="w-full"/>
|
<input pInputText id="seriesName" formControlName="seriesName" class="w-full"/>
|
||||||
@@ -154,15 +154,6 @@
|
|||||||
<p-button *ngIf="metadata['languageLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('language')" severity="warn"></p-button>
|
<p-button *ngIf="metadata['languageLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('language')" severity="warn"></p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-1 basis-1/6">
|
|
||||||
<label for="pageCount">Page Count</label>
|
|
||||||
<div class="flex justify-between items-center gap-2">
|
|
||||||
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
|
|
||||||
<p-button *ngIf="!metadata['pageCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="success"></p-button>
|
|
||||||
<p-button *ngIf="metadata['pageCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="warn"></p-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ISBN, Language, Review Count -->
|
<!-- ISBN, Language, Review Count -->
|
||||||
@@ -191,18 +182,12 @@
|
|||||||
<p-button *ngIf="metadata['asinLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('asin')" severity="warn"></p-button>
|
<p-button *ngIf="metadata['asinLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('asin')" severity="warn"></p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-1 w-1/4">
|
<div class="flex flex-col gap-1 basis-1/4">
|
||||||
<label for="reviewCount">Rating Count (Legacy)</label>
|
<label for="pageCount">Page Count</label>
|
||||||
<div class="flex justify-between items-center gap-2">
|
<div class="flex justify-between items-center gap-2">
|
||||||
<input [disabled]="true" pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
|
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
|
||||||
<p-button disabled icon="pi pi-lock" [outlined]="true" severity="warn"></p-button>
|
<p-button *ngIf="!metadata['pageCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="success"></p-button>
|
||||||
</div>
|
<p-button *ngIf="metadata['pageCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('pageCount')" severity="warn"></p-button>
|
||||||
</div>
|
|
||||||
<div class="flex flex-col gap-1 w-1/4">
|
|
||||||
<label for="rating">Rating (Legacy)</label>
|
|
||||||
<div class="flex justify-between items-center gap-2">
|
|
||||||
<input [disabled]="true" pInputText id="rating" formControlName="rating" class="w-full"/>
|
|
||||||
<p-button disabled icon="pi pi-lock" [outlined]="true" severity="warn"></p-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+1
-1
@@ -247,7 +247,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
publishedDateLocked: this.metadataForm.get('publishedDateLocked')?.value,
|
publishedDateLocked: this.metadataForm.get('publishedDateLocked')?.value,
|
||||||
isbn10Locked: this.metadataForm.get('isbn10Locked')?.value,
|
isbn10Locked: this.metadataForm.get('isbn10Locked')?.value,
|
||||||
isbn13Locked: this.metadataForm.get('isbn13Locked')?.value,
|
isbn13Locked: this.metadataForm.get('isbn13Locked')?.value,
|
||||||
asinLocked: this.metadataForm.get('asin')?.value,
|
asinLocked: this.metadataForm.get('asinLocked')?.value,
|
||||||
descriptionLocked: this.metadataForm.get('descriptionLocked')?.value,
|
descriptionLocked: this.metadataForm.get('descriptionLocked')?.value,
|
||||||
pageCountLocked: this.metadataForm.get('pageCountLocked')?.value,
|
pageCountLocked: this.metadataForm.get('pageCountLocked')?.value,
|
||||||
languageLocked: this.metadataForm.get('languageLocked')?.value,
|
languageLocked: this.metadataForm.get('languageLocked')?.value,
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="userService.userData$ | async as userData" class="pl-6 pt-4 flex flex-row w-full gap-4">
|
<div *ngIf="userService.userState$ | async as userData" class="pl-6 pt-4 flex flex-row w-full gap-4">
|
||||||
<p-button label="Read" icon="pi pi-book" severity="info" (onClick)="read(metadata.bookId)"></p-button>
|
<p-button label="Read" icon="pi pi-book" severity="info" (onClick)="read(metadata.bookId)"></p-button>
|
||||||
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
|
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
|
||||||
<p-button *ngIf="userData.permissions.canDownload || userData.permissions.admin" label="Download" icon="pi pi-download" severity="info" outlined
|
<p-button *ngIf="userData.permissions.canDownload || userData.permissions.admin" label="Download" icon="pi pi-download" severity="info" outlined
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ import {HttpClient} from '@angular/common/http';
|
|||||||
import {catchError, map} from 'rxjs/operators';
|
import {catchError, map} from 'rxjs/operators';
|
||||||
import {Library} from '../model/library.model';
|
import {Library} from '../model/library.model';
|
||||||
import {BookService} from './book.service';
|
import {BookService} from './book.service';
|
||||||
import {SortOption} from '../model/sort.model';
|
|
||||||
import {LibraryState} from '../model/state/library-state.model';
|
import {LibraryState} from '../model/state/library-state.model';
|
||||||
import {API_CONFIG} from '../../config/api-config';
|
import {API_CONFIG} from '../../config/api-config';
|
||||||
import {FetchMetadataRequest} from '../metadata/model/request/fetch-metadata-request.model';
|
|
||||||
import {BookMetadata} from '../model/book.model';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
|
|||||||
+5
-8
@@ -74,14 +74,11 @@ export class AuthenticationSettingsComponent implements OnInit {
|
|||||||
take(1)
|
take(1)
|
||||||
).subscribe(settings => this.loadSettings(settings));
|
).subscribe(settings => this.loadSettings(settings));
|
||||||
|
|
||||||
this.libraryService.getAllLibrariesFromAPI().subscribe({
|
this.libraryService.libraryState$
|
||||||
next: (libraries) => {
|
.pipe(
|
||||||
this.allLibraries = libraries;
|
filter(state => !!state?.loaded),
|
||||||
},
|
take(1)
|
||||||
error: () => {
|
).subscribe(state => this.allLibraries = state.libraries ?? []);
|
||||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load libraries'});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadSettings(settings: AppSettings): void {
|
loadSettings(settings: AppSettings): void {
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
<div class="dashboard" *ngIf="(bookState$ | async)?.loaded === true">
|
<div class="dashboard" *ngIf="(bookState$ | async)?.loaded === true">
|
||||||
<div>
|
<div>
|
||||||
<div class="dashboard-no-library" *ngIf="isLibrariesEmpty$ | async; else dashboardScroller">
|
<div class="dashboard-no-library" *ngIf="isLibrariesEmpty$ | async; else dashboardScroller">
|
||||||
<div *ngIf="(userService.userData$ | async)?.permissions as permissions">
|
<div *ngIf="(userService.userState$ | async)?.permissions as permissions">
|
||||||
<div *ngIf="permissions.admin || permissions.canManipulateLibrary">
|
<div *ngIf="permissions.admin || permissions.canManipulateLibrary">
|
||||||
<h1 class="no-library-header">Looks like you haven't added a library yet. Let's add one!</h1>
|
<h1 class="no-library-header">Looks like you haven't added a library yet. Let's add one!</h1>
|
||||||
<p-button
|
<p-button
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class AppMenuComponent implements OnInit {
|
|||||||
this.versionInfo = data;
|
this.versionInfo = data;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.userService.userData$.pipe(
|
this.userService.userState$.pipe(
|
||||||
filter(settings => !!settings))
|
filter(settings => !!settings))
|
||||||
.subscribe(user => {
|
.subscribe(user => {
|
||||||
if (user?.userSettings.sidebarLibrarySorting) {
|
if (user?.userSettings.sidebarLibrarySorting) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
|||||||
menuResetSubscription: Subscription;
|
menuResetSubscription: Subscription;
|
||||||
|
|
||||||
constructor(public router: Router, private menuService: MenuService, private userService: UserService) {
|
constructor(public router: Router, private menuService: MenuService, private userService: UserService) {
|
||||||
this.userService.userData$.subscribe(userData => {
|
this.userService.userState$.subscribe(userData => {
|
||||||
if (userData) {
|
if (userData) {
|
||||||
this.canManipulateLibrary = userData.permissions.canManipulateLibrary;
|
this.canManipulateLibrary = userData.permissions.canManipulateLibrary;
|
||||||
this.admin = userData.permissions.admin;
|
this.admin = userData.permissions.admin;
|
||||||
|
|||||||
@@ -21,13 +21,13 @@
|
|||||||
<app-book-searcher></app-book-searcher>
|
<app-book-searcher></app-book-searcher>
|
||||||
<ul class="topbar-items pl-6">
|
<ul class="topbar-items pl-6">
|
||||||
<div class="flex gap-6">
|
<div class="flex gap-6">
|
||||||
<li *ngIf="userService.userData$ | async as userData">
|
<li *ngIf="userService.userState$ | async as userData">
|
||||||
<a class="topbar-item" *ngIf="userData.permissions.canManipulateLibrary || userData.permissions.admin">
|
<a class="topbar-item" *ngIf="userData.permissions.canManipulateLibrary || userData.permissions.admin">
|
||||||
<i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()"
|
<i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()"
|
||||||
pTooltip="Create New Library" tooltipPosition="top"></i>
|
pTooltip="Create New Library" tooltipPosition="top"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li *ngIf="userService.userData$ | async as userData">
|
<li *ngIf="userService.userState$ | async as userData">
|
||||||
<a class="topbar-item" *ngIf="userData.permissions.canManipulateLibrary || userData.permissions.admin">
|
<a class="topbar-item" *ngIf="userData.permissions.canManipulateLibrary || userData.permissions.admin">
|
||||||
<i class="pi pi-upload text-surface-700 dark:text-surface-100" (click)="openFileUploadDialog()"
|
<i class="pi pi-upload text-surface-700 dark:text-surface-100" (click)="openFileUploadDialog()"
|
||||||
pTooltip="Upload Book" tooltipPosition="top"></i>
|
pTooltip="Upload Book" tooltipPosition="top"></i>
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ export class UserProfileDialogComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.userSubscription = this.userService.userData$.subscribe(user => {
|
this.userSubscription = this.userService.userState$.subscribe(user => {
|
||||||
this.currentUser = user;
|
this.currentUser = user;
|
||||||
this.resetEditForm();
|
this.resetEditForm();
|
||||||
});
|
});
|
||||||
|
|||||||
-48
@@ -201,52 +201,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p-divider></p-divider>
|
|
||||||
|
|
||||||
<div class="p-4">
|
|
||||||
<div class="flex items-center gap-2 pb-4 pt-4">
|
|
||||||
<p class="text-lg ">Sidebar Library and Shelf Sorting Perference</p>
|
|
||||||
<i class="pi pi-info-circle text-sky-600"
|
|
||||||
pTooltip="Configure sorting options for your library and shelves shown in the sidebar."
|
|
||||||
tooltipPosition="right"
|
|
||||||
style="cursor: pointer;">
|
|
||||||
</i>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
|
||||||
<p class="py-1">Library:
|
|
||||||
<i class="pi pi-info-circle text-sky-600"
|
|
||||||
pTooltip="Choose how books are sorted and displayed in the library sidebar."
|
|
||||||
tooltipPosition="right"
|
|
||||||
style="cursor: pointer;">
|
|
||||||
</i>
|
|
||||||
</p>
|
|
||||||
<div class="flex gap-4 justify-start">
|
|
||||||
<p-select
|
|
||||||
size="small"
|
|
||||||
[options]="sortingOptions"
|
|
||||||
[(ngModel)]="selectedLibrarySorting"
|
|
||||||
(ngModelChange)="onLibrarySortingChange()"
|
|
||||||
placeholder="Select Sorting">
|
|
||||||
</p-select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="py-1">Shelf:
|
|
||||||
<i class="pi pi-info-circle text-sky-600"
|
|
||||||
pTooltip="Choose how books are sorted and displayed in the shelf sidebar."
|
|
||||||
tooltipPosition="right"
|
|
||||||
style="cursor: pointer;">
|
|
||||||
</i>
|
|
||||||
</p>
|
|
||||||
<div class="flex gap-4 justify-start">
|
|
||||||
<p-select
|
|
||||||
size="small"
|
|
||||||
[options]="sortingOptions"
|
|
||||||
[(ngModel)]="selectedShelfSorting"
|
|
||||||
(ngModelChange)="onShelfSortingChange()"
|
|
||||||
placeholder="Select Sorting">
|
|
||||||
</p-select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
+6
-29
@@ -7,19 +7,18 @@ import {RadioButton} from 'primeng/radiobutton';
|
|||||||
import {Divider} from 'primeng/divider';
|
import {Divider} from 'primeng/divider';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {Tooltip} from 'primeng/tooltip';
|
import {Tooltip} from 'primeng/tooltip';
|
||||||
import {SidebarLibrarySorting, SidebarShelfSorting, User, UserService, UserSettings} from '../user-management/user.service';
|
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
|
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-preferences',
|
selector: 'app-reader-preferences',
|
||||||
templateUrl: './user-preferences.component.html',
|
templateUrl: './reader-preferences.component.html',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
styleUrls: ['./user-preferences.component.scss'],
|
styleUrls: ['./reader-preferences.component.scss'],
|
||||||
imports: [Select, FormsModule, NgForOf, RadioButton, Divider, Button, Tooltip]
|
imports: [Select, FormsModule, NgForOf, RadioButton, Divider, Button, Tooltip]
|
||||||
})
|
})
|
||||||
export class UserPreferences implements OnInit, OnDestroy {
|
export class ReaderPreferences implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
|
||||||
readonly cbxSpreads = [
|
readonly cbxSpreads = [
|
||||||
{name: 'Even', key: 'EVEN'},
|
{name: 'Even', key: 'EVEN'},
|
||||||
@@ -65,16 +64,8 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
{name: 'Scrolled', key: 'scrolled'}
|
{name: 'Scrolled', key: 'scrolled'}
|
||||||
];
|
];
|
||||||
|
|
||||||
readonly sortingOptions = [
|
|
||||||
{label: 'Name | Ascending', value: {field: 'name', order: 'asc'}},
|
|
||||||
{label: 'Name | Descending', value: {field: 'name', order: 'desc'}},
|
|
||||||
{label: 'Creation Date | Ascending', value: {field: 'id', order: 'asc'}},
|
|
||||||
{label: 'Creation Date | Descending', value: {field: 'id', order: 'desc'}},
|
|
||||||
];
|
|
||||||
|
|
||||||
readonly scopeOptions = ['Global', 'Individual'];
|
readonly scopeOptions = ['Global', 'Individual'];
|
||||||
|
|
||||||
|
|
||||||
selectedCbxSpread!: CbxPageSpread;
|
selectedCbxSpread!: CbxPageSpread;
|
||||||
selectedCbxViewMode!: CbxPageViewMode;
|
selectedCbxViewMode!: CbxPageViewMode;
|
||||||
|
|
||||||
@@ -90,13 +81,10 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
selectedEpubScope!: string;
|
selectedEpubScope!: string;
|
||||||
selectedCbxScope!: string;
|
selectedCbxScope!: string;
|
||||||
|
|
||||||
selectedLibrarySorting: SidebarLibrarySorting = {field: 'id', order: 'asc'};
|
|
||||||
selectedShelfSorting: SidebarShelfSorting = {field: 'id', order: 'asc'};
|
|
||||||
|
|
||||||
private readonly userService = inject(UserService);
|
private readonly userService = inject(UserService);
|
||||||
private readonly messageService = inject(MessageService);
|
private readonly messageService = inject(MessageService);
|
||||||
|
|
||||||
userData$: Observable<User | null> = this.userService.userData$;
|
userData$: Observable<User | null> = this.userService.userState$;
|
||||||
private subscription?: Subscription;
|
private subscription?: Subscription;
|
||||||
private currentUser: User | null = null;
|
private currentUser: User | null = null;
|
||||||
|
|
||||||
@@ -129,9 +117,6 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.selectedCbxSpread = settings.cbxReaderSetting.pageSpread;
|
this.selectedCbxSpread = settings.cbxReaderSetting.pageSpread;
|
||||||
this.selectedCbxViewMode = settings.cbxReaderSetting.pageViewMode;
|
this.selectedCbxViewMode = settings.cbxReaderSetting.pageViewMode;
|
||||||
|
|
||||||
this.selectedLibrarySorting = settings.sidebarLibrarySorting;
|
|
||||||
this.selectedShelfSorting = settings.sidebarShelfSorting;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updatePreference(path: string[], value: any): void {
|
private updatePreference(path: string[], value: any): void {
|
||||||
@@ -197,14 +182,6 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
this.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
this.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
onLibrarySortingChange() {
|
|
||||||
this.updatePreference(['sidebarLibrarySorting'], this.selectedLibrarySorting);
|
|
||||||
}
|
|
||||||
|
|
||||||
onShelfSortingChange() {
|
|
||||||
this.updatePreference(['sidebarShelfSorting'], this.selectedShelfSorting);
|
|
||||||
}
|
|
||||||
|
|
||||||
increaseFontSize() {
|
increaseFontSize() {
|
||||||
if (this.fontSize < 250) {
|
if (this.fontSize < 250) {
|
||||||
this.fontSize += 10;
|
this.fontSize += 10;
|
||||||
@@ -1,19 +1,23 @@
|
|||||||
<div *ngIf="userService.userData$ | async as userData">
|
<div *ngIf="userService.userState$ | async as userData">
|
||||||
<div class="rounded-xl overflow-hidden">
|
<div class="rounded-xl overflow-hidden">
|
||||||
<p-tabs [(value)]="activeTab" scrollable>
|
<p-tabs [(value)]="activeTab" scrollable>
|
||||||
<p-tablist>
|
<p-tablist>
|
||||||
<p-tab [value]="SettingsTab.BookReader">User Preferences</p-tab>
|
<p-tab [value]="SettingsTab.ReaderSettings">Reader Preferences</p-tab>
|
||||||
|
<p-tab [value]="SettingsTab.ViewPreferences">View Preferences</p-tab>
|
||||||
<ng-container *ngIf="userData.permissions.admin">
|
<ng-container *ngIf="userData.permissions.admin">
|
||||||
<p-tab [value]="SettingsTab.GlobalSettings">Global Settings</p-tab>
|
<p-tab [value]="SettingsTab.GlobalSettings">Global Settings</p-tab>
|
||||||
<p-tab [value]="SettingsTab.UserManagement">User Management</p-tab>
|
<p-tab [value]="SettingsTab.UserManagement">User Management</p-tab>
|
||||||
<p-tab [value]="SettingsTab.Email">Email Setting</p-tab>
|
<p-tab [value]="SettingsTab.EmailSettings">Email Setting</p-tab>
|
||||||
<p-tab [value]="SettingsTab.AuthenticationSettings">Authentication Settings</p-tab>
|
<p-tab [value]="SettingsTab.AuthenticationSettings">Authentication Settings</p-tab>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</p-tablist>
|
</p-tablist>
|
||||||
|
|
||||||
<p-tabpanels>
|
<p-tabpanels>
|
||||||
<p-tabpanel [value]="SettingsTab.BookReader">
|
<p-tabpanel [value]="SettingsTab.ReaderSettings">
|
||||||
<app-user-preferences></app-user-preferences>
|
<app-reader-preferences></app-reader-preferences>
|
||||||
|
</p-tabpanel>
|
||||||
|
<p-tabpanel [value]="SettingsTab.ViewPreferences">
|
||||||
|
<app-view-preferences-parent></app-view-preferences-parent>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
<ng-container *ngIf="userData.permissions.admin">
|
<ng-container *ngIf="userData.permissions.admin">
|
||||||
<p-tabpanel [value]="SettingsTab.GlobalSettings">
|
<p-tabpanel [value]="SettingsTab.GlobalSettings">
|
||||||
@@ -22,7 +26,7 @@
|
|||||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||||
<app-user-management></app-user-management>
|
<app-user-management></app-user-management>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
<p-tabpanel [value]="SettingsTab.Email">
|
<p-tabpanel [value]="SettingsTab.EmailSettings">
|
||||||
<app-email></app-email>
|
<app-email></app-email>
|
||||||
</p-tabpanel>
|
</p-tabpanel>
|
||||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ import {ActivatedRoute, Router} from '@angular/router';
|
|||||||
import {Subscription} from 'rxjs';
|
import {Subscription} from 'rxjs';
|
||||||
import {UserManagementComponent} from './user-management/user-management.component';
|
import {UserManagementComponent} from './user-management/user-management.component';
|
||||||
import {AuthenticationSettingsComponent} from '../core/security/oauth2-management/authentication-settings.component';
|
import {AuthenticationSettingsComponent} from '../core/security/oauth2-management/authentication-settings.component';
|
||||||
import {UserPreferences} from './user-preferences/user-preferences.component';
|
import {ViewPreferencesParentComponent} from './view-preferences-parent/view-preferences-parent.component';
|
||||||
|
import {ReaderPreferences} from './reader-preferences/reader-preferences.component';
|
||||||
|
|
||||||
export enum SettingsTab {
|
export enum SettingsTab {
|
||||||
BookReader = 'book-reader',
|
ReaderSettings = 'reader-settings',
|
||||||
|
ViewPreferences = 'view-settings',
|
||||||
UserManagement = 'user-management',
|
UserManagement = 'user-management',
|
||||||
Email = 'email',
|
EmailSettings = 'email-settings',
|
||||||
GlobalSettings = 'global-settings',
|
GlobalSettings = 'global-settings',
|
||||||
AuthenticationSettings = 'auth-settings'
|
AuthenticationSettings = 'auth-settings'
|
||||||
}
|
}
|
||||||
@@ -26,13 +28,14 @@ export enum SettingsTab {
|
|||||||
Tab,
|
Tab,
|
||||||
TabPanels,
|
TabPanels,
|
||||||
TabPanel,
|
TabPanel,
|
||||||
UserPreferences,
|
|
||||||
NgIf,
|
NgIf,
|
||||||
AsyncPipe,
|
AsyncPipe,
|
||||||
EmailComponent,
|
EmailComponent,
|
||||||
GlobalPreferencesComponent,
|
GlobalPreferencesComponent,
|
||||||
UserManagementComponent,
|
UserManagementComponent,
|
||||||
AuthenticationSettingsComponent
|
AuthenticationSettingsComponent,
|
||||||
|
ViewPreferencesParentComponent,
|
||||||
|
ReaderPreferences
|
||||||
],
|
],
|
||||||
templateUrl: './settings.component.html',
|
templateUrl: './settings.component.html',
|
||||||
styleUrl: './settings.component.scss'
|
styleUrl: './settings.component.scss'
|
||||||
@@ -48,7 +51,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
|||||||
SettingsTab = SettingsTab;
|
SettingsTab = SettingsTab;
|
||||||
|
|
||||||
private validTabs = Object.values(SettingsTab);
|
private validTabs = Object.values(SettingsTab);
|
||||||
private _activeTab: SettingsTab = SettingsTab.BookReader;
|
private _activeTab: SettingsTab = SettingsTab.ReaderSettings;
|
||||||
|
|
||||||
get activeTab(): SettingsTab {
|
get activeTab(): SettingsTab {
|
||||||
return this._activeTab;
|
return this._activeTab;
|
||||||
@@ -69,7 +72,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
|
|||||||
if (this.validTabs.includes(tabParam)) {
|
if (this.validTabs.includes(tabParam)) {
|
||||||
this._activeTab = tabParam as SettingsTab;
|
this._activeTab = tabParam as SettingsTab;
|
||||||
} else {
|
} else {
|
||||||
this._activeTab = SettingsTab.BookReader;
|
this._activeTab = SettingsTab.ReaderSettings;
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
relativeTo: this.route,
|
relativeTo: this.route,
|
||||||
queryParams: { tab: this._activeTab },
|
queryParams: { tab: this._activeTab },
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {Library} from '../../book/model/library.model';
|
|||||||
import {LibraryService} from '../../book/service/library.service';
|
import {LibraryService} from '../../book/service/library.service';
|
||||||
import {Dialog} from 'primeng/dialog';
|
import {Dialog} from 'primeng/dialog';
|
||||||
import {Password} from 'primeng/password';
|
import {Password} from 'primeng/password';
|
||||||
|
import {filter, take} from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-management',
|
selector: 'app-user-management',
|
||||||
@@ -52,35 +53,16 @@ export class UserManagementComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.loadUsers();
|
this.loadUsers();
|
||||||
this.loadMyself();
|
|
||||||
this.libraryService.getAllLibrariesFromAPI().subscribe({
|
this.userService.userState$
|
||||||
next: (libraries) => {
|
.pipe(filter(user => !!user), take(1))
|
||||||
this.allLibraries = libraries;
|
.subscribe(user => this.currentUser = user);
|
||||||
},
|
|
||||||
error: () => {
|
this.libraryService.libraryState$
|
||||||
this.messageService.add({
|
.pipe(filter(state => !!state?.loaded), take(1))
|
||||||
severity: 'error',
|
.subscribe(libraries => this.allLibraries = libraries.libraries ?? []);
|
||||||
summary: 'Error',
|
|
||||||
detail: 'Failed to load libraries',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMyself() {
|
|
||||||
this.userService.getMyself().subscribe({
|
|
||||||
next: (user) => {
|
|
||||||
this.currentUser = user;
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.messageService.add({
|
|
||||||
severity: 'error',
|
|
||||||
summary: 'Error',
|
|
||||||
detail: 'Failed to fetch current user',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
loadUsers() {
|
loadUsers() {
|
||||||
this.userService.getUsers().subscribe({
|
this.userService.getUsers().subscribe({
|
||||||
|
|||||||
@@ -1,12 +1,29 @@
|
|||||||
import {inject, Injectable, Injector} from '@angular/core';
|
import {inject, Injectable, Injector} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {BehaviorSubject, Observable, tap, throwError} from 'rxjs';
|
import {BehaviorSubject, Observable, throwError} from 'rxjs';
|
||||||
import {API_CONFIG} from '../../config/api-config';
|
import {API_CONFIG} from '../../config/api-config';
|
||||||
import {RxStompService} from '../../shared/websocket/rx-stomp.service';
|
import {RxStompService} from '../../shared/websocket/rx-stomp.service';
|
||||||
import {Library} from '../../book/model/library.model';
|
import {Library} from '../../book/model/library.model';
|
||||||
import {catchError} from 'rxjs/operators';
|
import {catchError} from 'rxjs/operators';
|
||||||
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
|
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
|
||||||
|
|
||||||
|
export interface EntityViewPreferences {
|
||||||
|
global: EntityViewPreference;
|
||||||
|
overrides: EntityViewPreferenceOverride[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityViewPreference {
|
||||||
|
sortKey: string;
|
||||||
|
sortDir: 'ASC' | 'DESC';
|
||||||
|
view: 'GRID' | 'TABLE';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityViewPreferenceOverride {
|
||||||
|
entityType: 'LIBRARY' | 'SHELF';
|
||||||
|
entityId: number;
|
||||||
|
preferences: EntityViewPreference;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SidebarLibrarySorting {
|
export interface SidebarLibrarySorting {
|
||||||
field: string;
|
field: string;
|
||||||
order: string;
|
order: string;
|
||||||
@@ -49,7 +66,8 @@ export interface UserSettings {
|
|||||||
epubReaderSetting: EpubReaderSetting;
|
epubReaderSetting: EpubReaderSetting;
|
||||||
cbxReaderSetting: CbxReaderSetting;
|
cbxReaderSetting: CbxReaderSetting;
|
||||||
sidebarLibrarySorting: SidebarLibrarySorting;
|
sidebarLibrarySorting: SidebarLibrarySorting;
|
||||||
sidebarShelfSorting: SidebarShelfSorting
|
sidebarShelfSorting: SidebarShelfSorting;
|
||||||
|
entityViewPreferences: EntityViewPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
@@ -82,12 +100,12 @@ export class UserService {
|
|||||||
|
|
||||||
private rxStompService?: RxStompService;
|
private rxStompService?: RxStompService;
|
||||||
|
|
||||||
private userDataSubject = new BehaviorSubject<User | null>(null);
|
private userStateSubject = new BehaviorSubject<User | null>(null);
|
||||||
userData$ = this.userDataSubject.asObservable();
|
userState$ = this.userStateSubject.asObservable();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.getMyself().subscribe(user => {
|
this.getMyself().subscribe(user => {
|
||||||
this.userDataSubject.next(user);
|
this.userStateSubject.next(user);
|
||||||
this.startWebSocket();
|
this.startWebSocket();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -147,11 +165,11 @@ export class UserService {
|
|||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
responseType: 'text' as 'json'
|
responseType: 'text' as 'json'
|
||||||
}).subscribe(() => {
|
}).subscribe(() => {
|
||||||
const currentUser = this.userDataSubject.getValue();
|
const currentUser = this.userStateSubject.getValue();
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
const updatedSettings = {...currentUser.userSettings, [key]: value};
|
const updatedSettings = {...currentUser.userSettings, [key]: value};
|
||||||
const updatedUser = {...currentUser, settings: updatedSettings};
|
const updatedUser = {...currentUser, settings: updatedSettings};
|
||||||
this.userDataSubject.next(updatedUser);
|
this.userStateSubject.next(updatedUser);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
<div class="p-4">
|
||||||
|
<div class="flex items-center gap-2 pb-6 pt-4">
|
||||||
|
<p class="text-lg ">Sidebar Library and Shelf Sorting Perference</p>
|
||||||
|
<i class="pi pi-info-circle text-sky-600"
|
||||||
|
pTooltip="Configure sorting options for your library and shelves shown in the sidebar."
|
||||||
|
tooltipPosition="right"
|
||||||
|
style="cursor: pointer;">
|
||||||
|
</i>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||||
|
<p class="py-1">Library:
|
||||||
|
<i class="pi pi-info-circle text-sky-600"
|
||||||
|
pTooltip="Choose how books are sorted and displayed in the library sidebar."
|
||||||
|
tooltipPosition="right"
|
||||||
|
style="cursor: pointer;">
|
||||||
|
</i>
|
||||||
|
</p>
|
||||||
|
<div class="flex gap-4 justify-start">
|
||||||
|
<p-select
|
||||||
|
size="small"
|
||||||
|
[options]="sortingOptions"
|
||||||
|
[(ngModel)]="selectedLibrarySorting"
|
||||||
|
(ngModelChange)="onLibrarySortingChange()"
|
||||||
|
placeholder="Select Sorting">
|
||||||
|
</p-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="py-4">Shelf:
|
||||||
|
<i class="pi pi-info-circle text-sky-600"
|
||||||
|
pTooltip="Choose how books are sorted and displayed in the shelf sidebar."
|
||||||
|
tooltipPosition="right"
|
||||||
|
style="cursor: pointer;">
|
||||||
|
</i>
|
||||||
|
</p>
|
||||||
|
<div class="flex gap-4 justify-start">
|
||||||
|
<p-select
|
||||||
|
size="small"
|
||||||
|
[options]="sortingOptions"
|
||||||
|
[(ngModel)]="selectedShelfSorting"
|
||||||
|
(ngModelChange)="onShelfSortingChange()"
|
||||||
|
placeholder="Select Sorting">
|
||||||
|
</p-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
|
import {Select} from 'primeng/select';
|
||||||
|
import {Tooltip} from 'primeng/tooltip';
|
||||||
|
import {SidebarLibrarySorting, SidebarShelfSorting, User, UserService, UserSettings} from '../../user-management/user.service';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
import {Observable, Subscription} from 'rxjs';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-sidebar-sorting-preferences',
|
||||||
|
imports: [
|
||||||
|
Select,
|
||||||
|
Tooltip,
|
||||||
|
FormsModule
|
||||||
|
],
|
||||||
|
templateUrl: './sidebar-sorting-preferences.component.html',
|
||||||
|
styleUrl: './sidebar-sorting-preferences.component.scss'
|
||||||
|
})
|
||||||
|
export class SidebarSortingPreferencesComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
readonly sortingOptions = [
|
||||||
|
{label: 'Name | Ascending', value: {field: 'name', order: 'asc'}},
|
||||||
|
{label: 'Name | Descending', value: {field: 'name', order: 'desc'}},
|
||||||
|
{label: 'Creation Date | Ascending', value: {field: 'id', order: 'asc'}},
|
||||||
|
{label: 'Creation Date | Descending', value: {field: 'id', order: 'desc'}},
|
||||||
|
];
|
||||||
|
|
||||||
|
selectedLibrarySorting: SidebarLibrarySorting = {field: 'id', order: 'asc'};
|
||||||
|
selectedShelfSorting: SidebarShelfSorting = {field: 'id', order: 'asc'};
|
||||||
|
|
||||||
|
private readonly userService = inject(UserService);
|
||||||
|
private readonly messageService = inject(MessageService);
|
||||||
|
|
||||||
|
userData$: Observable<User | null> = this.userService.userState$;
|
||||||
|
private subscription?: Subscription;
|
||||||
|
private currentUser: User | null = null;
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.subscription = this.userData$.subscribe(user => {
|
||||||
|
if (user) {
|
||||||
|
this.currentUser = user;
|
||||||
|
this.loadPreferences(user.userSettings);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subscription?.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadPreferences(settings: UserSettings): void {
|
||||||
|
this.selectedLibrarySorting = settings.sidebarLibrarySorting;
|
||||||
|
this.selectedShelfSorting = settings.sidebarShelfSorting;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private updatePreference(path: string[], value: any): void {
|
||||||
|
if (!this.currentUser) return;
|
||||||
|
let target: any = this.currentUser.userSettings;
|
||||||
|
for (let i = 0; i < path.length - 1; i++) {
|
||||||
|
target = target[path[i]] ||= {};
|
||||||
|
}
|
||||||
|
target[path.at(-1)!] = value;
|
||||||
|
|
||||||
|
const [rootKey] = path;
|
||||||
|
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
|
||||||
|
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Preferences Updated',
|
||||||
|
detail: 'Your preferences have been saved successfully.',
|
||||||
|
life: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onLibrarySortingChange() {
|
||||||
|
this.updatePreference(['sidebarLibrarySorting'], this.selectedLibrarySorting);
|
||||||
|
}
|
||||||
|
|
||||||
|
onShelfSortingChange() {
|
||||||
|
this.updatePreference(['sidebarShelfSorting'], this.selectedShelfSorting);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||||
|
<app-view-preferences></app-view-preferences>
|
||||||
|
<p-divider></p-divider>
|
||||||
|
<app-sidebar-sorting-preferences></app-sidebar-sorting-preferences>
|
||||||
|
</div>
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
.enclosing-container {
|
||||||
|
border-color: var(--p-content-border-color);
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
import {Component} from '@angular/core';
|
||||||
|
import {Divider} from 'primeng/divider';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {TableModule} from 'primeng/table';
|
||||||
|
import {ToastModule} from 'primeng/toast';
|
||||||
|
import {ViewPreferencesComponent} from './view-preferences/view-preferences.component';
|
||||||
|
import {SidebarSortingPreferencesComponent} from './sidebar-sorting-preferences/sidebar-sorting-preferences.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-view-preferences-parent',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
Divider,
|
||||||
|
FormsModule,
|
||||||
|
TableModule,
|
||||||
|
ToastModule,
|
||||||
|
ViewPreferencesComponent,
|
||||||
|
SidebarSortingPreferencesComponent
|
||||||
|
],
|
||||||
|
templateUrl: './view-preferences-parent.component.html',
|
||||||
|
styleUrl: './view-preferences-parent.component.scss'
|
||||||
|
})
|
||||||
|
export class ViewPreferencesParentComponent {
|
||||||
|
|
||||||
|
}
|
||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
<div class="p-4">
|
||||||
|
<p class="text-lg pb-6 pt-4">
|
||||||
|
Library and Shelf View & Sort Preferences:
|
||||||
|
<i class="pi pi-info-circle text-sky-600"
|
||||||
|
pTooltip="Configure default and per-library/shelf preferences for sorting and view mode (grid or table) in the browser."
|
||||||
|
tooltipPosition="right"
|
||||||
|
style="cursor: pointer;"></i>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||||
|
<p>Default:</p>
|
||||||
|
<div class="flex gap-4 pl-4">
|
||||||
|
<p-select size="small" [options]="sortOptions" optionLabel="label" optionValue="field"
|
||||||
|
[(ngModel)]="selectedSort" placeholder="Sort" class="w-full md:w-72"></p-select>
|
||||||
|
<p-select size="small" [options]="sortDirectionOptions" [(ngModel)]="selectedSortDir"
|
||||||
|
placeholder="Direction" class="w-full md:w-44"></p-select>
|
||||||
|
<p-select size="small" [options]="viewModeOptions" [(ngModel)]="selectedView"
|
||||||
|
placeholder="View" class="w-full md:w-44"></p-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center mt-10">
|
||||||
|
<p>Overrides:</p>
|
||||||
|
<div class="flex gap-4">
|
||||||
|
<p-button label="Add New Override" outlined size="small" (onClick)="addOverride()"
|
||||||
|
[disabled]="availableLibraries.length === 0"></p-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pl-2 pt-2 min-w-[400px] max-w-[1000px]">
|
||||||
|
<p-table *ngIf="overrides.length > 0" [value]="overrides" class="relative z-0" [responsiveLayout]="'scroll'">
|
||||||
|
<ng-template pTemplate="header">
|
||||||
|
<tr>
|
||||||
|
<th class="min-w-[150px] max-w-[220px]">Type</th>
|
||||||
|
<th class="min-w-[220px] max-w-[280px]">Name</th>
|
||||||
|
<th class="min-w-[190px] max-w-[250px]">Sort By</th>
|
||||||
|
<th class="min-w-[125px]">Sort Dir</th>
|
||||||
|
<th class="min-w-[125px]">View</th>
|
||||||
|
<th class="w-[75px] text-center"></th>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template pTemplate="body" let-override let-rowIndex="rowIndex">
|
||||||
|
<tr>
|
||||||
|
<td><p-select size="small" [options]="entityTypeOptions" [(ngModel)]="override.entityType"
|
||||||
|
class="w-full" appendTo="body"></p-select></td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<ng-container *ngIf="override.entityType">
|
||||||
|
<p-select size="small"
|
||||||
|
[options]="getAvailableEntities(rowIndex, override.entityType)"
|
||||||
|
[(ngModel)]="override.library"
|
||||||
|
optionLabel="label" optionValue="value"
|
||||||
|
class="w-full" appendTo="body"></p-select>
|
||||||
|
</ng-container>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td><p-select size="small" [options]="sortOptions" optionLabel="label" optionValue="field"
|
||||||
|
[(ngModel)]="override.sort" class="w-full" appendTo="body"></p-select></td>
|
||||||
|
|
||||||
|
<td><p-select size="small" [options]="sortDirectionOptions" [(ngModel)]="override.sortDir"
|
||||||
|
class="w-full" appendTo="body"></p-select></td>
|
||||||
|
|
||||||
|
<td><p-select size="small" [options]="viewModeOptions" [(ngModel)]="override.view"
|
||||||
|
class="w-full" appendTo="body"></p-select></td>
|
||||||
|
|
||||||
|
<td class="text-center">
|
||||||
|
<p-button icon="pi pi-trash" severity="danger" class="p-button-sm" [outlined]="true"
|
||||||
|
(onClick)="removeOverride(rowIndex)"></p-button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
</p-table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-start px-6 pt-4">
|
||||||
|
<p-button label="Save" icon="pi pi-save" outlined size="small" (onClick)="saveSettings()"></p-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+176
@@ -0,0 +1,176 @@
|
|||||||
|
import {Component, inject, OnInit} from '@angular/core';
|
||||||
|
import {Button} from 'primeng/button';
|
||||||
|
import {NgIf} from '@angular/common';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
import {Select} from 'primeng/select';
|
||||||
|
import {TableModule} from 'primeng/table';
|
||||||
|
import {Tooltip} from 'primeng/tooltip';
|
||||||
|
import {User, UserService} from '../../user-management/user.service';
|
||||||
|
import {LibraryService} from '../../../book/service/library.service';
|
||||||
|
import {ShelfService} from '../../../book/service/shelf.service';
|
||||||
|
import {combineLatest} from 'rxjs';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {ToastModule} from 'primeng/toast';
|
||||||
|
import {filter, take} from 'rxjs/operators';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-view-preferences',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
Select,
|
||||||
|
Tooltip,
|
||||||
|
FormsModule,
|
||||||
|
Button,
|
||||||
|
NgIf,
|
||||||
|
TableModule,
|
||||||
|
ToastModule
|
||||||
|
],
|
||||||
|
templateUrl: './view-preferences.component.html',
|
||||||
|
styleUrl: './view-preferences.component.scss'
|
||||||
|
})
|
||||||
|
export class ViewPreferencesComponent implements OnInit {
|
||||||
|
sortOptions = [
|
||||||
|
{label: 'Title', field: 'title'},
|
||||||
|
{label: 'Title + Series', field: 'titleSeries'},
|
||||||
|
{label: 'Author', field: 'author'},
|
||||||
|
{label: 'Last Read', field: 'lastReadTime'},
|
||||||
|
{label: 'Added On', field: 'addedOn'},
|
||||||
|
{label: 'File Size', field: 'fileSizeKb'},
|
||||||
|
{label: 'Locked', field: 'locked'},
|
||||||
|
{label: 'Publisher', field: 'publisher'},
|
||||||
|
{label: 'Published Date', field: 'publishedDate'},
|
||||||
|
{label: 'Amazon Rating', field: 'amazonRating'},
|
||||||
|
{label: 'Amazon #', field: 'amazonReviewCount'},
|
||||||
|
{label: 'Goodreads Rating', field: 'goodreadsRating'},
|
||||||
|
{label: 'Goodreads #', field: 'goodreadsReviewCount'},
|
||||||
|
{label: 'Pages', field: 'pageCount'}
|
||||||
|
];
|
||||||
|
|
||||||
|
entityTypeOptions = [
|
||||||
|
{label: 'Library', value: 'LIBRARY'},
|
||||||
|
{label: 'Shelf', value: 'SHELF'}
|
||||||
|
];
|
||||||
|
|
||||||
|
sortDirectionOptions = [
|
||||||
|
{label: 'Ascending', value: 'ASC'},
|
||||||
|
{label: 'Descending', value: 'DESC'}
|
||||||
|
];
|
||||||
|
|
||||||
|
viewModeOptions = [
|
||||||
|
{label: 'Grid', value: 'GRID'},
|
||||||
|
{label: 'Table', value: 'TABLE'}
|
||||||
|
];
|
||||||
|
|
||||||
|
libraryOptions: { label: string; value: number }[] = [];
|
||||||
|
shelfOptions: { label: string; value: number }[] = [];
|
||||||
|
|
||||||
|
selectedSort: string = 'title';
|
||||||
|
selectedSortDir: 'ASC' | 'DESC' = 'ASC';
|
||||||
|
selectedView: 'GRID' | 'TABLE' = 'GRID';
|
||||||
|
|
||||||
|
overrides: {
|
||||||
|
entityType: 'LIBRARY' | 'SHELF';
|
||||||
|
library: number;
|
||||||
|
sort: string;
|
||||||
|
sortDir: 'ASC' | 'DESC';
|
||||||
|
view: 'GRID' | 'TABLE';
|
||||||
|
}[] = [];
|
||||||
|
|
||||||
|
private user: User | null = null;
|
||||||
|
|
||||||
|
private libraryService = inject(LibraryService);
|
||||||
|
private shelfService = inject(ShelfService);
|
||||||
|
private userService = inject(UserService);
|
||||||
|
private messageService = inject(MessageService);
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
combineLatest([
|
||||||
|
this.userService.userState$.pipe(filter(user => !!user), take(1)),
|
||||||
|
this.libraryService.libraryState$.pipe(filter(libraryState => !!libraryState?.libraries && libraryState.loaded), take(1)),
|
||||||
|
this.shelfService.shelfState$.pipe(filter(shelfState => !!shelfState?.shelves && shelfState.loaded), take(1)),
|
||||||
|
]).subscribe(([userState, librariesState, shelfState]) => {
|
||||||
|
|
||||||
|
this.user = userState;
|
||||||
|
const prefs = userState?.userSettings?.entityViewPreferences;
|
||||||
|
const global = prefs?.global;
|
||||||
|
this.selectedSort = global?.sortKey ?? 'title';
|
||||||
|
this.selectedSortDir = global?.sortDir ?? 'ASC';
|
||||||
|
this.selectedView = global?.view ?? 'GRID';
|
||||||
|
|
||||||
|
this.overrides = (prefs?.overrides ?? []).map(o => ({
|
||||||
|
entityType: o.entityType,
|
||||||
|
library: o.entityId,
|
||||||
|
sort: o.preferences.sortKey,
|
||||||
|
sortDir: o.preferences.sortDir ?? 'ASC',
|
||||||
|
view: o.preferences.view ?? 'GRID'
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.libraryOptions = (librariesState.libraries ?? []).filter(lib => lib.id !== undefined).map(lib => ({
|
||||||
|
label: lib.name,
|
||||||
|
value: lib.id!
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.shelfOptions = (shelfState?.shelves ?? []).filter(s => s.id !== undefined).map(s => ({
|
||||||
|
label: s.name,
|
||||||
|
value: s.id!
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getAvailableEntities(index: number, type: 'LIBRARY' | 'SHELF') {
|
||||||
|
const selected = this.overrides.map((o, i) => i !== index ? o.library : null);
|
||||||
|
const source = type === 'LIBRARY' ? this.libraryOptions : this.shelfOptions;
|
||||||
|
return source.filter(opt => !selected.includes(opt.value) || this.overrides[index]?.library === opt.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get availableLibraries() {
|
||||||
|
const used = new Set(this.overrides.map(o => `${o.entityType}_${o.library}`));
|
||||||
|
|
||||||
|
const withEntityType = (options: { label: string; value: number }[], entityType: 'LIBRARY' | 'SHELF') =>
|
||||||
|
options.map(opt => ({...opt, entityType}));
|
||||||
|
|
||||||
|
return [...withEntityType(this.libraryOptions, 'LIBRARY'), ...withEntityType(this.shelfOptions, 'SHELF')]
|
||||||
|
.filter(opt => !used.has(`${opt.entityType}_${opt.value}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
addOverride(): void {
|
||||||
|
const next = this.availableLibraries[0];
|
||||||
|
if (next) {
|
||||||
|
this.overrides.push({
|
||||||
|
entityType: next.entityType,
|
||||||
|
library: next.value,
|
||||||
|
sort: 'title',
|
||||||
|
sortDir: 'ASC',
|
||||||
|
view: 'GRID'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeOverride(index: number): void {
|
||||||
|
this.overrides.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettings(): void {
|
||||||
|
if (!this.user) return;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
global: {
|
||||||
|
sortKey: this.selectedSort,
|
||||||
|
sortDir: this.selectedSortDir,
|
||||||
|
view: this.selectedView
|
||||||
|
},
|
||||||
|
overrides: this.overrides.map(o => ({
|
||||||
|
entityType: o.entityType,
|
||||||
|
entityId: o.library,
|
||||||
|
preferences: {
|
||||||
|
sortKey: o.sort,
|
||||||
|
sortDir: o.sortDir,
|
||||||
|
view: o.view
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
this.userService.updateUserSetting(this.user.id, 'entityViewPreferences', payload);
|
||||||
|
this.messageService.add({severity: 'success', summary: 'Preferences Saved', detail: 'Your sorting and view preferences were saved successfully.'});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user