From 741c2d7fd690bbfb2b4a81f7df4414f17bba4945 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 14 Oct 2021 18:23:54 +0300 Subject: [PATCH] update manual annotation service --- .../services/annotation-actions.service.ts | 6 +- .../services/manual-annotation.service.ts | 176 ++++++++++++++---- .../services/pdf-viewer-data.service.ts | 3 +- libs/red-ui-http/src/lib/api.module.ts | 2 - 4 files changed, 145 insertions(+), 42 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts index 52978a165..291f42c10 100644 --- a/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts @@ -29,7 +29,7 @@ export class AnnotationActionsService { $event?.stopPropagation(); annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.approveRequest(annotation.id, annotation.isModifyDictionary), + this._manualAnnotationService.approve(annotation.id, annotation.isModifyDictionary), annotation, annotationsChanged, ); @@ -47,7 +47,7 @@ export class AnnotationActionsService { this._dialogService.openDialog('forceRedaction', $event, null, (request: ForceRedactionRequest) => { annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.forceRedaction({ + this._manualAnnotationService.force({ ...request, annotationId: annotation.id, }), @@ -98,7 +98,7 @@ export class AnnotationActionsService { this._dialogService.openDialog('recategorizeImage', $event, annotations, (data: { type: string; comment: string }) => { annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.recategorizeImage(annotation.annotationId, data.type, data.comment), + this._manualAnnotationService.recategorizeImg(annotation.annotationId, data.type, data.comment), annotation, annotationsChanged, ); diff --git a/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts b/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts index e5d4f5299..d8dd92ca6 100644 --- a/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts @@ -1,7 +1,17 @@ -import { Injectable } from '@angular/core'; +import { Injectable, Injector } from '@angular/core'; import { AppStateService } from '@state/app-state.service'; -import { AddRedactionRequest, ForceRedactionRequest, ManualRedactionControllerService } from '@redaction/red-ui-http'; +import { + AddRedactionRequest, + ApproveRequest, + CommentResponse, + ForceRedactionRequest, + ImageRecategorizationRequest, + LegalBasisChangeRequest, + ManualAddResponse, + RemoveRedactionRequest, +} from '@redaction/red-ui-http'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; +import { GenericService, RequiredParam, Toaster, Validate } from '@iqser/common-ui'; import { ErrorMessageService, Toaster } from '@iqser/common-ui'; import { TranslateService } from '@ngx-translate/core'; import { tap } from 'rxjs/operators'; @@ -13,7 +23,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DossiersService } from '@services/entity-services/dossiers.service'; @Injectable() -export class ManualAnnotationService { +export class ManualAnnotationService extends GenericService { CONFIG: { [key in AnnotationActionMode]: string; }; @@ -24,10 +34,11 @@ export class ManualAnnotationService { private readonly _userService: UserService, private readonly _translateService: TranslateService, private readonly _toaster: Toaster, - private readonly _manualRedactionControllerService: ManualRedactionControllerService, private readonly _permissionsService: PermissionsService, private readonly _errorMessageService: ErrorMessageService, + protected readonly _injector: Injector, ) { + super(_injector, 'manualRedaction'); this.CONFIG = { add: 'addRedaction', 'recategorize-image': 'recategorizeImage', @@ -47,17 +58,8 @@ export class ManualAnnotationService { _makeRequest(mode: AnnotationActionMode, body: any, secondParam: any = null, modifyDictionary = false) { const obs = !secondParam - ? this._manualRedactionControllerService[this.CONFIG[mode]]( - body, - this._dossiersService.activeDossierId, - this._appStateService.activeFileId, - ) - : this._manualRedactionControllerService[this.CONFIG[mode]]( - body, - secondParam, - this._dossiersService.activeDossierId, - this._appStateService.activeFileId, - ); + ? this[this.CONFIG[mode]](body, this._dossiersService.activeDossierId, this._appStateService.activeFileId) + : this[this.CONFIG[mode]](body, secondParam, this._dossiersService.activeDossierId, this._appStateService.activeFileId); return obs.pipe( tap( @@ -72,25 +74,26 @@ export class ManualAnnotationService { ); } - // Comments - // this wraps /manualRedaction/comment/add - addComment(comment: string, annotationId: string) { - return this._manualRedactionControllerService.addComment( - { text: comment }, - annotationId, - this._dossiersService.activeDossierId, - this._appStateService.activeFileId, - ); + @Validate() + addComment( + @RequiredParam() comment: string, + @RequiredParam() annotationId: string, + dossierId = this._dossiersService.activeDossierId, + fileId = this._appStateService.activeFileId, + ) { + const url = `${this._defaultModelPath}/comment/add/${dossierId}/${fileId}/${annotationId}`; + return this._post({ text: comment }, url); } - // this wraps /manualRedaction/comment/undo - deleteComment(commentId: string, annotationId: string) { - return this._manualRedactionControllerService.undoComment( - annotationId, - commentId, - this._dossiersService.activeDossierId, - this._appStateService.activeFileId, - ); + @Validate() + deleteComment( + @RequiredParam() commentId: string, + @RequiredParam() annotationId: string, + dossierId = this._dossiersService.activeDossierId, + fileId = this._appStateService.activeFileId, + ) { + const url = `${this._defaultModelPath}/comment/undo/${dossierId}/${fileId}/${annotationId}/${commentId}`; + return super.delete({}, url); } addRecommendation(annotation: AnnotationWrapper) { @@ -116,7 +119,7 @@ export class ManualAnnotationService { // this wraps // /manualRedaction/redaction/recategorize // /manualRedaction/request/recategorize - recategorizeImage(annotationId: string, type: string, comment: string) { + recategorizeImg(annotationId: string, type: string, comment: string) { const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'recategorize-image' : 'request-image-recategorization'; return this._makeRequest(mode, { annotationId, type, comment }); } @@ -132,14 +135,14 @@ export class ManualAnnotationService { // this wraps // /manualRedaction/redaction/force // /manualRedaction/request/force - forceRedaction(request: ForceRedactionRequest) { + force(request: ForceRedactionRequest) { const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'force-redaction' : 'request-force-redaction'; return this._makeRequest(mode, request); } // this wraps // /manualRedaction/approve - approveRequest(annotationId: string, addToDictionary: boolean = false) { + approve(annotationId: string, addToDictionary: boolean = false) { // for only here - approve the request return this._makeRequest('approve', { addOrRemoveFromDictionary: addToDictionary }, annotationId, addToDictionary); } @@ -213,6 +216,109 @@ export class ManualAnnotationService { } } + @Validate() + addRedaction(@RequiredParam() body: AddRedactionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/redaction/add/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + recategorizeImage( + @RequiredParam() body: ImageRecategorizationRequest, + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + ) { + const url = `${this._defaultModelPath}/redaction/recategorize/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + requestImageRecategorization( + @RequiredParam() body: ImageRecategorizationRequest, + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + ) { + const url = `${this._defaultModelPath}/request/recategorize/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + legalBasisChange(@RequiredParam() body: LegalBasisChangeRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/redaction/legalBasisChange/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + requestLegalBasisChange( + @RequiredParam() body: LegalBasisChangeRequest, + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + ) { + const url = `${this._defaultModelPath}/request/legalBasis/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + requestRemoveRedaction( + @RequiredParam() body: RemoveRedactionRequest, + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + ) { + const url = `${this._defaultModelPath}/request/remove/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + approveRequest( + @RequiredParam() body: ApproveRequest, + @RequiredParam() annotationId: string, + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + ) { + const url = `${this._defaultModelPath}/approve/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + declineRequest(@RequiredParam() annotationId: string, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/decline/${dossierId}/${fileId}/${annotationId}`; + return this._post({}, url); + } + + @Validate() + undo(@RequiredParam() annotationId: string, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/undo/${dossierId}/${fileId}/${annotationId}`; + return super.delete({}, url); + } + + @Validate() + removeRedaction(@RequiredParam() body: RemoveRedactionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/redaction/remove/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + requestAddRedaction(@RequiredParam() body: AddRedactionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/request/add/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + forceRedaction(@RequiredParam() body: ForceRedactionRequest, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/redaction/force/${dossierId}/${fileId}`; + return this._post(body, url); + } + + @Validate() + requestForceRedaction( + @RequiredParam() body: ForceRedactionRequest, + @RequiredParam() dossierId: string, + @RequiredParam() fileId: string, + ) { + const url = `${this._defaultModelPath}/request/force/${dossierId}/${fileId}`; + return this._post(body, url); + } + private _getMessage(mode: AnnotationActionMode, modifyDictionary?: boolean, error: boolean = false) { const type = modifyDictionary ? 'dictionary' : 'manual-redaction'; const resultType = error ? 'error' : 'success'; diff --git a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts index 0d954c037..7de5dd81d 100644 --- a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { forkJoin, Observable, of } from 'rxjs'; import { catchError, map, tap } from 'rxjs/operators'; -import { ManualRedactionControllerService, RedactionLogControllerService, ViewedPagesControllerService } from '@redaction/red-ui-http'; +import { RedactionLogControllerService, ViewedPagesControllerService } from '@redaction/red-ui-http'; import { FileDataModel } from '@models/file/file-data.model'; import { AppStateService } from '@state/app-state.service'; import { PermissionsService } from '@services/permissions.service'; @@ -15,7 +15,6 @@ export class PdfViewerDataService { private readonly _appStateService: AppStateService, private readonly _dossiersService: DossiersService, private readonly _permissionsService: PermissionsService, - private readonly _man: ManualRedactionControllerService, private readonly _fileManagementService: FileManagementService, private readonly _redactionLogControllerService: RedactionLogControllerService, private readonly _viewedPagesControllerService: ViewedPagesControllerService, diff --git a/libs/red-ui-http/src/lib/api.module.ts b/libs/red-ui-http/src/lib/api.module.ts index 9598f4954..bee3a2f09 100644 --- a/libs/red-ui-http/src/lib/api.module.ts +++ b/libs/red-ui-http/src/lib/api.module.ts @@ -1,7 +1,6 @@ import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; import { Configuration } from './configuration'; import { HttpClient } from '@angular/common/http'; -import { ManualRedactionControllerService } from './api/manualRedactionController.service'; import { ReanalysisControllerService } from './api/reanalysisController.service'; import { RedactionLogControllerService } from './api/redactionLogController.service'; import { ReportTemplateControllerService } from './api/reportTemplateController.service'; @@ -18,7 +17,6 @@ import { NotificationControllerService } from './api/notificationController.serv declarations: [], exports: [], providers: [ - ManualRedactionControllerService, ReanalysisControllerService, RedactionLogControllerService, ReportTemplateControllerService,