mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Add default tasks filters
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Component, AfterViewChecked, ViewChild, Input } from '@angular/core';
|
||||
import { ALFRESCO_TASKLIST_DIRECTIVES } from 'ng2-activiti-tasklist';
|
||||
import { ALFRESCO_TASKLIST_DIRECTIVES, TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { ACTIVITI_PROCESSLIST_DIRECTIVES } from 'ng2-activiti-processlist';
|
||||
import { ActivitiForm } from 'ng2-activiti-form';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
@@ -96,7 +96,14 @@ export class ActivitiDemoComponent implements AfterViewChecked {
|
||||
|
||||
onTaskFilterClick(event: any) {
|
||||
this.taskFilter = event;
|
||||
this.activititasklist.load(this.taskFilter.filter);
|
||||
let requestNode = {appDefinitionId: this.taskFilter.appId,
|
||||
processDefinitionId: this.taskFilter.filter.processDefinitionId,
|
||||
text: this.taskFilter.filter.name,
|
||||
assignment: this.taskFilter.filter.assignment,
|
||||
state: this.taskFilter.filter.state,
|
||||
sort: this.taskFilter.filter.sort,
|
||||
};
|
||||
this.activititasklist.load(new TaskQueryRequestRepresentationModel(requestNode));
|
||||
}
|
||||
|
||||
onSuccessTaskList(event: any) {
|
||||
|
@@ -22,5 +22,6 @@ import { NoTaskDetailsTemplateComponent } from './src/components/no-task-detail-
|
||||
|
||||
export * from './src/components/activiti-tasklist.component';
|
||||
export * from './src/services/activiti-tasklist.service';
|
||||
export * from './src/models/filter.model';
|
||||
|
||||
export const ALFRESCO_TASKLIST_DIRECTIVES: [any] = [NoTaskDetailsTemplateComponent, ActivitiFilters, ActivitiTaskList, ActivitiTaskDetails];
|
||||
|
@@ -25,15 +25,15 @@ import {
|
||||
import { ActivitiFilters } from './activiti-filters.component';
|
||||
import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { FilterModel } from '../models/filter.model';
|
||||
import { FilterRepresentationModel } from '../models/filter.model';
|
||||
|
||||
describe('ActivitiFilters', () => {
|
||||
|
||||
let filterList: ActivitiFilters;
|
||||
|
||||
let fakeGlobalFilter = [];
|
||||
fakeGlobalFilter.push(new FilterModel('FakeInvolvedTasks', false, 'glyphicon-align-left', '', 'open', 'fake-involved'));
|
||||
fakeGlobalFilter.push(new FilterModel('FakeMyTasks', false, 'glyphicon-align-left', '', 'open', 'fake-assignee'));
|
||||
fakeGlobalFilter.push(new FilterRepresentationModel({name: 'FakeInvolvedTasks', filter: { state: 'open', assignment: 'fake-involved'}}));
|
||||
fakeGlobalFilter.push(new FilterRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}}));
|
||||
|
||||
let fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
|
||||
resolve(fakeGlobalFilter);
|
||||
@@ -100,9 +100,9 @@ describe('ActivitiFilters', () => {
|
||||
});
|
||||
|
||||
it('should emit an event when a filter is selected', (done) => {
|
||||
let currentFilter = new FilterModel('FakeInvolvedTasks', false, 'glyphicon-align-left', '', 'open', 'fake-involved');
|
||||
let currentFilter = new FilterRepresentationModel({filter: { state: 'open', assignment: 'fake-involved'}});
|
||||
|
||||
filterList.filterClick.subscribe((filter: FilterModel) => {
|
||||
filterList.filterClick.subscribe((filter: FilterRepresentationModel) => {
|
||||
expect(filter).toBeDefined();
|
||||
expect(filter).toEqual(currentFilter);
|
||||
expect(filterList.currentFilter).toEqual(currentFilter);
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { Component, Output, EventEmitter, OnInit, Input } from '@angular/core';
|
||||
import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core';
|
||||
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
||||
import { FilterModel } from '../models/filter.model';
|
||||
import { FilterRepresentationModel } from '../models/filter.model';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
@@ -37,7 +37,7 @@ declare let __moduleName: string;
|
||||
export class ActivitiFilters implements OnInit {
|
||||
|
||||
@Output()
|
||||
filterClick: EventEmitter<FilterModel> = new EventEmitter<FilterModel>();
|
||||
filterClick: EventEmitter<FilterRepresentationModel> = new EventEmitter<FilterRepresentationModel>();
|
||||
|
||||
@Output()
|
||||
onSuccess: EventEmitter<any> = new EventEmitter<any>();
|
||||
@@ -51,12 +51,12 @@ export class ActivitiFilters implements OnInit {
|
||||
@Input()
|
||||
appName: string;
|
||||
|
||||
private filterObserver: Observer<FilterModel>;
|
||||
filter$: Observable<FilterModel>;
|
||||
private filterObserver: Observer<FilterRepresentationModel>;
|
||||
filter$: Observable<FilterRepresentationModel>;
|
||||
|
||||
currentFilter: FilterModel;
|
||||
currentFilter: FilterRepresentationModel;
|
||||
|
||||
filters: FilterModel [] = [];
|
||||
filters: FilterRepresentationModel [] = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -67,7 +67,7 @@ export class ActivitiFilters implements OnInit {
|
||||
constructor(private auth: AlfrescoAuthenticationService,
|
||||
private translate: AlfrescoTranslationService,
|
||||
public activiti: ActivitiTaskListService) {
|
||||
this.filter$ = new Observable<FilterModel>(observer => this.filterObserver = observer).share();
|
||||
this.filter$ = new Observable<FilterRepresentationModel>(observer => this.filterObserver = observer).share();
|
||||
|
||||
if (translate) {
|
||||
translate.addTranslationFolder('node_modules/ng2-activiti-tasklist/src');
|
||||
@@ -75,7 +75,7 @@ export class ActivitiFilters implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.filter$.subscribe((filter: FilterModel) => {
|
||||
this.filter$.subscribe((filter: FilterRepresentationModel) => {
|
||||
this.filters.push(filter);
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ export class ActivitiFilters implements OnInit {
|
||||
|
||||
private filterByAppId(appId) {
|
||||
this.activiti.getTaskListFilters(appId).subscribe(
|
||||
(res: FilterModel[]) => {
|
||||
(res: FilterRepresentationModel[]) => {
|
||||
res.forEach((filter) => {
|
||||
this.filterObserver.next(filter);
|
||||
});
|
||||
@@ -124,7 +124,7 @@ export class ActivitiFilters implements OnInit {
|
||||
* Pass the selected filter as next
|
||||
* @param filter
|
||||
*/
|
||||
public selectFilter(filter: FilterModel) {
|
||||
public selectFilter(filter: FilterRepresentationModel) {
|
||||
this.currentFilter = filter;
|
||||
this.filterClick.emit(filter);
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<div *ngIf="!hasFormKey()">
|
||||
<div *ngIf="!taskDetails">
|
||||
<template *ngIf="noTaskDetailsTemplateComponent" ngFor [ngForOf]="[data]"
|
||||
[ngForTemplate]="noTaskDetailsTemplateComponent">
|
||||
{{ 'TASK_DETAILS.MESSAGES.NONE' | translate }}
|
||||
@@ -7,7 +7,7 @@
|
||||
{{ 'TASK_DETAILS.MESSAGES.NONE' | translate }}
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="hasFormKey()">
|
||||
<div *ngIf="taskDetails">
|
||||
<h2 class="mdl-card__title-text">{{taskDetails.name}}</h2>
|
||||
<activiti-task-header [taskDetails]="taskDetails" #activitiheader></activiti-task-header>
|
||||
<div class="mdl-grid">
|
||||
|
@@ -138,12 +138,11 @@ export class ActivitiTaskDetails implements OnInit {
|
||||
let endDate: any = res.endDate;
|
||||
this.readOnly = !!(endDate && !isNaN(endDate.getTime()));
|
||||
|
||||
if (this.hasFormKey()) {
|
||||
if (this.taskDetails && this.taskDetails.involvedPeople) {
|
||||
this.taskDetails.involvedPeople.forEach((user) => {
|
||||
this.taskPeople.push(new User(user.id, user.email, user.firstName, user.lastName));
|
||||
this.taskPeople.push(new User(user));
|
||||
});
|
||||
|
||||
}
|
||||
if (this.activiticomments) {
|
||||
this.activiticomments.load(this.taskDetails.id);
|
||||
}
|
||||
@@ -151,9 +150,8 @@ export class ActivitiTaskDetails implements OnInit {
|
||||
if (this.activitichecklist) {
|
||||
this.activitichecklist.load(this.taskDetails.id);
|
||||
}
|
||||
}
|
||||
console.log(this.taskDetails);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
|
@@ -24,7 +24,7 @@ import {
|
||||
|
||||
import { ActivitiTaskList } from './activiti-tasklist.component';
|
||||
import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
|
||||
import { FilterModel } from '../models/filter.model';
|
||||
import { UserTaskFilterRepresentationModel } from '../models/filter.model';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { ObjectDataRow, DataRowEvent } from 'ng2-alfresco-datatable';
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('ActivitiTaskList', () => {
|
||||
it('should return the filtered task list when the taskFilter is passed', (done) => {
|
||||
spyOn(taskList.activiti, 'getTotalTasks').and.returnValue(Observable.fromPromise(fakeGlobalTotalTasksPromise));
|
||||
spyOn(taskList.activiti, 'getTasks').and.returnValue(Observable.fromPromise(fakeGlobalTaskPromise));
|
||||
taskList.taskFilter = new FilterModel('name', false, 'icon', '', 'open', 'fake-assignee');
|
||||
taskList.taskFilter = new UserTaskFilterRepresentationModel({filter: { state: 'open', assignment: 'fake-assignee'}});
|
||||
|
||||
taskList.onSuccess.subscribe( (res) => {
|
||||
expect(res).toBeDefined();
|
||||
@@ -119,7 +119,7 @@ describe('ActivitiTaskList', () => {
|
||||
|
||||
it('should throw an exception when the response is wrong', (done) => {
|
||||
spyOn(taskList.activiti, 'getTotalTasks').and.returnValue(Observable.fromPromise(fakeErrorTaskPromise));
|
||||
taskList.taskFilter = new FilterModel('name', false, 'icon', '', 'open', 'fake-assignee');
|
||||
taskList.taskFilter = new UserTaskFilterRepresentationModel({filter: { state: 'open', assignment: 'fake-assignee'}});
|
||||
|
||||
taskList.onError.subscribe( (err) => {
|
||||
expect(err).toBeDefined();
|
||||
|
@@ -19,7 +19,7 @@ import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
|
||||
import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core';
|
||||
import { ALFRESCO_DATATABLE_DIRECTIVES, ObjectDataTableAdapter, DataTableAdapter, DataRowEvent } from 'ng2-alfresco-datatable';
|
||||
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
||||
import { FilterModel, FilterParamsModel } from '../models/filter.model';
|
||||
import { UserTaskFilterRepresentationModel, TaskQueryRequestRepresentationModel } from '../models/filter.model';
|
||||
|
||||
declare let componentHandler: any;
|
||||
declare let __moduleName: string;
|
||||
@@ -37,7 +37,7 @@ declare let __moduleName: string;
|
||||
export class ActivitiTaskList implements OnInit {
|
||||
|
||||
@Input()
|
||||
taskFilter: FilterModel;
|
||||
taskFilter: UserTaskFilterRepresentationModel;
|
||||
|
||||
@Input()
|
||||
schemaColumn: any[] = [
|
||||
@@ -84,15 +84,21 @@ export class ActivitiTaskList implements OnInit {
|
||||
);
|
||||
|
||||
if (this.taskFilter) {
|
||||
this.load(this.taskFilter.filter);
|
||||
let requestNode = {appDefinitionId: this.taskFilter.appId,
|
||||
processDefinitionId: this.taskFilter.filter.processDefinitionId,
|
||||
text: this.taskFilter.filter.name,
|
||||
assignment: this.taskFilter.filter.assignment,
|
||||
state: this.taskFilter.filter.state,
|
||||
sort: this.taskFilter.filter.sort};
|
||||
this.load(new TaskQueryRequestRepresentationModel(requestNode));
|
||||
}
|
||||
}
|
||||
|
||||
public load(filterParam: FilterParamsModel) {
|
||||
this.activiti.getTotalTasks(filterParam).subscribe(
|
||||
public load(requestNode: TaskQueryRequestRepresentationModel) {
|
||||
this.activiti.getTotalTasks(requestNode).subscribe(
|
||||
(res) => {
|
||||
filterParam.size = res.total;
|
||||
this.activiti.getTasks(filterParam).subscribe(
|
||||
requestNode.size = res.total;
|
||||
this.activiti.getTasks(requestNode).subscribe(
|
||||
(response) => {
|
||||
this.renderTasks(response.data);
|
||||
this.selectFirstTask();
|
||||
|
@@ -20,20 +20,24 @@
|
||||
* This object represent the filter.
|
||||
*
|
||||
*
|
||||
* @returns {FilterModel} .
|
||||
* @returns {FilterRepresentationModel} .
|
||||
*/
|
||||
export class FilterModel {
|
||||
export class FilterRepresentationModel {
|
||||
id: number;
|
||||
appId: string;
|
||||
name: string;
|
||||
recent: boolean = false;
|
||||
recent: boolean;
|
||||
icon: string;
|
||||
filter: FilterParamsModel;
|
||||
filter: FilterParamRepresentationModel;
|
||||
index: number;
|
||||
|
||||
constructor(name: string, recent: boolean, icon: string, query: string, state: string, assignment: string, appDefinitionId?: string) {
|
||||
this.name = name;
|
||||
this.recent = recent;
|
||||
this.icon = icon;
|
||||
this.filter = new FilterParamsModel(assignment, state, query, appDefinitionId);
|
||||
constructor(obj?: any) {
|
||||
this.appId = obj && obj.appId || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.recent = obj && obj.recent || false;
|
||||
this.icon = obj && obj.icon || null;
|
||||
this.filter = new FilterParamRepresentationModel(obj.filter);
|
||||
this.index = obj && obj.index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +46,60 @@ export class FilterModel {
|
||||
* This object represent the parameters of a filter.
|
||||
*
|
||||
*
|
||||
* @returns {FilterModel} .
|
||||
* @returns {FilterParamRepresentationModel} .
|
||||
*/
|
||||
export class FilterParamsModel {
|
||||
export class FilterParamRepresentationModel {
|
||||
processDefinitionId: string;
|
||||
processDefinitionKey: string;
|
||||
name: string;
|
||||
state: string;
|
||||
sort: string;
|
||||
|
||||
constructor(obj?: any) {
|
||||
this.processDefinitionId = obj && obj.processDefinitionId || null;
|
||||
this.processDefinitionKey = obj && obj.processDefinitionKey || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.state = obj && obj.state || null;
|
||||
this.sort = obj && obj.sort || null;
|
||||
}
|
||||
}
|
||||
|
||||
export class UserProcessInstanceFilterRepresentationModel extends FilterRepresentationModel {
|
||||
public filter: ProcessInstanceFilterRepresentation;
|
||||
constructor(obj?: any) {
|
||||
super(obj);
|
||||
this.filter = new ProcessInstanceFilterRepresentation(obj.filter);
|
||||
}
|
||||
}
|
||||
|
||||
export class ProcessInstanceFilterRepresentation extends FilterParamRepresentationModel {
|
||||
constructor(obj?: any) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
||||
|
||||
export class UserTaskFilterRepresentationModel extends FilterRepresentationModel {
|
||||
public filter: TaskFilterRepresentationModel;
|
||||
constructor(obj?: any) {
|
||||
super(obj);
|
||||
this.filter = new TaskFilterRepresentationModel(obj.filter);
|
||||
}
|
||||
}
|
||||
|
||||
export class TaskFilterRepresentationModel extends FilterParamRepresentationModel {
|
||||
assignment: string;
|
||||
dueAfter: Date;
|
||||
dueBefore: Date;
|
||||
|
||||
constructor(obj?: any) {
|
||||
super(obj);
|
||||
this.assignment = obj && obj.assignment || null;
|
||||
this.dueAfter = obj && obj.dueAfter || null;
|
||||
this.dueBefore = obj && obj.dueBefore || null;
|
||||
}
|
||||
}
|
||||
|
||||
export class TaskQueryRequestRepresentationModel {
|
||||
appDefinitionId: string;
|
||||
processInstanceId: string;
|
||||
processDefinitionId: string;
|
||||
@@ -52,18 +107,18 @@ export class FilterParamsModel {
|
||||
assignment: string;
|
||||
state: string;
|
||||
sort: string;
|
||||
page: number = 0;
|
||||
size: number = 25;
|
||||
page: number;
|
||||
size: number;
|
||||
|
||||
constructor(assignment: string, state: string, text: string, appDefinitionId?: string, processInstanceId?: string,
|
||||
processDefinitionId?: string, page?: number, size?: number) {
|
||||
this.appDefinitionId = appDefinitionId;
|
||||
this.processInstanceId = processInstanceId;
|
||||
this.processDefinitionId = processDefinitionId;
|
||||
this.text = text;
|
||||
this.assignment = assignment;
|
||||
this.state = state;
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
constructor(obj?: any) {
|
||||
this.appDefinitionId = obj && obj.appDefinitionId || null;
|
||||
this.processInstanceId = obj && obj.processInstanceId || null;
|
||||
this.processDefinitionId = obj && obj.processDefinitionId || null;
|
||||
this.text = obj && obj.text || null;
|
||||
this.assignment = obj && obj.assignment || null;
|
||||
this.state = obj && obj.state || null;
|
||||
this.sort = obj && obj.sort || null;
|
||||
this.page = obj && obj.page || 0;
|
||||
this.size = obj && obj.size || 25;
|
||||
}
|
||||
}
|
||||
|
@@ -38,10 +38,10 @@ export class TaskDetailsModel {
|
||||
endDate: string;
|
||||
executionId: string;
|
||||
formKey: string;
|
||||
initiatorCanCompleteTask: boolean = false;
|
||||
managerOfCandidateGroup: boolean = false;
|
||||
memberOfCandidateGroup: boolean = false;
|
||||
memberOfCandidateUsers: boolean = false;
|
||||
initiatorCanCompleteTask: boolean;
|
||||
managerOfCandidateGroup: boolean;
|
||||
memberOfCandidateGroup: boolean;
|
||||
memberOfCandidateUsers: boolean;
|
||||
involvedPeople: User [];
|
||||
parentTaskId: string;
|
||||
parentTaskName: string;
|
||||
@@ -58,36 +58,36 @@ export class TaskDetailsModel {
|
||||
taskDefinitionKey: string;
|
||||
|
||||
|
||||
constructor(obj: any) {
|
||||
this.id = obj.id;
|
||||
this.name = obj.name;
|
||||
this.priority = obj.priority;
|
||||
this.assignee = new User(obj.assignee.id, obj.assignee.email, obj.assignee.firstName, obj.assignee.lastName);
|
||||
this.adhocTaskCanBeReassigned = obj.adhocTaskCanBeReassigned;
|
||||
this.created = obj.created;
|
||||
this.description = obj.description;
|
||||
this.dueDate = obj.dueDate;
|
||||
this.duration = obj.duration;
|
||||
this.endDate = obj.endDate;
|
||||
this.executionId = obj.executionId;
|
||||
this.formKey = obj.formKey;
|
||||
this.initiatorCanCompleteTask = obj.initiatorCanCompleteTask;
|
||||
this.managerOfCandidateGroup = obj.managerOfCandidateGroup;
|
||||
this.memberOfCandidateGroup = obj.memberOfCandidateGroup;
|
||||
this.memberOfCandidateUsers = obj.memberOfCandidateUsers;
|
||||
this.involvedPeople = obj.involvedPeople;
|
||||
this.parentTaskId = obj.parentTaskId;
|
||||
this.parentTaskName = obj.parentTaskName;
|
||||
this.processDefinitionCategory = obj.processDefinitionCategory;
|
||||
this.processDefinitionDeploymentId = obj.processDefinitionDeploymentId;
|
||||
this.processDefinitionDescription = obj.processDefinitionDescription;
|
||||
this.processDefinitionId = obj.processDefinitionId;
|
||||
this.processDefinitionKey = obj.processDefinitionKey;
|
||||
this.processDefinitionName = obj.processDefinitionName;
|
||||
this.processDefinitionVersion = obj.processDefinitionVersion;
|
||||
this.processInstanceId = obj.processInstanceId;
|
||||
this.processInstanceName = obj.processInstanceName;
|
||||
this.processInstanceStartUserId = obj.processInstanceStartUserId;
|
||||
this.taskDefinitionKey = obj.taskDefinitionKey;
|
||||
constructor(obj?: any) {
|
||||
this.id = obj && obj.id || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.priority = obj && obj.priority;
|
||||
this.assignee = new User(obj.assignee);
|
||||
this.adhocTaskCanBeReassigned = obj && obj.adhocTaskCanBeReassigned;
|
||||
this.created = obj && obj.created || null;
|
||||
this.description = obj && obj.description || null;
|
||||
this.dueDate = obj && obj.dueDate || null;
|
||||
this.duration = obj && obj.duration || null;
|
||||
this.endDate = obj && obj.endDate || null;
|
||||
this.executionId = obj && obj.executionId || null;
|
||||
this.formKey = obj && obj.formKey || null;
|
||||
this.initiatorCanCompleteTask = obj && obj.initiatorCanCompleteTask || false;
|
||||
this.managerOfCandidateGroup = obj && obj.managerOfCandidateGroup || false;
|
||||
this.memberOfCandidateGroup = obj && obj.memberOfCandidateGroup || false;
|
||||
this.memberOfCandidateUsers = obj && obj.memberOfCandidateUsers || false;
|
||||
this.involvedPeople = obj && obj.involvedPeople;
|
||||
this.parentTaskId = obj && obj.parentTaskId || null;
|
||||
this.parentTaskName = obj && obj.parentTaskName || null;
|
||||
this.processDefinitionCategory = obj && obj.processDefinitionCategory || null;
|
||||
this.processDefinitionDeploymentId = obj && obj.processDefinitionDeploymentId || null;
|
||||
this.processDefinitionDescription = obj && obj.processDefinitionDescription || null;
|
||||
this.processDefinitionId = obj && obj.processDefinitionId || null;
|
||||
this.processDefinitionKey = obj && obj.processDefinitionKey || null;
|
||||
this.processDefinitionName = obj && obj.processDefinitionName || null;
|
||||
this.processDefinitionVersion = obj && obj.processDefinitionVersion || 0;
|
||||
this.processInstanceId = obj && obj.processInstanceId || null;
|
||||
this.processInstanceName = obj && obj.processInstanceName || null;
|
||||
this.processInstanceStartUserId = obj && obj.processInstanceStartUserId || null;
|
||||
this.taskDefinitionKey = obj && obj.taskDefinitionKey || null;
|
||||
}
|
||||
}
|
||||
|
@@ -29,10 +29,10 @@ export class User {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
|
||||
constructor(id: number, email: string, firstName: string, lastName: string) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
constructor(obj?: any) {
|
||||
this.id = obj && obj.id;
|
||||
this.email = obj && obj.email || null;
|
||||
this.firstName = obj && obj.firstName || null;
|
||||
this.lastName = obj && obj.lastName || null;
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/
|
||||
import { ActivitiTaskListService } from './activiti-tasklist.service';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core';
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import { UserTaskFilterRepresentationModel } from '../models/filter.model';
|
||||
import { Comment } from '../models/comment.model';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
@@ -27,6 +28,11 @@ declare let jasmine: any;
|
||||
describe('ActivitiTaskListService', () => {
|
||||
let service: any;
|
||||
|
||||
let fakeEmptyFilters = {
|
||||
size: 0, total: 0, start: 0,
|
||||
data: [ ]
|
||||
};
|
||||
|
||||
let fakeFilters = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
@@ -319,5 +325,55 @@ describe('ActivitiTaskListService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the createDefaultFilter when the list is empty', (done) => {
|
||||
spyOn(service, 'createDefaultFilter');
|
||||
|
||||
service.getTaskListFilters().subscribe(
|
||||
(res) => {
|
||||
expect(service.createDefaultFilter).toHaveBeenCalled();
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeEmptyFilters)
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the default filters', () => {
|
||||
spyOn(service, 'addFilter');
|
||||
let filters = service.createDefaultFilter();
|
||||
expect(service.addFilter).toHaveBeenCalledTimes(4);
|
||||
expect(filters).toBeDefined();
|
||||
expect(filters.length).toEqual(4);
|
||||
});
|
||||
|
||||
it('should add a filter ', (done) => {
|
||||
let filterFake = new UserTaskFilterRepresentationModel({
|
||||
name: 'FakeNameFilter',
|
||||
assignment: 'fake-assignement'
|
||||
});
|
||||
|
||||
service.addFilter(filterFake).subscribe(
|
||||
(res: UserTaskFilterRepresentationModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual('');
|
||||
expect(res.name).toEqual('FakeNameFilter');
|
||||
expect(res.filter.assignment).toEqual('fake-assignement');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: '2233', name: 'FakeNameFilter', filter: {assignment: 'fake-assignement'}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
@@ -18,8 +18,8 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {AlfrescoAuthenticationService} from 'ng2-alfresco-core';
|
||||
import {Observable} from 'rxjs/Rx';
|
||||
import {FilterModel} from '../models/filter.model';
|
||||
import {FilterParamsModel} from '../models/filter.model';
|
||||
import {UserTaskFilterRepresentationModel} from '../models/filter.model';
|
||||
import {TaskQueryRequestRepresentationModel} from '../models/filter.model';
|
||||
import {Comment} from '../models/comment.model';
|
||||
import {User} from '../models/user.model';
|
||||
import {TaskDetailsModel} from '../models/task-details.model';
|
||||
@@ -47,23 +47,25 @@ export class ActivitiTaskListService {
|
||||
getTaskListFilters(appId?: string): Observable<any> {
|
||||
return Observable.fromPromise(this.callApiTaskFilters(appId))
|
||||
.map((response: any) => {
|
||||
let filters: FilterModel[] = [];
|
||||
response.data.forEach((filter) => {
|
||||
let filterModel = new FilterModel(filter.name, filter.recent, filter.icon,
|
||||
filter.filter.name, filter.filter.state, filter.filter.assignment, appId);
|
||||
let filters: UserTaskFilterRepresentationModel[] = [];
|
||||
response.data.forEach((filter: UserTaskFilterRepresentationModel) => {
|
||||
let filterModel = new UserTaskFilterRepresentationModel(filter);
|
||||
filters.push(filterModel);
|
||||
});
|
||||
if (response && response.data && response.data.length === 0) {
|
||||
return this.createDefaultFilter(appId);
|
||||
}
|
||||
return filters;
|
||||
}).catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive all the tasks filtered by filterModel
|
||||
* @param filter - FilterParamsModel
|
||||
* @param filter - TaskFilterRepresentationModel
|
||||
* @returns {any}
|
||||
*/
|
||||
getTasks(filter: FilterParamsModel): Observable<any> {
|
||||
return Observable.fromPromise(this.callApiTasksFiltered(filter))
|
||||
getTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<any> {
|
||||
return Observable.fromPromise(this.callApiTasksFiltered(requestNode))
|
||||
.map((res: any) => {
|
||||
return res;
|
||||
}).catch(this.handleError);
|
||||
@@ -93,8 +95,7 @@ export class ActivitiTaskListService {
|
||||
.map((response: any) => {
|
||||
let comments: Comment[] = [];
|
||||
response.data.forEach((comment) => {
|
||||
let user = new User(
|
||||
comment.createdBy.id, comment.createdBy.email, comment.createdBy.firstName, comment.createdBy.lastName);
|
||||
let user = new User(comment.createdBy);
|
||||
comments.push(new Comment(comment.id, comment.message, comment.created, user));
|
||||
});
|
||||
return comments;
|
||||
@@ -118,6 +119,33 @@ export class ActivitiTaskListService {
|
||||
}).catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return the default filters
|
||||
* @param appId
|
||||
* @returns {UserTaskFilterRepresentationModel[]}
|
||||
*/
|
||||
createDefaultFilter(appId: string): UserTaskFilterRepresentationModel[] {
|
||||
let filters: UserTaskFilterRepresentationModel[] = [];
|
||||
|
||||
let involvedTasksFilter = this.getInvolvedTasksFilterInstance(appId);
|
||||
this.addFilter(involvedTasksFilter);
|
||||
filters.push(involvedTasksFilter);
|
||||
|
||||
let myTasksFilter = this.getMyTasksFilterInstance(appId);
|
||||
this.addFilter(myTasksFilter);
|
||||
filters.push(myTasksFilter);
|
||||
|
||||
let queuedTasksFilter = this.getQueuedTasksFilterInstance(appId);
|
||||
this.addFilter(queuedTasksFilter);
|
||||
filters.push(queuedTasksFilter);
|
||||
|
||||
let completedTasksFilter = this.getCompletedTasksFilterInstance(appId);
|
||||
this.addFilter(completedTasksFilter);
|
||||
filters.push(completedTasksFilter);
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task
|
||||
* @param task - TaskDetailsModel
|
||||
@@ -131,6 +159,19 @@ export class ActivitiTaskListService {
|
||||
}).catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filter
|
||||
* @param filter - UserTaskFilterRepresentationModel
|
||||
* @returns {UserTaskFilterRepresentationModel}
|
||||
*/
|
||||
addFilter(filter: UserTaskFilterRepresentationModel): Observable<UserTaskFilterRepresentationModel> {
|
||||
return Observable.fromPromise(this.callApiAddFilter(filter))
|
||||
.map(res => res)
|
||||
.map((response: UserTaskFilterRepresentationModel) => {
|
||||
return response;
|
||||
}).catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a comment to a task
|
||||
* @param id - taskId
|
||||
@@ -159,19 +200,19 @@ export class ActivitiTaskListService {
|
||||
|
||||
/**
|
||||
* Return the total number of the tasks by filter
|
||||
* @param filter - FilterParamsModel
|
||||
* @param requestNode - TaskFilterRepresentationModel
|
||||
* @returns {any}
|
||||
*/
|
||||
public getTotalTasks(filter: FilterParamsModel): Observable<any> {
|
||||
filter.size = 0;
|
||||
return Observable.fromPromise(this.callApiTasksFiltered(filter))
|
||||
public getTotalTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<any> {
|
||||
requestNode.size = 0;
|
||||
return Observable.fromPromise(this.callApiTasksFiltered(requestNode))
|
||||
.map((res: any) => {
|
||||
return res;
|
||||
}).catch(this.handleError);
|
||||
}
|
||||
|
||||
private callApiTasksFiltered(filter: FilterParamsModel) {
|
||||
return this.authService.getAlfrescoApi().activiti.taskApi.listTasks(filter);
|
||||
private callApiTasksFiltered(requestNode: TaskQueryRequestRepresentationModel) {
|
||||
return this.authService.getAlfrescoApi().activiti.taskApi.listTasks(requestNode);
|
||||
}
|
||||
|
||||
private callApiTaskFilters(appId?: string) {
|
||||
@@ -198,6 +239,10 @@ export class ActivitiTaskListService {
|
||||
return this.authService.getAlfrescoApi().activiti.taskApi.addSubtask(task.parentTaskId, task);
|
||||
}
|
||||
|
||||
private callApiAddFilter(filter: UserTaskFilterRepresentationModel) {
|
||||
return this.authService.getAlfrescoApi().activiti.userFiltersApi.createUserTaskFilter(filter);
|
||||
}
|
||||
|
||||
private callApiTaskChecklist(id: string) {
|
||||
return this.authService.getAlfrescoApi().activiti.taskApi.getChecklist(id);
|
||||
}
|
||||
@@ -210,4 +255,65 @@ export class ActivitiTaskListService {
|
||||
console.error(error);
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a static Involved filter instance
|
||||
* @param appId
|
||||
* @returns {UserTaskFilterRepresentationModel}
|
||||
*/
|
||||
getInvolvedTasksFilterInstance(appId: string): UserTaskFilterRepresentationModel {
|
||||
return new UserTaskFilterRepresentationModel({
|
||||
'name': 'Involved Tasks',
|
||||
'appId': appId,
|
||||
'recent': false,
|
||||
'icon': 'glyphicon-align-left',
|
||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'open', 'assignment': 'involved'}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a static My task filter instance
|
||||
* @param appId
|
||||
* @returns {UserTaskFilterRepresentationModel}
|
||||
*/
|
||||
getMyTasksFilterInstance(appId: string): UserTaskFilterRepresentationModel {
|
||||
return new UserTaskFilterRepresentationModel({
|
||||
'name': 'My Tasks',
|
||||
'appId': appId,
|
||||
'recent': false,
|
||||
'icon': 'glyphicon-inbox',
|
||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'open', 'assignment': 'assignee'}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a static Queued filter instance
|
||||
* @param appId
|
||||
* @returns {UserTaskFilterRepresentationModel}
|
||||
*/
|
||||
getQueuedTasksFilterInstance(appId: string): UserTaskFilterRepresentationModel {
|
||||
return new UserTaskFilterRepresentationModel({
|
||||
'name': 'Queued Tasks',
|
||||
'appId': appId,
|
||||
'recent': false,
|
||||
'icon': 'glyphicon-record',
|
||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'open', 'assignment': 'candidate'}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a static Completed filter instance
|
||||
* @param appId
|
||||
* @returns {UserTaskFilterRepresentationModel}
|
||||
*/
|
||||
getCompletedTasksFilterInstance(appId: string): UserTaskFilterRepresentationModel {
|
||||
return new UserTaskFilterRepresentationModel({
|
||||
'name': 'Completed Tasks',
|
||||
'appId': appId,
|
||||
'recent': true,
|
||||
'icon': 'glyphicon-ok-sign',
|
||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'completed', 'assignment': 'involved'}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user