mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
External service integration demo (work in progress)
This commit is contained in:
84
demo-shell-ng2/app/components/tasks/activiti.service.ts
Normal file
84
demo-shell-ng2/app/components/tasks/activiti.service.ts
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
@@ -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: `
|
||||
<h2>Tasks</h2>
|
||||
`
|
||||
<ul>
|
||||
<li *ngFor="#task of tasks">
|
||||
{{task.name}}
|
||||
</li>
|
||||
</ul>
|
||||
`,
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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({
|
||||
|
||||
|
Reference in New Issue
Block a user