Skip to content

Commit

Permalink
[AAE-29424] applied pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszhanaj committed Dec 17, 2024
1 parent eff08c2 commit 2585e1e
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<div>
<div #container></div>
</div>
<div #container></div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ScreenCloudComponent } from './screen-cloud.component';
import { TaskScreenCloudComponent } from './screen-cloud.component';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ScreenRenderingService } from '../../../services/public-api';
Expand All @@ -31,15 +31,15 @@ import { By } from '@angular/platform-browser';
})
class TestComponent {}

describe('ScreenCloudComponent', () => {
let fixture: ComponentFixture<ScreenCloudComponent>;
describe('TaskScreenCloudComponent', () => {
let fixture: ComponentFixture<TaskScreenCloudComponent>;
let screenRenderingService: ScreenRenderingService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ScreenCloudComponent, TestComponent]
imports: [TaskScreenCloudComponent, TestComponent]
});
fixture = TestBed.createComponent(ScreenCloudComponent);
fixture = TestBed.createComponent(TaskScreenCloudComponent);
screenRenderingService = TestBed.inject(ScreenRenderingService);
screenRenderingService.register({ ['test']: () => TestComponent });
fixture.componentRef.setInput('screenId', 'test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
* limitations under the License.
*/

import { DynamicComponentModel } from '@alfresco/adf-core';
import { ScreenRenderingService } from '../../../services/public-api';
import { CommonModule } from '@angular/common';
import { Component, ComponentRef, inject, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { ScreenRenderingService } from '../../../services/public-api';

@Component({
selector: 'adf-cloud-screen-cloud',
selector: 'adf-cloud-task-screen',
standalone: true,
imports: [CommonModule],
template: '<div #container></div>'
})
export class ScreenCloudComponent implements OnInit {
export class TaskScreenCloudComponent implements OnInit {
/** Task id to fetch corresponding form and values. */
@Input() taskId: string;
/** App id to fetch corresponding form and values. */
Expand All @@ -41,15 +40,13 @@ export class ScreenCloudComponent implements OnInit {

@ViewChild('container', { read: ViewContainerRef, static: true })
container: ViewContainerRef;
screenComponent: DynamicComponentModel;
componentRef: ComponentRef<any>;

private readonly screenRenderingService = inject(ScreenRenderingService);

ngOnInit() {
if (this.screenId) {
this.screenComponent = { type: this.screenId };
const componentType = this.screenRenderingService.resolveComponentType(this.screenComponent);
const componentType = this.screenRenderingService.resolveComponentType({ type: this.screenId });
this.componentRef = this.container.createComponent(componentType);
if (this.taskId) {
this.componentRef.setInput('taskId', this.taskId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

import { DynamicComponentMapper } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { DynamicComponentMapper } from '../../../../core/src/lib/common/services/dynamic-component-mapper.service';

@Injectable({
providedIn: 'root'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<div class="adf-task-form-cloud-container" >
<adf-cloud-form #adfCloudForm
[appName]="appName"
[appVersion]="taskDetails.appVersion"
[taskId]="taskId"
[showTitle]="showTitle"
[processInstanceId]="taskDetails.processInstanceId"
[readOnly]="isReadOnly()"
[showRefreshButton]="showRefreshButton"
[showValidationIcon]="showValidationIcon"
[showCompleteButton]="canCompleteTask()"
[showSaveButton]="canCompleteTask()"
[displayModeConfigurations]="displayModeConfigurations"
[fieldValidators]="fieldValidators"
(formSaved)="onFormSaved($event)"
(formCompleted)="onFormCompleted($event)"
(formError)="onError($event)"
(error)="onError($event)"
(formContentClicked)="onFormContentClicked($event)"
(executeOutcome)="onFormExecuteOutcome($event)"
(displayModeOn)="onDisplayModeOn($event)"
(displayModeOff)="onDisplayModeOff($event)">
<div class="adf-task-form-cloud-container">
<adf-cloud-form
#adfCloudForm
[appName]="appName"
[appVersion]="taskDetails.appVersion"
[taskId]="taskId"
[showTitle]="showTitle"
[processInstanceId]="taskDetails.processInstanceId"
[readOnly]="isReadOnly()"
[showRefreshButton]="showRefreshButton"
[showValidationIcon]="showValidationIcon"
[showCompleteButton]="canCompleteTask()"
[showSaveButton]="canCompleteTask()"
[displayModeConfigurations]="displayModeConfigurations"
[fieldValidators]="fieldValidators"
(formSaved)="onFormSaved($event)"
(formCompleted)="onFormCompleted($event)"
(formError)="onError($event)"
(error)="onError($event)"
(formContentClicked)="onFormContentClicked($event)"
(executeOutcome)="onFormExecuteOutcome($event)"
(displayModeOn)="onDisplayModeOn($event)"
(displayModeOff)="onDisplayModeOff($event)"
>
<adf-cloud-form-custom-outcomes>
<adf-cloud-user-task-cloud-buttons
[appName]="appName"
Expand All @@ -30,7 +32,8 @@
(cancelClick)="onCancelClick()"
(claimTask)="onClaimTask()"
(unclaimTask)="onUnclaimTask()"
(error)="onError($event)">
(error)="onError($event)"
>
</adf-cloud-user-task-cloud-buttons>
</adf-cloud-form-custom-outcomes>
</adf-cloud-form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<button
mat-button
*ngIf="showCancelButton"
mat-button
id="adf-cloud-cancel-task"
(click)="onCancelClick()">
(click)="onCancelClick()"
>
{{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.CANCEL' | translate}}
</button>
<button
class="adf-user-task-cloud-claim-btn"
mat-button
*ngIf="canClaimTask"
adf-cloud-claim-task
class="adf-user-task-cloud-claim-btn"
mat-button
[appName]="appName"
[taskId]="taskId"
(success)="onClaimTask()"
(error)="onError($event)">
(error)="onError($event)"
>
{{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.CLAIM' | translate}}
</button>
<button
class="adf-user-task-cloud-unclaim-btn"
mat-button
*ngIf="canUnclaimTask"
adf-cloud-unclaim-task
class="adf-user-task-cloud-unclaim-btn"
mat-button
[appName]="appName"
[taskId]="taskId"
(success)="onUnclaimTask()"
(error)="onError($event)">
(error)="onError($event)"
>
{{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.UNCLAIM' | translate}}
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@
[appName]="appName"
[candidateUsers]="candidateUsers"
[candidateGroups]="candidateGroups"
[taskId]="taskId"
[taskDetails]="taskDetails"
[showValidationIcon]="showValidationIcon"
[showTitle]="showTitle"
[displayModeConfigurations]="displayModeConfigurations"
[fieldValidators]="fieldValidators"
[showValidationIcon]="showValidationIcon"
[showTitle]="showTitle"
[taskId]="taskId"
[taskDetails]="taskDetails"
(cancelClick)="onCancelForm()"
(executeOutcome)="onExecuteOutcome($event)"
(error)="onError($event)"
(formSaved)="onFormSaved()"
(formContentClicked)="onFormContentClicked($event)"
(taskCompleted)="onCompleteTaskForm()"
(taskClaimed)="onClaimTask()"
(taskUnclaimed)="onTaskUnclaimed()"
(formContentClicked)="onFormContentClicked($event)"
(executeOutcome)="onExecuteOutcome($event)"
(error)="onError($event)">
>
</adf-cloud-task-form>
</ng-container>

<ng-container *ngSwitchCase="taskTypeEnum.Screen">
<adf-cloud-screen-cloud [taskId]="taskId" [appName]="appName" [screenId]="screenId"></adf-cloud-screen-cloud>
<adf-cloud-task-screen
[taskId]="taskId"
[appName]="appName"
[screenId]="screenId"
>
</adf-cloud-task-screen>
</ng-container>

<ng-container *ngSwitchCase="taskTypeEnum.None">
Expand All @@ -48,16 +55,16 @@ <h4>
<ng-template [ngTemplateOutlet]="taskFormCloudButtons">
</ng-template>
<button
mat-button
*ngIf="canCompleteTask()"
mat-button
adf-cloud-complete-task
[appName]="appName"
[taskId]="taskId"
(success)="onCompleteTask()"
(error)="onError($event)"
color="primary"
id="adf-form-complete"
>
>
{{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.COMPLETE' | translate}}
</button>
</mat-card-actions>
Expand All @@ -68,7 +75,6 @@ <h4>
</div>
</div>


<ng-template #loadingTemplate>
<mat-spinner class="adf-user-task-cloud-spinner" />
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ export class UserTaskCloudComponent implements OnInit, OnChanges {
private taskCloudService: TaskCloudService = inject(TaskCloudService);
private readonly destroyRef = inject(DestroyRef);

ngOnChanges(changes: SimpleChanges) {
const appName = changes['appName'];
if (appName && appName.currentValue !== appName.previousValue && this.taskId) {
this.loadTask();
return;
}

const taskId = changes['taskId'];
if (taskId?.currentValue && this.appName) {
this.loadTask();
return;
}
}

ngOnInit() {
if (this.appName === '' && this.taskId) {
this.loadTask();
}
}

canClaimTask(): boolean {
return !this.readOnly && this.taskCloudService.canClaimTask(this.taskDetails) && this.hasCandidateUsersOrGroups();
}
Expand All @@ -140,7 +160,7 @@ export class UserTaskCloudComponent implements OnInit, OnChanges {
return !this.readOnly && this.taskCloudService.canUnclaimTask(this.taskDetails) && this.hasCandidateUsersOrGroups();
}

getTaskType() {
getTaskType(): void {
if (this.taskDetails && !!this.taskDetails.formKey && this.taskDetails.formKey.includes(this.taskTypeEnum.Form)) {
this.taskType = this.taskTypeEnum.Form;
} else if (this.taskDetails && !!this.taskDetails.formKey && this.taskDetails.formKey.includes(this.taskTypeEnum.Screen)) {
Expand All @@ -164,52 +184,52 @@ export class UserTaskCloudComponent implements OnInit, OnChanges {
return this.hasCandidateUsers() || this.hasCandidateGroups();
}

onCancelForm() {
onCancelForm(): void {
this.cancelClick.emit();
}

onCancelClick() {
onCancelClick(): void {
this.cancelClick.emit(this.taskId);
}

onClaimTask() {
onClaimTask(): void {
this.loadTask();
this.taskClaimed.emit(this.taskId);
}

onCompleteTask() {
onCompleteTask(): void {
this.loadTask();
this.taskCompleted.emit(this.taskId);
}

onCompleteTaskForm() {
onCompleteTaskForm(): void {
this.taskCompleted.emit();
}

onError(data: any) {
onError(data: any): void {
this.error.emit(data);
}

onExecuteOutcome(outcome: FormOutcomeEvent) {
onExecuteOutcome(outcome: FormOutcomeEvent): void {
this.executeOutcome.emit(outcome);
}
onFormContentClicked(content: ContentLinkModel) {
onFormContentClicked(content: ContentLinkModel): void {
this.formContentClicked.emit(content);
}
onFormSaved() {
onFormSaved(): void {
this.formSaved.emit();
}

onTaskUnclaimed() {
onTaskUnclaimed(): void {
this.taskUnclaimed.emit();
}

onUnclaimTask() {
onUnclaimTask(): void {
this.loadTask();
this.taskUnclaimed.emit(this.taskId);
}

private loadTask() {
private loadTask(): void {
this.loading = true;
this.taskCloudService
.getTaskById(this.appName, this.taskId)
Expand All @@ -225,29 +245,9 @@ export class UserTaskCloudComponent implements OnInit, OnChanges {
this.taskCloudService.getCandidateGroups(this.appName, this.taskId).subscribe((groups) => (this.candidateGroups = groups || []));
}

public switchToDisplayMode(newDisplayMode?: string) {
public switchToDisplayMode(newDisplayMode?: string): void {
if (this.adfCloudTaskForm) {
this.adfCloudTaskForm.switchToDisplayMode(newDisplayMode);
}
}

ngOnChanges(changes: SimpleChanges) {
const appName = changes['appName'];
if (appName && appName.currentValue !== appName.previousValue && this.taskId) {
this.loadTask();
return;
}

const taskId = changes['taskId'];
if (taskId?.currentValue && this.appName) {
this.loadTask();
return;
}
}

ngOnInit() {
if (this.appName === '' && this.taskId) {
this.loadTask();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { FormCloudModule } from '../../form/form-cloud.module';
import { TaskDirectiveModule } from '../directives/task-directive.module';
import { TaskFormCloudComponent } from './components/task-form-cloud/task-form-cloud.component';
import { CoreModule } from '@alfresco/adf-core';
import { ScreenCloudComponent } from '../../screen/components/screen-cloud/screen-cloud.component';
import { TaskScreenCloudComponent } from '../../screen/components/screen-cloud/screen-cloud.component';
import { UserTaskCloudComponent } from './components/user-task-cloud/user-task-cloud.component';
import { UserTaskCloudButtonsComponent } from './components/user-task-cloud-buttons/user-task-cloud-buttons.component';

@NgModule({
imports: [CoreModule, CommonModule, MaterialModule, FormCloudModule, TaskDirectiveModule, ScreenCloudComponent],
imports: [CoreModule, CommonModule, MaterialModule, FormCloudModule, TaskDirectiveModule, TaskScreenCloudComponent],
declarations: [TaskFormCloudComponent, UserTaskCloudComponent, UserTaskCloudButtonsComponent],
exports: [TaskFormCloudComponent, UserTaskCloudComponent]
})
Expand Down

0 comments on commit 2585e1e

Please sign in to comment.