mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Merge pull request #180 from Alfresco/dev-wabson-contentservice
Add new AlfrescoContentService for building URLs
This commit is contained in:
@@ -148,7 +148,7 @@
|
|||||||
[multipleFiles]="true"
|
[multipleFiles]="true"
|
||||||
(onSuccess)="refreshDocumentList($event)"></alfresco-upload-button>
|
(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>
|
<div class="mdl-spinner mdl-js-spinner is-active"></div>
|
||||||
</alfresco-viewer>
|
</alfresco-viewer>
|
||||||
<file-uploading-dialog></file-uploading-dialog>
|
<file-uploading-dialog></file-uploading-dialog>
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ import {
|
|||||||
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
|
} from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
|
||||||
import {
|
import {
|
||||||
MDL,
|
MDL,
|
||||||
AlfrescoSettingsService
|
AlfrescoSettingsService,
|
||||||
|
AlfrescoContentService
|
||||||
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
|
import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
|
||||||
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
@@ -46,12 +47,14 @@ export class FilesComponent {
|
|||||||
relativePath: string = '';
|
relativePath: string = '';
|
||||||
|
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
mimeType: string;
|
||||||
fileShowed: boolean = false;
|
fileShowed: boolean = false;
|
||||||
|
|
||||||
acceptedFilesType: string = '.jpg,.pdf,.js';
|
acceptedFilesType: string = '.jpg,.pdf,.js';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private settings: AlfrescoSettingsService,
|
private settings: AlfrescoSettingsService,
|
||||||
|
private contentService: AlfrescoContentService,
|
||||||
documentActions: DocumentActionsService) {
|
documentActions: DocumentActionsService) {
|
||||||
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
|
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
|
||||||
}
|
}
|
||||||
@@ -74,11 +77,9 @@ export class FilesComponent {
|
|||||||
|
|
||||||
showFile(event) {
|
showFile(event) {
|
||||||
if (event.value.entry.isFile) {
|
if (event.value.entry.isFile) {
|
||||||
let workSpace = 'workspace/SpacesStore/' + event.value.entry.id;
|
|
||||||
let nameFile = event.value.entry.name;
|
let nameFile = event.value.entry.name;
|
||||||
|
this.mimeType = event.value.entry.content.mimeType;
|
||||||
this.urlFile = this.settings.host + '/alfresco/s/slingshot/node/content/' + workSpace + '/' + nameFile;
|
this.urlFile = this.contentService.getContentUrl(event.value);
|
||||||
|
|
||||||
this.fileShowed = true;
|
this.fileShowed = true;
|
||||||
} else {
|
} else {
|
||||||
this.fileShowed = false;
|
this.fileShowed = false;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<alfresco-search-control *ngIf="isLoggedIn()" [searchTerm]="searchTerm" [autocomplete]="false"
|
<alfresco-search-control *ngIf="isLoggedIn()" [searchTerm]="searchTerm" [autocomplete]="false"
|
||||||
(searchChange)="searchTermChange($event);"(preview)="onFileClicked($event)"></alfresco-search-control>
|
(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>
|
<div class="mdl-spinner mdl-js-spinner is-active"></div>
|
||||||
</alfresco-viewer>
|
</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 { VIEWERCOMPONENT } from 'ng2-alfresco-viewer/dist/ng2-alfresco-viewer';
|
||||||
import {
|
import {
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
AlfrescoSettingsService
|
AlfrescoContentService
|
||||||
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
|
|
||||||
declare let __moduleName: string;
|
declare let __moduleName: string;
|
||||||
@@ -37,12 +37,14 @@ declare let __moduleName: string;
|
|||||||
export class SearchBarComponent {
|
export class SearchBarComponent {
|
||||||
|
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
mimeType: string;
|
||||||
fileShowed: boolean = false;
|
fileShowed: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public router: Router,
|
public router: Router,
|
||||||
public auth: AlfrescoAuthenticationService,
|
public auth: AlfrescoAuthenticationService,
|
||||||
public settings: AlfrescoSettingsService
|
public contentService: AlfrescoContentService
|
||||||
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +65,8 @@ export class SearchBarComponent {
|
|||||||
|
|
||||||
onFileClicked(event) {
|
onFileClicked(event) {
|
||||||
if (event.value.entry.isFile) {
|
if (event.value.entry.isFile) {
|
||||||
let workSpace = 'workspace/SpacesStore/' + event.value.entry.id;
|
this.mimeType = event.value.entry.content.mimeType;
|
||||||
let nameFile = event.value.entry.name;
|
this.urlFile = this.contentService.getContentUrl(event.value);
|
||||||
this.urlFile = this.settings.host + '/alfresco/s/slingshot/node/content/' + workSpace + '/' + nameFile;
|
|
||||||
this.fileShowed = true;
|
this.fileShowed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { AlfrescoTranslationLoader } from './src/services/AlfrescoTranslationLoa
|
|||||||
import { AlfrescoTranslationService } from './src/services/AlfrescoTranslationService.service';
|
import { AlfrescoTranslationService } from './src/services/AlfrescoTranslationService.service';
|
||||||
import { AlfrescoPipeTranslate } from './src/services/AlfrescoPipeTranslate.service';
|
import { AlfrescoPipeTranslate } from './src/services/AlfrescoPipeTranslate.service';
|
||||||
import { AlfrescoAuthenticationService } from './src/services/AlfrescoAuthenticationService.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/AlfrescoSettingsService.service';
|
||||||
export * from './src/services/AlfrescoTranslationLoader.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/services/AlfrescoPipeTranslate.service';
|
||||||
export * from './src/material/MaterialDesignLiteUpgradeElement';
|
export * from './src/material/MaterialDesignLiteUpgradeElement';
|
||||||
export * from './src/services/AlfrescoAuthenticationService.service';
|
export * from './src/services/AlfrescoAuthenticationService.service';
|
||||||
|
export * from './src/services/AlfrescoContentService.service';
|
||||||
|
|
||||||
export const ALFRESCO_CORE_PROVIDERS: [any] = [
|
export const ALFRESCO_CORE_PROVIDERS: [any] = [
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoContentService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoTranslationLoader,
|
AlfrescoTranslationLoader,
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-core",
|
"name": "ng2-alfresco-core",
|
||||||
"description": "Alfresco Angular 2 Components core",
|
"description": "Alfresco Angular 2 Components core",
|
||||||
"version": "0.1.27",
|
"version": "0.1.28",
|
||||||
"author": "Alfresco Software, Ltd.",
|
"author": "Alfresco Software, Ltd.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typings": "typings install",
|
"typings": "typings install",
|
||||||
|
|||||||
+3
-1
@@ -20,6 +20,7 @@ import { provide, Injector } from 'angular2/core';
|
|||||||
import { Http, HTTP_PROVIDERS, XHRBackend, Response, ResponseOptions } from 'angular2/http';
|
import { Http, HTTP_PROVIDERS, XHRBackend, Response, ResponseOptions } from 'angular2/http';
|
||||||
import { MockBackend } from 'angular2/http/testing';
|
import { MockBackend } from 'angular2/http/testing';
|
||||||
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
|
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
|
||||||
|
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
|
||||||
|
|
||||||
|
|
||||||
describe('AlfrescoAuthentication', () => {
|
describe('AlfrescoAuthentication', () => {
|
||||||
@@ -34,7 +35,8 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
MockBackend,
|
MockBackend,
|
||||||
provide(XHRBackend, {useClass: MockBackend}),
|
provide(XHRBackend, {useClass: MockBackend}),
|
||||||
AlfrescoAuthenticationService
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoSettingsService
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let store = {};
|
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()
|
@Injectable()
|
||||||
export class AlfrescoSettingsService {
|
export class AlfrescoSettingsService {
|
||||||
|
|
||||||
private _host: string = 'http://127.0.0.1:8080';
|
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 {
|
public get host(): string {
|
||||||
return this._host;
|
return this._host;
|
||||||
@@ -29,6 +32,10 @@ export class AlfrescoSettingsService {
|
|||||||
this._host = value;
|
this._host = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getApiBaseUrl(): string {
|
||||||
|
return this._host + this._contextPath + this._apiBasePath;
|
||||||
|
}
|
||||||
|
|
||||||
getAuthToken(): string {
|
getAuthToken(): string {
|
||||||
// todo: get proper token value
|
// todo: get proper token value
|
||||||
return 'Basic ' + btoa('admin:admin');
|
return 'Basic ' + btoa('admin:admin');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-documentlist",
|
"name": "ng2-alfresco-documentlist",
|
||||||
"description": "Alfresco Angular2 Document List Component",
|
"description": "Alfresco Angular2 Document List Component",
|
||||||
"version": "0.1.21",
|
"version": "0.1.22",
|
||||||
"author": "Alfresco Software, Ltd.",
|
"author": "Alfresco Software, Ltd.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typings": "typings install",
|
"typings": "typings install",
|
||||||
|
|||||||
@@ -17,16 +17,22 @@
|
|||||||
|
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
import {AlfrescoService} from '../../src/services/alfresco.service';
|
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 {
|
export class AlfrescoServiceMock extends AlfrescoService {
|
||||||
|
|
||||||
_folderToReturn: any = {};
|
_folderToReturn: any = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
settings: AlfrescoSettingsService = null
|
settings: AlfrescoSettingsService = null,
|
||||||
|
authService: AlfrescoAuthenticationService = null,
|
||||||
|
contentService: AlfrescoContentService = null
|
||||||
) {
|
) {
|
||||||
super(settings);
|
super(settings, authService, contentService);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFolder(folder: string) {
|
getFolder(folder: string) {
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ import { Injectable } from 'angular2/core';
|
|||||||
import { Response } from 'angular2/http';
|
import { Response } from 'angular2/http';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
|
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;
|
declare let AlfrescoApi: any;
|
||||||
|
|
||||||
@@ -62,23 +66,14 @@ export class AlfrescoService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private settings: AlfrescoSettingsService) {
|
private settings: AlfrescoSettingsService,
|
||||||
}
|
private authService: AlfrescoAuthenticationService,
|
||||||
|
private contentService: AlfrescoContentService
|
||||||
public getHost(): string {
|
) {
|
||||||
return this.settings.host;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getBaseUrl(): string {
|
|
||||||
return this.getHost() + this._baseUrlPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAlfrescoTicket() {
|
|
||||||
return localStorage.getItem('token');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAlfrescoClient() {
|
private getAlfrescoClient() {
|
||||||
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket());
|
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
private getNodesPromise(folder: string) {
|
private getNodesPromise(folder: string) {
|
||||||
@@ -117,18 +112,7 @@ export class AlfrescoService {
|
|||||||
* @returns {string} URL address.
|
* @returns {string} URL address.
|
||||||
*/
|
*/
|
||||||
getDocumentThumbnailUrl(document: MinimalNodeEntity) {
|
getDocumentThumbnailUrl(document: MinimalNodeEntity) {
|
||||||
return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1&alf_ticket=' + this.getAlfrescoTicket();
|
return this.contentService.getDocumentThumbnailUrl(document);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMimeTypeIcon(mimeType: string): string {
|
getMimeTypeIcon(mimeType: string): string {
|
||||||
|
|||||||
@@ -18,12 +18,18 @@
|
|||||||
import {Injectable} from 'angular2/core';
|
import {Injectable} from 'angular2/core';
|
||||||
import {ContentActionHandler} from '../models/content-action.model';
|
import {ContentActionHandler} from '../models/content-action.model';
|
||||||
import {AlfrescoService} from './alfresco.service';
|
import {AlfrescoService} from './alfresco.service';
|
||||||
|
import {
|
||||||
|
AlfrescoContentService
|
||||||
|
} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DocumentActionsService {
|
export class DocumentActionsService {
|
||||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||||
|
|
||||||
constructor(private _alfrescoService?: AlfrescoService) {
|
constructor(
|
||||||
|
private _alfrescoService?: AlfrescoService,
|
||||||
|
private _contentService?: AlfrescoContentService
|
||||||
|
) {
|
||||||
this.setupActionHandlers();
|
this.setupActionHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +76,7 @@ export class DocumentActionsService {
|
|||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.setAttribute('download', 'download');
|
link.setAttribute('download', 'download');
|
||||||
link.href = this._alfrescoService.getContentUrl(obj);
|
link.href = this._contentService.getContentUrl(obj);
|
||||||
link.click();
|
link.click();
|
||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-search",
|
"name": "ng2-alfresco-search",
|
||||||
"description": "Alfresco Angular2 Search Component",
|
"description": "Alfresco Angular2 Search Component",
|
||||||
"version": "0.1.17",
|
"version": "0.1.18",
|
||||||
"author": "Alfresco Software, Ltd.",
|
"author": "Alfresco Software, Ltd.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typings": "typings install",
|
"typings": "typings install",
|
||||||
|
|||||||
@@ -18,7 +18,11 @@
|
|||||||
import {Http} from 'angular2/http';
|
import {Http} from 'angular2/http';
|
||||||
import {Observable} from 'rxjs/Observable';
|
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';
|
import {AlfrescoService} from './../../src/services/alfresco.service';
|
||||||
|
|
||||||
export class AlfrescoServiceMock extends AlfrescoService {
|
export class AlfrescoServiceMock extends AlfrescoService {
|
||||||
@@ -26,9 +30,11 @@ export class AlfrescoServiceMock extends AlfrescoService {
|
|||||||
_folderToReturn: any = {};
|
_folderToReturn: any = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
settings: AlfrescoSettingsService = null
|
settings: AlfrescoSettingsService = null,
|
||||||
|
authService: AlfrescoAuthenticationService = null,
|
||||||
|
contentService: AlfrescoContentService = null
|
||||||
) {
|
) {
|
||||||
super(settings);
|
super(settings, authService, contentService);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFolder(folder: string) {
|
getFolder(folder: string) {
|
||||||
|
|||||||
@@ -64,18 +64,6 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
|
|||||||
this.displaySearchResults(this.searchTerm);
|
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.
|
* Gets thumbnail URL for the given document node.
|
||||||
* @param node Node to get URL for.
|
* @param node Node to get URL for.
|
||||||
|
|||||||
@@ -18,7 +18,11 @@
|
|||||||
import { Injectable } from 'angular2/core';
|
import { Injectable } from 'angular2/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
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;
|
declare let AlfrescoApi: any;
|
||||||
|
|
||||||
@@ -28,25 +32,15 @@ declare let AlfrescoApi: any;
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoService {
|
export class AlfrescoService {
|
||||||
|
|
||||||
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
|
constructor(
|
||||||
|
private settings: AlfrescoSettingsService,
|
||||||
constructor(private settings: AlfrescoSettingsService) {
|
private authService: AlfrescoAuthenticationService,
|
||||||
}
|
private contentService: AlfrescoContentService
|
||||||
|
) {
|
||||||
public getHost(): string {
|
|
||||||
return this.settings.host;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getBaseUrl(): string {
|
|
||||||
return this.getHost() + this._baseUrlPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getAlfrescoTicket() {
|
|
||||||
return localStorage.getItem('token');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAlfrescoClient() {
|
private getAlfrescoClient() {
|
||||||
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket());
|
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSearchNodesPromise(term: string) {
|
private getSearchNodesPromise(term: string) {
|
||||||
@@ -79,18 +73,7 @@ export class AlfrescoService {
|
|||||||
* @returns {string} URL address.
|
* @returns {string} URL address.
|
||||||
*/
|
*/
|
||||||
getDocumentThumbnailUrl(document: any) {
|
getDocumentThumbnailUrl(document: any) {
|
||||||
return this.getContentUrl(document) + '/thumbnails/doclib?c=queue&ph=true&lastModified=1&alf_ticket=' + this.getAlfrescoTicket();
|
return this.contentService.getDocumentThumbnailUrl(document);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: any) {
|
private handleError(error: any) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ng2-alfresco-viewer",
|
"name": "ng2-alfresco-viewer",
|
||||||
"description": "Alfresco documents viewer",
|
"description": "Alfresco documents viewer",
|
||||||
"version": "0.1.13",
|
"version": "0.1.14",
|
||||||
"author": "Eugenio Romano",
|
"author": "Eugenio Romano",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typings": "typings install",
|
"typings": "typings install",
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ export class ViewerComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
mimeType: string = null;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
overlayMode: boolean = false;
|
overlayMode: boolean = false;
|
||||||
|
|
||||||
@@ -63,8 +66,6 @@ export class ViewerComponent {
|
|||||||
if (this.urlFile) {
|
if (this.urlFile) {
|
||||||
this.nameFile = this.getFilenameFromUrl(this.urlFile);
|
this.nameFile = this.getFilenameFromUrl(this.urlFile);
|
||||||
this.extension = this.getFileExtension(this.nameFile);
|
this.extension = this.getFileExtension(this.nameFile);
|
||||||
|
|
||||||
this.urlFile = this.addAlfrescoTicket(this.urlFile);
|
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@@ -116,7 +117,7 @@ export class ViewerComponent {
|
|||||||
* check if the current file is a suppoerted pdf extension
|
* check if the current file is a suppoerted pdf extension
|
||||||
*/
|
*/
|
||||||
private isPdf() {
|
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
|
* Hide the othe possible menu in th eapplication
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user