diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts index 7de8f4adfb..dde90f4bb6 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts @@ -36,8 +36,8 @@ export class ContentNodeSelectorComponent { constructor(public translation: TranslationService, @Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) { - this.action = data.actionName.toUpperCase(); - this.buttonActionName = data.actionName ? `NODE_SELECTOR.${this.action}` : 'NODE_SELECTOR.CHOOSE'; + this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE'; + this.buttonActionName = `NODE_SELECTOR.${this.action}`; this.title = data.title; } diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html index 4aeeaa3dc8..70d0051436 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html @@ -1,6 +1,6 @@
{{data?.title}} + data-automation-id="content-node-selector-title">{{title}}
diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts index 5dda2d1368..08a65c10a5 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.spec.ts @@ -33,8 +33,8 @@ describe('AttachFileWidgetDialogComponent', () => { let widget: AttachFileWidgetDialogComponent; let fixture: ComponentFixture; const data: AttachFileWidgetDialogComponentData = { - title: 'Move along citizen...', - actionName: 'move', + title: 'Choose along citizen...', + actionName: 'Choose', selected: new EventEmitter(), ecmHost: 'http://fakeUrl.com/' }; @@ -144,5 +144,23 @@ describe('AttachFileWidgetDialogComponent', () => { chooseButton.click(); }); }); + + it('should update the title when the selected node is a file', () => { + const fakeNode: Node = new Node({ id: 'fake', isFile: true}); + contentNodePanel.componentInstance.select.emit([fakeNode]); + fixture.detectChanges(); + const titleElement = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-title"]')); + expect(titleElement).not.toBeNull(); + expect(titleElement.nativeElement.innerText).toBe('ATTACH-FILE.ACTIONS.CHOOSE_ITEM'); + }); + + it('should update the title when the selected node is a folder', () => { + const fakeNode: Node = new Node({ id: 'fake', isFolder: true}); + contentNodePanel.componentInstance.select.emit([fakeNode]); + fixture.detectChanges(); + const titleElement = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-title"]')); + expect(titleElement).not.toBeNull(); + expect(titleElement.nativeElement.innerText).toBe('ATTACH-FILE.ACTIONS.CHOOSE_IN'); + }); }); }); diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.ts index c7957e7f74..ba45178e0a 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.ts @@ -17,7 +17,7 @@ import { Component, Inject, ViewEncapsulation, ViewChild } from '@angular/core'; import { MAT_DIALOG_DATA } from '@angular/material'; -import { ExternalAlfrescoApiService, AlfrescoApiService, AuthenticationService, LoginDialogPanelComponent, SitesService, SearchService } from '@alfresco/adf-core'; +import { ExternalAlfrescoApiService, AlfrescoApiService, AuthenticationService, LoginDialogPanelComponent, SitesService, SearchService, TranslationService } from '@alfresco/adf-core'; import { DocumentListService, ContentNodeSelectorService } from '@alfresco/adf-content-services'; import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface'; import { Node } from '@alfresco/js-api'; @@ -39,13 +39,18 @@ export class AttachFileWidgetDialogComponent { @ViewChild('adfLoginPanel') loginPanel: LoginDialogPanelComponent; + title: string; + action: string; + buttonActionName: string; chosenNode: Node[]; - buttonActionName; - constructor(@Inject(MAT_DIALOG_DATA) public data: AttachFileWidgetDialogComponentData, + constructor(private translation: TranslationService, + @Inject(MAT_DIALOG_DATA) public data: AttachFileWidgetDialogComponentData, private externalApiService: AlfrescoApiService) { ( externalApiService).init(data.ecmHost, data.context); - this.buttonActionName = data.actionName ? `ATTACH-FILE.ACTIONS.${data.actionName.toUpperCase()}` : 'ATTACH-FILE.ACTIONS.CHOOSE'; + this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE'; + this.buttonActionName = `ATTACH-FILE.ACTIONS.${this.action}`; + this.title = data.title; } isLoggedIn() { @@ -66,6 +71,7 @@ export class AttachFileWidgetDialogComponent { } else { this.chosenNode = null; } + this.updateTitle(nodeList); } onClick() { @@ -73,4 +79,17 @@ export class AttachFileWidgetDialogComponent { this.data.selected.complete(); } + updateTitle(nodeList: Node[]): void { + if (this.action === 'CHOOSE' && nodeList) { + if (nodeList[0].isFile) { + this.title = this.getTitleTranslation(this.action + '_ITEM', nodeList[0].name); + } else if (nodeList[0].isFolder) { + this.title = this.getTitleTranslation(this.action + '_IN', nodeList[0].name); + } + } + } + + getTitleTranslation(action: string, name: string): string { + return this.translation.instant(`ATTACH-FILE.ACTIONS.${action}`, { name }); + } } diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts index a4ecda3b3f..0f84187161 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts @@ -17,6 +17,7 @@ import { MatDialog } from '@angular/material'; import { EventEmitter, Injectable, Output } from '@angular/core'; +import { TranslationService } from '@alfresco/adf-core'; import { Subject, Observable } from 'rxjs'; import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface'; import { Node } from '@alfresco/js-api'; @@ -31,7 +32,8 @@ export class AttachFileWidgetDialogService { @Output() error: EventEmitter = new EventEmitter(); - constructor(private dialog: MatDialog) { + constructor(private dialog: MatDialog, + private translation: TranslationService) { } /** @@ -41,19 +43,18 @@ export class AttachFileWidgetDialogService { * @returns Information about the chosen file(s) */ openLogin(ecmHost: string, actionName?: string, context?: string): Observable { - const titleString: string = `Please log in for ${ecmHost}`; const selected = new Subject(); selected.subscribe({ complete: this.close.bind(this) }); const data: AttachFileWidgetDialogComponentData = { - title : titleString, + title : this.getLoginTitleTranslation(ecmHost), actionName, selected, ecmHost, context, - isSelectionValid: this.isNodeFile.bind(this), + isSelectionValid: this.isNodeValid.bind(this), showFilesInResult: true }; @@ -70,8 +71,11 @@ export class AttachFileWidgetDialogService { this.dialog.closeAll(); } - private isNodeFile(entry: Node): boolean { - return entry.isFile; + private isNodeValid(entry: Node): boolean { + return entry.isFile || entry.isFolder; } + private getLoginTitleTranslation(ecmHost: string): string { + return this.translation.instant(`ATTACH-FILE.DIALOG.LOGIN`, { ecmHost }); + } } diff --git a/lib/process-services/src/lib/i18n/en.json b/lib/process-services/src/lib/i18n/en.json index 199cd86c4d..85c5023471 100644 --- a/lib/process-services/src/lib/i18n/en.json +++ b/lib/process-services/src/lib/i18n/en.json @@ -324,10 +324,15 @@ } }, "ATTACH-FILE": { + "DIALOG" : { + "LOGIN": "Please log in for {{ ecmHost }}" + }, "ACTIONS": { "LOGIN": "Login", "CANCEL": "Cancel", - "CHOOSE": "Choose" + "CHOOSE": "Choose", + "CHOOSE_ITEM": "Choose {{ name }} to...", + "CHOOSE_IN": "Choose file in {{ name }}..." } } }