Use alfresco-core-rest-api to fetch doclib items

Refs #7
This commit is contained in:
Will Abson 2016-05-06 13:48:00 +01:00
parent a8ba9203de
commit e619ff661c
12 changed files with 187 additions and 76 deletions

View File

@ -4,7 +4,7 @@
<content-column source="$thumbnail"></content-column> <content-column source="$thumbnail"></content-column>
<content-column <content-column
title="{{'DOCUMENT_LIST.COLUMNS.DISPLAY_NAME' | translate}}" title="{{'DOCUMENT_LIST.COLUMNS.DISPLAY_NAME' | translate}}"
source="displayName" source="name"
class="full-width name-column"> class="full-width name-column">
</content-column> </content-column>
<content-column <content-column
@ -13,11 +13,11 @@
</content-column> </content-column>
<content-column <content-column
title="{{'DOCUMENT_LIST.COLUMNS.CREATED_BY' | translate}}" title="{{'DOCUMENT_LIST.COLUMNS.CREATED_BY' | translate}}"
source="createdBy"> source="createdByUser">
</content-column> </content-column>
<content-column <content-column
title="{{'DOCUMENT_LIST.COLUMNS.CREATED_ON' | translate}}" title="{{'DOCUMENT_LIST.COLUMNS.CREATED_ON' | translate}}"
source="createdOn"> source="createdAt">
</content-column> </content-column>
</content-columns> </content-columns>

View File

@ -29,6 +29,7 @@
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="/app/js/xml2json.js"></script> <script src="/app/js/xml2json.js"></script>
<script src="node_modules/alfresco-core-rest-api/bundle.js"></script>
<!-- 2. Configure SystemJS --> <!-- 2. Configure SystemJS -->
<script> <script>

View File

