fix RED-2481

This commit is contained in:
Dan Percic 2021-10-19 15:33:06 +03:00
parent 28787b01fa
commit c94d76f435

View File

@ -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() {