From 7e907fc8763bb430116d448a9850d3f2460e86f4 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 4 Nov 2020 09:19:12 +0000 Subject: [PATCH] [AAE-3992] cleanup the code before refactoring (#6301) * use interface instead of class * cleanup code and fix html template typo * api cleanup * use interface instead of class * code cleanup and test fixes * use interface instead of class * use interface instead of class, fix typing issues * fix IDE support for spec files * fix IDE for spec files * unify filter compare * remove jest * use generics to reduce code duplication * generic saveas * unify code --- .../date-range-filter.component.ts | 6 +- .../edit-process-filter-cloud.component.html | 12 +- .../edit-process-filter-cloud.component.ts | 171 +++++------ .../process-filters-cloud.component.spec.ts | 11 +- .../process-filters-cloud.component.ts | 6 +- .../models/process-filter-cloud.model.ts | 44 +-- ...base-edit-task-filter-cloud.component.html | 16 +- .../base-edit-task-filter-cloud.component.ts | 189 +++++++----- ...dit-service-task-filter-cloud.component.ts | 209 +++++--------- .../edit-task-filter-cloud.component.ts | 268 +++++++----------- ...rvice-task-filters-cloud.component.spec.ts | 13 +- .../service-task-filters-cloud.component.ts | 4 +- .../task-filters-cloud.component.spec.ts | 13 +- .../task-filters-cloud.component.ts | 4 +- .../task-filters/models/filter-cloud.model.ts | 59 +--- lib/process-services-cloud/tsconfig.lib.json | 1 - lib/tsconfig.json | 2 +- lib/tsconfig.spec.json | 6 +- tsconfig.json | 1 + 19 files changed, 425 insertions(+), 610 deletions(-) diff --git a/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.ts b/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.ts index c8473b96fd..d413d9702a 100644 --- a/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.ts +++ b/lib/process-services-cloud/src/lib/common/date-range-filter/date-range-filter.component.ts @@ -51,7 +51,7 @@ import moment from 'moment-es6'; ngOnInit() { this.options = this.options ? this.options : this.createDefaultRangeOptions(); const defaultProperties = this.createDefaultDateOptions(); - this.filteredProperties = defaultProperties.filter((filterProperty: ProcessFilterOptions) => this.isValidProperty(this.options, filterProperty)); + this.filteredProperties = defaultProperties.filter((filterProperty) => this.isValidProperty(this.options, filterProperty.value.toString())); if (this.hasPreselectedValues()) { this.setPreselectedValues(); } @@ -98,8 +98,8 @@ import moment from 'moment-es6'; return this.processFilterProperty.value[attribute]; } - private isValidProperty(filterProperties: string[], filterProperty: any): boolean { - return filterProperties ? filterProperties.indexOf(filterProperty.value) >= 0 : true; + private isValidProperty(filterProperties: string[], key: string): boolean { + return filterProperties ? filterProperties.indexOf(key) >= 0 : true; } private createDefaultRangeOptions(): DateCloudFilterType[] { diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.html b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.html index be493bf8e5..1fb770baa3 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.html +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/edit-process-filter-cloud.component.html @@ -24,7 +24,7 @@
- + - + - + - + {{processFilterProperty.label | translate}} - -
+
= new EventEmitter(); + filterChange = new EventEmitter(); /** Emitted when a filter action occurs i.e Save, SaveAs, Delete. */ @Output() - action: EventEmitter = new EventEmitter(); + action = new EventEmitter(); processFilter: ProcessFilterCloudModel; changedProcessFilter: ProcessFilterCloudModel; @@ -163,7 +155,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes } getFormControlsConfig(processFilterProperties: ProcessFilterProperties[]): any { - const properties = processFilterProperties.map((property: ProcessFilterProperties) => { + const properties = processFilterProperties.map((property) => { if (!!property.attributes) { return this.getAttributesControlConfig(property); } else { @@ -219,16 +211,16 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes createAndFilterProperties(): ProcessFilterProperties[] { this.checkMandatoryFilterProperties(); - if (this.checkForProperty(EditProcessFilterCloudComponent.APPLICATION_NAME)) { + if (this.checkForProperty('appName')) { this.applicationNames = []; this.getRunningApplications(); } - if (this.checkForProperty(EditProcessFilterCloudComponent.PROCESS_DEFINITION_NAME)) { + if (this.checkForProperty('processDefinitionName')) { this.processDefinitionNames = []; this.getProcessDefinitions(); } const defaultProperties = this.createProcessFilterProperties(this.processFilter); - let filteredProperties = defaultProperties.filter((filterProperty: ProcessFilterProperties) => this.isValidProperty(this.filterProperties, filterProperty)); + let filteredProperties = defaultProperties.filter((filterProperty) => this.isValidProperty(this.filterProperties, filterProperty.key)); if (!this.hasSortProperty()) { filteredProperties = this.removeOrderProperty(filteredProperties); } @@ -248,23 +240,21 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes return this.filterProperties ? this.filterProperties.indexOf(property) >= 0 : false; } - private isValidProperty(filterProperties: string[], filterProperty: ProcessFilterProperties): boolean { - return filterProperties ? filterProperties.indexOf(filterProperty.key) >= 0 : true; + private isValidProperty(filterProperties: string[], key: string): boolean { + return filterProperties ? filterProperties.indexOf(key) >= 0 : true; } - hasSortProperty(): boolean { - return this.filterProperties.indexOf(EditProcessFilterCloudComponent.SORT) >= 0; + private hasSortProperty(): boolean { + return this.filterProperties.includes('sort'); } - hasLastModifiedProperty(): boolean { - return this.filterProperties.indexOf(EditProcessFilterCloudComponent.LAST_MODIFIED) >= 0; + private hasLastModifiedProperty(): boolean { + return this.filterProperties.includes('lastModified'); } removeOrderProperty(filteredProperties: ProcessFilterProperties[]): ProcessFilterProperties[] { if (filteredProperties && filteredProperties.length > 0) { - return filteredProperties.filter( - property => property.key !== EditProcessFilterCloudComponent.ORDER - ); + return filteredProperties.filter(property => property.key !== 'order'); } return []; } @@ -272,8 +262,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes get createSortProperties(): ProcessFilterOptions[] { this.checkMandatorySortProperties(); const defaultSortProperties = this.createProcessSortProperties(); - const sortProperties = defaultSortProperties.filter((sortProperty: ProcessFilterProperties) => this.isValidProperty(this.sortProperties, sortProperty)); - return sortProperties; + return defaultSortProperties.filter((sortProperty) => this.isValidProperty(this.sortProperties, sortProperty.key)); } checkMandatorySortProperties() { @@ -285,7 +274,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes createAndFilterActions() { this.checkMandatoryActions(); const actions = this.createFilterActions(); - return actions.filter((action: ProcessFilterAction) => this.isValidAction(this.actions, action)); + return actions.filter((action) => this.isValidAction(this.actions, action)); } checkMandatoryActions() { @@ -294,7 +283,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes } } - private isValidAction(actions: string[], action: any): boolean { + private isValidAction(actions: string[], action: ProcessFilterAction): boolean { return actions ? actions.indexOf(action.actionType) >= 0 : true; } @@ -309,12 +298,13 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes onDateChanged(newDateValue: any, dateProperty: ProcessFilterProperties) { if (newDateValue) { const momentDate = moment(newDateValue, this.DATE_FORMAT, true); + const controller = this.getPropertyController(dateProperty); if (momentDate.isValid()) { - this.getPropertyController(dateProperty).setValue(momentDate.toDate()); - this.getPropertyController(dateProperty).setErrors(null); + controller.setValue(momentDate.toDate()); + controller.setErrors(null); } else { - this.getPropertyController(dateProperty).setErrors({ invalid: true }); + controller.setErrors({ invalid: true }); } } } @@ -337,7 +327,8 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes } hasError(property: ProcessFilterProperties): boolean { - return this.getPropertyController(property).errors && this.getPropertyController(property).errors.invalid; + const controller = this.getPropertyController(property); + return controller.errors && controller.errors.invalid; } compareFilters(editedQuery: ProcessFilterCloudModel, currentQuery: ProcessFilterCloudModel): boolean { @@ -346,9 +337,8 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes getRunningApplications() { this.appsProcessCloudService - .getDeployedApplicationsByStatus(EditProcessFilterCloudComponent.APP_RUNNING_STATUS, this.role) - .pipe(takeUntil(this.onDestroy$)) - .subscribe((applications: ApplicationInstanceModel[]) => { + .getDeployedApplicationsByStatus('RUNNING', this.role) + .subscribe((applications) => { if (applications && applications.length > 0) { applications.map((application) => { this.applicationNames.push({ label: application.name, value: application.name }); @@ -358,9 +348,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes } getProcessDefinitions() { - this.processCloudService.getProcessDefinitions(this.appName) - .pipe(takeUntil(this.onDestroy$)) - .subscribe((processDefinitions: ProcessDefinitionCloud[]) => { + this.processCloudService.getProcessDefinitions(this.appName).subscribe((processDefinitions) => { if (processDefinitions && processDefinitions.length > 0) { this.processDefinitionNames.push(this.allProcessDefinitionNamesOption); processDefinitions.map((processDefinition) => { @@ -383,7 +371,6 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes save(saveAction: ProcessFilterAction) { this.processFilterCloudService .updateFilter(this.changedProcessFilter) - .pipe(takeUntil(this.onDestroy$)) .subscribe(() => { saveAction.filter = this.changedProcessFilter; this.action.emit(saveAction); @@ -403,8 +390,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes this.action.emit(deleteAction); return filters.length === 0; }), - switchMap(() => this.restoreDefaultProcessFilters()), - takeUntil(this.onDestroy$)) + switchMap(() => this.restoreDefaultProcessFilters())) .subscribe(() => {}); } @@ -432,7 +418,6 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes const resultFilter: ProcessFilterCloudModel = Object.assign({}, this.changedProcessFilter, newFilter); this.processFilterCloudService .addFilter(resultFilter) - .pipe(takeUntil(this.onDestroy$)) .subscribe(() => { saveAsAction.filter = resultFilter; this.action.emit(saveAsAction); @@ -475,30 +460,6 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes this.toggleFilterActions = false; } - isDateType(property: ProcessFilterProperties): boolean { - return property.type === 'date'; - } - - isDateRangeType(property: ProcessFilterProperties): boolean { - return property.type === 'date-range'; - } - - isSelectType(property: ProcessFilterProperties): boolean { - return property.type === 'select'; - } - - isTextType(property: ProcessFilterProperties): boolean { - return property.type === 'text'; - } - - isNumberType(property: ProcessFilterProperties): boolean { - return property.type === 'number'; - } - - isUserSelectType(property: ProcessFilterProperties): boolean { - return property.type === 'people'; - } - isDisabledAction(action: ProcessFilterAction): boolean { return this.isDisabledForDefaultFilters(action) ? true : this.hasFormChanged(action); } @@ -538,42 +499,42 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes createFilterActions(): ProcessFilterAction[] { return [ - new ProcessFilterAction({ + { actionType: EditProcessFilterCloudComponent.ACTION_SAVE, icon: 'save', tooltip: 'ADF_CLOUD_EDIT_PROCESS_FILTER.TOOL_TIP.SAVE' - }), - new ProcessFilterAction({ + }, + { actionType: EditProcessFilterCloudComponent.ACTION_SAVE_AS, icon: 'adf:save-as', tooltip: 'ADF_CLOUD_EDIT_PROCESS_FILTER.TOOL_TIP.SAVE_AS' - }), - new ProcessFilterAction({ + }, + { actionType: EditProcessFilterCloudComponent.ACTION_DELETE, icon: 'delete', tooltip: 'ADF_CLOUD_EDIT_PROCESS_FILTER.TOOL_TIP.DELETE' - }) + } ]; } createLastModifiedProperty(): ProcessFilterProperties[] { return [ - new ProcessFilterProperties({ + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.LAST_MODIFIED_DATE_FORM', type: 'date', key: 'lastModifiedFrom', value: '' - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.LAST_MODIFIED_TO', type: 'date', key: 'lastModifiedTo', value: '' - }) + } ]; } - createProcessSortProperties(): ProcessSortFilterProperties[] { + createProcessSortProperties(): ProcessSortFilterProperty[] { return [ { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.ID', @@ -645,85 +606,85 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes createProcessFilterProperties(currentProcessFilter: ProcessFilterCloudModel): ProcessFilterProperties[] { return [ - new ProcessFilterProperties({ + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.APP_NAME', type: 'select', key: 'appName', value: currentProcessFilter.appName || '', options: this.applicationNames - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.APP_VERSION', type: 'number', key: 'appVersion', value: currentProcessFilter.appVersion - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_INS_ID', type: 'text', key: 'processInstanceId', value: currentProcessFilter.processInstanceId || '' - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_NAME', type: 'text', key: 'processName', value: currentProcessFilter.processName || '' - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_DEF_NAME', type: 'select', key: 'processDefinitionName', value: currentProcessFilter.processDefinitionName || '', options: this.processDefinitionNames - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.STATUS', type: 'select', key: 'status', value: currentProcessFilter.status || this.status[0].value, options: this.status - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_DEF_ID', type: 'text', key: 'processDefinitionId', value: currentProcessFilter.processDefinitionId || '' - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.PROCESS_DEF_KEY', type: 'text', key: 'processDefinitionKey', value: currentProcessFilter.processDefinitionKey || '' - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.SORT', type: 'select', key: 'sort', value: currentProcessFilter.sort || this.createSortProperties[0].value, options: this.createSortProperties - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.DIRECTION', type: 'select', key: 'order', value: currentProcessFilter.order || this.directions[0].value, options: this.directions - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.COMPLETED_DATE', type: 'date', key: 'completedDate', value: currentProcessFilter.completedDate || false - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.STARTED_BY', type: 'people', key: 'initiator', value: currentProcessFilter.initiator, selectionMode: 'multiple' - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.COMPLETED_DATE', type: 'date-range', key: 'completedDateRange', @@ -733,8 +694,8 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes _completedFrom: currentProcessFilter.completedFrom || null, _completedTo: currentProcessFilter.completedTo || null } - }), - new ProcessFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_PROCESS_FILTER.LABEL.STARTED_DATE', type: 'date-range', key: 'startedDateRange', @@ -744,7 +705,7 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes _startFrom: currentProcessFilter.startFrom || null, _startTo: currentProcessFilter.startTo || null } - }) + } ]; } } diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts index 6c1916a0f1..3cf3ab17ff 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.spec.ts @@ -25,7 +25,6 @@ import { ProcessFiltersCloudComponent } from './process-filters-cloud.component' import { By } from '@angular/platform-browser'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessFiltersCloudModule } from '../process-filters-cloud.module'; -import { FilterParamsModel } from '../../../task/task-filters/models/filter-cloud.model'; import { PROCESS_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; import { TranslateModule } from '@ngx-translate/core'; @@ -194,7 +193,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should select the filter based on the input by name param', (done) => { spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ name: 'FakeRunningProcesses' }); + component.filterParam = { name: 'FakeRunningProcesses' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -212,7 +211,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should select the filter based on the input by key param', (done) => { spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ key: 'completed-processes' }); + component.filterParam = { key: 'completed-processes' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -231,7 +230,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should select the filter based on the input by index param', (done) => { spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ index: 2 }); + component.filterParam = { index: 2 }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -250,7 +249,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should select the filter based on the input by id param', (done) => { spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ id: '12' }); + component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -269,7 +268,7 @@ describe('ProcessFiltersCloudComponent', () => { it('should emit an event when a filter is selected', (done) => { spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ id: '10' }); + component.filterParam = { id: '10' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts index 1211124d61..6b679ace60 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters-cloud.component.ts @@ -44,15 +44,15 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro /** Emitted when a filter is selected/clicked */ @Output() - filterClick: EventEmitter = new EventEmitter(); + filterClick = new EventEmitter(); /** Emitted when filters are loaded successfully */ @Output() - success: EventEmitter = new EventEmitter(); + success = new EventEmitter(); /** Emitted when any error occurs while loading the filters */ @Output() - error: EventEmitter = new EventEmitter(); + error = new EventEmitter(); filters$: Observable; diff --git a/lib/process-services-cloud/src/lib/process/process-filters/models/process-filter-cloud.model.ts b/lib/process-services-cloud/src/lib/process/process-filters/models/process-filter-cloud.model.ts index 4160294b13..bf09533416 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/models/process-filter-cloud.model.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/models/process-filter-cloud.model.ts @@ -141,20 +141,11 @@ export class ProcessFilterCloudModel { } } -export class ProcessFilterAction { - actionType: string; - icon: string; - tooltip: string; - filter: ProcessFilterCloudModel; - - constructor(obj?: any) { - if (obj) { - this.actionType = obj.actionType || null; - this.icon = obj.icon || null; - this.tooltip = obj.tooltip || null; - this.filter = obj.filter || null; - } - } +export interface ProcessFilterAction { + actionType?: string; + icon?: string; + tooltip?: string; + filter?: ProcessFilterCloudModel; } export interface ProcessFilterOptions { @@ -162,31 +153,18 @@ export interface ProcessFilterOptions { value?: string | object; } -export class ProcessFilterProperties { - label: string; - type: string; - value: string | object; - key: string; +export interface ProcessFilterProperties { + label?: string; + type?: string; + value?: any; + key?: string; attributes?: { [key: string]: string; }; options?: ProcessFilterOptions[]; dateFilterOptions?: DateCloudFilterType[]; selectionMode?: ComponentSelectionMode; - - constructor(obj?: any) { - if (obj) { - this.label = obj.label || null; - this.type = obj.type || null; - this.value = obj.value || ''; - this.key = obj.key || null; - this.attributes = obj.attributes || null; - this.options = obj.options || null; - this.dateFilterOptions = obj.dateFilterOptions || null; - this.selectionMode = obj.selectionMode || null; - } - } } -export interface ProcessSortFilterProperties { +export interface ProcessSortFilterProperty { label: string; value: string | object; key: string; diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.html b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.html index 3e6be5a3ce..ae2ed0ceee 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.html +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.html @@ -40,7 +40,7 @@ fxLayoutAlign="start center"> {{taskFilterProperty.label | translate}} + [attr.data-automation-id]="'adf-cloud-edit-task-property-' + taskFilterProperty.key"> @@ -87,7 +87,7 @@
+ *ngIf="taskFilterProperty.type === 'checkbox'"> @@ -95,14 +95,14 @@
- -
+
diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.ts index 993a2449c1..3acd9822de 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/base-edit-task-filter-cloud.component.ts @@ -20,18 +20,19 @@ import { FilterOptions, TaskFilterAction, TaskFilterProperties } from '../../mod import { TaskCloudService } from './../../../services/task-cloud.service'; import { AppsProcessCloudService } from './../../../../app/services/apps-process-cloud.service'; import { ApplicationInstanceModel } from './../../../../app/models/application-instance.model'; -import { ProcessDefinitionCloud } from './../../../../models/process-definition-cloud.model'; import { DateCloudFilterType, DateRangeFilter } from '../../../../models/date-cloud-filter.model'; import moment, { Moment } from 'moment'; import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms'; -import { debounceTime, filter, takeUntil } from 'rxjs/operators'; -import { Subject } from 'rxjs'; +import { debounceTime, filter, finalize, switchMap, takeUntil } from 'rxjs/operators'; +import { Observable, Subject } from 'rxjs'; import { DateAdapter } from '@angular/material/core'; -import { IdentityGroupModel, IdentityUserModel, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core'; +import { IdentityGroupModel, IdentityUserModel, TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core'; +import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component'; +import { MatDialog } from '@angular/material/dialog'; @Directive() // tslint:disable-next-line: directive-class-suffix -export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestroy { +export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChanges, OnDestroy { public static ACTION_SAVE = 'save'; public static ACTION_SAVE_AS = 'saveAs'; @@ -91,7 +92,7 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan /** Emitted when a filter action occurs (i.e Save, Save As, Delete). */ @Output() - action: EventEmitter = new EventEmitter(); + action = new EventEmitter(); protected applicationNames: any[] = []; protected processDefinitionNames: any[] = []; @@ -102,6 +103,13 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan toggleFilterActions: boolean = false; allProcessDefinitionNamesOption = { label: 'All', value: '' }; + taskFilter: T; + changedTaskFilter: T; + + /** Emitted when a task filter property changes. */ + @Output() + filterChange = new EventEmitter(); + protected onDestroy$ = new Subject(); isLoading: boolean = false; @@ -110,7 +118,9 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan protected dateAdapter: DateAdapter, protected userPreferencesService: UserPreferencesService, protected appsProcessCloudService: AppsProcessCloudService, - protected taskCloudService: TaskCloudService) { + protected taskCloudService: TaskCloudService, + protected dialog: MatDialog, + protected translateService: TranslationService) { } ngOnInit() { @@ -134,21 +144,21 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan createFilterActions(): TaskFilterAction[] { return [ - new TaskFilterAction({ + { actionType: BaseEditTaskFilterCloudComponent.ACTION_SAVE, icon: 'save', tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.SAVE' - }), - new TaskFilterAction({ + }, + { actionType: BaseEditTaskFilterCloudComponent.ACTION_SAVE_AS, icon: 'adf:save-as', tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.SAVE_AS' - }), - new TaskFilterAction({ + }, + { actionType: BaseEditTaskFilterCloudComponent.ACTION_DELETE, icon: 'delete', tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.DELETE' - }) + } ]; } @@ -174,36 +184,12 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan this.toggleFilterActions = false; } - isDateType(property: TaskFilterProperties): boolean { - return property.type === 'date'; - } - - isDateRangeType(property: TaskFilterProperties): boolean { - return property.type === 'date-range'; - } - - isUserSelectType(property: TaskFilterProperties): boolean { - return property.type === 'people'; - } - - isSelectType(property: TaskFilterProperties): boolean { - return property.type === 'select'; - } - - isTextType(property: TaskFilterProperties): boolean { - return property.type === 'text'; - } - - isCheckBoxType(property: TaskFilterProperties): boolean { - return property.type === 'checkbox'; - } - isDisabledAction(action: TaskFilterAction): boolean { return this.isDisabledForDefaultFilters(action) ? true : this.hasFormChanged(action); } - isAssignmentType(property: TaskFilterProperties): boolean { - return property.type === 'assignment'; + protected deepCompare(left: any, right: any): boolean { + return JSON.stringify(left).toLowerCase() === JSON.stringify(right).toLowerCase(); } /** @@ -215,11 +201,7 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan return nameWithHyphen.toLowerCase(); } - /** - * Return name with hyphen - * @param name - */ - replaceSpaceWithHyphen(name: string): string { + private replaceSpaceWithHyphen(name: string): string { const regExt = new RegExp(' ', 'g'); return name.replace(regExt, '-'); } @@ -237,7 +219,6 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan getRunningApplications() { this.appsProcessCloudService .getDeployedApplicationsByStatus(BaseEditTaskFilterCloudComponent.APP_RUNNING_STATUS, this.role) - .pipe(takeUntil(this.onDestroy$)) .subscribe((applications: ApplicationInstanceModel[]) => { if (applications && applications.length > 0) { applications.map((application) => { @@ -249,8 +230,7 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan getProcessDefinitions() { this.taskCloudService.getProcessDefinitions(this.appName) - .pipe(takeUntil(this.onDestroy$)) - .subscribe((processDefinitions: ProcessDefinitionCloud[]) => { + .subscribe((processDefinitions) => { if (processDefinitions && processDefinitions.length > 0) { this.processDefinitionNames.push(this.allProcessDefinitionNamesOption); processDefinitions.map((processDefinition) => { @@ -281,12 +261,13 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan onDateChanged(newDateValue: any, dateProperty: TaskFilterProperties) { if (newDateValue) { const momentDate = moment(newDateValue, BaseEditTaskFilterCloudComponent.FORMAT_DATE, true); + const controller = this.getPropertyController(dateProperty); if (momentDate.isValid()) { - this.getPropertyController(dateProperty).setValue(momentDate.toISOString(true)); - this.getPropertyController(dateProperty).setErrors(null); + controller.setValue(momentDate.toISOString(true)); + controller.setErrors(null); } else { - this.getPropertyController(dateProperty).setErrors({ invalid: true }); + controller.setErrors({ invalid: true }); } } } @@ -321,7 +302,8 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan } hasError(property: TaskFilterProperties): boolean { - return this.getPropertyController(property).errors && this.getPropertyController(property).errors.invalid; + const controller = this.getPropertyController(property); + return controller.errors && controller.errors.invalid; } hasLastModifiedProperty(): boolean { @@ -330,10 +312,10 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan get createSortProperties(): FilterOptions[] { this.checkMandatorySortProperties(); - const sortProperties = this.sortProperties.map((property: string) => { - return { label: property.charAt(0).toUpperCase() + property.slice(1), value: property }; + + return this.sortProperties.map((property: string) => { + return { label: property.charAt(0).toUpperCase() + property.slice(1), value: property }; }); - return sortProperties; } createAndFilterActions(): TaskFilterAction[] { @@ -341,8 +323,8 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan return this.createFilterActions().filter(action => this.isValidAction(this.actions, action)); } - isValidProperty(filterProperties: string[], filterProperty: any): boolean { - return filterProperties ? filterProperties.indexOf(filterProperty.key) >= 0 : true; + isValidProperty(filterProperties: string[], key: string): boolean { + return filterProperties ? filterProperties.indexOf(key) >= 0 : true; } checkForProperty(property: string): boolean { @@ -373,7 +355,7 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan } const defaultProperties = this.createTaskFilterProperties(); - let filteredProperties = defaultProperties.filter((filterProperty: TaskFilterProperties) => this.isValidProperty(this.filterProperties, filterProperty)); + let filteredProperties = defaultProperties.filter((filterProperty) => this.isValidProperty(this.filterProperties, filterProperty.key)); if (!this.hasSortProperty()) { filteredProperties = this.removeOrderProperty(filteredProperties); @@ -398,7 +380,7 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan } getFormControlsConfig(taskFilterProperties: TaskFilterProperties[]): any { - const properties = taskFilterProperties.map((property: TaskFilterProperties) => { + const properties = taskFilterProperties.map((property) => { if (!!property.attributes) { return this.getAttributesControlConfig(property); } else { @@ -425,14 +407,93 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan this.editTaskFilterForm.get(property.attributes.dateType).setValue(dateType); } - abstract save(action: TaskFilterAction): void; - abstract saveAs(action: TaskFilterAction): void; - abstract delete(action: TaskFilterAction): void; - abstract checkMandatorySortProperties(): void; - abstract checkMandatoryFilterProperties(): void; + protected retrieveTaskFilterAndBuildForm() { + this.isLoading = true; + + this.getTaskFilterById(this.appName, this.id) + .pipe( + finalize(() => this.isLoading = false), + takeUntil(this.onDestroy$) + ) + .subscribe(response => { + this.taskFilter = response; + this.taskFilterProperties = this.createAndFilterProperties(); + this.taskFilterActions = this.createAndFilterActions(); + this.buildForm(this.taskFilterProperties); + }); + } + + delete(deleteAction: TaskFilterAction): void { + this.deleteFilter(this.taskFilter) + .pipe( + filter((filters) => { + deleteAction.filter = this.taskFilter; + this.action.emit(deleteAction); + return filters.length === 0; + }), + switchMap(() => this.restoreDefaultTaskFilters()), + takeUntil(this.onDestroy$)) + .subscribe(() => { }); + } + + save(saveAction: TaskFilterAction): void { + this.updateFilter(this.changedTaskFilter) + .pipe(takeUntil(this.onDestroy$)) + .subscribe(() => { + saveAction.filter = this.changedTaskFilter; + this.action.emit(saveAction); + this.formHasBeenChanged = this.deepCompare(this.changedTaskFilter, this.taskFilter); + }); + } + + saveAs(saveAsAction: TaskFilterAction): void { + const dialogRef = this.dialog.open(TaskFilterDialogCloudComponent, { + data: { + name: this.translateService.instant((this.taskFilter as any)?.name) + }, + height: 'auto', + minWidth: '30%' + }); + dialogRef.afterClosed().subscribe((result) => { + if (result && result.action === TaskFilterDialogCloudComponent.ACTION_SAVE) { + const filterId = Math.random().toString(36).substr(2, 9); + const filterKey = this.getSanitizeFilterName(result.name); + const newFilter = { + name: result.name, + icon: result.icon, + id: filterId, + key: 'custom-' + filterKey + }; + const resultFilter: T = Object.assign({}, this.changedTaskFilter, newFilter); + this.addFilter(resultFilter).subscribe(() => { + saveAsAction.filter = resultFilter; + this.action.emit(saveAsAction); + }); + } + }); + } + + checkMandatoryFilterProperties() { + if (this.filterProperties === undefined || this.filterProperties.length === 0) { + this.filterProperties = this.getDefaultFilterProperties(); + } + } + + checkMandatorySortProperties(): void { + if (this.sortProperties === undefined || this.sortProperties.length === 0) { + this.sortProperties = this.getDefaultSortProperties(); + } + } + + abstract getDefaultFilterProperties(): string[]; + abstract getDefaultSortProperties(): string[]; abstract isDisabledForDefaultFilters(action: TaskFilterAction): boolean; abstract createTaskFilterProperties(): TaskFilterProperties[]; - abstract retrieveTaskFilterAndBuildForm(): void; + protected abstract getTaskFilterById(appName: string, id: string); abstract assignNewFilter(formValues): void; + protected abstract restoreDefaultTaskFilters(): Observable; + protected abstract addFilter(filterToAdd: T): Observable; + protected abstract deleteFilter(filterToDelete: T): Observable; + protected abstract updateFilter(filterToUpdate: T): Observable; } diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.ts index 6e7eb5d3de..da7f351262 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/edit-task-filters/edit-service-task-filter-cloud.component.ts @@ -15,16 +15,15 @@ * limitations under the License. */ -import { Component, Output, EventEmitter } from '@angular/core'; +import { Component } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { DateAdapter } from '@angular/material/core'; import { MatDialog } from '@angular/material/dialog'; -import { filter, takeUntil, finalize, switchMap } from 'rxjs/operators'; +import { takeUntil } from 'rxjs/operators'; import { Observable } from 'rxjs'; import { Moment } from 'moment'; import { TaskFilterProperties, TaskFilterAction, ServiceTaskFilterCloudModel } from '../../models/filter-cloud.model'; -import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component'; import { TranslationService, UserPreferencesService } from '@alfresco/adf-core'; import { AppsProcessCloudService } from '../../../../app/services/apps-process-cloud.service'; import { TaskCloudService } from '../../../services/task-cloud.service'; @@ -36,135 +35,49 @@ import { BaseEditTaskFilterCloudComponent } from './base-edit-task-filter-cloud. templateUrl: './base-edit-task-filter-cloud.component.html', styleUrls: ['./base-edit-task-filter-cloud.component.scss'] }) -export class EditServiceTaskFilterCloudComponent extends BaseEditTaskFilterCloudComponent { - - public static DEFAULT_TASK_FILTER_PROPERTIES = ['appName', 'activityName', 'status', 'sort', 'order']; - public static DEFAULT_TASK_SORT_PROPERTIES = ['id', 'activityName', 'startedDate', 'completedDate']; - public static DEFAULT_TASK_STATUS_PROPERTIES = [ - { label: 'ALL', value: '' }, - { label: 'STARTED', value: 'STARTED' }, - { label: 'COMPLETED', value: 'COMPLETED' }, - { label: 'CANCELLED', value: 'CANCELLED' }, - { label: 'ERROR', value: 'ERROR' } - ]; - - /** Emitted when a task filter property changes. */ - @Output() - filterChange: EventEmitter = new EventEmitter(); - - taskFilter: ServiceTaskFilterCloudModel; - changedTaskFilter: ServiceTaskFilterCloudModel; - +export class EditServiceTaskFilterCloudComponent extends BaseEditTaskFilterCloudComponent { constructor( - protected formBuilder: FormBuilder, - public dialog: MatDialog, - private translateService: TranslationService, + formBuilder: FormBuilder, + dialog: MatDialog, + translateService: TranslationService, private serviceTaskFilterCloudService: ServiceTaskFilterCloudService, - protected dateAdapter: DateAdapter, - protected userPreferencesService: UserPreferencesService, - protected appsProcessCloudService: AppsProcessCloudService, - protected taskCloudService: TaskCloudService) { - super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService); + dateAdapter: DateAdapter, + userPreferencesService: UserPreferencesService, + appsProcessCloudService: AppsProcessCloudService, + taskCloudService: TaskCloudService) { + super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService, dialog, translateService); } - assignNewFilter(formValues: ServiceTaskFilterCloudModel) { - this.changedTaskFilter = Object.assign({}, this.taskFilter, formValues) as ServiceTaskFilterCloudModel; - this.formHasBeenChanged = !this.compareFilters(this.changedTaskFilter, this.taskFilter); + assignNewFilter(model: ServiceTaskFilterCloudModel) { + this.changedTaskFilter = { ...this.taskFilter, ...model }; + this.formHasBeenChanged = !this.deepCompare(this.changedTaskFilter, this.taskFilter); this.filterChange.emit(this.changedTaskFilter); } - /** - * Fetches task filter by application name and filter id and creates filter properties, build form - */ - retrieveTaskFilterAndBuildForm() { - this.isLoading = true; - this.serviceTaskFilterCloudService.getTaskFilterById(this.appName, this.id) - .pipe( - finalize(() => this.isLoading = false), - takeUntil(this.onDestroy$) - ) - .subscribe(response => { - this.taskFilter = response as ServiceTaskFilterCloudModel; - this.taskFilterProperties = this.createAndFilterProperties(); - this.taskFilterActions = this.createAndFilterActions(); - this.buildForm(this.taskFilterProperties); - }); + protected getTaskFilterById(appName: string, id: string) { + return this.serviceTaskFilterCloudService.getTaskFilterById(appName, id); } - checkMandatoryFilterProperties() { - if (this.filterProperties === undefined || this.filterProperties.length === 0) { - this.filterProperties = EditServiceTaskFilterCloudComponent.DEFAULT_TASK_FILTER_PROPERTIES; - } + getDefaultFilterProperties(): string[] { + return ['appName', 'activityName', 'status', 'sort', 'order']; } - checkMandatorySortProperties(): void { - if (this.sortProperties === undefined || this.sortProperties.length === 0) { - this.sortProperties = EditServiceTaskFilterCloudComponent.DEFAULT_TASK_SORT_PROPERTIES; - } + getDefaultSortProperties(): string[] { + return ['id', 'activityName', 'startedDate', 'completedDate']; } - /** - * Return true if both filters are same - * @param editedQuery, @param currentQuery - */ - compareFilters( - editedQuery: ServiceTaskFilterCloudModel, - currentQuery: ServiceTaskFilterCloudModel - ): boolean { - return JSON.stringify(editedQuery).toLowerCase() === JSON.stringify(currentQuery).toLowerCase(); + protected updateFilter(filterToUpdate: ServiceTaskFilterCloudModel) { + return this.serviceTaskFilterCloudService.updateFilter(filterToUpdate); } - save(saveAction: TaskFilterAction): void { - this.serviceTaskFilterCloudService - .updateFilter(this.changedTaskFilter) - .pipe(takeUntil(this.onDestroy$)) - .subscribe(() => { - saveAction.filter = this.changedTaskFilter; - this.action.emit(saveAction); - this.formHasBeenChanged = this.compareFilters(this.changedTaskFilter, this.taskFilter); - }); + protected deleteFilter(filterToDelete: ServiceTaskFilterCloudModel): Observable { + return this.serviceTaskFilterCloudService.deleteFilter(filterToDelete); } - delete(deleteAction: TaskFilterAction): void { - this.serviceTaskFilterCloudService - .deleteFilter(this.taskFilter) - .pipe( - filter((filters) => { - deleteAction.filter = this.taskFilter; - this.action.emit(deleteAction); - return filters.length === 0; - }), - switchMap(() => this.restoreDefaultTaskFilters()), - takeUntil(this.onDestroy$)) - .subscribe(() => { }); - } - - saveAs(saveAsAction: TaskFilterAction): void { - const dialogRef = this.dialog.open(TaskFilterDialogCloudComponent, { - data: { - name: this.translateService.instant(this.taskFilter.name) - }, - height: 'auto', - minWidth: '30%' - }); - dialogRef.afterClosed().subscribe((result) => { - if (result && result.action === TaskFilterDialogCloudComponent.ACTION_SAVE) { - const filterId = Math.random().toString(36).substr(2, 9); - const filterKey = this.getSanitizeFilterName(result.name); - const newFilter = { - name: result.name, - icon: result.icon, - id: filterId, - key: 'custom-' + filterKey - }; - const resultFilter: ServiceTaskFilterCloudModel = Object.assign({}, this.changedTaskFilter, newFilter); - this.serviceTaskFilterCloudService.addFilter(resultFilter) - .pipe(takeUntil(this.onDestroy$)).subscribe(() => { - saveAsAction.filter = resultFilter; - this.action.emit(saveAsAction); - }); - } - }); + protected addFilter(filterToAdd: ServiceTaskFilterCloudModel): Observable { + return this.serviceTaskFilterCloudService + .addFilter(filterToAdd) + .pipe(takeUntil(this.onDestroy$)); } isDisabledForDefaultFilters(action: TaskFilterAction): boolean { @@ -178,90 +91,100 @@ export class EditServiceTaskFilterCloudComponent extends BaseEditTaskFilterCloud return this.serviceTaskFilterCloudService.getTaskListFilters(this.appName); } + private getDefaultProperties() { + return [ + { label: 'ALL', value: '' }, + { label: 'STARTED', value: 'STARTED' }, + { label: 'COMPLETED', value: 'COMPLETED' }, + { label: 'CANCELLED', value: 'CANCELLED' }, + { label: 'ERROR', value: 'ERROR' } + ]; + } + createTaskFilterProperties(): TaskFilterProperties[] { return [ - new TaskFilterProperties({ + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.APP_NAME', type: 'select', key: 'appName', value: this.taskFilter.appName || '', options: this.applicationNames - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.SERVICE_TASK_ID', type: 'text', key: 'serviceTaskId', value: this.taskFilter.serviceTaskId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.ELEMENT_ID', type: 'text', key: 'elementId', value: this.taskFilter.elementId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.ACTIVITY_NAME', type: 'text', key: 'activityName', value: this.taskFilter.activityName || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.ACTIVITY_TYPE', type: 'text', key: 'activityType', value: this.taskFilter.activityType || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.SORT', type: 'select', key: 'sort', value: this.taskFilter.sort || this.createSortProperties[0].value, options: this.createSortProperties - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.DIRECTION', type: 'select', key: 'order', value: this.taskFilter.order || EditServiceTaskFilterCloudComponent.DIRECTIONS[0].value, options: EditServiceTaskFilterCloudComponent.DIRECTIONS - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.STATUS', type: 'select', key: 'status', - value: this.taskFilter.status || EditServiceTaskFilterCloudComponent.DEFAULT_TASK_STATUS_PROPERTIES[0].value, - options: EditServiceTaskFilterCloudComponent.DEFAULT_TASK_STATUS_PROPERTIES - }), - new TaskFilterProperties({ + value: this.taskFilter.status || this.getDefaultProperties()[0].value, + options: this.getDefaultProperties() + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.STARTED_DATE', type: 'date', key: 'startedDate', value: this.taskFilter.completedDate || false - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.COMPLETED_DATE', type: 'date', key: 'completedDate', value: this.taskFilter.completedDate || false - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.PROCESS_INSTANCE_ID', type: 'text', key: 'processInstanceId', value: this.taskFilter.processInstanceId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.PROCESS_DEF_ID', type: 'text', key: 'processDefinitionId', value: this.taskFilter.processDefinitionId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_SERVICE_TASK_FILTER.LABEL.SERVICE_NAME', type: 'text', key: 'serviceName', value: this.taskFilter.serviceName || '' - }) + } ]; } } 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 4a21db748f..132cddfb23 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 @@ -15,18 +15,17 @@ * limitations under the License. */ -import { Component, Output, EventEmitter } from '@angular/core'; +import { Component } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { DateAdapter } from '@angular/material/core'; import { MatDialog } from '@angular/material/dialog'; -import { filter, takeUntil, finalize, switchMap } from 'rxjs/operators'; +import { takeUntil, map } from 'rxjs/operators'; import { Observable } from 'rxjs'; import moment from 'moment-es6'; import { Moment } from 'moment'; import { TaskFilterCloudModel, TaskFilterProperties, TaskFilterAction } from '../../models/filter-cloud.model'; import { TaskFilterCloudService } from '../../services/task-filter-cloud.service'; -import { TaskFilterDialogCloudComponent } from '../task-filter-dialog/task-filter-dialog-cloud.component'; import { TranslationService, UserPreferencesService } from '@alfresco/adf-core'; import { AppsProcessCloudService } from '../../../../app/services/apps-process-cloud.service'; import { DateCloudFilterType } from '../../../../models/date-cloud-filter.model'; @@ -38,76 +37,53 @@ import { BaseEditTaskFilterCloudComponent } from './base-edit-task-filter-cloud. templateUrl: './base-edit-task-filter-cloud.component.html', styleUrls: ['./base-edit-task-filter-cloud.component.scss'] }) -export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudComponent { - - public static DEFAULT_TASK_FILTER_PROPERTIES = ['status', 'assignee', 'sort', 'order']; - public static DEFAULT_TASK_SORT_PROPERTIES = ['id', 'name', 'createdDate', 'priority']; - public static DEFAULT_TASK_STATUS_PROPERTIES = [ - { label: 'ALL', value: '' }, - { label: 'CREATED', value: 'CREATED' }, - { label: 'ASSIGNED', value: 'ASSIGNED' }, - { label: 'SUSPENDED', value: 'SUSPENDED' }, - { label: 'CANCELLED', value: 'CANCELLED' }, - { label: 'COMPLETED', value: 'COMPLETED' } - ]; - - /** Emitted when a task filter property changes. */ - @Output() - filterChange: EventEmitter = new EventEmitter(); - - taskFilter: TaskFilterCloudModel; - changedTaskFilter: TaskFilterCloudModel; - +export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudComponent { constructor( - protected formBuilder: FormBuilder, - public dialog: MatDialog, - private translateService: TranslationService, + formBuilder: FormBuilder, + dialog: MatDialog, + translateService: TranslationService, private taskFilterCloudService: TaskFilterCloudService, - protected dateAdapter: DateAdapter, - protected userPreferencesService: UserPreferencesService, - protected appsProcessCloudService: AppsProcessCloudService, - protected taskCloudService: TaskCloudService) { - super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService); + dateAdapter: DateAdapter, + userPreferencesService: UserPreferencesService, + appsProcessCloudService: AppsProcessCloudService, + taskCloudService: TaskCloudService) { + super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService, dialog, translateService); } - assignNewFilter(formValues: TaskFilterCloudModel) { - this.setLastModifiedToFilter( formValues); - this.changedTaskFilter = new TaskFilterCloudModel(Object.assign({}, this.taskFilter, formValues)); - this.formHasBeenChanged = !this.compareFilters(this.changedTaskFilter, this.taskFilter); + assignNewFilter(model: TaskFilterCloudModel) { + this.setLastModifiedToFilter(model); + this.changedTaskFilter = new TaskFilterCloudModel(Object.assign({}, this.taskFilter, model)); + this.formHasBeenChanged = !this.deepCompare(this.changedTaskFilter, this.taskFilter); this.filterChange.emit(this.changedTaskFilter); } - /** - * Fetches task filter by application name and filter id and creates filter properties, build form - */ - retrieveTaskFilterAndBuildForm() { - this.isLoading = true; - this.taskFilterCloudService.getTaskFilterById(this.appName, this.id) + protected getTaskFilterById(appName: string, id: string) { + return this.taskFilterCloudService + .getTaskFilterById(appName, id) .pipe( - finalize(() => this.isLoading = false), - takeUntil(this.onDestroy$) - ) - .subscribe(response => { - this.taskFilter = new TaskFilterCloudModel(response); - this.taskFilterProperties = this.createAndFilterProperties(); - if (this.hasLastModifiedProperty()) { - this.taskFilterProperties = [...this.taskFilterProperties, ...this.createLastModifiedProperty()]; - } - this.taskFilterActions = this.createAndFilterActions(); - this.buildForm(this.taskFilterProperties); - }); + map(response => new TaskFilterCloudModel(response)) + ); } - checkMandatoryFilterProperties() { - if (this.filterProperties === undefined || this.filterProperties.length === 0) { - this.filterProperties = EditTaskFilterCloudComponent.DEFAULT_TASK_FILTER_PROPERTIES; + createAndFilterProperties() { + const result = super.createAndFilterProperties(); + + if (this.hasLastModifiedProperty()) { + return [ + ...result, + ...this.createLastModifiedProperty() + ]; } + + return result; } - checkMandatorySortProperties(): void { - if (this.sortProperties === undefined || this.sortProperties.length === 0) { - this.sortProperties = EditTaskFilterCloudComponent.DEFAULT_TASK_SORT_PROPERTIES; - } + getDefaultFilterProperties(): string[] { + return ['status', 'assignee', 'sort', 'order']; + } + + getDefaultSortProperties(): string[] { + return ['id', 'name', 'createdDate', 'priority']; } private setLastModifiedToFilter(formValues: TaskFilterCloudModel) { @@ -122,68 +98,18 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone } } - /** - * Return true if both filters are same - * @param editedQuery, @param currentQuery - */ - compareFilters( - editedQuery: TaskFilterCloudModel, - currentQuery: TaskFilterCloudModel - ): boolean { - return JSON.stringify(editedQuery).toLowerCase() === JSON.stringify(currentQuery).toLowerCase(); + protected updateFilter(filterToUpdate: TaskFilterCloudModel): Observable { + return this.taskFilterCloudService.updateFilter(filterToUpdate); } - save(saveAction: TaskFilterAction): void { - this.taskFilterCloudService - .updateFilter(this.changedTaskFilter) - .pipe(takeUntil(this.onDestroy$)) - .subscribe(() => { - saveAction.filter = this.changedTaskFilter; - this.action.emit(saveAction); - this.formHasBeenChanged = this.compareFilters(this.changedTaskFilter, this.taskFilter); - }); + protected deleteFilter(filterToDelete: TaskFilterCloudModel): Observable { + return this.taskFilterCloudService.deleteFilter(filterToDelete); } - delete(deleteAction: TaskFilterAction): void { - this.taskFilterCloudService - .deleteFilter(this.taskFilter) - .pipe( - filter((filters) => { - deleteAction.filter = this.taskFilter; - this.action.emit(deleteAction); - return filters.length === 0; - }), - switchMap(() => this.restoreDefaultTaskFilters()), - takeUntil(this.onDestroy$)) - .subscribe(() => { }); - } - - saveAs(saveAsAction: TaskFilterAction): void { - const dialogRef = this.dialog.open(TaskFilterDialogCloudComponent, { - data: { - name: this.translateService.instant(this.taskFilter.name) - }, - height: 'auto', - minWidth: '30%' - }); - dialogRef.afterClosed().subscribe((result) => { - if (result && result.action === TaskFilterDialogCloudComponent.ACTION_SAVE) { - const filterId = Math.random().toString(36).substr(2, 9); - const filterKey = this.getSanitizeFilterName(result.name); - const newFilter = { - name: result.name, - icon: result.icon, - id: filterId, - key: 'custom-' + filterKey - }; - const resultFilter: TaskFilterCloudModel = Object.assign({}, this.changedTaskFilter, newFilter); - this.taskFilterCloudService.addFilter(resultFilter) - .pipe(takeUntil(this.onDestroy$)).subscribe(() => { - saveAsAction.filter = resultFilter; - this.action.emit(saveAsAction); - }); - } - }); + protected addFilter(filterToAdd: TaskFilterCloudModel): Observable { + return this.taskFilterCloudService + .addFilter(filterToAdd) + .pipe(takeUntil(this.onDestroy$)); } isDisabledForDefaultFilters(action: TaskFilterAction): boolean { @@ -197,122 +123,132 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone return this.taskFilterCloudService.getTaskListFilters(this.appName); } - createLastModifiedProperty(): TaskFilterProperties[] { + private createLastModifiedProperty(): TaskFilterProperties[] { return [ - new TaskFilterProperties({ + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.LAST_MODIFIED_FROM', type: 'date', key: 'lastModifiedFrom', value: '' - }), - - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.LAST_MODIFIED_TO', type: 'date', key: 'lastModifiedTo', value: '' - }) + } + ]; + } + + private getDefaultProperties() { + return [ + { label: 'ALL', value: '' }, + { label: 'CREATED', value: 'CREATED' }, + { label: 'ASSIGNED', value: 'ASSIGNED' }, + { label: 'SUSPENDED', value: 'SUSPENDED' }, + { label: 'CANCELLED', value: 'CANCELLED' }, + { label: 'COMPLETED', value: 'COMPLETED' } ]; } createTaskFilterProperties(): TaskFilterProperties[] { return [ - new TaskFilterProperties({ + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.APP_NAME', type: 'select', key: 'appName', value: this.taskFilter.appName || '', options: this.applicationNames - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.TASK_ID', type: 'text', key: 'taskId', value: '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.STATUS', type: 'select', key: 'status', - value: this.taskFilter.status || EditTaskFilterCloudComponent.DEFAULT_TASK_STATUS_PROPERTIES[0].value, - options: EditTaskFilterCloudComponent.DEFAULT_TASK_STATUS_PROPERTIES - }), - new TaskFilterProperties({ + value: this.taskFilter.status || this.getDefaultProperties()[0].value, + options: this.getDefaultProperties() + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.ASSIGNMENT', type: 'text', key: 'assignee', value: this.taskFilter.assignee || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.PROCESS_DEF_NAME', type: 'select', key: 'processDefinitionName', value: this.taskFilter.processDefinitionName || '', options: this.processDefinitionNames - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.PROCESS_INSTANCE_ID', type: 'text', key: 'processInstanceId', value: this.taskFilter.processInstanceId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.PROCESS_DEF_ID', type: 'text', key: 'processDefinitionId', value: this.taskFilter.processDefinitionId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.TASK_NAME', type: 'text', key: 'taskName', value: this.taskFilter.taskName || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.PARENT_TASK_ID', type: 'text', key: 'parentTaskId', value: this.taskFilter.parentTaskId || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.PRIORITY', type: 'text', key: 'priority', value: this.taskFilter.priority || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.OWNER', type: 'text', key: 'owner', value: this.taskFilter.owner || '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.CREATED_DATE', type: 'date', key: 'createdDate', value: '' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.SORT', type: 'select', key: 'sort', value: this.taskFilter.sort || this.createSortProperties[0].value, options: this.createSortProperties - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.DIRECTION', type: 'select', key: 'order', value: this.taskFilter.order || EditTaskFilterCloudComponent.DIRECTIONS[0].value, options: EditTaskFilterCloudComponent.DIRECTIONS - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.STAND_ALONE', type: 'checkbox', key: 'standalone', value: this.taskFilter.standalone || false - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.DUE_DATE', type: 'date-range', key: 'dueDateRange', @@ -329,8 +265,8 @@ 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', @@ -340,8 +276,8 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone _completedFrom: this.taskFilter.completedFrom || null, _completedTo: this.taskFilter.completedTo || null } - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.CREATED_DATE', type: 'date-range', key: 'createdDateRange', @@ -351,15 +287,15 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone _createdFrom: this.taskFilter.createdFrom || null, _createdTo: this.taskFilter.createdTo || null } - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.COMPLETED_BY', type: 'people', key: 'completedBy', value: this.taskFilter.completedBy ? [this.taskFilter.completedBy] : null, selectionMode: 'single' - }), - new TaskFilterProperties({ + }, + { label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.ASSIGNMENT', type: 'assignment', key: 'assignment', @@ -368,7 +304,7 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone assignee: this.taskFilter.assignee || null, candidateGroups: this.taskFilter.candidateGroups || [] } - }) + } ]; } } diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts index c55dbdeaf0..4b01c8d912 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.spec.ts @@ -21,7 +21,6 @@ import { setupTestBed } from '@alfresco/adf-core'; import { from, Observable } from 'rxjs'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; -import { FilterParamsModel } from '../models/filter-cloud.model'; import { By } from '@angular/platform-browser'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { TaskFiltersCloudModule } from '../task-filters-cloud.module'; @@ -184,7 +183,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { it('should select the task filter based on the input by name param', async(() => { spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ name: 'FakeMyServiceTasks1' }); + component.filterParam = { name: 'FakeMyServiceTasks1' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -202,7 +201,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { it('should select the default task filter if filter input does not exist', async(() => { spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ name: 'UnexistableFilter' }); + component.filterParam = { name: 'UnexistableFilter' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -221,7 +220,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { it('should select the task filter based on the input by index param', async(() => { spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ index: 2 }); + component.filterParam = { index: 2 }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -240,7 +239,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { it('should select the task filter based on the input by id param', async(() => { spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ id: 12 }); + component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -258,7 +257,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { it('should emit an event when a filter is selected', async(() => { spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ id: 12 }); + component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -344,7 +343,7 @@ describe('ServiceTaskFiltersCloudComponent', () => { }); it('should return the current filter after one is selected', () => { - const filter = new FilterParamsModel({ name: 'FakeMyServiceTasks2' }); + const filter = { name: 'FakeMyServiceTasks2' }; component.filters = fakeGlobalServiceFilters; expect(component.currentFilter).toBeUndefined(); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts index 04a9a50b08..6fd69f07b2 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/service-task-filters-cloud.component.ts @@ -32,7 +32,7 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon /** Emitted when a filter in the list is clicked. */ @Output() - filterClick: EventEmitter = new EventEmitter(); + filterClick = new EventEmitter(); filters$: Observable; filters: ServiceTaskFilterCloudModel[] = []; @@ -78,7 +78,7 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon public selectFilter(paramFilter: FilterParamsModel) { if (paramFilter) { - this.currentFilter = (this.filters as Array).find((filter: any, index) => + this.currentFilter = this.filters.find((filter, index) => paramFilter.index === index || paramFilter.key === filter.key || paramFilter.id === filter.id || diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts index 0362491151..eee31ec0cf 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.spec.ts @@ -21,7 +21,6 @@ import { setupTestBed } from '@alfresco/adf-core'; import { from, Observable } from 'rxjs'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service'; -import { FilterParamsModel } from '../models/filter-cloud.model'; import { TaskFilterCloudService } from '../services/task-filter-cloud.service'; import { TaskFiltersCloudComponent } from './task-filters-cloud.component'; import { By } from '@angular/platform-browser'; @@ -184,7 +183,7 @@ describe('TaskFiltersCloudComponent', () => { it('should select the task filter based on the input by name param', async(() => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ name: 'FakeMyTasks1' }); + component.filterParam = { name: 'FakeMyTasks1' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -202,7 +201,7 @@ describe('TaskFiltersCloudComponent', () => { it('should select the default task filter if filter input does not exist', async(() => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ name: 'UnexistableFilter' }); + component.filterParam = { name: 'UnexistableFilter' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -221,7 +220,7 @@ describe('TaskFiltersCloudComponent', () => { it('should select the task filter based on the input by index param', async(() => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ index: 2 }); + component.filterParam = { index: 2 }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -240,7 +239,7 @@ describe('TaskFiltersCloudComponent', () => { it('should select the task filter based on the input by id param', async(() => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ id: 12 }); + component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -258,7 +257,7 @@ describe('TaskFiltersCloudComponent', () => { it('should emit an event when a filter is selected', async(() => { spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable); - component.filterParam = new FilterParamsModel({ id: 12 }); + component.filterParam = { id: '12' }; const appName = 'my-app-1'; const change = new SimpleChange(null, appName, true); @@ -344,7 +343,7 @@ describe('TaskFiltersCloudComponent', () => { }); it('should return the current filter after one is selected', () => { - const filter = new FilterParamsModel({ name: 'FakeInvolvedTasks' }); + const filter = { name: 'FakeInvolvedTasks' }; component.filters = fakeGlobalFilter; expect(component.currentFilter).toBeUndefined(); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts index d63d2a7819..46386163d2 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters-cloud.component.ts @@ -31,7 +31,7 @@ import { BaseTaskFiltersCloudComponent } from './base-task-filters-cloud.compone export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent implements OnInit, OnChanges { /** Emitted when a filter in the list is clicked. */ @Output() - filterClick: EventEmitter = new EventEmitter(); + filterClick = new EventEmitter(); filters$: Observable; filters: TaskFilterCloudModel[] = []; @@ -77,7 +77,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp public selectFilter(paramFilter: FilterParamsModel) { if (paramFilter) { - this.currentFilter = this.filters.find((filter: any, index) => + this.currentFilter = this.filters.find((filter, index) => paramFilter.index === index || paramFilter.key === filter.key || paramFilter.id === filter.id || 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 7c96d4aac7..128f8b6dad 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 @@ -205,42 +205,18 @@ export interface ServiceTaskFilterCloudModel { startedDate?: Date; } -export enum TaskType { - UserTask = 'userTask', - ServiceTask = 'serviceTask' -} - -export class FilterParamsModel { - +export interface FilterParamsModel { id?: string; name?: string; key?: string; index?: number; - - constructor(obj?: any) { - if (obj) { - this.id = obj.id || null; - this.name = obj.name || null; - this.key = obj.key || null; - this.index = obj.index; - } - } } -export class TaskFilterAction { - actionType: string; - icon: string; - tooltip: string; - filter: TaskFilterCloudModel | ServiceTaskFilterCloudModel; - - constructor(obj?: any) { - if (obj) { - this.actionType = obj.actionType || null; - this.icon = obj.icon || null; - this.tooltip = obj.tooltip || null; - this.filter = obj.filter || null; - } - } +export interface TaskFilterAction { + actionType?: string; + icon?: string; + tooltip?: string; + filter?: TaskFilterCloudModel | ServiceTaskFilterCloudModel; } export interface FilterOptions { @@ -254,26 +230,13 @@ export enum AssignmentType { CANDIDATE_GROUPS = 'CANDIDATE_GROUPS' } -export class TaskFilterProperties { - label: string; - type: string; - value: any; - key: string; +export interface TaskFilterProperties { + label?: string; + type?: string; + value?: any; + key?: string; attributes?: { [key: string]: string; }; options?: FilterOptions[]; dateFilterOptions?: DateCloudFilterType[]; selectionMode?: ComponentSelectionMode; - - constructor(obj?: any) { - if (obj) { - this.label = obj.label || null; - this.type = obj.type || null; - this.value = obj.value || ''; - this.key = obj.key || null; - this.attributes = obj.attributes || null; - this.options = obj.options || null; - this.dateFilterOptions = obj.dateFilterOptions || null; - this.selectionMode = obj.selectionMode || null; - } - } } diff --git a/lib/process-services-cloud/tsconfig.lib.json b/lib/process-services-cloud/tsconfig.lib.json index ce6702bd12..cb5fe256c6 100644 --- a/lib/process-services-cloud/tsconfig.lib.json +++ b/lib/process-services-cloud/tsconfig.lib.json @@ -3,7 +3,6 @@ "compilerOptions": { "outDir": "../dist/process-services-cloud/", "baseUrl": "src", - "types": [], "resolveJsonModule": true, "paths": { "@alfresco/adf-extensions": ["../../dist/extensions"], diff --git a/lib/tsconfig.json b/lib/tsconfig.json index 0ab0d60db9..2498afa0c3 100644 --- a/lib/tsconfig.json +++ b/lib/tsconfig.json @@ -17,7 +17,7 @@ "downlevelIteration": true, "outDir": "./dist", "baseUrl": ".", - "types": ["jasmine"], + "types": ["jasmine", "node", "jasminewd2"], "allowSyntheticDefaultImports": true, "resolveJsonModule": true, "paths": { diff --git a/lib/tsconfig.spec.json b/lib/tsconfig.spec.json index 3c0b6a01f9..609d2b0bc4 100644 --- a/lib/tsconfig.spec.json +++ b/lib/tsconfig.spec.json @@ -1,11 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../out-tsc/spec", - "types": [ - "jasmine", - "node" - ] + "outDir": "../../out-tsc/spec" }, "include": [ "**/*.spec.ts", diff --git a/tsconfig.json b/tsconfig.json index 1021d24212..8a0c69a6a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,7 @@ "typeRoots": [ "node_modules/@types" ], + "types": ["jasmine", "node", "jasminewd2"], "lib": [ "es2018", "esnext.array",