#440 simple task and form api

This commit is contained in:
Denys Vuika
2016-07-18 17:00:48 +01:00
parent b1769746d5
commit f4f80a1c0d
3 changed files with 110 additions and 3 deletions
@@ -0,0 +1,9 @@
<div style="padding: 10px">
<h2>Task form content</h2>
<h3>Task</h3>
<pre>{{debugTask | json}}</pre>
<h3>Form</h3>
<pre>{{debugForm | json}}</pre>
</div>
@@ -15,15 +15,38 @@
* limitations under the License.
*/
import { Component } from '@angular/core';
import { Component, OnInit, Injectable } from '@angular/core';
import { FormService } from './../services/form.service';
declare let __moduleName: string;
@Component({
moduleId: __moduleName,
selector: 'activiti-form',
template: '<h3>Activiti Form Content</h3>'
templateUrl: './activiti-form.component.html',
providers: [
FormService
]
})
export class ActivitiForm {
export class ActivitiForm implements OnInit {
debugTask: any;
debugForm: any;
constructor(private formService: FormService) {
}
ngOnInit() {
this.formService.getTask('1').subscribe(task => {
console.log(task);
this.debugTask = task;
this.formService.getTaskForm('1').subscribe(form => {
console.log(form);
this.debugForm = form;
})
});
}
}
@@ -0,0 +1,75 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { Response, Http, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class FormService {
private basePath: string = 'http://localhost:9999/activiti-app';
constructor(private http: Http) {
}
getTask(id: string): Observable<any> {
let url = `${this.basePath}/api/enterprise/tasks/${id}`;
let options = this.getRequestOptions();
return this.http.get(url, options)
.map(this.toJson)
.catch(this.handleError);
}
getTaskForm(id: string): Observable<any> {
let url = `${this.basePath}/api/enterprise/task-forms/${id}`;
let options = this.getRequestOptions();
return this.http.get(url, options)
.map(this.toJson)
.catch(this.handleError);
}
private getHeaders(): Headers {
return new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('admin' + ':' + 'admin')
});
}
private getRequestOptions(): RequestOptions {
let headers = this.getHeaders();
return new RequestOptions({ headers: headers });
}
private toJson(res: Response) {
let body = res.json();
return body || {};
}
private handleError (error: any) {
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
}