diff --git a/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.ts b/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.ts index 4136e2197..9d2710da0 100644 --- a/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.ts +++ b/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.ts @@ -40,18 +40,16 @@ export class DossierTemplateActionsComponent { ); } - openDeleteDossierTemplateDialog($event: any) { - this._dialogService.openDeleteDossierTemplateDialog( - $event, - this.dossierTemplate, - async () => { - await this._appStateService.loadAllDossierTemplates(); - await this._appStateService.loadDictionaryData(); - await this._router.navigate(['main', 'admin']); - if (this.loadDossierTemplatesData) { - this.loadDossierTemplatesData.emit(); - } + openDeleteDossierTemplateDialog($event?: MouseEvent) { + $event?.stopPropagation(); + + this._dialogService.openDeleteDossierTemplateDialog(this.dossierTemplate, async () => { + await this._appStateService.loadAllDossierTemplates(); + await this._appStateService.loadDictionaryData(); + await this._router.navigate(['main', 'admin']); + if (this.loadDossierTemplatesData) { + this.loadDossierTemplatesData.emit(); } - ); + }); } } diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts index e60398154..712d9405f 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts @@ -115,7 +115,7 @@ export class AddEditDossierTemplateDialogComponent { .toPromise(); await this._appStateService.loadAllDossierTemplates(); await this._appStateService.loadDictionaryData(); - this.dialogRef.close({ dossierTemplate }); + this.dialogRef.close(dossierTemplate); } private _applyValidityIntervalConstraints(value): boolean { diff --git a/apps/red-ui/src/app/modules/admin/dialogs/edit-color-dialog/edit-color-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/edit-color-dialog/edit-color-dialog.component.ts index 94d786725..274d9789f 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/edit-color-dialog/edit-color-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/edit-color-dialog/edit-color-dialog.component.ts @@ -22,14 +22,14 @@ export class EditColorDialogComponent { private readonly _dictionaryControllerService: DictionaryControllerService, private readonly _notificationService: NotificationService, private readonly _translateService: TranslateService, - public dialogRef: MatDialogRef, + private readonly _dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) - public data: { colors: Colors; colorKey: string; dossierTemplateId: string } + private readonly _data: { colors: Colors; colorKey: string; dossierTemplateId: string } ) { - this.colors = data.colors; - this.colorKey = data.colorKey; - this._dossierTemplateId = data.dossierTemplateId; - this._initialColor = data.colors[this.colorKey]; + this.colors = _data.colors; + this.colorKey = _data.colorKey; + this._dossierTemplateId = _data.dossierTemplateId; + this._initialColor = _data.colors[this.colorKey]; this.colorForm = this._formBuilder.group({ color: [this.colors[this.colorKey], [Validators.required, Validators.minLength(7)]] @@ -50,7 +50,7 @@ export class EditColorDialogComponent { await this._dictionaryControllerService .setColors(colors, this._dossierTemplateId) .toPromise(); - this.dialogRef.close(true); + this._dialogRef.close(true); this._notificationService.showToastNotification( this._translateService.instant('edit-color-dialog.success', { color: this._translateService.instant( diff --git a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts index 371f7e7cc..02b4f2aee 100644 --- a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts @@ -28,25 +28,17 @@ export class DefaultColorsScreenComponent extends BaseListingComponent<{ protected readonly _injector: Injector ) { super(_injector); - this._appStateService.activateDossierTemplate( - _activatedRoute.snapshot.params.dossierTemplateId - ); + _appStateService.activateDossierTemplate(_activatedRoute.snapshot.params.dossierTemplateId); this._loadColors(); } - async loadDossierTemplatesData(): Promise { - await this._appStateService.loadAllDossierTemplates(); - } - openEditColorDialog($event: any, color: { key: string; value: string }) { $event.stopPropagation(); this._dialogService.openEditColorsDialog( this._colorsObj, color.key, this._appStateService.activeDossierTemplateId, - async () => { - this._loadColors(); - } + async () => this._loadColors() ); } diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html index e0f1fd189..082f7bbc9 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html @@ -30,21 +30,16 @@ - {{ - 'dictionary-listing.table-header.title' - | translate: { length: displayedEntities.length } - }} + {{ tableHeader }} - - - + @@ -160,25 +155,21 @@ > -
+
- + > - + >
diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts index a691cb394..97fbdd3cd 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts @@ -9,6 +9,7 @@ import { ActivatedRoute } from '@angular/router'; import { AdminDialogService } from '../../services/admin-dialog.service'; import { BaseListingComponent } from '@shared/base/base-listing.component'; import { TypeValueWrapper } from '../../../../models/file/type-value.wrapper'; +import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'redaction-dictionary-listing-screen', @@ -31,6 +32,7 @@ export class DictionaryListingScreenComponent private readonly _dictionaryControllerService: DictionaryControllerService, private readonly _activatedRoute: ActivatedRoute, private readonly _appStateService: AppStateService, + private readonly _translateService: TranslateService, readonly permissionsService: PermissionsService, protected readonly _injector: Injector ) { @@ -40,6 +42,12 @@ export class DictionaryListingScreenComponent ); } + get tableHeader(): string { + return this._translateService.instant('dictionary-listing.table-header.title', { + length: this.displayedEntities.length + }); + } + ngOnInit(): void { this._loadDictionaryData(); } @@ -47,7 +55,6 @@ export class DictionaryListingScreenComponent openDeleteDictionariesDialog($event?: MouseEvent, types = this.selectedEntitiesIds) { $event?.stopPropagation(); this._dialogService.openDeleteDictionariesDialog( - $event, types, this._appStateService.activeDossierTemplateId, async () => { @@ -77,17 +84,14 @@ export class DictionaryListingScreenComponent private _loadDictionaryData() { const appStateDictionaryData = this._appStateService.dictionaryData[this._appStateService.activeDossierTemplateId]; - this.allEntities = Object.keys(appStateDictionaryData) - .map(key => appStateDictionaryData[key]) - .filter(d => !d.virtual); + this.allEntities = Object.values(appStateDictionaryData).filter(d => !d.virtual); this.displayedEntities = [...this.allEntities]; + const dataObs = this.allEntities.map(dict => this._dictionaryControllerService .getDictionaryForType(this._appStateService.activeDossierTemplateId, dict.type) .pipe( - tap(values => { - dict.entries = values.entries ? values.entries : []; - }), + tap(values => (dict.entries = values.entries ?? [])), catchError(() => { console.log('error'); dict.entries = []; @@ -95,24 +99,24 @@ export class DictionaryListingScreenComponent }) ) ); + forkJoin(dataObs) .pipe(defaultIfEmpty(null)) - .subscribe(() => { - this._calculateData(); - }); + .subscribe(() => this._calculateData()); } - private _calculateData() { - this.chartData = []; - for (const dict of this.allEntities) { - this.chartData.push({ - value: dict.entries ? dict.entries.length : 0, - color: dict.hexColor, - label: dict.label, - key: dict.type - }); - } + private _calculateData(): void { + this.chartData = this.allEntities.map(dict => this._toChartConfig(dict)); this.chartData.sort((a, b) => (a.label < b.label ? -1 : 1)); this.viewReady = true; } + + private _toChartConfig(dict: TypeValueWrapper): DoughnutChartConfig { + return { + value: dict.entries ? dict.entries.length : 0, + color: dict.hexColor, + label: dict.label, + key: dict.type + }; + } } diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.html index be552ccfa..e59658806 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.html @@ -10,8 +10,7 @@ tooltip="dictionary-overview.action.delete" tooltipPosition="below" type="dark-bg" - > - + > - + > { await this._appStateService.loadDictionaryData(); - this._router.navigate([ + await this._router.navigate([ '/main', 'admin', 'dossier-templates', diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts index c484b2a36..e19c5ed1c 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts @@ -36,8 +36,8 @@ export class DossierTemplatesListingScreenComponent openDeleteTemplatesDialog($event?: MouseEvent) { $event?.stopPropagation(); + this._dialogService.openBulkDeleteDossierTemplatesDialog( - $event, this.selectedEntitiesIds, async () => { this.selectedEntitiesIds = []; diff --git a/apps/red-ui/src/app/modules/admin/services/admin-dialog.service.ts b/apps/red-ui/src/app/modules/admin/services/admin-dialog.service.ts index 29aa5ffb1..57219f61a 100644 --- a/apps/red-ui/src/app/modules/admin/services/admin-dialog.service.ts +++ b/apps/red-ui/src/app/modules/admin/services/admin-dialog.service.ts @@ -7,20 +7,16 @@ import { DossierTemplateModel, FileAttributeConfig, FileAttributesConfig, - FileManagementControllerService, - ManualRedactionControllerService, SMTPConfigurationModel, + TypeValue, User } from '@redaction/red-ui-http'; import { AddEditFileAttributeDialogComponent } from '../dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component'; import { AddEditDictionaryDialogComponent } from '../dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component'; import { AddEditDossierTemplateDialogComponent } from '../dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component'; -import { NotificationService } from '@services/notification.service'; import { ConfirmationDialogComponent } from '@shared/dialogs/confirmation-dialog/confirmation-dialog.component'; -import { AppStateService } from '@state/app-state.service'; import { ConfirmDeleteFileAttributeDialogComponent } from '../dialogs/confirm-delete-file-attribute-dialog/confirm-delete-file-attribute-dialog.component'; import { EditColorDialogComponent } from '../dialogs/edit-color-dialog/edit-color-dialog.component'; -import { TranslateService } from '@ngx-translate/core'; import { SmtpAuthDialogComponent } from '../dialogs/smtp-auth-dialog/smtp-auth-dialog.component'; import { AddEditUserDialogComponent } from '../dialogs/add-edit-user-dialog/add-edit-user-dialog.component'; import { ConfirmDeleteUsersDialogComponent } from '../dialogs/confirm-delete-users-dialog/confirm-delete-users-dialog.component'; @@ -44,22 +40,15 @@ const dialogConfig = { export class AdminDialogService { constructor( private readonly _dialog: MatDialog, - private readonly _translateService: TranslateService, - private readonly _appStateService: AppStateService, private readonly _dossierTemplateControllerService: DossierTemplateControllerService, - private readonly _dictionaryControllerService: DictionaryControllerService, - private readonly _fileManagementControllerService: FileManagementControllerService, - private readonly _notificationService: NotificationService, - private readonly _manualRedactionControllerService: ManualRedactionControllerService + private readonly _dictionaryControllerService: DictionaryControllerService ) {} openDeleteDictionariesDialog( - $event: MouseEvent, dictionaryTypes: string[], dossierTemplateId: string, - cb?: Function + cb?: () => void ): MatDialogRef { - $event.stopPropagation(); const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig); ref.afterClosed().subscribe(async result => { if (result) { @@ -73,11 +62,9 @@ export class AdminDialogService { } openDeleteDossierTemplateDialog( - $event: MouseEvent, dossierTemplate: DossierTemplateModel, - cb?: Function + cb?: () => void ): MatDialogRef { - $event.stopPropagation(); const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig); ref.afterClosed().subscribe(async result => { if (result) { @@ -88,11 +75,9 @@ export class AdminDialogService { } openBulkDeleteDossierTemplatesDialog( - $event: MouseEvent, dossierTemplateIds: string[], cb?: Function ): MatDialogRef { - $event.stopPropagation(); const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig); ref.afterClosed().subscribe(async result => { if (result) { @@ -105,7 +90,7 @@ export class AdminDialogService { openAddEditDictionaryDialog( dictionary: TypeValueWrapper, dossierTemplateId: string, - cb?: Function + cb?: (newDictionary: TypeValue | null) => void ): MatDialogRef { const ref = this._dialog.open(AddEditDictionaryDialogComponent, { ...dialogConfig, @@ -113,10 +98,9 @@ export class AdminDialogService { autoFocus: true }); - ref.afterClosed().subscribe(result => { - if (result && cb) { - cb(result); - } + ref.afterClosed().subscribe((newDictionary: TypeValue) => { + if (newDictionary && cb) cb(newDictionary); + else if (cb) cb(null); }); return ref; @@ -126,7 +110,7 @@ export class AdminDialogService { colors: Colors, colorKey: string, dossierTemplateId: string, - cb?: Function + cb?: (result: boolean) => void ): MatDialogRef { const ref = this._dialog.open(EditColorDialogComponent, { ...dialogConfig, @@ -134,7 +118,7 @@ export class AdminDialogService { autoFocus: true }); - ref.afterClosed().subscribe(result => { + ref.afterClosed().subscribe((result: boolean) => { if (result && cb) { cb(result); } diff --git a/apps/red-ui/src/app/services/sorting.service.ts b/apps/red-ui/src/app/services/sorting.service.ts index a51a79607..8b4495971 100644 --- a/apps/red-ui/src/app/services/sorting.service.ts +++ b/apps/red-ui/src/app/services/sorting.service.ts @@ -17,7 +17,7 @@ export type ScreenName = providedIn: 'root' }) export class SortingService { - private _options: { [key: string]: SortingOption } = { + private readonly _options: { [key: string]: SortingOption } = { 'dossier-listing': { column: 'dossier.dossierName', order: 'asc' }, 'dossier-overview': { column: 'filename', order: 'asc' }, 'dictionary-listing': { column: 'label', order: 'asc' }, @@ -26,8 +26,6 @@ export class SortingService { 'file-attributes-listing': { column: 'label', order: 'asc' } }; - constructor() {} - toggleSort(screen: ScreenName, column: string) { if (this._options[screen].column === column) { const currentOrder = this._options[screen].order;