RED-5654: Add separate calls for delete and add dictionary entry operations.
This commit is contained in:
parent
261527439e
commit
d3d0500ccf
@ -2,8 +2,9 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component';
|
||||
import { DictionaryService } from '@services/entity-services/dictionary.service';
|
||||
import { getCurrentUser, getParam, IqserPermissionsService, List, LoadingService } from '@iqser/common-ui';
|
||||
import { BehaviorSubject, firstValueFrom } from 'rxjs';
|
||||
import { List, LoadingService } from '@iqser/common-ui';
|
||||
import { UserService } from '@users/user.service';
|
||||
import { BehaviorSubject, firstValueFrom, lastValueFrom } from 'rxjs';
|
||||
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 { ROLES } from '@users/roles';
|
||||
@ -47,7 +48,7 @@ export class DictionaryScreenComponent implements OnInit {
|
||||
|
||||
this._loadingService.start();
|
||||
try {
|
||||
await firstValueFrom(
|
||||
await lastValueFrom(
|
||||
this._dictionaryService.saveEntries(
|
||||
entries,
|
||||
this.initialEntries$.value,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { forkJoin, Observable, of, throwError } from 'rxjs';
|
||||
import { forkJoin, Observable, throwError, zip } from 'rxjs';
|
||||
import { EntitiesService, List, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui';
|
||||
import { Dictionary, DictionaryEntryType, DictionaryEntryTypes, IDictionary, IUpdateDictionary, SuperTypes } from '@red/domain';
|
||||
import { catchError, map, switchMap, tap } from 'rxjs/operators';
|
||||
@ -104,23 +104,21 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
|
||||
showToast = true,
|
||||
dictionaryEntryType = DictionaryEntryTypes.ENTRY,
|
||||
): Observable<unknown> {
|
||||
let entriesToAdd = [];
|
||||
entries.forEach(currentEntry => {
|
||||
entriesToAdd.push(currentEntry);
|
||||
});
|
||||
const entriesToAdd = entries.map(e => e.trim()).filter(e => !!e);
|
||||
const deletedEntries = initialEntries.filter(e => !entries.includes(e));
|
||||
console.log({ entriesToAdd, deletedEntries });
|
||||
// remove empty lines
|
||||
entriesToAdd = entriesToAdd.filter(e => e && e.trim().length > 0).map(e => e.trim());
|
||||
const invalidRowsExist = entriesToAdd.filter(e => e.length < MIN_WORD_LENGTH);
|
||||
if (invalidRowsExist.length === 0) {
|
||||
// can add at least 1 - block UI
|
||||
let obs: Observable<IDictionary>;
|
||||
if (entriesToAdd.length > 0) {
|
||||
obs = this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId);
|
||||
} else {
|
||||
obs = this._deleteEntries(initialEntries, dossierTemplateId, type, dictionaryEntryType, dossierId);
|
||||
const obs: Observable<IDictionary>[] = [];
|
||||
if (deletedEntries.length) {
|
||||
obs.push(this._deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId));
|
||||
}
|
||||
|
||||
return obs.pipe(
|
||||
if (entriesToAdd.filter(e => !initialEntries.includes(e)).length) {
|
||||
obs.push(this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId));
|
||||
}
|
||||
return zip(obs).pipe(
|
||||
switchMap(dictionary => this._dossierTemplateStatsService.getFor([dossierTemplateId]).pipe(map(() => dictionary))),
|
||||
tap({
|
||||
next: () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user