From 486313d00a013f048c6a43d20bbc62ccabb84d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Wed, 21 Jul 2021 18:47:09 +0300 Subject: [PATCH] Translation rework: annotation action messages --- .../models/annotation-action-mode.model.ts | 14 +++ .../file-preview-screen.component.ts | 14 +-- .../services/manual-annotation.service.ts | 44 +++------- .../annotation-actions-translations.ts | 86 +++++++++++++++++++ apps/red-ui/src/assets/i18n/te.json | 81 ++++++++++++++++- 5 files changed, 203 insertions(+), 36 deletions(-) create mode 100644 apps/red-ui/src/app/modules/dossier/models/annotation-action-mode.model.ts create mode 100644 apps/red-ui/src/app/modules/dossier/translations/annotation-actions-translations.ts diff --git a/apps/red-ui/src/app/modules/dossier/models/annotation-action-mode.model.ts b/apps/red-ui/src/app/modules/dossier/models/annotation-action-mode.model.ts new file mode 100644 index 000000000..eabbda0a9 --- /dev/null +++ b/apps/red-ui/src/app/modules/dossier/models/annotation-action-mode.model.ts @@ -0,0 +1,14 @@ +export type AnnotationActionMode = + | 'add' + | 'approve' + | 'remove' + | 'change-legal-basis' + | 'decline' + | 'request-remove' + | 'request-change-legal-basis' + | 'recategorize-image' + | 'request-image-recategorization' + | 'suggest' + | 'undo' + | 'force-redaction' + | 'request-force-redaction'; diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 8acbcbf0d..f55db541e 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -120,11 +120,15 @@ export class FilePreviewScreenComponent extends AutoUnsubscribeComponent impleme } get activeViewerPage() { + const currentPage = this._instance?.docViewer?.getCurrentPage(); + if (!currentPage) { + return 0; + } return this.viewerComponent?.viewMode === 'STANDARD' - ? this._instance?.docViewer?.getCurrentPage() - : this._instance?.docViewer?.getCurrentPage() % 2 === 0 - ? this._instance?.docViewer?.getCurrentPage() / 2 - : (this._instance?.docViewer?.getCurrentPage() + 1) / 2; + ? currentPage + : currentPage % 2 === 0 + ? currentPage / 2 + : (currentPage + 1) / 2; } get canSwitchToRedactedView() { @@ -410,7 +414,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribeComponent impleme } async annotationsChangedByReviewAction(annotation: AnnotationWrapper) { - await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation.pageNumber); + await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation?.pageNumber || this.activeViewerPage); } async fileActionPerformed(action: string) { 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 4de092d50..a15210aab 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 @@ -12,26 +12,13 @@ import { TranslateService } from '@ngx-translate/core'; import { tap } from 'rxjs/operators'; import { UserService } from '@services/user.service'; import { PermissionsService } from '@services/permissions.service'; - -type Mode = - | 'add' - | 'approve' - | 'remove' - | 'change-legal-basis' - | 'decline' - | 'request-remove' - | 'request-change-legal-basis' - | 'recategorize-image' - | 'request-image-recategorization' - | 'suggest' - | 'undo' - | 'force-redaction' - | 'request-force-redaction'; +import { AnnotationActionMode } from '../models/annotation-action-mode.model'; +import { annotationActionsTranslations } from '../translations/annotation-actions-translations'; @Injectable() export class ManualAnnotationService { CONFIG: { - [key in Mode]: string; + [key in AnnotationActionMode]: string; }; constructor( @@ -60,7 +47,7 @@ export class ManualAnnotationService { }; } - _makeRequest(mode: Mode, body: any, secondParam: any = null, modifyDictionary = false) { + _makeRequest(mode: AnnotationActionMode, body: any, secondParam: any = null, modifyDictionary = false) { const obs = !secondParam ? this._manualRedactionControllerService[this.CONFIG[mode]]( body, @@ -123,7 +110,7 @@ export class ManualAnnotationService { // /manualRedaction/redaction/legalBasisChange // /manualRedaction/request/legalBasis changeLegalBasis(annotationId: string, legalBasis: string, comment?: string) { - const mode: Mode = this._permissionsService.isApprover() ? 'change-legal-basis' : 'request-change-legal-basis'; + const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'change-legal-basis' : 'request-change-legal-basis'; return this._makeRequest(mode, { annotationId, legalBasis, comment }); } @@ -131,7 +118,7 @@ export class ManualAnnotationService { // /manualRedaction/redaction/recategorize // /manualRedaction/request/recategorize recategorizeImage(annotationId: string, type: string, comment: string) { - const mode: Mode = 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 }); } @@ -139,7 +126,7 @@ export class ManualAnnotationService { // /manualRedaction/redaction/add // /manualRedaction/request/add addAnnotation(manualRedactionEntry: AddRedactionRequest) { - const mode: Mode = this._permissionsService.isApprover() ? 'add' : 'suggest'; + const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'add' : 'suggest'; return this._makeRequest(mode, manualRedactionEntry, null, manualRedactionEntry.addToDictionary); } @@ -147,7 +134,7 @@ export class ManualAnnotationService { // /manualRedaction/redaction/force // /manualRedaction/request/force forceRedaction(request: ForceRedactionRequest) { - const mode: Mode = this._permissionsService.isApprover() ? 'force-redaction' : 'request-force-redaction'; + const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'force-redaction' : 'request-force-redaction'; return this._makeRequest(mode, request); } @@ -166,7 +153,7 @@ export class ManualAnnotationService { // /manualRedaction/decline/remove // /manualRedaction/undo declineOrRemoveRequest(annotationWrapper: AnnotationWrapper) { - const mode: Mode = this._permissionsService.isApprover() ? 'decline' : 'undo'; + const mode: AnnotationActionMode = this._permissionsService.isApprover() ? 'decline' : 'undo'; return this._makeRequest(mode, annotationWrapper.id, null, annotationWrapper.isModifyDictionary); } @@ -174,7 +161,7 @@ export class ManualAnnotationService { // /manualRedaction/redaction/remove/ // /manualRedaction/request/remove/ removeOrSuggestRemoveAnnotation(annotationWrapper: AnnotationWrapper, removeFromDictionary: boolean = false) { - let mode: Mode, + let mode: AnnotationActionMode, body: any, removeDict = false; @@ -227,12 +214,9 @@ export class ManualAnnotationService { } } - private _getMessage(mode: Mode, modifyDictionary?: boolean, error: boolean = false) { - return ( - 'annotation-actions.message.' + - (modifyDictionary ? 'dictionary.' : 'manual-redaction.') + - mode + - (error ? '.error' : '.success') - ); + private _getMessage(mode: AnnotationActionMode, modifyDictionary?: boolean, error: boolean = false) { + const type = modifyDictionary ? 'dictionary' : 'manual-redaction'; + const resultType = error ? 'error' : 'success'; + return annotationActionsTranslations[type][mode][resultType]; } } diff --git a/apps/red-ui/src/app/modules/dossier/translations/annotation-actions-translations.ts b/apps/red-ui/src/app/modules/dossier/translations/annotation-actions-translations.ts new file mode 100644 index 000000000..2679a24ad --- /dev/null +++ b/apps/red-ui/src/app/modules/dossier/translations/annotation-actions-translations.ts @@ -0,0 +1,86 @@ +import { AnnotationActionMode } from '../models/annotation-action-mode.model'; +import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; + +type ActionType = { [key in AnnotationActionMode]?: { error: string; success: string } }; + +export const annotationActionsTranslations: { + dictionary: ActionType; + 'manual-redaction': ActionType; +} = { + dictionary: { + add: { + error: _('annotation-actions.message.dictionary.add.error'), + success: _('annotation-actions.message.dictionary.add.success') + }, + approve: { + error: _('annotation-actions.message.dictionary.approve.error'), + success: _('annotation-actions.message.dictionary.approve.success') + }, + decline: { + error: _('annotation-actions.message.dictionary.decline.error'), + success: _('annotation-actions.message.dictionary.decline.success') + }, + remove: { + error: _('annotation-actions.message.dictionary.remove.error'), + success: _('annotation-actions.message.dictionary.remove.success') + }, + 'request-remove': { + error: _('annotation-actions.message.dictionary.request-remove.error'), + success: _('annotation-actions.message.dictionary.request-remove.success') + }, + suggest: { + error: _('annotation-actions.message.dictionary.suggest.error'), + success: _('annotation-actions.message.dictionary.suggest.success') + }, + undo: { + error: _('annotation-actions.message.dictionary.undo.error'), + success: _('annotation-actions.message.dictionary.undo.success') + } + }, + 'manual-redaction': { + add: { + error: _('annotation-actions.message.manual-redaction.add.error'), + success: _('annotation-actions.message.manual-redaction.add.success') + }, + approve: { + error: _('annotation-actions.message.manual-redaction.approve.error'), + success: _('annotation-actions.message.manual-redaction.approve.success') + }, + 'change-legal-basis': { + error: _('annotation-actions.message.manual-redaction.change-legal-basis.error'), + success: _('annotation-actions.message.manual-redaction.change-legal-basis.success') + }, + decline: { + error: _('annotation-actions.message.manual-redaction.decline.error'), + success: _('annotation-actions.message.manual-redaction.decline.success') + }, + 'force-redaction': { + error: _('annotation-actions.message.manual-redaction.force-redaction.error'), + success: _('annotation-actions.message.manual-redaction.force-redaction.success') + }, + 'recategorize-image': { + error: _('annotation-actions.message.manual-redaction.recategorize-image.error'), + success: _('annotation-actions.message.manual-redaction.recategorize-image.success') + }, + 'request-change-legal-basis': { + error: _('annotation-actions.message.manual-redaction.request-change-legal-basis.error'), + success: _('annotation-actions.message.manual-redaction.request-change-legal-basis.success') + }, + 'request-force-redaction': { + error: _('annotation-actions.message.manual-redaction.request-force-redaction.error'), + success: _('annotation-actions.message.manual-redaction.request-force-redaction.success') + }, + 'request-image-recategorization': { + error: _('annotation-actions.message.manual-redaction.request-image-recategorization.error'), + success: _('annotation-actions.message.manual-redaction.request-image-recategorization.success') + }, + suggest: { + error: _('annotation-actions.message.manual-redaction.suggest.error'), + success: _('annotation-actions.message.manual-redaction.suggest.success') + }, + undo: { + error: _('annotation-actions.message.manual-redaction.undo.error'), + success: _('annotation-actions.message.manual-redaction.undo.success') + } + } +}; diff --git a/apps/red-ui/src/assets/i18n/te.json b/apps/red-ui/src/assets/i18n/te.json index 34854b952..9726570cc 100644 --- a/apps/red-ui/src/assets/i18n/te.json +++ b/apps/red-ui/src/assets/i18n/te.json @@ -116,6 +116,84 @@ "label": "" }, "hide": "", + "message": { + "dictionary": { + "add": { + "error": "", + "success": "" + }, + "approve": { + "error": "", + "success": "" + }, + "decline": { + "error": "", + "success": "" + }, + "remove": { + "error": "", + "success": "" + }, + "request-remove": { + "error": "", + "success": "" + }, + "suggest": { + "error": "", + "success": "" + }, + "undo": { + "error": "", + "success": "" + } + }, + "manual-redaction": { + "add": { + "error": "", + "success": "" + }, + "approve": { + "error": "", + "success": "" + }, + "change-legal-basis": { + "error": "", + "success": "" + }, + "decline": { + "error": "", + "success": "" + }, + "force-redaction": { + "error": "", + "success": "" + }, + "recategorize-image": { + "error": "", + "success": "" + }, + "request-change-legal-basis": { + "error": "", + "success": "" + }, + "request-force-redaction": { + "error": "", + "success": "" + }, + "request-image-recategorization": { + "error": "", + "success": "" + }, + "suggest": { + "error": "", + "success": "" + }, + "undo": { + "error": "", + "success": "" + } + } + }, "recategorize-image": "", "reject-suggestion": "", "remove-annotation": { @@ -688,7 +766,8 @@ "disable-read-only": "", "enable-read-only": "", "read-only": "", - "remove-selected": "" + "remove-selected": "", + "type": "" }, "title": "" },