diff --git a/docs/process-services/services/tasklist.service.md b/docs/process-services/services/tasklist.service.md index 86214e5e786..5dcad0e6b54 100644 --- a/docs/process-services/services/tasklist.service.md +++ b/docs/process-services/services/tasklist.service.md @@ -60,19 +60,15 @@ Manages Task Instances. Fetches the Task Audit information in PDF format. - _taskId:_ `string` - ID of the target task - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)`>` - Binary PDF data -- **findAllTaskByState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts), state?: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`
+- **findAllTasksByState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts), state?: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`
Gets all tasks matching a query and state value. - _requestNode:_ [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts) - Query to search for tasks. - - _state:_ `string` - (Optional) Task state. Can be "open" or "completed". - - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>` - List of tasks -- **findAllTasksWithoutState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`
- Gets all tasks matching the supplied query but ignoring the task state. - - _requestNode:_ [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts) - Query to search for tasks + - _state:_ `string` - (Optional) Task state. Can be "open" or "completed". State "all" applies to both "active" and "completed" tasks. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>` - List of tasks - **findTasksByState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts), state?: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`
Gets tasks matching a query and state value. - _requestNode:_ [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts) - Query to search for tasks - - _state:_ `string` - (Optional) Task state. Can be "open" or "completed". + - _state:_ `string` - (Optional) Task state. Can be "open" or "completed". State "all" applies to both "active" and "completed" tasks. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>` - List of tasks - **getFilterForTaskById**(taskId: `string`, filterList: [`FilterRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts)`[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`FilterRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts)`>`
Gets all the filters in the list that belong to a task. diff --git a/lib/process-services/src/lib/mock/task/task-filters.mock.ts b/lib/process-services/src/lib/mock/task/task-filters.mock.ts index 55f0178448f..6d36ff9becd 100644 --- a/lib/process-services/src/lib/mock/task/task-filters.mock.ts +++ b/lib/process-services/src/lib/mock/task/task-filters.mock.ts @@ -82,6 +82,12 @@ export const fakeFilter: TaskQueryRequestRepresentationModel = { assignment: 'fake-assignee' }; +export const mockFilterNoState: TaskQueryRequestRepresentationModel = { + sort: 'created-desc', + text: '', + assignment: 'fake-assignee' +}; + export const fakeRepresentationFilter1: FilterRepresentationModel = new FilterRepresentationModel({ appId: 1, name: 'CONTAIN FILTER', diff --git a/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts b/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts index 84177c221ba..a2032cb2225 100644 --- a/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts +++ b/lib/process-services/src/lib/mock/task/tasklist-service.mock.ts @@ -20,8 +20,6 @@ import { fakeAppFilter } from './task-filters.mock'; export const fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' }; -export const fakeUser2 = { id: 1001, email: 'some-one@somegroup.com', firstName: 'some', lastName: 'one' }; - export const fakeTaskList = new TaskListModel({ size: 1, total: 1, @@ -37,151 +35,4 @@ export const fakeTaskList = new TaskListModel({ } ] }); - -export const secondFakeTaskList = { - size: 1, - total: 1, - start: 0, - data: [ - { - id: '200', - name: 'FakeNameTask', - description: null, - category: null, - assignee: fakeUser1, - created: '2016-07-15T11:19:17.440+0000' - } - ] -}; - -export const fakeTaskDetails = { id: '999', name: 'fake-task-name', formKey: '99', assignee: fakeUser1 }; - -export const fakeTasksChecklist = { - size: 1, - total: 1, - start: 0, - data: [ - { - id: 1, - name: 'FakeCheckTask1', - description: null, - category: null, - assignee: fakeUser1, - created: '2016-07-15T11:19:17.440+0000' - }, - { - id: 2, - name: 'FakeCheckTask2', - description: null, - category: null, - assignee: fakeUser1, - created: '2016-07-15T11:19:17.440+0000' - } - ] -}; - export const fakeAppPromise = Promise.resolve(fakeAppFilter); - -export const fakeFormList = { - size: 2, - total: 2, - start: 0, - data: [ - { - id: 1, - name: 'form with all widgets', - description: '', - createdBy: 2, - createdByFullName: 'Admin Admin', - lastUpdatedBy: 2, - lastUpdatedByFullName: 'Admin Admin', - lastUpdated: 1491400951205, - latestVersion: true, - version: 4, - comment: null, - stencilSet: null, - referenceId: null, - modelType: 2, - favorite: null, - permission: 'write', - tenantId: null - }, - { - id: 2, - name: 'uppy', - description: '', - createdBy: 2, - createdByFullName: 'Admin Admin', - lastUpdatedBy: 2, - lastUpdatedByFullName: 'Admin Admin', - lastUpdated: 1490951054477, - latestVersion: true, - version: 2, - comment: null, - stencilSet: null, - referenceId: null, - modelType: 2, - favorite: null, - permission: 'write', - tenantId: null - } - ] -}; - -export const fakeTaskOpen1 = { - id: '1', - name: 'FakeOpenTask1', - description: null, - category: null, - assignee: fakeUser1, - created: '2017-07-15T11:19:17.440+0000', - dueDate: null, - endDate: null -}; - -export const fakeTaskOpen2 = { - id: '1', - name: 'FakeOpenTask2', - description: null, - category: null, - assignee: { id: 1, email: 'fake-open-email@dom.com', firstName: 'firstName', lastName: 'lastName' }, - created: '2017-07-15T11:19:17.440+0000', - dueDate: null, - endDate: null -}; - -export const fakeTaskCompleted1 = { - id: '1', - name: 'FakeCompletedTaskName1', - description: null, - category: null, - assignee: { id: 1, email: 'fake-completed-email@dom.com', firstName: 'firstName', lastName: 'lastName' }, - created: '2016-07-15T11:19:17.440+0000', - dueDate: null, - endDate: '2016-11-03T15:25:42.749+0000' -}; - -export const fakeTaskCompleted2 = { - id: '1', - name: 'FakeCompletedTaskName2', - description: null, - category: null, - assignee: fakeUser1, - created: null, - dueDate: null, - endDate: '2016-11-03T15:25:42.749+0000' -}; - -export const fakeOpenTaskList = new TaskListModel({ - size: 2, - total: 2, - start: 0, - data: [fakeTaskOpen1, fakeTaskOpen2] -}); - -export const fakeCompletedTaskList = new TaskListModel({ - size: 2, - total: 2, - start: 0, - data: [fakeTaskCompleted1, fakeTaskCompleted2] -}); diff --git a/lib/process-services/src/lib/task-list/components/task-list.component.ts b/lib/process-services/src/lib/task-list/components/task-list.component.ts index b87b69a3f2e..a71e9a8f7a2 100644 --- a/lib/process-services/src/lib/task-list/components/task-list.component.ts +++ b/lib/process-services/src/lib/task-list/components/task-list.component.ts @@ -406,9 +406,7 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft } private loadTasksByState(): Observable { - return this.requestNode.state === 'all' - ? this.taskListService.findAllTasksWithoutState(this.requestNode) - : this.taskListService.findTasksByState(this.requestNode); + return this.taskListService.findTasksByState(this.requestNode); } /** diff --git a/lib/process-services/src/lib/task-list/services/tasklist.service.spec.ts b/lib/process-services/src/lib/task-list/services/tasklist.service.spec.ts index 8f1fd39bca1..921695ba593 100644 --- a/lib/process-services/src/lib/task-list/services/tasklist.service.spec.ts +++ b/lib/process-services/src/lib/task-list/services/tasklist.service.spec.ts @@ -18,10 +18,10 @@ import { TestBed } from '@angular/core/testing'; import { CoreModule } from '@alfresco/adf-core'; import { of } from 'rxjs'; -import { fakeCompletedTaskList, fakeOpenTaskList, fakeTaskList } from '../../mock'; -import { fakeFilter } from '../../mock/task/task-filters.mock'; +import { fakeFilter, mockFilterNoState } from '../../mock/task/task-filters.mock'; import { TaskListService } from './tasklist.service'; import { ProcessTestingModule } from '../../testing/process.testing.module'; +import { fakeTaskList } from '../../mock'; describe('Activiti TaskList Service', () => { let service: TaskListService; @@ -38,7 +38,7 @@ describe('Activiti TaskList Service', () => { spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList)); spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList)); - service.findAllTaskByState(fakeFilter, 'open').subscribe((res) => { + service.findAllTasksByState(fakeFilter, 'open').subscribe((res) => { expect(res).toBeDefined(); expect(res.size).toEqual(1); expect(res.start).toEqual(0); @@ -56,7 +56,7 @@ describe('Activiti TaskList Service', () => { spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList)); spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList)); - service.findAllTaskByState(fakeFilter).subscribe((res) => { + service.findAllTasksByState(fakeFilter).subscribe((res) => { expect(res).toBeDefined(); expect(res.size).toEqual(1); expect(res.start).toEqual(0); @@ -74,51 +74,11 @@ describe('Activiti TaskList Service', () => { spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList)); spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList)); - service.findAllTasksWithoutState(fakeFilter).subscribe((res) => { + service.findAllTasksByState(mockFilterNoState).subscribe((res) => { expect(res).toBeDefined(); expect(res.data).toBeDefined(); - expect(res.data.length).toEqual(2); - 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'); - - expect(res.data[1].name).toEqual('FakeNameTask'); - expect(res.data[1].assignee.email).toEqual('fake-email@dom.com'); - expect(res.data[1].assignee.firstName).toEqual('firstName'); - expect(res.data[1].assignee.lastName).toEqual('lastName'); - done(); - }); - }); - - it('Should return both open and completed task', (done) => { - spyOn(service, 'findTasksByState').and.returnValue(of(fakeOpenTaskList)); - spyOn(service, 'findAllTaskByState').and.returnValue(of(fakeCompletedTaskList)); - service.findAllTasksWithoutState(fakeFilter).subscribe((res) => { - expect(res).toBeDefined(); - expect(res.data).toBeDefined(); - expect(res.data.length).toEqual(4); - expect(res.data[0].name).toEqual('FakeOpenTask1'); - expect(res.data[1].assignee.email).toEqual('fake-open-email@dom.com'); - expect(res.data[2].name).toEqual('FakeCompletedTaskName1'); - expect(res.data[2].assignee.email).toEqual('fake-completed-email@dom.com'); - expect(res.data[3].name).toEqual('FakeCompletedTaskName2'); - done(); - }); - }); - - it('should add the task list to the tasklistSubject with all tasks filtered without state', (done) => { - spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList)); - spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList)); - - service.findAllTasksWithoutState(fakeFilter).subscribe((res) => { - expect(res).toBeDefined(); - expect(res.data).toBeDefined(); - expect(res.data.length).toEqual(2); + 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[1].name).toEqual('FakeNameTask'); - expect(res.data[1].assignee.email).toEqual('fake-email@dom.com'); done(); }); }); diff --git a/lib/process-services/src/lib/task-list/services/tasklist.service.ts b/lib/process-services/src/lib/task-list/services/tasklist.service.ts index e13a9104f71..f8d77d4b194 100644 --- a/lib/process-services/src/lib/task-list/services/tasklist.service.ts +++ b/lib/process-services/src/lib/task-list/services/tasklist.service.ts @@ -17,7 +17,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; -import { Observable, from, forkJoin, of } from 'rxjs'; +import { Observable, from, 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'; @@ -104,7 +104,7 @@ export class TaskListService { * Gets tasks matching a query and state value. * * @param requestNode Query to search for tasks - * @param state Task state. Can be "open" or "completed". + * @param state Task state. Can be "open" or "completed". State "all" applies to both "open" and "completed" tasks. * @returns List of tasks */ findTasksByState(requestNode: TaskQueryRequestRepresentationModel, state?: string): Observable { @@ -119,10 +119,10 @@ export class TaskListService { * Gets all tasks matching a query and state value. * * @param requestNode Query to search for tasks. - * @param state Task state. Can be "open" or "completed". + * @param state Task state. Can be "open" or "completed". State "all" applies to both "open" and "completed" tasks. * @returns List of tasks */ - findAllTaskByState(requestNode: TaskQueryRequestRepresentationModel, state?: string): Observable { + findAllTasksByState(requestNode: TaskQueryRequestRepresentationModel, state?: string): Observable { if (state) { requestNode.state = state; } @@ -135,25 +135,6 @@ export class TaskListService { ); } - /** - * Gets all tasks matching the supplied query but ignoring the task state. - * - * @param requestNode Query to search for tasks - * @returns List of tasks - */ - findAllTasksWithoutState(requestNode: TaskQueryRequestRepresentationModel): Observable { - return forkJoin( - this.findTasksByState(requestNode, 'open'), - this.findAllTaskByState(requestNode, 'completed'), - (activeTasks: TaskListModel, completedTasks: TaskListModel) => { - const tasks = Object.assign({}, activeTasks); - tasks.total += completedTasks.total; - tasks.data = tasks.data.concat(completedTasks.data); - return tasks; - } - ); - } - /** * Gets details for a task. *