Translation rework: annotation action messages

This commit is contained in:
Adina Țeudan 2021-07-21 18:47:09 +03:00
parent 0db16789d8
commit 486313d00a
5 changed files with 203 additions and 36 deletions

View File

@ -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';

View File

@ -120,11 +120,15 @@ export class FilePreviewScreenComponent extends AutoUnsubscribeComponent impleme
} }
get activeViewerPage() { get activeViewerPage() {
const currentPage = this._instance?.docViewer?.getCurrentPage();
if (!currentPage) {
return 0;
}
return this.viewerComponent?.viewMode === 'STANDARD' return this.viewerComponent?.viewMode === 'STANDARD'
? this._instance?.docViewer?.getCurrentPage() ? currentPage
: this._instance?.docViewer?.getCurrentPage() % 2 === 0 : currentPage % 2 === 0
? this._instance?.docViewer?.getCurrentPage() / 2 ? currentPage / 2
: (this._instance?.docViewer?.getCurrentPage() + 1) / 2; : (currentPage + 1) / 2;
} }
get canSwitchToRedactedView() { get canSwitchToRedactedView() {
@ -410,7 +414,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribeComponent impleme
} }
async annotationsChangedByReviewAction(annotation: AnnotationWrapper) { async annotationsChangedByReviewAction(annotation: AnnotationWrapper) {
await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation.pageNumber); await this._cleanupAndRedrawManualAnnotationsForEntirePage(annotation?.pageNumber || this.activeViewerPage);
} }
async fileActionPerformed(action: string) { async fileActionPerformed(action: string) {

View File

@ -12,26 +12,13 @@ import { TranslateService } from '@ngx-translate/core';
import { tap } from 'rxjs/operators'; import { tap } from 'rxjs/operators';
import { UserService } from '@services/user.service'; import { UserService } from '@services/user.service';
import { PermissionsService } from '@services/permissions.service'; import { PermissionsService } from '@services/permissions.service';
import { AnnotationActionMode } from '../models/annotation-action-mode.model';
type Mode = import { annotationActionsTranslations } from '../translations/annotation-actions-translations';
| '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';
@Injectable() @Injectable()
export class ManualAnnotationService { export class ManualAnnotationService {
CONFIG: { CONFIG: {
[key in Mode]: string; [key in AnnotationActionMode]: string;
}; };
constructor( 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 const obs = !secondParam
? this._manualRedactionControllerService[this.CONFIG[mode]]( ? this._manualRedactionControllerService[this.CONFIG[mode]](
body, body,
@ -123,7 +110,7 @@ export class ManualAnnotationService {
// /manualRedaction/redaction/legalBasisChange // /manualRedaction/redaction/legalBasisChange
// /manualRedaction/request/legalBasis // /manualRedaction/request/legalBasis
changeLegalBasis(annotationId: string, legalBasis: string, comment?: string) { 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 }); return this._makeRequest(mode, { annotationId, legalBasis, comment });
} }
@ -131,7 +118,7 @@ export class ManualAnnotationService {
// /manualRedaction/redaction/recategorize // /manualRedaction/redaction/recategorize
// /manualRedaction/request/recategorize // /manualRedaction/request/recategorize
recategorizeImage(annotationId: string, type: string, comment: string) { 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 }); return this._makeRequest(mode, { annotationId, type, comment });
} }
@ -139,7 +126,7 @@ export class ManualAnnotationService {
// /manualRedaction/redaction/add // /manualRedaction/redaction/add
// /manualRedaction/request/add // /manualRedaction/request/add
addAnnotation(manualRedactionEntry: AddRedactionRequest) { 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); return this._makeRequest(mode, manualRedactionEntry, null, manualRedactionEntry.addToDictionary);
} }
@ -147,7 +134,7 @@ export class ManualAnnotationService {
// /manualRedaction/redaction/force // /manualRedaction/redaction/force
// /manualRedaction/request/force // /manualRedaction/request/force
forceRedaction(request: ForceRedactionRequest) { 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); return this._makeRequest(mode, request);
} }
@ -166,7 +153,7 @@ export class ManualAnnotationService {
// /manualRedaction/decline/remove // /manualRedaction/decline/remove
// /manualRedaction/undo // /manualRedaction/undo
declineOrRemoveRequest(annotationWrapper: AnnotationWrapper) { 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); return this._makeRequest(mode, annotationWrapper.id, null, annotationWrapper.isModifyDictionary);
} }
@ -174,7 +161,7 @@ export class ManualAnnotationService {
// /manualRedaction/redaction/remove/ // /manualRedaction/redaction/remove/
// /manualRedaction/request/remove/ // /manualRedaction/request/remove/
removeOrSuggestRemoveAnnotation(annotationWrapper: AnnotationWrapper, removeFromDictionary: boolean = false) { removeOrSuggestRemoveAnnotation(annotationWrapper: AnnotationWrapper, removeFromDictionary: boolean = false) {
let mode: Mode, let mode: AnnotationActionMode,
body: any, body: any,
removeDict = false; removeDict = false;
@ -227,12 +214,9 @@ export class ManualAnnotationService {
} }
} }
private _getMessage(mode: Mode, modifyDictionary?: boolean, error: boolean = false) { private _getMessage(mode: AnnotationActionMode, modifyDictionary?: boolean, error: boolean = false) {
return ( const type = modifyDictionary ? 'dictionary' : 'manual-redaction';
'annotation-actions.message.' + const resultType = error ? 'error' : 'success';
(modifyDictionary ? 'dictionary.' : 'manual-redaction.') + return annotationActionsTranslations[type][mode][resultType];
mode +
(error ? '.error' : '.success')
);
} }
} }

View File

@ -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')
}
}
};

View File

@ -116,6 +116,84 @@
"label": "" "label": ""
}, },
"hide": "", "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": "", "recategorize-image": "",
"reject-suggestion": "", "reject-suggestion": "",
"remove-annotation": { "remove-annotation": {
@ -688,7 +766,8 @@
"disable-read-only": "", "disable-read-only": "",
"enable-read-only": "", "enable-read-only": "",
"read-only": "", "read-only": "",
"remove-selected": "" "remove-selected": "",
"type": ""
}, },
"title": "" "title": ""
}, },