From 80cef8bad6f6b741ee49bef20b87921876464cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Wed, 6 Jul 2022 15:34:38 +0300 Subject: [PATCH] RED-4416: Customize dossier dictionary colors --- .../src/app/modules/admin/admin.module.ts | 3 +- .../add-entity-dialog.component.html | 1 + .../add-entity-dialog.component.ts | 2 +- .../entities/screens/info/info.component.html | 6 +- .../entities/screens/info/info.component.ts | 2 +- .../screens/watermark/watermark.module.ts | 3 +- .../admin/shared/shared-admin.module.ts | 6 +- .../file-preview/file-preview.module.ts | 2 - .../dictionary-details-dialog.component.html | 22 ++++ .../dictionary-details-dialog.component.scss | 0 .../dictionary-details-dialog.component.ts | 41 +++++++ .../edit-dossier-dictionary.component.html | 30 ++--- .../edit-dossier-dictionary.component.ts | 73 +++--------- .../services/dossiers-dialog.service.ts | 7 +- .../shared-dossiers/shared-dossiers.module.ts | 3 +- .../add-edit-entity.component.html | 10 +- .../add-edit-entity.component.scss | 0 .../add-edit-entity.component.ts | 104 +++++++++++------- .../src/app/modules/shared/shared.module.ts | 6 +- .../entity-services/dictionary.service.ts | 9 +- .../src/app/services/permissions.service.ts | 6 +- apps/red-ui/src/assets/i18n/de.json | 16 ++- apps/red-ui/src/assets/i18n/en.json | 16 ++- libs/common-ui | 2 +- 24 files changed, 207 insertions(+), 163 deletions(-) create mode 100644 apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.html create mode 100644 apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.scss create mode 100644 apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.ts rename apps/red-ui/src/app/modules/{admin => }/shared/components/add-edit-entity/add-edit-entity.component.html (91%) rename apps/red-ui/src/app/modules/{admin => }/shared/components/add-edit-entity/add-edit-entity.component.scss (100%) rename apps/red-ui/src/app/modules/{admin => }/shared/components/add-edit-entity/add-edit-entity.component.ts (70%) diff --git a/apps/red-ui/src/app/modules/admin/admin.module.ts b/apps/red-ui/src/app/modules/admin/admin.module.ts index 91432eb9e..89bbcaa60 100644 --- a/apps/red-ui/src/app/modules/admin/admin.module.ts +++ b/apps/red-ui/src/app/modules/admin/admin.module.ts @@ -9,7 +9,6 @@ import { DigitalSignatureScreenComponent } from './screens/digital-signature/dig import { FileAttributesListingScreenComponent } from './screens/file-attributes-listing/file-attributes-listing-screen.component'; import { UserListingScreenComponent } from './screens/user-listing/user-listing-screen.component'; import { DossierTemplateBreadcrumbsComponent } from './components/dossier-template-breadcrumbs/dossier-template-breadcrumbs.component'; -import { ColorPickerModule } from 'ngx-color-picker'; import { AddEditFileAttributeDialogComponent } from './dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component'; import { AddEditCloneDossierTemplateDialogComponent } from './dialogs/add-edit-dossier-template-dialog/add-edit-clone-dossier-template-dialog.component'; import { AddEntityDialogComponent } from './dialogs/add-entity-dialog/add-entity-dialog.component'; @@ -102,6 +101,6 @@ const components = [ @NgModule({ declarations: [...components], providers: [AdminDialogService, AuditService, DigitalSignatureService, RulesService, SmtpConfigService], - imports: [CommonModule, SharedModule, AdminRoutingModule, SharedAdminModule, ColorPickerModule, A11yModule], + imports: [CommonModule, SharedModule, AdminRoutingModule, SharedAdminModule, A11yModule], }) export class AdminModule {} diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.html index e2267fb81..f6d044cee 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.html +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.html @@ -8,6 +8,7 @@ #redactionAddEditEntity [dossierTemplateId]="dossierTemplateId" [entity]="null" + [readOnly]="false" > diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.ts index 8308e519b..d51cea4dd 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-entity-dialog/add-entity-dialog.component.ts @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, Inject, Injector, ViewChild } from import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { TranslateService } from '@ngx-translate/core'; import { UserService } from '@services/user.service'; -import { AddEditEntityComponent } from '../../shared/components/add-edit-entity/add-edit-entity.component'; +import { AddEditEntityComponent } from '../../../shared/components/add-edit-entity/add-edit-entity.component'; import { BaseDialogComponent } from '@iqser/common-ui'; interface DialogData { diff --git a/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.html b/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.html index db6a27e1b..9e28a7115 100644 --- a/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.html @@ -10,7 +10,11 @@
- +
diff --git a/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.ts b/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.ts index b551a6be2..0397da7a3 100644 --- a/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/entities/screens/info/info.component.ts @@ -4,7 +4,7 @@ import { DictionariesMapService } from '@services/entity-services/dictionaries-m import { ActivatedRoute } from '@angular/router'; import { UserService } from '@services/user.service'; import { PermissionsService } from '@services/permissions.service'; -import { AddEditEntityComponent } from '../../../../shared/components/add-edit-entity/add-edit-entity.component'; +import { AddEditEntityComponent } from '@shared/components/add-edit-entity/add-edit-entity.component'; import { IqserEventTarget } from '@iqser/common-ui'; import { Observable } from 'rxjs'; diff --git a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts index 019258112..962eecb37 100644 --- a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts +++ b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts @@ -3,12 +3,11 @@ import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; import { SharedModule } from '@shared/shared.module'; import { WatermarkScreenComponent } from './watermark-screen/watermark-screen.component'; -import { ColorPickerModule } from 'ngx-color-picker'; const routes = [{ path: '', component: WatermarkScreenComponent }]; @NgModule({ declarations: [WatermarkScreenComponent], - imports: [RouterModule.forChild(routes), CommonModule, SharedModule, ColorPickerModule], + imports: [RouterModule.forChild(routes), CommonModule, SharedModule], }) export class WatermarkModule {} diff --git a/apps/red-ui/src/app/modules/admin/shared/shared-admin.module.ts b/apps/red-ui/src/app/modules/admin/shared/shared-admin.module.ts index 285cc8f30..0cb49519c 100644 --- a/apps/red-ui/src/app/modules/admin/shared/shared-admin.module.ts +++ b/apps/red-ui/src/app/modules/admin/shared/shared-admin.module.ts @@ -2,17 +2,15 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { SharedModule } from '@shared/shared.module'; import { DossierTemplateActionsComponent } from './components/dossier-template-actions/dossier-template-actions.component'; -import { AddEditEntityComponent } from './components/add-edit-entity/add-edit-entity.component'; -import { ColorPickerModule } from 'ngx-color-picker'; import { RouterModule } from '@angular/router'; -const components = [DossierTemplateActionsComponent, AddEditEntityComponent]; +const components = [DossierTemplateActionsComponent]; const modules = [CommonModule, SharedModule]; @NgModule({ declarations: [...components], exports: [...components, ...modules], - imports: [...modules, RouterModule, ColorPickerModule], + imports: [...modules, RouterModule], }) export class SharedAdminModule {} diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview.module.ts b/apps/red-ui/src/app/modules/file-preview/file-preview.module.ts index 796757b48..7d2e3ec45 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview.module.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview.module.ts @@ -32,7 +32,6 @@ import { ChangeLegalBasisDialogComponent } from './dialogs/change-legal-basis-di import { RecategorizeImageDialogComponent } from './dialogs/recategorize-image-dialog/recategorize-image-dialog.component'; import { HighlightActionDialogComponent } from './dialogs/highlight-action-dialog/highlight-action-dialog.component'; import { FilePreviewDialogService } from './services/file-preview-dialog.service'; -import { ColorPickerModule } from 'ngx-color-picker'; import { DocumentInfoDialogComponent } from './dialogs/document-info-dialog/document-info-dialog.component'; import { ManualRedactionService } from './services/manual-redaction.service'; import { AnnotationWrapperComponent } from './components/annotation-wrapper/annotation-wrapper.component'; @@ -94,7 +93,6 @@ const components = [ IqserIconsModule, TranslateModule, OverlayModule, - ColorPickerModule, ], providers: [FilePreviewDialogService, ManualRedactionService, DocumentUnloadedGuard], }) diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.html b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.html new file mode 100644 index 000000000..354b4577d --- /dev/null +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.html @@ -0,0 +1,22 @@ +
+
{{ 'dictionary-details.title' | translate }}
+ +
+ +
+ +
+ + +
+
+ + +
diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.scss b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.ts b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.ts new file mode 100644 index 000000000..8fa41f1bd --- /dev/null +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component.ts @@ -0,0 +1,41 @@ +import { Component, Inject, Injector, ViewChild } from '@angular/core'; +import { BaseDialogComponent } from '@iqser/common-ui'; +import { dossiersServiceProvider } from '@services/entity-services/dossiers.service.provider'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { Dictionary } from '@red/domain'; +import { AddEditEntityComponent } from '@shared/components/add-edit-entity/add-edit-entity.component'; + +@Component({ + templateUrl: './dictionary-details-dialog.component.html', + styleUrls: ['./dictionary-details-dialog.component.scss'], + providers: [dossiersServiceProvider], +}) +export class DictionaryDetailsDialogComponent extends BaseDialogComponent { + @ViewChild(AddEditEntityComponent, { static: true }) private readonly _addEditEntityComponent: AddEditEntityComponent; + + constructor( + @Inject(MAT_DIALOG_DATA) + readonly data: { dictionary: Dictionary; dossierId: string; readOnly: boolean }, + protected readonly _injector: Injector, + protected readonly _dialogRef: MatDialogRef, + ) { + super(_injector, _dialogRef, true); + } + + get valid(): boolean { + return this._addEditEntityComponent.valid; + } + + get changed(): boolean { + return this._addEditEntityComponent.changed; + } + + get disabled(): boolean { + return this._addEditEntityComponent.disabled; + } + + async save(): Promise { + await this._addEditEntityComponent.save(); + this._dialogRef.close(true); + } +} diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html index 966c5faf9..299d49b02 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html @@ -9,28 +9,18 @@
- -
-
- - {{ 'edit-dossier-dialog.dictionary.add-to-dictionary-action' | translate }} - -
-
-
-
- +
+
diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts index 583ac1514..2e3fb7f4d 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.ts @@ -1,14 +1,12 @@ import { Component, Input, OnInit, ViewChild } from '@angular/core'; -import { Dictionary, Dossier, IDictionary } from '@red/domain'; +import { Dictionary, Dossier } from '@red/domain'; import { EditDossierSaveResult, EditDossierSectionInterface } from '../edit-dossier-section.interface'; import { PermissionsService } from '@services/permissions.service'; import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component'; import { DictionaryService } from '@services/entity-services/dictionary.service'; -import { CircleButtonTypes, LoadingService, Toaster } from '@iqser/common-ui'; -import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; +import { CircleButtonTypes, LoadingService } from '@iqser/common-ui'; import { firstValueFrom } from 'rxjs'; -import { DossiersService } from '@services/dossiers/dossiers.service'; +import { DossiersDialogService } from '../../../services/dossiers-dialog.service'; @Component({ selector: 'redaction-edit-dossier-dictionary', @@ -18,33 +16,22 @@ import { DossiersService } from '@services/dossiers/dossiers.service'; export class EditDossierDictionaryComponent implements EditDossierSectionInterface, OnInit { @Input() dossier: Dossier; - form: UntypedFormGroup; canEdit = false; - canEditDisplayName = false; + canEditProperties = false; dossierDictionary: Dictionary; readonly circleButtonTypes = CircleButtonTypes; @ViewChild(DictionaryManagerComponent, { static: false }) private readonly _dictionaryManager: DictionaryManagerComponent; constructor( - private readonly _dossiersService: DossiersService, private readonly _dictionaryService: DictionaryService, private readonly _permissionsService: PermissionsService, private readonly _loadingService: LoadingService, - private readonly _formBuilder: UntypedFormBuilder, - private readonly _toaster: Toaster, + private readonly _dialogService: DossiersDialogService, ) {} - get formChanged() { - if (this.form) { - return this.form.get('addToDictionaryAction').value !== this.dossierDictionary.addToDictionaryAction; - } - - return false; - } - get changed(): boolean { - return this._dictionaryManager.editor.hasChanges || this.formChanged; + return this._dictionaryManager.editor.hasChanges; } get disabled(): boolean { @@ -52,52 +39,25 @@ export class EditDossierDictionaryComponent implements EditDossierSectionInterfa } get valid(): boolean { - return this._dictionaryManager.editor.hasChanges || this.formChanged; + return this._dictionaryManager.editor.hasChanges; } async ngOnInit() { this._loadingService.start(); this.canEdit = this._permissionsService.canEditDossierDictionary(this.dossier); - this.canEditDisplayName = this._permissionsService.canEditDossierDictionaryDisplayName(this.dossier); + this.canEditProperties = this._permissionsService.canEditDossierDictionaryProperties(this.dossier); await this._updateDossierDictionary(); - this.form = this._getForm(); - this._loadingService.stop(); - } - - async updateDisplayName(label: string) { - try { - this._loadingService.start(); - // TODO: Setting the type manually shouldn't be necessary, but for now it fails with status code 500... - const dictionary: IDictionary = { ...this.dossierDictionary, type: 'dossier_redaction', label }; - await firstValueFrom( - this._dictionaryService.updateDictionary(dictionary, this.dossier.dossierTemplateId, 'dossier_redaction', this.dossier.id), - ); - await this._updateDossierDictionary(); - this._toaster.success(_('edit-dossier-dialog.dictionary.display-name.success')); - } catch (error) { - this._toaster.error(_('edit-dossier-dialog.dictionary.display-name.error')); - } this._loadingService.stop(); } async save(): EditDossierSaveResult { try { - const dictionary: IDictionary = { - ...this.dossierDictionary, - type: 'dossier_redaction', - hasDictionary: true, - addToDictionaryAction: this.form.get('addToDictionaryAction').value, - }; - await firstValueFrom( - this._dictionaryService.updateDictionary(dictionary, this.dossier.dossierTemplateId, 'dossier_redaction', this.dossier.id), - ); - await firstValueFrom( this._dictionaryService.saveEntries( this._dictionaryManager.editor.currentEntries, this._dictionaryManager.initialEntries, this.dossier.dossierTemplateId, - 'dossier_redaction', + this.dossierDictionary.type, this.dossier.id, false, ), @@ -112,19 +72,12 @@ export class EditDossierDictionaryComponent implements EditDossierSectionInterfa revert() { this._dictionaryManager.revert(); - this.form.reset({ - addToDictionaryAction: this.dossierDictionary.addToDictionaryAction, - }); } - private _getForm(): UntypedFormGroup { - return this._formBuilder.group({ - addToDictionaryAction: [ - { - value: this.dossierDictionary.addToDictionaryAction, - disabled: !this._permissionsService.canEditDossierDictionaryAddAction(this.dossier), - }, - ], + openEditDetailsDialog(): void { + const data = { dictionary: this.dossierDictionary, dossierId: this.dossier.id, readOnly: !this.canEditProperties }; + this._dialogService.openDialog('editDictionaryDetails', null, data, async () => { + await this._updateDossierDictionary(); }); } diff --git a/apps/red-ui/src/app/modules/shared-dossiers/services/dossiers-dialog.service.ts b/apps/red-ui/src/app/modules/shared-dossiers/services/dossiers-dialog.service.ts index 0b55d8f20..e5628187b 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/services/dossiers-dialog.service.ts +++ b/apps/red-ui/src/app/modules/shared-dossiers/services/dossiers-dialog.service.ts @@ -4,8 +4,9 @@ import { EditDossierDialogComponent } from '../dialogs/edit-dossier-dialog/edit- import { AssignReviewerApproverDialogComponent } from '../dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component'; import { ConfirmationDialogComponent, DialogConfig, DialogService, largeDialogConfig } from '@iqser/common-ui'; import { ImportRedactionsDialogComponent } from '../../file-preview/dialogs/import-redactions-dialog/import-redactions-dialog'; +import { DictionaryDetailsDialogComponent } from '../dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component'; -type DialogType = 'confirm' | 'editDossier' | 'assignFile' | 'importRedactions'; +type DialogType = 'confirm' | 'editDossier' | 'assignFile' | 'importRedactions' | 'editDictionaryDetails'; @Injectable() export class DossiersDialogService extends DialogService { @@ -26,6 +27,10 @@ export class DossiersDialogService extends DialogService { component: ImportRedactionsDialogComponent, dialogConfig: { disableClose: false }, }, + editDictionaryDetails: { + component: DictionaryDetailsDialogComponent, + dialogConfig: { disableClose: false }, + }, }; constructor(protected readonly _dialog: MatDialog) { diff --git a/apps/red-ui/src/app/modules/shared-dossiers/shared-dossiers.module.ts b/apps/red-ui/src/app/modules/shared-dossiers/shared-dossiers.module.ts index 01d6b5d19..8a57d0a07 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/shared-dossiers.module.ts +++ b/apps/red-ui/src/app/modules/shared-dossiers/shared-dossiers.module.ts @@ -12,6 +12,7 @@ import { EditDossierAttributesComponent } from './dialogs/edit-dossier-dialog/at import { EditDossierTeamComponent } from './dialogs/edit-dossier-dialog/edit-dossier-team/edit-dossier-team.component'; import { DateColumnComponent } from './components/date-column/date-column.component'; import { FileAssignService } from './services/file-assign.service'; +import { DictionaryDetailsDialogComponent } from './dialogs/edit-dossier-dialog/dictionary/dictionary-details-dialog/dictionary-details-dialog.component'; const components = [ FileActionsComponent, @@ -23,7 +24,7 @@ const components = [ FileActionsComponent, DateColumnComponent, ]; -const dialogs = [EditDossierDialogComponent, AssignReviewerApproverDialogComponent]; +const dialogs = [EditDossierDialogComponent, AssignReviewerApproverDialogComponent, DictionaryDetailsDialogComponent]; const services = [DossiersDialogService, FileAssignService]; @NgModule({ diff --git a/apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.html b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html similarity index 91% rename from apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.html rename to apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html index bb8c35c8e..7d671c703 100644 --- a/apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.html +++ b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html @@ -5,7 +5,7 @@ -
+
@@ -34,7 +34,7 @@
-
+
{{ this.form.get('type').value || '-' }}
-
+
{{ 'add-edit-entity.form.redaction' | translate }} @@ -63,7 +63,7 @@ >
-
+
-
+
{{ 'add-edit-entity.form.has-dictionary' | translate }} diff --git a/apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.scss b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.scss similarity index 100% rename from apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.scss rename to apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.scss diff --git a/apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.ts b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts similarity index 70% rename from apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.ts rename to apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts index 2b5752c55..769080ed8 100644 --- a/apps/red-ui/src/app/modules/admin/shared/components/add-edit-entity/add-edit-entity.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts @@ -13,7 +13,7 @@ import { BaseFormComponent, LoadingService, Toaster } from '@iqser/common-ui'; const REDACTION_FIELDS = ['defaultReason']; @Component({ - selector: 'redaction-add-edit-entity [entity] [dossierTemplateId]', + selector: 'redaction-add-edit-entity [entity] [dossierTemplateId] [readOnly]', templateUrl: './add-edit-entity.component.html', styleUrls: ['./add-edit-entity.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, @@ -21,6 +21,8 @@ const REDACTION_FIELDS = ['defaultReason']; export class AddEditEntityComponent extends BaseFormComponent implements OnInit { @Input() dossierTemplateId: string; @Input() entity: Dictionary; + @Input() readOnly: boolean; + @Input() dossierId?: string; technicalName$: Observable; @@ -44,16 +46,20 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit super(); } + get #isDossierRedaction(): boolean { + return this.entity?.type === 'dossier_redaction'; + } + get #isSystemManaged(): boolean { return !!this.entity?.systemManaged; } get #addToDictionaryActionControl() { - return { value: !!this.entity?.addToDictionaryAction, disabled: this.#isSystemManaged }; + return { value: !!this.entity?.addToDictionaryAction, disabled: this.#isSystemManaged && !this.#isDossierRedaction }; } get #isHint(): boolean { - return this.form.get('hint').value; + return !!this.form.get('hint')?.value; } revert(): void { @@ -71,7 +77,10 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit try { if (this.entity) { // edit mode - await firstValueFrom(this._dictionaryService.updateDictionary(dictionary, this.dossierTemplateId, dictionary.type)); + console.log({ dossierId: this.dossierId }); + await firstValueFrom( + this._dictionaryService.updateDictionary(dictionary, this.dossierTemplateId, dictionary.type, this.dossierId), + ); this._toaster.success(_('add-edit-entity.success.edit')); } else { // create mode @@ -114,20 +123,26 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit } private _initializeForm(): void { - const controlsConfig = { - type: [this.entity?.type], + let controlsConfig: Record = { label: [this.entity?.label, [Validators.required, Validators.minLength(3)]], - description: [this.entity?.description], - rank: [{ value: this.entity?.rank, disabled: this.#isSystemManaged }, Validators.required], hexColor: [this.entity?.hexColor, [Validators.required, Validators.minLength(7)]], recommendationHexColor: [this.entity?.recommendationHexColor, [Validators.required, Validators.minLength(7)]], skippedHexColor: [this.entity?.skippedHexColor, [Validators.required, Validators.minLength(7)]], - hint: [{ value: !!this.entity?.hint, disabled: this.#isSystemManaged }], - hasDictionary: [{ value: !!this.entity?.hasDictionary, disabled: this.#isSystemManaged }], - caseSensitive: [{ value: this.entity ? !this.entity.caseInsensitive : false, disabled: this.#isSystemManaged }], }; - if (!this.entity?.hint) { + if (!this.#isDossierRedaction) { + controlsConfig = { + ...controlsConfig, + type: [this.entity?.type], + description: [this.entity?.description], + rank: [{ value: this.entity?.rank, disabled: this.#isSystemManaged }, Validators.required], + hint: [{ value: !!this.entity?.hint, disabled: this.#isSystemManaged }], + hasDictionary: [{ value: !!this.entity?.hasDictionary, disabled: this.#isSystemManaged }], + caseSensitive: [{ value: this.entity ? !this.entity.caseInsensitive : false, disabled: this.#isSystemManaged }], + }; + } + + if (!this.entity?.hint && !this.#isDossierRedaction) { Object.assign(controlsConfig, { defaultReason: [{ value: null, disabled: true }], }); @@ -144,29 +159,31 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit this.#initializeColors(form); this.technicalName$ = form.get('label').valueChanges.pipe(map((value: string) => this._toTechnicalName(value))); - form.get('hint').valueChanges.subscribe(isHint => { - if (isHint) { - REDACTION_FIELDS.forEach(field => form.removeControl(field)); - } else { - form.addControl('defaultReason', new UntypedFormControl({ value: null, disabled: true })); - } - }); - - form.get('hasDictionary').valueChanges.subscribe(hasDictionary => { - if (hasDictionary) { - form.addControl('addToDictionaryAction', new UntypedFormControl(this.#addToDictionaryActionControl)); - } else { - form.removeControl('addToDictionaryAction'); - } - }); - - if (!this.entity) { - form.get('label').valueChanges.subscribe((label: string) => { - form.get('type').setValue(this._toTechnicalName(label)); + if (!this.#isDossierRedaction) { + form.get('hint').valueChanges.subscribe(isHint => { + if (isHint) { + REDACTION_FIELDS.forEach(field => form.removeControl(field)); + } else { + form.addControl('defaultReason', new UntypedFormControl({ value: null, disabled: true })); + } }); + + form.get('hasDictionary').valueChanges.subscribe(hasDictionary => { + if (hasDictionary) { + form.addControl('addToDictionaryAction', new UntypedFormControl(this.#addToDictionaryActionControl)); + } else { + form.removeControl('addToDictionaryAction'); + } + }); + + if (!this.entity) { + form.get('label').valueChanges.subscribe((label: string) => { + form.get('type').setValue(this._toTechnicalName(label)); + }); + } } - if (!this._permissionsService.canEditEntities()) { + if (this.readOnly) { form.disable(); } @@ -198,19 +215,28 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit const addToDictionaryAction = !!this.form.get('addToDictionaryAction')?.value; const hasDictionary = !!this.form.get('hasDictionary')?.value; - return { - type: this.form.get('type').value, + let entity = { + ...this.entity, label: this.form.get('label').value, - description: this.form.get('description').value, hexColor: this.form.get('hexColor').value, recommendationHexColor: this.form.get('recommendationHexColor').value, skippedHexColor: this.form.get('skippedHexColor').value, - hint: this.#isHint, - rank: this.form.get('rank').value, dossierTemplateId: this.dossierTemplateId, - caseInsensitive: !this.form.get('caseSensitive').value, addToDictionaryAction, - hasDictionary, }; + + if (this.entity.type !== 'dossier_redaction') { + entity = { + ...entity, + type: this.form.get('type').value, + description: this.form.get('description').value, + hint: this.#isHint, + rank: this.form.get('rank').value, + caseInsensitive: !this.form.get('caseSensitive').value, + hasDictionary, + }; + } + + return entity; } } diff --git a/apps/red-ui/src/app/modules/shared/shared.module.ts b/apps/red-ui/src/app/modules/shared/shared.module.ts index 2107a41bc..beba57d71 100644 --- a/apps/red-ui/src/app/modules/shared/shared.module.ts +++ b/apps/red-ui/src/app/modules/shared/shared.module.ts @@ -36,6 +36,8 @@ import { RouterModule } from '@angular/router'; import { AddDossierDialogComponent } from '@shared/dialogs/add-dossier-dialog/add-dossier-dialog.component'; import { SharedDialogService } from '@shared/services/dialog.service'; import { DossierWatermarkSelectorComponent } from '@components/dossier-watermark-selector/dossier-watermark-selector.component'; +import { AddEditEntityComponent } from '@shared/components/add-edit-entity/add-edit-entity.component'; +import { ColorPickerModule } from 'ngx-color-picker'; const buttons = [FileDownloadBtnComponent, UserButtonComponent]; @@ -59,6 +61,8 @@ const components = [ DossiersTypeSwitchComponent, AddDossierDialogComponent, DossierWatermarkSelectorComponent, + AddEditEntityComponent, + ...buttons, ]; @@ -66,7 +70,7 @@ const utils = [DatePipe, NamePipe, NavigateLastDossiersScreenDirective, LongPres const services = [SharedDialogService]; -const modules = [MatConfigModule, ScrollingModule, IconsModule, FormsModule, ReactiveFormsModule, CommonUiModule]; +const modules = [MatConfigModule, ScrollingModule, IconsModule, FormsModule, ReactiveFormsModule, CommonUiModule, ColorPickerModule]; @NgModule({ declarations: [...components, ...utils, EditorComponent], diff --git a/apps/red-ui/src/app/services/entity-services/dictionary.service.ts b/apps/red-ui/src/app/services/entity-services/dictionary.service.ts index 9421115f1..e32c06b02 100644 --- a/apps/red-ui/src/app/services/entity-services/dictionary.service.ts +++ b/apps/red-ui/src/app/services/entity-services/dictionary.service.ts @@ -1,6 +1,6 @@ import { Injectable, Injector } from '@angular/core'; import { firstValueFrom, forkJoin, Observable, of, throwError } from 'rxjs'; -import { EntitiesService, List, log, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui'; +import { EntitiesService, List, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui'; import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, IColors, IDictionary, IUpdateDictionary } from '@red/domain'; import { catchError, map, switchMap, tap } from 'rxjs/operators'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; @@ -170,11 +170,10 @@ export class DictionaryService extends EntitiesService }, ), ); - } else { - this._toaster.error(_('dictionary-overview.error.entries-too-short')); - - return throwError('Entries too short'); } + this._toaster.error(_('dictionary-overview.error.entries-too-short')); + + return throwError('Entries too short'); } async getDictionariesOptions(dossierTemplateId: string, dossierId: string): Promise { diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index fceea66d7..c5285512f 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -221,11 +221,7 @@ export class PermissionsService { return dossier.isActive && this.isDossierMember(dossier); } - canEditDossierDictionaryDisplayName(dossier: Dossier): boolean { - return dossier.isActive && this.isOwner(dossier); - } - - canEditDossierDictionaryAddAction(dossier: Dossier): boolean { + canEditDossierDictionaryProperties(dossier: Dossier): boolean { return dossier.isActive && this.isOwner(dossier); } diff --git a/apps/red-ui/src/assets/i18n/de.json b/apps/red-ui/src/assets/i18n/de.json index 5382fc037..b4bdd2972 100644 --- a/apps/red-ui/src/assets/i18n/de.json +++ b/apps/red-ui/src/assets/i18n/de.json @@ -618,6 +618,13 @@ }, "dev-mode": "DEV", "dictionary": "Wörterbuch", + "dictionary-details": { + "actions": { + "cancel": "", + "save": "" + }, + "title": "" + }, "dictionary-overview": { "compare": { "compare": "Vergleichen", @@ -1061,16 +1068,13 @@ "change-successful": "Dossier wurde aktualisiert.", "delete-successful": "Dossier wurde gelöscht.", "dictionary": { - "add-to-dictionary-action": "", "display-name": { - "cancel": "Abbrechen", - "edit": "Anzeigenamen bearbeiten", "error": "Anzeigename des Wörterbuchs konnte nicht aktualisiert werden.", - "placeholder": "Anzeigenamen eingeben", - "save": "Anzeigenamen speichern", "success": "Anzeigename des Wörterbuchs erfolgreich aktualisiert." }, - "entries": "{length} {length, plural, one{entry} other{entries}}" + "edit": "", + "entries": "{length} {length, plural, one{entry} other{entries}}", + "info": "" }, "general-info": { "form": { diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index 720241ed3..a94eb7d76 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -618,6 +618,13 @@ }, "dev-mode": "DEV", "dictionary": "Dictionary", + "dictionary-details": { + "actions": { + "cancel": "Cancel", + "save": "Save" + }, + "title": "Edit Dossier Dictionary" + }, "dictionary-overview": { "compare": { "compare": "Compare", @@ -1061,16 +1068,13 @@ "change-successful": "Dossier {dossierName} was updated.", "delete-successful": "Dossier {dossierName} was deleted.", "dictionary": { - "add-to-dictionary-action": "Enable 'Add to dictionary'", "display-name": { - "cancel": "Cancel", - "edit": "Edit Display Name", "error": "Failed to update dictionary display name.", - "placeholder": "Enter Display Name", - "save": "Save Display Name", "success": "Successfully updated dictionary display name." }, - "entries": "{length} {length, plural, one{entry} other{entries}}" + "edit": "Edit", + "entries": "{length} {length, plural, one{entry} other{entries}}", + "info": "Info" }, "general-info": { "form": { diff --git a/libs/common-ui b/libs/common-ui index 17fc935e0..738c38cf5 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 17fc935e0815f0d151a2674e7b4c77886319da71 +Subproject commit 738c38cf5f13de9542facd84d8c70f9929b980e6