Add mechanism for locking cover
This commit is contained in:
@@ -55,6 +55,7 @@ export interface BookMetadata {
|
|||||||
authorsLocked?: boolean;
|
authorsLocked?: boolean;
|
||||||
categoriesLocked?: boolean;
|
categoriesLocked?: boolean;
|
||||||
awardsLocked?: boolean;
|
awardsLocked?: boolean;
|
||||||
|
coverLocked?: boolean;
|
||||||
|
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-6
@@ -144,14 +144,17 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label class="label"></label>
|
<label class="label"></label>
|
||||||
<div class="input-container">
|
<div class="input-container">
|
||||||
<img *ngIf="!updateThumbnailUrl" [src]="urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn)" alt="Book Thumbnail" class="thumbnail"/>
|
<p-button *ngIf="!metadata['coverLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
|
||||||
<img *ngIf="updateThumbnailUrl" [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
|
<p-button *ngIf="metadata['coverLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="warn"></p-button>
|
||||||
|
<img [src]="metadataForm.get('thumbnailUrl')?.value" alt="Book Thumbnail" class="thumbnail"/>
|
||||||
|
<input type="hidden" id="thumbnailUrl" formControlName="thumbnailUrl" class="input"/>
|
||||||
<p-button
|
<p-button
|
||||||
[icon]="thumbnailSaved ? 'pi pi-check' : 'pi pi-arrow-left'"
|
[icon]="isValueSaved('thumbnailUrl') ? 'pi pi-check' : 'pi pi-arrow-left'"
|
||||||
[outlined]="true"
|
[outlined]="true"
|
||||||
[ngClass]="{'green-outlined-button': thumbnailSaved, 'yellow-outlined-button': updateThumbnailUrl}"
|
[ngClass]="{'green-outlined-button': isValueSaved('thumbnailUrl'), 'yellow-outlined-button': isValueCopied('thumbnailUrl')}"
|
||||||
class="arrow-button"
|
class="arrow-button"
|
||||||
(click)="shouldUpdateThumbnail()"/>
|
(click)="copyFetchedToCurrent('thumbnailUrl')"/>
|
||||||
|
<input type="hidden" [value]="fetchedMetadata.thumbnailUrl" class="input" readonly/>
|
||||||
<img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
|
<img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -288,8 +291,11 @@
|
|||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<p-button label="Back" icon="pi pi-arrow-left" severity="info" (onClick)="goBackClick()"></p-button>
|
<p-button label="Back" icon="pi pi-arrow-left" severity="info" (onClick)="goBackClick()"></p-button>
|
||||||
<div class="flex gap-x-4 justify-end">
|
<div class="flex gap-x-4 justify-end">
|
||||||
|
<p-button label="Unlock All" icon="pi pi-lock-open" [outlined]="true" severity="success" (onClick)="unlockAll()"></p-button>
|
||||||
|
<p-button label="Lock All" icon="pi pi-lock" [outlined]="true" severity="warn" (onClick)="lockAll()"></p-button>
|
||||||
|
<p-divider layout="vertical"/>
|
||||||
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
<p-button label="Close" icon="pi pi-times" severity="secondary" (onClick)="closeDialog()"></p-button>
|
||||||
<p-button label="Save" icon="pi pi-check" severity="primary" type="submit"></p-button>
|
<p-button label="Save" icon="pi pi-check" type="submit"></p-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+36
-10
@@ -37,8 +37,6 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
|
|
||||||
metadataForm: FormGroup;
|
metadataForm: FormGroup;
|
||||||
currentBookId!: number;
|
currentBookId!: number;
|
||||||
updateThumbnailUrl: boolean = false;
|
|
||||||
thumbnailSaved: boolean = false;
|
|
||||||
copiedFields: Record<string, boolean> = {};
|
copiedFields: Record<string, boolean> = {};
|
||||||
savedFields: Record<string, boolean> = {};
|
savedFields: Record<string, boolean> = {};
|
||||||
|
|
||||||
@@ -67,6 +65,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
seriesName: new FormControl(''),
|
seriesName: new FormControl(''),
|
||||||
seriesNumber: new FormControl(''),
|
seriesNumber: new FormControl(''),
|
||||||
seriesTotal: new FormControl(''),
|
seriesTotal: new FormControl(''),
|
||||||
|
thumbnailUrl: new FormControl(''),
|
||||||
|
|
||||||
titleLocked: new FormControl(false),
|
titleLocked: new FormControl(false),
|
||||||
subtitleLocked: new FormControl(false),
|
subtitleLocked: new FormControl(false),
|
||||||
@@ -84,6 +83,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
seriesNameLocked: new FormControl(false),
|
seriesNameLocked: new FormControl(false),
|
||||||
seriesNumberLocked: new FormControl(false),
|
seriesNumberLocked: new FormControl(false),
|
||||||
seriesTotalLocked: new FormControl(false),
|
seriesTotalLocked: new FormControl(false),
|
||||||
|
thumbnailUrlLocked: new FormControl(false),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +108,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
seriesName: metadata.seriesName,
|
seriesName: metadata.seriesName,
|
||||||
seriesNumber: metadata.seriesNumber,
|
seriesNumber: metadata.seriesNumber,
|
||||||
seriesTotal: metadata.seriesTotal,
|
seriesTotal: metadata.seriesTotal,
|
||||||
|
thumbnailUrl: this.urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn),
|
||||||
|
|
||||||
titleLocked: metadata.titleLocked || false,
|
titleLocked: metadata.titleLocked || false,
|
||||||
subtitleLocked: metadata.subtitleLocked || false,
|
subtitleLocked: metadata.subtitleLocked || false,
|
||||||
@@ -125,6 +126,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
seriesNameLocked: metadata.seriesNameLocked || false,
|
seriesNameLocked: metadata.seriesNameLocked || false,
|
||||||
seriesNumberLocked: metadata.seriesNumberLocked || false,
|
seriesNumberLocked: metadata.seriesNumberLocked || false,
|
||||||
seriesTotalLocked: metadata.seriesTotalLocked || false,
|
seriesTotalLocked: metadata.seriesTotalLocked || false,
|
||||||
|
thumbnailUrlLocked: metadata.coverLocked || false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (metadata.titleLocked) this.metadataForm.get('title')?.disable();
|
if (metadata.titleLocked) this.metadataForm.get('title')?.disable();
|
||||||
@@ -164,9 +166,6 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
this.savedFields[field] = true;
|
this.savedFields[field] = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this.updateThumbnailUrl) {
|
|
||||||
this.thumbnailSaved = true;
|
|
||||||
}
|
|
||||||
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
|
||||||
this.metadataCenterService.emit(bookMetadata);
|
this.metadataCenterService.emit(bookMetadata);
|
||||||
},
|
},
|
||||||
@@ -195,7 +194,7 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
seriesName: this.metadataForm.get('seriesName')?.value || this.copiedFields['seriesName'] ? this.getValueOrCopied('seriesName') : '',
|
seriesName: this.metadataForm.get('seriesName')?.value || this.copiedFields['seriesName'] ? this.getValueOrCopied('seriesName') : '',
|
||||||
seriesNumber: this.metadataForm.get('seriesNumber')?.value || this.copiedFields['seriesNumber'] ? this.getNumberOrCopied('seriesNumber') : null,
|
seriesNumber: this.metadataForm.get('seriesNumber')?.value || this.copiedFields['seriesNumber'] ? this.getNumberOrCopied('seriesNumber') : null,
|
||||||
seriesTotal: this.metadataForm.get('seriesTotal')?.value || this.copiedFields['seriesTotal'] ? this.getNumberOrCopied('seriesTotal') : null,
|
seriesTotal: this.metadataForm.get('seriesTotal')?.value || this.copiedFields['seriesTotal'] ? this.getNumberOrCopied('seriesTotal') : null,
|
||||||
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : '',
|
thumbnailUrl: this.getThumbnail(),
|
||||||
|
|
||||||
titleLocked: this.metadataForm.get('titleLocked')?.value,
|
titleLocked: this.metadataForm.get('titleLocked')?.value,
|
||||||
subtitleLocked: this.metadataForm.get('subtitleLocked')?.value,
|
subtitleLocked: this.metadataForm.get('subtitleLocked')?.value,
|
||||||
@@ -213,10 +212,19 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
seriesNameLocked: this.metadataForm.get('seriesNameLocked')?.value,
|
seriesNameLocked: this.metadataForm.get('seriesNameLocked')?.value,
|
||||||
seriesNumberLocked: this.metadataForm.get('seriesNumberLocked')?.value,
|
seriesNumberLocked: this.metadataForm.get('seriesNumberLocked')?.value,
|
||||||
seriesTotalLocked: this.metadataForm.get('seriesTotalLocked')?.value,
|
seriesTotalLocked: this.metadataForm.get('seriesTotalLocked')?.value,
|
||||||
|
coverLocked: this.metadataForm.get('thumbnailUrlLocked')?.value,
|
||||||
};
|
};
|
||||||
return updatedBookMetadata;
|
return updatedBookMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getThumbnail() {
|
||||||
|
const thumbnailUrl = this.metadataForm.get('thumbnailUrl')?.value;
|
||||||
|
if (thumbnailUrl?.includes('api/v1')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.copiedFields['thumbnailUrl'] ? this.getValueOrCopied('thumbnailUrl') : null;
|
||||||
|
}
|
||||||
|
|
||||||
private updateMetadata(): void {
|
private updateMetadata(): void {
|
||||||
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
|
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
@@ -287,10 +295,6 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
return Array.isArray(fieldValue) ? fieldValue : [];
|
return Array.isArray(fieldValue) ? fieldValue : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldUpdateThumbnail() {
|
|
||||||
this.updateThumbnailUrl = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
copyFetchedToCurrent(field: string): void {
|
copyFetchedToCurrent(field: string): void {
|
||||||
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
|
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
|
||||||
if (isLocked) {
|
if (isLocked) {
|
||||||
@@ -309,6 +313,28 @@ export class MetadataPickerComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lockAll(): void {
|
||||||
|
Object.keys(this.metadataForm.controls).forEach((key) => {
|
||||||
|
if (key.endsWith('Locked')) {
|
||||||
|
this.metadataForm.get(key)?.setValue(true);
|
||||||
|
const fieldName = key.replace('Locked', '');
|
||||||
|
this.metadataForm.get(fieldName)?.disable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.updateMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
unlockAll(): void {
|
||||||
|
Object.keys(this.metadataForm.controls).forEach((key) => {
|
||||||
|
if (key.endsWith('Locked')) {
|
||||||
|
this.metadataForm.get(key)?.setValue(false);
|
||||||
|
const fieldName = key.replace('Locked', '');
|
||||||
|
this.metadataForm.get(fieldName)?.enable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.updateMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
highlightCopiedInput(field: string): void {
|
highlightCopiedInput(field: string): void {
|
||||||
this.copiedFields = {...this.copiedFields, [field]: true};
|
this.copiedFields = {...this.copiedFields, [field]: true};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user