Merge pull request #180 from Alfresco/dev-wabson-contentservice

Add new AlfrescoContentService for building URLs
This commit is contained in:
Mario Romano
2016-06-10 09:53:12 +01:00
committed by GitHub
19 changed files with 135 additions and 112 deletions
@@ -148,7 +148,7 @@
[multipleFiles]="true"
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button>
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [overlayMode]="true">
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [mimeType]="mimeType" [overlayMode]="true">
<div class="mdl-spinner mdl-js-spinner is-active"></div>
</alfresco-viewer>
<file-uploading-dialog></file-uploading-dialog>
@@ -23,7 +23,8 @@ import {
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
import {
MDL,
AlfrescoSettingsService
AlfrescoSettingsService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
@@ -46,12 +47,14 @@ export class FilesComponent {
relativePath: string = '';
urlFile: string;
mimeType: string;
fileShowed: boolean = false;
acceptedFilesType: string = '.jpg,.pdf,.js';
constructor(
private settings: AlfrescoSettingsService,
private contentService: AlfrescoContentService,
documentActions: DocumentActionsService) {
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
}
@@ -74,11 +77,9 @@ export class FilesComponent {
showFile(event) {
if (event.value.entry.isFile) {
let workSpace = 'workspace/SpacesStore/' + event.value.entry.id;
let nameFile = event.value.entry.name;
this.urlFile = this.settings.host + '/alfresco/s/slingshot/node/content/' + workSpace + '/' + nameFile;
this.mimeType = event.value.entry.content.mimeType;
this.urlFile = this.contentService.getContentUrl(event.value);
this.fileShowed = true;
} else {
this.fileShowed = false;
@@ -1,6 +1,6 @@
<alfresco-search-control *ngIf="isLoggedIn()" [searchTerm]="searchTerm" [autocomplete]="false"
(searchChange)="searchTermChange($event);"(preview)="onFileClicked($event)"></alfresco-search-control>
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [overlayMode]="true">
<alfresco-viewer [(showViewer)]="fileShowed" [urlFile]="urlFile" [mimeType]="mimeType" [overlayMode]="true">
<div class="mdl-spinner mdl-js-spinner is-active"></div>
</alfresco-viewer>
@@ -21,7 +21,7 @@ import { ALFRESCO_SEARCH_DIRECTIVES } from 'ng2-alfresco-search/dist/ng2-alfresc
import { VIEWERCOMPONENT } from 'ng2-alfresco-viewer/dist/ng2-alfresco-viewer';
import {
AlfrescoAuthenticationService,
AlfrescoSettingsService
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let __moduleName: string;
@@ -37,12 +37,14 @@ declare let __moduleName: string;
export class SearchBarComponent {
urlFile: string;
mimeType: string;
fileShowed: boolean = false;
constructor(
public router: Router,
public auth: AlfrescoAuthenticationService,
public settings: AlfrescoSettingsService
public contentService: AlfrescoContentService
) {
}
@@ -63,9 +65,8 @@ export class SearchBarComponent {
onFileClicked(event) {
if (event.value.entry.isFile) {
let workSpace = 'workspace/SpacesStore/' + event.value.entry.id;
let nameFile = event.value.entry.name;
this.urlFile = this.settings.host + '/alfresco/s/slingshot/node/content/' + workSpace + '/' + nameFile;
this.mimeType = event.value.entry.content.mimeType;
this.urlFile = this.contentService.getContentUrl(event.value);
this.fileShowed = true;
}
}
@@ -20,6 +20,7 @@ import { AlfrescoTranslationLoader } from './src/services/AlfrescoTranslationLoa
import { AlfrescoTranslationService } from './src/services/AlfrescoTranslationService.service';
import { AlfrescoPipeTranslate } from './src/services/AlfrescoPipeTranslate.service';
import { AlfrescoAuthenticationService } from './src/services/AlfrescoAuthenticationService.service';
import { AlfrescoContentService } from './src/services/AlfrescoContentService.service';
export * from './src/services/AlfrescoSettingsService.service';
export * from './src/services/AlfrescoTranslationLoader.service';
@@ -27,9 +28,11 @@ export * from './src/services/AlfrescoTranslationService.service';
export * from './src/services/AlfrescoPipeTranslate.service';
export * from './src/material/MaterialDesignLiteUpgradeElement';
export * from './src/services/AlfrescoAuthenticationService.service';
export * from './src/services/AlfrescoContentService.service';
export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoAuthenticationService,
AlfrescoContentService,
AlfrescoSettingsService,
AlfrescoTranslationLoader,
AlfrescoTranslationService,
@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-core",
"description": "Alfresco Angular 2 Components core",
"version": "0.1.27",
"version": "0.1.28",
"author": "Alfresco Software, Ltd.",
"scripts": {
"typings": "typings install",
@@ -20,6 +20,7 @@ import { provide, Injector } from 'angular2/core';
import { Http, HTTP_PROVIDERS, XHRBackend, Response, ResponseOptions } from 'angular2/http';
import { MockBackend } from 'angular2/http/testing';
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
describe('AlfrescoAuthentication', () => {
@@ -34,7 +35,8 @@ describe('AlfrescoAuthentication', () => {
HTTP_PROVIDERS,
MockBackend,
provide(XHRBackend, {useClass: MockBackend}),
AlfrescoAuthenticationService
AlfrescoAuthenticationService,
AlfrescoSettingsService
]);
let store = {};
@@ -0,0 +1,51 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from 'angular2/core';
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
@Injectable()
export class AlfrescoContentService {
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService
) {
}
/**
* Get thumbnail URL for the given document node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/renditions/doclib/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
}
}
@@ -19,7 +19,10 @@ import { Injectable } from 'angular2/core';
@Injectable()
export class AlfrescoSettingsService {
private _host: string = 'http://127.0.0.1:8080';
private _contextPath = '/alfresco';
private _apiBasePath: string = '/api/-default-/public/alfresco/versions/1';
public get host(): string {
return this._host;
@@ -29,6 +32,10 @@ export class AlfrescoSettingsService {
this._host = value;
}
getApiBaseUrl(): string {
return this._host + this._contextPath + this._apiBasePath;
}
getAuthToken(): string {
// todo: get proper token value
return 'Basic ' + btoa('admin:admin');
@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-documentlist",
"description": "Alfresco Angular2 Document List Component",
"version": "0.1.21",
"version": "0.1.22",
"author": "Alfresco Software, Ltd.",
"scripts": {
"typings": "typings install",
@@ -17,16 +17,22 @@
import {Observable} from 'rxjs/Observable';
import {AlfrescoService} from '../../src/services/alfresco.service';
import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
export class AlfrescoServiceMock extends AlfrescoService {
_folderToReturn: any = {};
constructor(
settings: AlfrescoSettingsService = null
settings: AlfrescoSettingsService = null,
authService: AlfrescoAuthenticationService = null,
contentService: AlfrescoContentService = null
) {
super(settings);
super(settings, authService, contentService);
}
getFolder(folder: string) {
@@ -19,7 +19,11 @@ import { Injectable } from 'angular2/core';
import { Response } from 'angular2/http';
import { Observable } from 'rxjs/Rx';
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any;
@@ -62,23 +66,14 @@ export class AlfrescoService {
};
constructor(
private settings: AlfrescoSettingsService) {
}
public getHost(): string {
return this.settings.host;
}
private getBaseUrl(): string {
return this.getHost() + this._baseUrlPath;
}
private getAlfrescoTicket() {
return localStorage.getItem('token');
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService,
private contentService: AlfrescoContentService
) {
}
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket());
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
}
private getNodesPromise(folder: string) {
@@ -117,18 +112,7 @@ export class AlfrescoService {
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: MinimalNodeEntity) {
return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1&alf_ticket=' + this.getAlfrescoTicket();
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: MinimalNodeEntity) {
return this.getHost() +
'/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content';
return this.contentService.getDocumentThumbnailUrl(document);
}
getMimeTypeIcon(mimeType: string): string {
@@ -18,12 +18,18 @@
import {Injectable} from 'angular2/core';
import {ContentActionHandler} from '../models/content-action.model';
import {AlfrescoService} from './alfresco.service';
import {
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
@Injectable()
export class DocumentActionsService {
private handlers: { [id: string]: ContentActionHandler; } = {};
constructor(private _alfrescoService?: AlfrescoService) {
constructor(
private _alfrescoService?: AlfrescoService,
private _contentService?: AlfrescoContentService
) {
this.setupActionHandlers();
}
@@ -70,7 +76,7 @@ export class DocumentActionsService {
let link = document.createElement('a');
document.body.appendChild(link);
link.setAttribute('download', 'download');
link.href = this._alfrescoService.getContentUrl(obj);
link.href = this._contentService.getContentUrl(obj);
link.click();
document.body.removeChild(link);
}
@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-search",
"description": "Alfresco Angular2 Search Component",
"version": "0.1.17",
"version": "0.1.18",
"author": "Alfresco Software, Ltd.",
"scripts": {
"typings": "typings install",
@@ -18,7 +18,11 @@
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {AlfrescoService} from './../../src/services/alfresco.service';
export class AlfrescoServiceMock extends AlfrescoService {
@@ -26,9 +30,11 @@ export class AlfrescoServiceMock extends AlfrescoService {
_folderToReturn: any = {};
constructor(
settings: AlfrescoSettingsService = null
settings: AlfrescoSettingsService = null,
authService: AlfrescoAuthenticationService = null,
contentService: AlfrescoContentService = null
) {
super(settings);
super(settings, authService, contentService);
}
getFolder(folder: string) {
@@ -64,18 +64,6 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
this.displaySearchResults(this.searchTerm);
}
/**
* Gets content URL for the given node.
* @param node Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(node: any): string {
if (this._alfrescoService) {
return this._alfrescoService.getContentUrl(node);
}
return null;
}
/**
* Gets thumbnail URL for the given document node.
* @param node Node to get URL for.
@@ -18,7 +18,11 @@
import { Injectable } from 'angular2/core';
import { Observable } from 'rxjs/Observable';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any;
@@ -28,25 +32,15 @@ declare let AlfrescoApi: any;
@Injectable()
export class AlfrescoService {
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
constructor(private settings: AlfrescoSettingsService) {
}
public getHost(): string {
return this.settings.host;
}
private getBaseUrl(): string {
return this.getHost() + this._baseUrlPath;
}
private getAlfrescoTicket() {
return localStorage.getItem('token');
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService,
private contentService: AlfrescoContentService
) {
}
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket());
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
}
private getSearchNodesPromise(term: string) {
@@ -79,18 +73,7 @@ export class AlfrescoService {
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any) {
return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1&alf_ticket=' + this.getAlfrescoTicket();
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any) {
return this.getHost() +
'/alfresco/service/api/node/workspace/SpacesStore/' +
document.entry.id + '/content';
return this.contentService.getDocumentThumbnailUrl(document);
}
private handleError(error: any) {
@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-viewer",
"description": "Alfresco documents viewer",
"version": "0.1.13",
"version": "0.1.14",
"author": "Eugenio Romano",
"scripts": {
"typings": "typings install",
@@ -34,6 +34,9 @@ export class ViewerComponent {
@Input()
urlFile: string;
@Input()
mimeType: string = null;
@Input()
overlayMode: boolean = false;
@@ -63,8 +66,6 @@ export class ViewerComponent {
if (this.urlFile) {
this.nameFile = this.getFilenameFromUrl(this.urlFile);
this.extension = this.getFileExtension(this.nameFile);
this.urlFile = this.addAlfrescoTicket(this.urlFile);
}
resolve();
});
@@ -116,7 +117,7 @@ export class ViewerComponent {
* check if the current file is a suppoerted pdf extension
*/
private isPdf() {
return this.extension === 'pdf';
return this.extension === 'pdf' || this.mimeType == 'application/pdf';
}
/**
@@ -142,22 +143,6 @@ export class ViewerComponent {
}
}
/**
* Add Ticket to the file request
* @returns {string}
*/
private addAlfrescoTicket(url: string) {
return url + '?alf_ticket=' + this.getAlfrescoTicket();
}
/**
* Get the token from the local storage
* @returns {string}
*/
private getAlfrescoTicket() {
return localStorage.getItem('token');
}
/**
* Hide the othe possible menu in th eapplication
*/