[AAE-9284] Changes en base edit task filter to be able to save and restore filters

This commit is contained in:
Juan Antonio Aranda
2022-08-31 20:07:56 +02:00
parent 109e99786b
commit 52378d8a5a
5 changed files with 55 additions and 10 deletions

View File

@@ -178,7 +178,8 @@
"TOOL_TIP": { "TOOL_TIP": {
"SAVE": "Save filter", "SAVE": "Save filter",
"SAVE_AS": "Save filter as", "SAVE_AS": "Save filter as",
"DELETE": "Delete filter" "DELETE": "Delete filter",
"RESTORE":"Restore filter"
}, },
"LABEL": { "LABEL": {
"APP_NAME": "ApplicationName", "APP_NAME": "ApplicationName",

View File

@@ -13,7 +13,7 @@
matTooltip="{{ filterAction.tooltip | translate}}" matTooltip="{{ filterAction.tooltip | translate}}"
[attr.data-automation-id]="'adf-filter-action-' + filterAction.actionType" [attr.data-automation-id]="'adf-filter-action-' + filterAction.actionType"
[disabled]="isDisabledAction(filterAction)" [disabled]="isDisabledAction(filterAction)"
(click)="executeFilterActions(filterAction)"> (click)="executeFilterActions($event, filterAction)">
<adf-icon [value]="filterAction.icon"></adf-icon> <adf-icon [value]="filterAction.icon"></adf-icon>
</button> </button>
</ng-container> </ng-container>

View File

@@ -16,13 +16,13 @@
*/ */
import { OnChanges, SimpleChanges, OnInit, OnDestroy, Directive, Input, Output, EventEmitter } from '@angular/core'; import { OnChanges, SimpleChanges, OnInit, OnDestroy, Directive, Input, Output, EventEmitter } from '@angular/core';
import { AssignmentType, FilterOptions, TaskFilterAction, TaskFilterProperties, TaskStatusFilter } from '../../models/filter-cloud.model'; import { AssignmentType, FilterOptions, TaskFilterAction, TaskFilterCloudModel, TaskFilterProperties, TaskStatusFilter } from '../../models/filter-cloud.model';
import { TaskCloudService } from './../../../services/task-cloud.service'; import { TaskCloudService } from './../../../services/task-cloud.service';
import { AppsProcessCloudService } from './../../../../app/services/apps-process-cloud.service'; import { AppsProcessCloudService } from './../../../../app/services/apps-process-cloud.service';
import { DateCloudFilterType, DateRangeFilter } from '../../../../models/date-cloud-filter.model'; import { DateCloudFilterType, DateRangeFilter } from '../../../../models/date-cloud-filter.model';
import moment, { Moment } from 'moment'; import moment, { Moment } from 'moment';
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { AbstractControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { debounceTime, filter, finalize, switchMap, takeUntil } from 'rxjs/operators'; import { debounceTime, filter, finalize, switchMap, takeUntil, tap } from 'rxjs/operators';
import { Observable, Subject } from 'rxjs'; import { Observable, Subject } from 'rxjs';
import { DateAdapter } from '@angular/material/core'; import { DateAdapter } from '@angular/material/core';
import { TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core'; import { TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core';
@@ -31,6 +31,7 @@ import { MatDialog } from '@angular/material/dialog';
import { IdentityUserModel } from '../../../../people/models/identity-user.model'; import { IdentityUserModel } from '../../../../people/models/identity-user.model';
import { IdentityGroupModel } from '../../../../group/models/identity-group.model'; import { IdentityGroupModel } from '../../../../group/models/identity-group.model';
import { MatSelectChange } from '@angular/material/select'; import { MatSelectChange } from '@angular/material/select';
import { TaskFilterCloudService } from '../../services/task-filter-cloud.service';
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/naming-convention */
@@ -46,6 +47,8 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
public static ACTION_SAVE = 'save'; public static ACTION_SAVE = 'save';
public static ACTION_SAVE_AS = 'saveAs'; public static ACTION_SAVE_AS = 'saveAs';
public static ACTION_DELETE = 'delete'; public static ACTION_DELETE = 'delete';
public static ACTION_SAVE_DEFAULT = 'saveDefaultFilter';
public static ACTION_RESTORE = 'restoreDefaultFilter';
public static APP_RUNNING_STATUS: string = 'RUNNING'; public static APP_RUNNING_STATUS: string = 'RUNNING';
public static APPLICATION_NAME: string = 'appName'; public static APPLICATION_NAME: string = 'appName';
public static PROCESS_DEFINITION_NAME: string = 'processDefinitionName'; public static PROCESS_DEFINITION_NAME: string = 'processDefinitionName';
@@ -117,7 +120,7 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
label: 'ADF_CLOUD_TASK_FILTERS.STATUS.ALL' label: 'ADF_CLOUD_TASK_FILTERS.STATUS.ALL'
}; };
taskFilter: T; taskFilter: TaskFilterCloudModel;
changedTaskFilter: T; changedTaskFilter: T;
/** Emitted when a task filter property changes. */ /** Emitted when a task filter property changes. */
@@ -134,7 +137,8 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
protected appsProcessCloudService: AppsProcessCloudService, protected appsProcessCloudService: AppsProcessCloudService,
protected taskCloudService: TaskCloudService, protected taskCloudService: TaskCloudService,
protected dialog: MatDialog, protected dialog: MatDialog,
protected translateService: TranslationService) { protected translateService: TranslationService,
protected taskFilterCloudService: TaskFilterCloudService) {
} }
ngOnInit() { ngOnInit() {
@@ -172,6 +176,16 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
actionType: BaseEditTaskFilterCloudComponent.ACTION_DELETE, actionType: BaseEditTaskFilterCloudComponent.ACTION_DELETE,
icon: 'delete', icon: 'delete',
tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.DELETE' tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.DELETE'
},
{
actionType: BaseEditTaskFilterCloudComponent.ACTION_SAVE_DEFAULT,
icon: 'adf:save',
tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.SAVE'
},
{
actionType: BaseEditTaskFilterCloudComponent.ACTION_RESTORE,
icon: 'settings_backup_restore',
tooltip: 'ADF_CLOUD_EDIT_TASK_FILTER.TOOL_TIP.RESTORE'
} }
]; ];
} }
@@ -221,14 +235,19 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
return name.replace(regExt, '-'); return name.replace(regExt, '-');
} }
executeFilterActions(action: TaskFilterAction): void { executeFilterActions(event: Event, action: TaskFilterAction): void {
if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_SAVE) { if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_SAVE) {
this.save(action); this.save(action);
} else if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_SAVE_AS) { } else if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_SAVE_AS) {
this.saveAs(action); this.saveAs(action);
} else if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_DELETE) { } else if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_DELETE) {
this.delete(action); this.delete(action);
} else if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_SAVE_DEFAULT) {
this.save(action);
} else if (action.actionType === BaseEditTaskFilterCloudComponent.ACTION_RESTORE) {
this.reset(action);
} }
event.stopPropagation();
} }
getRunningApplications() { getRunningApplications() {
@@ -520,6 +539,16 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
}); });
} }
reset(resetAction: TaskFilterAction) {
this.taskFilterCloudService.resetTaskFilterToDefaults(this.appName, this.taskFilter).pipe(
tap((filters: TaskFilterCloudModel[]) => {
resetAction.filter = filters.find(defaultFilter => defaultFilter.name === this.taskFilter.name) || this.taskFilter;
this.action.emit(resetAction);
}),
switchMap(() => this.restoreDefaultTaskFilters()))
.subscribe(() => { });
}
checkMandatoryFilterProperties() { checkMandatoryFilterProperties() {
if (this.filterProperties === undefined || this.filterProperties.length === 0) { if (this.filterProperties === undefined || this.filterProperties.length === 0) {
this.filterProperties = this.getDefaultFilterProperties(); this.filterProperties = this.getDefaultFilterProperties();
@@ -541,6 +570,6 @@ export abstract class BaseEditTaskFilterCloudComponent<T> implements OnInit, OnC
protected abstract restoreDefaultTaskFilters(): Observable<T[]>; protected abstract restoreDefaultTaskFilters(): Observable<T[]>;
protected abstract addFilter(filterToAdd: T): Observable<any>; protected abstract addFilter(filterToAdd: T): Observable<any>;
protected abstract deleteFilter(filterToDelete: T): Observable<T[]>; protected abstract deleteFilter(filterToDelete: TaskFilterCloudModel): Observable<TaskFilterCloudModel[]>;
protected abstract updateFilter(filterToUpdate: T): Observable<any>; protected abstract updateFilter(filterToUpdate: T): Observable<any>;
} }

View File

@@ -42,12 +42,12 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone
formBuilder: UntypedFormBuilder, formBuilder: UntypedFormBuilder,
dialog: MatDialog, dialog: MatDialog,
translateService: TranslationService, translateService: TranslationService,
private taskFilterCloudService: TaskFilterCloudService, taskFilterCloudService: TaskFilterCloudService,
dateAdapter: DateAdapter<Moment>, dateAdapter: DateAdapter<Moment>,
userPreferencesService: UserPreferencesService, userPreferencesService: UserPreferencesService,
appsProcessCloudService: AppsProcessCloudService, appsProcessCloudService: AppsProcessCloudService,
taskCloudService: TaskCloudService) { taskCloudService: TaskCloudService) {
super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService, dialog, translateService); super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService, dialog, translateService, taskFilterCloudService);
} }
assignNewFilter(model: TaskFilterCloudModel) { assignNewFilter(model: TaskFilterCloudModel) {

View File

@@ -369,4 +369,19 @@ export class TaskFilterCloudService extends BaseCloudService {
return this.notificationCloudService.makeGQLQuery(appName, TASK_EVENT_SUBSCRIPTION_QUERY) return this.notificationCloudService.makeGQLQuery(appName, TASK_EVENT_SUBSCRIPTION_QUERY)
.pipe(map((events: any) => events.data.engineEvents)); .pipe(map((events: any) => events.data.engineEvents));
} }
/**
* Reset the task filters to the default configuration if it exists and stores it.
* If there is no default configuration for the task cloud filter with the provided filter name,
* then it changes nothing but stores the current values of the filter
*
* @param appName Name of the target app
* @param filter The task filter to be restored to defaults
* @returns Observable of task filters details
*/
resetTaskFilterToDefaults(appName: string, filter: TaskFilterCloudModel): Observable<TaskFilterCloudModel[]> {
const defaultFilter = this.defaultTaskFilters(appName).find(defaultFilterDefinition => defaultFilterDefinition.name === filter.name) || filter;
defaultFilter.id = filter.id;
return this.updateFilter(defaultFilter);
}
} }