RED-6786: update editor
This commit is contained in:
parent
0c4a705e52
commit
e2bf87d147
@ -3,7 +3,7 @@ import { ActivatedRoute } from '@angular/router';
|
|||||||
import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component';
|
import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component';
|
||||||
import { DictionaryService } from '@services/entity-services/dictionary.service';
|
import { DictionaryService } from '@services/entity-services/dictionary.service';
|
||||||
import { getCurrentUser, getParam, IqserPermissionsService, List, LoadingService } from '@iqser/common-ui';
|
import { getCurrentUser, getParam, IqserPermissionsService, List, LoadingService } from '@iqser/common-ui';
|
||||||
import { BehaviorSubject, firstValueFrom, lastValueFrom } from 'rxjs';
|
import { BehaviorSubject, firstValueFrom } from 'rxjs';
|
||||||
import { DICTIONARY_TO_ENTRY_TYPE_MAP, DICTIONARY_TYPE_KEY_MAP, DictionaryType, DOSSIER_TEMPLATE_ID, ENTITY_TYPE, User } from '@red/domain';
|
import { DICTIONARY_TO_ENTRY_TYPE_MAP, DICTIONARY_TYPE_KEY_MAP, DictionaryType, DOSSIER_TEMPLATE_ID, ENTITY_TYPE, User } from '@red/domain';
|
||||||
import { PermissionsService } from '@services/permissions.service';
|
import { PermissionsService } from '@services/permissions.service';
|
||||||
import { ROLES } from '@users/roles';
|
import { ROLES } from '@users/roles';
|
||||||
@ -47,16 +47,14 @@ export class DictionaryScreenComponent implements OnInit {
|
|||||||
|
|
||||||
this._loadingService.start();
|
this._loadingService.start();
|
||||||
try {
|
try {
|
||||||
await lastValueFrom(
|
await this._dictionaryService.saveEntries(
|
||||||
this._dictionaryService.saveEntries(
|
entries,
|
||||||
entries,
|
this.initialEntries$.value,
|
||||||
this.initialEntries$.value,
|
this.#dossierTemplateId,
|
||||||
this.#dossierTemplateId,
|
this.entityType,
|
||||||
this.entityType,
|
null,
|
||||||
null,
|
true,
|
||||||
true,
|
DICTIONARY_TO_ENTRY_TYPE_MAP[this.type],
|
||||||
DICTIONARY_TO_ENTRY_TYPE_MAP[this.type],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
await this._loadEntries();
|
await this._loadEntries();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -50,17 +50,14 @@ export class EditDossierDictionaryComponent implements EditDossierSectionInterfa
|
|||||||
|
|
||||||
async save(): EditDossierSaveResult {
|
async save(): EditDossierSaveResult {
|
||||||
try {
|
try {
|
||||||
await firstValueFrom(
|
await this._dictionaryService.saveEntries(
|
||||||
this._dictionaryService.saveEntries(
|
this._dictionaryManager.editor.currentEntries,
|
||||||
this._dictionaryManager.editor.currentEntries,
|
this._dictionaryManager.initialEntries,
|
||||||
this._dictionaryManager.initialEntries,
|
this.dossier.dossierTemplateId,
|
||||||
this.dossier.dossierTemplateId,
|
this.dossierDictionary.type,
|
||||||
this.dossierDictionary.type,
|
this.dossier.id,
|
||||||
this.dossier.id,
|
false,
|
||||||
false,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await this._updateDossierDictionary();
|
await this._updateDossierDictionary();
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -92,7 +92,6 @@ export class DictionaryManagerComponent implements OnChanges {
|
|||||||
|
|
||||||
this._onDossierChanged(dossier.dossierTemplateId, dossier.id)
|
this._onDossierChanged(dossier.dossierTemplateId, dossier.id)
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
// eslint-disable-next-line rxjs/no-ignored-subscription
|
|
||||||
.subscribe(entries => {
|
.subscribe(entries => {
|
||||||
this.diffEditorText = entries;
|
this.diffEditorText = entries;
|
||||||
this.showDiffEditor = true;
|
this.showDiffEditor = true;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { forkJoin, Observable, of, throwError, zip } from 'rxjs';
|
import { firstValueFrom, forkJoin, Observable, of, throwError } from 'rxjs';
|
||||||
import { EntitiesService, List, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui';
|
import { EntitiesService, List, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui';
|
||||||
import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, IDictionary, IUpdateDictionary, SuperTypes } from '@red/domain';
|
import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, IDictionary, IUpdateDictionary, SuperTypes } from '@red/domain';
|
||||||
import { catchError, map, switchMap, tap } from 'rxjs/operators';
|
import { catchError, map, switchMap, tap } from 'rxjs/operators';
|
||||||
@ -95,7 +95,7 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveEntries(
|
async saveEntries(
|
||||||
entries: List,
|
entries: List,
|
||||||
initialEntries: List,
|
initialEntries: List,
|
||||||
dossierTemplateId: string,
|
dossierTemplateId: string,
|
||||||
@ -103,42 +103,50 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
|
|||||||
dossierId: string,
|
dossierId: string,
|
||||||
showToast = true,
|
showToast = true,
|
||||||
dictionaryEntryType = DictionaryEntryTypes.ENTRY,
|
dictionaryEntryType = DictionaryEntryTypes.ENTRY,
|
||||||
): Observable<unknown> {
|
): Promise<unknown> {
|
||||||
const entriesToAdd = entries.map(e => e.trim()).filter(e => !!e);
|
const entriesToAdd: Array<string> = [];
|
||||||
const deletedEntries = initialEntries.filter(e => !entries.includes(e));
|
const deletedEntries: Array<string> = [];
|
||||||
console.log({ entriesToAdd, deletedEntries });
|
for (let i = 0; i < entries.length; i++) {
|
||||||
|
if (!entries.at(i).trim()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entriesToAdd.push(entries.at(i));
|
||||||
|
}
|
||||||
|
for (let i = 0; i < initialEntries.length; i++) {
|
||||||
|
if (entries.includes(initialEntries.at(i))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
deletedEntries.push(initialEntries.at(i));
|
||||||
|
}
|
||||||
// remove empty lines
|
// remove empty lines
|
||||||
const invalidRowsExist = entriesToAdd.filter(e => e.length < MIN_WORD_LENGTH);
|
const invalidRowsExist = entriesToAdd.filter(e => e.length < MIN_WORD_LENGTH);
|
||||||
if (invalidRowsExist.length === 0) {
|
if (invalidRowsExist.length === 0) {
|
||||||
// can add at least 1 - block UI
|
// can add at least 1 - block UI
|
||||||
const obs: Observable<IDictionary>[] = [];
|
const promises: Promise<IDictionary>[] = [];
|
||||||
if (deletedEntries.length) {
|
if (deletedEntries.length) {
|
||||||
obs.push(this._deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId));
|
promises.push(firstValueFrom(this._deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId)));
|
||||||
}
|
}
|
||||||
if (entriesToAdd.filter(e => !initialEntries.includes(e)).length) {
|
if (entriesToAdd.filter(e => !initialEntries.includes(e)).length) {
|
||||||
obs.push(this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId));
|
promises.push(firstValueFrom(this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId)));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await Promise.all(promises);
|
||||||
|
if (showToast) {
|
||||||
|
this._toaster.success(_('dictionary-overview.success.generic'));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
if ((error as HttpErrorResponse).status === 400) {
|
||||||
|
this._toaster.error(_('dictionary-overview.error.400'));
|
||||||
|
} else {
|
||||||
|
this._toaster.error(_('dictionary-overview.error.generic'));
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return zip(obs).pipe(
|
|
||||||
switchMap(dictionary => this._dossierTemplateStatsService.getFor([dossierTemplateId]).pipe(map(() => dictionary))),
|
|
||||||
tap({
|
|
||||||
next: () => {
|
|
||||||
if (showToast) {
|
|
||||||
this._toaster.success(_('dictionary-overview.success.generic'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: error => {
|
|
||||||
if (error.status === 400) {
|
|
||||||
this._toaster.error(_('dictionary-overview.error.400'));
|
|
||||||
} else {
|
|
||||||
this._toaster.error(_('dictionary-overview.error.generic'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
this._toaster.error(_('dictionary-overview.error.entries-too-short'));
|
this._toaster.error(_('dictionary-overview.error.entries-too-short'));
|
||||||
|
|
||||||
return throwError(() => 'Entries too short');
|
throw new Error('Entries too short');
|
||||||
}
|
}
|
||||||
|
|
||||||
hasManualType(dossierTemplateId: string): boolean {
|
hasManualType(dossierTemplateId: string): boolean {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user