@ -16,7 +16,7 @@
*/ */
import { OnInit, EventEmitter, AfterContentInit, AfterViewChecked } from 'angular2/core'; import { OnInit, EventEmitter, AfterContentInit, AfterViewChecked } from 'angular2/core';
import { AlfrescoService } from './../services/alfresco.service'; import { AlfrescoService } from './../services/alfresco.service';
import { FolderEntity, DocumentEntity } from './../models/document-library.model'; import { MinimalNodeEntity, NodePaging } from './../models/document-library.model';
import { ContentActionModel } from './../models/content-action.model'; import { ContentActionModel } from './../models/content-action.model';
import { ContentColumnModel } from './../models/content-column.model'; import { ContentColumnModel } from './../models/content-column.model';
export declare class DocumentList implements OnInit, AfterViewChecked, AfterContentInit { export declare class DocumentList implements OnInit, AfterViewChecked, AfterContentInit {
@ -30,7 +30,7 @@ export declare class DocumentList implements OnInit, AfterViewChecked, AfterCont
path: string; path: string;
}; };
currentFolderPath: string; currentFolderPath: string;
folder: FolderEntity; folder: NodePaging;
errorMessage: any; errorMessage: any;
route: any[]; route: any[];
actions: ContentActionModel[]; actions: ContentActionModel[];
@ -61,7 +61,7 @@ export declare class DocumentList implements OnInit, AfterViewChecked, AfterCont
* @param item Underlying node item * @param item Underlying node item
* @param e DOM event (optional) * @param e DOM event (optional)
*/ */
onItemClick(item: DocumentEntity, e?: any): void; onItemClick(item: MinimalNodeEntity, e?: any): void;
/** /**
* 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
@ -73,19 +73,19 @@ export declare class DocumentList implements OnInit, AfterViewChecked, AfterCont
* @param node Node to get URL for. * @param node Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getContentUrl(node: DocumentEntity): string; getContentUrl(node: MinimalNodeEntity): string;
/** /**
* Gets thumbnail URL for the given document node. * Gets thumbnail URL for the given document node.
* @param node Node to get URL for. * @param node Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getDocumentThumbnailUrl(node: DocumentEntity): string; getDocumentThumbnailUrl(node: MinimalNodeEntity): string;
/** /**
* Invoked when executing content action for a document or folder. * Invoked when executing content action for a document or folder.
* @param node Node to be the context of the execution. * @param node Node to be the context of the execution.
* @param action Action to be executed against the context. * @param action Action to be executed against the context.
*/ */
executeContentAction(node: DocumentEntity, action: ContentActionModel): void; executeContentAction(node: MinimalNodeEntity, action: ContentActionModel): void;
/** /**
* Loads and displays folder content * Loads and displays folder content
* @param path Node path * @param path Node path
@ -96,7 +96,7 @@ export declare class DocumentList implements OnInit, AfterViewChecked, AfterCont
* @param node * @param node
* @returns {string} * @returns {string}
*/ */
getNodePath(node: DocumentEntity): string; getNodePath(node: MinimalNodeEntity): string;
/** /**
* Gets a value from an object by composed key * Gets a value from an object by composed key
* documentList.getObjectValue({ item: { nodeType: 'cm:folder' }}, 'item.nodeType') ==> 'cm:folder' * documentList.getObjectValue({ item: { nodeType: 'cm:folder' }}, 'item.nodeType') ==> 'cm:folder'

View File

@ -28,26 +28,26 @@
</td> </td>
</tr> </tr>
<tr *ngFor="#content of folder.items; #idx = index"> <tr *ngFor="#content of folder.list.entries; #idx = index">
<!-- Columns --> <!-- Columns -->
<td *ngFor="#col of columns" [ngSwitch]="col.source" <td *ngFor="#col of columns" [ngSwitch]="col.source"
class="mdl-data-table__cell--non-numeric {{content.isFolder ? 'folder-row-cell' : 'document-row-cell'}} {{col.cssClass}}" class="mdl-data-table__cell--non-numeric {{content.entry.isFolder ? 'folder-row-cell' : 'document-row-cell'}} {{col.cssClass}}"
(click)="onItemClick(content, $event)"> (click)="onItemClick(content, $event)">
<div *ngSwitchWhen="'$thumbnail'"> <div *ngSwitchWhen="'$thumbnail'">
<div *ngIf="content.isFolder"> <div *ngIf="content.entry.isFolder">
<i class="material-icons folder-thumbnail">{{folderIcon || 'folder_open'}}</i> <i class="material-icons folder-thumbnail">{{folderIcon || 'folder_open'}}</i>
</div> </div>
<div *ngIf="!content.isFolder"> <div *ngIf="!content.entry.isFolder">
<img class="document-thumbnail" alt="" src="{{getDocumentThumbnailUrl(content)}}"> <img class="document-thumbnail" alt="" src="{{getDocumentThumbnailUrl(content)}}">
</div> </div>
</div> </div>
<span *ngSwitchDefault> <span *ngSwitchDefault>
{{getObjectValue(content, col.source)}} {{getObjectValue(content.entry, col.source)}}
</span> </span>
</td> </td>
<!-- Actions: folder --> <!-- Actions: folder -->
<td *ngIf="content.isFolder"> <td *ngIf="content.entry.isFolder">
<!-- action buttons --> <!-- action buttons -->
<button class="mdl-button mdl-js-button mdl-button--icon" <button class="mdl-button mdl-js-button mdl-button--icon"
*ngFor="#action of getContentActions('folder', 'button')" *ngFor="#action of getContentActions('folder', 'button')"
@ -69,7 +69,7 @@
</ul> </ul>
</td> </td>
<!-- Actions: document --> <!-- Actions: document -->
<td *ngIf="!content.isFolder"> <td *ngIf="!content.entry.isFolder">
<!-- action buttons --> <!-- action buttons -->
<button class="mdl-button mdl-js-button mdl-button--icon" <button class="mdl-button mdl-js-button mdl-button--icon"
*ngFor="#action of getContentActions('document', 'button')" *ngFor="#action of getContentActions('document', 'button')"

View File

@ -125,10 +125,10 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
value: item value: item
}); });
if (this.navigate && item) { if (this.navigate && item) {
if (item.isFolder) { if (item.entry.isFolder) {
var path = this.getNodePath(item); var path = this.getNodePath(item);
this.route.push({ this.route.push({
name: item.displayName, name: item.entry.name,
path: path path: path
}); });
this.displayFolderContent(path); this.displayFolderContent(path);
@ -204,10 +204,8 @@ System.register(['angular2/core', './../services/alfresco.service', './../models
*/ */
DocumentList.prototype.getNodePath = function (node) { DocumentList.prototype.getNodePath = function (node) {
if (node) { if (node) {
var container = node.location.container; var pathWithCompanyHome = node.entry.path.name;
var path = node.location.path !== '/' ? (node.location.path + '/') : '/'; return pathWithCompanyHome.replace('/Company Home', '') + '/' + node.entry.name;
var relativePath = container + path + node.fileName;
return node.location.site + '/' + relativePath;
} }
return null; return null;
}; };

