mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Provide a way to retrieve the process filter by id or name (#1817)
* Provide a way to retrieve the process filter by id or name * Update activiti-process.service.ts
This commit is contained in:
committed by
Mario Romano
parent
d4cc54d561
commit
88edb1697a
@@ -18,17 +18,17 @@
|
||||
import {
|
||||
AppDefinitionRepresentationModel,
|
||||
Comment,
|
||||
FilterRepresentationModel,
|
||||
TaskDetailsModel,
|
||||
User
|
||||
} from 'ng2-activiti-tasklist';
|
||||
import { ProcessDefinitionRepresentation } from '../models/index';
|
||||
import { ProcessDefinitionRepresentation, FilterProcessRepresentationModel } from '../models/index';
|
||||
|
||||
export var fakeFilters = {
|
||||
size: 1, total: 1, start: 0,
|
||||
data: [new FilterRepresentationModel({
|
||||
data: [new FilterProcessRepresentationModel({
|
||||
'name': 'Running',
|
||||
'appId': '22',
|
||||
'id': '333',
|
||||
'recent': true,
|
||||
'icon': 'glyphicon-random',
|
||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'running'}
|
||||
|
@@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Rx';
|
||||
import { LogServiceMock } from 'ng2-alfresco-core';
|
||||
import { ActivitiProcessFilters } from './activiti-filters.component';
|
||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||
import { FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
|
||||
|
||||
describe('ActivitiFilters', () => {
|
||||
|
||||
@@ -29,8 +29,8 @@ describe('ActivitiFilters', () => {
|
||||
let logService: LogServiceMock;
|
||||
|
||||
let fakeGlobalFilter = [];
|
||||
fakeGlobalFilter.push(new FilterRepresentationModel({name: 'FakeInvolvedTasks', filter: { state: 'open', assignment: 'fake-involved'}}));
|
||||
fakeGlobalFilter.push(new FilterRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}}));
|
||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({name: 'FakeInvolvedTasks', filter: { state: 'open', assignment: 'fake-involved'}}));
|
||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}}));
|
||||
|
||||
let fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
|
||||
resolve(fakeGlobalFilter);
|
||||
@@ -121,9 +121,9 @@ describe('ActivitiFilters', () => {
|
||||
});
|
||||
|
||||
it('should emit an event when a filter is selected', (done) => {
|
||||
let currentFilter = new FilterRepresentationModel({filter: { state: 'open', assignment: 'fake-involved'}});
|
||||
let currentFilter = new FilterProcessRepresentationModel({filter: { state: 'open', assignment: 'fake-involved'}});
|
||||
|
||||
filterList.filterClick.subscribe((filter: FilterRepresentationModel) => {
|
||||
filterList.filterClick.subscribe((filter: FilterProcessRepresentationModel) => {
|
||||
expect(filter).toBeDefined();
|
||||
expect(filter).toEqual(currentFilter);
|
||||
expect(filterList.currentFilter).toEqual(currentFilter);
|
||||
@@ -164,7 +164,7 @@ describe('ActivitiFilters', () => {
|
||||
});
|
||||
|
||||
it('should return the current filter after one is selected', () => {
|
||||
let filter = new FilterRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}});
|
||||
let filter = new FilterProcessRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}});
|
||||
expect(filterList.currentFilter).toBeUndefined();
|
||||
filterList.selectFilter(filter);
|
||||
expect(filterList.getCurrentFilter()).toBe(filter);
|
||||
|
@@ -160,7 +160,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges {
|
||||
|
||||
/**
|
||||
* Return the current task
|
||||
* @returns {FilterRepresentationModel}
|
||||
* @returns {FilterProcessRepresentationModel}
|
||||
*/
|
||||
getCurrentFilter(): FilterProcessRepresentationModel {
|
||||
return this.currentFilter;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
* @returns {FilterProcessRepresentationModel} .
|
||||
*/
|
||||
export class FilterProcessRepresentationModel {
|
||||
id: number;
|
||||
id: string;
|
||||
appId: string;
|
||||
name: string;
|
||||
recent: boolean;
|
||||
@@ -32,6 +32,7 @@ export class FilterProcessRepresentationModel {
|
||||
index: number;
|
||||
|
||||
constructor(obj?: any) {
|
||||
this.id = obj && obj.id || null;
|
||||
this.appId = obj && obj.appId || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.recent = obj && obj.recent || false;
|
||||
|
@@ -18,7 +18,6 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { async } from '@angular/core/testing';
|
||||
import { CoreModule, AlfrescoApiService } from 'ng2-alfresco-core';
|
||||
import { FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { AlfrescoApi } from 'alfresco-js-api';
|
||||
import {
|
||||
fakeFilters,
|
||||
@@ -581,7 +580,7 @@ describe('ActivitiProcessService', () => {
|
||||
|
||||
createFilter = spyOn(alfrescoApi.activiti.userFiltersApi, 'createUserProcessInstanceFilter')
|
||||
.and
|
||||
.callFake((filter: FilterRepresentationModel) => Promise.resolve(filter));
|
||||
.callFake((filter: FilterProcessRepresentationModel) => Promise.resolve(filter));
|
||||
});
|
||||
|
||||
describe('get filters', () => {
|
||||
@@ -596,6 +595,32 @@ describe('ActivitiProcessService', () => {
|
||||
expect(getFilters).toHaveBeenCalledWith({appId: 226});
|
||||
});
|
||||
|
||||
it('should return the task filter by id', (done) => {
|
||||
service.getProcessFilterById('333').subscribe(
|
||||
(res: FilterProcessRepresentationModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).toEqual('333');
|
||||
expect(res.name).toEqual('Running');
|
||||
expect(res.filter.sort).toEqual('created-desc');
|
||||
expect(res.filter.state).toEqual('running');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the task filter by name', (done) => {
|
||||
service.getProcessFilterByName('Running').subscribe(
|
||||
(res: FilterProcessRepresentationModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).toEqual('333');
|
||||
expect(res.name).toEqual('Running');
|
||||
expect(res.filter.sort).toEqual('created-desc');
|
||||
expect(res.filter.state).toEqual('running');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the non-empty filter list that is returned by the API', async(() => {
|
||||
service.getProcessFilters(null).subscribe(
|
||||
(res) => {
|
||||
@@ -640,7 +665,7 @@ describe('ActivitiProcessService', () => {
|
||||
});
|
||||
|
||||
it('should return the created filter', async(() => {
|
||||
service.addFilter(filter).subscribe((createdFilter: FilterRepresentationModel) => {
|
||||
service.addFilter(filter).subscribe((createdFilter: FilterProcessRepresentationModel) => {
|
||||
expect(createdFilter).toBe(filter);
|
||||
});
|
||||
}));
|
||||
|
@@ -70,10 +70,34 @@ export class ActivitiProcessService {
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the process filter by id
|
||||
* @param processId - string - The id of the filter
|
||||
* @returns {Observable<FilterProcessRepresentationModel>}
|
||||
*/
|
||||
getProcessFilterById(processId: string, appId?: string): Observable<FilterProcessRepresentationModel> {
|
||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(appId))
|
||||
.map((response: any) => {
|
||||
return response.data.find(filter => filter.id === processId);
|
||||
}).catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the process filter by name
|
||||
* @param processName - string - The name of the filter
|
||||
* @returns {Observable<FilterProcessRepresentationModel>}
|
||||
*/
|
||||
getProcessFilterByName(processName: string, appId?: string): Observable<FilterProcessRepresentationModel> {
|
||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(appId))
|
||||
.map((response: any) => {
|
||||
return response.data.find(filter => filter.name === processName);
|
||||
}).catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return the default filters
|
||||
* @param appId
|
||||
* @returns {FilterRepresentationModel[]}
|
||||
* @returns {FilterProcessRepresentationModel[]}
|
||||
*/
|
||||
public createDefaultFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
|
||||
let runnintFilter = this.getRunningFilterInstance(appId);
|
||||
@@ -294,6 +318,14 @@ export class ActivitiProcessService {
|
||||
return this.apiService.getInstance().activiti.userFiltersApi.createUserProcessInstanceFilter(filter);
|
||||
}
|
||||
|
||||
callApiProcessFilters(appId?: string) {
|
||||
if (appId) {
|
||||
return this.apiService.getInstance().activiti.userFiltersApi.getUserProcessInstanceFilters({ appId: appId });
|
||||
} else {
|
||||
return this.apiService.getInstance().activiti.userFiltersApi.getUserProcessInstanceFilters();
|
||||
}
|
||||
}
|
||||
|
||||
private extractData(res: any) {
|
||||
return res.data || {};
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ export class AppDefinitionRepresentationModel {
|
||||
* @returns {FilterRepresentationModel} .
|
||||
*/
|
||||
export class FilterRepresentationModel {
|
||||
id: number;
|
||||
id: string;
|
||||
appId: string;
|
||||
name: string;
|
||||
recent: boolean;
|
||||
@@ -64,6 +64,7 @@ export class FilterRepresentationModel {
|
||||
landingTaskId: string;
|
||||
|
||||
constructor(obj?: any) {
|
||||
this.id = obj && obj.id || null;
|
||||
this.appId = obj && obj.appId || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.recent = obj && obj.recent || false;
|
||||
|
Reference in New Issue
Block a user