mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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
This commit is contained in:
@@ -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[] {
|
||||
|
@@ -24,7 +24,7 @@
|
||||
<form [formGroup]="editProcessFilterForm" *ngIf="editProcessFilterForm">
|
||||
<div fxLayout="row wrap" fxLayout.xs="column" fxLayoutGap="10px" fxLayoutAlign="start center">
|
||||
<ng-container *ngFor="let processFilterProperty of processFilterProperties">
|
||||
<mat-form-field fxFlex="23%" *ngIf="isSelectType(processFilterProperty)" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<mat-form-field fxFlex="23%" *ngIf="processFilterProperty.type === 'select'" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<mat-select
|
||||
placeholder="{{processFilterProperty.label | translate}}"
|
||||
[formControlName]="processFilterProperty.key"
|
||||
@@ -34,21 +34,21 @@
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="23%" *ngIf="isTextType(processFilterProperty)" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<mat-form-field fxFlex="23%" *ngIf="processFilterProperty.type === 'text'" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<input matInput
|
||||
[formControlName]="processFilterProperty.key"
|
||||
type="text"
|
||||
placeholder="{{processFilterProperty.label | translate}}"
|
||||
[attr.data-automation-id]="'adf-cloud-edit-process-property-' + processFilterProperty.key"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="23%" *ngIf="isNumberType(processFilterProperty)" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<mat-form-field fxFlex="23%" *ngIf="processFilterProperty.type === 'number'" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<input matInput
|
||||
[formControlName]="processFilterProperty.key"
|
||||
type="number" min="0"
|
||||
placeholder="{{processFilterProperty.label | translate}}"
|
||||
[attr.data-automation-id]="'adf-cloud-edit-process-property-' + processFilterProperty.key"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="23%" *ngIf="isDateType(processFilterProperty)" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<mat-form-field fxFlex="23%" *ngIf="processFilterProperty.type === 'date'" [attr.data-automation-id]="processFilterProperty.key">
|
||||
<mat-label>{{processFilterProperty.label | translate}}</mat-label>
|
||||
<input
|
||||
matInput
|
||||
@@ -67,13 +67,13 @@
|
||||
</div>
|
||||
</mat-form-field>
|
||||
|
||||
<adf-cloud-date-range-filter *ngIf="isDateRangeType(processFilterProperty)"
|
||||
<adf-cloud-date-range-filter *ngIf="processFilterProperty.type === 'date-range'"
|
||||
[processFilterProperty]="processFilterProperty"
|
||||
[options]="processFilterProperty.dateFilterOptions"
|
||||
(dateTypeChange)="onDateTypeChange($event, processFilterProperty)"
|
||||
(dateChanged)="onDateRangeFilterChanged($event, processFilterProperty)"></adf-cloud-date-range-filter>
|
||||
|
||||
<div fxFlex="23%" *ngIf="isUserSelectType(processFilterProperty)">
|
||||
<div fxFlex="23%" *ngIf="processFilterProperty.type === 'people'">
|
||||
<adf-cloud-people
|
||||
[preSelectUsers]="processFilterProperty.value"
|
||||
[title]="processFilterProperty.label"
|
||||
|
@@ -24,13 +24,11 @@ import { Subject, Observable } from 'rxjs';
|
||||
import moment from 'moment-es6';
|
||||
import { Moment } from 'moment';
|
||||
import { AppsProcessCloudService } from '../../../app/services/apps-process-cloud.service';
|
||||
import { ProcessFilterCloudModel, ProcessFilterProperties, ProcessFilterAction, ProcessFilterOptions, ProcessSortFilterProperties } from '../models/process-filter-cloud.model';
|
||||
import { ProcessFilterCloudModel, ProcessFilterProperties, ProcessFilterAction, ProcessFilterOptions, ProcessSortFilterProperty } from '../models/process-filter-cloud.model';
|
||||
import { IdentityUserModel, TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core';
|
||||
import { ProcessFilterCloudService } from '../services/process-filter-cloud.service';
|
||||
import { ProcessFilterDialogCloudComponent } from './process-filter-dialog-cloud.component';
|
||||
import { ApplicationInstanceModel } from '../../../app/models/application-instance.model';
|
||||
import { ProcessCloudService } from '../../services/process-cloud.service';
|
||||
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
||||
import { DateCloudFilterType, DateRangeFilter } from '../../../models/date-cloud-filter.model';
|
||||
|
||||
@Component({
|
||||
@@ -43,12 +41,6 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
|
||||
public static ACTION_SAVE = 'save';
|
||||
public static ACTION_SAVE_AS = 'saveAs';
|
||||
public static ACTION_DELETE = 'delete';
|
||||
public static APPLICATION_NAME: string = 'appName';
|
||||
public static PROCESS_DEFINITION_NAME: string = 'processDefinitionName';
|
||||
public static APP_RUNNING_STATUS: string = 'RUNNING';
|
||||
public static LAST_MODIFIED: string = 'lastModified';
|
||||
public static SORT: string = 'sort';
|
||||
public static ORDER: string = 'order';
|
||||
public static DEFAULT_PROCESS_FILTER_PROPERTIES = ['status', 'sort', 'order', 'lastModified'];
|
||||
public static DEFAULT_SORT_PROPERTIES = ['id', 'name', 'status', 'startDate'];
|
||||
public static DEFAULT_ACTIONS = ['save', 'saveAs', 'delete'];
|
||||
@@ -92,11 +84,11 @@ export class EditProcessFilterCloudComponent implements OnInit, OnChanges, OnDes
|
||||
|
||||
/** Emitted when a process instance filter property changes. */
|
||||
@Output()
|
||||
filterChange: EventEmitter<ProcessFilterCloudModel> = new EventEmitter();
|
||||
filterChange = new EventEmitter<ProcessFilterCloudModel>();
|
||||
|
||||
/** Emitted when a filter action occurs i.e Save, SaveAs, Delete. */
|
||||
@Output()
|
||||
action: EventEmitter<ProcessFilterAction> = new EventEmitter();
|
||||
action = new EventEmitter<ProcessFilterAction>();
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -44,15 +44,15 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
|
||||
|
||||
/** Emitted when a filter is selected/clicked */
|
||||
@Output()
|
||||
filterClick: EventEmitter<ProcessFilterCloudModel> = new EventEmitter<ProcessFilterCloudModel>();
|
||||
filterClick = new EventEmitter<ProcessFilterCloudModel>();
|
||||
|
||||
/** Emitted when filters are loaded successfully */
|
||||
@Output()
|
||||
success: EventEmitter<any> = new EventEmitter<any>();
|
||||
success = new EventEmitter<any>();
|
||||
|
||||
/** Emitted when any error occurs while loading the filters */
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
error = new EventEmitter<any>();
|
||||
|
||||
filters$: Observable<ProcessFilterCloudModel[]>;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -40,7 +40,7 @@
|
||||
fxLayoutAlign="start center">
|
||||
<ng-container *ngFor="let taskFilterProperty of taskFilterProperties">
|
||||
<mat-form-field fxFlex="23%"
|
||||
*ngIf="isSelectType(taskFilterProperty)"
|
||||
*ngIf="taskFilterProperty.type === 'select'"
|
||||
[attr.data-automation-id]="taskFilterProperty.key">
|
||||
<mat-select placeholder="{{taskFilterProperty.label | translate}}"
|
||||
[formControlName]="taskFilterProperty.key"
|
||||
@@ -53,7 +53,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="23%"
|
||||
*ngIf="isTextType(taskFilterProperty)"
|
||||
*ngIf="taskFilterProperty.type === 'text'"
|
||||
[attr.data-automation-id]="taskFilterProperty.key">
|
||||
<input matInput
|
||||
[formControlName]="taskFilterProperty.key"
|
||||
@@ -62,7 +62,7 @@
|
||||
[attr.data-automation-id]="'adf-cloud-edit-task-property-' + taskFilterProperty.key" />
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="23%"
|
||||
*ngIf="isDateType(taskFilterProperty)"
|
||||
*ngIf="taskFilterProperty.type === 'date'"
|
||||
[attr.data-automation-id]="taskFilterProperty.key">
|
||||
<mat-label>{{taskFilterProperty.label | translate}}</mat-label>
|
||||
<input matInput
|
||||
@@ -70,7 +70,7 @@
|
||||
(dateChange)="onDateChanged($event.value, taskFilterProperty)"
|
||||
[matDatepicker]="dateController"
|
||||
placeholder="{{taskFilterProperty.label | translate}}"
|
||||
[attr.data-automation-id]="'adf-cloud-edit-task-`perty-' + taskFilterProperty.key">
|
||||
[attr.data-automation-id]="'adf-cloud-edit-task-property-' + taskFilterProperty.key">
|
||||
<mat-datepicker-toggle matSuffix
|
||||
[for]="dateController"
|
||||
[attr.data-automation-id]="'adf-cloud-edit-task-property-date-toggle-' + taskFilterProperty.key">
|
||||
@@ -87,7 +87,7 @@
|
||||
</div>
|
||||
</mat-form-field>
|
||||
<div class="adf-edit-task-filter-checkbox"
|
||||
*ngIf="isCheckBoxType(taskFilterProperty)">
|
||||
*ngIf="taskFilterProperty.type === 'checkbox'">
|
||||
<mat-checkbox color="primary"
|
||||
[formControlName]="taskFilterProperty.key"
|
||||
[attr.data-automation-id]="taskFilterProperty.key">
|
||||
@@ -95,14 +95,14 @@
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
|
||||
<adf-cloud-date-range-filter *ngIf="isDateRangeType(taskFilterProperty)"
|
||||
<adf-cloud-date-range-filter *ngIf="taskFilterProperty.type === 'date-range'"
|
||||
[processFilterProperty]="taskFilterProperty"
|
||||
[options]="taskFilterProperty.dateFilterOptions"
|
||||
(dateTypeChange)="onDateTypeChange($event, taskFilterProperty)"
|
||||
(dateChanged)="onDateRangeFilterChanged($event, taskFilterProperty)">
|
||||
</adf-cloud-date-range-filter>
|
||||
|
||||
<div fxFlex="23%" class="{{ 'adf-edit-task-filter-' + taskFilterProperty.key }}" *ngIf="isUserSelectType(taskFilterProperty)">
|
||||
<div fxFlex="23%" class="{{ 'adf-edit-task-filter-' + taskFilterProperty.key }}" *ngIf="taskFilterProperty.type === 'people'">
|
||||
<adf-cloud-people
|
||||
[preSelectUsers]="taskFilterProperty.value"
|
||||
[title]="taskFilterProperty.label"
|
||||
@@ -113,7 +113,7 @@
|
||||
</div>
|
||||
|
||||
<adf-cloud-task-assignment-filter
|
||||
*ngIf="isAssignmentType(taskFilterProperty)"
|
||||
*ngIf="taskFilterProperty.type === 'assignment'"
|
||||
[taskFilterProperty]="taskFilterProperty"
|
||||
(assignedChange)="onAssignedChange($event)"
|
||||
(assignedGroupChange)="onAssignedGroupsChange($event)"></adf-cloud-task-assignment-filter>
|
||||
|
@@ -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<T> 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<TaskFilterAction> = new EventEmitter();
|
||||
action = new EventEmitter<TaskFilterAction>();
|
||||
|
||||
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<T>();
|
||||
|
||||
protected onDestroy$ = new Subject<boolean>();
|
||||
isLoading: boolean = false;
|
||||
|
||||
@@ -110,7 +118,9 @@ export abstract class BaseEditTaskFilterCloudComponent implements OnInit, OnChan
|
||||
protected dateAdapter: DateAdapter<Moment>,
|
||||
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 <FilterOptions> { 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<T[]>;
|
||||
protected abstract addFilter(filterToAdd: T): Observable<any>;
|
||||
protected abstract deleteFilter(filterToDelete: T): Observable<T[]>;
|
||||
protected abstract updateFilter(filterToUpdate: T): Observable<any>;
|
||||
}
|
||||
|
@@ -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<ServiceTaskFilterCloudModel> = new EventEmitter();
|
||||
|
||||
taskFilter: ServiceTaskFilterCloudModel;
|
||||
changedTaskFilter: ServiceTaskFilterCloudModel;
|
||||
|
||||
export class EditServiceTaskFilterCloudComponent extends BaseEditTaskFilterCloudComponent<ServiceTaskFilterCloudModel> {
|
||||
constructor(
|
||||
protected formBuilder: FormBuilder,
|
||||
public dialog: MatDialog,
|
||||
private translateService: TranslationService,
|
||||
formBuilder: FormBuilder,
|
||||
dialog: MatDialog,
|
||||
translateService: TranslationService,
|
||||
private serviceTaskFilterCloudService: ServiceTaskFilterCloudService,
|
||||
protected dateAdapter: DateAdapter<Moment>,
|
||||
protected userPreferencesService: UserPreferencesService,
|
||||
protected appsProcessCloudService: AppsProcessCloudService,
|
||||
protected taskCloudService: TaskCloudService) {
|
||||
super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService);
|
||||
dateAdapter: DateAdapter<Moment>,
|
||||
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<ServiceTaskFilterCloudModel[]> {
|
||||
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<any> {
|
||||
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 || ''
|
||||
})
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -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<TaskFilterCloudModel> = new EventEmitter();
|
||||
|
||||
taskFilter: TaskFilterCloudModel;
|
||||
changedTaskFilter: TaskFilterCloudModel;
|
||||
|
||||
export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudComponent<TaskFilterCloudModel> {
|
||||
constructor(
|
||||
protected formBuilder: FormBuilder,
|
||||
public dialog: MatDialog,
|
||||
private translateService: TranslationService,
|
||||
formBuilder: FormBuilder,
|
||||
dialog: MatDialog,
|
||||
translateService: TranslationService,
|
||||
private taskFilterCloudService: TaskFilterCloudService,
|
||||
protected dateAdapter: DateAdapter<Moment>,
|
||||
protected userPreferencesService: UserPreferencesService,
|
||||
protected appsProcessCloudService: AppsProcessCloudService,
|
||||
protected taskCloudService: TaskCloudService) {
|
||||
super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService);
|
||||
dateAdapter: DateAdapter<Moment>,
|
||||
userPreferencesService: UserPreferencesService,
|
||||
appsProcessCloudService: AppsProcessCloudService,
|
||||
taskCloudService: TaskCloudService) {
|
||||
super(formBuilder, dateAdapter, userPreferencesService, appsProcessCloudService, taskCloudService, dialog, translateService);
|
||||
}
|
||||
|
||||
assignNewFilter(formValues: TaskFilterCloudModel) {
|
||||
this.setLastModifiedToFilter(<TaskFilterCloudModel> 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<any> {
|
||||
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<TaskFilterCloudModel[]> {
|
||||
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<any> {
|
||||
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 || []
|
||||
}
|
||||
})
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -32,7 +32,7 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
|
||||
|
||||
/** Emitted when a filter in the list is clicked. */
|
||||
@Output()
|
||||
filterClick: EventEmitter<ServiceTaskFilterCloudModel> = new EventEmitter<ServiceTaskFilterCloudModel>();
|
||||
filterClick = new EventEmitter<ServiceTaskFilterCloudModel>();
|
||||
|
||||
filters$: Observable<ServiceTaskFilterCloudModel[]>;
|
||||
filters: ServiceTaskFilterCloudModel[] = [];
|
||||
@@ -78,7 +78,7 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
|
||||
|
||||
public selectFilter(paramFilter: FilterParamsModel) {
|
||||
if (paramFilter) {
|
||||
this.currentFilter = (this.filters as Array<ServiceTaskFilterCloudModel>).find((filter: any, index) =>
|
||||
this.currentFilter = this.filters.find((filter, index) =>
|
||||
paramFilter.index === index ||
|
||||
paramFilter.key === filter.key ||
|
||||
paramFilter.id === filter.id ||
|
||||
|
@@ -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();
|
||||
|
@@ -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<TaskFilterCloudModel> = new EventEmitter<TaskFilterCloudModel>();
|
||||
filterClick = new EventEmitter<TaskFilterCloudModel>();
|
||||
|
||||
filters$: Observable<TaskFilterCloudModel[]>;
|
||||
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 ||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user