#242 Reworked breadcrumb, deprecated up button

- 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
This commit is contained in:
Denys Vuika
2016-06-21 11:40:49 +01:00
parent 14449da0ba
commit bf7414fc85
5 changed files with 61 additions and 131 deletions

View File

@@ -1,12 +1,11 @@
<alfresco-upload-drag-area <alfresco-upload-drag-area
[showUploadDialog]="true" [showUploadDialog]="true"
currentFolderPath="{{absolutePath}}" [currentFolderPath]="currentPath"
uploaddirectory="{{relativePath}}" [uploaddirectory]="currentPath"
(onSuccess)="refreshDocumentList($event)"> (onSuccess)="documentList.reload()">
<alfresco-document-list <alfresco-document-list
#documentList #documentList
[currentFolderPath]="absolutePath" [currentFolderPath]="currentPath"
[breadcrumb]="breadcrumb"
(preview)="showFile($event)" (preview)="showFile($event)"
(folderChange)="onFolderChanged($event)"> (folderChange)="onFolderChanged($event)">
<!-- <!--
@@ -113,23 +112,12 @@
<context-menu-holder></context-menu-holder> <context-menu-holder></context-menu-holder>
<div class="p-10">
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox-1">
<input type="checkbox" id="checkbox-1" class="mdl-checkbox__input" [(ngModel)]="breadcrumb">
<span class="mdl-checkbox__label">Breadcrumb</span>
</label>
</div>
<div class="p-10"> <div class="p-10">
<ul> <ul>
<li>Current relative path: {{relativePath}}</li> <li>Current path: {{documentList.currentFolderPath}}</li>
<li>Current absolute path: {{absolutePath}}</li>
<li> <li>
<button (click)="documentList.changePath('/Sites/swsdp/documentLibrary/Agency Files/Contracts')">Go to agency contracts</button> <button (click)="documentList.changePath('/Sites/swsdp/documentLibrary/Agency Files/Contracts')">Go to agency contracts</button>
</li> </li>
<li>
<button (click)="documentList.changePath('')">Got to site root</button>
</li>
<li> <li>
<button (click)="documentList.changePath('/')">Go to root</button> <button (click)="documentList.changePath('/')">Go to root</button>
</li> </li>
@@ -139,20 +127,35 @@
<h5>Single file upload</h5> <h5>Single file upload</h5>
<alfresco-upload-button data-automation-id="single-file-upload" uploaddirectory="{{relativePath}}" currentFolderPath="{{absolutePath}}" <alfresco-upload-button data-automation-id="single-file-upload"
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button> [uploaddirectory]="currentPath"
[currentFolderPath]="currentPath"
(onSuccess)="documentList.reload()">
</alfresco-upload-button>
<h5>Folder upload</h5> <h5>Folder upload</h5>
<alfresco-upload-button data-automation-id="folder-upload" uploaddirectory="{{relativePath}}" currentFolderPath="{{absolutePath}}" <alfresco-upload-button data-automation-id="folder-upload"
[uploaddirectory]="currentPath"
[currentFolderPath]="currentPath"
[uploadFolders]="true" [uploadFolders]="true"
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button> (onSuccess)="documentList.reload()">
</alfresco-upload-button>
<h5>Multiple file upload</h5> <h5>Multiple file upload</h5>
<input type="text" data-automation-id="accepted-files-type" [(ngModel)]="acceptedFilesType"> <input type="text" data-automation-id="accepted-files-type" [(ngModel)]="acceptedFilesType">
<alfresco-upload-button data-automation-id="multiple-file-upload" uploaddirectory="{{relativePath}}" currentFolderPath="{{absolutePath}}" <alfresco-upload-button data-automation-id="multiple-file-upload"
[uploaddirectory]="currentPath"
[currentFolderPath]="currentPath"
acceptedFilesType="{{acceptedFilesType}}" acceptedFilesType="{{acceptedFilesType}}"
[multipleFiles]="true" [multipleFiles]="true"
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button> (onSuccess)="documentList.reload()">
</alfresco-upload-button>
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [fileName]="fileName" [mimeType]="mimeType" [overlayMode]="true"> <alfresco-viewer [(showViewer)]="fileShowed"
[urlFile]="urlFile"
[fileName]="fileName"
[mimeType]="mimeType"
[overlayMode]="true">
<div class="mdl-spinner mdl-js-spinner is-active"></div> <div class="mdl-spinner mdl-js-spinner is-active"></div>
</alfresco-viewer> </alfresco-viewer>
<file-uploading-dialog></file-uploading-dialog> <file-uploading-dialog></file-uploading-dialog>

View File

