From 07123ef70b72fa003622dac9ea980415a5e5abda Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sat, 25 Sep 2021 21:41:55 +0300 Subject: [PATCH] TypeValueWrapper => TypeValue --- .../src/app/models/file/file-data.model.ts | 4 +- apps/red-ui/src/app/models/file/type-value.ts | 37 ++++++++ .../src/app/models/file/type-value.wrapper.ts | 50 ---------- .../add-edit-dictionary-dialog.component.ts | 19 ++-- .../dictionary-listing-screen.component.ts | 15 ++- .../dictionary-overview-screen.component.ts | 4 +- .../manual-annotation-dialog.component.ts | 4 +- .../annotation-icon.component.ts | 4 +- .../dictionary-annotation-icon.component.ts | 4 +- .../red-ui/src/app/state/app-state.service.ts | 91 +++++++------------ .../lib/api/dictionaryController.service.ts | 30 +++--- .../red-ui-http/src/lib/model/typeResponse.ts | 4 +- libs/red-ui-http/src/lib/model/typeValue.ts | 22 ++--- 13 files changed, 125 insertions(+), 163 deletions(-) create mode 100644 apps/red-ui/src/app/models/file/type-value.ts delete mode 100644 apps/red-ui/src/app/models/file/type-value.wrapper.ts diff --git a/apps/red-ui/src/app/models/file/file-data.model.ts b/apps/red-ui/src/app/models/file/file-data.model.ts index 036d91ad1..4a44df195 100644 --- a/apps/red-ui/src/app/models/file/file-data.model.ts +++ b/apps/red-ui/src/app/models/file/file-data.model.ts @@ -4,7 +4,7 @@ import { UserWrapper } from '@services/user.service'; import { AnnotationWrapper } from './annotation.wrapper'; import { RedactionLogEntryWrapper } from './redaction-log-entry.wrapper'; import { ViewMode } from './view-mode'; -import { TypeValueWrapper } from './type-value.wrapper'; +import { TypeValue } from './type-value'; export class AnnotationData { visibleAnnotations: AnnotationWrapper[]; @@ -21,7 +21,7 @@ export class FileDataModel { ) {} getAnnotations( - dictionaryData: { [p: string]: TypeValueWrapper }, + dictionaryData: { [p: string]: TypeValue }, currentUser: UserWrapper, viewMode: ViewMode, areDevFeaturesEnabled: boolean diff --git a/apps/red-ui/src/app/models/file/type-value.ts b/apps/red-ui/src/app/models/file/type-value.ts new file mode 100644 index 000000000..208805f64 --- /dev/null +++ b/apps/red-ui/src/app/models/file/type-value.ts @@ -0,0 +1,37 @@ +import { IListable } from '@iqser/common-ui'; +import { ITypeValue } from '@redaction/red-ui-http'; + +export class TypeValue implements ITypeValue, IListable { + readonly type: string; + readonly addToDictionaryAction: boolean; + readonly caseInsensitive: boolean; + readonly description?: string; + readonly dossierTemplateId?: string; + readonly hexColor?: string; + readonly label?: string; + readonly hint: boolean; + readonly rank?: number; + readonly recommendation: boolean; + entries: string[] = []; + + constructor(typeValue: ITypeValue, readonly virtual = false) { + this.type = typeValue.type; + this.addToDictionaryAction = !!typeValue.addToDictionaryAction; + this.caseInsensitive = !!typeValue.caseInsensitive; + this.description = typeValue.description; + this.dossierTemplateId = typeValue.dossierTemplateId; + this.hexColor = typeValue.hexColor; + this.hint = !!typeValue.hint; + this.rank = typeValue.rank; + this.recommendation = !!typeValue.recommendation; + this.label = typeValue.label; + } + + get id(): string { + return this.type; + } + + get searchKey(): string { + return this.type; + } +} diff --git a/apps/red-ui/src/app/models/file/type-value.wrapper.ts b/apps/red-ui/src/app/models/file/type-value.wrapper.ts deleted file mode 100644 index 1b19947dc..000000000 --- a/apps/red-ui/src/app/models/file/type-value.wrapper.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { IListable } from '@iqser/common-ui'; -import { TypeValue } from '@redaction/red-ui-http'; - -export class TypeValueWrapper implements IListable { - entries: string[] = []; - - constructor(public typeValue: TypeValue, public label?: string, public virtual?: boolean) { - this.label = label || typeValue.label; - } - - get id() { - return this.typeValue.type; - } - - get addToDictionaryAction() { - return this.typeValue.addToDictionaryAction; - } - - get caseInsensitive() { - return this.typeValue.caseInsensitive; - } - - get description() { - return this.typeValue.description; - } - - get dossierTemplateId() { - return this.typeValue.dossierTemplateId; - } - - get hexColor() { - return this.typeValue.hexColor; - } - - get hint() { - return this.typeValue.hint; - } - - get rank() { - return this.typeValue.rank; - } - - get recommendation() { - return this.typeValue.recommendation; - } - - get type() { - return this.typeValue.type; - } -} diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts index 8ca6130a2..c8054ee1b 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts @@ -1,11 +1,11 @@ import { Component, Inject } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { DictionaryControllerService, TypeValue } from '@redaction/red-ui-http'; +import { DictionaryControllerService, ITypeValue } from '@redaction/red-ui-http'; import { Observable } from 'rxjs'; import { Toaster } from '@iqser/common-ui'; import { TranslateService } from '@ngx-translate/core'; -import { TypeValueWrapper } from '@models/file/type-value.wrapper'; +import { TypeValue } from '@models/file/type-value'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { AppStateService } from '@state/app-state.service'; import { toKebabCase } from '@utils/functions'; @@ -17,7 +17,7 @@ import { toKebabCase } from '@utils/functions'; }) export class AddEditDictionaryDialogComponent { dictionaryForm: FormGroup; - readonly dictionary: TypeValueWrapper; + readonly dictionary: TypeValue; technicalName = ''; private readonly _dossierTemplateId: string; @@ -29,7 +29,7 @@ export class AddEditDictionaryDialogComponent { private readonly _translateService: TranslateService, private readonly _dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) - private readonly _data: { dictionary: TypeValueWrapper; dossierTemplateId: string } + private readonly _data: { dictionary: TypeValue; dossierTemplateId: string } ) { this.dictionary = _data.dictionary; this._dossierTemplateId = _data.dossierTemplateId; @@ -81,17 +81,16 @@ export class AddEditDictionaryDialogComponent { return false; } - async saveDictionary() { - const typeValue: TypeValue = this._formToObject(); - let observable: Observable; + async saveDictionary(): Promise { + const typeValue: ITypeValue = this._formToObject(); + let observable: Observable; if (this.dictionary) { // edit mode observable = this._dictionaryControllerService.updateType(typeValue, this._dossierTemplateId, typeValue.type); } else { // create mode - typeValue.dossierTemplateId = this._dossierTemplateId; - observable = this._dictionaryControllerService.addType(typeValue); + observable = this._dictionaryControllerService.addType({ ...typeValue, dossierTemplateId: this._dossierTemplateId }); } observable.subscribe( @@ -120,7 +119,7 @@ export class AddEditDictionaryDialogComponent { this.technicalName = technicalName; } - private _formToObject(): TypeValue { + private _formToObject(): ITypeValue { return { type: this.dictionary?.type || this.technicalName, label: this.dictionaryForm.get('label').value, diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts index e6eff876d..258dc62ce 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts @@ -5,7 +5,7 @@ import { AppStateService } from '@state/app-state.service'; import { catchError, defaultIfEmpty, tap } from 'rxjs/operators'; import { forkJoin, of } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { TypeValueWrapper } from '@models/file/type-value.wrapper'; +import { TypeValue } from '@models/file/type-value'; import { TranslateService } from '@ngx-translate/core'; import { CircleButtonTypes, @@ -19,7 +19,7 @@ import { AdminDialogService } from '../../services/admin-dialog.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { UserService } from '@services/user.service'; -const toChartConfig = (dict: TypeValueWrapper): DoughnutChartConfig => ({ +const toChartConfig = (dict: TypeValue): DoughnutChartConfig => ({ value: dict.entries?.length ?? 0, color: dict.hexColor, label: dict.label, @@ -31,17 +31,16 @@ const toChartConfig = (dict: TypeValueWrapper): DoughnutChartConfig => ({ styleUrls: ['./dictionary-listing-screen.component.scss'], providers: [...DefaultListingServices, { provide: ListingComponent, useExisting: forwardRef(() => DictionaryListingScreenComponent) }] }) -export class DictionaryListingScreenComponent extends ListingComponent implements OnInit { +export class DictionaryListingScreenComponent extends ListingComponent implements OnInit { readonly iconButtonTypes = IconButtonTypes; readonly circleButtonTypes = CircleButtonTypes; readonly currentUser = this._userService.currentUser; readonly tableHeaderLabel = _('dictionary-listing.table-header.title'); - tableColumnConfigs: TableColumnConfig[]; + tableColumnConfigs: TableColumnConfig[]; chartData: DoughnutChartConfig[] = []; @ViewChild('labelTemplate', { static: true }) labelTemplate: TemplateRef; @ViewChild('rankTemplate', { static: true }) rankTemplate: TemplateRef; @ViewChild('iconTemplate', { static: true }) iconTemplate: TemplateRef; - protected readonly _primaryKey = 'type'; constructor( protected readonly _injector: Injector, @@ -58,7 +57,7 @@ export class DictionaryListingScreenComponent extends ListingComponent [entity.type]; + routerLinkFn = (entity: TypeValue) => [entity.type]; ngOnInit(): void { this._configureTableColumns(); @@ -82,7 +81,7 @@ export class DictionaryListingScreenComponent extends ListingComponent rs.dossierTemplateId === id); } - getDictionaryTypeValue(key: string, dossierTemplateId?: string): TypeValueWrapper { + getDictionaryTypeValue(key: string, dossierTemplateId?: string): TypeValue { if (!dossierTemplateId && this.activeDossier) { dossierTemplateId = this.activeDossier.dossierTemplateId; } @@ -446,7 +446,7 @@ export class AppStateService { const typeObs = this._dictionaryControllerService.getAllTypes(dossierTemplateId).pipe( tap(typesResponse => { for (const type of typesResponse.types) { - dictionaryData[type.type] = new TypeValueWrapper(type); + dictionaryData[type.type] = new TypeValue(type); } }) ); @@ -465,207 +465,184 @@ export class AppStateService { } } - // declined - dictionaryData['declined-suggestion'] = new TypeValueWrapper( + dictionaryData['declined-suggestion'] = new TypeValue( { hexColor: colors.notRedacted, type: 'declined-suggestion' }, - null, true ); - // manual - dictionaryData['manual'] = new TypeValueWrapper( + + dictionaryData['manual'] = new TypeValue( { hexColor: colors.manualRedactionColor, type: 'manual' }, - null, true ); - // manual - dictionaryData['manual-redaction'] = new TypeValueWrapper( + + dictionaryData['manual-redaction'] = new TypeValue( { hexColor: colors.manualRedactionColor, type: 'manual-redaction' }, - null, true ); // dictionary actions - dictionaryData['recommendation'] = new TypeValueWrapper( + dictionaryData['recommendation'] = new TypeValue( { hexColor: '#c5d3eb', type: 'recommendation' }, - null, true ); // dictionary actions - dictionaryData['add-dictionary'] = new TypeValueWrapper( + dictionaryData['add-dictionary'] = new TypeValue( { hexColor: colors.analysisColor, type: 'add-dictionary' }, - null, true ); - dictionaryData['remove-dictionary'] = new TypeValueWrapper( + dictionaryData['remove-dictionary'] = new TypeValue( { hexColor: colors.analysisColor, type: 'remove-dictionary' }, - null, true ); - dictionaryData['remove-only-here'] = new TypeValueWrapper( + dictionaryData['remove-only-here'] = new TypeValue( { hexColor: colors.analysisColor, type: 'remove-only-here' }, - null, true ); // generic suggestions - dictionaryData['suggestion'] = new TypeValueWrapper( + dictionaryData['suggestion'] = new TypeValue( { hexColor: colors.requestAdd, type: 'suggestion' }, - null, true ); - // add suggestions - dictionaryData['suggestion-add'] = new TypeValueWrapper( + + dictionaryData['suggestion-add'] = new TypeValue( { hexColor: colors.requestAdd, type: 'suggestion-add' }, - null, true ); // add suggestions - dictionaryData['suggestion-change-legal-basis'] = new TypeValueWrapper( + dictionaryData['suggestion-change-legal-basis'] = new TypeValue( { hexColor: colors.requestAdd, type: 'suggestion-change-legal-basis' }, - null, true ); - dictionaryData['suggestion-recategorize-image'] = new TypeValueWrapper( + dictionaryData['suggestion-recategorize-image'] = new TypeValue( { hexColor: colors.requestAdd, type: 'suggestion-recategorize-image' }, - null, true ); - dictionaryData['suggestion-add-dictionary'] = new TypeValueWrapper( + dictionaryData['suggestion-add-dictionary'] = new TypeValue( { hexColor: colors.dictionaryRequestColor, type: 'suggestion-add' }, - null, true ); - // suggestion remove - dictionaryData['suggestion-remove'] = new TypeValueWrapper( + + dictionaryData['suggestion-remove'] = new TypeValue( { hexColor: colors.requestRemove, type: 'suggestion-add' }, - null, true ); - dictionaryData['suggestion-remove-dictionary'] = new TypeValueWrapper( + dictionaryData['suggestion-remove-dictionary'] = new TypeValue( { hexColor: colors.dictionaryRequestColor, type: 'suggestion-add' }, - null, true ); - dictionaryData['skipped'] = new TypeValueWrapper( + dictionaryData['skipped'] = new TypeValue( { hexColor: colors.notRedacted, type: 'skipped' }, - null, true ); - dictionaryData['default'] = new TypeValueWrapper( + dictionaryData['default'] = new TypeValue( { hexColor: colors.defaultColor, type: 'default' }, - null, true ); - dictionaryData['add'] = new TypeValueWrapper( + dictionaryData['add'] = new TypeValue( { hexColor: colors.requestAdd, type: 'add' }, - null, true ); - dictionaryData['analysis'] = new TypeValueWrapper( + + dictionaryData['analysis'] = new TypeValue( { hexColor: colors.analysisColor, type: 'analysis' }, - null, true ); - dictionaryData['pending-analysis'] = new TypeValueWrapper( + dictionaryData['pending-analysis'] = new TypeValue( { hexColor: colors.analysisColor, type: 'analysis' }, - null, true ); - dictionaryData['change-legal-basis'] = new TypeValueWrapper( + dictionaryData['change-legal-basis'] = new TypeValue( { hexColor: colors.analysisColor, type: 'analysis' }, - null, true ); - dictionaryData['hint'] = new TypeValueWrapper( + dictionaryData['hint'] = new TypeValue( { hexColor: '#fa98f7', type: 'hint', hint: true }, - null, true ); - dictionaryData['redaction'] = new TypeValueWrapper( + dictionaryData['redaction'] = new TypeValue( { hexColor: colors.previewColor, type: 'redaction' }, - null, true ); - dictionaryData['updated'] = new TypeValueWrapper( + dictionaryData['updated'] = new TypeValue( { hexColor: colors.updatedColor, type: 'updated' }, - null, true ); }) diff --git a/libs/red-ui-http/src/lib/api/dictionaryController.service.ts b/libs/red-ui-http/src/lib/api/dictionaryController.service.ts index ce77d7944..7cf6bece3 100644 --- a/libs/red-ui-http/src/lib/api/dictionaryController.service.ts +++ b/libs/red-ui-http/src/lib/api/dictionaryController.service.ts @@ -10,20 +10,20 @@ * Do not edit the class manually. */ /* tslint:disable:no-unused-variable member-ordering */ -import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'; -import { CustomHttpUrlEncodingCodec } from '../encoder'; +import { Inject, Injectable, Optional } from "@angular/core"; +import { HttpClient, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from "@angular/common/http"; +import { CustomHttpUrlEncodingCodec } from "../encoder"; -import { Observable } from 'rxjs'; +import { Observable } from "rxjs"; -import { Colors } from '../model/colors'; -import { Dictionary } from '../model/dictionary'; -import { TypeResponse } from '../model/typeResponse'; -import { TypeValue } from '../model/typeValue'; -import { UpdateTypeValue } from '../model/updateTypeValue'; +import { Colors } from "../model/colors"; +import { Dictionary } from "../model/dictionary"; +import { TypeResponse } from "../model/typeResponse"; +import { ITypeValue } from "../model/typeValue"; +import { UpdateTypeValue } from "../model/updateTypeValue"; -import { BASE_PATH } from '../variables'; -import { Configuration } from '../configuration'; +import { BASE_PATH } from "../variables"; +import { Configuration } from "../configuration"; @Injectable() export class DictionaryControllerService { @@ -160,13 +160,13 @@ export class DictionaryControllerService { * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public addType(body: TypeValue, dossierId?: string, observe?: 'body', reportProgress?: boolean): Observable; + public addType(body: ITypeValue, dossierId?: string, observe?: 'body', reportProgress?: boolean): Observable; - public addType(body: TypeValue, dossierId?: string, observe?: 'response', reportProgress?: boolean): Observable>; + public addType(body: ITypeValue, dossierId?: string, observe?: 'response', reportProgress?: boolean): Observable>; - public addType(body: TypeValue, dossierId?: string, observe?: 'events', reportProgress?: boolean): Observable>; + public addType(body: ITypeValue, dossierId?: string, observe?: 'events', reportProgress?: boolean): Observable>; - public addType(body: TypeValue, dossierId?: string, observe: any = 'body', reportProgress: boolean = false): Observable { + public addType(body: ITypeValue, dossierId?: string, observe: any = 'body', reportProgress: boolean = false): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addType.'); } diff --git a/libs/red-ui-http/src/lib/model/typeResponse.ts b/libs/red-ui-http/src/lib/model/typeResponse.ts index 59e88f092..7093440c6 100644 --- a/libs/red-ui-http/src/lib/model/typeResponse.ts +++ b/libs/red-ui-http/src/lib/model/typeResponse.ts @@ -9,7 +9,7 @@ * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ -import { TypeValue } from './typeValue'; +import { ITypeValue } from "./typeValue"; /** * Object containing a list of values of an entry type. @@ -18,5 +18,5 @@ export interface TypeResponse { /** * The list of values of an entry type, which include colors, hint and caseInsensitive. */ - types?: Array; + types?: Array; } diff --git a/libs/red-ui-http/src/lib/model/typeValue.ts b/libs/red-ui-http/src/lib/model/typeValue.ts index c46a17a52..1eccf2099 100644 --- a/libs/red-ui-http/src/lib/model/typeValue.ts +++ b/libs/red-ui-http/src/lib/model/typeValue.ts @@ -13,45 +13,45 @@ /** * Object containing entry type with an array of r-g-b colors. */ -export interface TypeValue { +export interface ITypeValue { /** * If true the ui will add a action to add values to dictionary */ - addToDictionaryAction?: boolean; + readonly addToDictionaryAction?: boolean; /** * True if the entries in this type should be matched case insensitively, default is false. */ - caseInsensitive?: boolean; + readonly caseInsensitive?: boolean; /** * The description of the dictionary type */ - description?: string; + readonly description?: string; /** * The DossierTemplate Id for this type */ - dossierTemplateId?: string; + readonly dossierTemplateId?: string; /** * The value of color must be a correct hex color */ - hexColor?: string; + readonly hexColor?: string; /** * True if the type just for hint, not for redaction, default is false. */ - hint?: boolean; + readonly hint?: boolean; /** * The rank of this dictionary, higher rank means higher importance. */ - rank?: number; + readonly rank?: number; /** * True if the type just for recommendations, not for redaction, default is false. */ - recommendation?: boolean; + readonly recommendation?: boolean; /** * The nonnull entry type. */ - type?: string; + readonly type?: string; /** * The label of this type */ - label?: string; + readonly label?: string; }