From 615a45d91d78959d02f22baa61171885c4105f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 7 Jan 2021 22:53:09 +0200 Subject: [PATCH] Rule sets --- apps/red-ui/src/app/app.module.ts | 18 +- .../file-actions/file-actions.component.scss | 4 + .../app/common/service/permissions.service.ts | 5 +- .../admin-breadcrumbs.component.html | 35 ++- .../admin-breadcrumbs.component.ts | 25 +-- .../dictionary-annotation-icon.component.ts | 5 +- .../needs-work-badge.component.ts | 7 +- .../rule-set-actions.component.ts | 11 +- .../rule-set-view-switch.component.html | 1 + .../rule-set-view-switch.component.ts | 17 +- .../type-filter/type-filter.component.ts | 3 +- apps/red-ui/src/app/dialogs/dialog.service.ts | 13 +- .../manual-annotation-dialog.component.ts | 9 +- .../add-edit-dictionary-dialog.component.ts | 17 +- .../dictionary-listing-screen.component.html | 2 +- .../dictionary-listing-screen.component.ts | 23 +- .../dictionary-overview-screen.component.html | 5 +- .../dictionary-overview-screen.component.scss | 4 - .../dictionary-overview-screen.component.ts | 22 +- .../add-edit-rule-set-dialog.component.ts | 3 +- .../rules-screen/rules-screen.component.html | 2 +- .../rules-screen/rules-screen.component.scss | 4 - .../rules-screen/rules-screen.component.ts | 34 +-- .../watermark-screen.component.html | 6 +- .../watermark-screen.component.scss | 4 - .../watermark-screen.component.ts | 11 +- .../file-preview-screen.component.scss | 4 + .../file-preview-screen.component.ts | 2 +- .../red-ui/src/app/state/app-state.service.ts | 209 ++++++++++++------ apps/red-ui/src/assets/styles/red-editor.scss | 1 + .../src/assets/styles/red-toggle-button.scss | 8 +- 31 files changed, 288 insertions(+), 226 deletions(-) diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index b3f4625ce..1b21c2483 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -218,6 +218,15 @@ const routes = [ routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] } }, + { + path: 'watermark', + component: WatermarkScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard], + requiredRoles: ['RED_ADMIN'] + } + }, { path: '', redirectTo: 'dictionaries', pathMatch: 'full' } ] } @@ -230,15 +239,6 @@ const routes = [ data: { routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] } - }, - { - path: 'watermark', - component: WatermarkScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard], - requiredRoles: ['RED_ADMIN'] - } } ] } diff --git a/apps/red-ui/src/app/common/file-actions/file-actions.component.scss b/apps/red-ui/src/app/common/file-actions/file-actions.component.scss index 4a9497c79..e42b0242b 100644 --- a/apps/red-ui/src/app/common/file-actions/file-actions.component.scss +++ b/apps/red-ui/src/app/common/file-actions/file-actions.component.scss @@ -16,3 +16,7 @@ margin-right: 5px; font-weight: bold; } + +redaction-status-bar { + margin-left: 2px; +} diff --git a/apps/red-ui/src/app/common/service/permissions.service.ts b/apps/red-ui/src/app/common/service/permissions.service.ts index 88f301865..7b4d35139 100644 --- a/apps/red-ui/src/app/common/service/permissions.service.ts +++ b/apps/red-ui/src/app/common/service/permissions.service.ts @@ -43,10 +43,11 @@ export class PermissionsService { if (!fileStatus) { return false; } + const project = this._appStateService.getProjectById(fileStatus.projectId); return ( ((fileStatus.status === 'UNASSIGNED' || fileStatus.status === 'UNDER_REVIEW' || fileStatus.status === 'UNDER_APPROVAL') && - (fileStatus.dictionaryVersion !== this._appStateService.dictionaryVersion || - fileStatus.rulesVersion !== this._appStateService.rulesVersion || + (fileStatus.dictionaryVersion !== this._appStateService.dictionaryVersion(project.ruleSetId) || + fileStatus.rulesVersion !== this._appStateService.rulesVersion(project.ruleSetId) || fileStatus.hasUnappliedSuggestions)) || fileStatus.isError ); diff --git a/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.html b/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.html index 33266b062..542fcde47 100644 --- a/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.html +++ b/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.html @@ -5,7 +5,7 @@ [routerLinkActiveOptions]="{ exact: true }" routerLinkActive="active" translate="project-templates" - *ngIf="root || !!ruleSet" + *ngIf="root || !!appStateService.activeRuleSetId" > - - - - - - {{ ruleSet.name }} - - - - + + {{ appStateService.activeRuleSet.name }} + + + + + + - {{ dictionary.label }} + {{ appStateService.activeDictionary.label }} diff --git a/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.ts b/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.ts index d7b4e412c..c4318ebc3 100644 --- a/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.ts +++ b/apps/red-ui/src/app/components/admin-page-header/admin-breadcrumbs.component.ts @@ -1,6 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; -import { RuleSetModel, TypeValue } from '@redaction/red-ui-http'; +import { Component, Input } from '@angular/core'; import { AppStateService } from '../../state/app-state.service'; import { UserPreferenceService } from '../../common/service/user-preference.service'; import { PermissionsService } from '../../common/service/permissions.service'; @@ -10,27 +8,12 @@ import { PermissionsService } from '../../common/service/permissions.service'; templateUrl: './admin-breadcrumbs.component.html', styleUrls: ['./admin-breadcrumbs.component.scss'] }) -export class AdminBreadcrumbsComponent implements OnInit { - public dictionary: TypeValue; - public ruleSet: RuleSetModel; - @Input() - public root = false; +export class AdminBreadcrumbsComponent { + @Input() public root = false; constructor( public readonly userPreferenceService: UserPreferenceService, public readonly permissionService: PermissionsService, - private readonly _activatedRoute: ActivatedRoute, - private readonly _appStateService: AppStateService + public readonly appStateService: AppStateService ) {} - - ngOnInit(): void { - this._activatedRoute.params.subscribe((params) => { - if (params.ruleSetId) { - this.ruleSet = this._appStateService.getRuleSetById(params.ruleSetId); - } - if (params.type) { - this.dictionary = this._appStateService.getDictionaryTypeValue(params.type); - } - }); - } } diff --git a/apps/red-ui/src/app/components/dictionary-annotation-icon/dictionary-annotation-icon.component.ts b/apps/red-ui/src/app/components/dictionary-annotation-icon/dictionary-annotation-icon.component.ts index 1cb8507d3..ff202d35b 100644 --- a/apps/red-ui/src/app/components/dictionary-annotation-icon/dictionary-annotation-icon.component.ts +++ b/apps/red-ui/src/app/components/dictionary-annotation-icon/dictionary-annotation-icon.component.ts @@ -9,6 +9,7 @@ import { TypeValue } from '@redaction/red-ui-http'; }) export class DictionaryAnnotationIconComponent implements OnChanges { @Input() dictionaryKey: string; + @Input() ruleSetId: string; color: string; label: string; @@ -18,8 +19,8 @@ export class DictionaryAnnotationIconComponent implements OnChanges { ngOnChanges(): void { if (this.dictionaryKey) { - const typeValue: TypeValue = this._appStateService.getDictionaryTypeValue(this.dictionaryKey); - this.color = this._appStateService.getDictionaryColor(this.dictionaryKey); + const typeValue: TypeValue = this._appStateService.getDictionaryTypeValue(this.dictionaryKey, this.ruleSetId); + this.color = this._appStateService.getDictionaryColor(this.dictionaryKey, this.ruleSetId); this.type = typeValue.hint ? 'circle' : 'square'; this.label = this.dictionaryKey[0].toUpperCase(); } diff --git a/apps/red-ui/src/app/components/needs-work-badge/needs-work-badge.component.ts b/apps/red-ui/src/app/components/needs-work-badge/needs-work-badge.component.ts index 123fb44a0..3617529a4 100644 --- a/apps/red-ui/src/app/components/needs-work-badge/needs-work-badge.component.ts +++ b/apps/red-ui/src/app/components/needs-work-badge/needs-work-badge.component.ts @@ -25,6 +25,11 @@ export class NeedsWorkBadgeComponent implements OnInit { } get suggestionColor() { - return this.appStateService.getDictionaryColor('suggestion'); + let ruleSetId = null; + if (this.needsWorkInput instanceof ProjectWrapper) { + ruleSetId = this.needsWorkInput.ruleSetId; + } + + return this.appStateService.getDictionaryColor('suggestion', ruleSetId); } } diff --git a/apps/red-ui/src/app/components/rule-set-actions/rule-set-actions.component.ts b/apps/red-ui/src/app/components/rule-set-actions/rule-set-actions.component.ts index 849d3cc12..d4c4d947b 100644 --- a/apps/red-ui/src/app/components/rule-set-actions/rule-set-actions.component.ts +++ b/apps/red-ui/src/app/components/rule-set-actions/rule-set-actions.component.ts @@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { DialogService } from '../../dialogs/dialog.service'; import { PermissionsService } from '../../common/service/permissions.service'; import { RuleSetModel } from '@redaction/red-ui-http'; +import { AppStateService } from '../../state/app-state.service'; @Component({ selector: 'redaction-rule-set-actions', @@ -12,7 +13,15 @@ export class RuleSetActionsComponent implements OnInit { @Input() ruleSet: RuleSetModel; @Output() loadRuleSetsData = new EventEmitter(); - constructor(private readonly _dialogService: DialogService, public readonly permissionsService: PermissionsService) {} + constructor( + private readonly _dialogService: DialogService, + private readonly _appStateService: AppStateService, + public readonly permissionsService: PermissionsService + ) { + if (!this.ruleSet) { + this.ruleSet = this._appStateService.activeRuleSet; + } + } ngOnInit(): void {} diff --git a/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.html b/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.html index a1d64e213..fa73c8be7 100644 --- a/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.html +++ b/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.html @@ -3,6 +3,7 @@ {{ 'dictionaries' | translate }} {{ 'rule-editor' | translate }} + {{ 'watermark' | translate }} diff --git a/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.ts b/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.ts index c5ef646b8..c2b0e8fa4 100644 --- a/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.ts +++ b/apps/red-ui/src/app/components/rule-set-view-switch/rule-set-view-switch.component.ts @@ -1,5 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { Router } from '@angular/router'; +import { AppStateService } from '../../state/app-state.service'; @Component({ selector: 'redaction-rule-set-view-switch', @@ -7,21 +8,13 @@ import { ActivatedRoute, Router } from '@angular/router'; styleUrls: ['./rule-set-view-switch.component.scss'] }) export class RuleSetViewSwitchComponent implements OnInit { - @Input() public screen: 'rules' | 'dictionaries'; + @Input() public screen: 'rules' | 'dictionaries' | 'watermark'; - private readonly _ruleSetId: string; - - constructor(private readonly _actr: ActivatedRoute, private _router: Router) { - this._ruleSetId = this._actr.snapshot.params.ruleSetId; - } + constructor(private readonly _router: Router, private readonly _appStateService: AppStateService) {} ngOnInit(): void {} public switchView($event) { - if ($event.value === 'dictionaries') { - this._router.navigate(['ui/admin/project-templates/' + this._ruleSetId + '/dictionaries']); - } else { - this._router.navigate(['ui/admin/project-templates/' + this._ruleSetId + '/rules']); - } + this._router.navigate(['ui/admin/project-templates/' + this._appStateService.activeRuleSetId + '/' + $event.value]); } } diff --git a/apps/red-ui/src/app/components/type-filter/type-filter.component.ts b/apps/red-ui/src/app/components/type-filter/type-filter.component.ts index 6f460abee..ed7bbc11f 100644 --- a/apps/red-ui/src/app/components/type-filter/type-filter.component.ts +++ b/apps/red-ui/src/app/components/type-filter/type-filter.component.ts @@ -1,6 +1,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { FilterModel } from '../../common/filter/model/filter.model'; import { AppStateService } from '../../state/app-state.service'; +import { DEFAULT_RUL_SET_UUID } from '../../utils/rule-set-default'; @Component({ selector: 'redaction-type-filter', @@ -15,6 +16,6 @@ export class TypeFilterComponent implements OnInit { constructor(public appStateService: AppStateService) {} ngOnInit(): void { - this.dictionaryColor = this.appStateService.getDictionaryColor(this.filter.key); + this.dictionaryColor = this.appStateService.getDictionaryColor(this.filter.key, this.appStateService.activeProject?.ruleSetId || DEFAULT_RUL_SET_UUID); } } diff --git a/apps/red-ui/src/app/dialogs/dialog.service.ts b/apps/red-ui/src/app/dialogs/dialog.service.ts index 76a992b44..ca58650da 100644 --- a/apps/red-ui/src/app/dialogs/dialog.service.ts +++ b/apps/red-ui/src/app/dialogs/dialog.service.ts @@ -5,6 +5,7 @@ import { FileManagementControllerService, FileStatus, ManualRedactionControllerService, + RuleSetControllerService, RuleSetModel, TypeValue } from '@redaction/red-ui-http'; @@ -21,7 +22,6 @@ import { ManualAnnotationService } from '../screens/file/service/manual-annotati import { ProjectWrapper } from '../state/model/project.wrapper'; import { AddEditDictionaryDialogComponent } from '../screens/admin/dictionary-listing-screen/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component'; import { AddEditRuleSetDialogComponent } from '../screens/admin/rule-sets-listing-screen/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component'; -import { DEFAULT_RUL_SET_UUID } from '../utils/rule-set-default'; const dialogConfig = { width: '662px', @@ -37,6 +37,7 @@ export class DialogService { private readonly _dialog: MatDialog, private readonly _translateService: TranslateService, private readonly _appStateService: AppStateService, + private readonly _ruleSetControllerService: RuleSetControllerService, private readonly _dictionaryControllerService: DictionaryControllerService, private readonly _fileManagementControllerService: FileManagementControllerService, private readonly _notificationService: NotificationService, @@ -170,12 +171,12 @@ export class DialogService { return ref; } - public openDeleteDictionaryDialog($event: MouseEvent, dictionary: TypeValue, cb?: Function): MatDialogRef { + public openDeleteDictionaryDialog($event: MouseEvent, dictionary: TypeValue, ruleSetId: string, cb?: Function): MatDialogRef { $event.stopPropagation(); const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig); ref.afterClosed().subscribe(async (result) => { if (result) { - await this._dictionaryControllerService.deleteType(dictionary.type, DEFAULT_RUL_SET_UUID).toPromise(); + await this._dictionaryControllerService.deleteType(dictionary.type, ruleSetId).toPromise(); if (cb) cb(); } }); @@ -187,6 +188,8 @@ export class DialogService { const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig); ref.afterClosed().subscribe(async (result) => { if (result) { + await this._ruleSetControllerService.getAllRuleSets(ruleSet.ruleSetId).toPromise(); + await this._appStateService.loadAllRuleSets(); if (cb) cb(); } }); @@ -276,10 +279,10 @@ export class DialogService { return ref; } - public openAddEditDictionaryDialog(dictionary: TypeValue, cb?: Function): MatDialogRef { + public openAddEditDictionaryDialog(dictionary: TypeValue, ruleSetId: string, cb?: Function): MatDialogRef { const ref = this._dialog.open(AddEditDictionaryDialogComponent, { ...dialogConfig, - data: dictionary, + data: { dictionary, ruleSetId }, autoFocus: true }); diff --git a/apps/red-ui/src/app/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts b/apps/red-ui/src/app/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts index fcba3769e..c048094b9 100644 --- a/apps/red-ui/src/app/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts +++ b/apps/red-ui/src/app/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Inject, OnInit, ViewChild } from '@angular/core'; +import { Component, Inject, 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'; @@ -10,7 +10,6 @@ import { ManualRedactionEntryWrapper } from '../../screens/file/model/manual-red import { ManualAnnotationService } from '../../screens/file/service/manual-annotation.service'; import { ManualAnnotationResponse } from '../../screens/file/model/manual-annotation-response'; import { PermissionsService } from '../../common/service/permissions.service'; -import { DEFAULT_RUL_SET_UUID } from '../../utils/rule-set-default'; export interface LegalBasisOption { label?: string; @@ -57,7 +56,7 @@ export class ManualAnnotationDialogComponent implements OnInit { ) {} async ngOnInit() { - this._legalBasisMappingControllerService.getLegalBasisMapping(DEFAULT_RUL_SET_UUID).subscribe((data) => { + this._legalBasisMappingControllerService.getLegalBasisMapping(this._appStateService.activeProject.ruleSetId).subscribe((data) => { for (const key of Object.keys(data.reasonByLegalBasis)) { this.legalOptions.push({ legalBasis: key, @@ -80,8 +79,8 @@ export class ManualAnnotationDialogComponent implements OnInit { comment: this.isDocumentAdmin ? [null] : [null, Validators.required] }); - for (const key of Object.keys(this._appStateService.dictionaryData)) { - const dictionaryData = this._appStateService.dictionaryData[key]; + for (const key of Object.keys(this._appStateService.dictionaryData[this._appStateService.activeProject.ruleSetId])) { + const dictionaryData = this._appStateService.getDictionaryTypeValue(key); if (!dictionaryData.virtual && !(dictionaryData.type.indexOf('recommendation_') === 0)) { if (!dictionaryData.hint && dictionaryData.type !== 'manual') { this.redactionDictionaries.push(dictionaryData); diff --git a/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts b/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts index c30163e83..db9b3f414 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts +++ b/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, OnInit } from '@angular/core'; +import { Component, Inject } from '@angular/core'; import { AppStateService } from '../../../../state/app-state.service'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; @@ -6,7 +6,6 @@ import { DictionaryControllerService, TypeValue } from '@redaction/red-ui-http'; import { Observable } from 'rxjs'; import { NotificationService, NotificationType } from '../../../../notification/notification.service'; import { TranslateService } from '@ngx-translate/core'; -import { DEFAULT_RUL_SET_UUID } from '../../../../utils/rule-set-default'; @Component({ selector: 'redaction-add-edit-dictionary-dialog', @@ -15,6 +14,8 @@ import { DEFAULT_RUL_SET_UUID } from '../../../../utils/rule-set-default'; }) export class AddEditDictionaryDialogComponent { dictionaryForm: FormGroup; + public readonly dictionary: TypeValue; + private readonly _ruleSetId: string; constructor( private readonly _dictionaryControllerService: DictionaryControllerService, @@ -23,8 +24,10 @@ export class AddEditDictionaryDialogComponent { private readonly _notificationService: NotificationService, private readonly _translateService: TranslateService, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public dictionary: TypeValue + @Inject(MAT_DIALOG_DATA) public data: { dictionary: TypeValue; ruleSetId: string } ) { + this.dictionary = data.dictionary; + this._ruleSetId = data.ruleSetId; this.dictionaryForm = this._formBuilder.group({ type: [this.dictionary?.type, Validators.required], rank: [this.dictionary?.rank, Validators.required], @@ -60,14 +63,13 @@ export class AddEditDictionaryDialogComponent { let observable: Observable; if (this.dictionary) { // edit mode - observable = this._dictionaryControllerService.updateType(typeValue, typeValue.type, DEFAULT_RUL_SET_UUID); + observable = this._dictionaryControllerService.updateType(typeValue, typeValue.type, this._ruleSetId); } else { // create mode - typeValue.ruleSetId = DEFAULT_RUL_SET_UUID; + typeValue.ruleSetId = this._ruleSetId; observable = this._dictionaryControllerService.addType(typeValue); } - // observable.subscribe( () => { this.dialogRef.close({ dictionary: typeValue }); @@ -94,7 +96,8 @@ export class AddEditDictionaryDialogComponent { hexColor: this.dictionaryForm.get('hexColor').value, hint: this.dictionaryForm.get('hint').value, type: this.dictionaryForm.get('type').value, - rank: this.dictionaryForm.get('rank').value + rank: this.dictionaryForm.get('rank').value, + ruleSetId: this._ruleSetId }; } } diff --git a/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.html b/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.html index 7417f7e3b..2b7a4a244 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.html +++ b/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.html @@ -5,7 +5,7 @@
- +
diff --git a/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.ts b/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.ts index 9335b58bd..ea920cff6 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.ts +++ b/apps/red-ui/src/app/screens/admin/dictionary-listing-screen/dictionary-listing-screen.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { DoughnutChartConfig } from '../../../components/simple-doughnut-chart/simple-doughnut-chart.component'; -import { DictionaryControllerService, RuleSetModel, TypeValue } from '@redaction/red-ui-http'; +import { DictionaryControllerService, TypeValue } from '@redaction/red-ui-http'; import { SortingOption, SortingService } from '../../../utils/sorting.service'; import { DialogService } from '../../../dialogs/dialog.service'; import { AppStateService } from '../../../state/app-state.service'; @@ -9,7 +9,6 @@ import { forkJoin } from 'rxjs'; import { PermissionsService } from '../../../common/service/permissions.service'; import { FormBuilder, FormGroup } from '@angular/forms'; import { debounce } from '../../../utils/debounce'; -import { DEFAULT_RUL_SET_UUID } from '../../../utils/rule-set-default'; import { ActivatedRoute } from '@angular/router'; @Component({ @@ -23,24 +22,23 @@ export class DictionaryListingScreenComponent implements OnInit { public displayedDictionaries: TypeValue[]; public selectedDictKeys: string[] = []; public searchForm: FormGroup; - public ruleSet: RuleSetModel; constructor( private readonly _dialogService: DialogService, private readonly _sortingService: SortingService, private readonly _formBuilder: FormBuilder, private readonly _dictionaryControllerService: DictionaryControllerService, + private readonly _activatedRoute: ActivatedRoute, private readonly _appStateService: AppStateService, - private readonly _actr: ActivatedRoute, public readonly permissionsService: PermissionsService ) { + this._appStateService.activateRuleSet(_activatedRoute.snapshot.params.ruleSetId); + this.searchForm = this._formBuilder.group({ query: [''] }); this.searchForm.valueChanges.subscribe((value) => this._executeSearch(value)); - - this.ruleSet = this._appStateService.getRuleSetById(this._actr.snapshot.params.ruleSetId); } ngOnInit(): void { @@ -54,15 +52,14 @@ export class DictionaryListingScreenComponent implements OnInit { } private _loadDictionaryData() { - this._appStateService.reset(); - const appStateDictionaryData = this._appStateService.dictionaryData; + const appStateDictionaryData = this._appStateService.dictionaryData[this._appStateService.activeRuleSetId]; this.dictionaries = Object.keys(appStateDictionaryData) .map((key) => appStateDictionaryData[key]) .filter((d) => !d.virtual || d.type === 'false_positive'); this.displayedDictionaries = [...this.dictionaries]; const dataObs = []; this.dictionaries.forEach((item) => { - const observable = this._dictionaryControllerService.getDictionaryForType(item.type, DEFAULT_RUL_SET_UUID).pipe( + const observable = this._dictionaryControllerService.getDictionaryForType(item.type, this._appStateService.activeRuleSetId).pipe( tap((values) => { item.entries = values.entries ? values.entries : []; }) @@ -126,7 +123,7 @@ export class DictionaryListingScreenComponent implements OnInit { } openAddEditDictionaryDialog(dict?: TypeValue) { - this._dialogService.openAddEditDictionaryDialog(dict, async (newDictionary) => { + this._dialogService.openAddEditDictionaryDialog(dict, this._appStateService.activeRuleSetId, async (newDictionary) => { if (newDictionary) { await this._appStateService.loadDictionaryData(); this._loadDictionaryData(); @@ -140,13 +137,13 @@ export class DictionaryListingScreenComponent implements OnInit { } openDeleteDictionaryDialog($event: any, dict: TypeValue) { - this._dialogService.openDeleteDictionaryDialog($event, dict, async () => { + this._dialogService.openDeleteDictionaryDialog($event, dict, this._appStateService.activeRuleSetId, async () => { await this._appStateService.loadDictionaryData(); this._loadDictionaryData(); }); } - public loadRuleSetsData(): void { - console.log('load rule sets data'); + public async loadRuleSetsData(): Promise { + await this._appStateService.loadAllRuleSets(); } } diff --git a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html index fa687087c..4eb626208 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html +++ b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.html @@ -132,7 +132,10 @@
- +
{{ (dictionary.hint ? 'hint' : 'redaction') | translate }}
diff --git a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.scss b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.scss index e427f5dce..efff8763d 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.scss +++ b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.scss @@ -5,10 +5,6 @@ height: calc(100% - 50px); } -.changes-box { - right: 403px; -} - .left-container { width: calc(100vw - 353px); padding: 15px; diff --git a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.ts b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.ts index 08edd23d5..a95701945 100644 --- a/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.ts +++ b/apps/red-ui/src/app/screens/admin/dictionary-overview-screen/dictionary-overview-screen.component.ts @@ -10,7 +10,6 @@ import { NotificationService, NotificationType } from '../../../notification/not import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { saveAs } from 'file-saver'; -import { DEFAULT_RUL_SET_UUID } from '../../../utils/rule-set-default'; import { ComponentHasChanges } from '../../../utils/can-deactivate.guard'; declare var ace; @@ -59,18 +58,13 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges { private readonly _appStateService: AppStateService ) { super(_translateService); - this._activatedRoute.params.subscribe((params) => { - this.dictionary = this._appStateService.dictionaryData[params.type]; - if (!this.dictionary) { - this._router.navigate(['/ui/admin/dictionaries']); - } else { - this._initialize(); - } - }); + this._appStateService.activateDictionary(this._activatedRoute.snapshot.params.type, this._activatedRoute.snapshot.params.ruleSetId); + this.dictionary = this._appStateService.activeDictionary; + this._initialize(); } private _initialize() { - this._dictionaryControllerService.getDictionaryForType(this.dictionary.type, DEFAULT_RUL_SET_UUID).subscribe( + this._dictionaryControllerService.getDictionaryForType(this.dictionary.type, this.dictionary.ruleSetId).subscribe( (data) => { this.initialDictionaryEntries = data.entries.sort((str1, str2) => str1.localeCompare(str2, undefined, { sensitivity: 'accent' })); this.revert(); @@ -83,7 +77,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges { openEditDictionaryDialog($event: any) { $event.stopPropagation(); - this._dialogService.openAddEditDictionaryDialog(this.dictionary, async (newDictionary) => { + this._dialogService.openAddEditDictionaryDialog(this.dictionary, this.dictionary.ruleSetId, async (newDictionary) => { if (newDictionary) { await this._appStateService.loadDictionaryData(); this.dictionary = this._appStateService.dictionaryData[this.dictionary.type]; @@ -92,7 +86,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges { } openDeleteDictionaryDialog($event: any) { - this._dialogService.openDeleteDictionaryDialog($event, this.dictionary, async () => { + this._dialogService.openDeleteDictionaryDialog($event, this.dictionary, this.dictionary.ruleSetId, async () => { await this._appStateService.loadDictionaryData(); this._router.navigate(['/ui/admin/dictionaries']); }); @@ -186,9 +180,9 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges { this.processing = true; let obs: Observable; if (entriesToAdd.length > 0) { - obs = this._dictionaryControllerService.addEntry(entriesToAdd, this.dictionary.type, DEFAULT_RUL_SET_UUID, true); + obs = this._dictionaryControllerService.addEntry(entriesToAdd, this.dictionary.type, this.dictionary.ruleSetId, true); } else { - obs = this._dictionaryControllerService.deleteEntries(this.initialDictionaryEntries, this.dictionary.type, DEFAULT_RUL_SET_UUID); + obs = this._dictionaryControllerService.deleteEntries(this.initialDictionaryEntries, this.dictionary.type, this.dictionary.ruleSetId); } obs.subscribe( diff --git a/apps/red-ui/src/app/screens/admin/rule-sets-listing-screen/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts b/apps/red-ui/src/app/screens/admin/rule-sets-listing-screen/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts index 97e5abdc1..cf487b94b 100644 --- a/apps/red-ui/src/app/screens/admin/rule-sets-listing-screen/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts +++ b/apps/red-ui/src/app/screens/admin/rule-sets-listing-screen/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts @@ -54,7 +54,8 @@ export class AddEditRuleSetDialogComponent { ruleSetId: this.ruleSet?.ruleSetId, ...this.ruleSetForm.getRawValue() }; - const res = await this._ruleSetController.createOrUpdateRuleSet(ruleSet).toPromise(); + await this._ruleSetController.createOrUpdateRuleSet(ruleSet).toPromise(); + await this._appStateService.loadAllRuleSets(); this.dialogRef.close({ ruleSet }); } } diff --git a/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.html b/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.html index 7432bdffb..3e1eccc64 100644 --- a/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.html +++ b/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.html @@ -5,7 +5,7 @@
- +
diff --git a/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.scss b/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.scss index ce018878f..1e01118db 100644 --- a/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.scss +++ b/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.scss @@ -6,10 +6,6 @@ @include inset-shadow; } -.changes-box { - right: 40px; -} - .page-header .actions { display: flex; justify-content: flex-end; diff --git a/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.ts b/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.ts index abdf9ec64..1fafe16cc 100644 --- a/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.ts +++ b/apps/red-ui/src/app/screens/admin/rules-screen/rules-screen.component.ts @@ -5,7 +5,6 @@ import { RulesControllerService, RuleSetModel } from '@redaction/red-ui-http'; import { NotificationService, NotificationType } from '../../../notification/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { saveAs } from 'file-saver'; -import { DEFAULT_RUL_SET_UUID } from '../../../utils/rule-set-default'; import { ComponentHasChanges } from '../../../utils/can-deactivate.guard'; import { ActivatedRoute } from '@angular/router'; import { AppStateService } from '../../../state/app-state.service'; @@ -26,7 +25,6 @@ export class RulesScreenComponent extends ComponentHasChanges { public currentLines: string[] = []; public changedLines: number[] = []; public activeEditMarkers: any[] = []; - public ruleSet: RuleSetModel; @ViewChild('editorComponent', { static: true }) editorComponent: AceEditorComponent; @@ -40,15 +38,15 @@ export class RulesScreenComponent extends ComponentHasChanges { private readonly _appStateService: AppStateService, private readonly _notificationService: NotificationService, protected readonly _translateService: TranslateService, - private readonly _actr: ActivatedRoute + private readonly _activatedRoute: ActivatedRoute ) { super(_translateService); + this._appStateService.activateRuleSet(_activatedRoute.snapshot.params.ruleSetId); this._initialize(); - this.ruleSet = this._appStateService.getRuleSetById(this._actr.snapshot.params.ruleSetId); } private _initialize() { - this._rulesControllerService.downloadRules(DEFAULT_RUL_SET_UUID).subscribe( + this._rulesControllerService.downloadRules(this._appStateService.activeRuleSetId).subscribe( (rules) => { this.rules = rules.rules; this.revert(); @@ -90,16 +88,22 @@ export class RulesScreenComponent extends ComponentHasChanges { public async save(): Promise { this.processing = true; - this._rulesControllerService.uploadRules({ rules: this.editorComponent.getEditor().getValue(), ruleSetId: DEFAULT_RUL_SET_UUID }).subscribe( - () => { - this._initialize(); - this._notificationService.showToastNotification(this._translateService.instant('rules-screen.success.generic'), null, NotificationType.SUCCESS); - }, - () => { - this.processing = false; - this._notificationService.showToastNotification(this._translateService.instant('rules-screen.error.generic'), null, NotificationType.ERROR); - } - ); + this._rulesControllerService + .uploadRules({ rules: this.editorComponent.getEditor().getValue(), ruleSetId: this._appStateService.activeRuleSetId }) + .subscribe( + () => { + this._initialize(); + this._notificationService.showToastNotification( + this._translateService.instant('rules-screen.success.generic'), + null, + NotificationType.SUCCESS + ); + }, + () => { + this.processing = false; + this._notificationService.showToastNotification(this._translateService.instant('rules-screen.error.generic'), null, NotificationType.ERROR); + } + ); } public revert(): void { diff --git a/apps/red-ui/src/app/screens/admin/watermark-screen/watermark-screen.component.html b/apps/red-ui/src/app/screens/admin/watermark-screen/watermark-screen.component.html index 4226e3577..532e46ffd 100644 --- a/apps/red-ui/src/app/screens/admin/watermark-screen/watermark-screen.component.html +++ b/apps/red-ui/src/app/screens/admin/watermark-screen/watermark-screen.component.html @@ -1,8 +1,10 @@