Organize code
This commit is contained in:
+93
@@ -0,0 +1,93 @@
|
||||
@if (!loading) {
|
||||
<div class="px-4 pt-4 pb-2 h-full flex flex-col">
|
||||
|
||||
<div class="flex items-center">
|
||||
<h2 class="text-xl font-semibold">Review Metadata Proposal </h2>
|
||||
</div>
|
||||
|
||||
<div class="flex-grow overflow-auto">
|
||||
@if (currentProposal?.metadataJson; as proposed) {
|
||||
<app-metadata-picker
|
||||
[fetchedMetadata]="proposed"
|
||||
[book$]="book$"
|
||||
(goBack)="close()"
|
||||
[reviewMode]="true">
|
||||
</app-metadata-picker>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p-divider/>
|
||||
|
||||
<div class="flex justify-between items-center flex-wrap gap-2 pt-4">
|
||||
|
||||
<div class="flex items-center gap-2 pl-1 group"
|
||||
pTooltip="{{ currentIndex + 1 }} of {{ proposals.length }} processed ({{ ((currentIndex + 1) / proposals.length * 100) | number: '1.0-0' }}%)"
|
||||
tooltipPosition="top">
|
||||
<p-progressBar
|
||||
[value]="((currentIndex + 1) / proposals.length) * 100"
|
||||
styleClass="w-40 h-3 transition-all duration-300 ease-in-out group-hover:shadow-md"
|
||||
showValue="false">
|
||||
</p-progressBar>
|
||||
<span class="text-sm text-gray-300 font-medium tabular-nums whitespace-nowrap">
|
||||
Book {{ currentIndex + 1 }} / {{ proposals.length }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2 justify-end">
|
||||
|
||||
<p-button
|
||||
label="Close"
|
||||
icon="pi pi-times-circle"
|
||||
severity="secondary"
|
||||
[outlined]="true"
|
||||
(click)="close()">
|
||||
</p-button>
|
||||
|
||||
<p-divider layout="vertical"/>
|
||||
|
||||
<p-button
|
||||
label="Lock All"
|
||||
icon="pi pi-lock"
|
||||
severity="warn"
|
||||
[outlined]="true"
|
||||
(click)="lockAllMetadata()">
|
||||
</p-button>
|
||||
|
||||
<p-button
|
||||
label="Unlock All"
|
||||
icon="pi pi-lock-open"
|
||||
severity="success"
|
||||
[outlined]="true"
|
||||
(click)="unlockAllMetadata()">
|
||||
</p-button>
|
||||
|
||||
<p-divider layout="vertical"/>
|
||||
|
||||
<p-button
|
||||
label="Accept & Save"
|
||||
icon="pi pi-check-circle"
|
||||
iconPos="right"
|
||||
severity="success"
|
||||
[outlined]="true"
|
||||
(click)="onSave(currentProposal!)">
|
||||
</p-button>
|
||||
|
||||
<p-divider layout="vertical"/>
|
||||
|
||||
<p-button
|
||||
[label]="isLast ? 'Finish & Close' : 'Next'"
|
||||
[icon]="isLast ? 'pi pi-check-circle' : 'pi pi-angle-right'"
|
||||
iconPos="right"
|
||||
severity="info"
|
||||
[outlined]="true"
|
||||
(click)="onNext()">
|
||||
</p-button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="p-4 h-full flex items-center justify-center">
|
||||
<p-progressSpinner class="w-8 h-8" strokeWidth="4"></p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
import {Component, DestroyRef, inject, OnInit, ViewChild} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {FetchedProposal, MetadataTaskService} from '../../../book/service/metadata-task';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Book} from '../../../book/model/book.model';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {ProgressBar} from 'primeng/progressbar';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MetadataProgressService} from '../../../../shared/service/metadata-progress-service';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {MetadataPickerComponent} from '../book-metadata-center/metadata-picker/metadata-picker.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-review-dialog-component',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-review-dialog-component.html',
|
||||
styleUrls: ['./metadata-review-dialog-component.scss'],
|
||||
imports: [CommonModule, MetadataPickerComponent, ProgressSpinner, Button, Divider, ProgressBar, Tooltip],
|
||||
})
|
||||
export class MetadataReviewDialogComponent implements OnInit {
|
||||
|
||||
@ViewChild(MetadataPickerComponent)
|
||||
pickerComponent!: MetadataPickerComponent;
|
||||
|
||||
private config = inject(DynamicDialogConfig);
|
||||
private dialogRef = inject(DynamicDialogRef);
|
||||
private metadataTaskService = inject(MetadataTaskService);
|
||||
private bookService = inject(BookService);
|
||||
private progressService = inject(MetadataProgressService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
proposals: FetchedProposal[] = [];
|
||||
currentBooks: Record<number, Book> = {};
|
||||
loading = true;
|
||||
currentIndex = 0;
|
||||
private initialized = false;
|
||||
|
||||
private currentIndexSubject = new BehaviorSubject<number>(0);
|
||||
|
||||
book$: Observable<Book | null> = this.currentIndexSubject.pipe(
|
||||
map(idx => {
|
||||
const proposal = this.proposals[idx];
|
||||
if (!proposal) return null;
|
||||
return this.currentBooks[proposal.bookId] ?? null;
|
||||
})
|
||||
);
|
||||
|
||||
ngOnInit() {
|
||||
const taskId = this.config.data?.taskId;
|
||||
if (!taskId) {
|
||||
this.dialogRef.close();
|
||||
return;
|
||||
}
|
||||
|
||||
this.metadataTaskService.getTaskWithProposals(taskId).subscribe({
|
||||
next: (task) => {
|
||||
this.proposals = task.proposals || [];
|
||||
const bookIds = new Set(this.proposals.map(p => p.bookId));
|
||||
|
||||
this.bookService.bookState$
|
||||
.pipe(
|
||||
map(bookState => bookState.books?.filter(book => bookIds.has(book.id)) ?? []),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
)
|
||||
.subscribe((matchedBooks) => {
|
||||
|
||||
if (!this.initialized && matchedBooks.length === bookIds.size) {
|
||||
this.currentBooks = matchedBooks.reduce((map, book) => {
|
||||
map[book.id] = book;
|
||||
return map;
|
||||
}, {} as Record<number, Book>);
|
||||
this.loading = false;
|
||||
this.currentIndex = 0;
|
||||
this.currentIndexSubject.next(0);
|
||||
this.initialized = true;
|
||||
} else if (!this.initialized) {
|
||||
this.loading = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.dialogRef.close();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get currentProposal(): FetchedProposal | null {
|
||||
return this.proposals[this.currentIndex] ?? null;
|
||||
}
|
||||
|
||||
onSave(updatedFields: Partial<FetchedProposal>): void {
|
||||
const currentProposal = this.currentProposal;
|
||||
if (!currentProposal) return;
|
||||
this.pickerComponent.onSave();
|
||||
this.metadataTaskService.updateProposalStatus(currentProposal.taskId, currentProposal.proposalId, 'ACCEPTED').subscribe({
|
||||
next: () => {
|
||||
if (this.isLast) {
|
||||
this.metadataTaskService.deleteTask(currentProposal.taskId).subscribe(() => {
|
||||
this.progressService.clearTask(currentProposal.taskId);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onNext(): void {
|
||||
const nextIndex = this.currentIndex + 1;
|
||||
if (nextIndex >= this.proposals.length) {
|
||||
this.dialogRef.close();
|
||||
} else {
|
||||
this.currentIndex = nextIndex;
|
||||
this.currentIndexSubject.next(nextIndex);
|
||||
}
|
||||
}
|
||||
|
||||
lockAllMetadata(): void {
|
||||
this.pickerComponent?.lockAll();
|
||||
}
|
||||
|
||||
unlockAllMetadata(): void {
|
||||
this.pickerComponent?.unlockAll();
|
||||
}
|
||||
|
||||
get isLast(): boolean {
|
||||
return this.currentIndex === this.proposals.length - 1;
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user