From 9c5d62f5d11f39eb8cace94095bc50570d1f9117 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Wed, 17 Aug 2016 16:50:23 +0100 Subject: [PATCH] tasklist modify step 1 --- ng2-components/ng2-activiti-form/README.md | 6 + .../ng2-activiti-form/karma.conf.js | 1 + .../ng2-activiti-processlist/karma.conf.js | 1 + .../ng2-activiti-tasklist/README.md | 6 + .../ng2-activiti-tasklist/demo/package.json | 16 +- .../ng2-activiti-tasklist/package.json | 4 + .../activiti-filters.component.spec.ts | 2 +- .../components/activiti-filters.component.ts | 1 + .../activiti-tasklist.component.spec.ts | 2 +- .../components/activiti-tasklist.component.ts | 1 + .../activiti-tasklist.service.spec.ts | 36 ++--- .../src/services/activiti-tasklist.service.ts | 143 +++++------------- .../src/services/AlfrescoSettings.service.ts | 2 +- .../src/services/upload.service.spec.ts | 6 +- .../ng2-alfresco-webscript/README.md | 2 +- 15 files changed, 92 insertions(+), 137 deletions(-) diff --git a/ng2-components/ng2-activiti-form/README.md b/ng2-components/ng2-activiti-form/README.md index cd1c2def52..cd66c1e8f6 100644 --- a/ng2-components/ng2-activiti-form/README.md +++ b/ng2-components/ng2-activiti-form/README.md @@ -13,6 +13,12 @@ npm install --save ng2-activiti-form ### Dependencies +Add the following dependency to your index.html: + +```html + +``` + You must separately install the following libraries for your application: - [ng2-translate](https://github.com/ocombe/ng2-translate) diff --git a/ng2-components/ng2-activiti-form/karma.conf.js b/ng2-components/ng2-activiti-form/karma.conf.js index 45e88af408..40bb7d31ca 100644 --- a/ng2-components/ng2-activiti-form/karma.conf.js +++ b/ng2-components/ng2-activiti-form/karma.conf.js @@ -17,6 +17,7 @@ module.exports = function (config) { {pattern: 'node_modules/@angular/**/*.map', included: false, 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}, diff --git a/ng2-components/ng2-activiti-processlist/karma.conf.js b/ng2-components/ng2-activiti-processlist/karma.conf.js index 5cd8767851..f9a39b76a0 100644 --- a/ng2-components/ng2-activiti-processlist/karma.conf.js +++ b/ng2-components/ng2-activiti-processlist/karma.conf.js @@ -21,6 +21,7 @@ module.exports = function (config) { {pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.html', included: false, served: true, watched: false}, {pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.css', 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}, diff --git a/ng2-components/ng2-activiti-tasklist/README.md b/ng2-components/ng2-activiti-tasklist/README.md index a0b8b66006..e6a5be262c 100644 --- a/ng2-components/ng2-activiti-tasklist/README.md +++ b/ng2-components/ng2-activiti-tasklist/README.md @@ -13,6 +13,12 @@ npm install --save ng2-activiti-tasklist ### Dependencies +Add the following dependency to your index.html: + +```html + +``` + You must separately install the following libraries for your application: - [ng2-translate](https://github.com/ocombe/ng2-translate) diff --git a/ng2-components/ng2-activiti-tasklist/demo/package.json b/ng2-components/ng2-activiti-tasklist/demo/package.json index 1936ffdd55..8b0a30c592 100644 --- a/ng2-components/ng2-activiti-tasklist/demo/package.json +++ b/ng2-components/ng2-activiti-tasklist/demo/package.json @@ -3,12 +3,6 @@ "description": "Alfresco Angular2 DataTable Component - Demo", "version": "0.1.0", "author": "Alfresco Software, Ltd.", - "contributors": [ - { - "name": "Maurizio Vitale", - "email": "maurizio.vitale84@gmail.com" - } - ], "main": "index.js", "scripts": { "clean": "rimraf dist node_modules typings", @@ -70,6 +64,16 @@ "!/**/typings/**/*", "!*.js" ], + "contributors": [ + { + "name": "Maurizio Vitale", + "email": "maurizio.vitale84@gmail.com" + }, + { + "name": "Eugenio Romano", + "email": "eugenio.romano@alfresco.com" + } + ], "path": "assets/license_header.txt", "blocking": true, "logInfo": false, diff --git a/ng2-components/ng2-activiti-tasklist/package.json b/ng2-components/ng2-activiti-tasklist/package.json index f2cdee6194..3142f4368a 100644 --- a/ng2-components/ng2-activiti-tasklist/package.json +++ b/ng2-components/ng2-activiti-tasklist/package.json @@ -38,6 +38,10 @@ { "name": "Maurizio Vitale", "email": "maurizio.vitale84@gmail.com" + }, + { + "name": "Eugenio Romano", + "email": "eugenio.romano@alfresco.com" } ], "keywords": [ diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts index bc48397fc9..d1663d2596 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.spec.ts @@ -48,7 +48,7 @@ describe('ActivitiFilters', () => { }); beforeEach(() => { - let activitiService = new ActivitiTaskListService(null, null, null); + let activitiService = new ActivitiTaskListService(null); filterList = new ActivitiFilters(null, null, activitiService); }); diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts index cc63fed507..bc43a1adfd 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-filters.component.ts @@ -62,6 +62,7 @@ export class ActivitiFilters implements OnInit { * Constructor * @param auth * @param translate + * @param activiti */ constructor(private auth: AlfrescoAuthenticationService, private translate: AlfrescoTranslationService, diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.spec.ts index 34d2b3a9aa..b8374faf83 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.spec.ts @@ -64,7 +64,7 @@ describe('ActivitiTaskList', () => { }); beforeEach(() => { - let activitiSerevice = new ActivitiTaskListService(null, null, null); + let activitiSerevice = new ActivitiTaskListService(null); taskList = new ActivitiTaskList(null, null, activitiSerevice); }); diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts index af6f5243a1..848c215aa3 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-tasklist.component.ts @@ -66,6 +66,7 @@ export class ActivitiTaskList implements OnInit { * Constructor * @param auth * @param translate + * @param translate */ constructor(private auth: AlfrescoAuthenticationService, private translate: AlfrescoTranslationService, diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts index 92ad494a08..a9fa61b30e 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; -import { ActivitiTaskListService } from './activiti-tasklist.service'; -import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; -import { HTTP_PROVIDERS } from '@angular/http'; -import { TaskDetailsModel } from '../models/task-details.model'; -import { Comment } from '../models/comment.model'; +import {it, describe, inject, beforeEach, beforeEachProviders} from '@angular/core/testing'; +import {ActivitiTaskListService} from './activiti-tasklist.service'; +import {AlfrescoSettingsService, AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import {TaskDetailsModel} from '../models/task-details.model'; +import {Comment} from '../models/comment.model'; declare let AlfrescoApi: any; declare let jasmine: any; @@ -44,10 +43,10 @@ describe('ActivitiTaskListService', () => { let fakeFilter = { page: 2, filterId: 2, appDefinitionId: null, - filter: {sort: 'created-desc', name: '', state: 'open', assignment: 'fake-assignee' } + filter: {sort: 'created-desc', name: '', state: 'open', assignment: 'fake-assignee'} }; - let fakeUser = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' }; + let fakeUser = {id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName'}; let fakeTaskList = { size: 1, total: 1, start: 0, @@ -64,7 +63,7 @@ describe('ActivitiTaskListService', () => { error: 'wrong request' }; - let fakeTaskDetails = {id: '999', name: 'fake-task-name', formKey: '99', assignee: fakeUser }; + let fakeTaskDetails = {id: '999', name: 'fake-task-name', formKey: '99', assignee: fakeUser}; let fakeTasksComment = { size: 2, total: 2, start: 0, @@ -96,16 +95,16 @@ describe('ActivitiTaskListService', () => { beforeEachProviders(() => { return [ - HTTP_PROVIDERS, + ActivitiTaskListService, AlfrescoSettingsService, - AlfrescoAuthenticationService, - ActivitiTaskListService + AlfrescoAuthenticationService ]; }); - beforeEach( inject([ActivitiTaskListService], (activitiService: ActivitiTaskListService) => { + + beforeEach(inject([ActivitiTaskListService], (activitiTaskListService: ActivitiTaskListService) => { jasmine.Ajax.install(); - service = activitiService; + service = activitiTaskListService; })); afterEach(() => { @@ -132,7 +131,7 @@ describe('ActivitiTaskListService', () => { it('should return the task list filtered', (done) => { service.getTasks(fakeFilter).subscribe( - res => { + res => { expect(res).toBeDefined(); expect(res.size).toEqual(1); expect(res.total).toEqual(1); @@ -235,7 +234,11 @@ describe('ActivitiTaskListService', () => { it('should add a task ', (done) => { let taskFake = new TaskDetailsModel({ - id: '', name: 'FakeNameTask', description: null, category: null, + id: 123, + parentTaskId: 456, + name: 'FakeNameTask', + description: null, + category: null, assignee: fakeUser, created: '' }); @@ -306,5 +309,4 @@ describe('ActivitiTaskListService', () => { }); */ - }); diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts index 95852eb6b1..b8405cb3fb 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts @@ -15,24 +15,19 @@ * limitations under the License. */ -import { Injectable } from '@angular/core'; -import { AlfrescoSettingsService } from 'ng2-alfresco-core'; -import { Http, Headers, RequestOptions, Response } from '@angular/http'; -import { Observable } from 'rxjs/Rx'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; -import { FilterModel } from '../models/filter.model'; -import { FilterParamsModel } from '../models/filter.model'; -import { Comment } from '../models/comment.model'; -import { User } from '../models/user.model'; - -import { TaskDetailsModel } from '../models/task-details.model'; +import {Injectable} from '@angular/core'; +import {AlfrescoAuthenticationService} from 'ng2-alfresco-core'; +import {Observable} from 'rxjs/Rx'; +import {FilterModel} from '../models/filter.model'; +import {FilterParamsModel} from '../models/filter.model'; +import {Comment} from '../models/comment.model'; +import {User} from '../models/user.model'; +import {TaskDetailsModel} from '../models/task-details.model'; @Injectable() export class ActivitiTaskListService { - constructor(private http: Http, - public alfrescoSettingsService: AlfrescoSettingsService, - private authService: AlfrescoAuthenticationService) { + constructor(public authService: AlfrescoAuthenticationService) { } @@ -41,12 +36,9 @@ export class ActivitiTaskListService { * @returns {Observable} */ getDeployedApplications(name: string): Observable { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/runtime-app-definitions`; - return this.http - .get(url, this.getRequestOptions()) - .map((response: Response) => response.json().data.find(p => p.name === name)) - .do(data => console.log('Application: ' + JSON.stringify(data))) - .catch(this.handleError); + return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.appsApi.getAppDefinitions()) + .map((response: any) => response.data.find(p => p.name === name)) + .do(data => console.log('Application: ' + JSON.stringify(data))); } /** @@ -55,7 +47,6 @@ export class ActivitiTaskListService { */ getTaskListFilters(appId?: string): Observable { return Observable.fromPromise(this.callApiTaskFilters(appId)) - .map(res => res.json()) .map((response: any) => { let filters: FilterModel[] = []; response.data.forEach((filter) => { @@ -64,8 +55,7 @@ export class ActivitiTaskListService { filters.push(filterModel); }); return filters; - }) - .catch(this.handleError); + }); } /** @@ -74,12 +64,10 @@ export class ActivitiTaskListService { * @returns {any} */ getTasks(filter: FilterModel): Observable { - return Observable.fromPromise(this.callApiTasksFiltered(filter.filter)) - .map((res: Response) => { - return res.json(); - }) - .catch(this.handleError); + .map((res: any) => { + return res; + }); } /** @@ -89,11 +77,10 @@ export class ActivitiTaskListService { */ getTaskDetails(id: string): Observable { return Observable.fromPromise(this.callApiTaskDetails(id)) - .map(res => res.json()) + .map(res => res) .map((details: any) => { return new TaskDetailsModel(details); - }) - .catch(this.handleError); + }); } /** @@ -103,7 +90,7 @@ export class ActivitiTaskListService { */ getTaskComments(id: string): Observable { return Observable.fromPromise(this.callApiTaskComments(id)) - .map(res => res.json()) + .map(res => res) .map((response: any) => { let comments: Comment[] = []; response.data.forEach((comment) => { @@ -112,8 +99,7 @@ export class ActivitiTaskListService { comments.push(new Comment(comment.id, comment.message, comment.created, user)); }); return comments; - }) - .catch(this.handleError); + }); } /** @@ -123,15 +109,14 @@ export class ActivitiTaskListService { */ getTaskChecklist(id: string): Observable { return Observable.fromPromise(this.callApiTaskChecklist(id)) - .map(res => res.json()) + .map(res => res) .map((response: any) => { let checklists: TaskDetailsModel[] = []; response.data.forEach((checklist) => { checklists.push(new TaskDetailsModel(checklist)); }); return checklists; - }) - .catch(this.handleError); + }); } /** @@ -141,11 +126,10 @@ export class ActivitiTaskListService { */ addTask(task: TaskDetailsModel): Observable { return Observable.fromPromise(this.callApiAddTask(task)) - .map(res => res.json()) + .map(res => res) .map((response: TaskDetailsModel) => { return new TaskDetailsModel(response); - }) - .catch(this.handleError); + }); } /** @@ -156,11 +140,10 @@ export class ActivitiTaskListService { */ addTaskComment(id: string, message: string): Observable { return Observable.fromPromise(this.callApiAddTaskComment(id, message)) - .map(res => res.json()) + .map(res => res) .map((response: Comment) => { return new Comment(response.id, response.message, response.created, response.createdBy); - }) - .catch(this.handleError); + }); } /** @@ -168,97 +151,45 @@ export class ActivitiTaskListService { * @param id - taskId * @returns {TaskDetailsModel} */ - completeTask(id: string): Observable { + completeTask(id: string) { return Observable.fromPromise(this.callApiCompleteTask(id)) - .map(res => res.json()) - .catch(this.handleError); + .map(res => res); } private callApiTasksFiltered(filter: FilterParamsModel) { - let data = JSON.stringify(filter); - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/query`; - - return this.http - .post(url, data, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.listTasks(filter); } private callApiTaskFilters(appId?: string) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl(); if (appId) { - url = url + `/api/enterprise/filters/tasks?appId=${appId}`; + return this.authService.getAlfrescoApi().activiti.taskApi.filterTasks({appDefinitionId: appId}); } else { - url = url + `/api/enterprise/filters/tasks`; + return this.authService.getAlfrescoApi().activiti.taskApi.filterTasks({}); } - - return this.http - .get(url, this.getRequestOptions()).toPromise(); } private callApiTaskDetails(id: string) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${id}`; - - return this.http - .get(url, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.getTask(id); } private callApiTaskComments(id: string) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${id}/comments`; - - return this.http - .get(url, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.getTaskComments(id); } private callApiAddTaskComment(id: string, message: string) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${id}/comments`; - let body = JSON.stringify({message: message}); - - return this.http - .post(url, body, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.addTaskComment({message: message}, id); } private callApiAddTask(task: TaskDetailsModel) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${task.parentTaskId}/checklist`; - let body = JSON.stringify(task); - - return this.http - .post(url, body, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.addSubtask(task.parentTaskId, task); } private callApiTaskChecklist(id: string) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${id}/checklist`; - - return this.http - .get(url, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.getChecklist(id); } private callApiCompleteTask(id: string) { - let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${id}/action/complete`; - - return this.http - .put(url, this.getRequestOptions()).toPromise(); + return this.authService.getAlfrescoApi().activiti.taskApi.completeTask(id); } - - /** - * The method write the error in the console browser - * @param error - * @returns {ErrorObservable} - */ - public handleError(error: Response): Observable { - console.error('Error when logging in', error); - return Observable.throw(error || 'Server error'); - } - - private getHeaders(): Headers { - return new Headers({ - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': this.authService.getTicket('BPM') - }); - } - - private getRequestOptions(): RequestOptions { - let headers = this.getHeaders(); - return new RequestOptions({headers: headers}); - } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts index 54df384d1d..0e58aa5b4b 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoSettings.service.ts @@ -30,7 +30,7 @@ export class AlfrescoSettingsService { private _bpmContextPath = AlfrescoSettingsService.DEFAULT_BPM_CONTEXT_PATH; - private providers: string = 'ECM'; // ECM, BPM , ALL + private providers: string = 'ALL'; // ECM, BPM , ALL public get ecmHost(): string { return this._ecmHost; diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index 91b7b35abe..34762123d2 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -16,11 +16,10 @@ */ import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; +import { EventEmitter } from '@angular/core'; import { UploadService } from './upload.service'; import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock'; -import { HTTP_PROVIDERS } from '@angular/http'; -import { EventEmitter } from '@angular/core'; declare let AlfrescoApi: any; declare let jasmine: any; @@ -40,9 +39,8 @@ describe('AlfrescoUploadService', () => { beforeEachProviders(() => { return [ - HTTP_PROVIDERS, { provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock }, - { provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService }, + AlfrescoAuthenticationService, UploadService ]; }); diff --git a/ng2-components/ng2-alfresco-webscript/README.md b/ng2-components/ng2-alfresco-webscript/README.md index b5285e2e89..398491efaa 100644 --- a/ng2-components/ng2-alfresco-webscript/README.md +++ b/ng2-components/ng2-alfresco-webscript/README.md @@ -56,7 +56,7 @@ The following component needs to be added to your systemjs.config: - ng2-translate - ng2-alfresco-core -- ng2-alfresco-datatable +- ng2-alfresco-dataƓtable Please refer to the following example to have an idea of how your systemjs.config should look like :