feat(custom-covers): add functionality to generate custom covers for selected books (#2355)
* feat(custom-covers): add functionality to generate custom covers for selected books Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * feat(book-menu): add option to generate custom covers in metadata menu Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> --------- Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
@@ -93,6 +93,7 @@ describe('BookMenuService', () => {
|
||||
const bulkEdit = vi.fn();
|
||||
const multiEdit = vi.fn();
|
||||
const regenerate = vi.fn();
|
||||
const generateCustomCovers = vi.fn();
|
||||
|
||||
const items = service.getMetadataMenuItems(
|
||||
autoFetch,
|
||||
@@ -100,10 +101,11 @@ describe('BookMenuService', () => {
|
||||
bulkEdit,
|
||||
multiEdit,
|
||||
regenerate,
|
||||
generateCustomCovers,
|
||||
mockUser
|
||||
);
|
||||
|
||||
expect(items).toHaveLength(5);
|
||||
expect(items).toHaveLength(6);
|
||||
expect(items[0].label).toBe('Auto Fetch Metadata');
|
||||
expect(items[0].icon).toBe('pi pi-bolt');
|
||||
expect(items[1].label).toBe('Custom Fetch Metadata');
|
||||
@@ -114,6 +116,8 @@ describe('BookMenuService', () => {
|
||||
expect(items[3].icon).toBe('pi pi-clone');
|
||||
expect(items[4].label).toBe('Regenerate Covers');
|
||||
expect(items[4].icon).toBe('pi pi-image');
|
||||
expect(items[5].label).toBe('Generate Custom Covers');
|
||||
expect(items[5].icon).toBe('pi pi-palette');
|
||||
});
|
||||
|
||||
it('should return empty array when user has no permissions', () => {
|
||||
@@ -123,6 +127,7 @@ describe('BookMenuService', () => {
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
mockUserNoPermissions
|
||||
);
|
||||
|
||||
@@ -136,6 +141,7 @@ describe('BookMenuService', () => {
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
null
|
||||
);
|
||||
|
||||
@@ -148,6 +154,7 @@ describe('BookMenuService', () => {
|
||||
const bulkEdit = vi.fn();
|
||||
const multiEdit = vi.fn();
|
||||
const regenerate = vi.fn();
|
||||
const generateCustomCovers = vi.fn();
|
||||
|
||||
const items = service.getMetadataMenuItems(
|
||||
autoFetch,
|
||||
@@ -155,6 +162,7 @@ describe('BookMenuService', () => {
|
||||
bulkEdit,
|
||||
multiEdit,
|
||||
regenerate,
|
||||
generateCustomCovers,
|
||||
mockUser
|
||||
);
|
||||
|
||||
@@ -172,6 +180,9 @@ describe('BookMenuService', () => {
|
||||
|
||||
items[4].command!({} as any);
|
||||
expect(regenerate).toHaveBeenCalledOnce();
|
||||
|
||||
items[5].command!({} as any);
|
||||
expect(generateCustomCovers).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('should return only items for granted permissions', () => {
|
||||
@@ -192,6 +203,7 @@ describe('BookMenuService', () => {
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
vi.fn(),
|
||||
partialUser
|
||||
);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ export class BookMenuService {
|
||||
bulkEditMetadata: () => void,
|
||||
multiBookEditMetadata: () => void,
|
||||
regenerateCovers: () => void,
|
||||
generateCustomCovers: () => void,
|
||||
user: User | null): MenuItem[] {
|
||||
|
||||
const permissions = user?.permissions;
|
||||
@@ -66,6 +67,11 @@ export class BookMenuService {
|
||||
icon: 'pi pi-image',
|
||||
command: regenerateCovers
|
||||
});
|
||||
items.push({
|
||||
label: 'Generate Custom Covers',
|
||||
icon: 'pi pi-palette',
|
||||
command: generateCustomCovers
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
|
||||
@@ -581,6 +581,10 @@ export class BookService {
|
||||
return this.http.post<void>(`${this.url}/${bookId}/generate-custom-cover`, {});
|
||||
}
|
||||
|
||||
generateCustomCoversForBooks(bookIds: number[]): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/bulk-generate-custom-covers`, {bookIds});
|
||||
}
|
||||
|
||||
regenerateCoversForBooks(bookIds: number[]): Observable<void> {
|
||||
return this.http.post<void>(`${this.url}/bulk-regenerate-covers`, {bookIds});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user