From 4dd1073f7002f7c8dd92abfacd173943ebbe75f7 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 8 Jun 2016 14:49:47 +0100 Subject: [PATCH] #124 double click navigation, 'preview' event --- .../app/components/files/files.component.html | 2 +- .../src/components/datatable.component.css | 4 +- .../src/components/datatable.component.html | 2 +- .../src/components/document-list.css | 27 +++--- .../src/components/document-list.html | 13 ++- .../src/components/document-list.spec.ts | 1 + .../src/components/document-list.ts | 93 +++++++++++++++---- 7 files changed, 105 insertions(+), 37 deletions(-) diff --git a/demo-shell-ng2/app/components/files/files.component.html b/demo-shell-ng2/app/components/files/files.component.html index 0197898389..e9a2ac89cf 100644 --- a/demo-shell-ng2/app/components/files/files.component.html +++ b/demo-shell-ng2/app/components/files/files.component.html @@ -7,7 +7,7 @@ #documentList [currentFolderPath]="absolutePath" [breadcrumb]="breadcrumb" - (itemClick)="showFile($event)" + (preview)="showFile($event)" (folderChange)="onFolderChanged($event)"> - - - + + @@ -37,8 +41,9 @@ [attr.data-automation-id]="getObjectValue(content.entry, 'name')">
diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts index 405d5752bf..fa29f46362 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts @@ -251,6 +251,7 @@ describe('DocumentList', () => { spyOn(documentList, 'getNodePath').and.returnValue(path); spyOn(documentList, 'displayFolderContent').and.stub(); + documentList.navigationMode = 'click'; documentList.onItemClick(node); expect(documentList.displayFolderContent).toHaveBeenCalledWith(path); diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts index 7f5990ca62..b41294b76d 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -52,6 +52,9 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, @Input() navigate: boolean = true; + @Input('navigation-mode') + navigationMode: string = 'dblclick'; // click|dblclick + @Input() breadcrumb: boolean = false; @@ -64,9 +67,15 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, @Output() itemClick: EventEmitter = new EventEmitter(); + @Output() + itemDblClick: EventEmitter = new EventEmitter(); + @Output() folderChange: EventEmitter = new EventEmitter(); + @Output() + preview: EventEmitter = new EventEmitter(); + rootFolder = { name: '', path: '' @@ -169,17 +178,23 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, * Invoked when 'parent folder' element is clicked. * @param e DOM event */ - onNavigateParentClick(e) { + onNavigateParentClick(e?: Event) { if (e) { e.preventDefault(); } - if (this.navigate) { - this.route.pop(); - let parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder; - if (parent) { - this.displayFolderContent(parent.path); - } + if (this.navigate && this.navigationMode === 'click') { + this.navigateToParent(); + } + } + + onNavigateParentDblClick(e?: Event) { + if (e) { + e.preventDefault(); + } + + if (this.navigate && this.navigationMode === 'dblclick') { + this.navigateToParent(); } } @@ -188,7 +203,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, * @param item Underlying node item * @param e DOM event (optional) */ - onItemClick(item: MinimalNodeEntity, e = null) { + onItemClick(item: MinimalNodeEntity, e?: Event) { if (e) { e.preventDefault(); } @@ -197,18 +212,64 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, value: item }); - if (this.navigate && item && item.entry) { - if (item.entry.isFolder) { - let path = this.getNodePath(item); - this.route.push({ - name: item.entry.name, - path: path - }); - this.displayFolderContent(path); + if (this.navigate && this.navigationMode === 'click') { + if (item && item.entry) { + if (item.entry.isFile) { + this.preview.emit({ + value: item + }); + } + + if (item.entry.isFolder) { + this.performNavigation(item); + } } } } + onItemDblClick(item: MinimalNodeEntity, e?: Event) { + if (e) { + e.preventDefault(); + } + + this.itemDblClick.emit({ + value: item + }); + + if (this.navigate && this.navigationMode === 'dblclick') { + if (item && item.entry) { + if (item.entry.isFile) { + this.preview.emit({ + value: item + }); + } + + if (item.entry.isFolder) { + this.performNavigation(item); + } + } + } + } + + private performNavigation(node: MinimalNodeEntity) { + if (node && node.entry && node.entry.isFolder) { + let path = this.getNodePath(node); + this.route.push({ + name: node.entry.name, + path: path + }); + this.displayFolderContent(path); + } + } + + navigateToParent() { + this.route.pop(); + let parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder; + if (parent) { + this.displayFolderContent(parent.path); + } + } + /** * Invoked when a breadcrumb route is clicked. * @param r Route to navigate to