@@ -48,10 +48,7 @@ declare let __moduleName: string;
pipes: [AlfrescoPipeTranslate] pipes: [AlfrescoPipeTranslate]
}) })
export class FilesComponent { export class FilesComponent {
breadcrumb: boolean = false; currentPath: string = '/Sites/swsdp/documentLibrary';
navigation: boolean = true;
absolutePath: string = '/Sites/swsdp/documentLibrary';
relativePath: string = '';
urlFile: string; urlFile: string;
fileName: string; fileName: string;
@@ -78,10 +75,6 @@ export class FilesComponent {
alert('Custom folder action for ' + event.value.entry.name); alert('Custom folder action for ' + event.value.entry.name);
} }
refreshDocumentList() {
this.absolutePath += '/';
}
showFile(event) { showFile(event) {
if (event.value.entry.isFile) { if (event.value.entry.isFile) {
this.fileName = event.value.entry.name; this.fileName = event.value.entry.name;
@@ -95,8 +88,7 @@ export class FilesComponent {
onFolderChanged(event?: any) { onFolderChanged(event?: any) {
if (event) { if (event) {
this.absolutePath = event.absolutePath; this.currentPath = event.path;
this.relativePath = event.relativePath;
} }
} }
} }

View File

@@ -25,18 +25,6 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngIf="canNavigateParent()"
data-automation-id="folder_up_row"
class="parent-folder-link"
(click)="onNavigateParentClick($event)"
(dblclick)="onNavigateParentDblClick($event)">
<td [attr.colspan]="1 + columns?.length" class="non-selectable">
<button class="mdl-button mdl-js-button mdl-button--icon">
<i data-automation-id="folder_up_icon" class="material-icons">arrow_upward</i>
</button>
</td>
</tr>
<tr *ngFor="let content of folder.list.entries; let idx = index" <tr *ngFor="let content of folder.list.entries; let idx = index"
[attr.data-automation-id]="getObjectValue(content.entry, 'name')"> [attr.data-automation-id]="getObjectValue(content.entry, 'name')">
<!-- Columns --> <!-- Columns -->

View File

@@ -316,21 +316,6 @@ describe('DocumentList', () => {
expect(documentList.getNodePath(null)).toBe(null); 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', () => { it('should return root object value', () => {
let target = { let target = {
key1: 'value1' key1: 'value1'

View File

@@ -51,7 +51,7 @@ declare let __moduleName: string;
}) })
export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit, OnChanges { 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', ''); baseComponentPath = __moduleName.replace('/components/document-list.js', '');
@@ -62,7 +62,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
navigationMode: string = 'dblclick'; // click|dblclick navigationMode: string = 'dblclick'; // click|dblclick
@Input() @Input()
breadcrumb: boolean = false; breadcrumb: boolean = true;
@Input() @Input()
thumbnails: boolean = false; thumbnails: boolean = false;
@@ -80,15 +80,15 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
preview: EventEmitter<any> = new EventEmitter(); preview: EventEmitter<any> = new EventEmitter();
rootFolder = { rootFolder = {
name: '', name: 'Root',
path: '' path: '/'
}; };
@Input() @Input()
currentFolderPath: string = ''; currentFolderPath: string = this.DEFAULT_ROOT_FOLDER;
errorMessage; errorMessage;
route: any[] = []; route: { name: string, path: string }[] = [];
actions: ContentActionModel[] = []; actions: ContentActionModel[] = [];
columns: ContentColumnModel[] = []; columns: ContentColumnModel[] = [];
@@ -106,8 +106,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
if (isChanged) { if (isChanged) {
this.folderChange.emit({ this.folderChange.emit({
value: value, value: value,
absolutePath: this.currentFolderPath, path: this.currentFolderPath
relativePath: this.getRelativePath(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() { ngOnInit() {
this.changePath(this.currentFolderPath); this.changePath(this.currentFolderPath);
this.contextActionHandler.subscribe(val => this.contextActionCallback(val)); this.contextActionHandler.subscribe(val => this.contextActionCallback(val));
@@ -190,9 +180,8 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
changePath(path: string) { changePath(path: string) {
this.currentFolderPath = path || this.DEFAULT_ROOT_FOLDER; this.currentFolderPath = path || this.DEFAULT_ROOT_FOLDER;
this.rootFolder = this._createRootFolder(this.currentFolderPath); this.route = this.parsePath(this.currentFolderPath);
this.route = [this.rootFolder]; this.displayFolderContent(this.currentFolderPath);
this.displayFolderContent(this.rootFolder.path);
} }
/** /**
@@ -215,30 +204,6 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
return []; 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. * Invoked when list row is clicked.
* @param item Underlying node item * @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. * Invoked when a breadcrumb route is clicked.
* @param r Route to navigate to * @param r Route to navigate to
@@ -526,14 +483,29 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
return val; return val;
} }
private _createRootFolder(path: string): any { private parsePath(path: string): { name: string, path: string }[] {
let parts = path.split('/'); let parts = path.split('/').filter(val => val ? true : false);
let namePart = parts[parts.length - 1];
return { let result = [
name: namePart, this.rootFolder
path: path ];
};
} 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 { 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);
@@ -542,14 +514,4 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit,
private _isSortableColumn(column: ContentColumnModel) { private _isSortableColumn(column: ContentColumnModel) {
return column && column.source && !column.source.startsWith('$'); 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', '');
}
}
} }