From bf7414fc8511e6f4d2841cdfec53a311586510de Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 21 Jun 2016 11:40:49 +0100 Subject: [PATCH] #242 Reworked breadcrumb, deprecated up button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - reworked breadcrumb - deprecated up button in favour of external implementations - removed hardcoded “document library” path from document list (always start with root) - always dealing with ‘absolute’ paths - simplified upload demo --- .../app/components/files/files.component.html | 51 ++++----- .../app/components/files/files.component.ts | 12 +-- .../src/components/document-list.html | 12 --- .../src/components/document-list.spec.ts | 15 --- .../src/components/document-list.ts | 102 ++++++------------ 5 files changed, 61 insertions(+), 131 deletions(-) diff --git a/demo-shell-ng2/app/components/files/files.component.html b/demo-shell-ng2/app/components/files/files.component.html index d6e89f92a3..988bb96484 100644 --- a/demo-shell-ng2/app/components/files/files.component.html +++ b/demo-shell-ng2/app/components/files/files.component.html @@ -1,12 +1,11 @@ + [currentFolderPath]="currentPath" + [uploaddirectory]="currentPath" + (onSuccess)="documentList.reload()"> 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 31374c9c97..956c8323ef 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 @@ -316,21 +316,6 @@ describe('DocumentList', () => { expect(documentList.getNodePath(null)).toBe(null); }); - /* - it('should get node path', () => { - let location = new LocationEntity(); - location.site = 'swsdp'; - location.container = 'documentLibrary'; - location.path = '\/'; - - let node = new DocumentEntity(); - node.fileName = 'fileName'; - node.location = location; - - expect(documentList.getNodePath(node)).toBe('swsdp/documentLibrary/fileName'); - }); - */ - it('should return root object value', () => { let target = { key1: 'value1' 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 82ccd4b3fd..85765d0c28 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -51,7 +51,7 @@ declare let __moduleName: string; }) export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, OnChanges { - DEFAULT_ROOT_FOLDER: string = '/Sites/swsdp/documentLibrary'; + DEFAULT_ROOT_FOLDER: string = '/'; baseComponentPath = __moduleName.replace('/components/document-list.js', ''); @@ -62,7 +62,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, navigationMode: string = 'dblclick'; // click|dblclick @Input() - breadcrumb: boolean = false; + breadcrumb: boolean = true; @Input() thumbnails: boolean = false; @@ -80,15 +80,15 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, preview: EventEmitter = new EventEmitter(); rootFolder = { - name: '', - path: '' + name: 'Root', + path: '/' }; @Input() - currentFolderPath: string = ''; + currentFolderPath: string = this.DEFAULT_ROOT_FOLDER; errorMessage; - route: any[] = []; + route: { name: string, path: string }[] = []; actions: ContentActionModel[] = []; columns: ContentColumnModel[] = []; @@ -106,8 +106,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, if (isChanged) { this.folderChange.emit({ value: value, - absolutePath: this.currentFolderPath, - relativePath: this.getRelativePath(this.currentFolderPath) + path: this.currentFolderPath }); } } @@ -157,15 +156,6 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } } - /** - * Determines whether navigation to parent folder is available. - * @returns {boolean} - */ - canNavigateParent(): boolean { - return this.navigate && !this.breadcrumb && - this.currentFolderPath !== this.rootFolder.path; - } - ngOnInit() { this.changePath(this.currentFolderPath); this.contextActionHandler.subscribe(val => this.contextActionCallback(val)); @@ -190,9 +180,8 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, changePath(path: string) { this.currentFolderPath = path || this.DEFAULT_ROOT_FOLDER; - this.rootFolder = this._createRootFolder(this.currentFolderPath); - this.route = [this.rootFolder]; - this.displayFolderContent(this.rootFolder.path); + this.route = this.parsePath(this.currentFolderPath); + this.displayFolderContent(this.currentFolderPath); } /** @@ -215,30 +204,6 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, return []; } - /** - * Invoked when 'parent folder' element is clicked. - * @param e DOM event - */ - onNavigateParentClick(e?: Event) { - if (e) { - e.preventDefault(); - } - - if (this.navigate && this.navigationMode === 'click') { - this.navigateToParent(); - } - } - - onNavigateParentDblClick(e?: Event) { - if (e) { - e.preventDefault(); - } - - if (this.navigate && this.navigationMode === 'dblclick') { - this.navigateToParent(); - } - } - /** * Invoked when list row is clicked. * @param item Underlying node item @@ -309,14 +274,6 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } } - 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 @@ -526,14 +483,29 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, return val; } - private _createRootFolder(path: string): any { - let parts = path.split('/'); - let namePart = parts[parts.length - 1]; - return { - name: namePart, - path: path - }; - } + private parsePath(path: string): { name: string, path: string }[] { + let parts = path.split('/').filter(val => val ? true : false); + + let result = [ + this.rootFolder + ]; + + let parentPath: string = this.rootFolder.path; + + for (let i = 0; i < parts.length; i++) { + if (!parentPath.endsWith('/')) { + parentPath += '/'; + } + parentPath += parts[i]; + + result.push({ + name: parts[i], + path: parentPath + }); + } + + return result; + }; private _hasEntries(node: NodePaging): boolean { return (node && node.list && node.list.entries && node.list.entries.length > 0); @@ -542,14 +514,4 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, private _isSortableColumn(column: ContentColumnModel) { return column && column.source && !column.source.startsWith('$'); } - - private getRelativePath(path: string): string { - if (path.indexOf('/Sites/swsdp/documentLibrary/') !== -1) { - return path.replace('/Sites/swsdp/documentLibrary/', ''); - } else { - return path.replace('/Sites/swsdp/documentLibrary', ''); - } - } } - -