mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-6196] await-thenable rule for ESLint, fix issues (#9027)
* fix issues for core lib * fix content services lib * fix and cleanup process services * [ci:force] process services cloud * [ci:force] align coverage with all libs * [ci:force] fix the insights
This commit is contained in:
@@ -56,7 +56,7 @@ module.exports = function (config) {
|
||||
reporters: [{ type: 'html' }, { type: 'text-summary' }],
|
||||
check: {
|
||||
global: {
|
||||
statements: 80,
|
||||
statements: 75,
|
||||
branches: 67,
|
||||
functions: 70,
|
||||
lines: 75
|
||||
|
@@ -16,22 +16,17 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, throwError, of } from 'rxjs';
|
||||
import { AlfrescoApiService, LogService, GroupModel } from '@alfresco/adf-core';
|
||||
import { Observable, from, of } from 'rxjs';
|
||||
import { AlfrescoApiService, GroupModel } from '@alfresco/adf-core';
|
||||
import { BpmUserModel } from '../models/bpm-user.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { catchError, combineAll, defaultIfEmpty, map, switchMap } from 'rxjs/operators';
|
||||
import {
|
||||
TaskActionsApi,
|
||||
UsersApi,
|
||||
ResultListDataRepresentationLightUserRepresentation, ActivitiGroupsApi, UserProfileApi
|
||||
} from '@alfresco/js-api';
|
||||
import { combineAll, defaultIfEmpty, map, switchMap } from 'rxjs/operators';
|
||||
import { TaskActionsApi, UsersApi, ResultListDataRepresentationLightUserRepresentation, ActivitiGroupsApi, UserProfileApi } from '@alfresco/js-api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PeopleProcessService {
|
||||
|
||||
private _taskActionsApi: TaskActionsApi;
|
||||
get taskActionsApi(): TaskActionsApi {
|
||||
this._taskActionsApi = this._taskActionsApi ?? new TaskActionsApi(this.apiService.getInstance());
|
||||
@@ -56,9 +51,7 @@ export class PeopleProcessService {
|
||||
return this._profileApi;
|
||||
}
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
}
|
||||
constructor(private apiService: AlfrescoApiService) {}
|
||||
|
||||
/**
|
||||
* Gets information about the current user.
|
||||
@@ -66,11 +59,7 @@ export class PeopleProcessService {
|
||||
* @returns User information object
|
||||
*/
|
||||
getCurrentUserInfo(): Observable<BpmUserModel> {
|
||||
return from(this.profileApi.getProfile())
|
||||
.pipe(
|
||||
map((userRepresentation) => new BpmUserModel(userRepresentation)),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.profileApi.getProfile()).pipe(map((userRepresentation) => new BpmUserModel(userRepresentation)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,11 +83,7 @@ export class PeopleProcessService {
|
||||
if (groupId) {
|
||||
option.groupId = groupId;
|
||||
}
|
||||
return from(this.groupsApi.getGroups(option))
|
||||
.pipe(
|
||||
map((response: any) => response.data || []),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.groupsApi.getGroups(option)).pipe(map((response: any) => response.data || []));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,17 +97,15 @@ export class PeopleProcessService {
|
||||
getWorkflowUsers(taskId?: string, searchWord?: string, groupId?: string): Observable<UserProcessModel[]> {
|
||||
const option = { excludeTaskId: taskId, filter: searchWord, groupId };
|
||||
|
||||
return from(this.getWorkflowUserApi(option))
|
||||
.pipe(
|
||||
switchMap(response => response.data as UserProcessModel[] || []),
|
||||
map((user) => {
|
||||
user.userImage = this.getUserProfileImageApi(user.id.toString());
|
||||
return of(user);
|
||||
}),
|
||||
combineAll(),
|
||||
defaultIfEmpty([]),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.getWorkflowUserApi(option)).pipe(
|
||||
switchMap((response) => (response.data as UserProcessModel[]) || []),
|
||||
map((user) => {
|
||||
user.userImage = this.getUserProfileImageApi(user.id.toString());
|
||||
return of(user);
|
||||
}),
|
||||
combineAll(),
|
||||
defaultIfEmpty([])
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Gets the profile picture URL for the specified user.
|
||||
@@ -142,11 +125,7 @@ export class PeopleProcessService {
|
||||
* @returns Empty response when the update completes
|
||||
*/
|
||||
involveUserWithTask(taskId: string, idToInvolve: string): Observable<UserProcessModel[]> {
|
||||
const node = { userId: idToInvolve };
|
||||
return from(this.involveUserToTaskApi(taskId, node))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.involveUserToTaskApi(taskId, { userId: idToInvolve }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,11 +136,7 @@ export class PeopleProcessService {
|
||||
* @returns Empty response when the update completes
|
||||
*/
|
||||
removeInvolvedUser(taskId: string, idToRemove: string): Observable<UserProcessModel[]> {
|
||||
const node = { userId: idToRemove };
|
||||
return from(this.removeInvolvedUserFromTaskApi(taskId, node))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.removeInvolvedUserFromTaskApi(taskId, { userId: idToRemove }));
|
||||
}
|
||||
|
||||
private getWorkflowUserApi(options: any): Promise<ResultListDataRepresentationLightUserRepresentation> {
|
||||
@@ -179,9 +154,4 @@ export class PeopleProcessService {
|
||||
private getUserProfileImageApi(userId: string): string {
|
||||
return this.userApi.getUserProfilePictureUrl(userId);
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { from, of } from 'rxjs';
|
||||
import { from, of, throwError } from 'rxjs';
|
||||
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
|
||||
import { AppsProcessService } from '../../app-list/services/apps-process.service';
|
||||
import { ProcessFilterService } from '../services/process-filter.service';
|
||||
@@ -28,6 +28,7 @@ import { ProcessTestingModule } from '../../testing/process.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NavigationStart, Router } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { ProcessInstanceFilterRepresentation, UserProcessInstanceFilterRepresentation } from '@alfresco/js-api';
|
||||
|
||||
describe('ProcessFiltersComponent', () => {
|
||||
|
||||
@@ -62,14 +63,8 @@ describe('ProcessFiltersComponent', () => {
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
await filterList.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(filterList.filters).toBeDefined();
|
||||
expect(filterList.filters.length).toEqual(3);
|
||||
expect(filterList.filters[0].name).toEqual('FakeCompleted');
|
||||
expect(filterList.filters[1].name).toEqual('FakeAll');
|
||||
expect(filterList.filters[2].name).toEqual('Running');
|
||||
});
|
||||
let lastValue: ProcessInstanceFilterRepresentation[];
|
||||
filterList.success.subscribe((res) => lastValue = res);
|
||||
|
||||
spyOn(filterList, 'getFiltersByAppId').and.callThrough();
|
||||
|
||||
@@ -79,6 +74,14 @@ describe('ProcessFiltersComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(filterList.getFiltersByAppId).toHaveBeenCalled();
|
||||
|
||||
expect(lastValue).toBeDefined();
|
||||
expect(lastValue).toEqual(filterList.filters);
|
||||
expect(filterList.filters).toBeDefined();
|
||||
expect(filterList.filters.length).toEqual(3);
|
||||
expect(filterList.filters[0].name).toEqual('FakeCompleted');
|
||||
expect(filterList.filters[1].name).toEqual('FakeAll');
|
||||
expect(filterList.filters[2].name).toEqual('Running');
|
||||
});
|
||||
|
||||
it('should select the Running process filter', async () => {
|
||||
@@ -87,15 +90,13 @@ describe('ProcessFiltersComponent', () => {
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
await filterList.success.subscribe(() => {
|
||||
filterList.selectRunningFilter();
|
||||
expect(filterList.currentFilter.name).toEqual('Running');
|
||||
});
|
||||
|
||||
filterList.ngOnChanges({ appId: change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
filterList.selectRunningFilter();
|
||||
expect(filterList.currentFilter.name).toEqual('Running');
|
||||
});
|
||||
|
||||
it('should emit the selected filter based on the filterParam input', async () => {
|
||||
@@ -104,13 +105,14 @@ describe('ProcessFiltersComponent', () => {
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
await filterList.filterSelected.subscribe((filter) => {
|
||||
expect(filter.name).toEqual('FakeCompleted');
|
||||
});
|
||||
let lastValue: UserProcessInstanceFilterRepresentation;
|
||||
filterList.filterSelected.subscribe((filter) => lastValue = filter);
|
||||
|
||||
filterList.ngOnChanges({ appId: change });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(lastValue.name).toEqual('FakeCompleted');
|
||||
});
|
||||
|
||||
it('should filterClicked emit when a filter is clicked from the UI', async () => {
|
||||
@@ -143,50 +145,44 @@ describe('ProcessFiltersComponent', () => {
|
||||
expect(filterList.currentFilter).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should return the filter task list, filtered By Name', async () => {
|
||||
spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(Promise.resolve({ id: 1 })));
|
||||
it('should return the filter task list, filtered By Name', () => {
|
||||
const deployApp = spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(Promise.resolve({ id: 1 })));
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(fakeProcessFilters));
|
||||
|
||||
const change = new SimpleChange(null, 'test', true);
|
||||
filterList.ngOnChanges({ appName: change });
|
||||
|
||||
await filterList.success.subscribe((res) => {
|
||||
const deployApp: any = appsProcessService.getDeployedApplicationsByName;
|
||||
expect(deployApp.calls.count()).toEqual(1);
|
||||
expect(res).toBeDefined();
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(deployApp.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it('should emit an error with a bad response of getProcessFilters', async () => {
|
||||
const mockErrorFilterPromise = Promise.reject(new Error('wrong request'));
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(mockErrorFilterPromise));
|
||||
it('should emit an error with a bad response of getProcessFilters', () => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(throwError('error'));
|
||||
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
let lastValue: any;
|
||||
filterList.error.subscribe((err) => lastValue = err);
|
||||
|
||||
filterList.ngOnChanges({ appId: change });
|
||||
|
||||
await filterList.error.subscribe((err) => {
|
||||
expect(err).toBeDefined();
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(lastValue).toBeDefined();
|
||||
});
|
||||
|
||||
it('should emit an error with a bad response of getDeployedApplicationsByName', async () => {
|
||||
const mockErrorFilterPromise = Promise.reject(new Error('wrong request'));
|
||||
spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(from(mockErrorFilterPromise));
|
||||
it('should emit an error with a bad response of getDeployedApplicationsByName', () => {
|
||||
spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(throwError('wrong request'));
|
||||
|
||||
const appId = 'fake-app';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
let lastValue: any;
|
||||
filterList.error.subscribe((err) => lastValue = err);
|
||||
|
||||
filterList.ngOnChanges({ appName: change });
|
||||
|
||||
await filterList.error.subscribe((err) => {
|
||||
expect(err).toBeDefined();
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(lastValue).toBeDefined();
|
||||
});
|
||||
|
||||
it('should emit an event when a filter is selected', async () => {
|
||||
@@ -196,13 +192,13 @@ describe('ProcessFiltersComponent', () => {
|
||||
filter: { state: 'open', assignment: 'fake-involved' }
|
||||
});
|
||||
|
||||
await filterList.filterClicked.subscribe((filter) => {
|
||||
expect(filter).toBeDefined();
|
||||
expect(filter).toEqual(currentFilter);
|
||||
expect(filterList.currentFilter).toEqual(currentFilter);
|
||||
});
|
||||
let lastValue: UserProcessInstanceFilterRepresentation;
|
||||
filterList.filterClicked.subscribe((filter) => lastValue = filter);
|
||||
|
||||
filterList.selectFilter(currentFilter);
|
||||
expect(lastValue).toBeDefined();
|
||||
expect(lastValue).toEqual(currentFilter);
|
||||
expect(filterList.currentFilter).toEqual(currentFilter);
|
||||
});
|
||||
|
||||
it('should reload filters by appId on binding changes', () => {
|
||||
|
@@ -127,16 +127,16 @@ export class ProcessFiltersComponent implements OnInit, OnChanges, OnDestroy {
|
||||
*/
|
||||
getFiltersByAppId(appId?: number) {
|
||||
this.processFilterService.getProcessFilters(appId).subscribe(
|
||||
(res: ProcessInstanceFilterRepresentation[]) => {
|
||||
(res) => {
|
||||
if (res.length === 0 && this.isFilterListEmpty()) {
|
||||
this.processFilterService.createDefaultFilters(appId).subscribe(
|
||||
(resDefault: ProcessInstanceFilterRepresentation[]) => {
|
||||
(resDefault) => {
|
||||
this.resetFilter();
|
||||
this.filters = resDefault;
|
||||
this.selectProcessFilter(this.filterParam);
|
||||
this.success.emit(resDefault);
|
||||
},
|
||||
(errDefault: any) => {
|
||||
(errDefault) => {
|
||||
this.error.emit(errDefault);
|
||||
}
|
||||
);
|
||||
@@ -147,7 +147,7 @@ export class ProcessFiltersComponent implements OnInit, OnChanges, OnDestroy {
|
||||
this.success.emit(res);
|
||||
}
|
||||
},
|
||||
(err: any) => {
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
|
@@ -19,14 +19,7 @@ import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import {
|
||||
FormModel,
|
||||
FormOutcomeEvent,
|
||||
FormOutcomeModel,
|
||||
LogService,
|
||||
CommentModel,
|
||||
User
|
||||
} from '@alfresco/adf-core';
|
||||
import { FormModel, FormOutcomeEvent, FormOutcomeModel, CommentModel, User } from '@alfresco/adf-core';
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import {
|
||||
noDataMock,
|
||||
@@ -60,7 +53,6 @@ const fakeTaskAssignResponse = new TaskDetailsModel({
|
||||
});
|
||||
|
||||
describe('TaskDetailsComponent', () => {
|
||||
|
||||
let taskListService: TaskListService;
|
||||
let taskService: TaskService;
|
||||
let taskFormService: TaskFormService;
|
||||
@@ -70,7 +62,6 @@ describe('TaskDetailsComponent', () => {
|
||||
let getCommentsSpy: jasmine.Spy;
|
||||
let getTasksSpy: jasmine.Spy;
|
||||
let assignTaskSpy: jasmine.Spy;
|
||||
let logService: LogService;
|
||||
let taskCommentsService: TaskCommentsService;
|
||||
let peopleProcessService: PeopleProcessService;
|
||||
|
||||
@@ -82,7 +73,6 @@ describe('TaskDetailsComponent', () => {
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
logService = TestBed.inject(LogService);
|
||||
peopleProcessService = TestBed.inject(PeopleProcessService);
|
||||
|
||||
spyOn(peopleProcessService, 'getCurrentUserInfo').and.returnValue(of({ email: 'fake-email' } as any));
|
||||
@@ -130,14 +120,14 @@ describe('TaskDetailsComponent', () => {
|
||||
expect(getTaskDetailsSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should send a claim task event when a task is claimed', async () => {
|
||||
await component.claimedTask.subscribe((taskId) => {
|
||||
expect(taskId).toBe('FAKE-TASK-CLAIM');
|
||||
});
|
||||
it('should send a claim task event when a task is claimed', () => {
|
||||
let lastValue: string;
|
||||
component.claimedTask.subscribe((taskId) => lastValue = taskId);
|
||||
component.onClaimAction('FAKE-TASK-CLAIM');
|
||||
expect(lastValue).toBe('FAKE-TASK-CLAIM');
|
||||
});
|
||||
|
||||
it('should send a unclaim task event when a task is unclaimed', async () => {
|
||||
it('should send a unclaim task event when a task is unclaimed', () => {
|
||||
const taskUnclaimedSpy = spyOn(component.unClaimedTask, 'emit');
|
||||
component.onUnclaimAction('FAKE-TASK-UNCLAIM');
|
||||
|
||||
@@ -397,7 +387,7 @@ describe('TaskDetailsComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should return an observable with user search results', async () => {
|
||||
it('should return an observable with user search results', () => {
|
||||
spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(of([{
|
||||
id: 1,
|
||||
firstName: 'fake-test-1',
|
||||
@@ -410,32 +400,25 @@ describe('TaskDetailsComponent', () => {
|
||||
email: 'fake-test-2@test.com'
|
||||
}]));
|
||||
|
||||
await component.peopleSearch.subscribe((users) => {
|
||||
expect(users.length).toBe(2);
|
||||
expect(users[0].firstName).toBe('fake-test-1');
|
||||
expect(users[0].lastName).toBe('fake-last-1');
|
||||
expect(users[0].email).toBe('fake-test-1@test.com');
|
||||
expect(users[0].id).toBe(1);
|
||||
});
|
||||
let lastValue: UserProcessModel[];
|
||||
component.peopleSearch.subscribe((users) => lastValue = users);
|
||||
component.searchUser('fake-search-word');
|
||||
|
||||
expect(lastValue.length).toBe(2);
|
||||
expect(lastValue[0].firstName).toBe('fake-test-1');
|
||||
expect(lastValue[0].lastName).toBe('fake-last-1');
|
||||
expect(lastValue[0].email).toBe('fake-test-1@test.com');
|
||||
expect(lastValue[0].id).toBe(1);
|
||||
});
|
||||
|
||||
it('should return an empty list for not valid search', async () => {
|
||||
it('should return an empty list for not valid search', () => {
|
||||
spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(of([]));
|
||||
|
||||
await component.peopleSearch.subscribe((users) => {
|
||||
expect(users.length).toBe(0);
|
||||
});
|
||||
let lastValue: UserProcessModel[];
|
||||
component.peopleSearch.subscribe((users) => lastValue = users);
|
||||
component.searchUser('fake-search-word');
|
||||
});
|
||||
|
||||
it('should log error message when search fails', async () => {
|
||||
const logServiceErrorSpy = spyOn(logService, 'error');
|
||||
|
||||
spyOn(peopleProcessService, 'getWorkflowUsers').and.returnValue(throwError('fake-error'));
|
||||
component.searchUser('fake-search');
|
||||
|
||||
expect(logServiceErrorSpy).toHaveBeenCalledWith('Could not load users');
|
||||
expect(lastValue.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should assign task to user', () => {
|
||||
|
@@ -19,7 +19,7 @@ import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AppsProcessService } from '../../app-list/services/apps-process.service';
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { from, of } from 'rxjs';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { FilterParamsModel, FilterRepresentationModel } from '../models/filter.model';
|
||||
import { TaskListService } from '../services/tasklist.service';
|
||||
import { TaskFilterService } from '../services/task-filter.service';
|
||||
@@ -60,37 +60,35 @@ describe('TaskFiltersComponent', () => {
|
||||
router = TestBed.inject(Router);
|
||||
});
|
||||
|
||||
it('should emit an error with a bad response', async () => {
|
||||
const mockErrorFilterList = {
|
||||
error: 'wrong request'
|
||||
};
|
||||
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise));
|
||||
it('should emit an error with a bad response', () => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(throwError('wrong request'));
|
||||
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
component.ngOnChanges({ appId: change });
|
||||
|
||||
await component.error.subscribe((err) => {
|
||||
expect(err).toBeDefined();
|
||||
});
|
||||
let lastError: any;
|
||||
component.error.subscribe((err) => lastError = err);
|
||||
|
||||
component.ngOnChanges({ appId: change });
|
||||
expect(lastError).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return the filter task list', async () => {
|
||||
it('should return the filter task list', () => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters));
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
await component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters.length).toEqual(3);
|
||||
expect(component.filters[0].name).toEqual('FakeInvolvedTasks');
|
||||
expect(component.filters[1].name).toEqual('FakeMyTasks1');
|
||||
expect(component.filters[2].name).toEqual('FakeMyTasks2');
|
||||
});
|
||||
let lastValue: any;
|
||||
component.success.subscribe((res) => lastValue = res);
|
||||
|
||||
component.ngOnChanges({ appId: change });
|
||||
|
||||
expect(lastValue).toBeDefined();
|
||||
expect(component.filters).toBeDefined();
|
||||
expect(component.filters.length).toEqual(3);
|
||||
expect(component.filters[0].name).toEqual('FakeInvolvedTasks');
|
||||
expect(component.filters[1].name).toEqual('FakeMyTasks1');
|
||||
expect(component.filters[2].name).toEqual('FakeMyTasks2');
|
||||
});
|
||||
|
||||
it('Should call the API to create the default task filters when no task filters exist', async () => {
|
||||
@@ -105,52 +103,54 @@ describe('TaskFiltersComponent', () => {
|
||||
expect(createDefaultFiltersSpy).toHaveBeenCalledWith(appId);
|
||||
});
|
||||
|
||||
it('should return the filter task list, filtered By Name', async () => {
|
||||
spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(of({} as any));
|
||||
it('should return the filter task list, filtered By Name', () => {
|
||||
const deployApp = spyOn(appsProcessService, 'getDeployedApplicationsByName').and.returnValue(of({} as any));
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters));
|
||||
|
||||
const change = new SimpleChange(null, 'test', true);
|
||||
|
||||
await component.success.subscribe((res) => {
|
||||
const deployApp: any = appsProcessService.getDeployedApplicationsByName;
|
||||
expect(deployApp.calls.count()).toEqual(1);
|
||||
expect(res).toBeDefined();
|
||||
});
|
||||
let lastValue: any;
|
||||
component.success.subscribe((res) => lastValue = res);
|
||||
|
||||
component.ngOnChanges({ appName: change });
|
||||
|
||||
expect(deployApp.calls.count()).toEqual(1);
|
||||
expect(lastValue).toBeDefined();
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by name param', async () => {
|
||||
it('should select the task filter based on the input by name param', () => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters));
|
||||
component.filterParam = new FilterParamsModel({ name: 'FakeMyTasks1' });
|
||||
|
||||
await component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks1');
|
||||
});
|
||||
let lastValue: any;
|
||||
component.success.subscribe((res) => lastValue = res);
|
||||
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
component.ngOnChanges({ appId: change });
|
||||
|
||||
expect(lastValue).toBeDefined();
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks1');
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by index param', async () => {
|
||||
it('should select the task filter based on the input by index param', () => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters));
|
||||
component.filterParam = new FilterParamsModel({ index: 2 });
|
||||
|
||||
await component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
|
||||
});
|
||||
let lastValue: any;
|
||||
component.success.subscribe((res) => lastValue = res);
|
||||
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
component.ngOnChanges({ appId: change });
|
||||
|
||||
expect(lastValue).toBeDefined();
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
|
||||
});
|
||||
|
||||
it('should select the task filter based on the input by id param', async () => {
|
||||
it('should select the task filter based on the input by id param', () => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeTaskFilters));
|
||||
|
||||
component.filterParam = new FilterParamsModel({ id: 10 });
|
||||
@@ -158,13 +158,14 @@ describe('TaskFiltersComponent', () => {
|
||||
const appId = '1';
|
||||
const change = new SimpleChange(null, appId, true);
|
||||
|
||||
await component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
|
||||
});
|
||||
let lastValue: any;
|
||||
component.success.subscribe((res) => lastValue = res);
|
||||
|
||||
component.ngOnChanges({ appId: change });
|
||||
|
||||
expect(lastValue).toBeDefined();
|
||||
expect(component.currentFilter).toBeDefined();
|
||||
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
|
||||
});
|
||||
|
||||
it('should emit the selected filter based on the filterParam input', () => {
|
||||
|
@@ -18,74 +18,27 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { of } from 'rxjs';
|
||||
import {
|
||||
fakeCompletedTaskList,
|
||||
fakeFormList,
|
||||
fakeOpenTaskList,
|
||||
fakeTaskDetails,
|
||||
fakeTaskList,
|
||||
fakeTasksChecklist,
|
||||
fakeUser1,
|
||||
fakeUser2,
|
||||
secondFakeTaskList
|
||||
} from '../../mock';
|
||||
import { fakeFilter, fakeRepresentationFilter1, fakeRepresentationFilter2 } from '../../mock/task/task-filters.mock';
|
||||
import { FilterRepresentationModel } from '../models/filter.model';
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import { fakeCompletedTaskList, fakeOpenTaskList, fakeTaskList } from '../../mock';
|
||||
import { fakeFilter } from '../../mock/task/task-filters.mock';
|
||||
import { TaskListService } from './tasklist.service';
|
||||
import { TaskRepresentation, TaskUpdateRepresentation } from '@alfresco/js-api';
|
||||
import { ProcessTestingModule } from '../../testing/process.testing.module';
|
||||
import { UserProcessModel } from '../../common/models/user-process.model';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('Activiti TaskList Service', () => {
|
||||
let service: TaskListService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
ProcessTestingModule
|
||||
]
|
||||
imports: [CoreModule.forRoot(), ProcessTestingModule]
|
||||
});
|
||||
service = TestBed.inject(TaskListService);
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
describe('Content tests', () => {
|
||||
|
||||
it('should return the task list filtered', (done) => {
|
||||
service.getTasks(fakeFilter).subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.size).toEqual(1);
|
||||
expect(res.start).toEqual(0);
|
||||
expect(res.data).toBeDefined();
|
||||
expect(res.data.length).toEqual(1);
|
||||
expect(res.data[0].name).toEqual('FakeNameTask');
|
||||
expect(res.data[0].assignee.email).toEqual('fake-email@dom.com');
|
||||
expect(res.data[0].assignee.firstName).toEqual('firstName');
|
||||
expect(res.data[0].assignee.lastName).toEqual('lastName');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTaskList)
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the task list with all tasks filtered by state', (done) => {
|
||||
spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList));
|
||||
spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList));
|
||||
|
||||
service.findAllTaskByState(fakeFilter, 'open').subscribe((res) => {
|
||||
|
||||
expect(res).toBeDefined();
|
||||
expect(res.size).toEqual(1);
|
||||
expect(res.start).toEqual(0);
|
||||
@@ -117,27 +70,6 @@ describe('Activiti TaskList Service', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the task list filtered by state', (done) => {
|
||||
service.findTasksByState(fakeFilter, 'open').subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.size).toEqual(1);
|
||||
expect(res.start).toEqual(0);
|
||||
expect(res.data).toBeDefined();
|
||||
expect(res.data.length).toEqual(1);
|
||||
expect(res.data[0].name).toEqual('FakeNameTask');
|
||||
expect(res.data[0].assignee.email).toEqual('fake-email@dom.com');
|
||||
expect(res.data[0].assignee.firstName).toEqual('firstName');
|
||||
expect(res.data[0].assignee.lastName).toEqual('lastName');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTaskList)
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the task list with all tasks filtered without state', (done) => {
|
||||
spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList));
|
||||
spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList));
|
||||
@@ -190,325 +122,5 @@ describe('Activiti TaskList Service', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the task details ', (done) => {
|
||||
service.getTaskDetails('999').subscribe((res: TaskDetailsModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).toEqual('999');
|
||||
expect(res.name).toEqual('fake-task-name');
|
||||
expect(res.formKey).toEqual('99');
|
||||
expect(res.assignee).toBeDefined();
|
||||
expect(res.assignee.email).toEqual('fake-email@dom.com');
|
||||
expect(res.assignee.firstName).toEqual('firstName');
|
||||
expect(res.assignee.lastName).toEqual('lastName');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTaskDetails)
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the tasks checklists ', (done) => {
|
||||
service.getTaskChecklist('999').subscribe((res: TaskDetailsModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res[0].name).toEqual('FakeCheckTask1');
|
||||
expect(res[0].assignee.email).toEqual('fake-email@dom.com');
|
||||
expect(res[0].assignee.firstName).toEqual('firstName');
|
||||
expect(res[0].assignee.lastName).toEqual('lastName');
|
||||
expect(res[1].name).toEqual('FakeCheckTask2');
|
||||
expect(res[1].assignee.email).toEqual('fake-email@dom.com');
|
||||
expect(res[1].assignee.firstName).toEqual('firstName');
|
||||
expect(res[0].assignee.lastName).toEqual('lastName');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTasksChecklist)
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a task ', (done) => {
|
||||
const taskFake = new TaskDetailsModel({
|
||||
id: 123,
|
||||
parentTaskId: 456,
|
||||
name: 'FakeNameTask',
|
||||
description: null,
|
||||
category: null,
|
||||
assignee: fakeUser1,
|
||||
created: ''
|
||||
});
|
||||
|
||||
service.addTask(taskFake).subscribe((res: TaskDetailsModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual('');
|
||||
expect(res.name).toEqual('FakeNameTask');
|
||||
expect(res.created).not.toEqual(null);
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: '777', name: 'FakeNameTask', description: null, category: null,
|
||||
assignee: fakeUser1,
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove a checklist task ', async () => {
|
||||
await service.deleteTask('999').subscribe((res) => {
|
||||
expect(res).toEqual({});
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({})
|
||||
});
|
||||
});
|
||||
|
||||
it('should complete the task', async () => {
|
||||
await service.completeTask('999').subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toEqual({});
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({})
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the total number of tasks', async () => {
|
||||
await service.getTotalTasks(fakeFilter).subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.size).toEqual(1);
|
||||
expect(res.total).toEqual(1);
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTaskList)
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a new standalone task ', async () => {
|
||||
const taskFake = new TaskDetailsModel({
|
||||
name: 'FakeNameTask',
|
||||
description: 'FakeDescription',
|
||||
category: '3'
|
||||
});
|
||||
|
||||
await service.createNewTask(taskFake).subscribe((res: TaskDetailsModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual('');
|
||||
expect(res.name).toEqual('FakeNameTask');
|
||||
expect(res.description).toEqual('FakeDescription');
|
||||
expect(res.category).toEqual('3');
|
||||
expect(res.created).not.toEqual(null);
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: '777',
|
||||
name: 'FakeNameTask',
|
||||
description: 'FakeDescription',
|
||||
category: '3',
|
||||
assignee: fakeUser1,
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should assign task to a user', async () => {
|
||||
const testTaskId = '8888';
|
||||
await service.assignTask(testTaskId, fakeUser2).subscribe((res: TaskDetailsModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).toEqual(testTaskId);
|
||||
expect(res.name).toEqual('FakeNameTask');
|
||||
expect(res.description).toEqual('FakeDescription');
|
||||
expect(res.category).toEqual('3');
|
||||
expect(res.created).not.toEqual(null);
|
||||
expect(res.adhocTaskCanBeReassigned).toBe(true);
|
||||
expect(res.assignee).toEqual(new UserProcessModel(fakeUser2));
|
||||
expect(res.involvedPeople[0].email).toEqual(fakeUser1.email);
|
||||
expect(res.involvedPeople[0].firstName).toEqual(fakeUser1.firstName);
|
||||
expect(res.involvedPeople[0].lastName).toEqual(fakeUser1.lastName);
|
||||
expect(res.involvedPeople[0].id).toEqual(fakeUser1.id);
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: testTaskId,
|
||||
name: 'FakeNameTask',
|
||||
description: 'FakeDescription',
|
||||
adhocTaskCanBeReassigned: true,
|
||||
category: '3',
|
||||
assignee: fakeUser2,
|
||||
involvedPeople: [fakeUser1],
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should assign task to a userId', async () => {
|
||||
const testTaskId = '8888';
|
||||
await service.assignTaskByUserId(testTaskId, fakeUser2.id.toString()).subscribe((res: TaskDetailsModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).toEqual(testTaskId);
|
||||
expect(res.name).toEqual('FakeNameTask');
|
||||
expect(res.description).toEqual('FakeDescription');
|
||||
expect(res.category).toEqual('3');
|
||||
expect(res.created).not.toEqual(null);
|
||||
expect(res.adhocTaskCanBeReassigned).toBe(true);
|
||||
expect(res.assignee).toEqual(new UserProcessModel(fakeUser2));
|
||||
expect(res.involvedPeople[0].email).toEqual(fakeUser1.email);
|
||||
expect(res.involvedPeople[0].firstName).toEqual(fakeUser1.firstName);
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: testTaskId,
|
||||
name: 'FakeNameTask',
|
||||
description: 'FakeDescription',
|
||||
adhocTaskCanBeReassigned: true,
|
||||
category: '3',
|
||||
assignee: fakeUser2,
|
||||
involvedPeople: [fakeUser1],
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should claim a task', async () => {
|
||||
const taskId = '111';
|
||||
|
||||
await service.claimTask(taskId).subscribe((res) => {
|
||||
expect(res).toEqual({});
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({})
|
||||
});
|
||||
});
|
||||
|
||||
it('should unclaim a task', async () => {
|
||||
const taskId = '111';
|
||||
|
||||
await service.unclaimTask(taskId).subscribe((res) => {
|
||||
expect(res).toEqual({});
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({})
|
||||
});
|
||||
});
|
||||
|
||||
it('should update a task', async () => {
|
||||
const taskId = '111';
|
||||
const updated: TaskUpdateRepresentation = {
|
||||
name: 'someName'
|
||||
};
|
||||
|
||||
await service.updateTask(taskId, updated).subscribe((res) => {
|
||||
expect(res).toEqual(new TaskRepresentation({}));
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({})
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the filter if it contains task id', async () => {
|
||||
const taskId = '1';
|
||||
const filterFake = new FilterRepresentationModel({
|
||||
name: 'FakeNameFilter',
|
||||
assignment: 'fake-assignment',
|
||||
filter: {
|
||||
processDefinitionKey: '1',
|
||||
assignment: 'fake',
|
||||
state: 'none',
|
||||
sort: 'asc'
|
||||
}
|
||||
});
|
||||
|
||||
await service.isTaskRelatedToFilter(taskId, filterFake).subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).not.toBeNull();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTaskList)
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the filters if it contains task id', async () => {
|
||||
const taskId = '1';
|
||||
|
||||
const fakeFilterList: FilterRepresentationModel[] = [];
|
||||
fakeFilterList.push(fakeRepresentationFilter1, fakeRepresentationFilter2);
|
||||
let resultFilter: FilterRepresentationModel = null;
|
||||
await service.getFilterForTaskById(taskId, fakeFilterList).subscribe((res: FilterRepresentationModel) => {
|
||||
resultFilter = res;
|
||||
}, () => {
|
||||
}, () => {
|
||||
expect(resultFilter).toBeDefined();
|
||||
expect(resultFilter).not.toBeNull();
|
||||
expect(resultFilter.name).toBe('CONTAIN FILTER');
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.at(0).respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTaskList)
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.at(1).respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(secondFakeTaskList)
|
||||
});
|
||||
});
|
||||
|
||||
it('should get possible form list', async () => {
|
||||
await service.getFormList().subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toBe(2);
|
||||
expect(res[0].id).toBe(1);
|
||||
expect(res[0].name).toBe('form with all widgets');
|
||||
expect(res[1].id).toBe(2);
|
||||
expect(res[1].name).toBe('uppy');
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeFormList)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, forkJoin, throwError, of } from 'rxjs';
|
||||
import { Observable, from, forkJoin, of } from 'rxjs';
|
||||
import { map, catchError, switchMap, flatMap, filter } from 'rxjs/operators';
|
||||
import { FilterRepresentationModel, TaskQueryRequestRepresentationModel } from '../models/filter.model';
|
||||
import { Form } from '../models/form.model';
|
||||
@@ -57,8 +57,7 @@ export class TaskListService {
|
||||
return this._checklistsApi;
|
||||
}
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
constructor(private apiService: AlfrescoApiService) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +86,7 @@ export class TaskListService {
|
||||
const requestNodeForFilter = this.generateTaskRequestNodeFromFilter(filterModel);
|
||||
return from(this.callApiTasksFiltered(requestNodeForFilter))
|
||||
.pipe(
|
||||
map(res => res.data.find((element) => element.id === taskId) ? filterModel : null),
|
||||
catchError((err) => this.handleError(err))
|
||||
map(res => res.data.find((element) => element.id === taskId) ? filterModel : null)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,10 +97,7 @@ export class TaskListService {
|
||||
* @returns List of tasks
|
||||
*/
|
||||
getTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<TaskListModel> {
|
||||
return from(this.callApiTasksFiltered(requestNode))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.callApiTasksFiltered(requestNode));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,8 +163,7 @@ export class TaskListService {
|
||||
getTaskDetails(taskId: string): Observable<TaskDetailsModel> {
|
||||
return from(this.callApiTaskDetails(taskId))
|
||||
.pipe(
|
||||
map(details => new TaskDetailsModel(details)),
|
||||
catchError((err) => this.handleError(err))
|
||||
map(details => new TaskDetailsModel(details))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -188,8 +182,7 @@ export class TaskListService {
|
||||
checklists.push(new TaskDetailsModel(checklist));
|
||||
});
|
||||
return checklists;
|
||||
}),
|
||||
catchError((err) => this.handleError(err))
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -213,8 +206,7 @@ export class TaskListService {
|
||||
forms.push(new Form(form.id, form.name));
|
||||
});
|
||||
return forms;
|
||||
}),
|
||||
catchError((err) => this.handleError(err))
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -226,10 +218,7 @@ export class TaskListService {
|
||||
* @returns Null response notifying when the operation is complete
|
||||
*/
|
||||
attachFormToATask(taskId: string, formId: number): Observable<any> {
|
||||
return from(this.taskActionsApi.attachForm(taskId, { formId }))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.taskActionsApi.attachForm(taskId, { formId }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,8 +230,7 @@ export class TaskListService {
|
||||
addTask(task: TaskDetailsModel): Observable<TaskDetailsModel> {
|
||||
return from(this.callApiAddTask(task))
|
||||
.pipe(
|
||||
map((response) => new TaskDetailsModel(response)),
|
||||
catchError((err) => this.handleError(err))
|
||||
map((response) => new TaskDetailsModel(response))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -253,10 +241,7 @@ export class TaskListService {
|
||||
* @returns Null response notifying when the operation is complete
|
||||
*/
|
||||
deleteTask(taskId: string): Observable<TaskDetailsModel> {
|
||||
return from(this.callApiDeleteTask(taskId))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.callApiDeleteTask(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,10 +251,7 @@ export class TaskListService {
|
||||
* @returns Null response notifying when the operation is complete
|
||||
*/
|
||||
deleteForm(taskId: string): Observable<TaskDetailsModel> {
|
||||
return from(this.callApiDeleteForm(taskId))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.callApiDeleteForm(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,10 +261,7 @@ export class TaskListService {
|
||||
* @returns Null response notifying when the operation is complete
|
||||
*/
|
||||
completeTask(taskId: string) {
|
||||
return from(this.taskActionsApi.completeTask(taskId))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.taskActionsApi.completeTask(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,12 +270,9 @@ export class TaskListService {
|
||||
* @param requestNode Query to search for tasks
|
||||
* @returns Number of tasks
|
||||
*/
|
||||
public getTotalTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<any> {
|
||||
public getTotalTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<TaskListModel> {
|
||||
requestNode.size = 0;
|
||||
return from(this.callApiTasksFiltered(requestNode))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.callApiTasksFiltered(requestNode));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,8 +284,7 @@ export class TaskListService {
|
||||
createNewTask(task: TaskDetailsModel): Observable<TaskDetailsModel> {
|
||||
return from(this.callApiCreateTask(task))
|
||||
.pipe(
|
||||
map((response) => new TaskDetailsModel(response)),
|
||||
catchError((err) => this.handleError(err))
|
||||
map((response) => new TaskDetailsModel(response))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -324,8 +299,7 @@ export class TaskListService {
|
||||
const assignee = { assignee: requestNode.id };
|
||||
return from(this.callApiAssignTask(taskId, assignee))
|
||||
.pipe(
|
||||
map((response) => new TaskDetailsModel(response)),
|
||||
catchError((err) => this.handleError(err))
|
||||
map((response) => new TaskDetailsModel(response))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -341,8 +315,7 @@ export class TaskListService {
|
||||
|
||||
return from(this.callApiAssignTask(taskId, assignee))
|
||||
.pipe(
|
||||
map((response) => new TaskDetailsModel(response)),
|
||||
catchError((err) => this.handleError(err))
|
||||
map((response) => new TaskDetailsModel(response))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -353,10 +326,7 @@ export class TaskListService {
|
||||
* @returns Details of the claimed task
|
||||
*/
|
||||
claimTask(taskId: string): Observable<TaskDetailsModel> {
|
||||
return from(this.taskActionsApi.claimTask(taskId))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.taskActionsApi.claimTask(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,10 +336,7 @@ export class TaskListService {
|
||||
* @returns Null response notifying when the operation is complete
|
||||
*/
|
||||
unclaimTask(taskId: string): Observable<TaskDetailsModel> {
|
||||
return from(this.taskActionsApi.unclaimTask(taskId))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.taskActionsApi.unclaimTask(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,8 +349,7 @@ export class TaskListService {
|
||||
updateTask(taskId: string, updated: TaskUpdateRepresentation): Observable<TaskDetailsModel> {
|
||||
return from(this.tasksApi.updateTask(taskId, updated))
|
||||
.pipe(
|
||||
map((result) => result as TaskDetailsModel),
|
||||
catchError((err) => this.handleError(err))
|
||||
map((result) => result as TaskDetailsModel)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -394,11 +360,7 @@ export class TaskListService {
|
||||
* @returns Binary PDF data
|
||||
*/
|
||||
fetchTaskAuditPdfById(taskId: string): Observable<Blob> {
|
||||
return from(this.tasksApi.getTaskAuditPdf(taskId))
|
||||
.pipe(
|
||||
map((data) => data as Blob),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.tasksApi.getTaskAuditPdf(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -408,10 +370,7 @@ export class TaskListService {
|
||||
* @returns JSON data
|
||||
*/
|
||||
fetchTaskAuditJsonById(taskId: string): Observable<any> {
|
||||
return from(this.tasksApi.getTaskAuditLog(taskId))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
return from(this.tasksApi.getTaskAuditLog(taskId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,10 +420,4 @@ export class TaskListService {
|
||||
private callApiAssignTask(taskId: string, requestNode: AssigneeIdentifierRepresentation): Promise<TaskDetailsModel> {
|
||||
return this.taskActionsApi.assignTask(taskId, requestNode);
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user