tasklist modify step 1

This commit is contained in:
Eugenio Romano
2016-08-17 16:50:23 +01:00
parent 077df4b87f
commit 9c5d62f5d1
15 changed files with 92 additions and 137 deletions

View File

@@ -13,6 +13,12 @@ npm install --save ng2-activiti-form
### Dependencies
Add the following dependency to your index.html:
```html
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
```
You must separately install the following libraries for your application:
- [ng2-translate](https://github.com/ocombe/ng2-translate)

View File

@@ -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},

View File

@@ -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},

View File

@@ -13,6 +13,12 @@ npm install --save ng2-activiti-tasklist
### Dependencies
Add the following dependency to your index.html:
```html
<script src="node_modules/alfresco-js-api/dist/alfresco-js-api.js"></script>
```
You must separately install the following libraries for your application:
- [ng2-translate](https://github.com/ocombe/ng2-translate)

View File

@@ -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,

View File

@@ -38,6 +38,10 @@
{
"name": "Maurizio Vitale",
"email": "maurizio.vitale84@gmail.com"
},
{
"name": "Eugenio Romano",
"email": "eugenio.romano@alfresco.com"
}
],
"keywords": [

View File

@@ -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);
});

View File

@@ -62,6 +62,7 @@ export class ActivitiFilters implements OnInit {
* Constructor
* @param auth
* @param translate
* @param activiti
*/
constructor(private auth: AlfrescoAuthenticationService,
private translate: AlfrescoTranslationService,

View File

@@ -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);
});

View File

@@ -66,6 +66,7 @@ export class ActivitiTaskList implements OnInit {
* Constructor
* @param auth
* @param translate
* @param translate
*/
constructor(private auth: AlfrescoAuthenticationService,
private translate: AlfrescoTranslationService,

View File

@@ -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', () => {
});
*/
});

View File

@@ -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<any>}
*/
getDeployedApplications(name: string): Observable<any> {
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<any> {
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<any> {
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<TaskDetailsModel> {
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<Comment[]> {
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<TaskDetailsModel[]> {
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<TaskDetailsModel> {
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<Comment> {
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<TaskDetailsModel> {
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<any> {
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});
}
}

View File

@@ -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;

View File

@@ -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
];
});

View File

@@ -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 :