Feature: Improve RxStompConfig and book card menu permissions
• Utilize beforeConnect in RxStompConfig to ensure token retrieval at connection time. • Dynamically generate the book card menu based on user permissions instead of hiding items.
This commit is contained in:
@@ -15,6 +15,7 @@ import {MetadataRefreshRequest} from '../../../../metadata/model/request/metadat
|
||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {UserService} from '../../../../user.service';
|
||||
import {filter} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card',
|
||||
@@ -41,10 +42,12 @@ export class BookCardComponent implements OnInit {
|
||||
private userPermissions: any;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.initMenu();
|
||||
this.userService.userData$.subscribe((userData) => {
|
||||
this.userPermissions = userData?.permissions;
|
||||
});
|
||||
this.userService.userData$
|
||||
.pipe(filter(userData => !!userData))
|
||||
.subscribe((userData) => {
|
||||
this.userPermissions = userData.permissions;
|
||||
this.initMenu();
|
||||
});
|
||||
}
|
||||
|
||||
readBook(book: Book): void {
|
||||
@@ -75,54 +78,65 @@ export class BookCardComponent implements OnInit {
|
||||
icon: 'pi pi-info-circle',
|
||||
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'view'),
|
||||
},
|
||||
{
|
||||
label: 'Match Book',
|
||||
icon: 'pi pi-sparkles',
|
||||
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'match'),
|
||||
disabled: !this.hasEditMetadataPermission()
|
||||
},
|
||||
{
|
||||
label: 'Quick Refresh',
|
||||
icon: 'pi pi-bolt',
|
||||
command: () => {
|
||||
const metadataRefreshRequest: MetadataRefreshRequest = {
|
||||
quick: true,
|
||||
refreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: [this.book.id],
|
||||
};
|
||||
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
|
||||
},
|
||||
disabled: !this.hasEditMetadataPermission()
|
||||
},
|
||||
{
|
||||
label: 'Granular Refresh',
|
||||
icon: 'pi pi-database',
|
||||
command: () => {
|
||||
this.dialogService.open(MetadataFetchOptionsComponent, {
|
||||
header: 'Metadata Refresh Options',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {
|
||||
bookIds: [this.book!.id],
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
},
|
||||
});
|
||||
},
|
||||
disabled: !this.hasEditMetadataPermission()
|
||||
},
|
||||
{
|
||||
label: 'Download',
|
||||
icon: 'pi pi-download',
|
||||
command: () => {
|
||||
this.bookService.downloadFile(this.book.id);
|
||||
},
|
||||
disabled: !this.hasDownloadPermission()
|
||||
},
|
||||
...this.getPermissionBasedMenuItems(),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
private getPermissionBasedMenuItems(): MenuItem[] {
|
||||
const items: MenuItem[] = [];
|
||||
|
||||
if (this.hasEditMetadataPermission()) {
|
||||
items.push(
|
||||
{
|
||||
label: 'Match Book',
|
||||
icon: 'pi pi-sparkles',
|
||||
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'match'),
|
||||
},
|
||||
{
|
||||
label: 'Quick Refresh',
|
||||
icon: 'pi pi-bolt',
|
||||
command: () => {
|
||||
const metadataRefreshRequest: MetadataRefreshRequest = {
|
||||
quick: true,
|
||||
refreshType: MetadataRefreshType.BOOKS,
|
||||
bookIds: [this.book.id],
|
||||
};
|
||||
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Granular Refresh',
|
||||
icon: 'pi pi-database',
|
||||
command: () => {
|
||||
this.dialogService.open(MetadataFetchOptionsComponent, {
|
||||
header: 'Metadata Refresh Options',
|
||||
modal: true,
|
||||
closable: true,
|
||||
data: {
|
||||
bookIds: [this.book!.id],
|
||||
metadataRefreshType: MetadataRefreshType.BOOKS,
|
||||
},
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.hasDownloadPermission()) {
|
||||
items.push({
|
||||
label: 'Download',
|
||||
icon: 'pi pi-download',
|
||||
command: () => {
|
||||
this.bookService.downloadFile(this.book.id);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private openShelfDialog(): void {
|
||||
this.dialogService.open(ShelfAssignerComponent, {
|
||||
header: `Update Book's Shelves`,
|
||||
|
||||
Reference in New Issue
Block a user