WIP: Locking

This commit is contained in:
aditya.chandel
2025-01-25 22:02:37 -07:00
parent a298f12649
commit 596207b0c5
14 changed files with 456 additions and 108 deletions
@@ -14,7 +14,6 @@ export class BookMetadataCenterService {
dialogClose$ = this.dialogCloseSubject.asObservable();
emit(bookMetadata: BookMetadata) {
console.log(bookMetadata)
this.bookMetadataSubject.next(bookMetadata);
}
@@ -1,4 +1,4 @@
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave()" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
<form [formGroup]="bookMetadataForm" (ngSubmit)="onSave('saveButton')" *ngIf="bookMetadata$ | async as metadata" class="pt-2 flex flex-col h-full">
<div class="overflow-y-scroll flex-1">
@@ -8,89 +8,136 @@
<div class="flex flex-col flex-grow pl-2">
<!-- Title and Subtitle -->
<div class="flex flex-row w-full gap-4 pb-1">
<div class="flex flex-col gap-1 w-2/3">
<label for="title">Title</label>
<input pInputText id="title" formControlName="title" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="title" formControlName="title" class="w-full"/>
<p-button *ngIf="!metadata['titleLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('title')" severity="success"></p-button>
<p-button *ngIf="metadata['titleLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('title')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="subtitle">Subtitle</label>
<input pInputText id="subtitle" formControlName="subtitle" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="subtitle" formControlName="subtitle" class="w-full"/>
<p-button *ngIf="!metadata['subtitleLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="success"></p-button>
<p-button *ngIf="metadata['subtitleLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('subtitle')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Authors and Publisher -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-2/3">
<label for="authors">Authors</label>
<input pInputText id="authors" formControlName="authors" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="authors" formControlName="authors" class="w-full"/>
<p-button *ngIf="!metadata['authorsLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('authors')" severity="success"></p-button>
<p-button *ngIf="metadata['authorsLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('authors')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="publisher">Publisher</label>
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="publisher" formControlName="publisher" class="w-full"/>
<p-button *ngIf="!metadata['publisherLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publisher')" severity="success"></p-button>
<p-button *ngIf="metadata['publisherLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publisher')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Categories and Published Date -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-2/3">
<label for="categories">Categories</label>
<input pInputText id="categories" formControlName="categories" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="categories" formControlName="categories" class="w-full"/>
<p-button *ngIf="!metadata['categoriesLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('categories')" severity="success"></p-button>
<p-button *ngIf="metadata['categoriesLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('categories')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="publishedDate">Publish Date</label>
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="publishedDate" formControlName="publishedDate" class="w-full"/>
<p-button *ngIf="!metadata['publishedDateLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="success"></p-button>
<p-button *ngIf="metadata['publishedDateLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('publishedDate')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Language, ISBN 10, and ISBN 13 -->
<!-- ISBN, Language, Review Count -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-1/3">
<label for="language">Language</label>
<input pInputText id="language" formControlName="language" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="language" formControlName="language" class="w-full"/>
<p-button *ngIf="!metadata['languageLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('language')" severity="success"></p-button>
<p-button *ngIf="metadata['languageLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('language')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="isbn10">ISBN 10</label>
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="isbn10" formControlName="isbn10" class="w-full"/>
<p-button *ngIf="!metadata['isbn10Locked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="success"></p-button>
<p-button *ngIf="metadata['isbn10Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn10')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="isbn13">ISBN 13</label>
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
<div class="flex justify-between items-center gap-2">
<input pInputText id="isbn13" formControlName="isbn13" class="w-full"/>
<p-button *ngIf="!metadata['isbn13Locked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="success"></p-button>
<p-button *ngIf="metadata['isbn13Locked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('isbn13')" severity="warn"></p-button>
</div>
</div>
</div>
<!-- Review Count, Rating, Page Count -->
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-1/3">
<label for="reviewCount">Review Count</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
<p-button *ngIf="!metadata['reviewCountLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('reviewCount')" severity="success"></p-button>
<p-button *ngIf="metadata['reviewCountLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('reviewCount')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="rating">Rating</label>
<div class="flex justify-between items-center gap-2">
<input pInputText id="rating" formControlName="rating" class="w-full"/>
<p-button *ngIf="!metadata['ratingLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('rating')" severity="success"></p-button>
<p-button *ngIf="metadata['ratingLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('rating')" severity="warn"></p-button>
</div>
</div>
<div class="flex flex-col gap-1 w-1/3">
<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 class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-1/3">
<label for="reviewCount">Review Count</label>
<input pInputText id="reviewCount" formControlName="reviewCount" class="w-full"/>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="rating">Rating</label>
<input pInputText id="rating" formControlName="rating" class="w-full"/>
</div>
<div class="flex flex-col gap-1 w-1/3">
<label for="pageCount">Page Count</label>
<input pInputText id="pageCount" formControlName="pageCount" class="w-full"/>
<div class="flex flex-col gap-1 w-full">
<label for="description">Description</label>
<div class="flex justify-between items-center gap-2">
<textarea rows="12" pTextarea id="description" formControlName="description" class="w-full"></textarea>
<p-button *ngIf="!metadata['descriptionLocked']" icon="pi pi-lock-open" [outlined]="true" (onClick)="toggleLock('description')" severity="success"></p-button>
<p-button *ngIf="metadata['descriptionLocked']" icon="pi pi-lock" [outlined]="true" (onClick)="toggleLock('description')" severity="warn"></p-button>
</div>
</div>
</div>
</div>
</div>
<div class="flex flex-row w-full gap-4 mt-2 pb-1">
<div class="flex flex-col gap-1 w-full">
<label for="description">Description</label>
<!--<p-editor class="w-full" formControlName="description" id="description" [style]="{ height: '18rem' }">
<ng-template #header>
<span class="ql-formats">
<button type="button" class="ql-bold" aria-label="Bold"></button>
<button type="button" class="ql-italic" aria-label="Italic"></button>
<button type="button" class="ql-underline" aria-label="Underline"></button>
</span>
</ng-template>
</p-editor>-->
<textarea rows="12" pTextarea id="description" formControlName="description" class="w-full"></textarea>
</div>
</div>
</div>
<div class="flex flex-col gap-x-4 mt-auto">
@@ -7,7 +7,6 @@ import {FormControl, FormGroup, FormsModule, ReactiveFormsModule} from '@angular
import {Observable} from 'rxjs';
import {BookMetadataCenterService} from '../book-metadata-center.service';
import {AsyncPipe, NgIf} from '@angular/common';
import {BookService} from '../../../book/service/book.service';
import {MessageService} from 'primeng/api';
import {MetadataService} from '../../service/metadata.service';
import {BookMetadata} from '../../../book/model/book.model';
@@ -17,7 +16,7 @@ import {UrlHelperService} from '../../../utilities/service/url-helper.service';
selector: 'app-metadata-editor',
standalone: true,
templateUrl: './metadata-editor.component.html',
styleUrl: './metadata-editor.component.scss',
styleUrls: ['./metadata-editor.component.scss'],
imports: [
InputText,
Textarea,
@@ -32,7 +31,6 @@ import {UrlHelperService} from '../../../utilities/service/url-helper.service';
export class MetadataEditorComponent implements OnInit {
private metadataCenterService = inject(BookMetadataCenterService);
private bookService = inject(BookService);
private messageService = inject(MessageService);
private metadataService = inject(MetadataService);
protected urlHelper = inject(UrlHelperService);
@@ -56,6 +54,20 @@ export class MetadataEditorComponent implements OnInit {
language: new FormControl(''),
rating: new FormControl(''),
reviewCount: new FormControl(''),
titleLocked: new FormControl(false),
subtitleLocked: new FormControl(false),
authorsLocked: new FormControl(false),
categoriesLocked: new FormControl(false),
publisherLocked: new FormControl(false),
publishedDateLocked: new FormControl(false),
isbn10Locked: new FormControl(false),
isbn13Locked: new FormControl(false),
descriptionLocked: new FormControl(false),
pageCountLocked: new FormControl(false),
languageLocked: new FormControl(false),
ratingLocked: new FormControl(false),
reviewCountLocked: new FormControl(false),
});
}
@@ -63,11 +75,12 @@ export class MetadataEditorComponent implements OnInit {
this.bookMetadata$.subscribe((metadata) => {
if (metadata) {
this.currentBookId = metadata.bookId;
this.bookMetadataForm.setValue({
title: metadata.title,
subtitle: metadata.subtitle,
authors: metadata.authors.map((author) => author.name).join(', '),
categories: metadata.categories.map((category) => category.name).join(', '),
authors: metadata.authors.map((author) => author.name).sort().join(', '),
categories: metadata.categories.map((category) => category.name).sort().join(', '),
publisher: metadata.publisher,
publishedDate: metadata.publishedDate,
isbn10: metadata.isbn10,
@@ -76,13 +89,41 @@ export class MetadataEditorComponent implements OnInit {
pageCount: metadata.pageCount == 0 ? null : metadata.pageCount,
language: metadata.language,
rating: metadata.rating,
reviewCount: metadata.reviewCount
reviewCount: metadata.reviewCount,
titleLocked: metadata.titleLocked || false,
subtitleLocked: metadata.subtitleLocked || false,
authorsLocked: metadata.authorsLocked || false,
categoriesLocked: metadata.categoriesLocked || false,
publisherLocked: metadata.publisherLocked || false,
publishedDateLocked: metadata.publishedDateLocked || false,
isbn10Locked: metadata.isbn10Locked || false,
isbn13Locked: metadata.isbn13Locked || false,
descriptionLocked: metadata.descriptionLocked || false,
pageCountLocked: metadata.pageCountLocked || false,
languageLocked: metadata.languageLocked || false,
ratingLocked: metadata.ratingLocked || false,
reviewCountLocked: metadata.reviewCountLocked || false,
});
if (metadata.titleLocked) this.bookMetadataForm.get('title')?.disable();
if (metadata.subtitleLocked) this.bookMetadataForm.get('subtitle')?.disable();
if (metadata.authorsLocked) this.bookMetadataForm.get('authors')?.disable();
if (metadata.categoriesLocked) this.bookMetadataForm.get('categories')?.disable();
if (metadata.publisherLocked) this.bookMetadataForm.get('publisher')?.disable();
if (metadata.publishedDateLocked) this.bookMetadataForm.get('publishedDate')?.disable();
if (metadata.languageLocked) this.bookMetadataForm.get('language')?.disable();
if (metadata.isbn10Locked) this.bookMetadataForm.get('isbn10')?.disable();
if (metadata.isbn13Locked) this.bookMetadataForm.get('isbn13')?.disable();
if (metadata.reviewCountLocked) this.bookMetadataForm.get('reviewCount')?.disable();
if (metadata.ratingLocked) this.bookMetadataForm.get('rating')?.disable();
if (metadata.pageCountLocked) this.bookMetadataForm.get('pageCount')?.disable();
if (metadata.descriptionLocked) this.bookMetadataForm.get('description')?.disable();
}
});
}
onSave(): void {
onSave(source: string): void {
const updatedBookMetadata: BookMetadata = {
bookId: this.currentBookId,
title: this.bookMetadataForm.get('title')?.value,
@@ -97,21 +138,46 @@ export class MetadataEditorComponent implements OnInit {
pageCount: this.bookMetadataForm.get('pageCount')?.value,
rating: this.bookMetadataForm.get('rating')?.value,
reviewCount: this.bookMetadataForm.get('reviewCount')?.value,
language: this.bookMetadataForm.get('language')?.value
language: this.bookMetadataForm.get('language')?.value,
titleLocked: this.bookMetadataForm.get('titleLocked')?.value,
subtitleLocked: this.bookMetadataForm.get('subtitleLocked')?.value,
authorsLocked: this.bookMetadataForm.get('authorsLocked')?.value,
categoriesLocked: this.bookMetadataForm.get('categoriesLocked')?.value,
publisherLocked: this.bookMetadataForm.get('publisherLocked')?.value,
publishedDateLocked: this.bookMetadataForm.get('publishedDateLocked')?.value,
isbn10Locked: this.bookMetadataForm.get('isbn10Locked')?.value,
isbn13Locked: this.bookMetadataForm.get('isbn13Locked')?.value,
descriptionLocked: this.bookMetadataForm.get('descriptionLocked')?.value,
pageCountLocked: this.bookMetadataForm.get('pageCountLocked')?.value,
languageLocked: this.bookMetadataForm.get('languageLocked')?.value,
ratingLocked: this.bookMetadataForm.get('ratingLocked')?.value,
reviewCountLocked: this.bookMetadataForm.get('reviewCountLocked')?.value,
};
this.metadataService.updateBookMetadata(this.currentBookId, updatedBookMetadata).subscribe({
next: () => {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
this.metadataCenterService.emit(updatedBookMetadata);
next: (response) => {
if (source === 'saveButton') {
this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book metadata updated'});
}
this.metadataCenterService.emit(response);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book metadata'});
}
})
});
}
coverImageSrc(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
toggleLock(field: string): void {
const isLocked = this.bookMetadataForm.get(field + 'Locked')?.value;
const updatedLockedState = !isLocked;
this.bookMetadataForm.get(field + 'Locked')?.setValue(updatedLockedState);
if (updatedLockedState) {
this.bookMetadataForm.get(field)?.disable();
} else {
this.bookMetadataForm.get(field)?.enable();
}
this.onSave('lock');
}
closeDialog() {
@@ -55,7 +55,7 @@ export class MetadataSearcherComponent implements OnInit {
}));
}
}));
this.onSubmit();
//this.onSubmit();
}
get isSearchEnabled(): boolean {
@@ -24,6 +24,20 @@ export class MetadataService {
return this.http.post<FetchedMetadata[]>(`${this.url}/${bookId}`, request);
}
updatedMetadataFieldLock(bookId: number, field: string, isLocked: boolean): Observable<any> {
const requestPayload = {
bookId: bookId,
field: field,
isLocked: isLocked
};
return this.http.put<BookMetadata>(`${this.url}/lock`, requestPayload).pipe(
map(updatedMetadata => {
this.bookService.handleBookMetadataUpdate(bookId, updatedMetadata);
return updatedMetadata;
})
);
}
updateBookMetadata(bookId: number, bookMetadata: BookMetadata): Observable<BookMetadata> {
return this.http.put<BookMetadata>(`${this.url}/${bookId}`, bookMetadata).pipe(
map(updatedMetadata => {