Moved DocumentList to the ng2-alfresco package

This commit is contained in:
Denys Vuika
2016-04-18 20:51:50 +01:00
parent 4735bee08d
commit f39653bf6f
14 changed files with 115 additions and 6 deletions

View File

@@ -1,41 +0,0 @@
import {Injectable} from 'angular2/core';
import {Http, Response, RequestOptions, Headers} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import {FolderEntity} from "./core/entities/folder.entity";
import {DocumentEntity} from "./core/entities/document.entity";
@Injectable()
export class AlfrescoService {
constructor(private http: Http) {}
private _host: string = 'http://192.168.99.100:8080';
private _baseUrl: string = this._host + '/alfresco/service/slingshot/doclib/doclist/all/site/';
getFolder(folder: string) {
let headers = new Headers({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('admin:admin')
});
let options = new RequestOptions({ headers: headers });
return this.http
.get(this._baseUrl + folder, options)
.map(res => <FolderEntity> res.json())
.do(data => console.log(data)) // eyeball results in the console
.catch(this.handleError);
}
getDocumentThumbnailUrl(document: DocumentEntity) {
return this._host + '/alfresco/service/api/node/' + document.nodeRef.replace('://', '/') + '/content/thumbnails/doclib?c=queue&amp;ph=true&amp;lastModified=1';
}
getContentUrl(document: DocumentEntity) {
return this._host + '/alfresco/service/' + document.contentUrl;
}
private handleError (error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}

View File

@@ -1,33 +0,0 @@
// contains only limited subset of available fields
import {LocationEntity} from "./location.entity";
export class DocumentEntity {
nodeRef: string;
nodeType: string;
type: string;
mimetype: string;
isFolder: boolean;
isLink: boolean;
fileName: string;
displayName: string;
status: string;
title: string;
description: string;
author: string;
createdOn: string;
createdBy: string;
createdByUser: string;
modifiedOn: string;
modifiedBy: string;
modifiedByUser: string;
lockedBy: string;
lockedByUser: string;
size: number;
version: string;
contentUrl: string;
webdavUrl: string;
actionSet: string;
tags: string[];
activeWorkflows: string;
location: LocationEntity;
}

View File

@@ -1,6 +0,0 @@
import {DocumentEntity} from "./document.entity";
// contains only limited subset of available fields
export class FolderEntity {
items: DocumentEntity[];
}

View File

@@ -1,14 +0,0 @@
// contains only limited subset of available fields
export class LocationEntity {
repositoryId: string;
site: string;
siteTitle: string;
container: string;
path: string;
file: string;
parent: LocationParentEntity;
}
export class LocationParentEntity {
nodeRef: string;
}

View File

@@ -1,186 +0,0 @@
import {Component, OnInit, Input, Output, EventEmitter} 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;
}
:host .download-button {
color: #777;
text-decoration: none;
}
:host .download-button:hover {
color: #555;
}
`
],
template: `
<ol *ngIf="breadcrumb" class="breadcrumb">
<li *ngFor="#r of route; #last = last" [class.active]="last" [ngSwitch]="last">
<span *ngSwitchWhen="true">{{r.name}}</span>
<a *ngSwitchDefault href="#" (click)="goToRoute(r, $event)">{{r.name}}</a>
</li>
</ol>
<div *ngIf="folder" class="list-group">
<a href="#" *ngIf="canNavigateParent()" (click)="onNavigateParentClick($event)" class="list-group-item">
<i class="fa fa-level-up"></i> ...
</a>
<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>
<img *ngIf="thumbnails && !document.isFolder" class="file-icon" src="{{getDocumentThumbnailUrl(document)}}">
<h4 class="list-group-item-heading document-header">
{{document.displayName}}
</h4>
<p class="list-group-item-text">{{document.description}}</p>
<small>
Modified {{document.modifiedOn}} by {{document.modifiedBy}}
</small>
</a>
</div>
`,
providers: [AlfrescoService]
})
export class DocumentList implements OnInit {
// example: <alfresco-document-list [navigate]="false"></alfresco-document-list>
@Input() navigate: boolean = true;
// example: <alfresco-document-list [breadcrumb]="true"></alfresco-document-list>
@Input() breadcrumb: boolean = false;
// example: <alfresco-document-list folder-icon-class="fa fa-folder fa-4x"></alfresco-document-list>
@Input('folder-icon-class') folderIconClass: string = 'fa fa-folder-o fa-4x';
// example: <alfresco-document-list #list [thumbnails]="false"></alfresco-document-list>
@Input() thumbnails: boolean = true;
// example: <alfresco-document-list #list [downloads]="false"></alfresco-document-list>
@Input() downloads: boolean = true;
@Output() itemClick: EventEmitter<any> = new EventEmitter();
rootFolder = {
name: 'Document Library',
path: 'swsdp/documentLibrary'
};
currentFolderPath: string = 'swsdp/documentLibrary';
folder: FolderEntity;
errorMessage;
route: any[] = [];
canNavigateParent(): boolean {
return this.navigate &&
!this.breadcrumb &&
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 = <any>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);
}
}
}
onDownloadClick(event) {
event.stopPropagation();
}
onItemClick(item: DocumentEntity, $event) {
if ($event) {
$event.preventDefault();
}
this.itemClick.emit({
value: item
});
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();
}
if (this.navigate) {
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;
}
getContentUrl(document: DocumentEntity) {
return this._alfrescoService.getContentUrl(document);
}
getDocumentThumbnailUrl(document: DocumentEntity) {
return this._alfrescoService.getDocumentThumbnailUrl(document);
}
}

View File

@@ -1,5 +1,5 @@
import {Component} from 'angular2/core';
import {DocumentList} from "./document-list.component";
import {DocumentList} from 'ng2-alfresco/components';
@Component({
selector: 'home-view',

View File

@@ -3,9 +3,11 @@ import {AppComponent} from './app.component';
import {ROUTER_PROVIDERS} from "angular2/router";
import {HTTP_PROVIDERS} from 'angular2/http';
import {Authentication} from "./services/authentication";
import {ALFRESCO_PROVIDERS} from "ng2-alfresco/components";
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
Authentication
Authentication,
ALFRESCO_PROVIDERS
]);