Reset form when cancel button clicked

- Remove use of any in component and add types
- Small refactoring of method name
- Add many more tests

Refs #1066
This commit is contained in:
Will Abson
2016-11-16 17:02:55 +00:00
committed by Mario Romano
parent dd13cb3707
commit b79319d1b5
4 changed files with 402 additions and 89 deletions

View File

@@ -18,6 +18,8 @@
import { Component, EventEmitter, Input, Output, OnInit, ViewChild, DebugElement, OnChanges, SimpleChanges } from '@angular/core';
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { ActivitiStartForm } from 'ng2-activiti-form';
import { ProcessInstance } from './../models/process-instance.model';
import { ProcessDefinitionRepresentation } from './../models/process-definition.model';
import { ActivitiProcessService } from './../services/activiti-process.service';
declare let componentHandler: any;
@@ -35,7 +37,7 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
appId: string;
@Output()
start: EventEmitter<any> = new EventEmitter<any>();
start: EventEmitter<ProcessInstance> = new EventEmitter<ProcessInstance>();
@ViewChild('dialog')
dialog: DebugElement;
@@ -43,11 +45,11 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
@ViewChild('startForm')
startForm: ActivitiStartForm;
processDefinitions: any[] = [];
processDefinitions: ProcessDefinitionRepresentation[] = [];
name: string;
currentProcessDef: any;
currentProcessDef: ProcessDefinitionRepresentation = new ProcessDefinitionRepresentation();
constructor(private translate: AlfrescoTranslationService,
private activitiProcess: ActivitiProcessService) {
@@ -70,9 +72,9 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
}
public load(appId: string) {
this.reset();
this.activitiProcess.getProcessDefinitions(this.appId).subscribe(
(res: any[]) => {
this.resetSelectedProcessDefinition();
this.activitiProcess.getProcessDefinitions(appId).subscribe(
(res) => {
this.processDefinitions = res;
},
(err) => {
@@ -92,7 +94,7 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
if (this.currentProcessDef.id && this.name) {
let formValues = this.startForm ? this.startForm.form.values : undefined;
this.activitiProcess.startProcess(this.currentProcessDef.id, this.name, formValues).subscribe(
(res: any) => {
(res) => {
this.name = '';
this.start.emit(res);
this.cancel();
@@ -105,10 +107,11 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
}
public cancel() {
this.reset();
this.dialog.nativeElement.close();
}
onChange(processDefinitionId) {
onProcessDefChange(processDefinitionId) {
let processDef = this.processDefinitions.find((processDefinition) => {
return processDefinition.id === processDefinitionId;
});
@@ -128,7 +131,15 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
return this.currentProcessDef.id && this.name && this.isStartFormMissingOrValid();
}
reset() {
this.currentProcessDef = {};
private resetSelectedProcessDefinition() {
this.currentProcessDef = new ProcessDefinitionRepresentation();
}
private reset() {
this.resetSelectedProcessDefinition();
this.name = '';
if (this.startForm) {
this.startForm.data = {};
}
}
}