Add property showNextTask and refactoring

This commit is contained in:
mauriziovitale84
2016-09-22 14:45:03 +01:00
parent d73a95b4fd
commit eb3a812525
2 changed files with 67 additions and 15 deletions

View File

@@ -22,11 +22,11 @@
</div>
</div>
<activiti-form *ngIf="hasFormKey()" [taskId]="taskDetails.id"
[showTitle]="showTitle"
[showTitle]="showFormTitle"
[showRefreshButton]="showRefreshButton"
[showCompleteButton]="showCompleteButton"
[showSaveButton]="showSaveButton"
[readOnly]="readOnly"
[showCompleteButton]="showFormCompleteButton"
[showSaveButton]="showFormSaveButton"
[readOnly]="readOnlyForm"
(formSaved)='formSavedEmitter($event)'
(formCompleted)='formCompletedEmitter($event)'
(formLoaded)='formLoadedEmitter($event)'

View File

@@ -25,6 +25,7 @@ import { ActivitiPeople } from './activiti-people.component';
import { TaskDetailsModel } from '../models/task-details.model';
import { User } from '../models/user.model';
import { ActivitiForm, FormModel, FormService } from 'ng2-activiti-form';
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
declare let componentHandler: any;
@@ -40,9 +41,6 @@ declare let __moduleName: string;
})
export class ActivitiTaskDetails implements OnInit, OnChanges {
@Input()
taskId: string;
@ViewChild('activiticomments')
activiticomments: any;
@@ -50,19 +48,25 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
activitichecklist: any;
@Input()
showTitle: boolean = true;
taskId: string;
@Input()
showCompleteButton: boolean = true;
showNextTask: boolean = true;
@Input()
showSaveButton: boolean = true;
showFormTitle: boolean = true;
@Input()
readOnly: boolean = false;
showFormCompleteButton: boolean = true;
@Input()
showRefreshButton: boolean = true;
showFormSaveButton: boolean = true;
@Input()
readOnlyForm: boolean = false;
@Input()
showFormRefreshButton: boolean = true;
@Output()
formSaved = new EventEmitter();
@@ -127,10 +131,14 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.taskDetails = null;
}
/**
* Check if the task has a form
* @returns {TaskDetailsModel|string|boolean}
*/
hasFormKey() {
return this.taskDetails
return (this.taskDetails
&& this.taskDetails.formKey
&& this.taskDetails.formKey !== 'null';
&& this.taskDetails.formKey !== 'null');
}
/**
@@ -146,7 +154,7 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.taskDetails = res;
let endDate: any = res.endDate;
this.readOnly = !!(endDate && !isNaN(endDate.getTime()));
this.readOnlyForm = !!(endDate && !isNaN(endDate.getTime()));
if (this.taskDetails && this.taskDetails.involvedPeople) {
this.taskDetails.involvedPeople.forEach((user) => {
@@ -169,6 +177,31 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
}
}
/**
* Retrieve the next open task
* @param processInstanceId
* @param processDefinitionId
*/
loadNextTask(processInstanceId: string, processDefinitionId: string) {
let requestNode = new TaskQueryRequestRepresentationModel(
{
processInstanceId: processInstanceId,
processDefinitionId: processDefinitionId
}
);
this.activitiTaskList.getTasks(requestNode).subscribe(
(response) => {
if (response.data && response.data.length > 0) {
this.taskDetails = response.data[0];
} else {
this.reset();
}
}, (error) => {
console.error(error);
this.onError.emit(error);
});
}
/**
* Complete the activiti task
*/
@@ -194,6 +227,9 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
*/
formCompletedEmitter(data: any) {
this.formCompleted.emit(data);
if (this.isShowNextTask()) {
this.loadNextTask(this.taskDetails.processInstanceId, this.taskDetails.processDefinitionId);
}
}
/**
@@ -204,11 +240,27 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.formLoaded.emit(data);
}
/**
* Emit the error event of the form
* @param data
*/
onErrorEmitter(err: any) {
this.onError.emit(err);
}
/**
* Emit the execute outcome of the form
* @param data
*/
executeOutcomeEmitter(data: any) {
this.executeOutcome.emit(data);
}
/**
* Return the showNexTask value
* @returns {boolean}
*/
isShowNextTask(): boolean {
return this.showNextTask;
}
}