diff --git a/demo-shell-ng2/app/components/tasks/activiti.service.ts b/demo-shell-ng2/app/components/tasks/activiti.service.ts new file mode 100644 index 0000000000..5df24b1323 --- /dev/null +++ b/demo-shell-ng2/app/components/tasks/activiti.service.ts @@ -0,0 +1,84 @@ +/*! + * @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 'angular2/core'; +import { Http, Headers, RequestOptions, Response } from 'angular2/http'; + +@Injectable() +export class ActivitiService { + + constructor(private http: Http) {} + + login(username: string, password: string) { + let url = 'http://localhost:9999/activiti-app/app/authentication'; + let headers = new Headers({ + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cache-Control': 'no-cache' + }); + let options = new RequestOptions({ headers: headers }); + let data = 'j_username=' + + encodeURIComponent(username) + + '&j_password=' + + encodeURIComponent(password) + + '&_spring_security_remember_me=true&submit=Login'; + + return this.http + .post(url, data, options) + .toPromise() + // .then(res => console.log(res)) + .catch(this.handleError); + } + + getTasks() { + // emulate filter value + let data = JSON.stringify({ + 'page': 0, + 'filterId': 3, + 'filter': { + 'sort': 'created-desc', + 'name': '', + 'state': 'open', + 'assignment': 'involved' + }, + 'appDefinitionId': null + }); + + let url = 'http://localhost:9999/activiti-app/app/rest/filter/tasks'; + let headers = new Headers({ + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache' + }); + let options = new RequestOptions({ headers: headers }); + + return this.http + .post(url, data, options) + .toPromise() + .then(this.parseJSON) + .catch(this.handleError); + } + + private parseJSON(res: Response) { + let body = res.json(); + return body.data || { }; + } + + private handleError(error: any) { + console.error('An error occurred', error); + return Promise.reject(error.message || error); + } + +} diff --git a/demo-shell-ng2/app/components/tasks/tasks-demo.component.ts b/demo-shell-ng2/app/components/tasks/tasks-demo.component.ts index 6ea70b9a16..f251a71656 100644 --- a/demo-shell-ng2/app/components/tasks/tasks-demo.component.ts +++ b/demo-shell-ng2/app/components/tasks/tasks-demo.component.ts @@ -15,14 +15,39 @@ * limitations under the License. */ -import { Component } from 'angular2/core'; +import { Component, OnInit } from 'angular2/core'; +import { ActivitiService } from './activiti.service'; @Component({ selector: 'tasks-demo', template: `

Tasks

- ` + + `, + providers: [ActivitiService] }) -export class TasksDemoComponent { +export class TasksDemoComponent implements OnInit { + + tasks: any[]; + + constructor( + private activitiService: ActivitiService) {} + + ngOnInit() { + this.activitiService + .login('denys.vuika@alfresco.com', 'test') + .then(() => { + this.activitiService + .getTasks() + .then((tasks) => { + this.tasks = tasks || [] + console.log(this.tasks); + }); + }); + } } diff --git a/demo-shell-ng2/browser-sync-config.js b/demo-shell-ng2/browser-sync-config.js index dac89903d2..edd9d8b4a6 100644 --- a/demo-shell-ng2/browser-sync-config.js +++ b/demo-shell-ng2/browser-sync-config.js @@ -1,5 +1,5 @@ var browserSync = require("browser-sync").create(); -var historyApiFallback = require('connect-history-api-fallback') +var historyApiFallback = require('connect-history-api-fallback'); browserSync.init({