mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
Add Tasklist filters
This commit is contained in:
@@ -1 +1,9 @@
|
||||
<div [ngStyle]="locationCss" class="menu-container">
|
||||
<ul class="context-menu">
|
||||
<li (click)="selectFilter(filter)" *ngFor="#filter of filtersList | async">
|
||||
{{filter.name}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<alfresco-datatable [data]="tasks"></alfresco-datatable>
|
@@ -15,11 +15,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { Component, Input, OnInit} from '@angular/core';
|
||||
import { AlfrescoTranslationService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { ALFRESCO_DATATABLE_DIRECTIVES, ObjectDataTableAdapter, DataTableAdapter } from 'ng2-alfresco-datatable';
|
||||
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
||||
|
||||
import { FilterModel } from '../models/filter.model';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
declare let componentHandler: any;
|
||||
declare let __moduleName: string;
|
||||
@@ -32,16 +34,18 @@ declare let __moduleName: string;
|
||||
providers: [ActivitiTaskListService]
|
||||
|
||||
})
|
||||
export class ActivitiTaskList {
|
||||
|
||||
tasks: ObjectDataTableAdapter;
|
||||
export class ActivitiTaskList implements OnInit {
|
||||
|
||||
@Input()
|
||||
data: DataTableAdapter;
|
||||
|
||||
@Input()
|
||||
assignment: string;
|
||||
private filterObserver: Observer<FilterModel>;
|
||||
|
||||
filter$: Observable<FilterModel>;
|
||||
|
||||
tasks: ObjectDataTableAdapter;
|
||||
|
||||
filtersList: Observable<FilterModel>;
|
||||
/**
|
||||
* Constructor
|
||||
* @param auth
|
||||
@@ -50,26 +54,20 @@ export class ActivitiTaskList {
|
||||
constructor(private auth: AlfrescoAuthenticationService,
|
||||
private translate: AlfrescoTranslationService,
|
||||
private activiti: ActivitiTaskListService) {
|
||||
this.filter$ = new Observable<FilterModel>(observer => this.filterObserver = observer).share();
|
||||
|
||||
translate.addTranslationFolder('node_modules/ng2-alfresco-activiti-tasklist');
|
||||
}
|
||||
|
||||
if (auth.isLoggedIn('BPM')) {
|
||||
activiti.getTaskListFilters().subscribe((resFilter) => {
|
||||
let tasksListFilter = resFilter.data || [];
|
||||
if (tasksListFilter.length === 0) {
|
||||
activiti.createMyTaskFilter().subscribe(() => {
|
||||
console.log('Default filters created');
|
||||
});
|
||||
activiti.getTasks(this.assignment).subscribe((res) => {
|
||||
let tasks = res.data || [];
|
||||
console.log(tasks);
|
||||
ngOnInit() {
|
||||
this.filtersList = this.activiti.getTaskListFilters().map(res => (res.data));
|
||||
|
||||
this.filter$.subscribe( (filter: FilterModel) => {
|
||||
this.activiti.getTasks(filter).subscribe((res) => {
|
||||
let tasks = res.data;
|
||||
this.loadTasks(tasks);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('User unauthorized');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +79,19 @@ export class ActivitiTaskList {
|
||||
this.tasks = new ObjectDataTableAdapter(tasks, this.data.getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass the selected filter as next
|
||||
* @param filter
|
||||
*/
|
||||
public selectFilter(filter: FilterModel) {
|
||||
this.filterObserver.next(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize task name field
|
||||
* @param tasks
|
||||
* @returns {any[]}
|
||||
*/
|
||||
private optimizeTaskName(tasks: any[]) {
|
||||
tasks = tasks.map(t => {
|
||||
t.name = t.name || 'Nameless task';
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This object represent the filter.
|
||||
*
|
||||
*
|
||||
* @returns {FilterModel} .
|
||||
*/
|
||||
export class FilterModel {
|
||||
id: number;
|
||||
name: string;
|
||||
recent: boolean = false;
|
||||
icon: string;
|
||||
filter: FilterParamsModel;
|
||||
|
||||
constructor(name: string, recent: boolean, icon: string, state: string, assignment: string) {
|
||||
this.name = name;
|
||||
this.recent = recent;
|
||||
this.icon = icon;
|
||||
this.filter = new FilterParamsModel(name, state, assignment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This object represent the parameters of a filter.
|
||||
*
|
||||
*
|
||||
* @returns {FilterModel} .
|
||||
*/
|
||||
export class FilterParamsModel {
|
||||
name: string;
|
||||
state: string;
|
||||
assignment: string;
|
||||
|
||||
constructor(name: string, state: string, assignment: string) {
|
||||
this.name = name;
|
||||
this.state = state;
|
||||
this.assignment = assignment;
|
||||
}
|
||||
}
|
@@ -18,19 +18,55 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Http, Headers, RequestOptions, Response } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { FilterModel } from '../models/filter.model';
|
||||
|
||||
@Injectable()
|
||||
export class ActivitiTaskListService {
|
||||
|
||||
constructor(private http: Http) {}
|
||||
constructor(private http: Http) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive all the Tasks filters
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
getTaskListFilters() {
|
||||
return this.callApiTaskFilters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive all the tasks created in activiti
|
||||
* @returns {any}
|
||||
*/
|
||||
getTasks(filter: FilterModel): Observable<any> {
|
||||
let data: any = {};
|
||||
data.filterId = filter.id;
|
||||
data.filter = filter.filter;
|
||||
data = JSON.stringify(data);
|
||||
return this.callApiTasksFiltered(data);
|
||||
}
|
||||
|
||||
private callApiTasksFiltered(data: Object): Observable<any> {
|
||||
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)
|
||||
.map((res: Response) => res.json())
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
private callApiTaskFilters(): Observable<any> {
|
||||
let url = 'http://localhost:9999/activiti-app/app/rest/filters/tasks';
|
||||
let headers = new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-cache'
|
||||
});
|
||||
let options = new RequestOptions({ headers: headers });
|
||||
let options = new RequestOptions({headers: headers});
|
||||
|
||||
return this.http
|
||||
.get(url, options)
|
||||
@@ -38,85 +74,6 @@ export class ActivitiTaskListService {
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createMyTaskFilter() {
|
||||
let data = JSON.stringify({
|
||||
'name': 'My Tasks',
|
||||
'index': 1,
|
||||
'icon': 'glyphicon-inbox',
|
||||
'filter': {
|
||||
'name': '',
|
||||
'sort': 'created-desc',
|
||||
'state': 'open',
|
||||
'assignment': 'assignee'
|
||||
},
|
||||
'appId': null
|
||||
});
|
||||
return this.callApiCreateFilter(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive all the tasks created in activiti
|
||||
* @returns {any}
|
||||
*/
|
||||
getTasks(assignment: string = 'assignee'): Observable<any> {
|
||||
let data = JSON.stringify({
|
||||
'page': 0,
|
||||
'filterId': 1,
|
||||
'filter': {
|
||||
'name': '',
|
||||
'sort': 'created-desc',
|
||||
'state': 'open',
|
||||
'assignment': assignment
|
||||
},
|
||||
'appDefinitionId': null
|
||||
});
|
||||
return this.callApiFilterTasks(data);
|
||||
}
|
||||
|
||||
getInvolvedTasks(): Observable<any> {
|
||||
let data = JSON.stringify({
|
||||
'page': 0,
|
||||
'filterId': 3,
|
||||
'filter': {
|
||||
'name': '',
|
||||
'sort': 'created-desc',
|
||||
'state': 'open',
|
||||
'assignment': 'involved'
|
||||
},
|
||||
'appDefinitionId': null
|
||||
});
|
||||
return this.callApiFilterTasks(data);
|
||||
}
|
||||
|
||||
private callApiCreateFilter(data: Object): Observable<any> {
|
||||
|
||||
let url = 'http://localhost:9999/activiti-app/app/rest/filters/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)
|
||||
.map((res: Response) => res.json())
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
private callApiFilterTasks(data: Object): Observable<any> {
|
||||
|
||||
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)
|
||||
.map((res: Response) => res.json())
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method write the error in the console browser
|
||||
|
Reference in New Issue
Block a user