create new TaskDetailsModel in loadNextTask (#2017)

This commit is contained in:
Eugenio Romano
2017-06-29 15:09:27 +01:00
committed by Eugenio Romano
parent f6116bf937
commit 82cad3415b
3 changed files with 28 additions and 25 deletions
@@ -15,8 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { Component,
Component,
Input, Input,
OnInit, OnInit,
ViewChild, ViewChild,
@@ -152,15 +151,13 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
} }
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges): void {
let taskId = changes['taskId']; let taskId = changes.taskId;
if (taskId && !taskId.currentValue) { if (taskId && !taskId.currentValue) {
this.reset(); this.reset();
return; } else if (taskId && taskId.currentValue) {
}
if (taskId && taskId.currentValue) {
this.loadDetails(taskId.currentValue); this.loadDetails(taskId.currentValue);
return;
} }
} }
@@ -221,7 +218,7 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
* @param processInstanceId * @param processInstanceId
* @param processDefinitionId * @param processDefinitionId
*/ */
private loadNextTask(processInstanceId: string, processDefinitionId: string) { private loadNextTask(processInstanceId: string, processDefinitionId: string): void {
let requestNode = new TaskQueryRequestRepresentationModel( let requestNode = new TaskQueryRequestRepresentationModel(
{ {
processInstanceId: processInstanceId, processInstanceId: processInstanceId,
@@ -231,7 +228,7 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.activitiTaskList.getTasks(requestNode).subscribe( this.activitiTaskList.getTasks(requestNode).subscribe(
(response) => { (response) => {
if (response && response.length > 0) { if (response && response.length > 0) {
this.taskDetails = <TaskDetailsModel>response[0]; this.taskDetails = new TaskDetailsModel(response[0]);
} else { } else {
this.reset(); this.reset();
} }
@@ -243,28 +240,28 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
/** /**
* Complete button clicked * Complete button clicked
*/ */
onComplete() { onComplete(): void {
this.activitiTaskList.completeTask(this.taskId).subscribe( this.activitiTaskList.completeTask(this.taskId).subscribe(
(res) => this.onFormCompleted(null) (res) => this.onFormCompleted(null)
); );
} }
onFormContentClick(content: ContentLinkModel) { onFormContentClick(content: ContentLinkModel): void {
this.formContentClicked.emit(content); this.formContentClicked.emit(content);
} }
onFormSaved(form: FormModel) { onFormSaved(form: FormModel): void {
this.formSaved.emit(form); this.formSaved.emit(form);
} }
onFormCompleted(form: FormModel) { onFormCompleted(form: FormModel): void {
this.formCompleted.emit(form); this.formCompleted.emit(form);
if (this.showNextTask) { if (this.showNextTask) {
this.loadNextTask(this.taskDetails.processInstanceId, this.taskDetails.processDefinitionId); this.loadNextTask(this.taskDetails.processInstanceId, this.taskDetails.processDefinitionId);
} }
} }
onFormLoaded(form: FormModel) { onFormLoaded(form: FormModel): void {
this.taskFormName = null; this.taskFormName = null;
if (form && form.name) { if (form && form.name) {
this.taskFormName = form.name; this.taskFormName = form.name;
@@ -272,20 +269,20 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.formLoaded.emit(form); this.formLoaded.emit(form);
} }
onChecklistTaskCreated(task: TaskDetailsModel) { onChecklistTaskCreated(task: TaskDetailsModel): void {
this.taskCreated.emit(task); this.taskCreated.emit(task);
} }
onChecklistTaskDeleted(taskId: string) { onChecklistTaskDeleted(taskId: string): void {
this.taskDeleted.emit(taskId); this.taskDeleted.emit(taskId);
} }
onFormError(error: any) { onFormError(error: any): void {
this.errorDialog.nativeElement.showModal(); this.errorDialog.nativeElement.showModal();
this.onError.emit(error); this.onError.emit(error);
} }
onFormExecuteOutcome(event: FormOutcomeEvent) { onFormExecuteOutcome(event: FormOutcomeEvent): void {
this.executeOutcome.emit(event); this.executeOutcome.emit(event);
} }
@@ -293,24 +290,24 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
this.errorDialog.nativeElement.close(); this.errorDialog.nativeElement.close();
} }
public showPeopleDialog() { public showPeopleDialog(): void {
if (!this.peopleDialog.nativeElement.showModal) { if (!this.peopleDialog.nativeElement.showModal) {
dialogPolyfill.registerDialog(this.peopleDialog.nativeElement); dialogPolyfill.registerDialog(this.peopleDialog.nativeElement);
} }
this.peopleDialog.nativeElement.showModal(); this.peopleDialog.nativeElement.showModal();
} }
public closePeopleDialog() { public closePeopleDialog(): void {
if (this.peopleDialog) { if (this.peopleDialog) {
this.peopleDialog.nativeElement.close(); this.peopleDialog.nativeElement.close();
} }
} }
onClaimTask(taskId: string) { onClaimTask(taskId: string): void {
this.loadDetails(taskId); this.loadDetails(taskId);
} }
toggleHeaderContent() { toggleHeaderContent(): void {
this.showHeaderContent = !this.showHeaderContent; this.showHeaderContent = !this.showHeaderContent;
} }
@@ -52,6 +52,7 @@ export class ActivitiTaskHeader implements OnChanges {
refreshData() { refreshData() {
if (this.taskDetails) { if (this.taskDetails) {
this.properties = [ this.properties = [
new CardViewModel({label: 'Status:', value: this.getTaskStatus(), key: 'status'}), new CardViewModel({label: 'Status:', value: this.getTaskStatus(), key: 'status'}),
new CardViewModel({label: 'Due Date:', value: this.taskDetails.dueDate, format: 'MMM DD YYYY', key: 'dueDate', default: 'No date'}), new CardViewModel({label: 'Due Date:', value: this.taskDetails.dueDate, format: 'MMM DD YYYY', key: 'dueDate', default: 'No date'}),
@@ -92,9 +92,14 @@ export class TaskDetailsModel {
} }
getFullName(): string { getFullName(): string {
let fullName: string = '';
if (this.assignee) { if (this.assignee) {
return this.assignee.firstName + ' ' + this.assignee.lastName; let firstName: string = this.assignee.firstName ? this.assignee.firstName : '';
let lastName: string = this.assignee.lastName ? this.assignee.lastName : '';
fullName = `${firstName} ${lastName}`;
} }
return '';
return fullName.trim();
} }
} }