From f2f1cb4187e70d3c3266e793d0a19bd97137d08f Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Wed, 30 Sep 2020 00:29:28 +0300 Subject: [PATCH] [ACA-3626] Cloud Task - completed date filter (#6185) * completedDate task filter * translation key * update TaskFilterCloudModel * update TaskQueryCloudRequestModel * add completed date inputs * update TaskQueryCloudRequestModel request params * update tests --- .../src/lib/i18n/en.json | 3 +- .../edit-task-filter-cloud.component.spec.ts | 58 +++++++++++++++++++ .../edit-task-filter-cloud.component.ts | 11 ++++ .../task-filters/models/filter-cloud.model.ts | 30 ++++++++++ .../components/task-list-cloud.component.ts | 17 +++++- .../task-list/models/filter-cloud-model.ts | 6 ++ 6 files changed, 123 insertions(+), 2 deletions(-) diff --git a/lib/process-services-cloud/src/lib/i18n/en.json b/lib/process-services-cloud/src/lib/i18n/en.json index 4a127240b9..1a6b2c59c8 100644 --- a/lib/process-services-cloud/src/lib/i18n/en.json +++ b/lib/process-services-cloud/src/lib/i18n/en.json @@ -160,7 +160,8 @@ "DUE_DATE": "DueDate", "SORT": "Sort", "START_DATE": "StartDate", - "COMPLETED_BY": "Completed By" + "COMPLETED_BY": "Completed By", + "COMPLETED_DATE": "CompletedDate" }, "DIALOG": { "TITLE": "Save filter as", diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts index b2a842e1e5..9e1e4e3a6a 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.spec.ts @@ -528,6 +528,64 @@ describe('EditTaskFilterCloudComponent', () => { }); component.onFilterChange(); }); + + it('should set the correct completed date range when date range option is changed', (done) => { + component.appName = 'fake'; + component.filterProperties = ['appName', 'processInstanceId', 'priority', 'completedDateRange']; + const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); + component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + + const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('completedDateType'); + startedDateTypeControl.setValue(DateCloudFilterType.TODAY); + const dateFilter = { + startFrom: moment().startOf('day').toDate(), + startTo: moment().endOf('day').toDate() + }; + + component.filterChange.subscribe(() => { + expect(component.changedTaskFilter.completedFrom).toEqual(dateFilter.startFrom.toISOString()); + expect(component.changedTaskFilter.completedTo).toEqual(dateFilter.startTo.toISOString()); + done(); + }); + component.onFilterChange(); + }); + + it('should update form on date range when completed value is updated', (done) => { + component.appName = 'fake'; + component.filterProperties = ['appName', 'processInstanceId', 'priority', 'completedDateRange']; + const taskFilterIdChange = new SimpleChange(undefined, 'mock-task-filter-id', true); + component.ngOnChanges({ 'id': taskFilterIdChange }); + fixture.detectChanges(); + + const dateFilter = { + startDate: moment().startOf('day').toDate(), + endDate: moment().endOf('day').toDate() + }; + + const startedDateTypeControl: AbstractControl = component.editTaskFilterForm.get('completedDateType'); + startedDateTypeControl.setValue(DateCloudFilterType.RANGE); + + component.onDateRangeFilterChanged(dateFilter, { + key: 'completedDateType', + label: '', + type: 'date-range', + value: '', + attributes: { + dateType: 'completedDateType', + from: '_completedFrom', + to: '_completedTo' + } + }); + + fixture.detectChanges(); + component.filterChange.subscribe(() => { + expect(component.changedTaskFilter.completedFrom).toEqual(dateFilter.startDate.toISOString()); + expect(component.changedTaskFilter.completedTo).toEqual(dateFilter.endDate.toISOString()); + done(); + }); + component.onFilterChange(); + }); }); describe('sort properties', () => { diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.ts index d3fcdec248..ebef0d6da8 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-task-filter-cloud.component.ts @@ -328,6 +328,17 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone DateCloudFilterType.NEXT_7_DAYS, DateCloudFilterType.RANGE ] + }), + new TaskFilterProperties({ + label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.COMPLETED_DATE', + type: 'date-range', + key: 'completedDateRange', + attributes: { dateType: 'completedDateType', from: '_completedFrom', to: '_completedTo'}, + value: { + completedDateType: this.taskFilter.completedDateType || null, + _completedFrom: this.taskFilter.completedFrom || null, + _completedTo: this.taskFilter.completedTo || null + } }) ]; } diff --git a/lib/process-services-cloud/src/lib/task/task-filters/models/filter-cloud.model.ts b/lib/process-services-cloud/src/lib/task/task-filters/models/filter-cloud.model.ts index 534da7a3c8..5fcfc5695a 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/models/filter-cloud.model.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/models/filter-cloud.model.ts @@ -45,7 +45,11 @@ export class TaskFilterCloudModel { lastModifiedFrom: Date; lastModifiedTo: Date; completedBy: string; + completedDateType: DateCloudFilterType; + completedDate: Date; + private _completedFrom: string; + private _completedTo: string; private _dueDateFrom: string; private _dueDateTo: string; private dateRangeFilterService = new DateRangeFilterService(); @@ -79,6 +83,10 @@ export class TaskFilterCloudModel { this.lastModifiedFrom = obj.lastModifiedFrom || null; this.lastModifiedTo = obj.lastModifiedTo || null; this.completedBy = obj.completedBy || null; + this.completedDateType = obj.completedDateType || null; + this.completedFrom = obj._completedFrom || null; + this.completedTo = obj._completedTo || null; + this.completedDate = obj.completedDate || null; } } @@ -104,6 +112,28 @@ export class TaskFilterCloudModel { return this.getEndDate(this.dueDateType); } + set completedFrom(completedFrom: string) { + this._completedFrom = completedFrom; + } + + set completedTo(completedTo: string) { + this._completedTo = completedTo; + } + + get completedFrom(): string { + if (this.isDateRangeType(this.completedDateType)) { + return this._completedFrom; + } + return this.getStartDate(this.completedDateType); + } + + get completedTo(): string { + if (this.isDateRangeType(this.completedDateType)) { + return this._completedTo; + } + return this.getEndDate(this.completedDateType); + } + private getStartDate(key: DateCloudFilterType) { return this.dateRangeFilterService.getDateRange(key).startDate?.toISOString(); } diff --git a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.ts index d064ca3abe..302cf934b7 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/components/task-list-cloud.component.ts @@ -107,6 +107,18 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent { @Input() standalone: boolean = false; + /** Filter the tasks. Display only tasks with completedDate equal to the supplied date. */ + @Input() + completedDate: string = ''; + + /** Filter the tasks. Display only tasks with completedFrom equal to the supplied date. */ + @Input() + completedFrom: string = ''; + + /** Filter the tasks. Display only tasks with completedTo equal to the supplied date. */ + @Input() + completedTo: string = ''; + constructor(private taskListCloudService: TaskListCloudService, appConfigService: AppConfigService, userPreferences: UserPreferencesService) { @@ -150,7 +162,10 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent { skipCount: this.skipCount, sorting: this.sorting, standalone: this.standalone, - completedBy: this.completedBy + completedBy: this.completedBy, + completedFrom: this.completedFrom, + completedTo: this.completedTo, + completedDate: this.completedDate }; return new TaskQueryCloudRequestModel(requestNode); } diff --git a/lib/process-services-cloud/src/lib/task/task-list/models/filter-cloud-model.ts b/lib/process-services-cloud/src/lib/task/task-list/models/filter-cloud-model.ts index f099a0ff77..10cffbe076 100644 --- a/lib/process-services-cloud/src/lib/task/task-list/models/filter-cloud-model.ts +++ b/lib/process-services-cloud/src/lib/task/task-list/models/filter-cloud-model.ts @@ -43,6 +43,9 @@ export class TaskQueryCloudRequestModel { maxItems: number; skipCount: number; sorting?: TaskListCloudSortingModel[]; + completedDate?: Date; + completedFrom?: string; + completedTo?: string; constructor(obj?: any) { if (obj) { @@ -71,6 +74,9 @@ export class TaskQueryCloudRequestModel { this.maxItems = obj.maxItems; this.skipCount = obj.skipCount; this.sorting = obj.sorting; + this.completedFrom = obj.completedFrom; + this.completedTo = obj.completedTo; + this.completedDate = obj.completedDate; } } }