import { Component, OnInit, ElementRef, Input, Output, EventEmitter } from '@angular/core'; import { CfCoreBusinessComponent } from '../core-business/core-business.component'; import { BpmTaskModel } from '../../models/bpm-task.model'; import { BpmTaskListModel } from '../../models/bpm-task-list.model'; import { IconModel } from '../../models/icon/icon.model'; import { ButtonModel } from '../../models/button/button.model'; import { InputModel } from '../../models/input/input.model'; import { ListModel } from '../../models/list/list.model'; import { MapModelsService } from '../../services/map-models.service'; import { BpmTasksService } from '../../services/bpm-tasks.service'; @Component({ selector: 'cf-bpm-list', template: "
{{it.subject}}
Work Item ID: {{it.workItemId}}
Task Due Date:{{it.dueDate | date: 'dd/MM/yyyy'}}
Instance Name: {{task.instanceName}}
Team: {{task.team.who}}
Task Status: {{task.taskStatus}}
Instance Due Date: {{task.instanceDueDate | date: 'dd/MM/yyyy'}}
The model that is bound to the template
*/ cfBpmList: BpmTaskListModel; /** *It represents the list of settings for the component
*/ @Input() settings: BpmTaskListModel; /** *It contains the lis tof tasks returned from the service.
*/ tasks: any = []; /** *The input settings for the input component.
*/ urlInput= new InputModel ({ type : "text", placeholder: " API URL", prefix : "", width: "90%", maxlength : "", dividerColor : "green", value : "", suffix : "", hint : { text : "", align : "end" }, icon: { name: "fa-link", type: "fa", size: "20px", color: { foreground: "blue", background: "transparent" } }, iconPosition:"left", menu: null }); /** *The input settings for the input component.
*/ usernameInput = new InputModel ({ type : "text", placeholder: " Username", prefix : "", maxlength : "", dividerColor : "green", value : "", suffix : "", hint : { text : "", align : "end" }, icon: { name: "fa-user", type: "fa", size: "20px", color: { foreground: "green", background: "transparent" } }, iconPosition:"left", menu: null }); /** *The input settings for the input component.
*/ passwordInput= new InputModel ({ type : "password", placeholder: " Password", prefix : "", maxlength : "", dividerColor : "blue", value : "", suffix : "", hint : { text : "", align : "end" }, icon: { name: "fa-key", type: "fa", size: "20px", color: { foreground: "green", background: "transparent" } }, iconPosition:"left", menu: null }); myList = new ListModel ({ title: '', //items: [] }); checkTooltip = { message: "Accept", position: "left" }; /** *The icon settings for the check button.
*/ checkIcon = new IconModel ({ name: "fa-check-circle-o", size: "15px", }); rejectTooltip = { message: "Reject", position: "left" }; /** *The icon settings for the reject button.
*/ rejectIcon = new IconModel ({ name: "fa-ban", size: "15px" }); constructor(public elementRef: ElementRef, private mappingService: MapModelsService, private bpmService: BpmTasksService) { super(elementRef); } ngOnInit() { super.ngOnInit(); this.cfBpmList = this.settings; this.mappings = [ { source:"assignedToUser", target:"assignedTo" }, { source:"bpdName", target:"title" }, { source:"taskSubject", target:"subject" }, { source:"taskStatus", target:"taskStatus" }, { source:"taskDueDate", target:"dueDate" }, { source:"taskPriority", target:"priority" }, { source:"instanceId", target: "workItemId"}, { source:"instanceName", target: "instanceName"}, { source:"taskId", target: "taskId"}, { source:"taskAssignedTo", target: "team"}, { source:"instanceDueDate", target: "instanceDueDate"} ]; this.urlInput.value = this.cfBpmList.bpmUrl; this.usernameInput.value = this.cfBpmList.username; this.passwordInput.value = this.cfBpmList.password; this.initializeTasks(); } initializeTasks(){ this.clearAll(); this.bpmService.getTasks(this.cfBpmList).subscribe(tsks => this.mapToTaskModel(tsks)); } clearAll(){ this.tasks = []; } mapToTaskModel(taskList: Object[]) { if(taskList!=null) { for(let data of taskList) { let newTask = new BpmTaskModel(this.mappingService.map(data, this.mappings)); newTask.subject= newTask.subject.substring(5); newTask.instanceName = newTask.instanceName.split(":")[0]; newTask.team.who = newTask.team.who.split("_")[0]; // switch(newTask.priority.toLowerCase()){ // case "highest": newTask.priorityIcon.color.foreground = "#F44336"; break; // case "high": newTask.priorityIcon.color.foreground = "#FFD54F"; break; // default: newTask.priorityIcon.color.foreground = "#E0E0E0"; break; // } this.tasks.push(newTask); } if(this.tasks.length>0) { this.myList.title = this.tasks[0].title; } //this.myList.items=this.tasks; } } getInfo(task: BpmTaskModel) { alert(task.title); } refresh() { this.cfBpmList.bpmUrl = this.urlInput.value; this.cfBpmList.username = this.usernameInput.value; this.cfBpmList.password = this.passwordInput.value; this.initializeTasks(); } acceptTask(task: Object){ this.bpmService.acceptTask(this.cfBpmList,task["taskId"]).subscribe(); this.initializeTasks(); } rejectTask(task: Object){ this.bpmService.acceptTask(this.cfBpmList,task["taskId"]).subscribe(); //this.bpmService.rejectTask(this.cfBpmList,task["taskId"]).subscribe(); this.initializeTasks(); } }