#543 dedicated AlfrescoApi service

This commit is contained in:
Denys Vuika
2016-08-24 15:17:39 +01:00
parent aa4b78e95f
commit 5773b88ab4
5 changed files with 63 additions and 17 deletions

View File

@@ -20,7 +20,8 @@
'ng2-activiti-form': 'node_modules/ng2-activiti-form/dist', 'ng2-activiti-form': 'node_modules/ng2-activiti-form/dist',
'ng2-alfresco-viewer': 'node_modules/ng2-alfresco-viewer/dist', 'ng2-alfresco-viewer': 'node_modules/ng2-alfresco-viewer/dist',
'ng2-alfresco-webscript': 'node_modules/ng2-alfresco-webscript/dist', 'ng2-alfresco-webscript': 'node_modules/ng2-alfresco-webscript/dist',
'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist' 'ng2-activiti-tasklist': 'node_modules/ng2-activiti-tasklist/dist',
'alfresco-js-api': 'node_modules/alfresco-js-api/dist'
}; };
// packages tells the System loader how to load when no filename and/or no extension // packages tells the System loader how to load when no filename and/or no extension
var packages = { var packages = {
@@ -39,7 +40,8 @@
'ng2-alfresco-viewer': { main: 'index.js', defaultExtension: 'js'}, 'ng2-alfresco-viewer': { main: 'index.js', defaultExtension: 'js'},
'ng2-activiti-form': { main: 'index.js', defaultExtension: 'js'}, 'ng2-activiti-form': { main: 'index.js', defaultExtension: 'js'},
'ng2-activiti-tasklist': { main: 'index.js', defaultExtension: 'js'}, 'ng2-activiti-tasklist': { main: 'index.js', defaultExtension: 'js'},
'ng2-alfresco-webscript': { main: 'index.js', defaultExtension: 'js'} 'ng2-alfresco-webscript': { main: 'index.js', defaultExtension: 'js'},
'alfresco-js-api': { main: 'alfresco-js-api.js', defaultExtension: 'js'}
}; };
var ngPackageNames = [ var ngPackageNames = [
'common', 'common',

View File

@@ -16,6 +16,7 @@
*/ */
import { import {
AlfrescoApiService,
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoTranslationLoader, AlfrescoTranslationLoader,
AlfrescoTranslationService, AlfrescoTranslationService,
@@ -31,6 +32,7 @@ export * from './src/components/index';
export * from './src/utils/index'; export * from './src/utils/index';
export const ALFRESCO_CORE_PROVIDERS: [any] = [ export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoApiService,
AlfrescoAuthenticationService, AlfrescoAuthenticationService,
AlfrescoContentService, AlfrescoContentService,
AlfrescoSettingsService, AlfrescoSettingsService,

View File

@@ -0,0 +1,34 @@
/*!
* @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 '@angular/core';
import { AlfrescoJsApi } from 'alfresco-js-api';
@Injectable()
export class AlfrescoApiService {
private _instance: AlfrescoJsApi;
public getInstance(): AlfrescoJsApi {
return this._instance;
}
public setInstance(value: AlfrescoJsApi) {
this._instance = value;
}
}

View File

@@ -18,8 +18,10 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { AlfrescoSettingsService } from './AlfrescoSettings.service'; import { AlfrescoSettingsService } from './AlfrescoSettings.service';
import { AlfrescoApiService } from './AlfrescoApi.service';
import { AlfrescoJsApi } from 'alfresco-js-api';
declare let AlfrescoApi: any; declare var AlfrescoApi: AlfrescoJsApi;
/** /**
* The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage * The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage
@@ -27,32 +29,37 @@ declare let AlfrescoApi: any;
@Injectable() @Injectable()
export class AlfrescoAuthenticationService { export class AlfrescoAuthenticationService {
alfrescoApi: any; alfrescoApi: AlfrescoJsApi;
/**A /**
* Constructor * Constructor
* @param alfrescoSetting * @param settingsService
* @param apiService
*/ */
constructor(public alfrescoSetting: AlfrescoSettingsService) { constructor(private settingsService: AlfrescoSettingsService,
private apiService: AlfrescoApiService) {
this.alfrescoApi = new AlfrescoApi({ this.alfrescoApi = new AlfrescoApi({
provider: this.alfrescoSetting.getProviders(), provider: this.settingsService.getProviders(),
ticketEcm: this.getTicketEcm(), ticketEcm: this.getTicketEcm(),
ticketBpm: this.getTicketBpm(), ticketBpm: this.getTicketBpm(),
hostEcm: this.alfrescoSetting.ecmHost, hostEcm: this.settingsService.ecmHost,
hostBpm: this.alfrescoSetting.bpmHost hostBpm: this.settingsService.bpmHost,
contextRoot: 'alfresco'
}); });
alfrescoSetting.bpmHostSubject.subscribe((bpmHost) => { settingsService.bpmHostSubject.subscribe((bpmHost) => {
this.alfrescoApi.changeBpmHost(bpmHost); this.alfrescoApi.changeBpmHost(bpmHost);
}); });
alfrescoSetting.ecmHostSubject.subscribe((ecmHost) => { settingsService.ecmHostSubject.subscribe((ecmHost) => {
this.alfrescoApi.changeEcmHost(ecmHost); this.alfrescoApi.changeEcmHost(ecmHost);
}); });
alfrescoSetting.providerSubject.subscribe((value) => { settingsService.providerSubject.subscribe((value) => {
this.alfrescoApi.config.provider = value; this.alfrescoApi.config.provider = value;
}); });
this.apiService.setInstance(this.alfrescoApi);
} }
/** /**
@@ -73,7 +80,7 @@ export class AlfrescoAuthenticationService {
return Observable.fromPromise(this.callApiLogin(username, password)) return Observable.fromPromise(this.callApiLogin(username, password))
.map((response: any) => { .map((response: any) => {
this.saveTickets(); this.saveTickets();
return {type: this.alfrescoSetting.getProviders(), ticket: response}; return {type: this.settingsService.getProviders(), ticket: response};
}) })
.catch(this.handleError); .catch(this.handleError);
} }

View File

@@ -15,6 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
export * from './AlfrescoApi.service';
export * from './AlfrescoSettings.service'; export * from './AlfrescoSettings.service';
export * from './AlfrescoTranslationLoader.service'; export * from './AlfrescoTranslationLoader.service';
export * from './AlfrescoTranslation.service'; export * from './AlfrescoTranslation.service';