migrate cloud components

This commit is contained in:
Denys Vuika
2024-10-02 09:57:27 -04:00
parent 7fa18879f5
commit 9843a2415f
6 changed files with 163 additions and 229 deletions
@@ -18,17 +18,17 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { TaskListCloudModule } from './task-list/task-list-cloud.module'; import { TaskListCloudModule } from './task-list/task-list-cloud.module';
import { TaskFiltersCloudModule } from './task-filters/task-filters-cloud.module'; import { TaskFiltersCloudModule } from './task-filters/task-filters-cloud.module';
import { TaskHeaderCloudModule } from './task-header/task-header-cloud.module';
import { TaskDirectiveModule } from './directives/task-directive.module'; import { TaskDirectiveModule } from './directives/task-directive.module';
import { TaskFormCloudComponent } from './task-form/components/task-form-cloud.component'; import { TaskFormCloudComponent } from './task-form/components/task-form-cloud.component';
import { StartTaskCloudComponent } from './start-task/components/start-task-cloud.component'; import { StartTaskCloudComponent } from './start-task/components/start-task-cloud.component';
import { TaskHeaderCloudComponent } from './task-header/components/task-header-cloud.component';
@NgModule({ @NgModule({
imports: [ imports: [
TaskListCloudModule, TaskListCloudModule,
TaskFiltersCloudModule, TaskFiltersCloudModule,
StartTaskCloudComponent, StartTaskCloudComponent,
TaskHeaderCloudModule, TaskHeaderCloudComponent,
TaskDirectiveModule, TaskDirectiveModule,
TaskFormCloudComponent TaskFormCloudComponent
], ],
@@ -36,7 +36,7 @@ import { StartTaskCloudComponent } from './start-task/components/start-task-clou
TaskListCloudModule, TaskListCloudModule,
TaskFiltersCloudModule, TaskFiltersCloudModule,
StartTaskCloudComponent, StartTaskCloudComponent,
TaskHeaderCloudModule, TaskHeaderCloudComponent,
TaskDirectiveModule, TaskDirectiveModule,
TaskFormCloudComponent TaskFormCloudComponent
] ]
@@ -23,7 +23,6 @@ import { AlfrescoApiService } from '@alfresco/adf-content-services';
import { AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TaskCloudService } from '../../services/task-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service';
import { TaskHeaderCloudModule } from '../task-header-cloud.module';
import { import {
assignedTaskDetailsCloudMock, assignedTaskDetailsCloudMock,
completedTaskDetailsCloudMock, completedTaskDetailsCloudMock,
@@ -32,7 +31,6 @@ import {
taskDetailsWithParentTaskIdMock, taskDetailsWithParentTaskIdMock,
createdTaskDetailsCloudMock createdTaskDetailsCloudMock
} from '../mocks/task-details-cloud.mock'; } from '../mocks/task-details-cloud.mock';
import { MatSelectModule } from '@angular/material/select';
import { HarnessLoader } from '@angular/cdk/testing'; import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing'; import { MatSelectHarness } from '@angular/material/select/testing';
@@ -62,7 +60,7 @@ describe('TaskHeaderCloudComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule, TaskHeaderCloudModule, MatSelectModule] imports: [ProcessServiceCloudTestingModule, TaskHeaderCloudComponent]
}); });
appConfigService = TestBed.inject(AppConfigService); appConfigService = TestBed.inject(AppConfigService);
appConfigService.config = { appConfigService.config = {
@@ -16,7 +16,6 @@
*/ */
import { applicationConfig, Meta, moduleMetadata, StoryFn } from '@storybook/angular'; import { applicationConfig, Meta, moduleMetadata, StoryFn } from '@storybook/angular';
import { TaskHeaderCloudModule } from '../task-header-cloud.module';
import { TaskHeaderCloudComponent } from './task-header-cloud.component'; import { TaskHeaderCloudComponent } from './task-header-cloud.component';
import { TaskCloudService } from '../../services/task-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service';
import { TaskCloudServiceMock } from '../../mock/task-cloud.service.mock'; import { TaskCloudServiceMock } from '../../mock/task-cloud.service.mock';
@@ -28,7 +27,7 @@ export default {
title: 'Process Services Cloud/Task Cloud/Task Header Cloud/Task Header Cloud', title: 'Process Services Cloud/Task Cloud/Task Header Cloud/Task Header Cloud',
decorators: [ decorators: [
moduleMetadata({ moduleMetadata({
imports: [TaskHeaderCloudModule], imports: [TaskHeaderCloudComponent],
providers: [{ provide: TaskCloudService, useClass: TaskCloudServiceMock }] providers: [{ provide: TaskCloudService, useClass: TaskCloudServiceMock }]
}), }),
applicationConfig({ applicationConfig({
@@ -30,19 +30,25 @@ import {
CardViewUpdateService, CardViewUpdateService,
CardViewDatetimeItemModel, CardViewDatetimeItemModel,
CardViewArrayItem, CardViewArrayItem,
CardViewSelectItemModel CardViewSelectItemModel,
CardViewComponent
} from '@alfresco/adf-core'; } from '@alfresco/adf-core';
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model'; import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
import { TaskCloudService } from '../../services/task-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatCardModule } from '@angular/material/card';
@Component({ @Component({
selector: 'adf-cloud-task-header', selector: 'adf-cloud-task-header',
standalone: true,
imports: [CommonModule, TranslateModule, MatProgressSpinnerModule, CardViewComponent, MatCardModule],
templateUrl: './task-header-cloud.component.html', templateUrl: './task-header-cloud.component.html',
styleUrls: ['./task-header-cloud.component.scss'], styleUrls: ['./task-header-cloud.component.scss'],
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges { export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
/** (Required) The name of the application. */ /** (Required) The name of the application. */
@Input() @Input()
appName: string = ''; appName: string = '';
@@ -92,16 +98,11 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
} }
ngOnInit() { ngOnInit() {
this.taskCloudService.dataChangesDetected$ this.taskCloudService.dataChangesDetected$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => {
this.loadTaskDetailsById(this.appName, this.taskId); this.loadTaskDetailsById(this.appName, this.taskId);
}); });
this.cardViewUpdateService.itemUpdated$ this.cardViewUpdateService.itemUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe(this.updateTaskDetails.bind(this));
.pipe(takeUntil(this.onDestroy$))
.subscribe(this.updateTaskDetails.bind(this)
);
} }
ngOnChanges() { ngOnChanges() {
@@ -115,162 +116,139 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
loadTaskDetailsById(appName: string, taskId: string) { loadTaskDetailsById(appName: string, taskId: string) {
this.isLoading = true; this.isLoading = true;
this.taskCloudService.getTaskById(appName, taskId).pipe( this.taskCloudService
concatMap((task) => .getTaskById(appName, taskId)
forkJoin( .pipe(
of(task), concatMap((task) =>
this.taskCloudService.getCandidateUsers(this.appName, this.taskId), forkJoin(
this.taskCloudService.getCandidateGroups(this.appName, this.taskId) of(task),
) this.taskCloudService.getCandidateUsers(this.appName, this.taskId),
), this.taskCloudService.getCandidateGroups(this.appName, this.taskId)
finalize(() => (this.isLoading = false)) )
).subscribe(([taskDetails, candidateUsers, candidateGroups]) => { ),
this.taskDetails = taskDetails; finalize(() => (this.isLoading = false))
this.candidateGroups = candidateGroups.map((user) => ({ icon: 'group', value: user } as CardViewArrayItem)); )
this.candidateUsers = candidateUsers.map((group) => ({ icon: 'person', value: group } as CardViewArrayItem)); .subscribe(
this.processInstanceId = taskDetails.processInstanceId; ([taskDetails, candidateUsers, candidateGroups]) => {
if (this.taskDetails.parentTaskId) { this.taskDetails = taskDetails;
this.loadParentName(`${this.taskDetails.parentTaskId}`); this.candidateGroups = candidateGroups.map((user) => ({ icon: 'group', value: user } as CardViewArrayItem));
} else { this.candidateUsers = candidateUsers.map((group) => ({ icon: 'person', value: group } as CardViewArrayItem));
this.refreshData(); this.processInstanceId = taskDetails.processInstanceId;
if (this.taskDetails.parentTaskId) {
this.loadParentName(`${this.taskDetails.parentTaskId}`);
} else {
this.refreshData();
}
},
(err) => {
this.error.emit(err);
} }
}, );
(err) => {
this.error.emit(err);
});
} }
private initDefaultProperties() { private initDefaultProperties() {
return [ return [
new CardViewTextItemModel( new CardViewTextItemModel({
{ label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE',
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE', value: this.taskDetails.assignee,
value: this.taskDetails.assignee, key: 'assignee',
key: 'assignee', clickable: this.isAssigneePropertyClickable(),
clickable: this.isAssigneePropertyClickable(), default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE_DEFAULT'),
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.ASSIGNEE_DEFAULT'), icon: 'create'
icon: 'create' }),
} new CardViewTextItemModel({
), label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.STATUS',
new CardViewTextItemModel( value: this.taskDetails.status,
{ key: 'status'
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.STATUS', }),
value: this.taskDetails.status, new CardViewSelectItemModel({
key: 'status' label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PRIORITY',
} value: this.taskDetails.priority.toString(),
), key: 'priority',
new CardViewSelectItemModel( editable: true,
{ displayNoneOption: false,
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PRIORITY', options$: of(this.taskCloudService.priorities)
value: this.taskDetails.priority.toString(), }),
key: 'priority', new CardViewDatetimeItemModel({
editable: true, label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.DUE_DATE',
displayNoneOption: false, value: this.taskDetails.dueDate,
options$: of(this.taskCloudService.priorities) key: 'dueDate',
} default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.DUE_DATE_DEFAULT'),
), editable: true,
new CardViewDatetimeItemModel( format: this.dateFormat,
{ locale: this.dateLocale
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.DUE_DATE', }),
value: this.taskDetails.dueDate, new CardViewTextItemModel({
key: 'dueDate', label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CATEGORY',
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.DUE_DATE_DEFAULT'), value: this.taskDetails.category,
editable: true, key: 'category',
format: this.dateFormat, default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.CATEGORY_DEFAULT')
locale: this.dateLocale }),
} new CardViewDateItemModel({
), label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CREATED',
new CardViewTextItemModel( value: this.taskDetails.createdDate,
{ key: 'created',
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CATEGORY', format: this.dateFormat,
value: this.taskDetails.category, locale: this.dateLocale
key: 'category', }),
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.CATEGORY_DEFAULT') new CardViewTextItemModel({
} label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PARENT_NAME',
), value: this.parentTaskName,
new CardViewDateItemModel( default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.PARENT_NAME_DEFAULT'),
{ key: 'parentName',
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CREATED', clickable: true
value: this.taskDetails.createdDate, }),
key: 'created', new CardViewTextItemModel({
format: this.dateFormat, label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PARENT_TASK_ID',
locale: this.dateLocale value: this.taskDetails.parentTaskId,
} key: 'parentTaskId',
), clickable: true
new CardViewTextItemModel( }),
{ new CardViewDateItemModel({
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PARENT_NAME', label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.END_DATE',
value: this.parentTaskName, value: this.taskDetails.completedDate,
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.PARENT_NAME_DEFAULT'), key: 'endDate',
key: 'parentName', format: this.dateFormat,
clickable: true locale: this.dateLocale
} }),
), new CardViewTextItemModel({
new CardViewTextItemModel( label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.ID',
{ value: this.taskDetails.id,
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PARENT_TASK_ID', key: 'id'
value: this.taskDetails.parentTaskId, }),
key: 'parentTaskId', new CardViewTextItemModel({
clickable: true label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PROCESS_INSTANCE_ID',
} value: this.processInstanceId,
), default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.PROCESS_INSTANCE_ID_DEFAULT'),
new CardViewDateItemModel( key: 'processInstanceId',
{ clickable: true
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.END_DATE', }),
value: this.taskDetails.completedDate, new CardViewTextItemModel({
key: 'endDate', label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.DESCRIPTION',
format: this.dateFormat, value: this.taskDetails.description,
locale: this.dateLocale key: 'description',
} default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.DESCRIPTION_DEFAULT'),
), multiline: true,
new CardViewTextItemModel( editable: true
{ }),
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.ID', new CardViewArrayItemModel({
value: this.taskDetails.id, label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_USERS',
key: 'id' value: of(this.candidateUsers),
} key: 'candidateUsers',
), icon: 'edit',
new CardViewTextItemModel( clickable: false,
{ default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_USERS_DEFAULT'),
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PROCESS_INSTANCE_ID', noOfItemsToDisplay: 2
value: this.processInstanceId, }),
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.PROCESS_INSTANCE_ID_DEFAULT'), new CardViewArrayItemModel({
key: 'processInstanceId', label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_GROUPS',
clickable: true value: of(this.candidateGroups),
} key: 'candidateGroups',
), icon: 'edit',
new CardViewTextItemModel( clickable: false,
{ default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_GROUPS_DEFAULT'),
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.DESCRIPTION', noOfItemsToDisplay: 2
value: this.taskDetails.description, })
key: 'description',
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.DESCRIPTION_DEFAULT'),
multiline: true,
editable: true
}
),
new CardViewArrayItemModel(
{
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_USERS',
value: of(this.candidateUsers),
key: 'candidateUsers',
icon: 'edit',
clickable: false,
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_USERS_DEFAULT'),
noOfItemsToDisplay: 2
}
),
new CardViewArrayItemModel(
{
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_GROUPS',
value: of(this.candidateGroups),
key: 'candidateGroups',
icon: 'edit',
clickable: false,
default: this.translationService.instant('ADF_CLOUD_TASK_HEADER.PROPERTIES.CANDIDATE_GROUPS_DEFAULT'),
noOfItemsToDisplay: 2
}
)
]; ];
} }
@@ -291,26 +269,26 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
* @param updateNotification notification model * @param updateNotification notification model
*/ */
private updateTaskDetails(updateNotification: UpdateNotification) { private updateTaskDetails(updateNotification: UpdateNotification) {
this.taskCloudService.updateTask(this.appName, this.taskId, updateNotification.changed) this.taskCloudService
.pipe(catchError(() => { .updateTask(this.appName, this.taskId, updateNotification.changed)
this.cardViewUpdateService.updateElement(updateNotification.target); .pipe(
return of(null); catchError(() => {
})) this.cardViewUpdateService.updateElement(updateNotification.target);
return of(null);
})
)
.subscribe((taskDetails) => { .subscribe((taskDetails) => {
if (taskDetails) { if (taskDetails) {
this.taskDetails = taskDetails; this.taskDetails = taskDetails;
} }
}); });
} }
private loadParentName(taskId: string) { private loadParentName(taskId: string) {
this.taskCloudService.getTaskById(this.appName, taskId) this.taskCloudService.getTaskById(this.appName, taskId).subscribe((taskDetails) => {
.subscribe( this.parentTaskName = taskDetails.name;
(taskDetails) => { this.refreshData();
this.parentTaskName = taskDetails.name; });
this.refreshData();
}
);
} }
isCompleted(): boolean { isCompleted(): boolean {
@@ -1,30 +0,0 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { TaskHeaderCloudModule } from './task-header-cloud.module';
describe('TaskHeaderCloudModule', () => {
let taskHeaderCloudModule: TaskHeaderCloudModule;
beforeEach(() => {
taskHeaderCloudModule = new TaskHeaderCloudModule();
});
it('should create an instance', () => {
expect(taskHeaderCloudModule).toBeTruthy();
});
});
@@ -16,22 +16,11 @@
*/ */
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MaterialModule } from '../../material.module';
import { CoreModule } from '@alfresco/adf-core';
import { TaskHeaderCloudComponent } from './components/task-header-cloud.component'; import { TaskHeaderCloudComponent } from './components/task-header-cloud.component';
/** @deprecated use TaskHeaderCloudComponent instead */
@NgModule({ @NgModule({
imports: [ imports: [TaskHeaderCloudComponent],
CommonModule, exports: [TaskHeaderCloudComponent]
MaterialModule,
CoreModule.forChild()
],
declarations: [
TaskHeaderCloudComponent
],
exports: [
TaskHeaderCloudComponent
]
}) })
export class TaskHeaderCloudModule { } export class TaskHeaderCloudModule {}