From ba7ba12ca1518d825a3ff9d734c153132bc517fc Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Wed, 30 Mar 2022 15:35:00 +0300 Subject: [PATCH] make bulk methods work --- .../services/annotation-actions.service.ts | 9 +- .../services/manual-redaction.service.ts | 138 ++++++++---------- 2 files changed, 68 insertions(+), 79 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts index acb3b5e32..a0d727cb7 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts @@ -74,13 +74,12 @@ export class AnnotationActionsService { rejectSuggestion($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { $event?.stopPropagation(); const { dossierId, fileId } = this._state; - const modifyDictionary = annotations[0].isModifyDictionary; this._processObsAndEmit( - this._manualRedactionService.declineOrRemoveRequest( + this._manualRedactionService.declineOrRemove( annotations.map(a => a.id), dossierId, fileId, - modifyDictionary, + annotations[0].isModifyDictionary, ), annotations, annotationsChanged, @@ -152,7 +151,7 @@ export class AnnotationActionsService { comment: result.comment, })); this._processObsAndEmit( - this._manualRedactionService.removeOrSuggestRemoveAnnotation(body, dossierId, fileId, removeFromDictionary), + this._manualRedactionService.removeOrSuggestRemove(body, dossierId, fileId, removeFromDictionary), annotations, annotationsChanged, ); @@ -447,7 +446,7 @@ export class AnnotationActionsService { }; this._processObsAndEmit( - this._manualRedactionService.resizeOrSuggestToResize([resizeRequest], data.dossier.dossierId, fileId), + this._manualRedactionService.resizeOrSuggestResize([resizeRequest], data.dossier.dossierId, fileId), [annotationWrapper], annotationsChanged, ); diff --git a/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts b/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts index 0b8a2df61..a86d7ae1f 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts @@ -30,7 +30,7 @@ function getDictionaryMessage(action: DictionaryActions, error = false, isConfli return dictionaryActionsTranslations[action][getResponseType(error, isConflict)]; } -function getManualRedactionMessage(action: ManualRedactionActions, error = false, isConflict = false) { +function getManualRedactionMessage(action: ManualRedactionActions, error = false, isConflict = false): string { return manualRedactionActionsTranslations[action][getResponseType(error, isConflict)]; } @@ -80,10 +80,10 @@ export class ManualRedactionService extends GenericService { changeLegalBasis(body: List, dossierId: string, fileId: string) { if (this._permissionsService.isApprover(this.#dossier(dossierId))) { - return this.bulkLegalBasisChange(body, dossierId, fileId).pipe(this.#showToast('change-legal-basis')); + return this.legalBasisChange(body, dossierId, fileId).pipe(this.#showToast('change-legal-basis')); } - return this.bulkRequestLegalBasisChange(body, dossierId, fileId).pipe(this.#showToast('request-change-legal-basis')); + return this.requestLegalBasisChange(body, dossierId, fileId).pipe(this.#showToast('request-change-legal-basis')); } recategorizeImage(body: List, dossierId: string, fileId: string) { @@ -91,7 +91,7 @@ export class ManualRedactionService extends GenericService { return this.recategorize(body, dossierId, fileId).pipe(this.#showToast('recategorize-image')); } - return this.bulkRequestImageRecategorization(body, dossierId, fileId).pipe(this.#showToast('request-image-recategorization')); + return this.requestRecategorize(body, dossierId, fileId).pipe(this.#showToast('request-image-recategorization')); } addAnnotation(requests: List, dossierId: string, fileId: string) { @@ -100,55 +100,46 @@ export class ManualRedactionService extends GenericService { return this.add(requests, dossierId, fileId).pipe(toast); } - return this.bulkRequestAddRedaction(requests, dossierId, fileId).pipe(toast); + return this.requestAdd(requests, dossierId, fileId).pipe(toast); } bulkForce(requests: List, dossierId: string, fileId: string) { if (this._permissionsService.isApprover(this.#dossier(dossierId))) { - return this.bulkForceRedaction(requests, dossierId, fileId).pipe(this.#showToast('force-redaction')); + return this.forceRedaction(requests, dossierId, fileId).pipe(this.#showToast('force-redaction')); } - return this.bulkForceRequest(requests, dossierId, fileId).pipe(this.#showToast('request-force-redaction')); - } - - approve(annotationIds: List, dossierId: string, fileId: string) { - return this.bulkApprove(annotationIds, dossierId, fileId).pipe(this.#showToast('approve')); + return this.forceRequest(requests, dossierId, fileId).pipe(this.#showToast('request-force-redaction')); } undoRequest(annotationIds: List, dossierId: string, fileId: string, modifyDictionary = false) { - const toast = modifyDictionary ? this.#showDictionaryToast : this.#showToast; - return this.bulkUndo(annotationIds, dossierId, fileId).pipe(toast('undo')); + const toast = action => (modifyDictionary ? this.#showDictionaryToast(action) : this.#showToast(action)); + return this.undo(annotationIds, dossierId, fileId).pipe(toast('undo')); } - declineOrRemoveRequest(annotationIds: List, dossierId: string, fileId: string, modifyDictionary = false) { - const toast = modifyDictionary ? this.#showDictionaryToast : this.#showToast; + declineOrRemove(annotationIds: List, dossierId: string, fileId: string, modifyDictionary = false) { + const toast = action => (modifyDictionary ? this.#showDictionaryToast(action) : this.#showToast(action)); if (this._permissionsService.isApprover(this.#dossier(dossierId))) { - return this.bulkDecline(annotationIds, dossierId, fileId).pipe(toast('decline')); + return this.decline(annotationIds, dossierId, fileId).pipe(toast('decline')); } - return this.bulkUndo(annotationIds, dossierId, fileId).pipe(toast('undo')); + return this.undo(annotationIds, dossierId, fileId).pipe(toast('undo')); } - resizeOrSuggestToResize(requests: List, dossierId: string, fileId: string) { + resizeOrSuggestResize(requests: List, dossierId: string, fileId: string) { if (this._permissionsService.isApprover(this.#dossier(dossierId))) { - return this.bulkResize(requests, dossierId, fileId); + return this.resize(requests, dossierId, fileId); } - return this.bulkRequestResize(requests, dossierId, fileId); + return this.requestResize(requests, dossierId, fileId); } - removeOrSuggestRemoveAnnotation( - body: List, - dossierId: string, - fileId: string, - removeFromDictionary: boolean = false, - ) { - const toast = removeFromDictionary ? this.#showDictionaryToast : this.#showToast; + removeOrSuggestRemove(body: List, dossierId: string, fileId: string, removeFromDictionary = false) { + const toast = action => (removeFromDictionary ? this.#showDictionaryToast(action) : this.#showToast(action)); if (this._permissionsService.isApprover(this.#dossier(dossierId))) { - return this.bulkRemoveRedaction(body, dossierId, fileId).pipe(toast('remove')); + return this.remove(body, dossierId, fileId).pipe(toast('remove')); } - return this.bulkRequestRemoveRedaction(body, dossierId, fileId).pipe(toast('request-remove')); + return this.requestRemoveRedaction(body, dossierId, fileId).pipe(toast('request-remove')); } getTitle(type: ManualRedactionEntryType, dossier: Dossier) { @@ -175,11 +166,7 @@ export class ManualRedactionService extends GenericService { @Validate() add(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._post(body, `${this.bulkRedaction}/add/${dossierId}/${fileId}`).pipe( - tap(response => { - this._logger.info('[MANUAL-REDACTIONS] Add ', body, response); - }), - ); + return this._post(body, `${this.bulkRedaction}/add/${dossierId}/${fileId}`).pipe(this.#log('Add', body)); } @Validate() @@ -188,109 +175,112 @@ export class ManualRedactionService extends GenericService { @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRedaction}/recategorize/${dossierId}/${fileId}`); - // .pipe( - // tap(response => { - // this._logger.info('[MANUAL-REDACTIONS] Recategorize', body, response); - // }), - // ); + return this._post(body, `${this.bulkRedaction}/recategorize/${dossierId}/${fileId}`).pipe(this.#log('Recategorize', body)); } @Validate() - bulkRequestImageRecategorization( + requestRecategorize( @RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRequest}/recategorize/${dossierId}/${fileId}`); + return this._post(body, `${this.bulkRequest}/recategorize/${dossierId}/${fileId}`).pipe(this.#log('Request recategorize', body)); } @Validate() - bulkLegalBasisChange( + legalBasisChange( @RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRedaction}/legalBasisChange/${dossierId}/${fileId}`); + return this._post(body, `${this.bulkRedaction}/legalBasisChange/${dossierId}/${fileId}`).pipe( + this.#log('Legal basis change', body), + ); } @Validate() - bulkRequestLegalBasisChange( + requestLegalBasisChange( @RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRequest}/legalBasis/${dossierId}/${fileId}`); + return this._post(body, `${this.bulkRequest}/legalBasis/${dossierId}/${fileId}`).pipe( + this.#log('Request legal basis change', body), + ); } @Validate() - bulkRequestRemoveRedaction( + requestRemoveRedaction( @RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRequest}/remove/${dossierId}/${fileId}`); + return this._post(body, `${this.bulkRequest}/remove/${dossierId}/${fileId}`).pipe(this.#log('Request remove', body)); } @Validate() - bulkApprove(@RequiredParam() annotationIds: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._post(annotationIds, `${this._defaultModelPath}/bulk/approve/${dossierId}/${fileId}`); + approve(@RequiredParam() annotationIds: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + return this._post(annotationIds, `${this._defaultModelPath}/bulk/approve/${dossierId}/${fileId}`).pipe( + this.#log('Approve', annotationIds), + this.#showToast('approve'), + ); } @Validate() - bulkDecline(@RequiredParam() annotationIds: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._post(annotationIds, `${this._defaultModelPath}/bulk/decline/${dossierId}/${fileId}`); + decline(@RequiredParam() annotationIds: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + return this._post(annotationIds, `${this._defaultModelPath}/bulk/decline/${dossierId}/${fileId}`).pipe( + this.#log('Decline', annotationIds), + ); } @Validate() - bulkUndo(@RequiredParam() annotationIds: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return super.delete(annotationIds, `${this._defaultModelPath}/bulk/undo/${dossierId}/${fileId}`); + undo(@RequiredParam() annotationIds: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + const url = `${this._defaultModelPath}/bulk/undo/${dossierId}/${fileId}`; + return super.delete(annotationIds, url).pipe(this.#log('Undo', annotationIds)); } @Validate() - bulkRemoveRedaction( - @RequiredParam() body: List, - @RequiredParam() dossierId: string, - @RequiredParam() fileId: string, - ) { - return this._post(body, `${this.bulkRedaction}/remove/${dossierId}/${fileId}`); + remove(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + return this._post(body, `${this.bulkRedaction}/remove/${dossierId}/${fileId}`).pipe(this.#log('Remove', body)); } @Validate() - bulkRequestAddRedaction( - @RequiredParam() body: List, - @RequiredParam() dossierId: string, - @RequiredParam() fileId: string, - ) { - return this._post(body, `${this.bulkRequest}/add/${dossierId}/${fileId}`); + requestAdd(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + return this._post(body, `${this.bulkRequest}/add/${dossierId}/${fileId}`).pipe(this.#log('Request add', body)); } @Validate() - bulkForceRedaction( + forceRedaction( @RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRedaction}/force/${dossierId}/${fileId}`); + return this._post(body, `${this.bulkRedaction}/force/${dossierId}/${fileId}`).pipe(this.#log('Force redaction', body)); } @Validate() - bulkForceRequest( + forceRequest( @RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string, ) { - return this._post(body, `${this.bulkRequest}/force/${dossierId}/${fileId}`); + return this._post(body, `${this.bulkRequest}/force/${dossierId}/${fileId}`).pipe(this.#log('Request force redaction', body)); } @Validate() - bulkResize(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._post(body, `${this.bulkRedaction}/resize/${dossierId}/${fileId}`); + resize(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + return this._post(body, `${this.bulkRedaction}/resize/${dossierId}/${fileId}`).pipe(this.#log('Resize', body)); } @Validate() - bulkRequestResize(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { - return this._post(body, `${this.bulkRequest}/resize/${dossierId}/${fileId}`); + requestResize(@RequiredParam() body: List, @RequiredParam() dossierId: string, @RequiredParam() fileId: string) { + return this._post(body, `${this.bulkRequest}/resize/${dossierId}/${fileId}`).pipe(this.#log('Request resize', body)); + } + + #log(action: string, body: unknown) { + return tap(response => { + this._logger.info(`[MANUAL-REDACTIONS] ${action} `, body, response); + }); } #showToast(action: ManualRedactionActions) {