From 34e322e9f60f12186472e3753b62aadc51ff86fc Mon Sep 17 00:00:00 2001 From: suzanadirla Date: Tue, 6 Feb 2018 07:21:06 +0200 Subject: [PATCH] [ACA-1091] Destination picker is not completely translated [ADF-2000] (#186) * [ACA-1091] Destination picker is not completely translated [ADF-2000] translate title taking into consideration also multiple selections for copy/move action * [ACA-1091] updated unit tests * [ACA-1091] removed translation to french as this will be added by the translation team and refactored title translation code --- .../services/node-actions.service.spec.ts | 16 +++++++++--- .../common/services/node-actions.service.ts | 25 +++++++++++++------ src/assets/i18n/en.json | 7 ++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/app/common/services/node-actions.service.spec.ts b/src/app/common/services/node-actions.service.spec.ts index 94d7c813e..3b17c02a1 100644 --- a/src/app/common/services/node-actions.service.spec.ts +++ b/src/app/common/services/node-actions.service.spec.ts @@ -27,7 +27,7 @@ import { TestBed, async } from '@angular/core/testing'; import { MatDialog } from '@angular/material'; import { OverlayModule } from '@angular/cdk/overlay'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService, NodesApiService } from '@alfresco/adf-core'; +import { AlfrescoApiService, NodesApiService, TranslationService } from '@alfresco/adf-core'; import { DocumentListService } from '@alfresco/adf-content-services'; import { CommonModule } from '../common.module'; @@ -285,12 +285,17 @@ describe('NodeActionsService', () => { let fileToCopy; let folderToCopy; let destinationFolder; + let translationService: TranslationService; beforeEach(() => { fileToCopy = new TestNode(fileId, isFile, 'file-name'); folderToCopy = new TestNode(); destinationFolder = new TestNode(folderDestinationId); + translationService = TestBed.get(TranslationService); + spyOn(translationService, 'instant').and.callFake(key => { + return key; + }); }); it('should be called', () => { @@ -324,7 +329,8 @@ describe('NodeActionsService', () => { expect(testContentNodeSelectorComponentData).toBeDefined(); expect(testContentNodeSelectorComponentData.data.rowFilter({node: destinationFolder})).toBeDefined(); expect(testContentNodeSelectorComponentData.data.imageResolver({node: destinationFolder})).toBeDefined(); - expect(testContentNodeSelectorComponentData.data.title).toBe('copy to ...'); + expect(testContentNodeSelectorComponentData.data.title).toBe('NODE_SELECTOR.COPY_ITEMS'); + expect(translationService.instant).toHaveBeenCalledWith('NODE_SELECTOR.COPY_ITEMS', {name: ''}); destinationFolder.entry['allowableOperations'] = ['update']; expect(testContentNodeSelectorComponentData.data.imageResolver({node: destinationFolder})).toBeDefined(); @@ -346,7 +352,8 @@ describe('NodeActionsService', () => { expect(spyOnBatchOperation).toHaveBeenCalled(); expect(testContentNodeSelectorComponentData).toBeDefined(); - expect(testContentNodeSelectorComponentData.data.title).toBe('copy \'entry-name\' to ...'); + expect(testContentNodeSelectorComponentData.data.title).toBe('NODE_SELECTOR.COPY_ITEM'); + expect(translationService.instant).toHaveBeenCalledWith('NODE_SELECTOR.COPY_ITEM', {name: 'entry-name'}); }); it('should use the ContentNodeSelectorComponentData object without file name in title, if no name exists', () => { @@ -365,7 +372,8 @@ describe('NodeActionsService', () => { expect(spyOnBatchOperation).toHaveBeenCalled(); expect(testContentNodeSelectorComponentData).toBeDefined(); - expect(testContentNodeSelectorComponentData.data.title).toBe('copy to ...'); + expect(testContentNodeSelectorComponentData.data.title).toBe('NODE_SELECTOR.COPY_ITEMS'); + expect(translationService.instant).toHaveBeenCalledWith('NODE_SELECTOR.COPY_ITEMS', {name: ''}); }); }); diff --git a/src/app/common/services/node-actions.service.ts b/src/app/common/services/node-actions.service.ts index 5e05c78e2..9edd073dc 100644 --- a/src/app/common/services/node-actions.service.ts +++ b/src/app/common/services/node-actions.service.ts @@ -27,7 +27,7 @@ import { Injectable } from '@angular/core'; import { MatDialog } from '@angular/material'; import { Observable, Subject } from 'rxjs/Rx'; -import { AlfrescoApiService, ContentService, NodesApiService, DataColumn } from '@alfresco/adf-core'; +import { AlfrescoApiService, ContentService, NodesApiService, DataColumn, TranslationService } from '@alfresco/adf-core'; import { DocumentListService, ContentNodeSelectorComponent, ContentNodeSelectorComponentData } from '@alfresco/adf-content-services'; import { MinimalNodeEntity, MinimalNodeEntryEntity, SitePaging } from 'alfresco-js-api'; @@ -44,7 +44,8 @@ export class NodeActionsService { private dialog: MatDialog, private documentListService: DocumentListService, private apiService: AlfrescoApiService, - private nodesApi: NodesApiService) {} + private nodesApi: NodesApiService, + private translation: TranslationService) {} /** * Copy node list @@ -175,11 +176,6 @@ export class NodeActionsService { getContentNodeSelection(action: string, contentEntities: MinimalNodeEntity[]): Subject { const currentParentFolderId = this.getFirstParentId(contentEntities); - let nodeEntryName = ''; - if (contentEntities.length === 1 && contentEntities[0].entry.name) { - nodeEntryName = `'${contentEntities[0].entry.name}' `; - } - const customDropdown: SitePaging = { list: { entries: [ @@ -199,8 +195,10 @@ export class NodeActionsService { } }; + const title = this.getTitleTranslation(action, contentEntities); + const data: ContentNodeSelectorComponentData = { - title: `${action} ${nodeEntryName}to ...`, + title: title, currentFolderId: currentParentFolderId, actionName: action, dropdownHideMyFiles: true, @@ -238,6 +236,17 @@ export class NodeActionsService { return data.select; } + getTitleTranslation(action: string, nodes: MinimalNodeEntity[] = []): string { + let keyPrefix = 'ITEMS'; + let name = ''; + + if (nodes.length === 1 && nodes[0].entry.name) { + name = nodes[0].entry.name; + keyPrefix = 'ITEM'; + } + return this.translation.instant(`NODE_SELECTOR.${action.toUpperCase()}_${keyPrefix}`, {name}); + } + private hasEntityCreatePermission(entry: MinimalNodeEntryEntity): boolean { return this.contentService.hasPermission(entry, 'create'); } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 09837a47a..b3a09d6dd 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -185,5 +185,12 @@ } } } + }, + "NODE_SELECTOR": { + "COPY_ITEM": "Copy '{{ name }}' to ...", + "COPY_ITEMS": "Copy to ...", + "MOVE_ITEM": "Move '{{ name }}' to ...", + "MOVE_ITEMS": "Move to ...", + "SEARCH": "Search" } }