mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-780] centralised call for process filters api (#1950)
* [ADF-780] centralised call for process filters api * [ADF-780] updated conversion to string
This commit is contained in:
@@ -29,8 +29,14 @@ describe('ActivitiFilters', () => {
|
|||||||
let logService: LogServiceMock;
|
let logService: LogServiceMock;
|
||||||
|
|
||||||
let fakeGlobalFilter = [];
|
let fakeGlobalFilter = [];
|
||||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({name: 'FakeInvolvedTasks', filter: { state: 'open', assignment: 'fake-involved'}}));
|
fakeGlobalFilter.push(new FilterProcessRepresentationModel({
|
||||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}}));
|
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) {
|
let fakeGlobalFilterPromise = new Promise(function (resolve, reject) {
|
||||||
resolve(fakeGlobalFilter);
|
resolve(fakeGlobalFilter);
|
||||||
@@ -71,7 +77,7 @@ describe('ActivitiFilters', () => {
|
|||||||
it('should return the filter task list, filtered By Name', (done) => {
|
it('should return the filter task list, filtered By Name', (done) => {
|
||||||
|
|
||||||
let fakeDeployedApplicationsPromise = new Promise(function (resolve, reject) {
|
let fakeDeployedApplicationsPromise = new Promise(function (resolve, reject) {
|
||||||
resolve({});
|
resolve({ id: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
spyOn(activitiService, 'getDeployedApplications').and.returnValue(Observable.fromPromise(fakeDeployedApplicationsPromise));
|
spyOn(activitiService, 'getDeployedApplications').and.returnValue(Observable.fromPromise(fakeDeployedApplicationsPromise));
|
||||||
@@ -121,7 +127,12 @@ describe('ActivitiFilters', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should emit an event when a filter is selected', (done) => {
|
it('should emit an event when a filter is selected', (done) => {
|
||||||
let currentFilter = new FilterProcessRepresentationModel({filter: { state: 'open', assignment: 'fake-involved'}});
|
let currentFilter = new FilterProcessRepresentationModel({
|
||||||
|
filter: {
|
||||||
|
state: 'open',
|
||||||
|
assignment: 'fake-involved'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
filterList.filterClick.subscribe((filter: FilterProcessRepresentationModel) => {
|
filterList.filterClick.subscribe((filter: FilterProcessRepresentationModel) => {
|
||||||
expect(filter).toBeDefined();
|
expect(filter).toBeDefined();
|
||||||
@@ -164,7 +175,10 @@ describe('ActivitiFilters', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the current filter after one is selected', () => {
|
it('should return the current filter after one is selected', () => {
|
||||||
let filter = new FilterProcessRepresentationModel({name: 'FakeMyTasks', filter: { state: 'open', assignment: 'fake-assignee'}});
|
let filter = new FilterProcessRepresentationModel({
|
||||||
|
name: 'FakeMyTasks',
|
||||||
|
filter: { state: 'open', assignment: 'fake-assignee' }
|
||||||
|
});
|
||||||
expect(filterList.currentFilter).toBeUndefined();
|
expect(filterList.currentFilter).toBeUndefined();
|
||||||
filterList.selectFilter(filter);
|
filterList.selectFilter(filter);
|
||||||
expect(filterList.getCurrentFilter()).toBe(filter);
|
expect(filterList.getCurrentFilter()).toBe(filter);
|
||||||
|
@@ -91,7 +91,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges {
|
|||||||
* Return the filter list filtered by appId
|
* Return the filter list filtered by appId
|
||||||
* @param appId - optional
|
* @param appId - optional
|
||||||
*/
|
*/
|
||||||
getFiltersByAppId(appId?: number) {
|
getFiltersByAppId(appId?: string) {
|
||||||
this.activiti.getProcessFilters(appId).subscribe(
|
this.activiti.getProcessFilters(appId).subscribe(
|
||||||
(res: FilterProcessRepresentationModel[]) => {
|
(res: FilterProcessRepresentationModel[]) => {
|
||||||
if (res.length === 0 && this.isFilterListEmpty()) {
|
if (res.length === 0 && this.isFilterListEmpty()) {
|
||||||
@@ -132,7 +132,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges {
|
|||||||
getFiltersByAppName(appName: string) {
|
getFiltersByAppName(appName: string) {
|
||||||
this.activiti.getDeployedApplications(appName).subscribe(
|
this.activiti.getDeployedApplications(appName).subscribe(
|
||||||
application => {
|
application => {
|
||||||
this.getFiltersByAppId(application.id);
|
this.getFiltersByAppId(application.id.toString());
|
||||||
this.selectTaskFilter(this.filterParam);
|
this.selectTaskFilter(this.filterParam);
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
|
@@ -595,12 +595,12 @@ describe('ActivitiProcessService', () => {
|
|||||||
|
|
||||||
it('should call the API without an appId defined by default', () => {
|
it('should call the API without an appId defined by default', () => {
|
||||||
service.getProcessFilters(null);
|
service.getProcessFilters(null);
|
||||||
expect(getFilters).toHaveBeenCalledWith({});
|
expect(getFilters).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the API with the correct appId when specified', () => {
|
it('should call the API with the correct appId when specified', () => {
|
||||||
service.getProcessFilters(226);
|
service.getProcessFilters('226');
|
||||||
expect(getFilters).toHaveBeenCalledWith({appId: 226});
|
expect(getFilters).toHaveBeenCalledWith({appId: '226'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the task filter by id', (done) => {
|
it('should return the task filter by id', (done) => {
|
||||||
@@ -638,7 +638,7 @@ describe('ActivitiProcessService', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return the default filters', (done) => {
|
it('should return the default filters', (done) => {
|
||||||
service.createDefaultFilters(1234).subscribe(
|
service.createDefaultFilters('1234').subscribe(
|
||||||
(res: FilterProcessRepresentationModel []) => {
|
(res: FilterProcessRepresentationModel []) => {
|
||||||
expect(res).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(res.length).toEqual(3);
|
expect(res.length).toEqual(3);
|
||||||
|
@@ -68,11 +68,8 @@ export class ActivitiProcessService {
|
|||||||
}).catch(err => this.handleError(err));
|
}).catch(err => this.handleError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
getProcessFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
|
getProcessFilters(appId: string): Observable<FilterProcessRepresentationModel[]> {
|
||||||
let filterOpts = appId ? {
|
return Observable.fromPromise(this.callApiProcessFilters(appId))
|
||||||
appId: appId
|
|
||||||
} : {};
|
|
||||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(filterOpts))
|
|
||||||
.map((response: any) => {
|
.map((response: any) => {
|
||||||
let filters: FilterProcessRepresentationModel[] = [];
|
let filters: FilterProcessRepresentationModel[] = [];
|
||||||
response.data.forEach((filter: FilterProcessRepresentationModel) => {
|
response.data.forEach((filter: FilterProcessRepresentationModel) => {
|
||||||
@@ -103,7 +100,7 @@ export class ActivitiProcessService {
|
|||||||
* @returns {Observable<FilterProcessRepresentationModel>}
|
* @returns {Observable<FilterProcessRepresentationModel>}
|
||||||
*/
|
*/
|
||||||
getProcessFilterByName(processName: string, appId?: string): Observable<FilterProcessRepresentationModel> {
|
getProcessFilterByName(processName: string, appId?: string): Observable<FilterProcessRepresentationModel> {
|
||||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(appId))
|
return Observable.fromPromise(this.callApiProcessFilters(appId))
|
||||||
.map((response: any) => {
|
.map((response: any) => {
|
||||||
return response.data.find(filter => filter.name === processName);
|
return response.data.find(filter => filter.name === processName);
|
||||||
}).catch(err => this.handleError(err));
|
}).catch(err => this.handleError(err));
|
||||||
@@ -114,7 +111,7 @@ export class ActivitiProcessService {
|
|||||||
* @param appId
|
* @param appId
|
||||||
* @returns {FilterProcessRepresentationModel[]}
|
* @returns {FilterProcessRepresentationModel[]}
|
||||||
*/
|
*/
|
||||||
public createDefaultFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
|
public createDefaultFilters(appId: string): Observable<FilterProcessRepresentationModel[]> {
|
||||||
let runnintFilter = this.getRunningFilterInstance(appId);
|
let runnintFilter = this.getRunningFilterInstance(appId);
|
||||||
let runnintObservable = this.addFilter(runnintFilter);
|
let runnintObservable = this.addFilter(runnintFilter);
|
||||||
|
|
||||||
@@ -150,13 +147,13 @@ export class ActivitiProcessService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRunningFilterInstance(appId: number): FilterProcessRepresentationModel {
|
private getRunningFilterInstance(appId: string): FilterProcessRepresentationModel {
|
||||||
return new FilterProcessRepresentationModel({
|
return new FilterProcessRepresentationModel({
|
||||||
'name': 'Running',
|
'name': 'Running',
|
||||||
'appId': appId,
|
'appId': appId,
|
||||||
'recent': true,
|
'recent': true,
|
||||||
'icon': 'glyphicon-random',
|
'icon': 'glyphicon-random',
|
||||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'running'}
|
'filter': { 'sort': 'created-desc', 'name': '', 'state': 'running' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,13 +162,13 @@ export class ActivitiProcessService {
|
|||||||
* @param appId
|
* @param appId
|
||||||
* @returns {FilterProcessRepresentationModel}
|
* @returns {FilterProcessRepresentationModel}
|
||||||
*/
|
*/
|
||||||
private getCompletedFilterInstance(appId: number): FilterProcessRepresentationModel {
|
private getCompletedFilterInstance(appId: string): FilterProcessRepresentationModel {
|
||||||
return new FilterProcessRepresentationModel({
|
return new FilterProcessRepresentationModel({
|
||||||
'name': 'Completed',
|
'name': 'Completed',
|
||||||
'appId': appId,
|
'appId': appId,
|
||||||
'recent': false,
|
'recent': false,
|
||||||
'icon': 'glyphicon-ok-sign',
|
'icon': 'glyphicon-ok-sign',
|
||||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'completed'}
|
'filter': { 'sort': 'created-desc', 'name': '', 'state': 'completed' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,13 +177,13 @@ export class ActivitiProcessService {
|
|||||||
* @param appId
|
* @param appId
|
||||||
* @returns {FilterProcessRepresentationModel}
|
* @returns {FilterProcessRepresentationModel}
|
||||||
*/
|
*/
|
||||||
private getAllFilterInstance(appId: number): FilterProcessRepresentationModel {
|
private getAllFilterInstance(appId: string): FilterProcessRepresentationModel {
|
||||||
return new FilterProcessRepresentationModel({
|
return new FilterProcessRepresentationModel({
|
||||||
'name': 'All',
|
'name': 'All',
|
||||||
'appId': appId,
|
'appId': appId,
|
||||||
'recent': true,
|
'recent': true,
|
||||||
'icon': 'glyphicon-th',
|
'icon': 'glyphicon-th',
|
||||||
'filter': {'sort': 'created-desc', 'name': '', 'state': 'all'}
|
'filter': { 'sort': 'created-desc', 'name': '', 'state': 'all' }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +252,7 @@ export class ActivitiProcessService {
|
|||||||
*/
|
*/
|
||||||
addProcessInstanceComment(id: string, message: string): Observable<Comment> {
|
addProcessInstanceComment(id: string, message: string): Observable<Comment> {
|
||||||
return Observable.fromPromise(
|
return Observable.fromPromise(
|
||||||
this.apiService.getInstance().activiti.commentsApi.addProcessInstanceComment({message: message}, id)
|
this.apiService.getInstance().activiti.commentsApi.addProcessInstanceComment({ message: message }, id)
|
||||||
)
|
)
|
||||||
.map((response: Comment) => {
|
.map((response: Comment) => {
|
||||||
return new Comment(response.id, response.message, response.created, response.createdBy);
|
return new Comment(response.id, response.message, response.created, response.createdBy);
|
||||||
@@ -328,10 +325,6 @@ export class ActivitiProcessService {
|
|||||||
.catch(err => this.handleError(err));
|
.catch(err => this.handleError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
private callApiGetUserProcessInstanceFilters(filterOpts) {
|
|
||||||
return this.apiService.getInstance().activiti.userFiltersApi.getUserProcessInstanceFilters(filterOpts);
|
|
||||||
}
|
|
||||||
|
|
||||||
private callApiAddFilter(filter: FilterProcessRepresentationModel) {
|
private callApiAddFilter(filter: FilterProcessRepresentationModel) {
|
||||||
return this.apiService.getInstance().activiti.userFiltersApi.createUserProcessInstanceFilter(filter);
|
return this.apiService.getInstance().activiti.userFiltersApi.createUserProcessInstanceFilter(filter);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user