From 859827f7c1c3db67fe5d457538267fdbda6434e0 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 22 Jun 2016 12:51:44 +0100 Subject: [PATCH] #251 api improvements (document list) --- .../app/components/files/files.component.html | 9 ++- .../document-list-breadcrumb.component.ts | 2 +- .../src/components/document-list.spec.ts | 2 +- .../src/components/document-list.ts | 57 +++++++++---------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/demo-shell-ng2/app/components/files/files.component.html b/demo-shell-ng2/app/components/files/files.component.html index a8bc517c1e..7c5d67921f 100644 --- a/demo-shell-ng2/app/components/files/files.component.html +++ b/demo-shell-ng2/app/components/files/files.component.html @@ -1,7 +1,7 @@
  • Current path: {{documentList.currentFolderPath}}
  • - +
  • - + +
  • +
  • +
  • diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts index ee28d74d03..16d086dfca 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list-breadcrumb.component.ts @@ -79,7 +79,7 @@ export class DocumentListBreadcrumb { }); if (this.target) { - this.target.changePath(route.path); + this.target.currentFolderPath = route.path; } } } 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 410cc77d52..30d12057e8 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 @@ -240,7 +240,7 @@ describe('DocumentList', () => { documentList.navigationMode = 'click'; documentList.onItemClick(node); - expect(documentList.displayFolderContent).toHaveBeenCalledWith(path); + expect(documentList.currentFolderPath).toBe(path); }); it('should not display folder content when no target node provided', () => { 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 690168d8b4..2d45a61e0b 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -76,8 +76,19 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, @Output() preview: EventEmitter = new EventEmitter(); + private _path = this.DEFAULT_ROOT_FOLDER; + + get currentFolderPath(): string { + return this._path; + } + @Input() - currentFolderPath: string = this.DEFAULT_ROOT_FOLDER; + set currentFolderPath(value: string) { + if (value !== this._path) { + this._path = value || this.DEFAULT_ROOT_FOLDER; + this.displayFolderContent(this._path); + } + } errorMessage; @@ -109,9 +120,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, contextActionHandler: Subject = new Subject(); - constructor( - private _alfrescoService: AlfrescoService) { - } + constructor(private alfrescoService: AlfrescoService) {} getContextActions(node: MinimalNodeEntity) { if (node && node.entry) { @@ -148,7 +157,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } ngOnInit() { - this.changePath(this.currentFolderPath); + this.displayFolderContent(this.currentFolderPath); this.contextActionHandler.subscribe(val => this.contextActionCallback(val)); } @@ -167,11 +176,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, if (componentHandler) { componentHandler.upgradeAllRegistered(); } - } - changePath(path: string) { - this.currentFolderPath = path || this.DEFAULT_ROOT_FOLDER; - this.displayFolderContent(this.currentFolderPath); } /** @@ -255,8 +260,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, private performNavigation(node: MinimalNodeEntity) { if (node && node.entry && node.entry.isFolder) { - let path = this.getNodePath(node); - this.displayFolderContent(path); + this.currentFolderPath = this.getNodePath(node); } } @@ -275,14 +279,14 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, if (entry.isFile) { if (this.thumbnails) { - if (this._alfrescoService) { - return this._alfrescoService.getDocumentThumbnailUrl(node); + if (this.alfrescoService) { + return this.alfrescoService.getDocumentThumbnailUrl(node); } return null; } if (entry.content && entry.content.mimeType) { - let icon = this._alfrescoService.getMimeTypeIcon(entry.content.mimeType); + let icon = this.alfrescoService.getMimeTypeIcon(entry.content.mimeType); return `${this.baseComponentPath}/img/${icon}`; } } @@ -304,14 +308,9 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } } - /** - * Loads and displays folder content - * @param path Node path - */ - displayFolderContent(path) { + displayFolderContent(path: string) { if (path !== null) { - this.currentFolderPath = path; - this._alfrescoService + this.alfrescoService .getFolder(path) .subscribe( folder => this.folder = this.sort(folder, this.sorting), @@ -367,7 +366,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } getCellValue(row: MinimalNodeEntity, col: ContentColumnModel): any { - let value = this._getObjectValueRaw(row.entry, col.source); + let value = this.getObjectValueRaw(row.entry, col.source); if (col.type === 'date') { let datePipe = new DatePipe(); @@ -409,7 +408,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } onColumnHeaderClick(column: ContentColumnModel) { - if (column && this._isSortableColumn(column)) { + if (column && this.isSortableColumn(column)) { if (this.sorting.key === column.source) { this.sorting.direction = this.sorting.direction === 'asc' ? 'desc' : 'asc'; } else { @@ -423,14 +422,14 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, } sort(node: NodePaging, options: ColumnSortingModel) { - if (this._hasEntries(node)) { + if (this.hasEntries(node)) { node.list.entries.sort((a: MinimalNodeEntity, b: MinimalNodeEntity) => { if (a.entry.isFolder !== b.entry.isFolder) { return a.entry.isFolder ? -1 : 1; } - let left = this._getObjectValueRaw(a.entry, options.key).toString(); - let right = this._getObjectValueRaw(b.entry, options.key).toString(); + let left = this.getObjectValueRaw(a.entry, options.key).toString(); + let right = this.getObjectValueRaw(b.entry, options.key).toString(); return options.direction === 'asc' ? left.localeCompare(right) @@ -440,7 +439,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, return node; } - private _getObjectValueRaw(target: any, key: string) { + private getObjectValueRaw(target: any, key: string) { let val = this.getObjectValue(target, key); if (val instanceof Date) { @@ -450,11 +449,11 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, return val; } - private _hasEntries(node: NodePaging): boolean { + private hasEntries(node: NodePaging): boolean { return (node && node.list && node.list.entries && node.list.entries.length > 0); } - private _isSortableColumn(column: ContentColumnModel) { + private isSortableColumn(column: ContentColumnModel) { return column && column.source && !column.source.startsWith('$'); } }