import {Component, OnInit, Input} from "angular2/core"; import {AlfrescoService} from "./alfresco.service"; import {FolderEntity} from "./core/entities/folder.entity"; import {DocumentEntity} from "./core/entities/document.entity"; @Component({ selector: 'alfresco-document-list', styles: [ ` :host .breadcrumb { margin-bottom: 4px; } :host .folder-icon { float: left; margin-right: 10px; } :host .file-icon { width: 52px; height: 52px; float: left; margin-right: 10px; } :host .document-header:hover { text-decoration: underline; } ` ], template: `
...

{{document.displayName}}

{{document.description}}

Modified {{document.modifiedOn}} by {{document.modifiedBy}}
`, providers: [AlfrescoService] }) export class DocumentList implements OnInit { // example: @Input() navigate: boolean = true; // example: @Input() breadcrumb: boolean = false; // example: @Input('folder-icon-class') folderIconClass: string = 'fa fa-folder-o fa-4x'; // example: @Input() thumbnails: boolean = true; rootFolder = { name: 'Document Library', path: 'swsdp/documentLibrary' }; currentFolderPath: string = 'swsdp/documentLibrary'; folder: FolderEntity; errorMessage; route: any[] = []; canNavigateParent(): boolean { return this.currentFolderPath !== this.rootFolder.path; } constructor ( private _alfrescoService: AlfrescoService ) {} ngOnInit() { this.route.push(this.rootFolder); this.displayFolderContent(this.rootFolder.path); } private displayFolderContent(path) { this.currentFolderPath = path; this._alfrescoService .getFolder(path) .subscribe( folder => this.folder = folder, error => this.errorMessage = error ); } onNavigateParentClick($event) { if ($event) { $event.preventDefault(); } if (this.navigate) { this.route.pop(); var parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder; if (parent) { this.displayFolderContent(parent.path); } } } onItemClick(item: DocumentEntity, $event) { if ($event) { $event.preventDefault(); } if (this.navigate && item) { if (item.isFolder) { var path = this.getItemPath(item); this.route.push({ name: item.displayName, path: path }); this.displayFolderContent(path); } } } goToRoute(r, $event) { if ($event) { $event.preventDefault(); } var idx = this.route.indexOf(r); if (idx > -1) { this.route.splice(idx + 1); this.displayFolderContent(r.path); } } private getItemPath(item: DocumentEntity):string { var container = item.location.container; var path = item.location.path !== '/' ? (item.location.path + '/' ) : '/'; var relativePath = container + path + item.fileName; return item.location.site + '/' + relativePath; } getDocumentThumbnailUrl(document: DocumentEntity) { return this._alfrescoService.getDocumentThumbnailUrl(document); } }