Removed app state service
This commit is contained in:
parent
638cb7060e
commit
76996afbf0
@ -1,10 +1,8 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { NavigationStart, Router } from '@angular/router';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { FileDownloadService } from '@upload-download/services/file-download.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { SpotlightSearchAction } from '@components/spotlight-search/spotlight-search-action';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
@ -34,13 +32,11 @@ export class BaseScreenComponent {
|
||||
name: _('top-bar.navigation-items.my-account.children.account'),
|
||||
routerLink: '/main/account',
|
||||
show: true,
|
||||
action: this.appStateService.reset,
|
||||
},
|
||||
{
|
||||
name: _('top-bar.navigation-items.my-account.children.admin'),
|
||||
routerLink: '/main/admin',
|
||||
show: this.currentUser.isManager || this.currentUser.isUserAdmin,
|
||||
action: this.appStateService.reset,
|
||||
},
|
||||
{
|
||||
name: _('top-bar.navigation-items.my-account.children.downloads'),
|
||||
@ -75,7 +71,6 @@ export class BaseScreenComponent {
|
||||
readonly isSearchScreen$ = this._navigationStart$.pipe(map(isSearchScreen));
|
||||
|
||||
constructor(
|
||||
readonly appStateService: AppStateService,
|
||||
readonly userService: UserService,
|
||||
readonly userPreferenceService: UserPreferenceService,
|
||||
readonly titleService: Title,
|
||||
|
||||
@ -24,7 +24,7 @@ export class FileDataModel {
|
||||
private readonly _file: File,
|
||||
private _redactionLog: IRedactionLog,
|
||||
public viewedPages?: IViewedPage[],
|
||||
private _dictionaryData?: { [p: string]: Dictionary },
|
||||
private _dictionaryData?: Dictionary[],
|
||||
private _areDevFeaturesEnabled?: boolean,
|
||||
) {
|
||||
this._buildAllAnnotations();
|
||||
@ -83,7 +83,8 @@ export class FileDataModel {
|
||||
// copy the redactionLog Entry
|
||||
|
||||
const changeLogValues = this.#getChangeLogValues(redactionLogEntry);
|
||||
if (!this._dictionaryData[redactionLogEntry.type]) {
|
||||
const dictionaryData = this._dictionaryData.find(dict => dict.type === redactionLogEntry.type);
|
||||
if (!dictionaryData) {
|
||||
this.missingTypes.add(redactionLogEntry.type);
|
||||
return;
|
||||
}
|
||||
@ -94,7 +95,7 @@ export class FileDataModel {
|
||||
changeLogValues.isChangeLogEntry,
|
||||
changeLogValues.hidden,
|
||||
this.redactionLog.legalBasis,
|
||||
!!this._dictionaryData[redactionLogEntry.type]?.hint,
|
||||
!!dictionaryData?.hint,
|
||||
);
|
||||
|
||||
if (
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Component, HostBinding, Input, OnInit } from '@angular/core';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { adminSideNavTranslations } from '../translations/admin-side-nav-translations';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
type Type = 'settings' | 'dossierTemplates';
|
||||
|
||||
@ -68,7 +68,7 @@ export class AdminSideNavComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private readonly _userService: UserService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _route: ActivatedRoute,
|
||||
readonly userPreferenceService: UserPreferenceService,
|
||||
) {}
|
||||
|
||||
@ -77,6 +77,6 @@ export class AdminSideNavComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.prefix = this._appStateService.activeDictionaryType ? '../../' : '../';
|
||||
this.prefix = this._route.snapshot.paramMap.get('dictionary') ? '../../' : '../';
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,23 +9,14 @@
|
||||
<mat-icon svgIcon="iqser:arrow-right"></mat-icon>
|
||||
|
||||
<ng-container *ngIf="dossierTemplate$ | async as dossierTemplate">
|
||||
<a [class.active]="!appStateService.activeDictionaryType" [routerLink]="dossierTemplate.routerLink" class="breadcrumb ml-0">
|
||||
<a [class.active]="(activeDictionary$ | async) === undefined" [routerLink]="dossierTemplate.routerLink" class="breadcrumb ml-0">
|
||||
{{ dossierTemplate.name }}
|
||||
</a>
|
||||
|
||||
<ng-container *ngIf="appStateService.activeDictionary">
|
||||
<ng-container *ngIf="activeDictionary$ | async as activeDictionary">
|
||||
<mat-icon svgIcon="iqser:arrow-right"></mat-icon>
|
||||
<a
|
||||
[routerLink]="
|
||||
'/main/admin/dossier-templates/' +
|
||||
dossierTemplate.dossierTemplateId +
|
||||
'/dictionaries/' +
|
||||
appStateService.activeDictionaryType
|
||||
"
|
||||
class="breadcrumb ml-0"
|
||||
routerLinkActive="active"
|
||||
>
|
||||
{{ appStateService.activeDictionary.label }}
|
||||
<a [routerLink]="activeDictionary.routerLink" class="breadcrumb ml-0" routerLinkActive="active">
|
||||
{{ activeDictionary.label }}
|
||||
</a>
|
||||
</ng-container>
|
||||
</ng-container>
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { PermissionsService } from '@services/permissions.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { DossierTemplate } from '@red/domain';
|
||||
import { Dictionary, DossierTemplate } from '@red/domain';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-dossier-template-breadcrumbs',
|
||||
@ -16,17 +16,24 @@ import { DossierTemplate } from '@red/domain';
|
||||
export class DossierTemplateBreadcrumbsComponent {
|
||||
@Input() root = false;
|
||||
readonly dossierTemplate$: Observable<DossierTemplate>;
|
||||
readonly activeDictionary$: Observable<Dictionary>;
|
||||
|
||||
constructor(
|
||||
readonly userPreferenceService: UserPreferenceService,
|
||||
readonly permissionService: PermissionsService,
|
||||
readonly appStateService: AppStateService,
|
||||
readonly dossierTemplatesService: DossierTemplatesService,
|
||||
readonly dictionariesMapService: DictionariesMapService,
|
||||
private readonly _route: ActivatedRoute,
|
||||
) {
|
||||
this.dossierTemplate$ = _route.paramMap.pipe(
|
||||
map(params => params.get('dossierTemplateId')),
|
||||
switchMap((dossierTemplateId: string) => this.dossierTemplatesService.getEntityChanged$(dossierTemplateId)),
|
||||
);
|
||||
this.activeDictionary$ = _route.paramMap.pipe(
|
||||
map(params => [params.get('dossierTemplateId'), params.get('dictionary')]),
|
||||
switchMap(([dossierTemplateId, dictionary]: [string, string]) =>
|
||||
dictionary ? this.dictionariesMapService.watch$(dossierTemplateId, dictionary) : of(undefined),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,13 +5,13 @@ import { firstValueFrom, Observable } from 'rxjs';
|
||||
import { BaseDialogComponent, shareDistinctLast, Toaster } from '@iqser/common-ui';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { toSnakeCase } from '@utils/functions';
|
||||
import { DictionaryService } from '@shared/services/dictionary.service';
|
||||
import { Dictionary, IDictionary } from '@red/domain';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { HttpStatusCode } from '@angular/common/http';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-add-edit-dictionary-dialog',
|
||||
@ -34,7 +34,7 @@ export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
|
||||
readonly userService: UserService,
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _translateService: TranslateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
protected readonly _injector: Injector,
|
||||
@ -103,7 +103,7 @@ export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
|
||||
}
|
||||
|
||||
private _toTechnicalName(value: string) {
|
||||
const existingTechnicalNames = Object.keys(this._appStateService.dictionaryData[this._dossierTemplateId]);
|
||||
const existingTechnicalNames = this._dictionariesMapService.get(this._dossierTemplateId).map(dict => dict.type);
|
||||
const baseTechnicalName = toSnakeCase(value.trim());
|
||||
let technicalName = baseTechnicalName;
|
||||
let suffix = 1;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Component, Inject, Injector } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import * as moment from 'moment';
|
||||
@ -11,7 +10,7 @@ import { BaseDialogComponent, LoadingService, Toaster } from '@iqser/common-ui';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DownloadFileType, IDossierTemplate } from '@red/domain';
|
||||
import { HttpStatusCode } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DictionaryService } from '../../../shared/services/dictionary.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './add-edit-dossier-template-dialog.component.html',
|
||||
@ -31,9 +30,9 @@ export class AddEditDossierTemplateDialogComponent extends BaseDialogComponent {
|
||||
private _lastValidTo: Moment;
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
protected readonly _injector: Injector,
|
||||
protected readonly _dialogRef: MatDialogRef<AddEditDossierTemplateDialogComponent>,
|
||||
@ -81,7 +80,7 @@ export class AddEditDossierTemplateDialogComponent extends BaseDialogComponent {
|
||||
validTo: this.hasValidTo ? this.form.get('validTo').value : null,
|
||||
} as IDossierTemplate;
|
||||
await this._dossierTemplatesService.createOrUpdate(dossierTemplate).toPromise();
|
||||
await this._appStateService.loadDictionaryData();
|
||||
await this._dictionaryService.loadDictionaryData();
|
||||
this._dialogRef.close(true);
|
||||
} catch (error: any) {
|
||||
const message =
|
||||
|
||||
@ -4,10 +4,10 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { FileAttributeEncodingTypes, IFileAttributesConfig } from '../../../../../../../../libs/red-domain/src';
|
||||
import { fileAttributeEncodingTypesTranslations } from '../../translations/file-attribute-encoding-types-translations';
|
||||
import { BaseDialogComponent, Toaster } from '../../../../../../../../libs/common-ui/src';
|
||||
import { DossierTemplatesService } from '../../../../services/entity-services/dossier-templates.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { FileAttributesService } from '../../../../services/entity-services/file-attributes.service';
|
||||
import { FileAttributesService } from '@services/entity-services/file-attributes.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './file-attributes-configurations-dialog.component.html',
|
||||
@ -15,10 +15,9 @@ import { FileAttributesService } from '../../../../services/entity-services/file
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class FileAttributesConfigurationsDialogComponent extends BaseDialogComponent {
|
||||
private readonly _configuration: IFileAttributesConfig = this._data;
|
||||
|
||||
readonly encodingTypeOptions = Object.keys(FileAttributeEncodingTypes);
|
||||
readonly translations = fileAttributeEncodingTypesTranslations;
|
||||
private readonly _configuration: IFileAttributesConfig = this._data;
|
||||
|
||||
constructor(
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component, forwardRef, Injector, OnInit } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { DefaultColorType, IColors } from '@red/domain';
|
||||
import { AdminDialogService } from '../../services/admin-dialog.service';
|
||||
import {
|
||||
@ -43,7 +42,6 @@ export class DefaultColorsScreenComponent extends ListingComponent<ListItem> imp
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
@ -66,14 +64,14 @@ export class DefaultColorsScreenComponent extends ListingComponent<ListItem> imp
|
||||
},
|
||||
async () => {
|
||||
await this._loadColors();
|
||||
await this._appStateService.refreshDossierTemplate(this._dossierTemplatesService.activeDossierTemplateId);
|
||||
await this._dictionaryService.refreshDossierTemplate(this._dossierTemplatesService.activeDossierTemplateId);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
private async _loadColors() {
|
||||
this._loadingService.start();
|
||||
const data = await firstValueFrom(this._appStateService.loadColors(this._dossierTemplatesService.activeDossierTemplateId));
|
||||
const data = await firstValueFrom(this._dictionaryService.getColors(this._dossierTemplatesService.activeDossierTemplateId));
|
||||
this._colorsObj = data;
|
||||
const entities = Object.keys(data)
|
||||
.map(key => ({
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { Component, forwardRef, Injector, OnInit } from '@angular/core';
|
||||
import { DoughnutChartConfig } from '@shared/components/simple-doughnut-chart/simple-doughnut-chart.component';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import {
|
||||
CircleButtonTypes,
|
||||
@ -20,6 +19,7 @@ import { firstValueFrom, Observable } from 'rxjs';
|
||||
import { DossierTemplateStatsService } from '@services/entity-services/dossier-template-stats.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './dictionary-listing-screen.component.html',
|
||||
@ -44,8 +44,8 @@ export class DictionaryListingScreenComponent extends ListingComponent<Dictionar
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
private readonly _translateService: TranslateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
@ -95,11 +95,12 @@ export class DictionaryListingScreenComponent extends ListingComponent<Dictionar
|
||||
|
||||
private async _loadDictionaryData(refresh = true): Promise<void> {
|
||||
if (refresh) {
|
||||
await this._appStateService.loadDictionaryData();
|
||||
await this._dictionaryService.loadDictionaryData();
|
||||
}
|
||||
|
||||
const appStateDictionaryData = this._appStateService.dictionaryData[this._dossierTemplatesService.activeDossierTemplateId];
|
||||
const entities = Object.values(appStateDictionaryData).filter(d => !d.virtual);
|
||||
const entities: Dictionary[] = this._dictionariesMapService
|
||||
.get(this._dossierTemplatesService.activeDossierTemplateId)
|
||||
.filter(d => !d.virtual);
|
||||
this.entitiesService.setEntities(entities);
|
||||
|
||||
this._calculateData();
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
<section>
|
||||
<section *ngIf="dictionary$ | async as dictionary">
|
||||
<div class="page-header">
|
||||
<redaction-dossier-template-breadcrumbs></redaction-dossier-template-breadcrumbs>
|
||||
|
||||
<div class="actions">
|
||||
<iqser-circle-button
|
||||
(action)="openDeleteDictionaryDialog($event)"
|
||||
(action)="openDeleteDictionaryDialog(dictionary, $event)"
|
||||
*ngIf="currentUser.isAdmin"
|
||||
[tooltip]="'dictionary-overview.action.delete' | translate"
|
||||
[type]="circleButtonTypes.dark"
|
||||
@ -13,7 +13,7 @@
|
||||
></iqser-circle-button>
|
||||
|
||||
<iqser-circle-button
|
||||
(action)="openEditDictionaryDialog($event)"
|
||||
(action)="openEditDictionaryDialog(dictionary, $event)"
|
||||
*ngIf="currentUser.isAdmin"
|
||||
[tooltip]="'dictionary-overview.action.edit' | translate"
|
||||
[type]="circleButtonTypes.dark"
|
||||
@ -22,7 +22,7 @@
|
||||
></iqser-circle-button>
|
||||
|
||||
<iqser-circle-button
|
||||
(action)="download()"
|
||||
(action)="download(dictionary)"
|
||||
[tooltip]="'dictionary-overview.action.download' | translate"
|
||||
icon="iqser:download"
|
||||
tooltipPosition="below"
|
||||
@ -55,11 +55,11 @@
|
||||
|
||||
<redaction-dictionary-manager
|
||||
#dictionaryManager
|
||||
(saveDictionary)="save()"
|
||||
(saveDictionary)="save(dictionary)"
|
||||
[canEdit]="currentUser.isAdmin"
|
||||
[isLeavingPage]="isLeavingPage"
|
||||
[filterByDossierTemplate]="true"
|
||||
[initialEntries]="initialEntries"
|
||||
[isLeavingPage]="isLeavingPage"
|
||||
></redaction-dictionary-manager>
|
||||
|
||||
<div *ngIf="!!dictionary" class="right-container">
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { Component, ElementRef, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { saveAs } from 'file-saver';
|
||||
@ -10,20 +9,23 @@ import { CircleButtonTypes, LoadingService } from '@iqser/common-ui';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { Dictionary } from '@red/domain';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { firstValueFrom, Observable, of } from 'rxjs';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
templateUrl: './dictionary-overview-screen.component.html',
|
||||
styleUrls: ['./dictionary-overview-screen.component.scss'],
|
||||
})
|
||||
export class DictionaryOverviewScreenComponent implements OnInit, OnDestroy {
|
||||
export class DictionaryOverviewScreenComponent {
|
||||
readonly circleButtonTypes = CircleButtonTypes;
|
||||
readonly currentUser = this._userService.currentUser;
|
||||
|
||||
initialEntries: string[] = [];
|
||||
dictionary: Dictionary;
|
||||
isLeavingPage = false;
|
||||
|
||||
readonly dictionary$: Observable<Dictionary>;
|
||||
|
||||
@ViewChild('dictionaryManager', { static: false })
|
||||
private readonly _dictionaryManager: DictionaryManagerComponent;
|
||||
@ViewChild('fileInput') private readonly _fileInput: ElementRef;
|
||||
@ -33,46 +35,48 @@ export class DictionaryOverviewScreenComponent implements OnInit, OnDestroy {
|
||||
private readonly _userService: UserService,
|
||||
private readonly _activatedRoute: ActivatedRoute,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
protected readonly _translateService: TranslateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
) {}
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _route: ActivatedRoute,
|
||||
) {
|
||||
this.dictionary$ = _route.paramMap.pipe(
|
||||
map(params => [params.get('dossierTemplateId'), params.get('dictionary')]),
|
||||
switchMap(([dossierTemplateId, dictionary]: [string, string]) =>
|
||||
dossierTemplateId ? this._dictionariesMapService.watch$(dossierTemplateId, dictionary) : of(undefined),
|
||||
),
|
||||
switchMap(dictionary => this._loadEntries(dictionary)),
|
||||
);
|
||||
}
|
||||
|
||||
get changed() {
|
||||
return this._dictionaryManager.editor.hasChanges;
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this._appStateService.activateDictionary(this._activatedRoute.snapshot.params.dictionary);
|
||||
this.dictionary = this._appStateService.activeDictionary;
|
||||
await this._loadEntries();
|
||||
}
|
||||
|
||||
openEditDictionaryDialog($event: any) {
|
||||
openEditDictionaryDialog(dictionary: Dictionary, $event: MouseEvent) {
|
||||
this._dialogService.openDialog(
|
||||
'addEditDictionary',
|
||||
$event,
|
||||
{
|
||||
dictionary: this.dictionary,
|
||||
dossierTemplateId: this.dictionary.dossierTemplateId,
|
||||
dictionary,
|
||||
dossierTemplateId: dictionary.dossierTemplateId,
|
||||
},
|
||||
async () => {
|
||||
this._loadingService.start();
|
||||
await this._appStateService.loadDictionaryData();
|
||||
this.dictionary = this._appStateService.activeDictionary;
|
||||
await this._dictionaryService.loadDictionaryData();
|
||||
this._loadingService.stop();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
openDeleteDictionaryDialog($event?: MouseEvent) {
|
||||
openDeleteDictionaryDialog(dictionary: Dictionary, $event?: MouseEvent) {
|
||||
$event?.stopPropagation();
|
||||
|
||||
this._dialogService.openDialog('confirm', $event, null, async () => {
|
||||
await firstValueFrom(this._dictionaryService.deleteDictionaries([this.dictionary.type], this.dictionary.dossierTemplateId));
|
||||
await this._appStateService.loadDictionaryData();
|
||||
await firstValueFrom(this._dictionaryService.deleteDictionaries([dictionary.type], dictionary.dossierTemplateId));
|
||||
await this._dictionaryService.loadDictionaryData();
|
||||
await this._router.navigate([
|
||||
'/main',
|
||||
'admin',
|
||||
@ -83,16 +87,16 @@ export class DictionaryOverviewScreenComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
download(): void {
|
||||
download(dictionary: Dictionary): void {
|
||||
const content = this._dictionaryManager.editor.value;
|
||||
const blob = new Blob([content], {
|
||||
type: 'text/plain;charset=utf-8',
|
||||
});
|
||||
saveAs(blob, `${this.dictionary.label}.txt`);
|
||||
saveAs(blob, `${dictionary.label}.txt`);
|
||||
}
|
||||
|
||||
upload($event): void {
|
||||
const file = $event.target.files[0];
|
||||
const file: File = $event.target.files[0];
|
||||
const fileReader = new FileReader();
|
||||
|
||||
if (file) {
|
||||
@ -115,24 +119,18 @@ export class DictionaryOverviewScreenComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
save() {
|
||||
async save(dictionary: Dictionary) {
|
||||
const entries = this._dictionaryManager.editor?.currentEntries;
|
||||
|
||||
this._loadingService.start();
|
||||
this._dictionaryService
|
||||
.saveEntries(entries, this.initialEntries, this.dictionary.dossierTemplateId, this.dictionary.type, null)
|
||||
.subscribe(
|
||||
async () => {
|
||||
await this._loadEntries();
|
||||
},
|
||||
() => {
|
||||
this._loadingService.stop();
|
||||
},
|
||||
try {
|
||||
await firstValueFrom(
|
||||
this._dictionaryService.saveEntries(entries, this.initialEntries, dictionary.dossierTemplateId, dictionary.type, null),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._appStateService.reset();
|
||||
await this._loadEntries(dictionary);
|
||||
} catch (e) {
|
||||
this._loadingService.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private _overwrite(fileContent: string): void {
|
||||
@ -148,24 +146,16 @@ export class DictionaryOverviewScreenComponent implements OnInit, OnDestroy {
|
||||
this._dictionaryManager.editor.value = currentEntries.join('\n');
|
||||
}
|
||||
|
||||
private async _loadEntries() {
|
||||
private async _loadEntries(dictionary: Dictionary) {
|
||||
this._loadingService.start();
|
||||
await firstValueFrom(this._dictionaryService.getForType(this.dictionary.dossierTemplateId, this.dictionary.type))
|
||||
.then(
|
||||
data => {
|
||||
this._loadingService.stop();
|
||||
this.initialEntries = [...data.entries].sort((str1, str2) =>
|
||||
str1.localeCompare(str2, undefined, { sensitivity: 'accent' }),
|
||||
);
|
||||
},
|
||||
() => {
|
||||
this._loadingService.stop();
|
||||
this.initialEntries = [];
|
||||
},
|
||||
)
|
||||
.catch(() => {
|
||||
this._loadingService.stop();
|
||||
this.initialEntries = [];
|
||||
});
|
||||
try {
|
||||
const data = await firstValueFrom(this._dictionaryService.getForType(dictionary.dossierTemplateId, dictionary.type));
|
||||
this._loadingService.stop();
|
||||
this.initialEntries = [...data.entries].sort((str1, str2) => str1.localeCompare(str2, undefined, { sensitivity: 'accent' }));
|
||||
} catch (e) {
|
||||
this._loadingService.stop();
|
||||
this.initialEntries = [];
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component, forwardRef, Injector } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { AdminDialogService } from '../../../services/admin-dialog.service';
|
||||
import { DossierTemplate } from '@red/domain';
|
||||
@ -19,6 +18,7 @@ import { RouterHistoryService } from '@services/router-history.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { HttpStatusCode } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DictionaryService } from '../../../../shared/services/dictionary.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './dossier-templates-listing-screen.component.html',
|
||||
@ -48,7 +48,7 @@ export class DossierTemplatesListingScreenComponent extends ListingComponent<Dos
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
readonly routerHistoryService: RouterHistoryService,
|
||||
readonly userPreferenceService: UserPreferenceService,
|
||||
@ -75,6 +75,6 @@ export class DossierTemplatesListingScreenComponent extends ListingComponent<Dos
|
||||
this._toaster.error(_('dossier-templates-listing.error.generic'));
|
||||
}
|
||||
});
|
||||
await this._appStateService.loadDictionaryData();
|
||||
await this._dictionaryService.loadDictionaryData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component, ElementRef, forwardRef, Injector, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { AdminDialogService } from '../../services/admin-dialog.service';
|
||||
import {
|
||||
CircleButtonTypes,
|
||||
@ -19,6 +18,7 @@ import { DossierTemplatesService } from '@services/entity-services/dossier-templ
|
||||
import { HttpStatusCode } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { ReportTemplateService } from '../../../../services/report-template.service';
|
||||
import { DictionaryService } from '../../../shared/services/dictionary.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './file-attributes-listing-screen.component.html',
|
||||
@ -57,7 +57,7 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
private readonly _fileAttributesService: FileAttributesService,
|
||||
@ -108,7 +108,7 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
|
||||
),
|
||||
);
|
||||
}
|
||||
await this._appStateService.refreshDossierTemplate(dossierTemplateId);
|
||||
await this._dictionaryService.refreshDossierTemplate(dossierTemplateId);
|
||||
await this._loadData();
|
||||
});
|
||||
}
|
||||
@ -144,7 +144,7 @@ export class FileAttributesListingScreenComponent extends ListingComponent<FileA
|
||||
}
|
||||
this._loadingService.stop();
|
||||
});
|
||||
await this._appStateService.refreshDossierTemplate(this._dossierTemplatesService.activeDossierTemplateId);
|
||||
await this._dictionaryService.refreshDossierTemplate(this._dossierTemplatesService.activeDossierTemplateId);
|
||||
await this._loadData();
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { AdminDialogService } from '../../../services/admin-dialog.service';
|
||||
import { CircleButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
|
||||
@ -8,6 +7,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { HttpStatusCode } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DictionaryService } from '../../../../shared/services/dictionary.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-dossier-template-actions',
|
||||
@ -25,7 +25,7 @@ export class DossierTemplateActionsComponent implements OnInit {
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dialogService: AdminDialogService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
) {}
|
||||
@ -49,7 +49,7 @@ export class DossierTemplateActionsComponent implements OnInit {
|
||||
await firstValueFrom(this._dossierTemplatesService.delete([this.dossierTemplateId]))
|
||||
.then(async () => {
|
||||
await firstValueFrom(this._dossierTemplatesService.loadAll());
|
||||
await this._appStateService.loadDictionaryData();
|
||||
await this._dictionaryService.loadDictionaryData();
|
||||
await this._router.navigate(['main', 'admin']);
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { Component, Inject, Injector, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper';
|
||||
import { ManualAnnotationService } from '../../services/manual-annotation.service';
|
||||
@ -33,7 +32,6 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme
|
||||
private readonly _dossier: Dossier;
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
private readonly _justificationsService: JustificationsService,
|
||||
private readonly _manualAnnotationService: ManualAnnotationService,
|
||||
@ -77,7 +75,7 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme
|
||||
|
||||
async ngOnInit() {
|
||||
super.ngOnInit();
|
||||
this.possibleDictionaries = await this._appStateService.getDictionariesOptions(
|
||||
this.possibleDictionaries = await this._dictionaryService.getDictionariesOptions(
|
||||
this._dossier.dossierTemplateId,
|
||||
this._dossier.dossierId,
|
||||
);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { DoughnutChartConfig } from '@shared/components/simple-doughnut-chart/simple-doughnut-chart.component';
|
||||
import { TranslateChartService } from '@services/translate-chart.service';
|
||||
import { UserService } from '@services/user.service';
|
||||
@ -35,7 +34,6 @@ export class DossierDetailsComponent {
|
||||
readonly dossierStats$: Observable<DossierStats>;
|
||||
|
||||
constructor(
|
||||
readonly appStateService: AppStateService,
|
||||
readonly dossiersService: DossiersService,
|
||||
readonly translateChartService: TranslateChartService,
|
||||
readonly filterService: FilterService,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { File } from '@red/domain';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
import { UserService } from '../../../../../../../services/user.service';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-file-workload',
|
||||
@ -14,8 +14,8 @@ export class FileWorkloadComponent {
|
||||
@Input() file: File;
|
||||
|
||||
constructor(
|
||||
public readonly userService: UserService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
readonly userService: UserService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
) {}
|
||||
|
||||
@ -44,6 +44,6 @@ export class FileWorkloadComponent {
|
||||
}
|
||||
|
||||
private _getDictionaryColor(type: string) {
|
||||
return this._appStateService.getDictionaryColor(type, this._dossiersService.find(this.file.dossierId).dossierTemplateId);
|
||||
return this._dictionariesMapService.getDictionaryColor(type, this._dossiersService.find(this.file.dossierId).dossierTemplateId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { Dossier, DossierStats } from '@red/domain';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-dossier-workload-column',
|
||||
@ -12,17 +12,17 @@ export class DossierWorkloadColumnComponent {
|
||||
@Input() dossier: Dossier;
|
||||
@Input() dossierStats: DossierStats;
|
||||
|
||||
constructor(private readonly _appStateService: AppStateService) {}
|
||||
constructor(private readonly _dictionariesMapService: DictionariesMapService) {}
|
||||
|
||||
get suggestionColor() {
|
||||
return this._appStateService.getDictionaryColor('suggestion', this.dossier.dossierTemplateId);
|
||||
return this._dictionariesMapService.getDictionaryColor('suggestion', this.dossier.dossierTemplateId);
|
||||
}
|
||||
|
||||
get hintColor() {
|
||||
return this._appStateService.getDictionaryColor('hint', this.dossier.dossierTemplateId);
|
||||
return this._dictionariesMapService.getDictionaryColor('hint', this.dossier.dossierTemplateId);
|
||||
}
|
||||
|
||||
get redactionColor() {
|
||||
return this._appStateService.getDictionaryColor('redaction', this.dossier.dossierTemplateId);
|
||||
return this._dictionariesMapService.getDictionaryColor('redaction', this.dossier.dossierTemplateId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Component, Input, OnChanges } from '@angular/core';
|
||||
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { FilePreviewStateService } from '../../services/file-preview-state.service';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-type-annotation-icon',
|
||||
@ -15,7 +15,7 @@ export class TypeAnnotationIconComponent implements OnChanges {
|
||||
color: string;
|
||||
type: 'square' | 'rhombus' | 'circle' | 'hexagon';
|
||||
|
||||
constructor(private _appStateService: AppStateService, readonly screenStateService: FilePreviewStateService) {}
|
||||
constructor(private _dictionariesMapService: DictionariesMapService, readonly screenStateService: FilePreviewStateService) {}
|
||||
|
||||
private get _dossierTemplateId(): string {
|
||||
return this.screenStateService.dossierTemplateId;
|
||||
@ -29,9 +29,9 @@ export class TypeAnnotationIconComponent implements OnChanges {
|
||||
const { isSuggestion, isRecommendation, isSkipped, isDeclinedSuggestion, isHint, isIgnoredHint } = this.annotation;
|
||||
|
||||
if (this.annotation.isSuperTypeBasedColor) {
|
||||
this.color = this._appStateService.getDictionaryColor(this.annotation.superType, this._dossierTemplateId);
|
||||
this.color = this._dictionariesMapService.getDictionaryColor(this.annotation.superType, this._dossierTemplateId);
|
||||
} else {
|
||||
this.color = this._appStateService.getDictionaryColor(this.annotation.type, this._dossierTemplateId);
|
||||
this.color = this._dictionariesMapService.getDictionaryColor(this.annotation.type, this._dossierTemplateId);
|
||||
}
|
||||
|
||||
this.type =
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { Component, Inject, Injector, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { PermissionsService } from '@services/permissions.service';
|
||||
import { Dictionary, Dossier } from '@red/domain';
|
||||
@ -31,7 +30,6 @@ export class AcceptRecommendationDialogComponent extends BaseDialogComponent imp
|
||||
private readonly _dossier: Dossier;
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
private readonly _manualAnnotationService: ManualAnnotationService,
|
||||
private readonly _permissionsService: PermissionsService,
|
||||
@ -58,7 +56,7 @@ export class AcceptRecommendationDialogComponent extends BaseDialogComponent imp
|
||||
|
||||
async ngOnInit() {
|
||||
super.ngOnInit();
|
||||
this.possibleDictionaries = await this._appStateService.getDictionariesOptions(
|
||||
this.possibleDictionaries = await this._dictionaryService.getDictionariesOptions(
|
||||
this._dossier.dossierTemplateId,
|
||||
this._dossier.dossierId,
|
||||
);
|
||||
|
||||
@ -142,8 +142,8 @@ export class AnnotationActionsService {
|
||||
annotation,
|
||||
dossierId,
|
||||
fileId,
|
||||
removeFromDictionary,
|
||||
result.comment,
|
||||
removeFromDictionary,
|
||||
),
|
||||
annotation,
|
||||
annotationsChanged,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Core, WebViewerInstance } from '@pdftron/webviewer';
|
||||
import { hexToRgb } from '@utils/functions';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
@ -11,12 +10,13 @@ import { environment } from '@environments/environment';
|
||||
import { IRectangle, ISectionGrid, ISectionRectangle } from '@red/domain';
|
||||
import { SkippedService } from './skipped.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
import Annotation = Core.Annotations.Annotation;
|
||||
|
||||
@Injectable()
|
||||
export class AnnotationDrawService {
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _redactionLogService: RedactionLogService,
|
||||
private readonly _userPreferenceService: UserPreferenceService,
|
||||
@ -50,13 +50,13 @@ export class AnnotationDrawService {
|
||||
case 'hint':
|
||||
case 'redaction':
|
||||
case 'recommendation':
|
||||
color = this._appStateService.getDictionaryColor(dictionary, dossierTemplateId);
|
||||
color = this._dictionariesMapService.getDictionaryColor(dictionary, dossierTemplateId);
|
||||
break;
|
||||
case 'skipped':
|
||||
color = this._appStateService.getDictionaryColor(superType, dossierTemplateId);
|
||||
color = this._dictionariesMapService.getDictionaryColor(superType, dossierTemplateId);
|
||||
break;
|
||||
default:
|
||||
color = this._appStateService.getDictionaryColor(superType, dossierTemplateId);
|
||||
color = this._dictionariesMapService.getDictionaryColor(superType, dossierTemplateId);
|
||||
break;
|
||||
}
|
||||
return color;
|
||||
|
||||
@ -2,13 +2,13 @@ import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, firstValueFrom, Observable, pairwise, switchMap } from 'rxjs';
|
||||
import { FileDataModel } from '@models/file/file-data.model';
|
||||
import { Dossier, File } from '@red/domain';
|
||||
import { DossiersService } from '../../../../../services/entity-services/dossiers.service';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { FilesMapService } from '../../../../../services/entity-services/files-map.service';
|
||||
import { FilesMapService } from '@services/entity-services/files-map.service';
|
||||
import { PermissionsService } from '../../../../../services/permissions.service';
|
||||
import { boolFactory, shareLast } from '@iqser/common-ui';
|
||||
import { filter, startWith } from 'rxjs/operators';
|
||||
import { FileManagementService } from '../../../../../services/entity-services/file-management.service';
|
||||
import { FileManagementService } from '@services/entity-services/file-management.service';
|
||||
|
||||
@Injectable()
|
||||
export class FilePreviewStateService {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import {
|
||||
Dossier,
|
||||
IAddRedactionRequest,
|
||||
@ -20,6 +19,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Injectable()
|
||||
export class ManualAnnotationService extends GenericService<IManualAddResponse> {
|
||||
@ -28,7 +28,7 @@ export class ManualAnnotationService extends GenericService<IManualAddResponse>
|
||||
};
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _permissionsService: PermissionsService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
@ -74,8 +74,10 @@ export class ManualAnnotationService extends GenericService<IManualAddResponse>
|
||||
this._toaster.error(this._getMessage(mode, modifyDictionary, true, isConflict), {
|
||||
error,
|
||||
params: {
|
||||
dictionaryName: this._appStateService.getDictionary(body.type, this._dossier(dossierId).dossierTemplateId)
|
||||
.label,
|
||||
dictionaryName: this._dictionariesMapService.getDictionary(
|
||||
body.type as string,
|
||||
this._dossier(dossierId).dossierTemplateId,
|
||||
).label,
|
||||
content: body.value,
|
||||
},
|
||||
positionClass: 'toast-file-preview',
|
||||
@ -199,8 +201,8 @@ export class ManualAnnotationService extends GenericService<IManualAddResponse>
|
||||
annotationWrapper: AnnotationWrapper,
|
||||
dossierId: string,
|
||||
fileId: string,
|
||||
removeFromDictionary: boolean = false,
|
||||
comment: string,
|
||||
removeFromDictionary: boolean = false,
|
||||
) {
|
||||
let mode: AnnotationActionMode,
|
||||
body: any,
|
||||
|
||||
@ -3,14 +3,14 @@ import { forkJoin, Observable, of } from 'rxjs';
|
||||
import { catchError, map, tap } from 'rxjs/operators';
|
||||
import { FileDataModel } from '@models/file/file-data.model';
|
||||
import { PermissionsService } from '@services/permissions.service';
|
||||
import { File, IRedactionLog, IViewedPage } from '@red/domain';
|
||||
import { Dictionary, File, IRedactionLog, IViewedPage } from '@red/domain';
|
||||
import { RedactionLogService } from './redaction-log.service';
|
||||
import { ViewedPagesService } from '@services/entity-services/viewed-pages.service';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { UserPreferenceService } from '@services/user-preference.service';
|
||||
import { FilePreviewStateService } from '../screens/file-preview-screen/services/file-preview-state.service';
|
||||
import { Toaster } from '@iqser/common-ui';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Injectable()
|
||||
export class PdfViewerDataService {
|
||||
@ -18,10 +18,10 @@ export class PdfViewerDataService {
|
||||
private readonly _permissionsService: PermissionsService,
|
||||
private readonly _redactionLogService: RedactionLogService,
|
||||
private readonly _viewedPagesService: ViewedPagesService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _userPreferenceService: UserPreferenceService,
|
||||
private readonly _stateService: FilePreviewStateService,
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
) {}
|
||||
|
||||
loadRedactionLogFor(dossierId: string, fileId: string) {
|
||||
@ -37,12 +37,8 @@ export class PdfViewerDataService {
|
||||
|
||||
return forkJoin([redactionLog$, viewedPages$]).pipe(
|
||||
map((data: [redactionLog: IRedactionLog, viewedPages: IViewedPage[]]) => {
|
||||
const fileDataModel = new FileDataModel(
|
||||
newFile,
|
||||
...data,
|
||||
this._appStateService.dictionaryData[this._stateService.dossierTemplateId],
|
||||
this._userPreferenceService.areDevFeaturesEnabled,
|
||||
);
|
||||
const dictionaries: Dictionary[] = this._dictionariesMapService.get(this._stateService.dossierTemplateId);
|
||||
const fileDataModel = new FileDataModel(newFile, ...data, dictionaries, this._userPreferenceService.areDevFeaturesEnabled);
|
||||
if (fileDataModel.missingTypes.size > 0) {
|
||||
this._toaster.error(_('error.missing-types'), {
|
||||
disableTimeOut: true,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Component, Input, OnChanges } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-dictionary-annotation-icon',
|
||||
@ -14,12 +14,12 @@ export class DictionaryAnnotationIconComponent implements OnChanges {
|
||||
label: string;
|
||||
type: 'square' | 'circle';
|
||||
|
||||
constructor(private readonly _appStateService: AppStateService) {}
|
||||
constructor(private readonly _dictionariesMapService: DictionariesMapService) {}
|
||||
|
||||
ngOnChanges(): void {
|
||||
if (this.dictionaryKey) {
|
||||
const dictionary = this._appStateService.getDictionary(this.dictionaryKey, this.dossierTemplateId);
|
||||
this.color = this._appStateService.getDictionaryColor(this.dictionaryKey, this.dossierTemplateId);
|
||||
const dictionary = this._dictionariesMapService.getDictionary(this.dictionaryKey, this.dossierTemplateId);
|
||||
this.color = this._dictionariesMapService.getDictionaryColor(this.dictionaryKey, this.dossierTemplateId);
|
||||
this.type = dictionary.hint ? 'circle' : 'square';
|
||||
this.label = this.dictionaryKey[0].toUpperCase();
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DictionaryService } from '@shared/services/dictionary.service';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { EditorComponent } from '@shared/components/editor/editor.component';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
import IModelDeltaDecoration = monaco.editor.IModelDeltaDecoration;
|
||||
import FindMatch = monaco.editor.FindMatch;
|
||||
|
||||
@ -46,8 +46,8 @@ export class DictionaryManagerComponent implements OnChanges {
|
||||
|
||||
constructor(
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
readonly dossiersService: DossiersService,
|
||||
readonly appStateService: AppStateService,
|
||||
readonly dossierTemplatesService: DossierTemplatesService,
|
||||
) {}
|
||||
|
||||
@ -101,9 +101,8 @@ 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: List =
|
||||
this._dictionary.entries ?? this._dictionariesMapService.get(this._dictionary.dossierTemplateId, this._dictionary.type).entries;
|
||||
|
||||
if (entries.length) {
|
||||
this.diffEditorText = this._toString([...entries]);
|
||||
@ -125,11 +124,11 @@ export class DictionaryManagerComponent implements OnChanges {
|
||||
});
|
||||
}
|
||||
|
||||
get _dictionaries() {
|
||||
get _dictionaries(): Dictionary[] {
|
||||
if (!this._dossierTemplate || this._dossierTemplate.name === this.selectDossierTemplate.name) {
|
||||
return;
|
||||
}
|
||||
return Object.values(this.appStateService.dictionaryData[this.dossierTemplate?.dossierTemplateId]).filter(dict => !dict.virtual);
|
||||
return this._dictionariesMapService.get(this.dossierTemplate?.dossierTemplateId).filter(dict => !dict.virtual);
|
||||
}
|
||||
|
||||
get dossierTemplateIsNotSelected() {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Component, Input, OnChanges } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { INestedFilter, Required } from '@iqser/common-ui';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-type-filter',
|
||||
@ -23,13 +23,13 @@ export class TypeFilterComponent implements OnChanges {
|
||||
];
|
||||
private _needsAnalysisKeys = ['add-dictionary', 'remove-only-here', 'change-legal-basis', 'analysis'];
|
||||
|
||||
constructor(private readonly _appStateService: AppStateService) {}
|
||||
constructor(private readonly _dictionariesMapService: DictionariesMapService) {}
|
||||
|
||||
isSuggestion = (key: string) => this._suggestionsKeys.includes(key);
|
||||
|
||||
needsAnalysis = (key: string) => this._needsAnalysisKeys.includes(key);
|
||||
|
||||
ngOnChanges(): void {
|
||||
this.dictionaryColor = this._appStateService.getDictionaryColor(this.filter.id, this.dossierTemplateId);
|
||||
this.dictionaryColor = this._dictionariesMapService.getDictionaryColor(this.filter.id, this.dossierTemplateId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,15 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { firstValueFrom, forkJoin, Observable, of, throwError } from 'rxjs';
|
||||
import { EntitiesService, List, QueryParam, RequiredParam, Toaster, Validate } from '@iqser/common-ui';
|
||||
import { Dictionary, IColors, IDictionary, IUpdateDictionary } from '@red/domain';
|
||||
import { mapTo, switchMap, tap } from 'rxjs/operators';
|
||||
import { Dictionary, DossierTemplate, IColors, IDictionary, IUpdateDictionary } from '@red/domain';
|
||||
import { catchError, map, mapTo, switchMap, tap } from 'rxjs/operators';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DossierTemplateStatsService } from '@services/entity-services/dossier-template-stats.service';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
import { FALLBACK_COLOR } from '@utils/constants';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { hexToRgb } from '@utils/functions';
|
||||
import { FileAttributesService } from '@services/entity-services/file-attributes.service';
|
||||
|
||||
const MIN_WORD_LENGTH = 2;
|
||||
|
||||
@ -15,7 +20,10 @@ export class DictionaryService extends EntitiesService<Dictionary, IDictionary>
|
||||
constructor(
|
||||
private readonly _toaster: Toaster,
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _fileAttributesService: FileAttributesService,
|
||||
private readonly _dossierTemplateStatsService: DossierTemplateStatsService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
) {
|
||||
super(_injector, Dictionary, 'dictionary');
|
||||
}
|
||||
@ -55,7 +63,22 @@ export class DictionaryService extends EntitiesService<Dictionary, IDictionary>
|
||||
*/
|
||||
@Validate()
|
||||
getColors(@RequiredParam() dossierTemplateId: string) {
|
||||
return this._getOne<IColors>([dossierTemplateId], 'color');
|
||||
return this._getOne<IColors>([dossierTemplateId], 'color').pipe(
|
||||
catchError(() =>
|
||||
of({
|
||||
analysisColor: FALLBACK_COLOR,
|
||||
dictionaryRequestColor: FALLBACK_COLOR,
|
||||
defaultColor: FALLBACK_COLOR,
|
||||
manualRedactionColor: FALLBACK_COLOR,
|
||||
notRedacted: FALLBACK_COLOR,
|
||||
requestAdd: FALLBACK_COLOR,
|
||||
previewColor: FALLBACK_COLOR,
|
||||
requestRemove: FALLBACK_COLOR,
|
||||
updatedColor: FALLBACK_COLOR,
|
||||
dossierTemplateId: dossierTemplateId,
|
||||
} as IColors),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,6 +159,57 @@ export class DictionaryService extends EntitiesService<Dictionary, IDictionary>
|
||||
}
|
||||
}
|
||||
|
||||
async getDictionariesOptions(dossierTemplateId: string, dossierId: string): Promise<Dictionary[]> {
|
||||
const possibleDictionaries: Dictionary[] = [];
|
||||
|
||||
const dossierDictionary = await firstValueFrom(this.getForType(dossierTemplateId, 'dossier_redaction', dossierId));
|
||||
|
||||
for (const dictionary of this._dictionariesMapService.get(dossierTemplateId)) {
|
||||
if (!dictionary.virtual && dictionary.addToDictionaryAction) {
|
||||
possibleDictionaries.push(dictionary as Dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
if (dossierDictionary.addToDictionaryAction) {
|
||||
// TODO fix this in the backend
|
||||
possibleDictionaries.push(new Dictionary({ ...dossierDictionary, type: 'dossier_redaction' }));
|
||||
}
|
||||
|
||||
possibleDictionaries.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
return possibleDictionaries;
|
||||
}
|
||||
|
||||
async loadDictionaryDataIfNecessary() {
|
||||
if (this._dictionariesMapService.empty) {
|
||||
await this.loadDictionaryData();
|
||||
}
|
||||
}
|
||||
|
||||
async loadDictionaryData(): Promise<void> {
|
||||
const observables: Observable<Dictionary[]>[] = [];
|
||||
for (const dossierTemplate of this._dossierTemplatesService.all) {
|
||||
observables.push(this._loadDictionaryDataForDossierTemplate$(dossierTemplate.dossierTemplateId));
|
||||
}
|
||||
await firstValueFrom(forkJoin(observables));
|
||||
}
|
||||
|
||||
async refreshDossierTemplateDictionaryData(dossierTemplateId: string): Promise<void> {
|
||||
await firstValueFrom(this._loadDictionaryDataForDossierTemplate$(dossierTemplateId));
|
||||
}
|
||||
|
||||
// TODO: Maybe move this in dossier templates service
|
||||
async refreshDossierTemplate(dossierTemplateId: string) {
|
||||
const dossierTemplate = await firstValueFrom(this._dossierTemplatesService.get(dossierTemplateId));
|
||||
|
||||
await firstValueFrom(this._fileAttributesService.getFileAttributesConfig(dossierTemplateId));
|
||||
|
||||
const newDossierTemplate = new DossierTemplate(dossierTemplate);
|
||||
this._dossierTemplatesService.replace(newDossierTemplate);
|
||||
|
||||
await this.refreshDossierTemplateDictionaryData(dossierTemplateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add dictionary entries with entry type.
|
||||
*/
|
||||
@ -169,4 +243,66 @@ export class DictionaryService extends EntitiesService<Dictionary, IDictionary>
|
||||
const url = `${this._defaultModelPath}/delete/${type}/${dossierTemplateId}`;
|
||||
return this._post(body, url, queryParams);
|
||||
}
|
||||
|
||||
private _loadDictionaryDataForDossierTemplate$(dossierTemplateId: string): Observable<Dictionary[]> {
|
||||
const types$: Observable<Dictionary[]> = this.getAllDictionaries(dossierTemplateId).pipe(
|
||||
map(typesResponse => typesResponse.types.map(type => new Dictionary(type))),
|
||||
);
|
||||
|
||||
const virtualTypes$: Observable<Dictionary[]> = this.getColors(dossierTemplateId).pipe(
|
||||
tap(colors => {
|
||||
for (const key of Object.keys(colors)) {
|
||||
const color = colors[key];
|
||||
try {
|
||||
const rgbValue = hexToRgb(color);
|
||||
if (!rgbValue) {
|
||||
colors[key] = FALLBACK_COLOR;
|
||||
}
|
||||
} catch (e) {
|
||||
colors[key] = FALLBACK_COLOR;
|
||||
}
|
||||
}
|
||||
}),
|
||||
map(colors => {
|
||||
const virtualTypes = [
|
||||
{
|
||||
hexColor: colors.manualRedactionColor || FALLBACK_COLOR,
|
||||
type: 'dossier_redaction',
|
||||
hint: false,
|
||||
recommendation: false,
|
||||
},
|
||||
{ hexColor: colors.notRedacted || FALLBACK_COLOR, type: 'declined-suggestion' },
|
||||
{ hexColor: colors.manualRedactionColor || FALLBACK_COLOR, type: 'manual' },
|
||||
{ hexColor: colors.ignoredHintColor || FALLBACK_COLOR, type: 'ignored-hint' },
|
||||
{ hexColor: colors.manualRedactionColor || FALLBACK_COLOR, type: 'manual-redaction' },
|
||||
// dictionary actions
|
||||
{ hexColor: '#c5d3eb', type: 'recommendation' },
|
||||
{ hexColor: colors.analysisColor || FALLBACK_COLOR, type: 'remove-only-here' },
|
||||
// generic suggestions
|
||||
{ hexColor: colors.requestAdd || FALLBACK_COLOR, type: 'suggestion' },
|
||||
{ hexColor: colors.requestAdd || FALLBACK_COLOR, type: 'suggestion-add' },
|
||||
// add suggestions
|
||||
{ hexColor: colors.requestAdd || FALLBACK_COLOR, type: 'suggestion-change-legal-basis' },
|
||||
{ hexColor: colors.requestAdd || FALLBACK_COLOR, type: 'suggestion-recategorize-image' },
|
||||
{ hexColor: colors.dictionaryRequestColor || FALLBACK_COLOR, type: 'suggestion-add-dictionary' },
|
||||
{ hexColor: colors.dictionaryRequestColor || FALLBACK_COLOR, type: 'suggestion-resize' },
|
||||
{ hexColor: colors.requestRemove || FALLBACK_COLOR, type: 'suggestion-remove' },
|
||||
{ hexColor: colors.dictionaryRequestColor || FALLBACK_COLOR, type: 'suggestion-remove-dictionary' },
|
||||
{ hexColor: colors.notRedacted || FALLBACK_COLOR, type: 'skipped' },
|
||||
{ hexColor: colors.defaultColor || FALLBACK_COLOR, type: 'default' },
|
||||
{ hexColor: colors.requestAdd || FALLBACK_COLOR, type: 'add' },
|
||||
{ hexColor: colors.analysisColor || FALLBACK_COLOR, type: 'analysis' },
|
||||
{ hexColor: '#fa98f7', type: 'hint', hint: true },
|
||||
{ hexColor: colors.manualRedactionColor || FALLBACK_COLOR, type: 'redaction' },
|
||||
{ hexColor: colors.updatedColor || FALLBACK_COLOR, type: 'updated' },
|
||||
];
|
||||
|
||||
return virtualTypes.map(config => new Dictionary(config, true));
|
||||
}),
|
||||
);
|
||||
|
||||
return forkJoin([types$, virtualTypes$])
|
||||
.pipe(map(([types, virtualTypes]: Dictionary[][]) => [...types, ...virtualTypes]))
|
||||
.pipe(tap(dictionaries => this._dictionariesMapService.set(dossierTemplateId, dictionaries)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Dictionary, IDictionary } from '@red/domain';
|
||||
import { EntitiesMapService } from '@iqser/common-ui';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DictionariesMapService extends EntitiesMapService<Dictionary, IDictionary> {
|
||||
constructor() {
|
||||
super('dossierTemplateId');
|
||||
}
|
||||
|
||||
/** If the type is not found, it returns the 'default' type. */
|
||||
getDictionary(type: string, dossierTemplateId: string): Dictionary | undefined {
|
||||
return this.get(dossierTemplateId, type) || this.get(dossierTemplateId, 'default');
|
||||
}
|
||||
|
||||
getDictionaryColor(type: string, dossierTemplateId: string) {
|
||||
return !this.get(dossierTemplateId) ? '#cccccc' : this.getDictionary(type, dossierTemplateId).hexColor;
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { AppStateService } from './app-state.service';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service';
|
||||
import { DictionaryService } from '@shared/services/dictionary.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AppStateGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _dictionariesMapService: DictionariesMapService,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _router: Router,
|
||||
) {}
|
||||
@ -24,17 +26,17 @@ export class AppStateGuard implements CanActivate {
|
||||
if (this._userService.currentUser.isUser || this._userService.currentUser.isAdmin) {
|
||||
await firstValueFrom(this._userService.loadAll());
|
||||
await this._dossierTemplatesService.loadAllIfEmpty();
|
||||
await this._appStateService.loadDictionaryDataIfNecessary();
|
||||
await this._dictionaryService.loadDictionaryDataIfNecessary();
|
||||
}
|
||||
|
||||
const { dossierTemplateId, type } = route.params;
|
||||
|
||||
if (dossierTemplateId && !this._dossierTemplatesService.find(dossierTemplateId)) {
|
||||
if (dossierTemplateId && !this._dossierTemplatesService.find(dossierTemplateId as string)) {
|
||||
await this._router.navigate(['main', 'admin', 'dossier-templates']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type && !this._appStateService.dictionaryData[dossierTemplateId][type]) {
|
||||
if (type && !this._dictionariesMapService.get(dossierTemplateId, type)) {
|
||||
await this._router.navigate(['main', 'admin', 'dossier-templates', dossierTemplateId]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,371 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Dictionary, DossierTemplate, IColors } from '@red/domain';
|
||||
import { Router } from '@angular/router';
|
||||
import { firstValueFrom, forkJoin, Observable, of } from 'rxjs';
|
||||
import { catchError, map, tap } from 'rxjs/operators';
|
||||
import { FALLBACK_COLOR, hexToRgb } from '@utils/functions';
|
||||
import { DictionaryService } from '@shared/services/dictionary.service';
|
||||
import { DossierTemplatesService } from '@services/entity-services/dossier-templates.service';
|
||||
import { FileAttributesService } from '@services/entity-services/file-attributes.service';
|
||||
|
||||
export interface AppState {
|
||||
activeDictionaryType?: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AppStateService {
|
||||
private _appState: AppState = {};
|
||||
|
||||
constructor(
|
||||
private readonly _router: Router,
|
||||
private readonly _dictionaryService: DictionaryService,
|
||||
private readonly _dossierTemplatesService: DossierTemplatesService,
|
||||
private readonly _fileAttributesService: FileAttributesService,
|
||||
) {}
|
||||
|
||||
private _dictionaryData?: { [key: string]: { [key: string]: Dictionary } };
|
||||
|
||||
get dictionaryData(): { [key: string]: { [key: string]: Dictionary } } | undefined {
|
||||
return this._dictionaryData;
|
||||
}
|
||||
|
||||
get dossierTemplates(): DossierTemplate[] {
|
||||
return this._dossierTemplatesService.all;
|
||||
}
|
||||
|
||||
get activeDictionaryType(): string | undefined {
|
||||
return this._appState.activeDictionaryType;
|
||||
}
|
||||
|
||||
get activeDictionary(): Dictionary | undefined {
|
||||
const activeDossierTemplateId = this._dossierTemplatesService.activeDossierTemplateId;
|
||||
return activeDossierTemplateId && this.activeDictionaryType && this.dictionaryData && this.dictionaryData[activeDossierTemplateId]
|
||||
? this.dictionaryData[activeDossierTemplateId][this.activeDictionaryType]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
async getDictionariesOptions(dossierTemplateId: string, dossierId: string): Promise<Dictionary[]> {
|
||||
const possibleDictionaries: Dictionary[] = [];
|
||||
|
||||
const dossierDictionary = await firstValueFrom(
|
||||
this._dictionaryService.getForType(dossierTemplateId, 'dossier_redaction', dossierId),
|
||||
);
|
||||
|
||||
for (const key of Object.keys(this.dictionaryData[dossierTemplateId])) {
|
||||
const dictionaryData = this.getDictionary(key, dossierTemplateId);
|
||||
if (!dictionaryData.virtual && dictionaryData.addToDictionaryAction) {
|
||||
possibleDictionaries.push(dictionaryData);
|
||||
}
|
||||
}
|
||||
|
||||
if (dossierDictionary.addToDictionaryAction) {
|
||||
// TODO fix this in the backend
|
||||
possibleDictionaries.push(new Dictionary({ ...dossierDictionary, type: 'dossier_redaction' }));
|
||||
}
|
||||
|
||||
possibleDictionaries.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
return possibleDictionaries;
|
||||
}
|
||||
|
||||
getDictionaryColor(type: string, dossierTemplateId: string) {
|
||||
return !this._dictionaryData
|
||||
? '#cccccc'
|
||||
: this._dictionaryData[dossierTemplateId][type]?.hexColor || this._dictionaryData[dossierTemplateId]['default'].hexColor;
|
||||
}
|
||||
|
||||
getDictionary(key: string, dossierTemplateId: string): Dictionary | undefined {
|
||||
if (!dossierTemplateId) {
|
||||
dossierTemplateId = this.dossierTemplates.length > 0 ? this.dossierTemplates[0].dossierTemplateId : undefined;
|
||||
}
|
||||
if (!dossierTemplateId || !this._dictionaryData) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const data = this._dictionaryData[dossierTemplateId][key];
|
||||
return data ? data : this._dictionaryData[dossierTemplateId]['default'];
|
||||
}
|
||||
|
||||
activateDictionary(dictionaryType: string) {
|
||||
if (this._dossierTemplatesService.activeDossierTemplate) {
|
||||
this._appState.activeDictionaryType = dictionaryType;
|
||||
if (!this.activeDictionary) {
|
||||
this._appState.activeDictionaryType = null;
|
||||
this._router.navigate([this._dossierTemplatesService.activeDossierTemplate.routerLink]).then();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this._appState.activeDictionaryType = null;
|
||||
}
|
||||
|
||||
async refreshDossierTemplate(dossierTemplateId: string) {
|
||||
const dossierTemplate = await firstValueFrom(this._dossierTemplatesService.get(dossierTemplateId));
|
||||
|
||||
await firstValueFrom(this._fileAttributesService.getFileAttributesConfig(dossierTemplateId));
|
||||
|
||||
const newDossierTemplate = new DossierTemplate(dossierTemplate);
|
||||
this._dossierTemplatesService.replace(newDossierTemplate);
|
||||
|
||||
await this.refreshDossierTemplateDictionaryData(dossierTemplateId);
|
||||
}
|
||||
|
||||
async loadDictionaryDataIfNecessary() {
|
||||
if (!this._dictionaryData) {
|
||||
await this.loadDictionaryData();
|
||||
} else {
|
||||
return this._dictionaryData;
|
||||
}
|
||||
}
|
||||
|
||||
async loadDictionaryData(): Promise<void> {
|
||||
const observables = [];
|
||||
for (const dossierTemplate of this.dossierTemplates) {
|
||||
observables.push(this._getDictionaryDataForDossierTemplate$(dossierTemplate.dossierTemplateId));
|
||||
}
|
||||
const result = await firstValueFrom(forkJoin(observables));
|
||||
|
||||
const dictionaryData = {};
|
||||
for (let i = 0; i < this.dossierTemplates.length; i++) {
|
||||
dictionaryData[this.dossierTemplates[i].dossierTemplateId] = result[i];
|
||||
}
|
||||
|
||||
this._dictionaryData = dictionaryData;
|
||||
}
|
||||
|
||||
async refreshDossierTemplateDictionaryData(dossierTemplateId: string) {
|
||||
this._dictionaryData[dossierTemplateId] = await firstValueFrom(this._getDictionaryDataForDossierTemplate$(dossierTemplateId));
|
||||
}
|
||||
|
||||
loadColors(dossierTemplateId: string) {
|
||||
return this._dictionaryService.getColors(dossierTemplateId).pipe(
|
||||
catchError(() =>
|
||||
of({
|
||||
analysisColor: FALLBACK_COLOR,
|
||||
dictionaryRequestColor: FALLBACK_COLOR,
|
||||
defaultColor: FALLBACK_COLOR,
|
||||
manualRedactionColor: FALLBACK_COLOR,
|
||||
notRedacted: FALLBACK_COLOR,
|
||||
requestAdd: FALLBACK_COLOR,
|
||||
previewColor: FALLBACK_COLOR,
|
||||
requestRemove: FALLBACK_COLOR,
|
||||
updatedColor: FALLBACK_COLOR,
|
||||
dossierTemplateId: dossierTemplateId,
|
||||
} as IColors),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private _getDictionaryDataForDossierTemplate$(dossierTemplateId: string): Observable<{ [key: string]: any }> {
|
||||
const dictionaryData: { [key: string]: any } = {};
|
||||
|
||||
const typeObs = this._dictionaryService.getAllDictionaries(dossierTemplateId).pipe(
|
||||
tap(typesResponse => {
|
||||
for (const type of typesResponse.types) {
|
||||
dictionaryData[type.type] = new Dictionary(type);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
const colorsObs = this.loadColors(dossierTemplateId).pipe(
|
||||
tap(colors => {
|
||||
for (const key of Object.keys(colors)) {
|
||||
const color = colors[key];
|
||||
try {
|
||||
const rgbValue = hexToRgb(color);
|
||||
if (!rgbValue) {
|
||||
colors[key] = FALLBACK_COLOR;
|
||||
}
|
||||
} catch (e) {
|
||||
colors[key] = FALLBACK_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
dictionaryData['dossier_redaction'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.manualRedactionColor || FALLBACK_COLOR,
|
||||
type: 'dossier_redaction',
|
||||
hint: false,
|
||||
recommendation: false,
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['declined-suggestion'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.notRedacted || FALLBACK_COLOR,
|
||||
type: 'declined-suggestion',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['manual'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.manualRedactionColor || FALLBACK_COLOR,
|
||||
type: 'manual',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['ignored-hint'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.ignoredHintColor || FALLBACK_COLOR,
|
||||
type: 'ignored-hint',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['manual-redaction'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.manualRedactionColor || FALLBACK_COLOR,
|
||||
type: 'manual-redaction',
|
||||
},
|
||||
true,
|
||||
);
|
||||
// dictionary actions
|
||||
dictionaryData['recommendation'] = new Dictionary(
|
||||
{
|
||||
hexColor: '#c5d3eb',
|
||||
type: 'recommendation',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['remove-only-here'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.analysisColor || FALLBACK_COLOR,
|
||||
type: 'remove-only-here',
|
||||
},
|
||||
true,
|
||||
);
|
||||
// generic suggestions
|
||||
dictionaryData['suggestion'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.requestAdd || FALLBACK_COLOR,
|
||||
type: 'suggestion',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['suggestion-add'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.requestAdd || FALLBACK_COLOR,
|
||||
type: 'suggestion-add',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
// add suggestions
|
||||
dictionaryData['suggestion-change-legal-basis'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.requestAdd || FALLBACK_COLOR,
|
||||
type: 'suggestion-change-legal-basis',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['suggestion-recategorize-image'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.requestAdd || FALLBACK_COLOR,
|
||||
type: 'suggestion-recategorize-image',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['suggestion-add-dictionary'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.dictionaryRequestColor || FALLBACK_COLOR,
|
||||
type: 'suggestion-add',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['suggestion-resize'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.dictionaryRequestColor || FALLBACK_COLOR,
|
||||
type: 'suggestion-resize',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['suggestion-remove'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.requestRemove || FALLBACK_COLOR,
|
||||
type: 'suggestion-add',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['suggestion-remove-dictionary'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.dictionaryRequestColor || FALLBACK_COLOR,
|
||||
type: 'suggestion-add',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['skipped'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.notRedacted || FALLBACK_COLOR,
|
||||
type: 'skipped',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['default'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.defaultColor || FALLBACK_COLOR,
|
||||
type: 'default',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['add'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.requestAdd || FALLBACK_COLOR,
|
||||
type: 'add',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['analysis'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.analysisColor || FALLBACK_COLOR,
|
||||
type: 'analysis',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['hint'] = new Dictionary(
|
||||
{
|
||||
hexColor: '#fa98f7',
|
||||
type: 'hint',
|
||||
hint: true,
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['redaction'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.manualRedactionColor || FALLBACK_COLOR,
|
||||
type: 'redaction',
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
dictionaryData['updated'] = new Dictionary(
|
||||
{
|
||||
hexColor: colors.updatedColor || FALLBACK_COLOR,
|
||||
type: 'updated',
|
||||
},
|
||||
true,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
return forkJoin([typeObs, colorsObs]).pipe(map(() => dictionaryData));
|
||||
}
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
export const CHANGED_CHECK_INTERVAL = 5000;
|
||||
export const FALLBACK_COLOR = '#CCCCCC';
|
||||
|
||||
@ -8,8 +8,6 @@ export const currentComponentRoute = filter(
|
||||
event => event instanceof ActivationEnd && !!event.snapshot.component && event.snapshot.component !== BaseScreenComponent,
|
||||
);
|
||||
|
||||
export const FALLBACK_COLOR = '#CCCCCC';
|
||||
|
||||
export function groupBy(xs: List<unknown>, key: string) {
|
||||
return xs.reduce((rv, x) => {
|
||||
(rv[x[key]] = rv[x[key]] || []).push(x);
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 492ac8d7c046d6a22a6d3ac07d569721fb14082e
|
||||
Subproject commit b040815b8568d8a4fce8faef2afc57fe6fce2e10
|
||||
@ -1,7 +1,7 @@
|
||||
import { IListable, List } from '@iqser/common-ui';
|
||||
import { Entity, List } from '@iqser/common-ui';
|
||||
import { IDictionary } from './dictionary';
|
||||
|
||||
export class Dictionary implements IDictionary, IListable {
|
||||
export class Dictionary extends Entity<IDictionary> implements IDictionary {
|
||||
readonly addToDictionaryAction: boolean;
|
||||
readonly caseInsensitive: boolean;
|
||||
readonly description: string;
|
||||
@ -15,6 +15,7 @@ export class Dictionary implements IDictionary, IListable {
|
||||
readonly type: string;
|
||||
|
||||
constructor(dictionary: IDictionary, readonly virtual = false) {
|
||||
super(dictionary);
|
||||
this.addToDictionaryAction = !!dictionary.addToDictionaryAction;
|
||||
this.caseInsensitive = !!dictionary.caseInsensitive;
|
||||
this.description = dictionary.description ?? '';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user