diff --git a/demo-shell-ng2/app/components/files/files.component.html b/demo-shell-ng2/app/components/files/files.component.html index e9a2ac89cf..e49dab14c4 100644 --- a/demo-shell-ng2/app/components/files/files.component.html +++ b/demo-shell-ng2/app/components/files/files.component.html @@ -148,7 +148,7 @@ [multipleFiles]="true" (onSuccess)="refreshDocumentList($event)"> - +
diff --git a/demo-shell-ng2/app/components/files/files.component.ts b/demo-shell-ng2/app/components/files/files.component.ts index 8e2b5b4425..cc9ebb4f29 100644 --- a/demo-shell-ng2/app/components/files/files.component.ts +++ b/demo-shell-ng2/app/components/files/files.component.ts @@ -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; diff --git a/demo-shell-ng2/app/components/search/search-bar.component.html b/demo-shell-ng2/app/components/search/search-bar.component.html index ff4c5adacd..97a5ce8a8a 100644 --- a/demo-shell-ng2/app/components/search/search-bar.component.html +++ b/demo-shell-ng2/app/components/search/search-bar.component.html @@ -1,6 +1,6 @@ - +
diff --git a/demo-shell-ng2/app/components/search/search-bar.component.ts b/demo-shell-ng2/app/components/search/search-bar.component.ts index 990d025365..9bf5ce4949 100644 --- a/demo-shell-ng2/app/components/search/search-bar.component.ts +++ b/demo-shell-ng2/app/components/search/search-bar.component.ts @@ -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; } } diff --git a/ng2-components/ng2-alfresco-core/ng2-alfresco-core.ts b/ng2-components/ng2-alfresco-core/ng2-alfresco-core.ts index b37c614ece..3af89b70b7 100644 --- a/ng2-components/ng2-alfresco-core/ng2-alfresco-core.ts +++ b/ng2-components/ng2-alfresco-core/ng2-alfresco-core.ts @@ -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, diff --git a/ng2-components/ng2-alfresco-core/package.json b/ng2-components/ng2-alfresco-core/package.json index 4f664367eb..f23d9b6a45 100644 --- a/ng2-components/ng2-alfresco-core/package.json +++ b/ng2-components/ng2-alfresco-core/package.json @@ -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", diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts index e3a09bed90..d912d42258 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthenticationService.service.spec.ts @@ -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 = {}; diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.service.ts new file mode 100644 index 0000000000..dffecbf90f --- /dev/null +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoContentService.service.ts @@ -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(); + } +} diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts index 33741c73fe..754a96e6fc 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettingsService.service.ts @@ -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'); diff --git a/ng2-components/ng2-alfresco-documentlist/package.json b/ng2-components/ng2-alfresco-documentlist/package.json index cc895a578c..0def635f8a 100644 --- a/ng2-components/ng2-alfresco-documentlist/package.json +++ b/ng2-components/ng2-alfresco-documentlist/package.json @@ -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", diff --git a/ng2-components/ng2-alfresco-documentlist/src/assets/alfresco.service.mock.ts b/ng2-components/ng2-alfresco-documentlist/src/assets/alfresco.service.mock.ts index ebcb6c6466..1a30abe443 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/assets/alfresco.service.mock.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/assets/alfresco.service.mock.ts @@ -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) { diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts index 58f49456fe..02e5fbc38d 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/alfresco.service.ts @@ -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 { diff --git a/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts b/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts index ce3b921ad4..0bef5b995a 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/services/document-actions.service.ts @@ -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); } diff --git a/ng2-components/ng2-alfresco-search/package.json b/ng2-components/ng2-alfresco-search/package.json index 440f8faabb..a437559e58 100644 --- a/ng2-components/ng2-alfresco-search/package.json +++ b/ng2-components/ng2-alfresco-search/package.json @@ -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", diff --git a/ng2-components/ng2-alfresco-search/src/assets/alfresco.service.mock.ts b/ng2-components/ng2-alfresco-search/src/assets/alfresco.service.mock.ts index e748a63bf5..1746fded55 100644 --- a/ng2-components/ng2-alfresco-search/src/assets/alfresco.service.mock.ts +++ b/ng2-components/ng2-alfresco-search/src/assets/alfresco.service.mock.ts @@ -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) { diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts index b94b97859b..c94a146211 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts @@ -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. diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco.service.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco.service.ts index 190a46e7e0..60a3b625ff 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco.service.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco.service.ts @@ -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) { diff --git a/ng2-components/ng2-alfresco-viewer/package.json b/ng2-components/ng2-alfresco-viewer/package.json index 12faa23949..1a0422cc97 100644 --- a/ng2-components/ng2-alfresco-viewer/package.json +++ b/ng2-components/ng2-alfresco-viewer/package.json @@ -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", diff --git a/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts b/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts index c7f620bc32..49ab13d3c5 100644 --- a/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts +++ b/ng2-components/ng2-alfresco-viewer/src/viewer.component.ts @@ -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 */