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
@@ -22,11 +22,11 @@
</div> </div>
</div> </div>
<activiti-form *ngIf="hasFormKey()" [taskId]="taskDetails.id" <activiti-form *ngIf="hasFormKey()" [taskId]="taskDetails.id"
[showTitle]="showTitle" [showTitle]="showFormTitle"
[showRefreshButton]="showRefreshButton" [showRefreshButton]="showRefreshButton"
[showCompleteButton]="showCompleteButton" [showCompleteButton]="showFormCompleteButton"
[showSaveButton]="showSaveButton" [showSaveButton]="showFormSaveButton"
[readOnly]="readOnly" [readOnly]="readOnlyForm"
(formSaved)='formSavedEmitter($event)' (formSaved)='formSavedEmitter($event)'
(formCompleted)='formCompletedEmitter($event)' (formCompleted)='formCompletedEmitter($event)'
(formLoaded)='formLoadedEmitter($event)' (formLoaded)='formLoadedEmitter($event)'
@@ -25,6 +25,7 @@ import { ActivitiPeople } from './activiti-people.component';
import { TaskDetailsModel } from '../models/task-details.model'; import { TaskDetailsModel } from '../models/task-details.model';
import { User } from '../models/user.model'; import { User } from '../models/user.model';
import { ActivitiForm, FormModel, FormService } from 'ng2-activiti-form'; import { ActivitiForm, FormModel, FormService } from 'ng2-activiti-form';
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
declare let componentHandler: any; declare let componentHandler: any;
@@ -40,9 +41,6 @@ declare let __moduleName: string;
}) })
export class ActivitiTaskDetails implements OnInit, OnChanges { export class ActivitiTaskDetails implements OnInit, OnChanges {
@Input()
taskId: string;
@ViewChild('activiticomments') @ViewChild('activiticomments')
activiticomments: any; activiticomments: any;
@@ -50,19 +48,25 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
activitichecklist: any; activitichecklist: any;
@Input() @Input()
showTitle: boolean = true; taskId: string;
@Input() @Input()
showCompleteButton: boolean = true; showNextTask: boolean = true;
@Input() @Input()
showSaveButton: boolean = true; showFormTitle: boolean = true;
@Input() @Input()
readOnly: boolean = false; showFormCompleteButton: boolean = true;
@Input() @Input()
showRefreshButton: boolean = true; showFormSaveButton: boolean = true;
@Input()
readOnlyForm: boolean = false;
@Input()
showFormRefreshButton: boolean = true;
@Output() @Output()
formSaved = new EventEmitter(); formSaved = new EventEmitter();
@@ -127,10 +131,14 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.taskDetails = null; this.taskDetails = null;
} }
/**
* Check if the task has a form
* @returns {TaskDetailsModel|string|boolean}
*/
hasFormKey() { hasFormKey() {
return this.taskDetails return (this.taskDetails
&& this.taskDetails.formKey && this.taskDetails.formKey
&& this.taskDetails.formKey !== 'null'; && this.taskDetails.formKey !== 'null');
} }
/** /**
@@ -146,7 +154,7 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.taskDetails = res; this.taskDetails = res;
let endDate: any = res.endDate; let endDate: any = res.endDate;
this.readOnly = !!(endDate && !isNaN(endDate.getTime())); this.readOnlyForm = !!(endDate && !isNaN(endDate.getTime()));
if (this.taskDetails && this.taskDetails.involvedPeople) { if (this.taskDetails && this.taskDetails.involvedPeople) {
this.taskDetails.involvedPeople.forEach((user) => { 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 * Complete the activiti task
*/ */
@@ -194,6 +227,9 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
*/ */
formCompletedEmitter(data: any) { formCompletedEmitter(data: any) {
this.formCompleted.emit(data); 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); this.formLoaded.emit(data);
} }
/**
* Emit the error event of the form
* @param data
*/
onErrorEmitter(err: any) { onErrorEmitter(err: any) {
this.onError.emit(err); this.onError.emit(err);
} }
/**
* Emit the execute outcome of the form
* @param data
*/
executeOutcomeEmitter(data: any) { executeOutcomeEmitter(data: any) {
this.executeOutcome.emit(data); this.executeOutcome.emit(data);
} }
/**
* Return the showNexTask value
* @returns {boolean}
*/
isShowNextTask(): boolean {
return this.showNextTask;
}
} }