File diff suppressed because one or more lines are too long

View File

@ -25,9 +25,10 @@ import {
AfterViewChecked AfterViewChecked
} from 'angular2/core'; } from 'angular2/core';
import {AlfrescoService} from './../services/alfresco.service'; import {AlfrescoService} from './../services/alfresco.service';
import {FolderEntity, DocumentEntity} from './../models/document-library.model'; import {MinimalNodeEntity} from './../models/document-library.model';
import {ContentActionModel} from './../models/content-action.model'; import {ContentActionModel} from './../models/content-action.model';
import {ContentColumnModel} from './../models/content-column.model'; import {ContentColumnModel} from './../models/content-column.model';
import {NodePaging} from "../models/document-library.model";
declare var componentHandler; declare var componentHandler;
declare let __moduleName: string; declare let __moduleName: string;
@ -58,7 +59,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
path: 'swsdp/documentLibrary' path: 'swsdp/documentLibrary'
}; };
currentFolderPath: string = 'swsdp/documentLibrary'; currentFolderPath: string = 'swsdp/documentLibrary';
folder: FolderEntity; folder: NodePaging;
errorMessage; errorMessage;
route: any[] = []; route: any[] = [];
@ -140,7 +141,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
* @param item Underlying node item * @param item Underlying node item
* @param e DOM event (optional) * @param e DOM event (optional)
*/ */
onItemClick(item: DocumentEntity, e = null) { onItemClick(item: MinimalNodeEntity, e = null) {
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
@ -150,10 +151,10 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
}); });
if (this.navigate && item) { if (this.navigate && item) {
if (item.isFolder) { if (item.entry.isFolder) {
let path = this.getNodePath(item); let path = this.getNodePath(item);
this.route.push({ this.route.push({
name: item.displayName, name: item.entry.name,
path: path path: path
}); });
this.displayFolderContent(path); this.displayFolderContent(path);
@ -185,7 +186,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
* @param node Node to get URL for. * @param node Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getContentUrl(node: DocumentEntity): string { getContentUrl(node: MinimalNodeEntity): string {
if (this._alfrescoService) { if (this._alfrescoService) {
return this._alfrescoService.getContentUrl(node); return this._alfrescoService.getContentUrl(node);
} }
@ -197,7 +198,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
* @param node Node to get URL for. * @param node Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getDocumentThumbnailUrl(node: DocumentEntity): string { getDocumentThumbnailUrl(node: MinimalNodeEntity): string {
if (this._alfrescoService) { if (this._alfrescoService) {
return this._alfrescoService.getDocumentThumbnailUrl(node); return this._alfrescoService.getDocumentThumbnailUrl(node);
} }
@ -209,7 +210,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
* @param node Node to be the context of the execution. * @param node Node to be the context of the execution.
* @param action Action to be executed against the context. * @param action Action to be executed against the context.
*/ */
executeContentAction(node: DocumentEntity, action: ContentActionModel) { executeContentAction(node: MinimalNodeEntity, action: ContentActionModel) {
if (action) { if (action) {
action.handler(node); action.handler(node);
} }
@ -236,12 +237,10 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
* @param node * @param node
* @returns {string} * @returns {string}
*/ */
getNodePath(node: DocumentEntity): string { getNodePath(node: MinimalNodeEntity): string {
if (node) { if (node) {
let container = node.location.container; let pathWithCompanyHome = item.entry.path.name;
let path = node.location.path !== '/' ? (node.location.path + '/' ) : '/'; return pathWithCompanyHome.replace('/Company Home', '') + '/' + item.entry.name;
let relativePath = container + path + node.fileName;
return node.location.site + '/' + relativePath;
} }
return null; return null;
} }

View File

@ -65,3 +65,53 @@ export class LocationEntity {
export class LocationParentEntity { export class LocationParentEntity {
nodeRef: string; nodeRef: string;
} }
export class NodePaging {
list: NodePagingList;
}
export class NodePagingList {
entries: MinimalNodeEntity[];
}
export class MinimalNodeEntity {
entry: MinimalNodeEntryEntity;
}
export class MinimalNodeEntryEntity {
id: string;
parentId: string;
name: string;
nodeType: string;
isFolder: boolean;
isFile: boolean;
modifiedAt: string;
modifiedByUser: UserInfo;
createdAt: string;
createdByUser: UserInfo;
content: ContentInfo;
path: PathInfoEntity
}
export class UserInfo {
displayName: string;
id: string;
}
export class ContentInfo {
mimeType: string;
mimeTypeName: string;
sizeInBytes: number;
encoding: string;
}
export class PathInfoEntity {
elements: PathElementEntity;
isComplete: boolean;
name: string
}
export class PathElementEntity {
id: string;
name: string;
}

View File

@ -1,6 +1,6 @@
import { Http } from 'angular2/http'; import { Http } from 'angular2/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { FolderEntity, DocumentEntity } from './../models/document-library.model'; import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import { AlfrescoSettingsService } from '../../../ng2-alfresco-core/services'; import { AlfrescoSettingsService } from '../../../ng2-alfresco-core/services';
/** /**
* Internal service used by Document List component. * Internal service used by Document List component.
@ -16,20 +16,20 @@ export declare class AlfrescoService {
/** /**
* Gets the folder node with the content. * Gets the folder node with the content.
* @param folder Path to folder. * @param folder Path to folder.
* @returns {Observable<FolderEntity>} Folder entity. * @returns {Observable<NodePaging>} Folder entity.
*/ */
getFolder(folder: string): Observable<FolderEntity>; getFolder(folder: string): Observable<NodePaging>;
/** /**
* Get thumbnail URL for the given document node. * Get thumbnail URL for the given document node.
* @param document Node to get URL for. * @param document Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getDocumentThumbnailUrl(document: DocumentEntity): string; getDocumentThumbnailUrl(document: MinimalNodeEntity): string;
/** /**
* Get content URL for the given node. * Get content URL for the given node.
* @param document Node to get URL for. * @param document Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getContentUrl(document: DocumentEntity): string; getContentUrl(document: MinimalNodeEntity): string;
private handleError(error); private handleError(error);
} }

View File

@ -51,7 +51,7 @@ System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', '../../../
this.http = http; this.http = http;
this.settings = settings; this.settings = settings;
this._host = 'http://127.0.0.1:8080'; this._host = 'http://127.0.0.1:8080';
this._baseUrlPath = '/alfresco/service/slingshot/doclib/doclist/all/site/'; this._baseUrlPath = '/alfresco/api/-default-/public/alfresco/versions/1';
if (settings) { if (settings) {
this._host = settings.host; this._host = settings.host;
} }
@ -69,21 +69,49 @@ System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', '../../../
AlfrescoService.prototype.getBaseUrl = function () { AlfrescoService.prototype.getBaseUrl = function () {
return this.host + this._baseUrlPath; return this.host + this._baseUrlPath;
}; };
AlfrescoService.prototype.getAlfrescoTicket = function () {
return localStorage.getItem('token');
};
AlfrescoService.prototype.getAlfrescoClient = function () {
var defaultClient = new AlfrescoApi.ApiClient();
defaultClient.basePath = this.getBaseUrl();
// Configure HTTP basic authorization: basicAuth
var basicAuth = defaultClient.authentications['basicAuth'];
basicAuth.username = 'ROLE_TICKET';
basicAuth.password = this.getAlfrescoTicket();
return defaultClient;
};
AlfrescoService.prototype.getNodesPromise = function (folder) {
var alfrescoClient = this.getAlfrescoClient();
return new Promise(function (resolve, reject) {
var apiInstance = new AlfrescoApi.NodesApi(alfrescoClient);
var nodeId = '-root-';
var opts = {
relativePath: folder,
include: ['path']
};
var callback = function (error, data /*, response*/) {
if (error) {
console.error(error);
reject(error);
}
else {
console.log('API returned data', data);
resolve(data);
}
};
apiInstance.getNodeChildren(nodeId, opts, callback);
});
};
/** /**
* Gets the folder node with the content. * Gets the folder node with the content.
* @param folder Path to folder. * @param folder Path to folder.
* @returns {Observable<FolderEntity>} Folder entity. * @returns {Observable<NodePaging>} Folder entity.
*/ */
AlfrescoService.prototype.getFolder = function (folder) { AlfrescoService.prototype.getFolder = function (folder) {
var headers = new http_1.Headers({ return Observable_1.Observable.fromPromise(this.getNodesPromise(folder))
'Content-Type': 'application/json', .map(function (res) { return res; })
'Authorization': this.settings.getAuthToken() .do(function (data) { return console.log('Node data', data); }) // eyeball results in the console
});
var options = new http_1.RequestOptions({ headers: headers });
return this.http
.get(this.getBaseUrl() + folder, options)
.map(function (res) { return res.json(); })
.do(function (data) { return console.log(data); }) // eyeball results in the console
.catch(this.handleError); .catch(this.handleError);
}; };
/** /**
@ -92,9 +120,7 @@ System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', '../../../
* @returns {string} URL address. * @returns {string} URL address.
*/ */
AlfrescoService.prototype.getDocumentThumbnailUrl = function (document) { AlfrescoService.prototype.getDocumentThumbnailUrl = function (document) {
return this._host + return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1';
'/alfresco/service/api/node/' +
document.nodeRef.replace('://', '/') + '/content/thumbnails/doclib?c=queue&amp;ph=true&amp;lastModified=1';
}; };
/** /**
* Get content URL for the given node. * Get content URL for the given node.
@ -102,7 +128,9 @@ System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', '../../../
* @returns {string} URL address. * @returns {string} URL address.
*/ */
AlfrescoService.prototype.getContentUrl = function (document) { AlfrescoService.prototype.getContentUrl = function (document) {
return this._host + '/alfresco/service/' + document.contentUrl; return this._host +
'/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content';
}; };
AlfrescoService.prototype.handleError = function (error) { AlfrescoService.prototype.handleError = function (error) {
// 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

View File

@ -1 +1 @@
{"version":3,"file":"alfresco.service.js","sourceRoot":"","sources":["alfresco.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAQH;;eAEG;YAEH;gBAEI,yBACY,IAAU,EACV,QAAiC;oBADjC,SAAI,GAAJ,IAAI,CAAM;oBACV,aAAQ,GAAR,QAAQ,CAAyB;oBAOrC,UAAK,GAAW,uBAAuB,CAAC;oBACxC,iBAAY,GAAW,sDAAsD,CAAC;oBANlF,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACX,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;oBAC/B,CAAC;gBACL,CAAC;gBAKD,sBAAW,iCAAI;yBAAf;wBACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;oBACtB,CAAC;yBAED,UAAgB,KAAY;wBACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;oBACvB,CAAC;;;mBAJA;gBAMO,oCAAU,GAAlB;oBACI,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC;gBACzC,CAAC;gBAED;;;;mBAIG;gBACH,mCAAS,GAAT,UAAU,MAAc;oBACpB,IAAI,OAAO,GAAG,IAAI,cAAO,CAAC;wBACtB,cAAc,EAAE,kBAAkB;wBAClC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,Y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AAmD,CAAC;gBAC9F,CAAC;gBAED,uCAAa,GAAb,UAAc,QAA2B;oBACrC,MAAM,CAAC,IAAI,CAAC,KAAK;wBACb,mDAAmD;wBACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC;gBACvC,CAAC;gBAEO,qCAAW,GAAnB,UAAqB,KAAe;oBAChC,mFAAmF;oBACnF,4CAA4C;oBAC5C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrB,MAAM,CAAC,uBAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;gBAClE,CAAC;gBAvFL;oBAAC,iBAAU,EAAE;;mCAAA;gBAwFb,sBAAC;YAAD,CAAC,AAvFD,IAuFC;YAvFD,6CAuFC,CAAA"}

View File

@ -18,9 +18,11 @@
import {Injectable} from 'angular2/core'; import {Injectable} from 'angular2/core';
import {Http, Response, RequestOptions, Headers} from 'angular2/http'; import {Http, Response, RequestOptions, Headers} from 'angular2/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {FolderEntity, DocumentEntity} from './../models/document-library.model'; import {NodePaging, MinimalNodeEntity} from './../models/document-library.model';
import {AlfrescoSettingsService} from '../../../ng2-alfresco-core/services'; import {AlfrescoSettingsService} from '../../../ng2-alfresco-core/services';
declare var AlfrescoApi: any;
/** /**
* Internal service used by Document List component. * Internal service used by Document List component.
*/ */
@ -37,7 +39,7 @@ export class AlfrescoService {
} }
private _host: string = 'http://127.0.0.1:8080'; private _host: string = 'http://127.0.0.1:8080';
private _baseUrlPath: string = '/alfresco/service/slingshot/doclib/doclist/all/site/'; private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
public get host():string { public get host():string {
return this._host; return this._host;
@ -51,21 +53,54 @@ export class AlfrescoService {
return this.host + this._baseUrlPath; return this.host + this._baseUrlPath;
} }
private getAlfrescoTicket() {
return localStorage.getItem('token');
}
private getAlfrescoClient() {
var defaultClient = new AlfrescoApi.ApiClient();
defaultClient.basePath = this.getBaseUrl();
// Configure HTTP basic authorization: basicAuth
var basicAuth = defaultClient.authentications['basicAuth'];
basicAuth.username = 'ROLE_TICKET';
basicAuth.password = this.getAlfrescoTicket();
return defaultClient;
}
private getNodesPromise(folder: string) {
var alfrescoClient = this.getAlfrescoClient();
return new Promise(function(resolve, reject) {
var apiInstance = new AlfrescoApi.NodesApi(alfrescoClient);
var nodeId = '-root-';
var opts = {
relativePath: folder,
include: ['path']
};
var callback = function(error, data /*, response*/) {
if (error) {
console.error(error);
reject(error);
} else {
console.log('API returned data', data);
resolve(data);
}
};
apiInstance.getNodeChildren(nodeId, opts, callback);
});
}
/** /**
* Gets the folder node with the content. * Gets the folder node with the content.
* @param folder Path to folder. * @param folder Path to folder.
* @returns {Observable<FolderEntity>} Folder entity. * @returns {Observable<FolderEntity>} Folder entity.
*/ */
getFolder(folder: string) { getFolder(folder: string) {
let headers = new Headers({ return Observable.fromPromise(this.getNodesPromise(folder))
'Content-Type': 'application/json', .map(res => <NodePaging> res)
'Authorization': this.settings.getAuthToken() .do(data => console.log('Node data', data)) // eyeball results in the console
});
let options = new RequestOptions({ headers: headers });
return this.http
.get(this.getBaseUrl() + folder, options)
.map(res => <FolderEntity> res.json())
.do(data => console.log(data)) // eyeball results in the console
.catch(this.handleError); .catch(this.handleError);
} }
@ -74,10 +109,8 @@ export class AlfrescoService {
* @param document Node to get URL for. * @param document Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getDocumentThumbnailUrl(document: DocumentEntity): string { getDocumentThumbnailUrl(document: MinimalNodeEntity) {
return this._host + return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1';
'/alfresco/service/api/node/' +
document.nodeRef.replace('://', '/') + '/content/thumbnails/doclib?c=queue&amp;ph=true&amp;lastModified=1';
} }
/** /**
@ -85,14 +118,16 @@ export class AlfrescoService {
* @param document Node to get URL for. * @param document Node to get URL for.
* @returns {string} URL address. * @returns {string} URL address.
*/ */
getContentUrl(document: DocumentEntity): string { getContentUrl(document: MinimalNodeEntity) {
return this._host + '/alfresco/service/' + document.contentUrl; return this._host +
'/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content';
} }
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
console.error(error); console.error(error);
return Observable.throw(error.json().error || 'Server error'); return Observable.throw(error || 'Server error');
} }
} }