TypeValueWrapper => TypeValue

This commit is contained in:
Dan Percic 2021-09-25 21:41:55 +03:00
parent 5387fef462
commit 07123ef70b
13 changed files with 125 additions and 163 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<AddEditDictionaryDialogComponent>,
@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<any>;
async saveDictionary(): Promise<void> {
const typeValue: ITypeValue = this._formToObject();
let observable: Observable<unknown>;
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,

View File

@ -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<TypeValueWrapper> implements OnInit {
export class DictionaryListingScreenComponent extends ListingComponent<TypeValue> implements OnInit {
readonly iconButtonTypes = IconButtonTypes;
readonly circleButtonTypes = CircleButtonTypes;
readonly currentUser = this._userService.currentUser;
readonly tableHeaderLabel = _('dictionary-listing.table-header.title');
tableColumnConfigs: TableColumnConfig<TypeValueWrapper>[];
tableColumnConfigs: TableColumnConfig<TypeValue>[];
chartData: DoughnutChartConfig[] = [];
@ViewChild('labelTemplate', { static: true }) labelTemplate: TemplateRef<never>;
@ViewChild('rankTemplate', { static: true }) rankTemplate: TemplateRef<never>;
@ViewChild('iconTemplate', { static: true }) iconTemplate: TemplateRef<never>;
protected readonly _primaryKey = 'type';
constructor(
protected readonly _injector: Injector,
@ -58,7 +57,7 @@ export class DictionaryListingScreenComponent extends ListingComponent<TypeValue
_appStateService.activateDossierTemplate(_activatedRoute.snapshot.params.dossierTemplateId);
}
routerLinkFn = (entity: TypeValueWrapper) => [entity.type];
routerLinkFn = (entity: TypeValue) => [entity.type];
ngOnInit(): void {
this._configureTableColumns();
@ -82,7 +81,7 @@ export class DictionaryListingScreenComponent extends ListingComponent<TypeValue
});
}
openAddEditDictionaryDialog($event?: MouseEvent, dictionary?: TypeValueWrapper) {
openAddEditDictionaryDialog($event?: MouseEvent, dictionary?: TypeValue) {
this._dialogService.openDialog(
'addEditDictionary',
$event,
@ -104,7 +103,7 @@ export class DictionaryListingScreenComponent extends ListingComponent<TypeValue
this.tableColumnConfigs = [
{
label: _('dictionary-listing.table-col-names.type'),
sortByKey: 'label',
sortByKey: 'searchKey',
width: '2fr',
template: this.labelTemplate
},

View File

@ -8,7 +8,7 @@ import { ComponentHasChanges } from '@guards/can-deactivate.guard';
import { AdminDialogService } from '../../services/admin-dialog.service';
import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component';
import { DictionarySaveService } from '@shared/services/dictionary-save.service';
import { TypeValueWrapper } from '@models/file/type-value.wrapper';
import { TypeValue } from '@models/file/type-value';
import { CircleButtonTypes, LoadingService } from '@iqser/common-ui';
import { UserService } from '@services/user.service';
@ -21,7 +21,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
readonly currentUser = this._userService.currentUser;
entries: string[] = [];
dictionary: TypeValueWrapper;
dictionary: TypeValue;
@ViewChild('dictionaryManager', { static: false })
private readonly _dictionaryManager: DictionaryManagerComponent;

View File

@ -10,7 +10,7 @@ import { ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry
import { ManualAnnotationService } from '../../services/manual-annotation.service';
import { ManualAnnotationResponse } from '@models/file/manual-annotation-response';
import { PermissionsService } from '@services/permissions.service';
import { TypeValueWrapper } from '@models/file/type-value.wrapper';
import { TypeValue } from '@models/file/type-value';
export interface LegalBasisOption {
label?: string;
@ -30,7 +30,7 @@ export class ManualAnnotationDialogComponent implements OnInit {
isDictionaryRequest: boolean;
isFalsePositiveRequest: boolean;
redactionDictionaries: TypeValueWrapper[] = [];
redactionDictionaries: TypeValue[] = [];
legalOptions: LegalBasisOption[] = [];
constructor(

View File

@ -1,5 +1,5 @@
import { Component, ElementRef, Input, OnChanges, ViewChild } from '@angular/core';
import { TypeValueWrapper } from '@models/file/type-value.wrapper';
import { TypeValue } from '@models/file/type-value';
@Component({
selector: 'redaction-annotation-icon',
@ -10,7 +10,7 @@ export class AnnotationIconComponent implements OnChanges {
@Input() color: string;
@Input() type: 'square' | 'rhombus' | 'circle' | 'hexagon' | 'none';
@Input() label: string;
@Input() dictType: TypeValueWrapper;
@Input() dictType: TypeValue;
@ViewChild('icon', { static: true }) icon: ElementRef;

View File

@ -1,6 +1,6 @@
import { Component, Input, OnChanges } from '@angular/core';
import { AppStateService } from '@state/app-state.service';
import { TypeValueWrapper } from '@models/file/type-value.wrapper';
import { TypeValue } from '@models/file/type-value';
@Component({
selector: 'redaction-dictionary-annotation-icon',
@ -19,7 +19,7 @@ export class DictionaryAnnotationIconComponent implements OnChanges {
ngOnChanges(): void {
if (this.dictionaryKey) {
const typeValue: TypeValueWrapper = this._appStateService.getDictionaryTypeValue(this.dictionaryKey, this.dossierTemplateId);
const typeValue: TypeValue = this._appStateService.getDictionaryTypeValue(this.dictionaryKey, this.dossierTemplateId);
this.color = this._appStateService.getDictionaryColor(this.dictionaryKey, this.dossierTemplateId);
this.type = typeValue.hint ? 'circle' : 'square';
this.label = this.dictionaryKey[0].toUpperCase();

View File

@ -18,7 +18,7 @@ import { catchError, map, tap } from 'rxjs/operators';
import { FALLBACK_COLOR, hexToRgb } from '@utils/functions';
import { FileStatusWrapper } from '@models/file/file-status.wrapper';
import { Dossier } from './model/dossier';
import { TypeValueWrapper } from '@models/file/type-value.wrapper';
import { TypeValue } from '@models/file/type-value';
import { DossierTemplateModelWrapper } from '@models/file/dossier-template-model.wrapper';
import { DossiersService } from '../modules/dossier/services/dossiers.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -85,9 +85,9 @@ export class AppStateService {
});
}
private _dictionaryData: { [key: string]: { [key: string]: TypeValueWrapper } } = null;
private _dictionaryData: { [key: string]: { [key: string]: TypeValue } } = null;
get dictionaryData(): { [key: string]: { [key: string]: TypeValueWrapper } } {
get dictionaryData(): { [key: string]: { [key: string]: TypeValue } } {
return this._dictionaryData;
}
@ -111,7 +111,7 @@ export class AppStateService {
return this._appState.activeDictionaryType;
}
get activeDictionary(): TypeValueWrapper {
get activeDictionary(): TypeValue {
return this.activeDossierTemplateId && this.dictionaryData[this.activeDossierTemplateId]
? this.dictionaryData[this.activeDossierTemplateId][this.activeDictionaryType]
: null;
@ -191,7 +191,7 @@ export class AppStateService {
return this.dossierTemplates.find(rs => 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
);
})

View File

@ -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<any>;
public addType(body: ITypeValue, dossierId?: string, observe?: 'body', reportProgress?: boolean): Observable<any>;
public addType(body: TypeValue, dossierId?: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
public addType(body: ITypeValue, dossierId?: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
public addType(body: TypeValue, dossierId?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
public addType(body: ITypeValue, dossierId?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
public addType(body: TypeValue, dossierId?: string, observe: any = 'body', reportProgress: boolean = false): Observable<any> {
public addType(body: ITypeValue, dossierId?: string, observe: any = 'body', reportProgress: boolean = false): Observable<any> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling addType.');
}

View File

@ -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<TypeValue>;
types?: Array<ITypeValue>;
}

View File

@ -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;
}