Update from development branch

This commit is contained in:
Denys Vuika
2016-07-13 12:58:02 +01:00
60 changed files with 429 additions and 484 deletions

View File

@@ -24,7 +24,7 @@
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="/app/js/xml2json.js"></script>
<script src="node_modules/alfresco-js-api/bundle.js"></script>
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
<script src="node_modules/pdfjs-dist/build/pdf.js"></script>
<script src="node_modules/pdfjs-dist/build/pdf.worker.js"></script>

View File

@@ -75,7 +75,7 @@
"pdfjs-dist": "1.5.258",
"flag-icon-css": "2.3.0",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "0.2.0",
"ng2-alfresco-core": "0.2.0",
"ng2-alfresco-datatable": "0.2.0",
"ng2-alfresco-documentlist": "0.2.0",

View File

@@ -14,7 +14,8 @@ var map = {
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'alfresco-js-api' : { main: 'alfresco-js-api.js', defaultExtension: 'js' },
'ng2-translate': { defaultExtension: 'js' }
};

View File

@@ -11,10 +11,13 @@ module.exports = function (config) {
{pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
{pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true},
{pattern: 'node_modules/zone.js/dist/async-test.js', included: true, watched: true},
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.map', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.map', included: false, watched: false},
{pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@@ -6,19 +6,15 @@
"scripts": {
"clean": "rimraf dist node_modules typings",
"typings": "typings install",
"build": "npm run tslint && typings install && rimraf dist && tsc && npm run copytemplates && license-check",
"build": "npm run tslint && typings install && rimraf dist && tsc && license-check",
"build:w": "npm run tslint && typings install && rimraf dist && npm run watch-task",
"watch-task": "concurrently \"npm run tsc:w\" \"license-check\"",
"tslint": "npm run tslint-src && npm run tslint-root",
"tslint-src": "tslint -c tslint.json src/{,**/}**.ts",
"tslint-root": "tslint -c tslint.json *.ts",
"copytemplates": "npm run copy-html-css && npm run copy-i18n",
"copy-html-css": "cpx \"./src/**/*.{html,css}\" ./dist/src",
"copy-html-css:w": "cpx \"./src/**/*.{html,css}\" ./dist/src -w",
"copy-i18n": "cpx \"./i18n/**/*.json\" ./dist/i18n",
"copy-i18n:w": "cpx \"./i18n/**/*.json\" ./dist/i18n -w",
"copy-images": "cpx \"./src/**/*.{png,jpg,gif,svg}\" ./dist/src",
"copy-images:w": "cpx \"./src/**/*.{png,jpg,gif,svg}\" ./dist/src -w",
"licensecheck": "license-check",
"tsc": "tsc",
"tsc:w": "tsc -w",
"pretest": "npm run build",
"test": "karma start karma.conf.js --reporters mocha,coverage --single-run",
"test-browser": "karma start karma.conf.js --reporters kjhtml ",
@@ -45,6 +41,10 @@
{
"name": "Mario Romano",
"email": "mario.romano83@gmail.com"
},
{
"name": "Eugenio Romano",
"email": "eugenio.romano@alfresco.com"
}
],
"keywords": [
@@ -54,6 +54,7 @@
"alfresco"
],
"dependencies": {
"alfresco-js-api": "^0.2.0",
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
@@ -69,8 +70,7 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"ng2-translate": "2.2.2",
"rimraf": "2.5.2"
"ng2-translate": "2.2.2"
},
"peerDependencies": {
"material-design-icons": "^2.2.3",
@@ -90,6 +90,7 @@
"karma-mocha-reporter": "2.0.3",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -0,0 +1,35 @@
/*!
* @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.
*/
export class AlfrescoApiMock {
login(username: string, password: string) {
return new Promise((resolve) => {
resolve('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
});
}
logout() {
return new Promise((resolve) => {
resolve('logout');
});
}
changeConfig() {
}
}

View File

@@ -19,6 +19,7 @@ import { Observable } from 'rxjs/Rx';
export interface AbstractAuthentication {
TYPE: string;
alfrescoApi: any;
login(username: string, password: string): Observable<any>;
@@ -26,8 +27,7 @@ export interface AbstractAuthentication {
isLoggedIn(): boolean ;
getToken(): string;
saveToken(): void;
getTicket(): string;
saveTicket(ticket: any): void;
}

View File

@@ -24,7 +24,6 @@ import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implements AbstractAuthentication {
TYPE: string = 'BPM';
private token: string;
constructor(private alfrescoSettingsService: AlfrescoSettingsService,
private http: Http) {
@@ -41,9 +40,8 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
login(username: string, password: string): Observable<any> {
return Observable.fromPromise(this.apiActivitiLogin(username, password))
.map((response: any) => {
this.token = response.status;
return this.token;
// return {name: this.TYPE, token: response.status};
this.saveTicket(response.status);
return response.status;
})
.catch(this.handleError);
}
@@ -57,7 +55,7 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
return Observable.fromPromise(this.apiActivitiLogout())
.map(res => <any> res)
.do(response => {
this.removeToken(this.TYPE);
this.removeTicket(this.TYPE);
})
.catch(this.handleError);
}
@@ -67,7 +65,7 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
* @returns {boolean}
*/
isLoggedIn(): boolean {
return !!this.getToken();
return !!this.getTicket();
}
private apiActivitiLogin(username: string, password: string) {
@@ -91,17 +89,17 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
return this.http.get(url).toPromise();
}
public getToken (): string {
return localStorage.getItem(`token-${this.TYPE}`);
public getTicket(): string {
return localStorage.getItem(`ticket-${this.TYPE}`);
}
/**
* The method save the toke in the localStorage
* @param token
* The method save the ticket in the localStorage
* @param ticket
*/
public saveToken(): void {
if (this.token) {
super.saveToken(this.TYPE, this.token);
public saveTicket(ticket): void {
if (ticket) {
super.saveTicket(this.TYPE, ticket);
}
}

View File

@@ -23,6 +23,8 @@ declare let AlfrescoApi: any;
export class AlfrescoAuthenticationBase {
alfrescoApi: any;
private _authUrl: string = '/alfresco/api/-default-/public/authentication/versions/1';
private alfrescoSetting: AlfrescoSettingsService;
/**
@@ -40,19 +42,19 @@ export class AlfrescoAuthenticationBase {
/**
* The method save the toke in the localStorage
* @param token
* @param ticket
*/
public saveToken(provider:string, token: string): void {
if (token) {
localStorage.setItem(`token-${provider}`, token);
public saveTicket(provider:string, ticket: string): void {
if (ticket) {
localStorage.setItem(`ticket-${provider}`, ticket);
}
}
/**
* Remove the login token from localStorage
* Remove the login ticket from localStorage
*/
public removeToken(provider:string): void {
localStorage.removeItem(`token-${provider}`);
public removeTicket(provider:string): void {
localStorage.removeItem(`ticket-${provider}`);
}
/**

View File

@@ -26,84 +26,97 @@ declare let AlfrescoApi: any;
export class AlfrescoAuthenticationECM extends AlfrescoAuthenticationBase implements AbstractAuthentication {
TYPE: string = 'ECM';
private token: string;
alfrescoApi: any;
/**
* Constructor
* @param alfrescoSettingsService
*/
constructor(private alfrescoSettingsService: AlfrescoSettingsService,
private http: Http) {
super(alfrescoSettingsService, http);
if (!this.isLoggedIn) {
this.alfrescoApi = new AlfrescoApi({
host: this.getBaseUrl()
});
} else {
this.alfrescoApi = new AlfrescoApi({
ticket: this.getTicket(),
host: this.getBaseUrl()
});
}
}
getBaseUrl(): string {
return this.alfrescoSettingsService.host;
}
getAlfrescoApi(): any {
return this.alfrescoApi;
}
/**
* Perform a login on behalf of the user and store the ticket returned
*
* The method return tru if the user is logged in
* @returns {boolean}
*/
isLoggedIn(): boolean {
return !!this.getTicket();
}
/**
* Method to delegate to POST login
* @param username
* @param password
* @returns {Observable<R>|Observable<T>}
*/
login(username: string, password: string): Observable<any> {
return Observable.fromPromise(this.getCreateTicketPromise(username, password))
.map((response: any) => {
this.token = response.entry.id;
return this.token;
// return {name: this.TYPE, token: response.entry.id};
login(username: string, password: string) {
this.alfrescoApi = new AlfrescoApi({
username: username,
password: password,
host: this.getBaseUrl()
});
return Observable.fromPromise(this.alfrescoApi.login())
.map(res => <any> res)
.do(response => {
this.saveTicket(response);
return response;
})
.catch(this.handleError);
}
/**
* Delete the current login ticket from the server
* The method remove the ticket from the local storage
*
* @returns {Observable<R>|Observable<T>}
*/
logout() {
return Observable.fromPromise(this.getDeleteTicketPromise())
public logout() {
return Observable.fromPromise(this.alfrescoApi.logout())
.map(res => <any> res)
.do(response => {
this.removeToken(this.TYPE);
this.removeTicket(this.TYPE);
return response;
})
.catch(this.handleError);
}
/**
* The method return true if the user is logged in
* @returns {boolean}
* The method return the ticket stored in the localStorage
* @returns ticket
*/
isLoggedIn(): boolean {
return !!this.getToken();
}
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getToken());
}
private getCreateTicketPromise(username: string, password: string) {
let apiInstance = new AlfrescoApi.Auth.AuthenticationApi(this.getAlfrescoClient());
let loginRequest = new AlfrescoApi.Auth.LoginRequest();
loginRequest.userId = username;
loginRequest.password = password;
return apiInstance.createTicket(loginRequest);
}
private getDeleteTicketPromise() {
let apiInstance = new AlfrescoApi.Auth.AuthenticationApi(this.getAlfrescoClient());
return apiInstance.deleteTicket();
public getTicket(): string {
return localStorage.getItem(`ticket-${this.TYPE}`);
}
/**
* The method return the token stored in the localStorage
* @param token
* The method save the ticket in the localStorage
* @param ticket
*/
public getToken (): string {
return localStorage.getItem(`token-${this.TYPE}`);
}
/**
* The method save the toke in the localStorage
* @param token
*/
public saveToken(): void {
if (this.token) {
super.saveToken(this.TYPE, this.token);
public saveTicket(ticket): void {
if (ticket) {
super.saveTicket(this.TYPE, ticket);
}
}

View File

@@ -36,7 +36,7 @@ describe('AlfrescoAuthentication', () => {
resolve({
entry: {
userId: 'fake-username',
id: 'fake-post-token-ECM'
id: 'fake-post-ticket-ECM'
}
});
reject({
@@ -48,7 +48,7 @@ describe('AlfrescoAuthentication', () => {
fakePromiseBPM = new Promise(function (resolve, reject) {
resolve({
status: 'fake-post-token-BPM'
status: 'fake-post-ticket-BPM'
});
reject({
response: {
@@ -109,7 +109,7 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return an ECM token after the login done', (done) => {
it('should return an ECM ticket after the login done', (done) => {
let providers = ['ECM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -120,13 +120,13 @@ describe('AlfrescoAuthentication', () => {
service.login('fake-username', 'fake-password', providers)
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(true);
expect(service.getToken(providers[0])).toEqual('fake-post-token-ECM');
expect(service.getTicket(providers[0])).toEqual('fake-post-ticket-ECM');
done();
}
);
});
it('should return token undefined when the credentials are wrong', (done) => {
it('should return ticket undefined when the credentials are wrong', (done) => {
let providers = ['ECM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -142,7 +142,7 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
done();
}
);
@@ -186,21 +186,21 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return a token undefined after logout', (done) => {
it('should return a ticket undefined after logout', (done) => {
let providers = ['ECM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
service = injector.get(AlfrescoAuthenticationService);
localStorage.setItem('token-ECM', 'fake-post-token-ECM');
localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM');
service.createProviderInstance(providers);
spyOn(AlfrescoAuthenticationECM.prototype, 'getDeleteTicketPromise').and.returnValue(fakePromiseECM);
service.logout()
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(localStorage.getItem('token-ECM')).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(localStorage.getItem('ticket-ECM')).toBeUndefined();
done();
}
);
@@ -252,7 +252,7 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return an BPM token after the login done', (done) => {
it('should return an BPM ticket after the login done', (done) => {
let providers = ['BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -263,13 +263,13 @@ describe('AlfrescoAuthentication', () => {
service.login('fake-username', 'fake-password', providers)
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(true);
expect(service.getToken(providers[0])).toEqual('fake-post-token-BPM');
expect(service.getTicket(providers[0])).toEqual('fake-post-ticket-BPM');
done();
}
);
});
it('should return token undefined when the credentials are wrong', (done) => {
it('should return ticket undefined when the credentials are wrong', (done) => {
let providers = ['BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -284,27 +284,27 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
done();
}
);
});
it('should return a token undefined after logout', (done) => {
it('should return a ticket undefined after logout', (done) => {
let providers = ['BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
service = injector.get(AlfrescoAuthenticationService);
localStorage.setItem('token-BPM', 'fake-post-token-BPM');
localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM');
service.createProviderInstance(providers);
spyOn(AlfrescoAuthenticationBPM.prototype, 'apiActivitiLogout').and.returnValue(fakePromiseBPM);
service.logout()
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(localStorage.getItem('token-BPM')).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(localStorage.getItem('ticket-BPM')).toBeUndefined();
done();
}
);
@@ -316,7 +316,7 @@ describe('AlfrescoAuthentication', () => {
alfSetting.providers = providers;
service = injector.get(AlfrescoAuthenticationService);
localStorage.setItem('token-BPM', 'fake-post-token-BPM');
localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM');
service.createProviderInstance(providers);
spyOn(AlfrescoAuthenticationBPM.prototype, 'apiActivitiLogout').and.returnValue(Promise.reject('fake logout error'));
@@ -328,7 +328,7 @@ describe('AlfrescoAuthentication', () => {
(err: any) => {
expect(err).toBeDefined();
expect(err.message).toEqual('fake logout error');
expect(localStorage.getItem('token-BPM')).toEqual('fake-post-token-BPM');
expect(localStorage.getItem('ticket-BPM')).toEqual('fake-post-ticket-BPM');
done();
}
);
@@ -361,7 +361,7 @@ describe('AlfrescoAuthentication', () => {
);
});
it('should return both ECM and BPM tokens after the login done', (done) => {
it('should return both ECM and BPM tickets after the login done', (done) => {
let providers = ['ECM', 'BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -374,14 +374,14 @@ describe('AlfrescoAuthentication', () => {
.subscribe(() => {
expect(service.isLoggedIn(providers[0])).toBe(true);
expect(service.isLoggedIn(providers[1])).toBe(true);
expect(service.getToken(providers[0])).toEqual('fake-post-token-ECM');
expect(service.getToken(providers[1])).toEqual('fake-post-token-BPM');
expect(service.getTicket(providers[0])).toEqual('fake-post-ticket-ECM');
expect(service.getTicket(providers[1])).toEqual('fake-post-ticket-BPM');
done();
}
);
});
it('should return token undefined when the credentials are correct for the ECM login but wrong for the BPM login', (done) => {
it('should return ticket undefined when the credentials are correct for the ECM login but wrong for the BPM login', (done) => {
let providers = ['ECM', 'BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -397,15 +397,15 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(service.isLoggedIn(providers[1])).toBe(false);
expect(service.getToken(providers[1])).toBeUndefined();
expect(service.getTicket(providers[1])).toBeUndefined();
done();
}
);
});
it('should return token undefined when the credentials are correct for the BPM login but wrong for the ECM login', (done) => {
it('should return ticket undefined when the credentials are correct for the BPM login but wrong for the ECM login', (done) => {
let providers = ['ECM', 'BPM'];
let alfSetting = injector.get(AlfrescoSettingsService);
alfSetting.providers = providers;
@@ -422,9 +422,9 @@ describe('AlfrescoAuthentication', () => {
},
(err: any) => {
expect(service.isLoggedIn(providers[0])).toBe(false);
expect(service.getToken(providers[0])).toBeUndefined();
expect(service.getTicket(providers[0])).toBeUndefined();
expect(service.isLoggedIn(providers[1])).toBe(false);
expect(service.getToken(providers[1])).toBeUndefined();
expect(service.getTicket(providers[1])).toBeUndefined();
done();
}
);

View File

@@ -26,7 +26,7 @@ import { AlfrescoAuthenticationBase } from './AlfrescoAuthenticationBase.service
declare let AlfrescoApi: any;
/**
* The AlfrescoAuthenticationService provide the login service and store the token in the localStorage
* The AlfrescoAuthenticationService provide the login service and store the ticket in the localStorage
*/
@Injectable()
export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
@@ -78,10 +78,6 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
return Observable.create(observer => {
Observable.forkJoin(observableBatch).subscribe(
(response: any[]) => {
this.performeSaveToken();
/*response.forEach((res) => {
this.performeSaveToken(res.name, res.token);
});*/
observer.next(response);
},
(err: any) => {
@@ -91,7 +87,7 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
}
/**
* The method return tru if the user is logged in
* The method return true if the user is logged in
* @returns {boolean}
*/
isLoggedIn(type: string = 'ECM'): boolean {
@@ -102,36 +98,24 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
return false;
}
getAlfrescoApi(): any {
return this.findProviderInstance('ECM').alfrescoApi;
}
/**
* Return the token stored in the localStorage of the specific provider type
* @param token
* Return the ticket stored in the localStorage of the specific provider type
* @param ticket
*/
public getToken(type: string = 'ECM'): string {
public getTicket(type: string = 'ECM'): string {
let auth: AbstractAuthentication = this.findProviderInstance(type);
if (auth) {
return auth.getToken();
return auth.getTicket();
}
return '';
}
/**
* Save the token calling the method of the specific provider type
* @param providerName
* @param token
*/
private performeSaveToken() {
/* let auth: AbstractAuthentication = this.findProviderInstance(type);
if (auth) {
auth.saveToken();
}
*/
this.providersInstance.forEach((authInstance) => {
authInstance.saveToken();
});
}
/**
* The method remove the token from the local storage
* The method remove the ticket from the local storage
* @returns {Observable<T>}
*/
public logout(): Observable<string> {
@@ -190,7 +174,7 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
let auth: AbstractAuthentication = null;
if (this.providersInstance && this.providersInstance.length !== 0) {
this.providersInstance.forEach((provider) => {
if (provider.TYPE === type) {
if (provider.TYPE === type.toUpperCase()) {
auth = provider;
}
});

View File

@@ -18,15 +18,11 @@
import { Injectable } from '@angular/core';
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
@Injectable()
export class AlfrescoContentService {
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService
) {
constructor(private authService: AlfrescoAuthenticationService) {
}
/**
@@ -34,9 +30,8 @@ export class AlfrescoContentService {
* @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();
getDocumentThumbnailUrl(document: any): string {
return this.authService.alfrescoApi.content.getDocumentThumbnailUrl(document.entry.id);
}
/**
@@ -44,8 +39,7 @@ export class AlfrescoContentService {
* @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();
getContentUrl(document: any): string {
return this.authService.alfrescoApi.content.getContentUrl(document.entry.id);
}
}

View File

@@ -26,6 +26,8 @@ describe('AlfrescoContentService', () => {
let injector, service: AlfrescoContentService, authService: AlfrescoAuthenticationService;
const nodeId = 'blah';
let DEFAULT_CONTEXT_PATH: string = '/alfresco';
let DEFAULT_BASE_API_PATH: string = '/api/-default-/public/alfresco/versions/1';
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
@@ -35,7 +37,7 @@ describe('AlfrescoContentService', () => {
AlfrescoSettingsService
]);
spyOn(localStorage, 'getItem').and.callFake(function (key) {
return 'myToken';
return 'myTicket';
});
service = injector.get(AlfrescoContentService);
authService = injector.get(AlfrescoAuthenticationService);
@@ -47,9 +49,9 @@ describe('AlfrescoContentService', () => {
id: nodeId
}
})).toBe(
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH +
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
'?attachment=false&alf_ticket=' + authService.getToken()
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + DEFAULT_CONTEXT_PATH +
DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
'?attachment=false&alf_ticket=' + authService.getTicket()
);
});
@@ -59,9 +61,9 @@ describe('AlfrescoContentService', () => {
id: nodeId
}
})).toBe(
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH +
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
'?attachment=false&alf_ticket=' + authService.getToken()
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + DEFAULT_CONTEXT_PATH +
DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
'?attachment=false&alf_ticket=' + authService.getTicket()
);
});
});

View File

@@ -37,11 +37,4 @@ describe('AlfrescoSettingsService', () => {
expect(service.host).toBe(address);
});
it('should format api url', () => {
let address = 'http://192.168.0.1';
let expectedUrl =
`${address}${AlfrescoSettingsService.DEFAULT_CONTEXT_PATH}${AlfrescoSettingsService.DEFAULT_BASE_API_PATH}`;
service.host = address;
expect(service.getApiBaseUrl()).toBe(expectedUrl);
});
});

View File

@@ -40,7 +40,6 @@
"zone.js": "0.6.12",
"license-check": "1.1.5",
"rimraf": "2.5.2",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"ng2-translate": "2.2.2",
@@ -51,6 +50,7 @@
"devDependencies": {
"browser-sync": "2.10.0",
"concurrently": "2.0.0",
"rimraf": "2.5.2",
"tslint": "3.8.1",
"typescript": "1.8.10",
"typings": "1.0.4",

View File

@@ -67,7 +67,6 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"ng2-alfresco-core": "0.2.0"
},
@@ -89,6 +88,7 @@
"karma-mocha-reporter": "2.0.3",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -20,7 +20,7 @@
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- Additional Alfresco libraries -->
<script src="node_modules/alfresco-js-api/bundle.js"></script>
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
<script src="systemjs.config.js"></script>
<script>

View File

@@ -1,58 +1,56 @@
{
"name": "ng2-alfresco-documentlist-demo",
"description": "Alfresco Angular2 Documentlist Component - Demo",
"version": "0.1.0",
"author": "Alfresco Software, Ltd.",
"main": "index.js",
"scripts": {
"clean": "rimraf dist node_modules typings",
"typings": "typings install",
"postinstall": "npm run typings && npm run build",
"start": "concurrently \"npm run build:w\" \"npm run server\" ",
"server": "wsrv -o -s -l",
"build": "npm run tslint && rimraf dist && tsc",
"build:w": "npm run tslint && rimraf dist && tsc -w",
"tslint": "npm run tslint-src && npm run tslint-root",
"tslint-src": "tslint -c tslint.json src/{,**/}**.ts",
"tslint-root": "tslint -c tslint.json *.ts"
},
"license": "Apache-2.0",
"dependencies": {
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/forms": "0.1.1",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/router": "3.0.0-alpha.7",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.3",
"systemjs": "0.19.27",
"core-js": "2.4.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"ng2-translate": "2.2.2",
"alfresco-js-api": "^0.1.0",
"ng2-alfresco-core": "^0.1.36",
"ng2-alfresco-documentlist": "^0.1.34",
"ng2-alfresco-datatable": "^0.1.17"
},
"devDependencies": {
"concurrently": "2.0.0",
"tslint": "3.8.1",
"typescript": "1.8.10",
"typings": "1.0.4",
"wsrv": "0.1.3"
},
"keywords": [
"angular2",
"typescript"
]
"name": "ng2-alfresco-documentlist-demo",
"description": "Alfresco Angular2 Documentlist Component - Demo",
"version": "0.1.0",
"author": "Alfresco Software, Ltd.",
"main": "index.js",
"scripts": {
"clean": "rimraf dist node_modules typings",
"typings": "typings install",
"postinstall": "npm run typings && npm run build",
"start": "concurrently \"npm run build:w\" \"npm run server\" ",
"server": "wsrv -o -s -l",
"build": "npm run tslint && rimraf dist && tsc",
"build:w": "npm run tslint && rimraf dist && tsc -w",
"tslint": "npm run tslint-src && npm run tslint-root",
"tslint-src": "tslint -c tslint.json src/{,**/}**.ts",
"tslint-root": "tslint -c tslint.json *.ts"
},
"license": "Apache-2.0",
"dependencies": {
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/forms": "0.1.1",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/router": "3.0.0-alpha.7",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.3",
"systemjs": "0.19.27",
"core-js": "2.4.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"ng2-translate": "2.2.2",
"alfresco-js-api": "^0.2.0",
"ng2-alfresco-core": "^0.2.0",
"ng2-alfresco-documentlist": "^0.2.0",
"ng2-alfresco-datatable": "^0.2.0"
},
"devDependencies": {
"concurrently": "2.0.0",
"rimraf": "2.5.2",
"tslint": "3.8.1",
"typescript": "1.8.10",
"typings": "1.0.4",
"wsrv": "0.1.3"
},
"keywords": [
"angular2",
"typescript"
]
}

View File

@@ -46,7 +46,7 @@ import {
operations.
</div>
<hr>
<div class="container">
<div class="container" *ngIf="authenticated">
<alfresco-document-list-breadcrumb
[currentFolderPath]="currentPath"
@@ -155,11 +155,9 @@ class DocumentListDemo implements OnInit {
private documentActions: DocumentActionsService) {
alfrescoSettingsService.host = this.host;
if (this.authService.getToken()) {
this.token = this.authService.getToken();
if (this.authService.getTicket()) {
this.token = this.authService.getTicket();
}
translation.addTranslationFolder();
documentActions.setHandler('my-handler', this.myDocumentActionHandler.bind(this));
}
@@ -177,7 +175,7 @@ class DocumentListDemo implements OnInit {
this.login();
}
myDocumentActionHandler(obj: any) {
myDocumentActionHandler() {
window.alert('my custom action handler');
}
@@ -195,6 +193,7 @@ class DocumentListDemo implements OnInit {
this.authService.login('admin', 'admin', ['ECM']).subscribe(
token => {
console.log(token);
this.token = token;
this.authenticated = true;
},
error => {

View File

@@ -26,7 +26,7 @@
"label-undefined": true,
"max-line-length": [
true,
140
180
],
"member-ordering": [
true,

View File

@@ -1,6 +1,7 @@
{
"watch": [
"node_modules/ng2-alfresco-datatable/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-core/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-documentlist/dist/**/*.{html,htm,css,js}"
]
}

View File

@@ -18,6 +18,7 @@ module.exports = function (config) {
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
{pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.js', included: false, served: true, watched: false},
{pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false},
{pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@@ -48,6 +48,10 @@
{
"name": "Mario Romano",
"email": "mario.romano83@gmail.com"
},
{
"name": "Eugenio Romano",
"email": "eugenio.romano@alfresco.com"
}
],
"keywords": [
@@ -72,11 +76,10 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"ng2-alfresco-core": "0.2.0",
"ng2-alfresco-datatable": "0.2.0",
"alfresco-js-api": "^0.1.0"
"ng2-alfresco-datatable": "0.2.0",
"alfresco-js-api": "0.2.0"
},
"peerDependencies": {
"material-design-icons": "^2.2.3",
@@ -96,6 +99,7 @@
"karma-jasmine-html-reporter": "0.2.0",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -36,7 +36,7 @@ export class DocumentListServiceMock extends DocumentListService {
authService?: AlfrescoAuthenticationService,
contentService?: AlfrescoContentService
) {
super(settings, authService, contentService);
super(authService, contentService);
}
getFolder(folder: string) {

View File

@@ -39,7 +39,7 @@ describe('DocumentActionsService', () => {
beforeEach(() => {
documentListService = new DocumentListServiceMock();
contentService = new AlfrescoContentService(null, null);
contentService = new AlfrescoContentService(null);
service = new DocumentActionsService(documentListService, contentService);
});

View File

@@ -48,8 +48,8 @@ describe('DocumentListService', () => {
settingsService = injector.get(AlfrescoSettingsService);
authService = injector.get(AlfrescoAuthenticationService);
contentService = new AlfrescoContentService(settingsService, authService);
service = new DocumentListService(settingsService, authService, contentService);
contentService = new AlfrescoContentService(authService);
service = new DocumentListService(authService, contentService);
});
it('should require node to get thumbnail url', () => {
@@ -57,7 +57,7 @@ describe('DocumentListService', () => {
});
it('should require content service to get thumbnail url', () => {
service = new DocumentListService(settingsService, authService, null);
service = new DocumentListService(authService, null);
let file = new FileNode();
expect(service.getDocumentThumbnailUrl(file)).toBeNull();
});

View File

@@ -20,7 +20,6 @@ import { Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService,
AlfrescoContentService
} from 'ng2-alfresco-core';
@@ -62,19 +61,16 @@ export class DocumentListService {
};
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService,
private contentService: AlfrescoContentService
) {
}
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
private getAlfrescoApi() {
return this.authService.getAlfrescoApi();
}
private getNodesPromise(folder: string, opts?: any) {
let alfrescoClient = this.getAlfrescoClient();
let apiInstance = new AlfrescoApi.Core.NodesApi(alfrescoClient);
let nodeId = '-root-';
let params: any = {
relativePath: folder,
@@ -90,23 +86,20 @@ export class DocumentListService {
}
}
return apiInstance.getNodeChildren(nodeId, params);
}
deleteNode(nodeId: string) {
let client = this.getAlfrescoClient();
let nodesApi = new AlfrescoApi.Core.NodesApi(client);
let opts = {};
return Observable.fromPromise(nodesApi.deleteNode(nodeId, opts));
return this.getAlfrescoApi().node.getNodeChildren(nodeId, params);
}
deleteNode(nodeId: string) {
return Observable.fromPromise(this.getAlfrescoApi().node.deleteNode(nodeId));
}
// TODO: rename to 'getFolderContent'
/**
* Gets the folder node with the content.
* @param folder Path to folder.
* @param opts Options
* @param opts Options.
* @returns {Observable<NodePaging>} Folder entity.
*/
getFolder(folder: string, opts?: any): Observable<NodePaging> {
getFolder(folder: string, opts?: any) {
return Observable.fromPromise(this.getNodesPromise(folder, opts))
.map(res => <NodePaging> res)
// .do(data => console.log('Node data', data)) // eyeball results in the console
@@ -118,7 +111,7 @@ export class DocumentListService {
* @param node Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(node: MinimalNodeEntity): string {
getDocumentThumbnailUrl(node: MinimalNodeEntity) {
if (node && this.contentService) {
return this.contentService.getDocumentThumbnailUrl(node);
}

View File

@@ -20,7 +20,7 @@
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- Additional Alfresco libraries -->
<script src="node_modules/alfresco-js-api/bundle.js"></script>
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
<script src="systemjs.config.js"></script>
<script>

View File

@@ -9,7 +9,7 @@
"typings": "typings install",
"postinstall": "npm run typings && npm run build",
"start": "concurrently \"npm run build:w\" \"npm run server\" ",
"server": "wsrv -o -l -s",
"server": "wsrv -o -s -l",
"build": "npm run tslint && rimraf dist && tsc",
"build:w": "npm run tslint && rimraf dist && tsc -w",
"tslint": "npm run tslint-src && npm run tslint-root",
@@ -62,17 +62,17 @@
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"ng2-translate": "2.2.2",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "^0.2.0",
"ng2-alfresco-core": "^0.1.36",
"ng2-alfresco-login": "^0.1.29"
"ng2-alfresco-login": "file:../"
},
"devDependencies": {
"concurrently": "^2.0.0",
"rimraf": "2.5.2",
"tslint": "^3.8.1",
"typescript": "^1.8.10",
"typings": "^1.0.4",

View File

@@ -28,27 +28,30 @@ import {
@Component({
selector: 'my-app',
template: `<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
<input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br>
<div style="border-radius: 8px; position: absolute; background-color: papayawhip; color: cadetblue; left: 10px; top: 120px; z-index: 1;">
<p style="width:120px;margin: 20px;">
<label for="switch1" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" id="switch1" class="mdl-switch__input" checked (click)="toggleECM(ecm.checked)" #ecm>
<span class="mdl-switch__label">ECM</span>
</label>
</p>
<p style="width:120px;margin: 20px;">
<label for="switch2" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" id="switch2" class="mdl-switch__input" (click)="toggleBPM(bpm.checked)" #bpm>
<span class="mdl-switch__label">BPM</span>
</label>
</p>
</div>
{{ status }}
<hr>
template: `
<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
<input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br>
<div style="border-radius: 8px; position: absolute; background-color: papayawhip; color: cadetblue; left: 10px; top: 120px; z-index: 1;">
<p style="width:120px;margin: 20px;">
<label for="switch1" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" id="switch1" class="mdl-switch__input" checked
(click)="toggleECM(ecm.checked)" #ecm>
<span class="mdl-switch__label">ECM</span>
</label>
</p>
<p style="width:120px;margin: 20px;">
<label for="switch2" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" id="switch2" class="mdl-switch__input"
(click)="toggleBPM(bpm.checked)" #bpm>
<span class="mdl-switch__label">BPM</span>
</label>
</p>
</div>
{{ status }}
<hr>
<alfresco-login [providers]="providers" (onSuccess)="mySuccessMethod($event)"
(onError)="myErrorMethod($event)"></alfresco-login>`,
<alfresco-login [providers]="providers" (onSuccess)="mySuccessMethod($event)"
(onError)="myErrorMethod($event)"></alfresco-login>`,
directives: [AlfrescoLoginComponent]
})
export class AppComponent {

View File

@@ -26,7 +26,7 @@
"label-undefined": true,
"max-line-length": [
true,
140
180
],
"member-ordering": [
true,

View File

@@ -0,0 +1,6 @@
{
"watch": [
"node_modules/ng2-alfresco-core/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-login/dist/**/*.{html,htm,css,js}"
]
}

View File

@@ -80,10 +80,9 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"ng2-alfresco-core": "0.2.0",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "^0.2.0",
"coveralls": "^2.11.9"
},
"devDependencies": {
@@ -100,6 +99,7 @@
"karma-jasmine-html-reporter": "0.2.0",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -92,7 +92,6 @@ export class AlfrescoLoginComponent {
this.form.valueChanges.subscribe(data => this.onValueChanged(data));
// this.onValueChanged(null);
}
/**

View File

@@ -18,7 +18,7 @@
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- Additional Alfresco libraries -->
<script src="node_modules/alfresco-js-api/bundle.js"></script>
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
<script src="systemjs.config.js"></script>
<script>

View File

@@ -6,10 +6,10 @@
"main": "index.js",
"scripts": {
"clean": "rimraf dist node_modules typings",
"postinstall": "npm run typings && npm run build",
"typings": "typings install",
"postinstall": "npm run typings && npm run build",
"start": "concurrently \"npm run build:w\" \"npm run server\" ",
"server": "wsrv -o -l -s",
"server": "wsrv -o -s -l",
"build": "npm run tslint && rimraf dist && tsc",
"build:w": "npm run tslint && rimraf dist && tsc -w",
"tslint": "npm run tslint-src && npm run tslint-root",
@@ -62,17 +62,17 @@
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "^0.2.0",
"ng2-alfresco-core": "^0.1.36",
"ng2-alfresco-search": "^0.1.21"
"ng2-alfresco-search": "^0.1.25"
},
"devDependencies": {
"concurrently": "2.0.0",
"rimraf": "2.5.2",
"tslint": "3.8.1",
"typescript": "1.8.10",
"typings": "1.0.4",

View File

@@ -41,7 +41,7 @@ import {
operations.
</div>
<hr>
<div class="container" >
<div class="container" *ngIf="authenticated">
<alfresco-search-control [searchTerm]="searchTerm"
(searchChange)="searchTermChange($event);"></alfresco-search-control>
<alfresco-search [searchTerm]="searchTerm"></alfresco-search>
@@ -67,17 +67,10 @@ class SearchDemo implements OnInit {
translation: AlfrescoTranslationService) {
alfrescoSettingsService.host = this.host;
if (this.authService.getToken()) {
this.token = this.authService.getToken();
}
translation.addTranslationFolder();
}
public updateToken(): void {
localStorage.setItem('token', this.token);
}
public updateHost(): void {
this.alfrescoSettingsService.host = this.host;
this.login();
@@ -88,9 +81,10 @@ class SearchDemo implements OnInit {
}
login() {
this.authService.login('admin', 'admin').subscribe(
this.authService.login('admin', 'admin', ['ECM']).subscribe(
token => {
console.log(token);
this.token = token;
this.authenticated = true;
},
error => {

View File

@@ -0,0 +1,7 @@
{
"watch": [
"node_modules/ng2-alfresco-core/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-search/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-viewer/dist/**/*.{html,htm,css,js}"
]
}

View File

@@ -16,7 +16,7 @@ module.exports = function (config) {
{pattern: 'node_modules/@angular/**/*.map', included: false, watched: false},
{pattern: 'node_modules/material-design-lite/material.min.js', included: true, watched: false},
{pattern: 'node_modules/alfresco-js-api/bundle.js', included: true, watched: false},
{pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false},
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
{pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false},

View File

@@ -48,6 +48,10 @@
{
"name": "Denys Vuika",
"email": "denys.vuika@alfresco.com"
},
{
"name": "Eugenio Romano",
"email": "eugenio.romano@alfresco.com"
}
],
"keywords": [
@@ -72,10 +76,9 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"material-design-lite": "1.1.3",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "^0.2.0",
"ng2-alfresco-core": "0.2.0"
},
"peerDependencies": {
@@ -95,6 +98,7 @@
"karma-mocha-reporter": "2.0.3",
"karma-jasmine-html-reporter": "0.2.0",
"license-check": "1.1.5",
"rimraf": "2.5.2",
"remap-istanbul": "0.6.3",
"traceur": "0.0.91",
"tslint": "3.8.1",

View File

@@ -18,7 +18,6 @@
import {Observable} from 'rxjs/Rx';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService
} from 'ng2-alfresco-core';
import {AlfrescoSearchService} from './../../src/services/alfresco-search.service';
@@ -28,10 +27,9 @@ export class AlfrescoServiceMock extends AlfrescoSearchService {
_folderToReturn: any = {};
constructor(
settings: AlfrescoSettingsService = null,
authService: AlfrescoAuthenticationService = null
) {
super(settings, authService);
super(authService);
}
getFolder(folder: string) {

View File

@@ -26,6 +26,6 @@ describe('AlfrescoSearchService', () => {
let service: AlfrescoSearchService;
beforeEach(() => {
service = new AlfrescoSearchService(null, null);
service = new AlfrescoSearchService(null);
});
});

View File

@@ -19,7 +19,6 @@ import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import {
AlfrescoSettingsService,
AlfrescoAuthenticationService
} from 'ng2-alfresco-core';
@@ -31,23 +30,17 @@ declare let AlfrescoApi: any;
@Injectable()
export class AlfrescoSearchService {
constructor(private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService) {
}
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
constructor(private authService: AlfrescoAuthenticationService) {
}
private getSearchNodesPromise(term: string) {
let apiInstance = new AlfrescoApi.Core.SearchApi(this.getAlfrescoClient());
let nodeId = '-root-';
let opts = {
include: ['path'],
rootNodeId: nodeId,
nodeType: 'cm:content'
};
return apiInstance.liveSearchNodes(term, opts);
return this.authService.getAlfrescoApi().search.liveSearchNodes(term, opts);
}
/**

View File

@@ -20,8 +20,6 @@ import {
AlfrescoContentService
} from 'ng2-alfresco-core';
declare let AlfrescoApi: any;
@Injectable()
export class AlfrescoThumbnailService {

View File

@@ -20,7 +20,7 @@
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- Additional Alfresco libraries -->
<script src="node_modules/alfresco-js-api/bundle.js"></script>
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
<script src="systemjs.config.js"></script>
<script>

View File

@@ -62,17 +62,17 @@
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "^0.2.0",
"ng2-alfresco-core": "^0.1.36",
"ng2-alfresco-upload": "^0.1.49"
},
"devDependencies": {
"concurrently": "2.0.0",
"rimraf": "2.5.2",
"tslint": "3.8.1",
"typescript": "1.8.10",
"typings": "1.0.4",

View File

@@ -83,8 +83,8 @@ export class MyDemoApp implements OnInit {
constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) {
alfrescoSettingsService.host = this.host;
if (this.authService.getToken()) {
this.token = this.authService.getToken();
if (this.authService.getTicket()) {
this.token = this.authService.getTicket();
}
}
@@ -106,9 +106,10 @@ export class MyDemoApp implements OnInit {
}
login() {
this.authService.login('admin', 'admin').subscribe(
this.authService.login('admin', 'admin', ['ECM']).subscribe(
token => {
console.log(token);
this.token = token;
this.authenticated = true;
},
error => {

View File

@@ -0,0 +1,6 @@
{
"watch": [
"node_modules/ng2-alfresco-core/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-upload/dist/**/*.{html,htm,css,js}"
]
}

View File

@@ -19,6 +19,7 @@ module.exports = function (config) {
{pattern: 'node_modules/material-design-lite/material.min.js', included: true, watched: false},
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
{pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false},
{pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@@ -75,9 +75,8 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"ng2-translate": "2.2.2",
"alfresco-js-api": "^0.1.0",
"alfresco-js-api": "^0.2.0",
"ng2-alfresco-core": "0.2.0"
},
"peerDependencies": {
@@ -100,6 +99,7 @@
"karma-mocha-reporter": "2.0.3",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -25,8 +25,7 @@ export class UploadServiceMock extends UploadService {
filesUpload$: Observable<any>;
totalCompleted$: Observable<number>;
constructor(settings: AlfrescoSettingsService,
authService: AlfrescoAuthenticationService) {
constructor(settings: AlfrescoSettingsService, authService: AlfrescoAuthenticationService) {
super(settings, authService);
}

View File

@@ -82,7 +82,6 @@ export class UploadButtonComponent {
constructor(public el: ElementRef,
private _uploaderService: UploadService,
translate: AlfrescoTranslationService) {
console.log('UploadComponent constructor', el);
let formFields = this.createFormFields();
this._uploaderService.setOptions(formFields);

View File

@@ -31,8 +31,7 @@ let errorFn = jasmine.createSpy('error');
class MockUploadService extends UploadService {
constructor(settings: AlfrescoSettingsService,
authService: AlfrescoAuthenticationService) {
constructor(settings: AlfrescoSettingsService, authService: AlfrescoAuthenticationService) {
super(settings, authService);
}
@@ -88,13 +87,13 @@ describe('AlfrescoUploadService', () => {
service.setOptions(empty);
expect(service.getUrl()).toEqual('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children');
let formFields: Object = {};
expect(service.getFormFileds()).toEqual(formFields);
expect(service.getFormFields()).toEqual(formFields);
});
it('should show the option passed as input', () => {
service.setOptions(options);
expect(service.getUrl()).toEqual('/some/cool/url');
expect(service.getFormFileds()).toEqual({
expect(service.getFormFields()).toEqual({
siteid: 'fakeSite',
containerid: 'fakeFolder'
});

View File

@@ -14,17 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EventEmitter, Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
import { AlfrescoAuthenticationService} from 'ng2-alfresco-core';
import { FileModel } from '../models/file.model';
declare let AlfrescoApi: any;
/**
*
* UploadService keep the queue of the file to upload and uploads them.
@@ -33,29 +29,21 @@ declare let AlfrescoApi: any;
*/
@Injectable()
export class UploadService {
private _url: string = '/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children';
private _method: string = 'POST';
private _fieldName: string = 'filedata';
private _formFields: Object = {};
private formFields: Object = {};
private queue: FileModel[] = [];
private _queue: FileModel[] = [];
filesUpload$: Observable<FileModel[]>;
totalCompleted$: Observable<any>;
private _filesUploadObserver: Observer<FileModel[]>;
private _totalCompletedObserver: Observer<number>;
private _alfrescoClient: any;
private filesUploadObserverProgressBar: Observer<FileModel[]>;
private totalCompletedObserver: Observer<number>;
public totalCompleted: number = 0;
constructor(private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService) {
console.log('UploadService constructor');
this.filesUpload$ = new Observable<FileModel[]>(observer => this._filesUploadObserver = observer).share();
this.totalCompleted$ = new Observable<number>(observer => this._totalCompletedObserver = observer).share();
this._alfrescoClient = this.getAlfrescoClient();
filesUpload$: Observable<FileModel[]>;
totalCompleted$: Observable<any>;
constructor(private authService: AlfrescoAuthenticationService) {
this.filesUpload$ = new Observable<FileModel[]>(observer => this.filesUploadObserverProgressBar = observer).share();
this.totalCompleted$ = new Observable<number>(observer => this.totalCompletedObserver = observer).share();
}
/**
@@ -65,40 +53,16 @@ export class UploadService {
*
*/
public setOptions(options: any): void {
this._url = options.url || this._url;
this._formFields = options.formFields != null ? options.formFields : this._formFields;
this.formFields = options.formFields != null ? options.formFields : this.formFields;
}
/**
* Get the host
* @returns {string}
*/
public getHost(): string {
return this.settings.host;
}
/**
* Get the url
* @returns {string}
*/
public getUrl(): string {
return this._url;
}
/**
* Get the form fields
* @returns {Object}
*/
public getFormFileds(): Object {
return this._formFields;
}
/**
* Get the alfresco client
* @returns {AlfrescoApi.ApiClient}
*/
private getAlfrescoClient() {
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken());
public getFormFields(): Object {
return this.formFields;
}
/**
@@ -112,12 +76,12 @@ export class UploadService {
let latestFilesAdded: FileModel[] = [];
for (let file of files) {
if (this._isFile(file)) {
if (this.isFile(file)) {
let uploadingFileModel = new FileModel(file);
latestFilesAdded.push(uploadingFileModel);
this._queue.push(uploadingFileModel);
if (this._filesUploadObserver) {
this._filesUploadObserver.next(this._queue);
this.queue.push(uploadingFileModel);
if (this.filesUploadObserverProgressBar) {
this.filesUploadObserverProgressBar.next(this.queue);
}
}
}
@@ -128,92 +92,48 @@ export class UploadService {
* Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder.
*/
public uploadFilesInTheQueue(directory: string, elementEmit: EventEmitter<any>): void {
let filesToUpload = this._queue.filter((uploadingFileModel) => {
let filesToUpload = this.queue.filter((uploadingFileModel) => {
return !uploadingFileModel.uploading && !uploadingFileModel.done && !uploadingFileModel.abort && !uploadingFileModel.error;
});
filesToUpload.forEach((uploadingFileModel) => {
uploadingFileModel.setUploading();
this.uploadFile(uploadingFileModel, directory, elementEmit);
});
}
/**
* Create an XMLHttpRequest and return it
* @returns {XMLHttpRequest}
*/
createXMLHttpRequestInstance(uploadingFileModel: any, elementEmit: EventEmitter<any>) {
let xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.upload.onprogress = (e) => {
if (e.lengthComputable) {
let percent = Math.round(e.loaded / e.total * 100);
uploadingFileModel.setProgres({
total: e.total,
loaded: e.loaded,
percent: percent
});
if (this._filesUploadObserver) {
this._filesUploadObserver.next(this._queue);
}
}
};
let _filesUploadObserverProgressBar = this.filesUploadObserverProgressBar;
let _queue = this.queue;
xmlHttpRequest.upload.onabort = (e) => {
uploadingFileModel.setAbort();
};
xmlHttpRequest.upload.onerror = (e) => {
uploadingFileModel.setError();
};
xmlHttpRequest.onreadystatechange = () => {
if (xmlHttpRequest.readyState === XMLHttpRequest.DONE) {
elementEmit.emit({
value: 'File uploaded'
});
uploadingFileModel.onFinished(
xmlHttpRequest.status,
xmlHttpRequest.statusText,
xmlHttpRequest.response
);
this._filesUploadObserver.next(this._queue);
if (!uploadingFileModel.abort && !uploadingFileModel.error) {
if (this._totalCompletedObserver) {
this._totalCompletedObserver.next(++this.totalCompleted);
this.authService.getAlfrescoApi().
upload.uploadFile(uploadingFileModel.file, directory)
.on('progress', (progress: any) => {
uploadingFileModel.setProgres(progress);
if (_filesUploadObserverProgressBar) {
_filesUploadObserverProgressBar.next(_queue);
}
}
}
};
return xmlHttpRequest;
}
})
.on('abort', () => {
uploadingFileModel.setAbort();
})
.on('error', () => {
uploadingFileModel.setError();
})
.on('success', (data: any) => {
elementEmit.emit({
value: 'File uploaded'
});
uploadingFileModel.onFinished(
data.status,
data.statusText,
data.response
);
/**
* Upload a file into the directory folder, and enrich it with the xhr.
*
* @param {FileModel} - files to be uploaded.
*
*/
uploadFile(uploadingFileModel: FileModel, directory: string, elementEmit: EventEmitter<any>): void {
// Configure HTTP basic authorization: basicAuth
let basicAuth = this._alfrescoClient.authentications['basicAuth'];
let form = new FormData();
form.append(this._fieldName, uploadingFileModel.file, uploadingFileModel.name);
Object.keys(this._formFields).forEach((key: any) => {
form.append(key, this._formFields[key]);
_filesUploadObserverProgressBar.next(_queue);
if (!uploadingFileModel.abort && !uploadingFileModel.error) {
if (this.totalCompletedObserver) {
this.totalCompletedObserver.next(++this.totalCompleted);
}
}
});
});
form.append('relativePath', directory);
let xmlHttpRequest = this.createXMLHttpRequestInstance(uploadingFileModel, elementEmit);
uploadingFileModel._xmlHttpRequest = xmlHttpRequest;
xmlHttpRequest.open(this._method, this.getHost() + this.getUrl(), true);
let authToken = btoa(basicAuth.username + ':' + basicAuth.password);
if (authToken) {
xmlHttpRequest.setRequestHeader('Authorization', `${basicAuth.type} ${authToken}`);
}
xmlHttpRequest.send(form);
}
/**
@@ -222,7 +142,7 @@ export class UploadService {
* @return {FileModel[]} - files in the upload queue.
*/
getQueue(): FileModel[] {
return this._queue;
return this.queue;
}
/**
@@ -230,7 +150,7 @@ export class UploadService {
*
* @return {boolean}
*/
private _isFile(file: any): boolean {
private isFile(file: any): boolean {
return file !== null && (file instanceof Blob || (file.name && file.size));
}
@@ -239,15 +159,7 @@ export class UploadService {
* @param name - the folder name
*/
createFolder(relativePath: string, name: string) {
console.log('Directory created' + name);
let apiInstance = new AlfrescoApi.NodesApi(this._alfrescoClient);
let nodeId = '-root-';
let nodeBody = {
'name': name,
'nodeType': 'cm:folder',
'relativePath': relativePath
};
return Observable.fromPromise(apiInstance.addNode(nodeId, nodeBody))
return Observable.fromPromise(this.authService.getAlfrescoApi().node.createFolder(name, relativePath))
.map(res => {
return res;
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

View File

@@ -9,7 +9,7 @@
"typings": "typings install",
"postinstall": "npm run typings && npm run build",
"start": "concurrently \"npm run build:w\" \"npm run server\" ",
"server": "wsrv -o -l -s",
"server": "wsrv -o -s -l",
"build": "npm run tslint && rimraf dist && tsc",
"build:w": "npm run tslint && rimraf dist && tsc -w",
"tslint": "npm run tslint-src && npm run tslint-root",
@@ -34,15 +34,15 @@
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"material-design-icons": "2.2.3",
"material-design-lite": "1.1.3",
"pdfjs-dist": "1.5.258",
"ng2-alfresco-viewer": "^0.1.32"
"ng2-alfresco-viewer" : "file:../"
},
"devDependencies": {
"concurrently": "2.0.0",
"rimraf": "2.5.2",
"tslint": "3.8.1",
"typescript": "1.8.10",
"typings": "1.0.4",

View File

@@ -0,0 +1,6 @@
{
"watch": [
"node_modules/ng2-alfresco-core/dist/**/*.{html,htm,css,js}",
"node_modules/ng2-alfresco-viewer/dist/**/*.{html,htm,css,js}"
]
}

View File

@@ -68,7 +68,6 @@
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12",
"rimraf": "2.5.2",
"pdfjs-dist": "1.5.258"
},
"peerDependencies": {
@@ -92,6 +91,7 @@
"karma-mocha-reporter": "2.0.3",
"license-check": "1.1.5",
"remap-istanbul": "0.6.3",
"rimraf": "2.5.2",
"traceur": "0.0.91",
"tslint": "3.8.1",
"typescript": "1.8.10",

View File

@@ -107,8 +107,6 @@ import { EventMock } from './assets/event.mock';
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
fixture.detectChanges();
EventMock.keyDown(27);
fixture.detectChanges();