Compare dictionaries

This commit is contained in:
Adina Țeudan 2022-03-23 20:44:27 +02:00
parent be227454b7
commit ed84299160
7 changed files with 28 additions and 18 deletions

View File

@ -5,4 +5,5 @@
[filterByDossierTemplate]="true"
[initialEntries]="initialEntries$ | async"
[isLeavingPage]="isLeavingPage"
[type]="type"
></redaction-dictionary-manager>

View File

@ -2,7 +2,7 @@ import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component';
import { DictionaryService } from '@services/entity-services/dictionary.service';
import { LoadingService } from '@iqser/common-ui';
import { List, LoadingService } from '@iqser/common-ui';
import { UserService } from '@services/user.service';
import { BehaviorSubject, firstValueFrom } from 'rxjs';
import { DOSSIER_TEMPLATE_ID, ENTITY_TYPE } from '@utils/constants';
@ -16,9 +16,9 @@ export class DictionaryScreenComponent implements OnInit {
readonly currentUser = this._userService.currentUser;
initialEntries$ = new BehaviorSubject<string[]>([]);
isLeavingPage = false;
readonly type: DictionaryType;
readonly #dossierTemplateId: string;
readonly #entityType: string;
readonly #type: DictionaryType;
@ViewChild('dictionaryManager', { static: false })
private readonly _dictionaryManager: DictionaryManagerComponent;
@ViewChild('fileInput') private readonly _fileInput: ElementRef;
@ -31,7 +31,7 @@ export class DictionaryScreenComponent implements OnInit {
) {
this.#dossierTemplateId = _route.parent.snapshot.paramMap.get(DOSSIER_TEMPLATE_ID);
this.#entityType = _route.parent.snapshot.paramMap.get(ENTITY_TYPE);
this.#type = this._route.snapshot.routeConfig.path as DictionaryType;
this.type = this._route.snapshot.routeConfig.path as DictionaryType;
}
get changed() {
@ -55,7 +55,7 @@ export class DictionaryScreenComponent implements OnInit {
this.#entityType,
null,
true,
DICTIONARY_TO_ENTRY_TYPE_MAP[this.#type],
DICTIONARY_TO_ENTRY_TYPE_MAP[this.type],
),
);
await this._loadEntries();
@ -68,7 +68,7 @@ export class DictionaryScreenComponent implements OnInit {
this._loadingService.start();
try {
const data = await firstValueFrom(this._dictionaryService.getForType(this.#dossierTemplateId, this.#entityType));
const entries: string[] = data[DICTIONARY_TYPE_KEY_MAP[this.#type]];
const entries: List = data[DICTIONARY_TYPE_KEY_MAP[this.type]];
this.initialEntries$.next([...entries].sort((str1, str2) => str1.localeCompare(str2, undefined, { sensitivity: 'accent' })));
this._loadingService.stop();
} catch (e) {

View File

@ -85,6 +85,7 @@ export class EditDossierDictionaryComponent implements EditDossierSectionInterfa
const dictionary: IDictionary = {
...this.dossierDictionary,
type: 'dossier_redaction',
hasDictionary: true,
addToDictionaryAction: this.form.get('addToDictionaryAction').value,
};
await firstValueFrom(

View File

@ -2,7 +2,7 @@ import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output, S
import { Debounce, IconButtonTypes, List, LoadingService } from '@iqser/common-ui';
import { firstValueFrom, Observable, of } from 'rxjs';
import { catchError, map, take, tap } from 'rxjs/operators';
import { Dictionary, Dossier, DossierTemplate } from '@red/domain';
import { Dictionary, DICTIONARY_TYPE_KEY_MAP, DictionaryType, Dossier, DossierTemplate } from '@red/domain';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { DictionaryService } from '@services/entity-services/dictionary.service';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
@ -22,6 +22,7 @@ const SMOOTH_SCROLL = 0;
export class DictionaryManagerComponent implements OnChanges {
readonly iconButtonTypes = IconButtonTypes;
@Input() type: DictionaryType = 'dictionary';
@Input() withFloatingActions = true;
@Input() filterByDossierTemplate = false;
@Input() initialEntries: List;
@ -96,6 +97,7 @@ export class DictionaryManagerComponent implements OnChanges {
}
set compareDictionary(dictionary: Dictionary) {
this._loadingService.start();
this._compareDictionary = dictionary;
if (dictionary.label === this.selectDictionary.label) {
@ -104,8 +106,8 @@ export class DictionaryManagerComponent implements OnChanges {
return;
}
const entries: List =
this._compareDictionary.entries ??
this._dictionariesMapService.get(this._compareDictionary.dossierTemplateId, this._compareDictionary.type).entries;
this._compareDictionary.getEntries(this.type) ??
this._dictionariesMapService.get(this._compareDictionary.dossierTemplateId, this._compareDictionary.type).getEntries(this.type);
if (entries.length) {
this.diffEditorText = this._toString([...entries]);
@ -113,17 +115,18 @@ export class DictionaryManagerComponent implements OnChanges {
return;
}
this._loadingService.start();
firstValueFrom(
this._dictionaryService.getForType(this._compareDictionary.dossierTemplateId, this._compareDictionary.type).pipe(
tap(values => (this._compareDictionary.entries = [...values.entries] ?? [])),
tap(values => {
this._compareDictionary.setEntries([...values[DICTIONARY_TYPE_KEY_MAP[this.type]]] ?? [], this.type);
}),
catchError(() => {
this._compareDictionary.entries = [];
this._compareDictionary.setEntries([], this.type);
return of({});
}),
),
).then(() => {
this.diffEditorText = this._toString([...this._compareDictionary.entries]);
this.diffEditorText = this._toString([...(this._compareDictionary.getEntries(this.type) as string[])]);
this.showDiffEditor = true;
this._changeRef.markForCheck();
this._loadingService.stop();
@ -213,7 +216,6 @@ export class DictionaryManagerComponent implements OnChanges {
private _onDossierChanged(dossierTemplateId: string, dossierId?: string, type = 'dossier_redaction'): Observable<string> {
const dictionary$ = this._dictionaryService.getForType(dossierTemplateId, type, dossierId);
return dictionary$.pipe(map(data => this._toString([...data.entries])));
}

View File

@ -32,7 +32,7 @@ export class DictionaryService extends EntitiesService<Dictionary, IDictionary>
* Retrieves all dictionary entries of an entry type
*/
@Validate()
getForType(@RequiredParam() dossierTemplateId: string, @RequiredParam() type: string, dossierId?: string) {
getForType(@RequiredParam() dossierTemplateId: string, @RequiredParam() type: string, dossierId?: string): Observable<IDictionary> {
const queryParams = dossierId ? [{ key: 'dossierId', value: dossierId }] : undefined;
return this._getOne([type, dossierTemplateId], this._defaultModelPath, queryParams);
}

View File

@ -1,5 +1,6 @@
import { Entity, List } from '@iqser/common-ui';
import { IDictionary } from './dictionary';
import { DICTIONARY_TYPE_KEY_MAP, DictionaryType } from '../redaction-log';
export class Dictionary extends Entity<IDictionary> implements IDictionary {
readonly addToDictionaryAction: boolean;
@ -51,4 +52,12 @@ export class Dictionary extends Entity<IDictionary> implements IDictionary {
get routerLink(): string {
return `/main/admin/dossier-templates/${this.dossierTemplateId}/entities/${this.type}`;
}
setEntries(entries: List, type: DictionaryType): void {
this[DICTIONARY_TYPE_KEY_MAP[type]] = entries;
}
getEntries(type: DictionaryType): List {
return this[DICTIONARY_TYPE_KEY_MAP[type]];
}
}

View File

@ -1,6 +1,3 @@
import { KeysOf } from '@iqser/common-ui';
import { Dictionary } from '../dictionaries';
export type DictionaryEntryType = 'ENTRY' | 'FALSE_POSITIVE' | 'FALSE_RECOMMENDATION';
export const DictionaryEntryTypes = {
@ -11,7 +8,7 @@ export const DictionaryEntryTypes = {
export type DictionaryType = 'dictionary' | 'false-positive' | 'false-recommendations';
export const DICTIONARY_TYPE_KEY_MAP: { [key in DictionaryType]: KeysOf<Dictionary> } = {
export const DICTIONARY_TYPE_KEY_MAP: { [key in DictionaryType]: 'entries' | 'falsePositiveEntries' | 'falseRecommendationEntries' } = {
dictionary: 'entries',
'false-positive': 'falsePositiveEntries',
'false-recommendations': 'falseRecommendationEntries',