Add mechanism for locking cover

This commit is contained in:
aditya.chandel
2025-01-26 13:45:01 -07:00
parent c049c2bbc0
commit 1e6195f88e
3 changed files with 49 additions and 16 deletions
@@ -55,6 +55,7 @@ export interface BookMetadata {
authorsLocked?: boolean;
categoriesLocked?: boolean;
awardsLocked?: boolean;
coverLocked?: boolean;
[key: string]: any;
}
@@ -144,14 +144,17 @@
<div class="form-row">
<label class="label"></label>
<div class="input-container">
<img *ngIf="!updateThumbnailUrl" [src]="urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn)" alt="Book Thumbnail" class="thumbnail"/>
<img *ngIf="updateThumbnailUrl" [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
<p-button *ngIf="!metadata['coverLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('thumbnailUrl')" severity="success"></p-button>
<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
[icon]="thumbnailSaved ? 'pi pi-check' : 'pi pi-arrow-left'"
[icon]="isValueSaved('thumbnailUrl') ? 'pi pi-check' : 'pi pi-arrow-left'"
[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"
(click)="shouldUpdateThumbnail()"/>
(click)="copyFetchedToCurrent('thumbnailUrl')"/>
<input type="hidden" [value]="fetchedMetadata.thumbnailUrl" class="input" readonly/>
<img [src]="fetchedMetadata.thumbnailUrl" alt="Fetched Thumbnail" class="thumbnail"/>
</div>
</div>
@@ -288,8 +291,11 @@
<div class="flex justify-between">
<p-button label="Back" icon="pi pi-arrow-left" severity="info" (onClick)="goBackClick()"></p-button>
<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="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>
@@ -37,8 +37,6 @@ export class MetadataPickerComponent implements OnInit {
metadataForm: FormGroup;
currentBookId!: number;
updateThumbnailUrl: boolean = false;
thumbnailSaved: boolean = false;
copiedFields: Record<string, boolean> = {};
savedFields: Record<string, boolean> = {};
@@ -67,6 +65,7 @@ export class MetadataPickerComponent implements OnInit {
seriesName: new FormControl(''),
seriesNumber: new FormControl(''),
seriesTotal: new FormControl(''),
thumbnailUrl: new FormControl(''),
titleLocked: new FormControl(false),
subtitleLocked: new FormControl(false),
@@ -84,6 +83,7 @@ export class MetadataPickerComponent implements OnInit {
seriesNameLocked: new FormControl(false),
seriesNumberLocked: new FormControl(false),
seriesTotalLocked: new FormControl(false),
thumbnailUrlLocked: new FormControl(false),
});
}
@@ -108,6 +108,7 @@ export class MetadataPickerComponent implements OnInit {
seriesName: metadata.seriesName,
seriesNumber: metadata.seriesNumber,
seriesTotal: metadata.seriesTotal,
thumbnailUrl: this.urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn),
titleLocked: metadata.titleLocked || false,
subtitleLocked: metadata.subtitleLocked || false,
@@ -125,6 +126,7 @@ export class MetadataPickerComponent implements OnInit {
seriesNameLocked: metadata.seriesNameLocked || false,
seriesNumberLocked: metadata.seriesNumberLocked || false,
seriesTotalLocked: metadata.seriesTotalLocked || false,
thumbnailUrlLocked: metadata.coverLocked || false,
});
if (metadata.titleLocked) this.metadataForm.get('title')?.disable();
@@ -164,9 +166,6 @@ export class MetadataPickerComponent implements OnInit {
this.savedFields[field] = true;
}
});
if (this.updateThumbnailUrl) {
this.thumbnailSaved = true;
}
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
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') : '',
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,
thumbnailUrl: this.updateThumbnailUrl ? this.fetchedMetadata.thumbnailUrl : '',
thumbnailUrl: this.getThumbnail(),
titleLocked: this.metadataForm.get('titleLocked')?.value,
subtitleLocked: this.metadataForm.get('subtitleLocked')?.value,
@@ -213,10 +212,19 @@ export class MetadataPickerComponent implements OnInit {
seriesNameLocked: this.metadataForm.get('seriesNameLocked')?.value,
seriesNumberLocked: this.metadataForm.get('seriesNumberLocked')?.value,
seriesTotalLocked: this.metadataForm.get('seriesTotalLocked')?.value,
coverLocked: this.metadataForm.get('thumbnailUrlLocked')?.value,
};
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 {
this.metadataService.updateBookMetadata(this.currentBookId, this.buildMetadata()).subscribe({
next: (response) => {
@@ -287,10 +295,6 @@ export class MetadataPickerComponent implements OnInit {
return Array.isArray(fieldValue) ? fieldValue : [];
}
shouldUpdateThumbnail() {
this.updateThumbnailUrl = true;
}
copyFetchedToCurrent(field: string): void {
const isLocked = this.metadataForm.get(`${field}Locked`)?.value;
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 {
this.copiedFields = {...this.copiedFields, [field]: true};
}