[AAE-4077] - TaskCloud: Refactor priority (#6385)

* [AAE-4077] - TaskCloud: Refactor priority

* export default priority values

* Fix e2e tests

* fix navigation from task-list

* Update task-list-properties-sort.e2e.ts

* Fix lint

Co-authored-by: Cano <david.cano.nieto@gmail.com>
This commit is contained in:
Silviu Popa
2020-11-26 19:38:40 +02:00
committed by GitHub
parent 5086620991
commit f73dece82d
13 changed files with 99 additions and 53 deletions

View File

@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './task.model';

View File

@@ -21,6 +21,7 @@ export * from './start-task/public-api';
export * from './task-header/public-api';
export * from './task-form/public-api';
export * from './directives/public-api';
export * from './models/public-api';
export * from './services/task-cloud.service';
export * from './services/start-task-cloud.service';

View File

@@ -11,6 +11,7 @@
[actions]="showActions"
[actionsPosition]="actionsPosition"
[contextMenu]="showContextMenu"
[resolverFn]="boundReplacePriorityValues"
(showRowActionsMenu)="onShowRowActionsMenu($event)"
(showRowContextMenu)="onShowRowContextMenu($event)"
(executeRowAction)="onExecuteRowAction($event)"

View File

@@ -20,13 +20,14 @@ import {
AppConfigService, UserPreferencesService,
DataTableSchema, UserPreferenceValues,
PaginatedComponent, PaginationModel,
DataRowEvent, CustomEmptyContentTemplateDirective, DataCellEvent, DataRowActionEvent
DataRowEvent, CustomEmptyContentTemplateDirective, DataCellEvent, DataRowActionEvent, DataRow, DataColumn
} from '@alfresco/adf-core';
import { taskPresetsCloudDefaultModel } from '../models/task-preset-cloud.model';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model';
import { BehaviorSubject, Subject } from 'rxjs';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { takeUntil } from 'rxjs/operators';
import { TaskCloudService } from '../../services/task-cloud.service';
@Directive()
// tslint:disable-next-line: directive-class-suffix
@@ -114,10 +115,12 @@ export abstract class BaseTaskListCloudComponent extends DataTableSchema impleme
selectedInstances: any[];
formattedSorting: any[];
private defaultSorting = { key: 'startDate', direction: 'desc' };
boundReplacePriorityValues: Function;
private onDestroy$ = new Subject<boolean>();
constructor(appConfigService: AppConfigService,
private taskCloudService: TaskCloudService,
private userPreferences: UserPreferencesService,
presetKey: string) {
super(appConfigService, presetKey, taskPresetsCloudDefaultModel);
@@ -129,6 +132,7 @@ export abstract class BaseTaskListCloudComponent extends DataTableSchema impleme
totalItems: 0
});
this.boundReplacePriorityValues = this.replacePriorityValues.bind(this);
}
ngOnInit() {
@@ -251,6 +255,15 @@ export abstract class BaseTaskListCloudComponent extends DataTableSchema impleme
return sorting && sorting.length && sorting[0].orderBy && sorting[0].direction;
}
replacePriorityValues(row: DataRow, column: DataColumn) {
return column.key.split('.').reduce((source, key) => {
if (key === 'priority' && typeof(source[key]) === 'number') {
return source[key] = this.taskCloudService.getPriorityLabel(source[key]);
}
return source ? source[key] : '';
}, row.obj);
}
abstract load(requestNode);
abstract createRequestNode();
}

View File

@@ -22,6 +22,7 @@ import {
import { ServiceTaskQueryCloudRequestModel } from '../models/service-task-cloud.model';
import { BaseTaskListCloudComponent } from './base-task-list-cloud.component';
import { ServiceTaskListCloudService } from '../services/service-task-list-cloud.service';
import { TaskCloudService } from '../../services/task-cloud.service';
@Component({
selector: 'adf-cloud-service-task-list',
@@ -38,8 +39,9 @@ export class ServiceTaskListCloudComponent extends BaseTaskListCloudComponent {
constructor(private serviceTaskListCloudService: ServiceTaskListCloudService,
appConfigService: AppConfigService,
taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService) {
super(appConfigService, userPreferences, ServiceTaskListCloudComponent.PRESET_KEY);
super(appConfigService, taskCloudService, userPreferences, ServiceTaskListCloudComponent.PRESET_KEY);
}
load(requestNode: ServiceTaskQueryCloudRequestModel) {

View File

@@ -208,7 +208,7 @@ describe('TaskListCloudComponent', () => {
expect(component.rows[0].entry['createdDate']).toBe(1538059139420);
expect(component.rows[0].entry['dueDate']).toBeNull();
expect(component.rows[0].entry['claimedDate']).toBeNull();
expect(component.rows[0].entry['priority']).toBe('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NOT_SET');
expect(component.rows[0].entry['priority']).toBe(0);
expect(component.rows[0].entry['category']).toBeNull();
expect(component.rows[0].entry['processDefinitionId']).toBeNull();
expect(component.rows[0].entry['processInstanceId']).toBeNull();

View File

@@ -20,9 +20,7 @@ import { AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model';
import { TaskListCloudService } from '../services/task-list-cloud.service';
import { BaseTaskListCloudComponent } from './base-task-list-cloud.component';
import { map } from 'rxjs/operators';
import { TaskCloudService } from '../../services/task-cloud.service';
import { TaskCloudEntryModel, TaskCloudNodePaging } from '../models/task-cloud.model';
@Component({
selector: 'adf-cloud-task-list',
@@ -135,17 +133,15 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent {
candidateGroupId: string = '';
constructor(private taskListCloudService: TaskListCloudService,
private taskCloudService: TaskCloudService,
appConfigService: AppConfigService,
taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService) {
super(appConfigService, userPreferences, TaskListCloudComponent.PRESET_KEY);
super(appConfigService, taskCloudService, userPreferences, TaskListCloudComponent.PRESET_KEY);
}
load(requestNode: TaskQueryCloudRequestModel) {
this.isLoading = true;
this.taskListCloudService.getTaskByRequest(requestNode).pipe(
map((tasks: TaskCloudNodePaging) => this.replacePriorityValues(tasks)
)).subscribe(
this.taskListCloudService.getTaskByRequest(requestNode).subscribe(
(tasks) => {
this.rows = tasks.list.entries;
this.success.emit(tasks);
@@ -190,22 +186,4 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent {
};
return new TaskQueryCloudRequestModel(requestNode);
}
private replacePriorityValues(tasks: TaskCloudNodePaging) {
const entries = tasks.list.entries.map((item: TaskCloudEntryModel) => {
return {
entry: {
...item.entry,
['priority']: this.taskCloudService.getPriorityLabel(item.entry?.priority)
}
};
});
return {
list: {
...tasks.list,
entries: [...entries]
}
};
}
}