From 82e31fffd8c6e8bb9da6a5b2a382f5f1e5d92271 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Fri, 8 Nov 2024 13:27:37 +0200 Subject: [PATCH 1/2] RED-10332 - Dossier Template not changeable when comparing dossier dictionaries in Edit dossier modal --- .../dictionary-manager.component.html | 144 +++++++++--------- 1 file changed, 76 insertions(+), 68 deletions(-) diff --git a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html index c1429100c..e41b354f0 100644 --- a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html +++ b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html @@ -29,63 +29,67 @@ -
- - - - - {{ dossierTemplate.id ? dossierTemplate.name : (dossierTemplate.name | translate) }} - - - - -
+ @if (dossierTemplates) { +
+ + + @for (dossierTemplate of dossierTemplates; track dossierTemplate) { + @if (!initialDossierTemplateId || dossierTemplate?.id !== selectedDossierTemplate.id) { + + {{ dossierTemplate.id ? dossierTemplate.name : (dossierTemplate.name | translate) }} + + } + } + + +
+ }
- - - - - {{ dossier.dossierName }} - - - - - + @if (initialDossierTemplateId) { + + + @for (dossier of dossiers; track dossier; let index = $index) { + @if (dossier.dossierId !== selectedDossier.dossierId) { + + {{ dossier.dossierName }} + + @if (index === dossiers.length - 2 && !selectedDossier.dossierId?.includes('template')) { + + } + } + } + + + } - - - - - {{ dictionary.id ? dictionary.label : (dictionary.label | translate) }} - - - - + @if (!initialDossierTemplateId) { + + + @for (dictionary of dictionaries; track dictionary; let index = $index) { + + {{ dictionary.id ? dictionary.label : (dictionary.label | translate) }} + + } + + + }
@@ -100,20 +104,24 @@ [showDiffEditor]="compare && showDiffEditor" > -
- - -
+ @if (compare && optionNotSelected) { +
+ + +
+ } -
- -
-
+ @if (withFloatingActions && !!editor?.hasChanges && canEdit && !isLeavingPage) { +
+ +
+
+ } From f0b6cf971234fb352c26330dfaa2cfcf5c2f9367 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Fri, 8 Nov 2024 17:06:29 +0200 Subject: [PATCH 2/2] WIP on VM/RED-10332 RED-10332 - Dossier Template not changeable when comparing dossier dictionaries in Edit dossier modal --- .../edit-dossier-dictionary.component.html | 2 +- .../edit-dossier-dictionary.component.ts | 2 +- .../file-download-btn.component.ts | 4 +- .../dictionary-manager.component.html | 24 +++-- .../dictionary-manager.component.ts | 99 ++++++++++--------- 5 files changed, 73 insertions(+), 58 deletions(-) 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 7adbcaea3..7f29746f6 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 @@ -54,8 +54,8 @@ [currentDossierTemplateId]="dossier.dossierTemplateId" [hint]="selectedDictionary.hint" [initialEntries]="entriesToDisplay || []" - [selectedDictionaryTypeLabel]="selectedDictionary.label" [selectedDictionaryType]="selectedDictionary.type" + [activeDictionary]="selectedDictionary" [withFloatingActions]="false" > 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 28d5e725f..716d29aca 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 @@ -83,7 +83,7 @@ export class EditDossierDictionaryComponent implements OnInit { try { await this._dictionaryService.saveEntries( this._dictionaryManager.editor.currentEntries, - this._dictionaryManager.initialEntries, + this._dictionaryManager.initialEntries(), this.dossier.dossierTemplateId, this.selectedDictionary.type, this.dossier.id, diff --git a/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts b/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts index 83b6089e4..1107af8b2 100644 --- a/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts @@ -24,8 +24,8 @@ export class FileDownloadBtnComponent implements OnChanges { readonly tooltipPosition = input<'above' | 'below' | 'before' | 'after'>('above'); readonly type = input(CircleButtonTypes.default); readonly tooltipClass = input(); - readonly disabled = input(false); - readonly singleFileDownload = input(false); + readonly disabled = input(false, { transform: booleanAttribute }); + readonly singleFileDownload = input(false, { transform: booleanAttribute }); readonly dossierDownload = input(false, { transform: booleanAttribute }); readonly dropdownButton = computed(() => this.isDocumine && (this.dossierDownload() || this.singleFileDownload())); tooltip: string; diff --git a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html index e41b354f0..a7794e65d 100644 --- a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html +++ b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html @@ -5,7 +5,7 @@ @for (dossier of dossiers; track dossier; let index = $index) { @if (dossier.dossierId !== selectedDossier.dossierId) { - - {{ dossier.dossierName }} - - @if (index === dossiers.length - 2 && !selectedDossier.dossierId?.includes('template')) { - + @if (!activeDictionary().dossierDictionaryOnly) { + + {{ dossier.dossierName }} + + @if (index === dossiers.length - 2 && !selectedDossier.dossierId?.includes('template')) { + + } + } @else if (!dossier.dossierId?.includes('template')) { + + {{ dossier.dossierName }} + } } } @@ -98,9 +104,9 @@
@@ -112,7 +118,7 @@ }
- @if (withFloatingActions && !!editor?.hasChanges && canEdit && !isLeavingPage) { + @if (withFloatingActions() && !!editor?.hasChanges && canEdit() && !isLeavingPage()) {
(); +export class DictionaryManagerComponent implements OnInit { + readonly type = input('dictionary'); + readonly entityType = input(); + readonly currentDossierId = input(); + readonly currentDossierTemplateId = model(); + readonly withFloatingActions = input(true, { transform: booleanAttribute }); + readonly initialEntries = input.required(); + readonly canEdit = input(false, { transform: booleanAttribute }); + readonly canDownload = input(false, { transform: booleanAttribute }); + readonly isLeavingPage = input(false, { transform: booleanAttribute }); + readonly hint = input(false, { transform: booleanAttribute }); + readonly activeDictionary = input(); + readonly selectedDictionaryType = model('dossier_redaction'); + readonly activeEntryType = input(DictionaryEntryTypes.ENTRY); + readonly saveDictionary = output(); @ViewChild(EditorComponent) readonly editor: EditorComponent; readonly iconButtonTypes = IconButtonTypes; dossiers: Dossier[]; @@ -102,7 +107,24 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { private readonly _changeRef: ChangeDetectorRef, private readonly _dossierTemplatesService: DossierTemplatesService, protected readonly _loadingService: LoadingService, - ) {} + ) { + effect(() => { + if (this.activeEntryType() && this.#dossier?.dossierTemplateId && this.selectedDossier?.dossierId) { + this.#onDossierChanged(this.#dossier.dossierTemplateId, this.#dossier.dossierId).then(entries => + this.#updateDiffEditorText(entries), + ); + } + }); + effect( + () => { + if (this.selectedDictionaryType()) { + this.#disableDiffEditor(); + this.#updateDropdownsOptions(); + } + }, + { allowSignalWrites: true }, + ); + } get selectedDossierTemplate() { return this.#dossierTemplate; @@ -115,12 +137,12 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { : this.selectDossierTemplate; } this.#dossierTemplate = value; - this.currentDossierTemplateId = value.dossierTemplateId; + this.currentDossierTemplateId.set(value.dossierTemplateId); this.#dossier = this.selectDossier; this.dictionaries = this.#dictionaries; this.#disableDiffEditor(); - if (!this.initialDossierTemplateId && !this.currentDossierId) { + if (!this.initialDossierTemplateId && !this.currentDossierId()) { this.selectedDictionary = this.selectDictionary; } @@ -148,7 +170,7 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { set selectedDictionary(dictionary: Dictionary) { if (dictionary.type) { - this.selectedDictionaryType = dictionary.type; + this.selectedDictionaryType.set(dictionary.type); this.#dictionary = dictionary; this.#onDossierChanged(this.#dossier.dossierTemplateId).then(entries => this.#updateDiffEditorText(entries)); } @@ -181,7 +203,7 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { get #templatesWithCurrentEntityType() { return this._dossierTemplatesService.all.filter(t => - this._dictionaryService.hasType(t.dossierTemplateId, this.selectedDictionaryType), + this._dictionaryService.hasType(t.dossierTemplateId, this.selectedDictionaryType()), ); } @@ -190,7 +212,7 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { this.dossierTemplates = this._dossierTemplatesService.all; await firstValueFrom(this._dictionaryService.loadDictionaryDataForDossierTemplates(this.dossierTemplates.map(t => t.id))); this.#dossierTemplate = this._dossierTemplatesService.all[0]; - this.initialDossierTemplateId = this.currentDossierTemplateId; + this.initialDossierTemplateId = this.currentDossierTemplateId(); this.#updateDropdownsOptions(); } @@ -199,7 +221,7 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { const blob = new Blob([content], { type: 'text/plain;charset=utf-8', }); - saveAs(blob, `${this.entityType}-${this.type}.txt`); + saveAs(blob, `${this.entityType()}-${this.type()}.txt`); } revert() { @@ -213,43 +235,30 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { } } - ngOnChanges(changes: SimpleChanges): void { - if (changes.activeEntryType && this.#dossier?.dossierTemplateId && this.selectedDossier?.dossierId) { - this.#onDossierChanged(this.#dossier.dossierTemplateId, this.#dossier.dossierId).then(entries => - this.#updateDiffEditorText(entries), - ); - } - - if (changes.selectedDictionaryType) { - this.#disableDiffEditor(); - this.#updateDropdownsOptions(); - } - } - async #onDossierChanged(dossierTemplateId: string, dossierId?: string) { let dictionary: IDictionary; if (dossierId === 'template') { - dictionary = await this._dictionaryService.getForType(dossierTemplateId, this.selectedDictionaryType); + dictionary = await this._dictionaryService.getForType(dossierTemplateId, this.selectedDictionaryType()); } else { if (dossierId) { dictionary = ( await firstValueFrom( - this._dictionaryService.loadDictionaryEntriesByType([this.selectedDictionaryType], dossierTemplateId, dossierId), + this._dictionaryService.loadDictionaryEntriesByType([this.selectedDictionaryType()], dossierTemplateId, dossierId), ).catch(() => { return [{ entries: [COMPARE_ENTRIES_ERROR], type: '' }]; }) )[0]; } else { - dictionary = this.selectedDictionaryType - ? await this._dictionaryService.getForType(this.currentDossierTemplateId, this.selectedDictionaryType) + dictionary = this.selectedDictionaryType() + ? await this._dictionaryService.getForType(this.currentDossierTemplateId(), this.selectedDictionaryType()) : { entries: [COMPARE_ENTRIES_ERROR], type: '' }; } } const activeEntries = - this.activeEntryType === DictionaryEntryTypes.ENTRY || this.hint + this.activeEntryType() === DictionaryEntryTypes.ENTRY || this.hint() ? [...dictionary.entries] - : this.activeEntryType === DictionaryEntryTypes.FALSE_POSITIVE + : this.activeEntryType() === DictionaryEntryTypes.FALSE_POSITIVE ? [...dictionary.falsePositiveEntries] : [...dictionary.falseRecommendationEntries]; return activeEntries.join('\n'); @@ -257,23 +266,23 @@ export class DictionaryManagerComponent implements OnChanges, OnInit { #updateDropdownsOptions(updateSelectedDossierTemplate = true) { if (updateSelectedDossierTemplate) { - this.currentDossierTemplateId = this.initialDossierTemplateId ?? this.currentDossierTemplateId; + this.currentDossierTemplateId.set(this.initialDossierTemplateId ?? this.currentDossierTemplateId()); this.dossierTemplates = this.currentDossierTemplateId ? this.#templatesWithCurrentEntityType : this._dossierTemplatesService.all; if (!this.currentDossierTemplateId) { this.dossierTemplates = [this.selectDossierTemplate, ...this.dossierTemplates]; } - this.selectedDossierTemplate = this.dossierTemplates.find(t => t.id === this.currentDossierTemplateId); + this.selectedDossierTemplate = this.dossierTemplates.find(t => t.id === this.currentDossierTemplateId()); } this.dossiers = this._activeDossiersService.all.filter( - d => d.dossierTemplateId === this.currentDossierTemplateId && d.id !== this.currentDossierId, + d => d.dossierTemplateId === this.currentDossierTemplateId() && d.id !== this.currentDossierId(), ); const templateDictionary = { id: 'template', dossierId: 'template', dossierName: 'Template Dictionary', - dossierTemplateId: this.currentDossierTemplateId, + dossierTemplateId: this.currentDossierTemplateId(), } as Dossier; this.dossiers.push(templateDictionary); }