From c94d76f43537b40a11cf347a26e467ec114b1def Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Tue, 19 Oct 2021 15:33:06 +0300 Subject: [PATCH] fix RED-2481 --- .../dictionary-manager.component.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts index 6a322f016..1cec571f2 100644 --- a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.ts @@ -1,7 +1,7 @@ import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'; import { Debounce, IconButtonTypes, List } from '@iqser/common-ui'; -import { Observable } from 'rxjs'; -import { map, take } from 'rxjs/operators'; +import { Observable, of } from 'rxjs'; +import { catchError, map, take, tap } from 'rxjs/operators'; import { Dossier } from '@state/model/dossier'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DictionaryService } from '@shared/services/dictionary.service'; @@ -102,18 +102,37 @@ export class DictionaryManagerComponent implements OnChanges { this.diffEditorText = ''; return; } + const entries = + this._dictionary.entries ?? + this.appStateService.dictionaryData[this._dictionary.dossierTemplateId][this._dictionary.type].entries; - const entries = this.appStateService.dictionaryData[this._dictionary.dossierTemplateId][this._dictionary.type].entries; + if (entries.length) { + this.diffEditorText = this._toString(entries); + this.showDiffEditor = true; + return; + } - this.diffEditorText = this._toString(entries); - this.showDiffEditor = true; + this._dictionaryService + .getFor(this._dictionary.dossierTemplateId, this._dictionary.type) + .pipe( + tap(values => (this._dictionary.entries = [...values.entries] ?? [])), + catchError(() => { + this._dictionary.entries = []; + return of({}); + }), + ) + .toPromise() + .then(() => { + this.diffEditorText = this._toString(this._dictionary.entries); + this.showDiffEditor = true; + }); } get _dictionaries() { if (!this._dossierTemplate || this._dossierTemplate.name === this.selectDossierTemplate.name) { return; } - return Object.values(this.appStateService.dictionaryData[this.dossierTemplate?.dossierTemplateId]); + return Object.values(this.appStateService.dictionaryData[this.dossierTemplate?.dossierTemplateId]).filter(dict => !!dict.label); } get dossierTemplateIsNotSelected() {