mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
File download button for ng2 document list
- ability to download the file from the list - ability to toggle download button via attributes
This commit is contained in:
@@ -28,6 +28,10 @@ export class AlfrescoService {
|
|||||||
return this._host + '/alfresco/service/api/node/' + document.nodeRef.replace('://', '/') + '/content/thumbnails/doclib?c=queue&ph=true&lastModified=1';
|
return this._host + '/alfresco/service/api/node/' + document.nodeRef.replace('://', '/') + '/content/thumbnails/doclib?c=queue&ph=true&lastModified=1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getContentUrl(document: DocumentEntity) {
|
||||||
|
return this._host + '/alfresco/service/' + document.contentUrl;
|
||||||
|
}
|
||||||
|
|
||||||
private handleError (error: Response) {
|
private handleError (error: Response) {
|
||||||
// in a real world app, we may send the error to some remote logging infrastructure
|
// in a real world app, we may send the error to some remote logging infrastructure
|
||||||
// instead of just logging it to the console
|
// instead of just logging it to the console
|
||||||
|
@@ -26,6 +26,15 @@ import {DocumentEntity} from "./core/entities/document.entity";
|
|||||||
:host .document-header:hover {
|
:host .document-header:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host .download-button {
|
||||||
|
color: #777;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host .download-button:hover {
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
`
|
`
|
||||||
],
|
],
|
||||||
template: `
|
template: `
|
||||||
@@ -36,10 +45,13 @@ import {DocumentEntity} from "./core/entities/document.entity";
|
|||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
<div *ngIf="folder" class="list-group">
|
<div *ngIf="folder" class="list-group">
|
||||||
<a href="#" *ngIf="!breadcrumb && canNavigateParent()" (click)="onNavigateParentClick($event)" class="list-group-item">
|
<a href="#" *ngIf="canNavigateParent()" (click)="onNavigateParentClick($event)" class="list-group-item">
|
||||||
<i class="fa fa-level-up"></i> ...
|
<i class="fa fa-level-up"></i> ...
|
||||||
</a>
|
</a>
|
||||||
<a href="#" *ngFor="#document of folder.items" (click)="onItemClick(document, $event)" class="list-group-item clearfix">
|
<a href="#" *ngFor="#document of folder.items" (click)="onItemClick(document, $event)" class="list-group-item clearfix">
|
||||||
|
<a *ngIf="downloads && !document.isFolder" href="{{getContentUrl(document)}}" (click)="onDownloadClick($event)" class="download-button pull-right" download target="_blank">
|
||||||
|
<i class="fa fa-download fa-2x"></i>
|
||||||
|
</a>
|
||||||
<i *ngIf="thumbnails && document.isFolder" class="folder-icon {{folderIconClass}}"></i>
|
<i *ngIf="thumbnails && document.isFolder" class="folder-icon {{folderIconClass}}"></i>
|
||||||
<img *ngIf="thumbnails && !document.isFolder" class="file-icon" src="{{getDocumentThumbnailUrl(document)}}">
|
<img *ngIf="thumbnails && !document.isFolder" class="file-icon" src="{{getDocumentThumbnailUrl(document)}}">
|
||||||
<h4 class="list-group-item-heading document-header">
|
<h4 class="list-group-item-heading document-header">
|
||||||
@@ -64,6 +76,8 @@ export class DocumentList implements OnInit {
|
|||||||
@Input('folder-icon-class') folderIconClass: string = 'fa fa-folder-o fa-4x';
|
@Input('folder-icon-class') folderIconClass: string = 'fa fa-folder-o fa-4x';
|
||||||
// example: <alfresco-document-list #list [thumbnails]="false"></alfresco-document-list>
|
// example: <alfresco-document-list #list [thumbnails]="false"></alfresco-document-list>
|
||||||
@Input() thumbnails: boolean = true;
|
@Input() thumbnails: boolean = true;
|
||||||
|
// example: <alfresco-document-list #list [downloads]="false"></alfresco-document-list>
|
||||||
|
@Input() downloads: boolean = true;
|
||||||
|
|
||||||
rootFolder = {
|
rootFolder = {
|
||||||
name: 'Document Library',
|
name: 'Document Library',
|
||||||
@@ -76,7 +90,9 @@ export class DocumentList implements OnInit {
|
|||||||
route: any[] = [];
|
route: any[] = [];
|
||||||
|
|
||||||
canNavigateParent(): boolean {
|
canNavigateParent(): boolean {
|
||||||
return this.currentFolderPath !== this.rootFolder.path;
|
return this.navigate &&
|
||||||
|
!this.breadcrumb &&
|
||||||
|
this.currentFolderPath !== this.rootFolder.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
@@ -112,6 +128,10 @@ export class DocumentList implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDownloadClick(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
onItemClick(item: DocumentEntity, $event) {
|
onItemClick(item: DocumentEntity, $event) {
|
||||||
if ($event) {
|
if ($event) {
|
||||||
$event.preventDefault();
|
$event.preventDefault();
|
||||||
@@ -134,12 +154,14 @@ export class DocumentList implements OnInit {
|
|||||||
$event.preventDefault();
|
$event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.navigate) {
|
||||||
var idx = this.route.indexOf(r);
|
var idx = this.route.indexOf(r);
|
||||||
if (idx > -1) {
|
if (idx > -1) {
|
||||||
this.route.splice(idx + 1);
|
this.route.splice(idx + 1);
|
||||||
this.displayFolderContent(r.path);
|
this.displayFolderContent(r.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private getItemPath(item: DocumentEntity):string {
|
private getItemPath(item: DocumentEntity):string {
|
||||||
var container = item.location.container;
|
var container = item.location.container;
|
||||||
@@ -148,6 +170,10 @@ export class DocumentList implements OnInit {
|
|||||||
return item.location.site + '/' + relativePath;
|
return item.location.site + '/' + relativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getContentUrl(document: DocumentEntity) {
|
||||||
|
return this._alfrescoService.getContentUrl(document);
|
||||||
|
}
|
||||||
|
|
||||||
getDocumentThumbnailUrl(document: DocumentEntity) {
|
getDocumentThumbnailUrl(document: DocumentEntity) {
|
||||||
return this._alfrescoService.getDocumentThumbnailUrl(document);
|
return this._alfrescoService.getDocumentThumbnailUrl(document);
|
||||||
}
|
}
|
||||||
|
@@ -5,13 +5,17 @@ import {DocumentList} from "./document-list.component";
|
|||||||
template: `
|
template: `
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div><label><input type="checkbox" [(ngModel)]="thumbnails"> Toggle Thumbnails</label></div>
|
<div><label><input type="checkbox" [(ngModel)]="thumbnails"> Thumbnails</label></div>
|
||||||
<div><label><input type="checkbox" [(ngModel)]="breadcrumb"> Toggle Breadcrumb</label></div>
|
<div><label><input type="checkbox" [(ngModel)]="breadcrumb"> Breadcrumb</label></div>
|
||||||
|
<div><label><input type="checkbox" [(ngModel)]="navigation"> Navigation</label></div>
|
||||||
|
<div><label><input type="checkbox" [(ngModel)]="downloads"> Downloads</label></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<alfresco-document-list #list
|
<alfresco-document-list #list
|
||||||
[thumbnails]="thumbnails"
|
[thumbnails]="thumbnails"
|
||||||
[breadcrumb]="breadcrumb">
|
[breadcrumb]="breadcrumb"
|
||||||
|
[navigate]="navigation"
|
||||||
|
[downloads]="downloads">
|
||||||
</alfresco-document-list>
|
</alfresco-document-list>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -21,4 +25,6 @@ import {DocumentList} from "./document-list.component";
|
|||||||
export class Page1View {
|
export class Page1View {
|
||||||
thumbnails: boolean = true;
|
thumbnails: boolean = true;
|
||||||
breadcrumb: boolean = false;
|
breadcrumb: boolean = false;
|
||||||
|
navigation: boolean = true;
|
||||||
|
downloads: boolean = true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user