mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
move form to activity js api
This commit is contained in:
parent
0110f486b6
commit
06c05ea9b5
@ -26,7 +26,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -80,6 +80,7 @@
|
|||||||
"karma-coverage": "1.0.0",
|
"karma-coverage": "1.0.0",
|
||||||
"karma-coveralls": "1.1.2",
|
"karma-coveralls": "1.1.2",
|
||||||
"karma-jasmine": "1.0.2",
|
"karma-jasmine": "1.0.2",
|
||||||
|
"karma-jasmine-ajax": "0.1.13",
|
||||||
"karma-jasmine-html-reporter": "0.2.0",
|
"karma-jasmine-html-reporter": "0.2.0",
|
||||||
"karma-jasmine-ajax": "0.1.13",
|
"karma-jasmine-ajax": "0.1.13",
|
||||||
"karma-mocha-reporter": "2.0.3",
|
"karma-mocha-reporter": "2.0.3",
|
||||||
|
@ -15,81 +15,57 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { it, describe, expect, beforeEach } from '@angular/core/testing';
|
import { it, inject, describe, expect, beforeEach, beforeEachProviders, afterEach } from '@angular/core/testing';
|
||||||
import { Http, RequestOptionsArgs, Response, ResponseOptions } from '@angular/http';
|
|
||||||
import { Observable } from 'rxjs/Rx';
|
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
|
import { Response, ResponseOptions } from '@angular/http';
|
||||||
import { FormService } from './form.service';
|
import { FormService } from './form.service';
|
||||||
import { FormValues } from './../components/widgets/core/index';
|
import { FormValues } from './../components/widgets/core/index';
|
||||||
|
|
||||||
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('FormService', () => {
|
describe('FormService', () => {
|
||||||
|
|
||||||
let http: Http;
|
let responseBody: any, formService: FormService;
|
||||||
let responseBody: any;
|
|
||||||
let formService: FormService;
|
|
||||||
let authService: AlfrescoAuthenticationService;
|
|
||||||
let settingsService: AlfrescoSettingsService;
|
|
||||||
|
|
||||||
let createResponse = (url, body): Observable<Response> => {
|
beforeEachProviders(() => {
|
||||||
return Observable.create(observer => {
|
return [
|
||||||
let response = new Response(new ResponseOptions({
|
FormService,
|
||||||
url: url,
|
AlfrescoSettingsService,
|
||||||
body: body
|
AlfrescoAuthenticationService
|
||||||
}));
|
];
|
||||||
observer.next(response);
|
|
||||||
observer.complete();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
|
|
||||||
http = <Http> {
|
|
||||||
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
|
|
||||||
return createResponse(url, responseBody);
|
|
||||||
},
|
|
||||||
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
|
||||||
return createResponse(url, responseBody);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
settingsService = new AlfrescoSettingsService();
|
|
||||||
settingsService.setProviders([]);
|
|
||||||
|
|
||||||
authService = new AlfrescoAuthenticationService(settingsService, null);
|
|
||||||
formService = new FormService(http, authService, settingsService);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve host address via settings service', () => {
|
beforeEach(inject([FormService], (service: FormService) => {
|
||||||
const url = '<url>';
|
jasmine.Ajax.install();
|
||||||
settingsService.bpmHost = url;
|
formService = service;
|
||||||
expect(formService.getHostAddress()).toBe(url);
|
}));
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse process definitions', (done) => {
|
it('should fetch and parse process definitions', (done) => {
|
||||||
spyOn(http, 'get').and.callThrough();
|
|
||||||
|
|
||||||
responseBody = {
|
responseBody = {
|
||||||
data: [
|
data: [
|
||||||
{ id: '1' },
|
{id: '1'},
|
||||||
{ id: '2' }
|
{id: '2'}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
formService.getProcessDefinitions().subscribe(result => {
|
formService.getProcessDefinitions().subscribe(result => {
|
||||||
expect(http.get).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/process-definitions')).toBeTruthy();
|
||||||
|
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||||
let args: any[] = (<any>http).get.calls.argsFor(0);
|
|
||||||
expect(args[0].endsWith('/process-definitions')).toBeTruthy();
|
|
||||||
|
|
||||||
expect(result).toEqual(responseBody.data);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse tasks', (done) => {
|
it('should fetch and parse tasks', (done) => {
|
||||||
spyOn(http, 'post').and.callThrough();
|
|
||||||
|
|
||||||
responseBody = {
|
responseBody = {
|
||||||
data: [
|
data: [
|
||||||
{ id: '1' },
|
{ id: '1' },
|
||||||
@ -98,126 +74,130 @@ describe('FormService', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
formService.getTasks().subscribe(result => {
|
formService.getTasks().subscribe(result => {
|
||||||
expect(http.post).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/query')).toBeTruthy();
|
||||||
|
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||||
let args: any[] = (<any>http).post.calls.argsFor(0);
|
|
||||||
expect(args[0].endsWith('/tasks/query')).toBeTruthy();
|
|
||||||
|
|
||||||
expect(result).toEqual(responseBody.data);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse the task by id', (done) => {
|
it('should fetch and parse the task by id', (done) => {
|
||||||
spyOn(http, 'get').and.callThrough();
|
|
||||||
|
|
||||||
responseBody = {
|
responseBody = {
|
||||||
id: '1'
|
id: '1'
|
||||||
};
|
};
|
||||||
|
|
||||||
formService.getTask('1').subscribe(result => {
|
formService.getTask('1').subscribe(result => {
|
||||||
expect(http.get).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/1')).toBeTruthy();
|
||||||
|
expect(result.id).toEqual(responseBody.id);
|
||||||
let args: any[] = (<any>http).get.calls.argsFor(0);
|
|
||||||
expect(args[0].endsWith('/tasks/1')).toBeTruthy();
|
|
||||||
|
|
||||||
expect(result).toEqual(responseBody);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should save task form', (done) => {
|
it('should save task form', (done) => {
|
||||||
spyOn(http, 'post').and.callThrough();
|
|
||||||
|
|
||||||
let values = <FormValues> {
|
let values = <FormValues> {
|
||||||
field1: 'one',
|
field1: 'one',
|
||||||
field2: 'two'
|
field2: 'two'
|
||||||
};
|
};
|
||||||
|
|
||||||
formService.saveTaskForm('1', values).subscribe(() => {
|
formService.saveTaskForm('1', values).subscribe(() => {
|
||||||
expect(http.post).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1/save-form')).toBeTruthy();
|
||||||
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field1).toEqual(values.field1);
|
||||||
let args: any[] = (<any>http).post.calls.argsFor(0);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field2).toEqual(values.field2);
|
||||||
expect(args[0].endsWith('/task-forms/1/save-form')).toBeTruthy();
|
|
||||||
expect(args[1]).toEqual(JSON.stringify({ values: values }));
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should complete task form', (done) => {
|
it('should complete task form', (done) => {
|
||||||
spyOn(http, 'post').and.callThrough();
|
|
||||||
|
|
||||||
let values = <FormValues> {
|
let values = <FormValues> {
|
||||||
field1: 'one',
|
field1: 'one',
|
||||||
field2: 'two'
|
field2: 'two'
|
||||||
};
|
};
|
||||||
|
|
||||||
formService.completeTaskForm('1', values).subscribe(() => {
|
formService.completeTaskForm('1', values).subscribe(() => {
|
||||||
expect(http.post).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
||||||
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field1).toEqual(values.field1);
|
||||||
let args: any[] = (<any>http).post.calls.argsFor(0);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field2).toEqual(values.field2);
|
||||||
expect(args[0].endsWith('/task-forms/1')).toBeTruthy();
|
|
||||||
expect(args[1]).toEqual(JSON.stringify({ values: values }));
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should complete task form with a specific outcome', (done) => {
|
it('should complete task form with a specific outcome', (done) => {
|
||||||
spyOn(http, 'post').and.callThrough();
|
|
||||||
|
|
||||||
let values = <FormValues> {
|
let values = <FormValues> {
|
||||||
field1: 'one',
|
field1: 'one',
|
||||||
field2: 'two'
|
field2: 'two'
|
||||||
};
|
};
|
||||||
|
|
||||||
formService.completeTaskForm('1', values, 'custom').subscribe(() => {
|
formService.completeTaskForm('1', values, 'custom').subscribe(() => {
|
||||||
expect(http.post).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
||||||
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).values.field2).toEqual(values.field2);
|
||||||
let args: any[] = (<any>http).post.calls.argsFor(0);
|
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).outcome).toEqual('custom' );
|
||||||
expect(args[0].endsWith('/task-forms/1')).toBeTruthy();
|
|
||||||
expect(args[1]).toEqual(JSON.stringify({ values: values, outcome: 'custom' }));
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get task form by id', (done) => {
|
it('should get task form by id', (done) => {
|
||||||
spyOn(http, 'get').and.callThrough();
|
responseBody = { id: 1 };
|
||||||
|
|
||||||
responseBody = { id: '1' };
|
|
||||||
|
|
||||||
formService.getTaskForm('1').subscribe(result => {
|
formService.getTaskForm('1').subscribe(result => {
|
||||||
expect(http.get).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/task-forms/1')).toBeTruthy();
|
||||||
|
expect(result.id).toEqual(responseBody.id);
|
||||||
let args: any[] = (<any>http).get.calls.argsFor(0);
|
|
||||||
expect(args[0].endsWith('/task-forms/1')).toBeTruthy();
|
|
||||||
|
|
||||||
expect(result).toEqual(responseBody);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get form definition by id', (done) => {
|
it('should get form definition by id', (done) => {
|
||||||
spyOn(http, 'get').and.callThrough();
|
responseBody = { id: 1 };
|
||||||
|
|
||||||
responseBody = { id: '1' };
|
|
||||||
|
|
||||||
formService.getFormDefinitionById('1').subscribe(result => {
|
formService.getFormDefinitionById('1').subscribe(result => {
|
||||||
expect(http.get).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/form-models/1')).toBeTruthy();
|
||||||
|
expect(result.id).toEqual(responseBody.id);
|
||||||
let args: any[] = (<any>http).get.calls.argsFor(0);
|
|
||||||
expect(args[0].endsWith('/form-models/1')).toBeTruthy();
|
|
||||||
|
|
||||||
expect(result).toEqual(responseBody);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get form definition id by name', (done) => {
|
it('should get form definition id by name', (done) => {
|
||||||
spyOn(http, 'get').and.callThrough();
|
|
||||||
|
|
||||||
const formName = 'form1';
|
const formName = 'form1';
|
||||||
const formId = 1;
|
const formId = 1;
|
||||||
responseBody = {
|
responseBody = {
|
||||||
@ -227,14 +207,16 @@ describe('FormService', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
formService.getFormDefinitionByName(formName).subscribe(result => {
|
formService.getFormDefinitionByName(formName).subscribe(result => {
|
||||||
expect(http.get).toHaveBeenCalled();
|
expect(jasmine.Ajax.requests.mostRecent().url.endsWith(`models?filter=myReusableForms&filterText=${formName}&modelType=2`)).toBeTruthy();
|
||||||
|
|
||||||
let args: any[] = (<any>http).get.calls.argsFor(0);
|
|
||||||
expect(args[0].endsWith(`models?filter=myReusableForms&filterText=${formName}&modelType=2`)).toBeTruthy();
|
|
||||||
|
|
||||||
expect(result).toEqual(formId);
|
expect(result).toEqual(formId);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
http://localhost:9999/activiti-app/api/enterprise/models?filter=myReusableForms&modelType=2"
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(responseBody)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not get form id from response', () => {
|
it('should not get form id from response', () => {
|
||||||
@ -253,30 +235,6 @@ describe('FormService', () => {
|
|||||||
expect(formService.getFormId(null)).toBeNull();
|
expect(formService.getFormId(null)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert response to json object', () => {
|
|
||||||
let data = { id: 1 };
|
|
||||||
let response = new Response(new ResponseOptions({ body: data }));
|
|
||||||
expect(formService.toJson(response)).toEqual(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fallback to empty json object', () => {
|
|
||||||
let response = new Response(new ResponseOptions({ body: null }));
|
|
||||||
expect(formService.toJson(response)).toEqual({});
|
|
||||||
|
|
||||||
expect(formService.toJson(null)).toEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should convert response to json array', () => {
|
|
||||||
let payload = {
|
|
||||||
data: [
|
|
||||||
{ id: 1 }
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let response = new Response(new ResponseOptions({ body: JSON.stringify(payload) }));
|
|
||||||
expect(formService.toJsonArray(response)).toEqual(payload.data);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fallback to empty json array', () => {
|
it('should fallback to empty json array', () => {
|
||||||
expect(formService.toJsonArray(null)).toEqual([]);
|
expect(formService.toJsonArray(null)).toEqual([]);
|
||||||
|
|
||||||
|
@ -15,12 +15,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import { Response, Http, Headers, RequestOptions } from '@angular/http';
|
import {Observable} from 'rxjs/Rx';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import {AlfrescoAuthenticationService} from 'ng2-alfresco-core';
|
||||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import {FormValues} from './../components/widgets/core/index';
|
||||||
import { FormValues } from './../components/widgets/core/index';
|
|
||||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormService {
|
export class FormService {
|
||||||
@ -28,92 +26,60 @@ export class FormService {
|
|||||||
static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error';
|
static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error';
|
||||||
static GENERIC_ERROR_MESSAGE: string = 'Server error';
|
static GENERIC_ERROR_MESSAGE: string = 'Server error';
|
||||||
|
|
||||||
constructor(private http: Http,
|
constructor(private authService: AlfrescoAuthenticationService) {
|
||||||
private authService: AlfrescoAuthenticationService,
|
|
||||||
private alfrescoSettingsService: AlfrescoSettingsService) {
|
|
||||||
}
|
|
||||||
|
|
||||||
getHostAddress(): string {
|
|
||||||
return this.alfrescoSettingsService.bpmHost;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getProcessDefinitions(): Observable<any> {
|
getProcessDefinitions(): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/api/enterprise/process-definitions`;
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.processApi.getProcessDefinitions({}))
|
||||||
let options = this.getRequestOptions();
|
|
||||||
return this.http
|
|
||||||
.get(url, options)
|
|
||||||
.map(this.toJsonArray)
|
.map(this.toJsonArray)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTasks(): Observable<any> {
|
getTasks(): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/api/enterprise/tasks/query`;
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.taskApi.listTasks({}))
|
||||||
let body = JSON.stringify({});
|
|
||||||
let options = this.getRequestOptions();
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.post(url, body, options)
|
|
||||||
.map(this.toJsonArray)
|
.map(this.toJsonArray)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTask(id: string): Observable<any> {
|
getTask(taskId: string): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/api/enterprise/tasks/${id}`;
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.taskApi.getTask(taskId))
|
||||||
let options = this.getRequestOptions();
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.get(url, options)
|
|
||||||
.map(this.toJson)
|
.map(this.toJson)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTaskForm(id: string, formValues: FormValues): Observable<Response> {
|
saveTaskForm(taskId: string, formValues: FormValues): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/api/enterprise/task-forms/${id}/save-form`;
|
let body = JSON.stringify({values: formValues});
|
||||||
let body = JSON.stringify({ values: formValues });
|
|
||||||
let options = this.getRequestOptions();
|
|
||||||
|
|
||||||
return this.http
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.taskApi.saveTaskForm(taskId, body))
|
||||||
.post(url, body, options)
|
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete Task Form
|
* Complete Task Form
|
||||||
* @param id Task Id
|
* @param taskId Task Id
|
||||||
* @param formValues Form Values
|
* @param formValues Form Values
|
||||||
* @param outcome Form Outcome
|
* @param outcome Form Outcome
|
||||||
* @returns {any}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
completeTaskForm(id: string, formValues: FormValues, outcome?: string): Observable<Response> {
|
completeTaskForm(taskId: string, formValues: FormValues, outcome?: string): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/api/enterprise/task-forms/${id}`;
|
let data: any = {values: formValues};
|
||||||
let data: any = { values: formValues };
|
|
||||||
if (outcome) {
|
if (outcome) {
|
||||||
data.outcome = outcome;
|
data.outcome = outcome;
|
||||||
}
|
}
|
||||||
let body = JSON.stringify(data);
|
let body = JSON.stringify(data);
|
||||||
let options = this.getRequestOptions();
|
|
||||||
|
|
||||||
return this.http
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.taskApi.completeTaskForm(taskId, body))
|
||||||
.post(url, body, options)
|
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTaskForm(id: string): Observable<any> {
|
getTaskForm(taskId: string): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/api/enterprise/task-forms/${id}`;
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.taskApi.getTaskForm(taskId))
|
||||||
let options = this.getRequestOptions();
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.get(url, options)
|
|
||||||
.map(this.toJson)
|
.map(this.toJson)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormDefinitionById(id: string): Observable<any> {
|
getFormDefinitionById(formId: string): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/app/rest/form-models/${id}`;
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.editorApi.getForm(formId))
|
||||||
let options = this.getRequestOptions();
|
|
||||||
|
|
||||||
return this.http
|
|
||||||
.get(url, options)
|
|
||||||
.map(this.toJson)
|
.map(this.toJson)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
@ -124,53 +90,37 @@ export class FormService {
|
|||||||
* @returns {Promise<T>|Promise<ErrorObservable>}
|
* @returns {Promise<T>|Promise<ErrorObservable>}
|
||||||
*/
|
*/
|
||||||
getFormDefinitionByName(name: string): Observable<any> {
|
getFormDefinitionByName(name: string): Observable<any> {
|
||||||
let url = `${this.getHostAddress()}/activiti-app/app/rest/models?filter=myReusableForms&filterText=${name}&modelType=2`;
|
let opts = {
|
||||||
let options = this.getRequestOptions();
|
'filter': 'myReusableForms',
|
||||||
|
'filterText': name,
|
||||||
|
'modelType': 2
|
||||||
|
};
|
||||||
|
|
||||||
return this.http
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.modelsApi.getModels(opts))
|
||||||
.get(url, options)
|
|
||||||
.map(this.getFormId)
|
.map(this.getFormId)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getHeaders(): Headers {
|
getFormId(res: any) {
|
||||||
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});
|
|
||||||
}
|
|
||||||
|
|
||||||
getFormId(res: Response) {
|
|
||||||
let result = null;
|
let result = null;
|
||||||
|
|
||||||
if (res) {
|
if (res && res.data && res.data.length > 0) {
|
||||||
let body = res.json();
|
result = res.data[0].id;
|
||||||
if (body && body.data && body.data.length > 0) {
|
|
||||||
result = body.data[0].id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(res: Response) {
|
toJson(res: any) {
|
||||||
if (res) {
|
if (res) {
|
||||||
let body = res.json();
|
return res || {};
|
||||||
return body || {};
|
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
toJsonArray(res: Response) {
|
toJsonArray(res: any) {
|
||||||
if (res) {
|
if (res) {
|
||||||
let body = res.json();
|
return res.data || [];
|
||||||
return body.data || [];
|
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -184,5 +134,4 @@ export class FormService {
|
|||||||
console.error(errMsg);
|
console.error(errMsg);
|
||||||
return Observable.throw(errMsg);
|
return Observable.throw(errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -101,7 +101,6 @@ describe('ActivitiTaskListService', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
beforeEach(inject([ActivitiTaskListService], (activitiTaskListService: ActivitiTaskListService) => {
|
beforeEach(inject([ActivitiTaskListService], (activitiTaskListService: ActivitiTaskListService) => {
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
service = activitiTaskListService;
|
service = activitiTaskListService;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -1,121 +1,121 @@
|
|||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"align": [
|
"align": [
|
||||||
true,
|
true,
|
||||||
"parameters",
|
"parameters",
|
||||||
"statements"
|
"statements"
|
||||||
],
|
],
|
||||||
"ban": false,
|
"ban": false,
|
||||||
"class-name": true,
|
"class-name": true,
|
||||||
"comment-format": [
|
"comment-format": [
|
||||||
true,
|
true,
|
||||||
"check-space"
|
"check-space"
|
||||||
],
|
],
|
||||||
"curly": true,
|
"curly": true,
|
||||||
"eofline": true,
|
"eofline": true,
|
||||||
"forin": true,
|
"forin": true,
|
||||||
"indent": [
|
"indent": [
|
||||||
true,
|
true,
|
||||||
"spaces"
|
"spaces"
|
||||||
],
|
],
|
||||||
"interface-name": false,
|
"interface-name": false,
|
||||||
"jsdoc-format": true,
|
"jsdoc-format": true,
|
||||||
"label-position": true,
|
"label-position": true,
|
||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
"static-before-instance",
|
"static-before-instance",
|
||||||
"variables-before-functions"
|
"variables-before-functions"
|
||||||
],
|
],
|
||||||
"no-any": false,
|
"no-any": false,
|
||||||
"no-arg": true,
|
"no-arg": true,
|
||||||
"no-bitwise": false,
|
"no-bitwise": false,
|
||||||
"no-conditional-assignment": true,
|
"no-conditional-assignment": true,
|
||||||
"no-consecutive-blank-lines": false,
|
"no-consecutive-blank-lines": false,
|
||||||
"no-console": [
|
"no-console": [
|
||||||
true,
|
true,
|
||||||
"debug",
|
"debug",
|
||||||
"info",
|
"info",
|
||||||
"time",
|
"time",
|
||||||
"timeEnd",
|
"timeEnd",
|
||||||
"trace"
|
"trace"
|
||||||
],
|
],
|
||||||
"no-construct": true,
|
"no-construct": true,
|
||||||
"no-constructor-vars": false,
|
"no-constructor-vars": false,
|
||||||
"no-debugger": true,
|
"no-debugger": true,
|
||||||
"no-duplicate-key": true,
|
"no-duplicate-key": true,
|
||||||
"no-duplicate-variable": true,
|
"no-duplicate-variable": true,
|
||||||
"no-empty": false,
|
"no-empty": false,
|
||||||
"no-eval": true,
|
"no-eval": true,
|
||||||
"no-inferrable-types": false,
|
"no-inferrable-types": false,
|
||||||
"no-internal-module": true,
|
"no-internal-module": true,
|
||||||
"no-require-imports": true,
|
"no-require-imports": true,
|
||||||
"no-shadowed-variable": true,
|
"no-shadowed-variable": true,
|
||||||
"no-switch-case-fall-through": true,
|
"no-switch-case-fall-through": true,
|
||||||
"no-trailing-whitespace": true,
|
"no-trailing-whitespace": true,
|
||||||
"no-unreachable": true,
|
"no-unreachable": true,
|
||||||
"no-unused-expression": true,
|
"no-unused-expression": true,
|
||||||
"no-unused-variable": true,
|
"no-unused-variable": true,
|
||||||
"no-use-before-declare": true,
|
"no-use-before-declare": true,
|
||||||
"no-var-keyword": true,
|
"no-var-keyword": true,
|
||||||
"no-var-requires": true,
|
"no-var-requires": true,
|
||||||
"object-literal-sort-keys": false,
|
"object-literal-sort-keys": false,
|
||||||
"one-line": [
|
"one-line": [
|
||||||
true,
|
true,
|
||||||
"check-open-brace",
|
"check-open-brace",
|
||||||
"check-catch",
|
"check-catch",
|
||||||
"check-else",
|
"check-else",
|
||||||
"check-whitespace"
|
"check-whitespace"
|
||||||
],
|
],
|
||||||
"quotemark": [
|
"quotemark": [
|
||||||
true,
|
true,
|
||||||
"single",
|
"single",
|
||||||
"avoid-escape"
|
"avoid-escape"
|
||||||
],
|
],
|
||||||
"radix": true,
|
"radix": true,
|
||||||
"semicolon": true,
|
"semicolon": true,
|
||||||
"switch-default": true,
|
"switch-default": true,
|
||||||
"trailing-comma": [
|
"trailing-comma": [
|
||||||
true,
|
true,
|
||||||
{
|
{
|
||||||
"multiline": "never",
|
"multiline": "never",
|
||||||
"singleline": "never"
|
"singleline": "never"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"triple-equals": [
|
"triple-equals": [
|
||||||
true,
|
true,
|
||||||
"allow-null-check"
|
"allow-null-check"
|
||||||
],
|
],
|
||||||
"typedef": false,
|
"typedef": false,
|
||||||
"typedef-whitespace": [
|
"typedef-whitespace": [
|
||||||
true,
|
true,
|
||||||
{
|
{
|
||||||
"call-signature": "nospace",
|
"call-signature": "nospace",
|
||||||
"index-signature": "nospace",
|
"index-signature": "nospace",
|
||||||
"parameter": "nospace",
|
"parameter": "nospace",
|
||||||
"property-declaration": "nospace",
|
"property-declaration": "nospace",
|
||||||
"variable-declaration": "nospace"
|
"variable-declaration": "nospace"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"use-strict": false,
|
"use-strict": false,
|
||||||
"variable-name": [
|
"variable-name": [
|
||||||
true,
|
true,
|
||||||
"check-format",
|
"check-format",
|
||||||
"allow-leading-underscore",
|
"allow-leading-underscore",
|
||||||
"ban-keywords"
|
"ban-keywords"
|
||||||
],
|
],
|
||||||
"whitespace": [
|
"whitespace": [
|
||||||
true,
|
true,
|
||||||
"check-branch",
|
"check-branch",
|
||||||
"check-operator",
|
"check-operator",
|
||||||
"check-separator",
|
"check-separator",
|
||||||
"check-type",
|
"check-type",
|
||||||
"check-module",
|
"check-module",
|
||||||
"check-decl"
|
"check-decl"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"label-undefined": true,
|
"label-undefined": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
180
|
||||||
],
|
],
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user