WIP: Arrange UI files for better structuring
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
<div class="flex flex-col space-y-6 p-4">
|
||||
<table class="min-w-full table-auto border-collapse custom-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">Book Field</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">Base</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">Higher Precedence</th>
|
||||
<th class="px-4 py-2 text-left font-semibold text-gray-300">Highest Precedence</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<td class="px-4 py-2 text-gray-300"></td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="allDefault.value"
|
||||
(onChange)="syncProvider($event, 'default')"
|
||||
placeholder="Select All"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="allP2.value"
|
||||
(onChange)="syncProvider($event, 'p2')"
|
||||
placeholder="Select All"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="allP1.value"
|
||||
(onChange)="syncProvider($event, 'p1')"
|
||||
placeholder="Select All"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr *ngFor="let field of fields" [hidden]="field === 'cover' && !refreshCovers">
|
||||
<td class="px-4 py-2 text-gray-300">{{ field | titlecase }}</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].default"
|
||||
placeholder="Unset"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p2"
|
||||
placeholder="Unset"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<p-select [options]="providers" [(ngModel)]="fieldOptions[field].p1"
|
||||
placeholder="Unset"
|
||||
class="w-full">
|
||||
</p-select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="flex flex-row items-center justify-between">
|
||||
<div class="flex flex-row items-center gap-4 justify-start">
|
||||
<p>Refresh covers: </p>
|
||||
<p-checkbox [(ngModel)]="refreshCovers" [binary]="true"></p-checkbox>
|
||||
</div>
|
||||
<div class="flex flex-row gap-6">
|
||||
<p-button severity="warn" label="Reset" (onClick)="reset()"></p-button>
|
||||
<p-button label="Submit" (onClick)="submit()"></p-button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
.custom-table {
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--card-border);
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import {Component, Output, EventEmitter} from '@angular/core';
|
||||
import {Select, SelectChangeEvent} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {NgForOf, TitleCasePipe} from '@angular/common';
|
||||
import {Checkbox} from 'primeng/checkbox';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {FieldOptions, FieldProvider, MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-advanced-fetch-options',
|
||||
templateUrl: './metadata-advanced-fetch-options.component.html',
|
||||
imports: [Select, FormsModule, NgForOf, Checkbox, Button, TitleCasePipe],
|
||||
styleUrl: './metadata-advanced-fetch-options.component.scss',
|
||||
standalone: true
|
||||
})
|
||||
export class MetadataAdvancedFetchOptionsComponent {
|
||||
|
||||
@Output() metadataOptionsSubmitted: EventEmitter<MetadataRefreshOptions> = new EventEmitter<MetadataRefreshOptions>();
|
||||
fields: (keyof FieldOptions)[] = ['title', 'description', 'authors', 'categories', 'cover'];
|
||||
providers: string[] = ['Amazon', 'Google', 'GoodReads'];
|
||||
refreshCovers: boolean = false;
|
||||
|
||||
allDefault = {placeholder: 'Set All', value: ''};
|
||||
allP2 = {placeholder: 'Set All', value: ''};
|
||||
allP1 = {placeholder: 'Set All', value: ''};
|
||||
|
||||
fieldOptions: FieldOptions = {
|
||||
title: {default: null, p2: null, p1: null},
|
||||
description: {default: null, p2: null, p1: null},
|
||||
authors: {default: null, p2: null, p1: null},
|
||||
categories: {default: null, p2: null, p1: null},
|
||||
cover: {default: null, p2: null, p1: null}
|
||||
};
|
||||
|
||||
constructor(private messageService: MessageService) {
|
||||
}
|
||||
|
||||
syncProvider(event: SelectChangeEvent, providerType: keyof FieldProvider) {
|
||||
for (const field of Object.keys(this.fieldOptions)) {
|
||||
this.fieldOptions[field as keyof FieldOptions][providerType] = event.value;
|
||||
}
|
||||
}
|
||||
|
||||
submit() {
|
||||
const allProvidersSelected = Object.keys(this.fieldOptions).every(field => {
|
||||
return this.fieldOptions[field as keyof FieldOptions].default !== null;
|
||||
});
|
||||
if (allProvidersSelected) {
|
||||
const metadataRefreshOptions: MetadataRefreshOptions = {
|
||||
defaultProvider: this.allDefault.value,
|
||||
refreshCovers: this.refreshCovers,
|
||||
fieldOptions: this.fieldOptions
|
||||
};
|
||||
|
||||
this.metadataOptionsSubmitted.emit(metadataRefreshOptions);
|
||||
} else {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
life: 5000,
|
||||
detail: 'Base provider must be selected for all the book fields.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.allDefault.value = '';
|
||||
this.allP2.value = '';
|
||||
this.allP1.value = '';
|
||||
for (const field of Object.keys(this.fieldOptions)) {
|
||||
this.fieldOptions[field as keyof FieldOptions] = {
|
||||
default: null,
|
||||
p2: null,
|
||||
p1: null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user