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 fakeGlobalFilter = [];
|
||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({name: 'FakeInvolvedTasks', filter: { state: 'open', assignment: 'fake-involved'}}));
|
||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({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);
|
||||
@@ -71,7 +77,7 @@ describe('ActivitiFilters', () => {
|
||||
it('should return the filter task list, filtered By Name', (done) => {
|
||||
|
||||
let fakeDeployedApplicationsPromise = new Promise(function (resolve, reject) {
|
||||
resolve({});
|
||||
resolve({ id: 1 });
|
||||
});
|
||||
|
||||
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) => {
|
||||
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) => {
|
||||
expect(filter).toBeDefined();
|
||||
@@ -164,7 +175,10 @@ describe('ActivitiFilters', () => {
|
||||
});
|
||||
|
||||
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();
|
||||
filterList.selectFilter(filter);
|
||||
expect(filterList.getCurrentFilter()).toBe(filter);
|
||||
|
@@ -91,7 +91,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges {
|
||||
* Return the filter list filtered by appId
|
||||
* @param appId - optional
|
||||
*/
|
||||
getFiltersByAppId(appId?: number) {
|
||||
getFiltersByAppId(appId?: string) {
|
||||
this.activiti.getProcessFilters(appId).subscribe(
|
||||
(res: FilterProcessRepresentationModel[]) => {
|
||||
if (res.length === 0 && this.isFilterListEmpty()) {
|
||||
@@ -132,7 +132,7 @@ export class ActivitiProcessFilters implements OnInit, OnChanges {
|
||||
getFiltersByAppName(appName: string) {
|
||||
this.activiti.getDeployedApplications(appName).subscribe(
|
||||
application => {
|
||||
this.getFiltersByAppId(application.id);
|
||||
this.getFiltersByAppId(application.id.toString());
|
||||
this.selectTaskFilter(this.filterParam);
|
||||
},
|
||||
(err) => {
|
||||
|
@@ -595,12 +595,12 @@ describe('ActivitiProcessService', () => {
|
||||
|
||||
it('should call the API without an appId defined by default', () => {
|
||||
service.getProcessFilters(null);
|
||||
expect(getFilters).toHaveBeenCalledWith({});
|
||||
expect(getFilters).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call the API with the correct appId when specified', () => {
|
||||
service.getProcessFilters(226);
|
||||
expect(getFilters).toHaveBeenCalledWith({appId: 226});
|
||||
service.getProcessFilters('226');
|
||||
expect(getFilters).toHaveBeenCalledWith({appId: '226'});
|
||||
});
|
||||
|
||||
it('should return the task filter by id', (done) => {
|
||||
@@ -638,7 +638,7 @@ describe('ActivitiProcessService', () => {
|
||||
}));
|
||||
|
||||
it('should return the default filters', (done) => {
|
||||
service.createDefaultFilters(1234).subscribe(
|
||||
service.createDefaultFilters('1234').subscribe(
|
||||
(res: FilterProcessRepresentationModel []) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(3);
|
||||
|
@@ -68,11 +68,8 @@ export class ActivitiProcessService {
|
||||
}).catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
getProcessFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
|
||||
let filterOpts = appId ? {
|
||||
appId: appId
|
||||
} : {};
|
||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(filterOpts))
|
||||
getProcessFilters(appId: string): Observable<FilterProcessRepresentationModel[]> {
|
||||
return Observable.fromPromise(this.callApiProcessFilters(appId))
|
||||
.map((response: any) => {
|
||||
let filters: FilterProcessRepresentationModel[] = [];
|
||||
response.data.forEach((filter: FilterProcessRepresentationModel) => {
|
||||
@@ -103,7 +100,7 @@ export class ActivitiProcessService {
|
||||
* @returns {Observable<FilterProcessRepresentationModel>}
|
||||
*/
|
||||
getProcessFilterByName(processName: string, appId?: string): Observable<FilterProcessRepresentationModel> {
|
||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(appId))
|
||||
return Observable.fromPromise(this.callApiProcessFilters(appId))
|
||||
.map((response: any) => {
|
||||
return response.data.find(filter => filter.name === processName);
|
||||
}).catch(err => this.handleError(err));
|
||||
@@ -114,7 +111,7 @@ export class ActivitiProcessService {
|
||||
* @param appId
|
||||
* @returns {FilterProcessRepresentationModel[]}
|
||||
*/
|
||||
public createDefaultFilters(appId: number): Observable<FilterProcessRepresentationModel[]> {
|
||||
public createDefaultFilters(appId: string): Observable<FilterProcessRepresentationModel[]> {
|
||||
let runnintFilter = this.getRunningFilterInstance(appId);
|
||||
let runnintObservable = this.addFilter(runnintFilter);
|
||||
|
||||
@@ -150,7 +147,7 @@ export class ActivitiProcessService {
|
||||
});
|
||||
}
|
||||
|
||||
private getRunningFilterInstance(appId: number): FilterProcessRepresentationModel {
|
||||
private getRunningFilterInstance(appId: string): FilterProcessRepresentationModel {
|
||||
return new FilterProcessRepresentationModel({
|
||||
'name': 'Running',
|
||||
'appId': appId,
|
||||
@@ -165,7 +162,7 @@ export class ActivitiProcessService {
|
||||
* @param appId
|
||||
* @returns {FilterProcessRepresentationModel}
|
||||
*/
|
||||
private getCompletedFilterInstance(appId: number): FilterProcessRepresentationModel {
|
||||
private getCompletedFilterInstance(appId: string): FilterProcessRepresentationModel {
|
||||
return new FilterProcessRepresentationModel({
|
||||
'name': 'Completed',
|
||||
'appId': appId,
|
||||
@@ -180,7 +177,7 @@ export class ActivitiProcessService {
|
||||
* @param appId
|
||||
* @returns {FilterProcessRepresentationModel}
|
||||
*/
|
||||
private getAllFilterInstance(appId: number): FilterProcessRepresentationModel {
|
||||
private getAllFilterInstance(appId: string): FilterProcessRepresentationModel {
|
||||
return new FilterProcessRepresentationModel({
|
||||
'name': 'All',
|
||||
'appId': appId,
|
||||
@@ -328,10 +325,6 @@ export class ActivitiProcessService {
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
private callApiGetUserProcessInstanceFilters(filterOpts) {
|
||||
return this.apiService.getInstance().activiti.userFiltersApi.getUserProcessInstanceFilters(filterOpts);
|
||||
}
|
||||
|
||||
private callApiAddFilter(filter: FilterProcessRepresentationModel) {
|
||||
return this.apiService.getInstance().activiti.userFiltersApi.createUserProcessInstanceFilter(filter);
|
||||
}
|
||||
|
Reference in New Issue
Block a user