Pull request #388: RED-5654

Merge in RED/ui from RED-5654 to master

* commit '2ba808e95b295a8eadc1b6c7db12614097a62831':
  RED-5654: Add missing import statement.
  RED-5654: Add separate calls for delete and add dictionary entry operations.
This commit is contained in:
George Balanesc 2022-12-05 11:23:37 +01:00 committed by Dan Percic
commit cf384ccdcc
2 changed files with 13 additions and 15 deletions

View File

@ -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 } from 'rxjs'; 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 { 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,7 +47,7 @@ export class DictionaryScreenComponent implements OnInit {
this._loadingService.start(); this._loadingService.start();
try { try {
await firstValueFrom( await lastValueFrom(
this._dictionaryService.saveEntries( this._dictionaryService.saveEntries(
entries, entries,
this.initialEntries$.value, this.initialEntries$.value,

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { forkJoin, Observable, of, throwError } from 'rxjs'; import { forkJoin, Observable, of, throwError, zip } 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';
@ -104,23 +104,21 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
showToast = true, showToast = true,
dictionaryEntryType = DictionaryEntryTypes.ENTRY, dictionaryEntryType = DictionaryEntryTypes.ENTRY,
): Observable<unknown> { ): Observable<unknown> {
let entriesToAdd = []; const entriesToAdd = entries.map(e => e.trim()).filter(e => !!e);
entries.forEach(currentEntry => { const deletedEntries = initialEntries.filter(e => !entries.includes(e));
entriesToAdd.push(currentEntry); console.log({ entriesToAdd, deletedEntries });
});
// remove empty lines // 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); 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
let obs: Observable<IDictionary>; const obs: Observable<IDictionary>[] = [];
if (entriesToAdd.length > 0) { if (deletedEntries.length) {
obs = this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId); obs.push(this._deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId));
} else {
obs = this._deleteEntries(initialEntries, dossierTemplateId, type, dictionaryEntryType, dossierId);
} }
if (entriesToAdd.filter(e => !initialEntries.includes(e)).length) {
return obs.pipe( obs.push(this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId));
}
return zip(obs).pipe(
switchMap(dictionary => this._dossierTemplateStatsService.getFor([dossierTemplateId]).pipe(map(() => dictionary))), switchMap(dictionary => this._dossierTemplateStatsService.getFor([dossierTemplateId]).pipe(map(() => dictionary))),
tap({ tap({
next: () => { next: () => {