[AAE-3638] - implement priority drodpown widget (#6351)

* [AAE-3638] - implement priority drodpown widget

* refactor task cloud service function

* fix remove value on card view text item and move priorities values in app.config.json

* revert app config unnecary changes

* PR changes

* fix unit test

* fix more unit tests

* PR changes

* create task cloud response model

* remove commented code

* fix e2e

* fix start task e2e and add return type
This commit is contained in:
Silviu Popa
2020-11-18 13:25:21 +02:00
committed by GitHub
parent c7e155386b
commit f0e8cd98e5
31 changed files with 242 additions and 97 deletions

View File

@@ -73,7 +73,8 @@
"CANDIDATE_GROUP": "Candidate Group",
"FORM": "Form",
"DATE": "Choose Date",
"NONE": "None"
"NONE": "None",
"PRIORITY": "Priority"
},
"ACTION": {
"START": "Start",
@@ -92,7 +93,13 @@
"DUE_DATE": "Due Date",
"CREATED": "Created",
"JSON_CELL": "Json",
"COMPLETED_BY": "Completed By"
"COMPLETED_BY": "Completed By",
"PRIORITY_VALUES": {
"NOT_SET": "Not set",
"LOW": "Low",
"NORMAL": "Normal",
"HIGH": "High"
}
},
"LIST": {
"MESSAGES": {

View File

@@ -19,3 +19,16 @@ export enum ClaimTaskEnum {
claim = 'claim',
unclaim = 'unclaim'
}
export interface TaskPriorityOption {
label: string;
key: string;
value: string;
}
export const DEFAULT_TASK_PRIORITIES: TaskPriorityOption[] = [
{ label: 'ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NOT_SET', value: '0', key: '0' },
{ label: 'ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.LOW', value: '1', key: '1' },
{ label: 'ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NORMAL', value: '2', key: '2' },
{ label: 'ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.HIGH', value: '3', key: '3' }
];

View File

@@ -16,7 +16,7 @@
*/
import { async, TestBed } from '@angular/core/testing';
import { setupTestBed, IdentityUserService, StorageService, AlfrescoApiServiceMock, LogService, AppConfigService } from '@alfresco/adf-core';
import { setupTestBed, IdentityUserService, TranslationService, AlfrescoApiService } from '@alfresco/adf-core';
import { TaskCloudService } from './task-cloud.service';
import { taskCompleteCloudMock } from '../task-header/mocks/fake-complete-task.mock';
import { assignedTaskDetailsCloudMock, createdTaskDetailsCloudMock, emptyOwnerTaskDetailsCloudMock } from '../task-header/mocks/task-details-cloud.mock';
@@ -28,8 +28,9 @@ import { TranslateModule } from '@ngx-translate/core';
describe('Task Cloud Service', () => {
let service: TaskCloudService;
let alfrescoApiMock: AlfrescoApiServiceMock;
let alfrescoApiMock: AlfrescoApiService;
let identityUserService: IdentityUserService;
let translateService: TranslationService;
function returnFakeTaskCompleteResults() {
return {
@@ -89,13 +90,12 @@ describe('Task Cloud Service', () => {
});
beforeEach(async(() => {
alfrescoApiMock = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
alfrescoApiMock = TestBed.inject(AlfrescoApiService);
identityUserService = TestBed.inject(IdentityUserService);
translateService = TestBed.inject(TranslationService);
service = TestBed.inject(TaskCloudService);
spyOn(translateService, 'instant').and.callFake((key) => key ? `${key}_translated` : null);
spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(cloudMockUser);
service = new TaskCloudService(alfrescoApiMock,
new AppConfigService(null),
new LogService(new AppConfigService(null)),
identityUserService);
}));

View File

@@ -16,13 +16,14 @@
*/
import { Injectable } from '@angular/core';
import { AlfrescoApiService, LogService, AppConfigService, IdentityUserService, CardViewArrayItem } from '@alfresco/adf-core';
import { AlfrescoApiService, LogService, AppConfigService, IdentityUserService, CardViewArrayItem, TranslationService } from '@alfresco/adf-core';
import { throwError, Observable, of, Subject } from 'rxjs';
import { map } from 'rxjs/operators';
import { TaskDetailsCloudModel, StartTaskCloudResponseModel } from '../start-task/models/task-details-cloud.model';
import { BaseCloudService } from '../../services/base-cloud.service';
import { StartTaskCloudRequestModel } from '../start-task/models/start-task-cloud-request.model';
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
import { DEFAULT_TASK_PRIORITIES, TaskPriorityOption } from '../models/task.model';
@Injectable({
providedIn: 'root'
@@ -36,6 +37,7 @@ export class TaskCloudService extends BaseCloudService {
apiService: AlfrescoApiService,
appConfigService: AppConfigService,
private logService: LogService,
private translateService: TranslationService,
private identityUserService: IdentityUserService
) {
super(apiService, appConfigService);
@@ -280,6 +282,15 @@ export class TaskCloudService extends BaseCloudService {
}
}
getPriorityLabel(priority: number): string {
const priorityItem = this.priorities.find(item => item.value === priority.toString()) || this.priorities[0];
return this.translateService.instant(priorityItem.label);
}
get priorities(): TaskPriorityOption[] {
return this.appConfigService.get('adf-cloud-priority-values') || DEFAULT_TASK_PRIORITIES;
}
private isAssignedToMe(assignee: string): boolean {
const currentUser = this.identityUserService.getCurrentUserInfo().username;
return assignee === currentUser;

View File

@@ -33,10 +33,11 @@
</textarea>
</mat-form-field>
<mat-form-field fxFlex>
<div style="height: 40px;">
<input matInput type="number" placeholder="Priority" formControlName="priority">
</div>
<mat-form-field fxFlex class="adf-cloud-priority-container">
<mat-label>{{ 'ADF_CLOUD_TASK_LIST.START_TASK.FORM.LABEL.PRIORITY' | translate }}</mat-label>
<mat-select formControlName="priority">
<mat-option *ngFor="let priorityOption of priorities" [value]="priorityOption.value">{{ priorityOption.label | translate }}</mat-option>
</mat-select>
</mat-form-field>
</div>
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px">

View File

@@ -15,6 +15,10 @@
}
}
.adf-cloud-priority-container {
padding-top: 1.1em;
}
.adf-cloud-date-error-container {
position: absolute;
height: 20px;

View File

@@ -33,6 +33,7 @@ import { GroupCloudComponent } from '../../../group/components/group-cloud.compo
import { TaskCloudService } from '../../services/task-cloud.service';
import { StartTaskCloudRequestModel } from '../models/start-task-cloud-request.model';
import { takeUntil } from 'rxjs/operators';
import { TaskPriorityOption } from '../../models/task.model';
@Component({
selector: 'adf-cloud-start-task',
@@ -100,6 +101,8 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
formKey: string;
priorities: TaskPriorityOption[];
private assigneeForm: AbstractControl = new FormControl('');
private groupForm: AbstractControl = new FormControl('');
private onDestroy$ = new Subject<boolean>();
@@ -119,6 +122,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
.subscribe(locale => this.dateAdapter.setLocale(locale));
this.loadCurrentUser();
this.buildForm();
this.loadDefaultPriorities();
}
ngOnDestroy() {
@@ -129,7 +133,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
buildForm() {
this.taskForm = this.formBuilder.group({
name: new FormControl(this.name, [Validators.required, Validators.maxLength(this.getMaxNameLength()), this.whitespaceValidator]),
priority: new FormControl(),
priority: new FormControl(''),
description: new FormControl('', [this.whitespaceValidator]),
formKey: new FormControl()
});
@@ -145,6 +149,10 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
this.assigneeName = this.currentUser.username;
}
private loadDefaultPriorities() {
this.priorities = this.taskService.priorities;
}
public saveTask() {
this.submitted = true;
const newTask = Object.assign(this.taskForm.value);

View File

@@ -48,7 +48,7 @@
<mat-option *ngFor="let propertyOption of taskFilterProperty.options"
[value]="propertyOption.value"
[attr.data-automation-id]="'adf-cloud-edit-task-property-options-' + taskFilterProperty.key">
{{ propertyOption.label }}
{{ propertyOption.label | translate }}
</mat-option>
</mat-select>
</mat-form-field>
@@ -112,7 +112,7 @@
(changedUsers)="onChangedUser($event, taskFilterProperty)"></adf-cloud-people>
</div>
<adf-cloud-task-assignment-filter
<adf-cloud-task-assignment-filter fxFlex="23%"
*ngIf="taskFilterProperty.type === 'assignment'"
[taskFilterProperty]="taskFilterProperty"
(assignedChange)="onAssignedChange($event)"

View File

@@ -212,9 +212,10 @@ export class EditTaskFilterCloudComponent extends BaseEditTaskFilterCloudCompone
},
{
label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.PRIORITY',
type: 'text',
type: 'select',
key: 'priority',
value: this.taskFilter.priority || ''
value: this.taskFilter.priority || '',
options: this.taskCloudService.priorities
},
{
label: 'ADF_CLOUD_EDIT_TASK_FILTER.LABEL.OWNER',

View File

@@ -1,4 +1,4 @@
<div fxLayout="row">
<div class="adf-cloud-assignment-container" fxLayout="row">
<mat-form-field>
<mat-select class="adf-task-assignment-filter"
placeholder="{{ 'ADF_CLOUD_TASK_ASSIGNEMNT_FILTER.ASSIGNMENT_TYPE' | translate }}"

View File

@@ -1,3 +1,11 @@
.adf-cloud-assignment-container {
align-items: center;
mat-form-field {
width: 100%;
}
}
.adf-task-assignment-filter {
margin-right: 10px;
}
@@ -5,4 +13,5 @@
.adf-group-cloud-filter {
margin-left:15px;
flex: 1;
width:100%;
}

View File

@@ -5,6 +5,7 @@
<mat-card-content>
<adf-card-view
*ngIf="!isLoading; else loadingTemplate"
[displayNoneOption]="false"
[properties]="properties"
[editable]="isTaskEditable()"
[displayClearAction]="displayDateClearAction">

View File

@@ -33,6 +33,7 @@ import {
} from '../mocks/task-details-cloud.mock';
import moment from 'moment-es6';
import { TranslateModule } from '@ngx-translate/core';
import { MatSelectModule } from '@angular/material/select';
describe('TaskHeaderCloudComponent', () => {
let component: TaskHeaderCloudComponent;
@@ -58,7 +59,8 @@ describe('TaskHeaderCloudComponent', () => {
imports: [
TranslateModule.forRoot(),
ProcessServiceCloudTestingModule,
TaskHeaderCloudModule
TaskHeaderCloudModule,
MatSelectModule
]
});
@@ -122,32 +124,21 @@ describe('TaskHeaderCloudComponent', () => {
expect(statusEl.nativeElement.value).toBe('ASSIGNED');
});
it('should display priority', async () => {
it('should display priority with default values', async () => {
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const priorityEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-priority"]'));
expect(priorityEl.nativeElement.value).toBe('5');
});
const priorityEl = fixture.debugElement.nativeElement.querySelector('[data-automation-id="header-priority"] .mat-select-trigger');
expect(priorityEl).toBeDefined();
expect(priorityEl).not.toBeNull();
it('should display error if priority is not a number', async (done) => {
fixture.detectChanges();
await fixture.whenStable();
priorityEl.click();
fixture.detectChanges();
const formPriorityEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-priority"]'));
formPriorityEl.nativeElement.value = 'stringValue';
formPriorityEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
const errorMessageEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-error-priority"]'));
expect(errorMessageEl).not.toBeNull();
done();
const options: any = fixture.debugElement.queryAll(By.css('mat-option'));
expect(options[0].nativeElement.innerText).toEqual('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NOT_SET');
expect(options[1].nativeElement.innerText).toEqual('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.LOW');
expect(options[2].nativeElement.innerText).toEqual('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NORMAL');
expect(options[3].nativeElement.innerText).toEqual('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.HIGH');
});
it('should display due date', async () => {
@@ -322,10 +313,8 @@ describe('TaskHeaderCloudComponent', () => {
it('should render edit icon if the task in assigned state and assingee should be current user', () => {
fixture.detectChanges();
const priorityEditIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-priority"] [class*="adf-textitem-edit-icon"]`));
const descriptionEditIcon = fixture.debugElement.query(By.css(`[data-automation-id="header-description"] [class*="adf-textitem-edit-icon"]`));
const dueDateEditIcon = fixture.debugElement.query(By.css(`[data-automation-id="datepickertoggle-dueDate"]`));
expect(priorityEditIcon).not.toBeNull('Priority edit icon should be shown');
expect(descriptionEditIcon).not.toBeNull('Description edit icon should be shown');
expect(dueDateEditIcon).not.toBeNull('Due date edit icon should be shown');
});

View File

@@ -29,11 +29,11 @@ import {
UpdateNotification,
CardViewUpdateService,
CardViewDatetimeItemModel,
CardViewArrayItem
CardViewArrayItem,
CardViewSelectItemModel
} from '@alfresco/adf-core';
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
import { TaskCloudService } from '../../services/task-cloud.service';
import { NumericFieldValidator } from '../../../validators/numeric-field.validator';
@Component({
selector: 'adf-cloud-task-header',
@@ -158,13 +158,13 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
key: 'status'
}
),
new CardViewTextItemModel(
new CardViewSelectItemModel(
{
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PRIORITY',
value: this.taskDetails.priority,
value: this.taskDetails.priority.toString(),
key: 'priority',
editable: true,
validators: [new NumericFieldValidator()]
options$: of(this.taskCloudService.priorities)
}
),
new CardViewDatetimeItemModel(

View File

@@ -51,7 +51,7 @@ export const assignedTaskDetailsCloudMock: TaskDetailsCloudModel = {
'createdDate': new Date(1545048055900),
'dueDate': new Date(),
'claimedDate': null,
'priority': 5,
'priority': 1,
'category': null,
'processDefinitionId': null,
'processInstanceId': null,

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(0);
expect(component.rows[0].entry['priority']).toBe('ADF_CLOUD_TASK_LIST.PROPERTIES.PRIORITY_VALUES.NOT_SET');
expect(component.rows[0].entry['category']).toBeNull();
expect(component.rows[0].entry['processDefinitionId']).toBeNull();
expect(component.rows[0].entry['processInstanceId']).toBeNull();

View File

@@ -20,6 +20,9 @@ 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',
@@ -132,6 +135,7 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent {
candidateGroupId: string = '';
constructor(private taskListCloudService: TaskListCloudService,
private taskCloudService: TaskCloudService,
appConfigService: AppConfigService,
userPreferences: UserPreferencesService) {
super(appConfigService, userPreferences, TaskListCloudComponent.PRESET_KEY);
@@ -139,7 +143,9 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent {
load(requestNode: TaskQueryCloudRequestModel) {
this.isLoading = true;
this.taskListCloudService.getTaskByRequest(<TaskQueryCloudRequestModel> requestNode).subscribe(
this.taskListCloudService.getTaskByRequest(requestNode).pipe(
map((tasks: TaskCloudNodePaging) => this.replacePriorityValues(tasks)
)).subscribe(
(tasks) => {
this.rows = tasks.list.entries;
this.success.emit(tasks);
@@ -184,4 +190,22 @@ 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]
}
};
}
}

View File

@@ -0,0 +1,57 @@
/*!
* @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.
*/
import { Pagination } from '@alfresco/js-api';
import { IdentityGroupModel, IdentityUserModel } from '@alfresco/adf-core';
export class TaskCloudNodePaging {
list: TaskCloudPagingList;
}
export class TaskCloudPagingList {
pagination: Pagination;
entries: TaskCloudEntryModel[];
}
export class TaskCloudEntryModel {
entry: TaskCloudModel;
}
export interface TaskCloudModel {
appName: string;
appVersion: string;
assignee: string;
candidateGroups: IdentityGroupModel[];
candidateUsers: IdentityUserModel[];
createdDate: string;
formKey: string;
id: string;
inFinalState: boolean;
lastModified: string;
name: string;
priority: number;
processDefinitionId: string;
processDefinitionName: string;
processDefinitionVersion: number;
processInstanceId: string;
serviceFullName: string;
serviceName: string;
serviceVersion: string;
standalone: boolean;
status: string;
taskDefinitionKey: string;
}

View File

@@ -21,6 +21,7 @@ import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model';
import { Observable, throwError } from 'rxjs';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
import { BaseCloudService } from '../../../services/base-cloud.service';
import { TaskCloudNodePaging } from '../models/task-cloud.model';
@Injectable({ providedIn: 'root' })
export class TaskListCloudService extends BaseCloudService {
@@ -44,7 +45,7 @@ export class TaskListCloudService extends BaseCloudService {
if (sortingParams) {
queryParams['sort'] = sortingParams;
}
return this.get(queryUrl, queryParams);
return this.get<TaskCloudNodePaging>(queryUrl, queryParams);
} else {
this.logService.error('Appname is mandatory for querying task');
return throwError('Appname not configured');