From 54380fd693352b30bb0eaa6f18f570ee38d0b3c3 Mon Sep 17 00:00:00 2001 From: bbcodrin Date: Wed, 18 Jul 2018 12:14:54 +0300 Subject: [PATCH] [ADF-3237] Change and remove form from a task (#3597) * button added for task standalone * rebase fixed * review fix * test added & fixes * refresh task details * change and remove form added * localize & documentation work * tests added * tests fixes * tests fixes --- .../task-standalone.component.md | 1 + lib/process-services/i18n/en.json | 4 +- .../components/attach-form.component.html | 18 ++++-- .../components/attach-form.component.scss | 2 +- .../components/attach-form.component.spec.ts | 50 ++++++++++++++- .../components/attach-form.component.ts | 64 +++++++++++++------ .../components/task-details.component.html | 16 +++-- .../components/task-details.component.ts | 26 +++++--- .../components/task-header.component.spec.ts | 2 +- .../components/task-header.component.ts | 4 +- .../components/task-standalone.component.html | 8 +-- .../components/task-standalone.component.ts | 16 +---- .../task-list/services/tasklist.service.ts | 14 ++++ 13 files changed, 160 insertions(+), 65 deletions(-) diff --git a/docs/process-services/task-standalone.component.md b/docs/process-services/task-standalone.component.md index 5162e2c9f9..93b0223f7a 100644 --- a/docs/process-services/task-standalone.component.md +++ b/docs/process-services/task-standalone.component.md @@ -33,3 +33,4 @@ This component can be used when there is no form attached to a task. | -- | -- | -- | | cancel | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the "Cancel" button is clicked. | | complete | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the form associated with the task is completed. | +| showAttachForm | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the "Show Form" button is clicked. | diff --git a/lib/process-services/i18n/en.json b/lib/process-services/i18n/en.json index 66758a4497..d591da6110 100644 --- a/lib/process-services/i18n/en.json +++ b/lib/process-services/i18n/en.json @@ -154,7 +154,9 @@ "COMPLETE_TASK_SUB_MESSAGE": "No forms to be added" }, "ATTACH_FORM":{ - "SELECT_FORM": "Select Form To Attach" + "SELECT_FORM": "Select Form To Attach", + "REMOVE_FORM": "Remove Form", + "SELECT_OPTION": "Please select option" } }, "ADF_PROCESS_LIST": { diff --git a/lib/process-services/task-list/components/attach-form.component.html b/lib/process-services/task-list/components/attach-form.component.html index 356f11c23a..4c3dde0d17 100644 --- a/lib/process-services/task-list/components/attach-form.component.html +++ b/lib/process-services/task-list/components/attach-form.component.html @@ -7,24 +7,30 @@
- + {{ form.name }}
+ [showCompleteButton]="false" + [showRefreshButton]="false" + [showValidationIcon]="false"> - - +
+ +
+
+ + +
diff --git a/lib/process-services/task-list/components/attach-form.component.scss b/lib/process-services/task-list/components/attach-form.component.scss index 972a4d9da0..00cc380d2c 100644 --- a/lib/process-services/task-list/components/attach-form.component.scss +++ b/lib/process-services/task-list/components/attach-form.component.scss @@ -10,7 +10,7 @@ } .adf-no-form-mat-card-actions { - justify-content: flex-end; + justify-content: space-between; margin-top: 30px; text-align: right; } diff --git a/lib/process-services/task-list/components/attach-form.component.spec.ts b/lib/process-services/task-list/components/attach-form.component.spec.ts index a23aa16595..a9be4e5115 100644 --- a/lib/process-services/task-list/components/attach-form.component.spec.ts +++ b/lib/process-services/task-list/components/attach-form.component.spec.ts @@ -54,7 +54,7 @@ describe('AttachFormComponent', () => { it('should call attachFormToATask if clicked on Complete Button', async(() => { component.taskId = 1; - component.formKey = 2; + component.formId = 2; spyOn(taskService, 'attachFormToATask').and.returnValue(Observable.of(true)); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -75,4 +75,52 @@ describe('AttachFormComponent', () => { expect(formContainer).not.toBeNull(); }); })); + + it('should show the formPreview of the selected form', async(() => { + component.formKey = 12; + fixture.detectChanges(); + const formContainer = fixture.debugElement.nativeElement.querySelector('.adf-form-container'); + fixture.whenStable().then(() => { + expect(formContainer).toBeDefined(); + expect(formContainer).toBeNull(); + }); + })); + + it('should remove form if it is present', (done) => { + component.taskId = 1; + component.formId = 10; + component.formKey = 12; + spyOn(taskService, 'deleteForm').and.returnValue(Observable.of({})); + + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(element.querySelector('#adf-no-form-remove-button')).toBeDefined(); + const el = fixture.nativeElement.querySelector('#adf-no-form-remove-button'); + el.click(); + expect(component.formId).toBeNull(); + done(); + }); + }); + + it('should emit success when form is changed', async(() => { + component.taskId = 1; + component.formId = 10; + + spyOn(taskService, 'attachFormToATask').and.returnValue(Observable.of( + { + id: 91, + name: 'fakeName', + formKey: 1204, + assignee: null + } + )); + + fixture.detectChanges(); + fixture.whenStable().then(() => { + const emitSpy = spyOn(component.success, 'emit'); + const el = fixture.nativeElement.querySelector('#adf-no-form-attach-form-button'); + el.click(); + expect(emitSpy).toHaveBeenCalled(); + }); + })); }); diff --git a/lib/process-services/task-list/components/attach-form.component.ts b/lib/process-services/task-list/components/attach-form.component.ts index dce017980c..3bee1e9165 100644 --- a/lib/process-services/task-list/components/attach-form.component.ts +++ b/lib/process-services/task-list/components/attach-form.component.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { LogService } from '@alfresco/adf-core'; -import { Component, EventEmitter, Input, OnInit, OnChanges, Output } from '@angular/core'; +import { FormService, LogService } from '@alfresco/adf-core'; +import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; import { Form } from '../models/form.model'; import { TaskListService } from './../services/tasklist.service'; @@ -26,44 +26,53 @@ import { TaskListService } from './../services/tasklist.service'; styleUrls: ['./attach-form.component.scss'] }) -export class AttachFormComponent implements OnInit, OnChanges { +export class AttachFormComponent implements OnChanges { constructor(private taskService: TaskListService, - private logService: LogService) { } + private logService: LogService, + private formService: FormService) { } - /** The id of the task whose details we are asking for. */ @Input() taskId; - /** Emitted when the "Cancel" button is clicked. */ + @Input() + formKey; + @Output() cancelAttachForm: EventEmitter = new EventEmitter(); - /** Emitted when the form associated with the form task is attached. */ @Output() - completeAttachForm: EventEmitter = new EventEmitter(); + success: EventEmitter = new EventEmitter(); - /** Emitted when an error occurs. */ @Output() error: EventEmitter = new EventEmitter(); forms: Form[]; - formKey: number; - - ngOnInit() { - this.loadFormsTask(); - } + formId: number; ngOnChanges() { this.loadFormsTask(); + this.onFormAttached(); } onCancelButtonClick(): void { this.cancelAttachForm.emit(); } + onRemoveButtonClick(): void { + this.taskService.deleteForm(this.taskId).subscribe( + () => { + this.formId = null; + this.success.emit(); + }, + (err) => { + this.error.emit(err); + this.logService.error('An error occurred while trying to delete the form'); + }); + } + onAttachFormButtonClick(): void { - this.attachForm(this.taskId, this.formKey); + this.attachForm(this.taskId, this.formId); } private loadFormsTask(): void { @@ -76,11 +85,26 @@ export class AttachFormComponent implements OnInit, OnChanges { }); } - private attachForm(taskId: string, formKey: number) { - if (taskId && formKey) { - this.taskService.attachFormToATask(taskId, formKey) - .subscribe((res) => { - this.completeAttachForm.emit(); + private onFormAttached() { + this.formService.getTaskForm(this.taskId) + .subscribe((res) => { + this.formService.getFormDefinitionByName(res.name).subscribe((formDef) => { + this.formId = formDef; + }); + }, (err) => { + this.error.emit(err); + this.logService.error('Could not load forms'); + }); + } + + private attachForm(taskId: string, formId: number) { + if (taskId && formId) { + this.taskService.attachFormToATask(taskId, formId) + .subscribe(() => { + this.success.emit(); + }, (err) => { + this.error.emit(err); + this.logService.error('Could not attach form'); }); } } diff --git a/lib/process-services/task-list/components/task-details.component.html b/lib/process-services/task-list/components/task-details.component.html index d1e951a732..48698bd5f1 100644 --- a/lib/process-services/task-list/components/task-details.component.html +++ b/lib/process-services/task-list/components/task-details.component.html @@ -22,7 +22,7 @@
- - + (showAttachForm)="onShowAttachForm()"> + +
{{ 'ADF_TASK_LIST.DETAILS.MESSAGES.CLAIM' | translate }} diff --git a/lib/process-services/task-list/components/task-details.component.ts b/lib/process-services/task-list/components/task-details.component.ts index a9e019eb59..61e01148a0 100644 --- a/lib/process-services/task-list/components/task-details.component.ts +++ b/lib/process-services/task-list/components/task-details.component.ts @@ -21,7 +21,6 @@ import { CardViewUpdateService, ClickNotification, LogService, - FormService, UpdateNotification, FormRenderingService, CommentsComponent @@ -97,7 +96,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges { /** Toggles rendering of the form title. */ @Input() - showFormTitle: boolean = true; + showFormTitle: boolean = false; /** Toggles rendering of the `Complete` outcome button. */ @Input() @@ -175,6 +174,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges { noTaskDetailsTemplateComponent: TemplateRef; showAssignee: boolean = false; + showAttachForm: boolean = false; private peopleSearchObserver: Observer; public errorDialogRef: MatDialogRef>; @@ -187,7 +187,6 @@ export class TaskDetailsComponent implements OnInit, OnChanges { private authService: AuthenticationService, private peopleProcessService: PeopleProcessService, private formRenderingService: FormRenderingService, - private formService: FormService, private logService: LogService, private cardViewUpdateService: CardViewUpdateService, private dialog: MatDialog) { @@ -259,6 +258,9 @@ export class TaskDetailsComponent implements OnInit, OnChanges { if (clickNotification.target.key === 'assignee') { this.showAssignee = true; } + if (clickNotification.target.key === 'formName') { + this.showAttachForm = true; + } } /** @@ -290,7 +292,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges { } isAssigned(): boolean { - return this.taskDetails.assignee ? true : false; + return !!this.taskDetails.assignee; } private hasEmailAddress(): boolean { @@ -364,11 +366,17 @@ export class TaskDetailsComponent implements OnInit, OnChanges { ); } - onFormAttached() { - this.formService.getTaskForm(this.taskId) - .subscribe((res) => { - this.loadDetails(this.taskId); - }, error => this.logService.error('Could not load forms')); + onShowAttachForm() { + this.showAttachForm = true; + } + + onCancelAttachForm() { + this.showAttachForm = false; + } + + onCompleteAttachForm() { + this.showAttachForm = false; + this.loadDetails(this.taskId); } onFormContentClick(content: ContentLinkModel): void { diff --git a/lib/process-services/task-list/components/task-header.component.spec.ts b/lib/process-services/task-list/components/task-header.component.spec.ts index 828bf77f39..e9769054d1 100644 --- a/lib/process-services/task-list/components/task-header.component.spec.ts +++ b/lib/process-services/task-list/components/task-header.component.spec.ts @@ -301,7 +301,7 @@ describe('TaskHeaderComponent', () => { fixture.detectChanges(); fixture.whenStable().then(() => { - let valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-property-value')); + let valueEl = fixture.debugElement.query(By.css('[data-automation-id="header-formName"] .adf-textitem-clickable-value')); expect(valueEl.nativeElement.innerText).toBe('test form'); }); })); diff --git a/lib/process-services/task-list/components/task-header.component.ts b/lib/process-services/task-list/components/task-header.component.ts index 5b467c4637..6af99df6ec 100644 --- a/lib/process-services/task-list/components/task-header.component.ts +++ b/lib/process-services/task-list/components/task-header.component.ts @@ -153,7 +153,9 @@ export class TaskHeaderComponent implements OnChanges, OnInit { label: 'ADF_TASK_LIST.PROPERTIES.FORM_NAME', value: this.formName, key: 'formName', - default: this.translationService.instant('ADF_TASK_LIST.PROPERTIES.FORM_NAME_DEFAULT') + default: this.translationService.instant('ADF_TASK_LIST.PROPERTIES.FORM_NAME_DEFAULT'), + clickable: !!this.formName, + icon: 'create' } ) ]; diff --git a/lib/process-services/task-list/components/task-standalone.component.html b/lib/process-services/task-list/components/task-standalone.component.html index d77a91d09a..6d17c2a31f 100644 --- a/lib/process-services/task-list/components/task-standalone.component.html +++ b/lib/process-services/task-list/components/task-standalone.component.html @@ -1,4 +1,4 @@ - +
@@ -25,9 +25,3 @@
- - - diff --git a/lib/process-services/task-list/components/task-standalone.component.ts b/lib/process-services/task-list/components/task-standalone.component.ts index 680cda8c1b..e82f185b4a 100644 --- a/lib/process-services/task-list/components/task-standalone.component.ts +++ b/lib/process-services/task-list/components/task-standalone.component.ts @@ -54,10 +54,9 @@ export class TaskStandaloneComponent { @Output() complete: EventEmitter = new EventEmitter(); + /** Emitted when the form associated with the form task is attached. */ @Output() - formAttached: EventEmitter = new EventEmitter(); - - showAttachForm: boolean = false; + showAttachForm: EventEmitter = new EventEmitter(); constructor() { } @@ -82,15 +81,6 @@ export class TaskStandaloneComponent { } onShowAttachForm() { - this.showAttachForm = true; - } - - onCancelAttachForm() { - this.showAttachForm = false; - } - - onCompleteAttachForm() { - this.showAttachForm = false; - this.formAttached.emit(); + this.showAttachForm.emit(); } } diff --git a/lib/process-services/task-list/services/tasklist.service.ts b/lib/process-services/task-list/services/tasklist.service.ts index 742772b582..7b86c6f5fc 100644 --- a/lib/process-services/task-list/services/tasklist.service.ts +++ b/lib/process-services/task-list/services/tasklist.service.ts @@ -219,6 +219,16 @@ export class TaskListService { .catch(err => this.handleError(err)); } + /** + * Deletes a form from a task. + * @param taskId Task id related to form + * @returns Null response notifying when the operation is complete + */ + deleteForm(taskId: string): Observable { + return Observable.fromPromise(this.callApiDeleteForm(taskId)) + .catch(err => this.handleError(err)); + } + /** * Gives completed status to a task. * @param taskId ID of the target task @@ -353,6 +363,10 @@ export class TaskListService { return this.apiService.taskApi.deleteTask(taskId); } + private callApiDeleteForm(taskId: string) { + return this.apiService.taskApi.removeForm(taskId); + } + private callApiTaskChecklist(taskId: string) { return this.apiService.taskApi.getChecklist(taskId); }