update manual annotation service

This commit is contained in:
Dan Percic 2021-10-14 18:23:54 +03:00
parent 09cf5b795a
commit 741c2d7fd6
4 changed files with 145 additions and 42 deletions

View File

@ -29,7 +29,7 @@ export class AnnotationActionsService {
$event?.stopPropagation(); $event?.stopPropagation();
annotations.forEach(annotation => { annotations.forEach(annotation => {
this._processObsAndEmit( this._processObsAndEmit(
this._manualAnnotationService.approveRequest(annotation.id, annotation.isModifyDictionary), this._manualAnnotationService.approve(annotation.id, annotation.isModifyDictionary),
annotation, annotation,
annotationsChanged, annotationsChanged,
); );
@ -47,7 +47,7 @@ export class AnnotationActionsService {
this._dialogService.openDialog('forceRedaction', $event, null, (request: ForceRedactionRequest) => { this._dialogService.openDialog('forceRedaction', $event, null, (request: ForceRedactionRequest) => {
annotations.forEach(annotation => { annotations.forEach(annotation => {
this._processObsAndEmit( this._processObsAndEmit(
this._manualAnnotationService.forceRedaction({ this._manualAnnotationService.force({
...request, ...request,
annotationId: annotation.id, annotationId: annotation.id,
}), }),
@ -98,7 +98,7 @@ export class AnnotationActionsService {
this._dialogService.openDialog('recategorizeImage', $event, annotations, (data: { type: string; comment: string }) => { this._dialogService.openDialog('recategorizeImage', $event, annotations, (data: { type: string; comment: string }) => {
annotations.forEach(annotation => { annotations.forEach(annotation => {
this._processObsAndEmit( this._processObsAndEmit(
this._manualAnnotationService.recategorizeImage(annotation.annotationId, data.type, data.comment), this._manualAnnotationService.recategorizeImg(annotation.annotationId, data.type, data.comment),
annotation, annotation,
annotationsChanged, annotationsChanged,
); );

View File

@ -1,7 +1,17 @@
import { Injectable } from '@angular/core'; import { Injectable, Injector } from '@angular/core';
import { AppStateService } from '@state/app-state.service'; 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 { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { GenericService, RequiredParam, Toaster, Validate } from '@iqser/common-ui';
import { ErrorMessageService, Toaster } from '@iqser/common-ui'; import { ErrorMessageService, Toaster } from '@iqser/common-ui';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { tap } from 'rxjs/operators'; 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'; import { DossiersService } from '@services/entity-services/dossiers.service';
@Injectable() @Injectable()
export class ManualAnnotationService { export class ManualAnnotationService extends GenericService<ManualAddResponse> {
CONFIG: { CONFIG: {
[key in AnnotationActionMode]: string; [key in AnnotationActionMode]: string;
}; };
@ -24,10 +34,11 @@ export class ManualAnnotationService {
private readonly _userService: UserService, private readonly _userService: UserService,
private readonly _translateService: TranslateService, private readonly _translateService: TranslateService,
private readonly _toaster: Toaster, private readonly _toaster: Toaster,
private readonly _manualRedactionControllerService: ManualRedactionControllerService,
private readonly _permissionsService: PermissionsService, private readonly _permissionsService: PermissionsService,
private readonly _errorMessageService: ErrorMessageService, private readonly _errorMessageService: ErrorMessageService,
protected readonly _injector: Injector,
) { ) {
super(_injector, 'manualRedaction');
this.CONFIG = { this.CONFIG = {
add: 'addRedaction', add: 'addRedaction',
'recategorize-image': 'recategorizeImage', 'recategorize-image': 'recategorizeImage',
@ -47,17 +58,8 @@ export class ManualAnnotationService {
_makeRequest(mode: AnnotationActionMode, body: any, secondParam: any = null, modifyDictionary = false) { _makeRequest(mode: AnnotationActionMode, body: any, secondParam: any = null, modifyDictionary = false) {
const obs = !secondParam const obs = !secondParam
? this._manualRedactionControllerService[this.CONFIG[mode]]( ? this[this.CONFIG[mode]](body, this._dossiersService.activeDossierId, this._appStateService.activeFileId)
body, : this[this.CONFIG[mode]](body, secondParam, this._dossiersService.activeDossierId, this._appStateService.activeFileId);
this._dossiersService.activeDossierId,
this._appStateService.activeFileId,
)
: this._manualRedactionControllerService[this.CONFIG[mode]](
body,
secondParam,
this._dossiersService.activeDossierId,
this._appStateService.activeFileId,
);
return obs.pipe( return obs.pipe(
tap( tap(
@ -72,25 +74,26 @@ export class ManualAnnotationService {
); );
} }
// Comments @Validate()
// this wraps /manualRedaction/comment/add addComment(
addComment(comment: string, annotationId: string) { @RequiredParam() comment: string,
return this._manualRedactionControllerService.addComment( @RequiredParam() annotationId: string,
{ text: comment }, dossierId = this._dossiersService.activeDossierId,
annotationId, fileId = this._appStateService.activeFileId,
this._dossiersService.activeDossierId, ) {
this._appStateService.activeFileId, const url = `${this._defaultModelPath}/comment/add/${dossierId}/${fileId}/${annotationId}`;
); return this._post<CommentResponse>({ text: comment }, url);
} }
// this wraps /manualRedaction/comment/undo @Validate()
deleteComment(commentId: string, annotationId: string) { deleteComment(
return this._manualRedactionControllerService.undoComment( @RequiredParam() commentId: string,
annotationId, @RequiredParam() annotationId: string,
commentId, dossierId = this._dossiersService.activeDossierId,
this._dossiersService.activeDossierId, fileId = this._appStateService.activeFileId,
this._appStateService.activeFileId, ) {
); const url = `${this._defaultModelPath}/comment/undo/${dossierId}/${fileId}/${annotationId}/${commentId}`;
return super.delete({}, url);
} }
addRecommendation(annotation: AnnotationWrapper) { addRecommendation(annotation: AnnotationWrapper) {
@ -116,7 +119,7 @@ export class ManualAnnotationService {
// this wraps // this wraps
// /manualRedaction/redaction/recategorize // /manualRedaction/redaction/recategorize
// /manualRedaction/request/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'; const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'recategorize-image' : 'request-image-recategorization';
return this._makeRequest(mode, { annotationId, type, comment }); return this._makeRequest(mode, { annotationId, type, comment });
} }
@ -132,14 +135,14 @@ export class ManualAnnotationService {
// this wraps // this wraps
// /manualRedaction/redaction/force // /manualRedaction/redaction/force
// /manualRedaction/request/force // /manualRedaction/request/force
forceRedaction(request: ForceRedactionRequest) { force(request: ForceRedactionRequest) {
const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'force-redaction' : 'request-force-redaction'; const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'force-redaction' : 'request-force-redaction';
return this._makeRequest(mode, request); return this._makeRequest(mode, request);
} }
// this wraps // this wraps
// /manualRedaction/approve // /manualRedaction/approve
approveRequest(annotationId: string, addToDictionary: boolean = false) { approve(annotationId: string, addToDictionary: boolean = false) {
// for only here - approve the request // for only here - approve the request
return this._makeRequest('approve', { addOrRemoveFromDictionary: addToDictionary }, annotationId, addToDictionary); 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<unknown>(body, url);
}
@Validate()
declineRequest(@RequiredParam() annotationId: string, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) {
const url = `${this._defaultModelPath}/decline/${dossierId}/${fileId}/${annotationId}`;
return this._post<unknown>({}, 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) { private _getMessage(mode: AnnotationActionMode, modifyDictionary?: boolean, error: boolean = false) {
const type = modifyDictionary ? 'dictionary' : 'manual-redaction'; const type = modifyDictionary ? 'dictionary' : 'manual-redaction';
const resultType = error ? 'error' : 'success'; const resultType = error ? 'error' : 'success';

View File

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { forkJoin, Observable, of } from 'rxjs'; import { forkJoin, Observable, of } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators'; 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 { FileDataModel } from '@models/file/file-data.model';
import { AppStateService } from '@state/app-state.service'; import { AppStateService } from '@state/app-state.service';
import { PermissionsService } from '@services/permissions.service'; import { PermissionsService } from '@services/permissions.service';
@ -15,7 +15,6 @@ export class PdfViewerDataService {
private readonly _appStateService: AppStateService, private readonly _appStateService: AppStateService,
private readonly _dossiersService: DossiersService, private readonly _dossiersService: DossiersService,
private readonly _permissionsService: PermissionsService, private readonly _permissionsService: PermissionsService,
private readonly _man: ManualRedactionControllerService,
private readonly _fileManagementService: FileManagementService, private readonly _fileManagementService: FileManagementService,
private readonly _redactionLogControllerService: RedactionLogControllerService, private readonly _redactionLogControllerService: RedactionLogControllerService,
private readonly _viewedPagesControllerService: ViewedPagesControllerService, private readonly _viewedPagesControllerService: ViewedPagesControllerService,

View File

@ -1,7 +1,6 @@
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { Configuration } from './configuration'; import { Configuration } from './configuration';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { ManualRedactionControllerService } from './api/manualRedactionController.service';
import { ReanalysisControllerService } from './api/reanalysisController.service'; import { ReanalysisControllerService } from './api/reanalysisController.service';
import { RedactionLogControllerService } from './api/redactionLogController.service'; import { RedactionLogControllerService } from './api/redactionLogController.service';
import { ReportTemplateControllerService } from './api/reportTemplateController.service'; import { ReportTemplateControllerService } from './api/reportTemplateController.service';
@ -18,7 +17,6 @@ import { NotificationControllerService } from './api/notificationController.serv
declarations: [], declarations: [],
exports: [], exports: [],
providers: [ providers: [
ManualRedactionControllerService,
ReanalysisControllerService, ReanalysisControllerService,
RedactionLogControllerService, RedactionLogControllerService,
ReportTemplateControllerService, ReportTemplateControllerService,