mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
#251 api improvements (document list)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<alfresco-upload-drag-area
|
<alfresco-upload-drag-area
|
||||||
[showUploadDialog]="true"
|
[showUploadDialog]="true"
|
||||||
[currentFolderPath]="currentPath"
|
[currentFolderPath]="currentPath"
|
||||||
[uploaddirectory]="currentPath"
|
[uploaddirectory]=""
|
||||||
(onSuccess)="documentList.reload()">
|
(onSuccess)="documentList.reload()">
|
||||||
<alfresco-document-list-breadcrumb
|
<alfresco-document-list-breadcrumb
|
||||||
[currentFolderPath]="currentPath"
|
[currentFolderPath]="currentPath"
|
||||||
@@ -120,10 +120,13 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Current path: {{documentList.currentFolderPath}}</li>
|
<li>Current path: {{documentList.currentFolderPath}}</li>
|
||||||
<li>
|
<li>
|
||||||
<button (click)="documentList.changePath('/Sites/swsdp/documentLibrary/Agency Files/Contracts')">Go to agency contracts</button>
|
<button (click)="documentList.currentFolderPath = '/Sites/swsdp/documentLibrary';">Go to Document Library</button>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button (click)="documentList.changePath('/')">Go to root</button>
|
<button (click)="documentList.currentFolderPath = '/Sites/swsdp/documentLibrary/Agency Files/Contracts'">Go to agency contracts</button>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button (click)="documentList.currentFolderPath = '/'">Go to root</button>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<button (click)="fileDialog.toggleShowDialog()">Show/Hide File Dialog</button>
|
<button (click)="fileDialog.toggleShowDialog()">Show/Hide File Dialog</button>
|
||||||
|
@@ -79,7 +79,7 @@ export class DocumentListBreadcrumb {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.target) {
|
if (this.target) {
|
||||||
this.target.changePath(route.path);
|
this.target.currentFolderPath = route.path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -240,7 +240,7 @@ describe('DocumentList', () => {
|
|||||||
documentList.navigationMode = 'click';
|
documentList.navigationMode = 'click';
|
||||||
documentList.onItemClick(node);
|
documentList.onItemClick(node);
|
||||||
|
|
||||||
expect(documentList.displayFolderContent).toHaveBeenCalledWith(path);
|
expect(documentList.currentFolderPath).toBe(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not display folder content when no target node provided', () => {
|
it('should not display folder content when no target node provided', () => {
|
||||||
|
@@ -76,8 +76,19 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
@Output()
|
@Output()
|
||||||
preview: EventEmitter<any> = new EventEmitter();
|
preview: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
|
private _path = this.DEFAULT_ROOT_FOLDER;
|
||||||
|
|
||||||
|
get currentFolderPath(): string {
|
||||||
|
return this._path;
|
||||||
|
}
|
||||||
|
|
||||||
@Input()
|
@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;
|
errorMessage;
|
||||||
|
|
||||||
@@ -109,9 +120,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
|
|
||||||
contextActionHandler: Subject<any> = new Subject();
|
contextActionHandler: Subject<any> = new Subject();
|
||||||
|
|
||||||
constructor(
|
constructor(private alfrescoService: AlfrescoService) {}
|
||||||
private _alfrescoService: AlfrescoService) {
|
|
||||||
}
|
|
||||||
|
|
||||||
getContextActions(node: MinimalNodeEntity) {
|
getContextActions(node: MinimalNodeEntity) {
|
||||||
if (node && node.entry) {
|
if (node && node.entry) {
|
||||||
@@ -148,7 +157,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.changePath(this.currentFolderPath);
|
this.displayFolderContent(this.currentFolderPath);
|
||||||
this.contextActionHandler.subscribe(val => this.contextActionCallback(val));
|
this.contextActionHandler.subscribe(val => this.contextActionCallback(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,11 +176,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
if (componentHandler) {
|
if (componentHandler) {
|
||||||
componentHandler.upgradeAllRegistered();
|
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) {
|
private performNavigation(node: MinimalNodeEntity) {
|
||||||
if (node && node.entry && node.entry.isFolder) {
|
if (node && node.entry && node.entry.isFolder) {
|
||||||
let path = this.getNodePath(node);
|
this.currentFolderPath = this.getNodePath(node);
|
||||||
this.displayFolderContent(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,14 +279,14 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
|
|
||||||
if (entry.isFile) {
|
if (entry.isFile) {
|
||||||
if (this.thumbnails) {
|
if (this.thumbnails) {
|
||||||
if (this._alfrescoService) {
|
if (this.alfrescoService) {
|
||||||
return this._alfrescoService.getDocumentThumbnailUrl(node);
|
return this.alfrescoService.getDocumentThumbnailUrl(node);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.content && entry.content.mimeType) {
|
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}`;
|
return `${this.baseComponentPath}/img/${icon}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,14 +308,9 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
displayFolderContent(path: string) {
|
||||||
* Loads and displays folder content
|
|
||||||
* @param path Node path
|
|
||||||
*/
|
|
||||||
displayFolderContent(path) {
|
|
||||||
if (path !== null) {
|
if (path !== null) {
|
||||||
this.currentFolderPath = path;
|
this.alfrescoService
|
||||||
this._alfrescoService
|
|
||||||
.getFolder(path)
|
.getFolder(path)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
folder => this.folder = this.sort(folder, this.sorting),
|
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 {
|
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') {
|
if (col.type === 'date') {
|
||||||
let datePipe = new DatePipe();
|
let datePipe = new DatePipe();
|
||||||
@@ -409,7 +408,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
onColumnHeaderClick(column: ContentColumnModel) {
|
onColumnHeaderClick(column: ContentColumnModel) {
|
||||||
if (column && this._isSortableColumn(column)) {
|
if (column && this.isSortableColumn(column)) {
|
||||||
if (this.sorting.key === column.source) {
|
if (this.sorting.key === column.source) {
|
||||||
this.sorting.direction = this.sorting.direction === 'asc' ? 'desc' : 'asc';
|
this.sorting.direction = this.sorting.direction === 'asc' ? 'desc' : 'asc';
|
||||||
} else {
|
} else {
|
||||||
@@ -423,14 +422,14 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sort(node: NodePaging, options: ColumnSortingModel) {
|
sort(node: NodePaging, options: ColumnSortingModel) {
|
||||||
if (this._hasEntries(node)) {
|
if (this.hasEntries(node)) {
|
||||||
node.list.entries.sort((a: MinimalNodeEntity, b: MinimalNodeEntity) => {
|
node.list.entries.sort((a: MinimalNodeEntity, b: MinimalNodeEntity) => {
|
||||||
if (a.entry.isFolder !== b.entry.isFolder) {
|
if (a.entry.isFolder !== b.entry.isFolder) {
|
||||||
return a.entry.isFolder ? -1 : 1;
|
return a.entry.isFolder ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let left = this._getObjectValueRaw(a.entry, options.key).toString();
|
let left = this.getObjectValueRaw(a.entry, options.key).toString();
|
||||||
let right = this._getObjectValueRaw(b.entry, options.key).toString();
|
let right = this.getObjectValueRaw(b.entry, options.key).toString();
|
||||||
|
|
||||||
return options.direction === 'asc'
|
return options.direction === 'asc'
|
||||||
? left.localeCompare(right)
|
? left.localeCompare(right)
|
||||||
@@ -440,7 +439,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getObjectValueRaw(target: any, key: string) {
|
private getObjectValueRaw(target: any, key: string) {
|
||||||
let val = this.getObjectValue(target, key);
|
let val = this.getObjectValue(target, key);
|
||||||
|
|
||||||
if (val instanceof Date) {
|
if (val instanceof Date) {
|
||||||
@@ -450,11 +449,11 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _hasEntries(node: NodePaging): boolean {
|
private hasEntries(node: NodePaging): boolean {
|
||||||
return (node && node.list && node.list.entries && node.list.entries.length > 0);
|
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('$');
|
return column && column.source && !column.source.startsWith('$');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user