diff --git a/gulliver/js/pmchart/pmCharts.js b/gulliver/js/pmchart/pmCharts.js index 6fcba252a..434174dfc 100644 --- a/gulliver/js/pmchart/pmCharts.js +++ b/gulliver/js/pmchart/pmCharts.js @@ -109,6 +109,7 @@ BarChart.prototype.drawBars = function(data, canvas, param) { var currObj = this; if (data == null || data.length == 0) { + console.log(graphDim); canvas.append("text") .attr('class','pm-charts-no-draw') .attr("y", graphDim.height/2) @@ -1385,6 +1386,7 @@ PieChart.prototype.drawPie2D = function (dataset, canvas, param) { .enter() .append("text") .attr("x", width + 30) + .attr("class", "legend") .text(function (d, i) { return (d.datalabel + "-" + getPercent(d.value)) }) diff --git a/workflow/engine/classes/class.indicatorsCalculator.php b/workflow/engine/classes/class.indicatorsCalculator.php index c4fa95bd1..321e1857e 100644 --- a/workflow/engine/classes/class.indicatorsCalculator.php +++ b/workflow/engine/classes/class.indicatorsCalculator.php @@ -337,6 +337,36 @@ class indicatorsCalculator return $retval; } + public function ueiCostHistoric($employeeId, $initDate, $endDate, $periodicity) + { + if (!is_a($initDate, 'DateTime')) throw new InvalidArgumentException ('initDate parameter must be a DateTime object.', 0); + if (!is_a($endDate, 'DateTime')) throw new InvalidArgumentException ('endDate parameter must be a DateTime object.', 0); + + $periodicitySelectFields = $this->periodicityFieldsForSelect($periodicity); + $periodicityGroup = $this->periodicityFieldsForGrouping($periodicity); + $initYear = $initDate->format("Y"); + $initMonth = $initDate->format("m"); + $initDay = $endDay = 1; + $endYear = $endDate->format("Y"); + $endMonth = $endDate->format("m"); + + //$params[":initYear"] = $initYear; + //$params[":initMonth"] = $initMonth; + $params[":endYear"] = $endYear; + $params[":endMonth"] = $endMonth; + + + $sqlString = "SELECT $periodicitySelectFields " . $this->ueiCostFormula . " as EEC + FROM USR_REPORTING + WHERE + IF(`YEAR` = :endYear, `MONTH`, `YEAR`) <= IF (`YEAR` = :endYear, :endMonth, :endYear)" + . $periodicityGroup; + + $retval = $this->pdoExecutor($sqlString, $params); + //$retval = $this->propelExecutor($sqlString); + return $retval; + } + public function generalIndicatorData($indicatorId, $initDate, $endDate, $periodicity) { if (!is_a($initDate, 'DateTime')) throw new InvalidArgumentException ('initDate parameter must be a DateTime object.', 0); if (!is_a($endDate, 'DateTime')) throw new InvalidArgumentException ('endDate parameter must be a DateTime object.', 0); @@ -443,14 +473,16 @@ class indicatorsCalculator $sqlString = " select i.TAS_UID as uid, t.CON_VALUE as name, - i.efficienceIndex, + i.efficiencyIndex, + i.inefficiencyCost, i.averageTime, i.deviationTime, i.configuredTime FROM ( select TAS_UID, - $this->peiFormula as efficienceIndex, + $this->peiFormula as efficiencyIndex, + $this->peiCostFormula as inefficiencyCost, AVG(AVG_TIME) as averageTime, AVG(SDV_TIME) as deviationTime, CONFIGURED_TASK_TIME as configuredTime @@ -468,6 +500,95 @@ class indicatorsCalculator return $retval; } + public function statusIndicatorGeneral ($usrUid) + { + $params[':usrUid'] = $usrUid; + + $sqlString = "SELECT + COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) < 0 ) , 0 ) AS OVERDUE, + COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) > 0 ) , 0 ) AS ONTIME, + COALESCE( SUM( DATEDIFF( DEL_RISK_DATE , NOW( ) ) < 0 ) , 0 ) AS ATRISK + FROM LIST_INBOX + WHERE USR_UID = :usrUid + AND APP_STATUS = 'TO_DO' + AND DEL_DUE_DATE IS NOT NULL "; + + return $this->pdoExecutor($sqlString, $params); + } + + public function statusIndicatorDetail ($usrUid) + { + $params[':usrUid'] = $usrUid; + + $sqlString = "SELECT + TAS_UID as tasUid, + PRO_UID as proUid, + APP_TAS_TITLE AS taskTitle, + APP_PRO_TITLE AS proTitle, + + COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) < 0 ) , 0 ) AS overdue, + COALESCE( SUM( DATEDIFF( DEL_DUE_DATE , NOW( ) ) > 0 ) , 0 ) AS onTime, + COALESCE( SUM( DATEDIFF( DEL_RISK_DATE , NOW( ) ) < 0 ) , 0 ) AS atRisk + FROM LIST_INBOX + WHERE USR_UID = :usrUid + AND APP_STATUS = 'TO_DO' + AND DEL_DUE_DATE IS NOT NULL + GROUP BY TAS_UID"; + + return $this->pdoExecutor($sqlString, $params); + } + + public function statusIndicator($usrUid) + { + $response = array(); + $result = $this->statusIndicatorGeneral($usrUid); + + $response['overdue'] = 0; + $response['atRisk'] = 0; + $response['onTime'] = 0; + $response['percentageOverdue'] = 0; + $response['percentageAtRisk'] = 0; + $response['percentageOnTime'] = 0; + $response['dataList'] = array(); + + if (is_array($result) && isset($result[0])) { + $response['overdue'] = $result[0]['OVERDUE']; + $response['atRisk'] = $result[0]['ONTIME']; + $response['onTime'] = $result[0]['ATRISK']; + + $total = $response['overdue'] + $response['atRisk'] + $response['onTime']; + if ($total != 0) { + $response['percentageOverdue'] = ($response['overdue']*100)/$total; + $response['percentageAtRisk'] = ($response['atRisk']*100)/$total; + $response['percentageOnTime'] = ($response['onTime']*100)/$total; + } + } + + $result = $this->statusIndicatorDetail($usrUid); + + foreach ($result as $key => $value) { + $result[$key]['overdue'] = $value['overdue']; + $result[$key]['atRisk'] = $value['atRisk']; + $result[$key]['onTime'] = $value['onTime']; + $result[$key]['percentageOverdue'] = 0; + $result[$key]['percentageAtRisk'] = 0; + $result[$key]['percentageOnTime'] = 0; + $result[$key]['percentageTotalOverdue'] = 0; + $result[$key]['percentageTotalAtRisk'] = 0; + $result[$key]['percentageTotalOnTime'] = 0; + $total = $value['overdue'] + $value['onTime'] + $value['atRisk']; + if ($total != 0) { + $result[$key]['percentageOverdue'] = ($value['overdue']*100)/$total; + $result[$key]['percentageAtRisk'] = ($value['atRisk']*100)/$total; + $result[$key]['percentageOnTime'] = ($value['onTime']*100)/$total; + $result[$key]['percentageTotalOverdue'] = $response['overdue'] != 0 ? ($value['overdue']*100)/$response['overdue']: 0; + $result[$key]['percentageTotalAtRisk'] = $response['atRisk'] != 0 ? ($value['atRisk']*100)/$response['atRisk'] : 0; + $result[$key]['percentageTotalOnTime'] = $response['onTime'] != 0 ? ($value['onTime']*100)/$response['onTime']: 0; + } + } + $response['dataList'] = $result; + return $response; + } private function periodicityFieldsForSelect($periodicity) { $periodicityFields = $this->periodicityFieldsString($periodicity); diff --git a/workflow/engine/classes/model/DashboardIndicator.php b/workflow/engine/classes/model/DashboardIndicator.php index 6a4bdc47f..c33abdf7c 100644 --- a/workflow/engine/classes/model/DashboardIndicator.php +++ b/workflow/engine/classes/model/DashboardIndicator.php @@ -70,6 +70,28 @@ class DashboardIndicator extends BaseDashboardIndicator $oldValue = current(reset($calculator->ueiHistoric($uid, $compareDate, $compareDate, \ReportingPeriodicityEnum::NONE))); $row['DAS_IND_VARIATION'] = $value - $oldValue; break; + case '1050': + $value = $calculator->statusIndicatorGeneral($userUid); + $row['OVERDUE'] = 0; + $row['ON_TIME'] = 0; + $row['AT_RISK'] = 0; + $row['PERCENTAGE_OVERDUE'] = 0; + $row['PERCENTAGE_AT_RISK'] = 0; + $row['PERCENTAGE_ON_TIME'] = 0; + + if (is_array($value) && isset($value[0])) { + $row['OVERDUE'] = $value[0]['OVERDUE']; + $row['ON_TIME'] = $value[0]['ONTIME']; + $row['AT_RISK'] = $value[0]['ATRISK']; + + $total = $row['OVERDUE'] + $row['AT_RISK'] + $row['ON_TIME']; + if ($total != 0) { + $row['PERCENTAGE_OVERDUE'] = ($row['OVERDUE']*100)/$total; + $row['PERCENTAGE_AT_RISK'] = ($row['AT_RISK']*100)/$total; + $row['PERCENTAGE_ON_TIME'] = ($row['ON_TIME']*100)/$total; + } + } + break; default: $arrResult = $calculator->generalIndicatorData($row['DAS_IND_UID'], $measureDate, $measureDate, \ReportingPeriodicityEnum::NONE); $value = $arrResult[0]['value']; diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql old mode 100755 new mode 100644 index fbb333b5e..558cb0df4 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -59976,11 +59976,7 @@ INSERT INTO CATALOG (CAT_UID, CAT_LABEL_ID, CAT_TYPE, CAT_FLAG, CAT_OBSERVATION, ('400','ID_YEAR','PERIODICITY','','','2015-03-04','2015-03-04'), ('1010','ID_PROCESS_EFFICIENCE','INDICATOR','','','2015-03-04','2015-03-04'), ('1030','ID_EMPLYEE_EFFICIENCIE','INDICATOR','','','2015-03-04','2015-03-04'), -('1040','ID_USER_INEFFICIENCE','INDICATOR','','','2015-03-04','2015-03-04'), ('1050','ID_OVER_DUE','INDICATOR','%','Unit for displaying','2015-03-04','2015-03-04'), -('1060','ID_NEW_CASES','INDICATOR','','','2015-03-04','2015-03-04'), -('1070','ID_COMPLETED_CASES','INDICATOR','','','2015-03-04','2015-03-04'), -('1080','ID_WORKING_CASES','INDICATOR','','','2015-03-04','2015-03-04'); INSERT INTO ADDONS_MANAGER (ADDON_DESCRIPTION,ADDON_ID,ADDON_NAME,ADDON_NICK,ADDON_PUBLISHER,ADDON_RELEASE_TYPE,ADDON_STATUS,STORE_ID,ADDON_TYPE,ADDON_DOWNLOAD_URL,ADDON_VERSION,ADDON_DOWNLOAD_PROGRESS) VALUES ('Enables de Actions By Email feature.','actionsByEmail','actionsByEmail','actionsByEmail','Colosa','localRegistry','ready','00000000000000000000000000010004','features','','','0'), diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index ee3fbb175..ea632a452 100755 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -2789,7 +2789,7 @@ CREATE TABLE `DASHBOARD_DAS_IND` ( `DAS_UID` VARCHAR(32) default '' NOT NULL, `OWNER_UID` VARCHAR(32) default '' NOT NULL, - `OWNER_TYPE` VARCHAR(15) default '' NOT NULL + `OWNER_TYPE` VARCHAR(15) default '' NOT NULL, PRIMARY KEY (`DAS_UID`), CONSTRAINT `fk_dashboard_indicator_dashboard_das_ind` FOREIGN KEY (`DAS_UID`) diff --git a/workflow/engine/js/strategicDashboard/dashboard.js b/workflow/engine/js/strategicDashboard/dashboard.js deleted file mode 100644 index bc177d283..000000000 --- a/workflow/engine/js/strategicDashboard/dashboard.js +++ /dev/null @@ -1,1237 +0,0 @@ - var peiParams = { - canvas : { - containerId:'proEfficGenGraph', - width:300, - height:300, - stretch:true - }, - graph: { - allowDrillDown:false, - allowTransition:true, - showTip: true, - allowZoom: true, //verificar navegadores... - gapWidth:0.2, - useShadows: true, //for Firefox and Chrome - thickness: 30, - showLabels: true, - colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a'] - } - }; - - var ueiParams = { - canvas : { - containerId:'proEfficGenGraph', - width:300, - height:300, - stretch:true - }, - graph: { - allowTransition: false, - allowDrillDown: true, - showTip: true, - allowZoom: false, - useShadows: false, - gridLinesX: true, - gridLinesY: true, - area: {visible: false, css:"area"}, - axisX:{ showAxis: true, label: G_STRING.ID_GROUPS }, - axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, - showErrorBars: true - } - }; - - - var generalLineParams1 = { - canvas : { - containerId:'generalGraph1', - width:300, - height:300, - stretch:true - }, - graph: { - allowTransition: false, - allowDrillDown: true, - showTip: true, - allowZoom: false, - useShadows: false, - gridLinesX: true, - gridLinesY: true, - area: {visible: false, css:"area"}, - axisX:{ showAxis: true, label: G_STRING.ID_PROCESS_TASKS }, - axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, - showErrorBars: false - } - }; - - var generalLineParams2 = { - canvas : { - containerId:'generalGraph2', - width:300, - height:300, - stretch:true - }, - graph: { - allowTransition: false, - allowDrillDown: true, - showTip: true, - allowZoom: false, - useShadows: false, - gridLinesX: true, - gridLinesY: true, - area: {visible: false, css:"area"}, - axisX:{ showAxis: true, label: G_STRING.ID_PROCESS_TASKS }, - axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, - showErrorBars: false - } - }; - - - - var generalBarParams1 = { - canvas : { - containerId:'generalGraph1', - width:300, - height:300, - stretch:true - }, - graph: { - allowDrillDown:false, - allowTransition:true, - axisX:{ showAxis: true, label: G_STRING.ID_YEAR }, - axisY:{ showAxis: true, label: "Q" }, - gridLinesX:false, - gridLinesY:true, - showTip: true, - allowZoom: true, - useShadows: true, - paddingTop: 50, - colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a','#74a9a9'] - } - }; - - var generalBarParams2 = { - canvas : { - containerId:'generalGraph2', - width:300, - height:300, - stretch:true - }, - graph: { - allowDrillDown:false, - allowTransition:true, - axisX:{ showAxis: true, label: G_STRING.ID_YEAR }, - axisY:{ showAxis: true, label: "Q" }, - gridLinesX:false, - gridLinesY:true, - showTip: true, - allowZoom: true, - useShadows: true, - paddingTop: 50, - colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a','#74a9a9'] - } - }; - var peiDetailParams = { - canvas : { - containerId:'proEfficGraph', - width:300, - height:300, - stretch:true - }, - graph: { - allowTransition: false, - allowDrillDown: true, - showTip: true, - allowZoom: false, - useShadows: false, - gridLinesX: true, - gridLinesY: true, - area: {visible: false, css:"area"}, - axisX:{ showAxis: true, label: G_STRING.ID_PROCESS_TASKS }, - axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, - showErrorBars: true - - } - }; - - var ueiDetailParams = { - canvas : { - containerId:'proEfficGraph', - width:300, - height:300, - stretch:true - }, - graph: { - allowTransition: false, - allowDrillDown: true, - showTip: true, - allowZoom: false, - useShadows: false, - gridLinesX: true, - gridLinesY: true, - area: {visible: false, css:"area"}, - axisX:{ showAxis: true, label: G_STRING.ID_USERS }, - axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, - showErrorBars: true - - } - }; - - //Adding data to - function animateprogress (id, index, comparative, name, indUid, direction){ - var getRequestAnimationFrame = function () { - return window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function ( callback ){ - window.setTimeout(enroute, 1 / 60 * 1000); - }; - }; - - var fpAnimationFrame = getRequestAnimationFrame(); - var i = 0; - var j = 0; - - if(name.length>20){ - name = name.substring( -20, 20 ); - name = name+"..."; - } - - index = validaNull(index); - - document.getElementById(id+"Huge"+indUid).innerHTML = index; - document.getElementById(id+"Small"+indUid).innerHTML = comparative; - document.getElementById(id+"Span"+indUid).innerHTML = name; - - if(id == "proEffic" || id == "userEffic"){ - if(comparative<0){ - if(id == "proEffic"){ - $(document.getElementsByClassName("proGreen")).removeClass("panel-green").addClass("panel-red"); - $(document.getElementsByClassName("up")).removeClass("fa-chevron-up").addClass("fa-chevron-down"); - } - } else if(comparative>=0){ - $(document.getElementsByClassName("proRed")).removeClass("panel-red").addClass("panel-green"); - if(comparative==0){ - $(document.getElementsByClassName("down")).removeClass("fa-chevron-down").addClass("fa-circle-o"); - $(document.getElementsByClassName("up")).removeClass("fa-chevron-up").addClass("fa-circle-o"); - } else { - $(document.getElementsByClassName("down")).removeClass("fa-chevron-down").addClass("fa-chevron-up"); - } - } - } - - if(id == "generalGreat" || id == "generalLow"){ - var animacion = function () { - var comp = parseInt(comparative); - $(document.getElementById(id+indUid)).attr('aria-valuemax', comp); - var indexToPaint = index*100/comp; - if (i<=indexToPaint) - { - $(document.getElementById(id+indUid)).css('width', i+'%').attr('aria-valuenow', i); - i++; - fpAnimationFrame(animacion); - } - - if(j<=index){ - document.getElementById(id+"Huge"+indUid).innerHTML = j+"%"; - j++; - fpAnimationFrame(animacion); - } - - var direc = (direction == "1")? "<" : ">"; - if(id == "generalLow"){ - document.getElementById(id+"Small"+indUid).innerHTML = "Goal "+direc+" "+comparative+"%"; - } else{//si esq es positivo mostramos Well Done y la clase q setea las letras en blanco - document.getElementById(id+"Small"+indUid).innerHTML = "("+direc+" "+comparative+" %) "+ G_STRING.ID_WELL_DONE; - } - } - fpAnimationFrame(animacion); - } - }; - - //Button by dashbutton - var dasButton = '
'; - - //Items by each type: - var proEffic = '
\ -
\ - \ -
\ -
'; - - var userEffic = '
\ -
\ - \ -
\ -
'; - - var compCases = '
\ -
\ - \ -
\ -
'; - - var numCases = '
\ -
\ - \ -
\ -
'; - - //Data by Indicator elements: - var proEfficDataGen = '
\ -
'+ G_STRING.ID_PRO_EFFICIENCY_INDEX +'
\ -
\ -
\ -
26%
\ -
'+ G_STRING.ID_EFFICIENCY_INDEX +'
\ -
\ -
\ -
$1813.50
\ -
'+ G_STRING.ID_INEFFICIENCY_COST +'
\ -
\ -
\ -
\ -
\ -
'; - - var proEfficData = '
\ -
\ - \ -
\ -
\ -
\ -
26%
\ -
'+ G_STRING.ID_EFFICIENCY_INDEX +'
\ -
\ -
\ -
$1813.50
\ -
'+ G_STRING.ID_INEFFICIENCY_COST +'
\ -
\ -
\ -
\ -
\ -
'; - - var proEfficDetail = '
\ -
\ - \ -
\ -
Process name 1
\ -
\ -
\ -
4.3 Days
\ -
'+ G_STRING.ID_EFFICIENCY_INDEX +'
\ -
\ -
\ -
1.3 Days
\ -
'+ G_STRING.ID_EFFICIENCY_COST +'
\ -
\ -
\ -
\ -
\ -
\ -
'; - - var proEfficTaskDetail = '
\ -
\ -
Task 1
\ -
\ -
\ -
\ -
\ -
\ -
0.95
\ -
'+ G_STRING.ID_EFFICIENCY_COST +'
\ -
\ -
\ -
4.3
\ -
Average Time
\ -
\ -
\ -
1.3
\ -
Deviation
\ -
\ -
\ -
\ -
\ -
'; - - var userTaskDetail = '
\ -
\ -
Task 1
\ -
\ -
\ -
\ -
\ -
\ -
0.95
\ -
'+ G_STRING.ID_EFFICIENCY_INDEX +'
\ -
\ -
\ -
\ -
1.3
\ -
'+ G_STRING.ID_INEFFICIENCY_COST +'
\ -
\ -
\ -
\ -
\ -
'; - - var generalDataLow = '
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
'; - - var generalDataGreat = '
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
'; - - var oType; - var actualDashId; - - //fecha actual - var date = new Date(); - var dateMonth = date.getMonth(); - var dateYear = date.getFullYear(); - - var dateActual = "01-"+(dateMonth+1)+"-"+dateYear; - var dateActualEnd = "30-"+(dateMonth)+"-"+dateYear; - - function validaNull(val){ - if(val === null || val == undefined || val == "?"){ - val = "?"; - } else { - val = (parseFloat(val)).toFixed(2); - } - return val; - }; - - function back(){ - if(oType=="proEffic"){ - var oID = $('.dashPro').attr("id"); - var oIDs = oID.split('Item'); - var id = oIDs[0]; - var uid = oIDs[1]; - - if($('.proGreen').hasClass('panel-red')){ - var comparative = -1; - } else if($('.proRed').hasClass('panel-green')){ - var comparative = +1; - } - - proxy.peiData(uid, dateActual, dateActualEnd, - function(dataIndicator){ - indicatorsData(dataIndicator, "proEffic", uid, comparative ); - }); - } else if(oType == "userEffic"){ - var oID = $('.dashUsr').attr("id"); - var oIDs = oID.split('Item'); - var id = oIDs[0]; - var uid = oIDs[1]; - - if($('.proRed').hasClass('panel-red')){ - var comparative = -1; - } else if($('.proRed').hasClass('panel-green')){ - var comparative = +1; - } - - proxy.ueiData(uid, dateActual, dateActualEnd, - function(dataIndicator){ - indicatorsData(dataIndicator, "userEffic", uid, comparative); - }); - } - }; - - /***** Adding Data by indicator *****/ - function indicatorsData(dataIndicator, type, indUid, comparative){ - $('#indicatorsDataGridStack').gridstack(); - var gridIndicators = $('#indicatorsDataGridStack').data('gridstack'), - widgetDetailDom; - gridIndicators.remove_all(); - - var gridProcess = $('#relatedDataGridStack').data('gridstack'); - gridProcess.remove_all(); - - oType = type; - switch (type) { - case 'proEffic': //Process Efficience Index - case 'userEffic': - var widget = proEfficDataGen; - var widgetDetail = proEfficDetail; - type = 'proEffic'; - break; - case 'generalGreat': - var widget = generalDataGreat; - var widgetDetail = ""; - break; - case 'generalLow': - var widget = generalDataLow; - var widgetDetail = ""; - break; - } - - //Drawing - gridIndicators.add_widget($(widget), 0, 15, 20, 4.7, true); //General data - - if(oType == "proEffic" || oType == "userEffic"){ - if(comparative<0){ - $(document.getElementsByClassName("greenbg")).removeClass("greenbg").addClass("redbg"); - $(document.getElementsByClassName("green")).removeClass("green").addClass("red"); - } else if(comparative>=0) { - $(document.getElementsByClassName("redbg")).removeClass("redbg").addClass("greenbg"); - } - } - - if (oType == "generalGreat" || oType == "generalLow") { - document.getElementById("relatedLabel").innerHTML = ""; - var graph1 = null; - if (dataIndicator.graph1Type == '10') { - generalBarParams1.graph.axisX.label = dataIndicator.graph1XLabel; - generalBarParams1.graph.axisY.label = dataIndicator.graph1YLabel; - graph1 = new BarChart(dataIndicator.graph1Data, generalBarParams1, null, null); - } else { - generalLineParams1.graph.axisX.label = dataIndicator.graph1XLabel; - generalLineParams1.graph.axisY.label = dataIndicator.graph1YLabel; - graph1 = new LineChart(dataIndicator.graph1Data, generalLineParams1, null, null); - } - graph1.drawChart(); - - var graph2 = null; - if (dataIndicator.graph2Type == '10') { - generalBarParams2.graph.axisX.label = dataIndicator.graph2XLabel; - generalBarParams2.graph.axisY.label = dataIndicator.graph2YLabel; - graph2 = new BarChart(dataIndicator.graph2Data, generalBarParams2, null, null); - } else { - generalLineParams2.graph.axisX.label = dataIndicator.graph2XLabel; - generalLineParams2.graph.axisY.label = dataIndicator.graph2YLabel; - graph2 = new LineChart(dataIndicator.graph2Data, generalLineParams2, null, null); - } - graph2.drawChart(); - } - - //ProEffic or userEffic - if(type == "proEffic" || type == "userEffic"){ - var inValue = validaNull(dataIndicator.efficiencyIndex); - var inCost = validaNull(dataIndicator.inefficiencyCost); - - document.getElementById(type+"Index").innerHTML = inValue; - document.getElementById(type+"Cost").innerHTML = "$" +inCost; - - //first level draw - if(oType == "proEffic") { - document.getElementById("relatedLabel").innerHTML = "

"+ G_STRING.ID_RELATED_PROCESS +"

"; - var graph = new Pie3DChart(dataIndicator.dataToDraw, peiParams, null, null); - graph.drawChart(); - } - - if(oType == "userEffic") { - document.getElementById("relatedLabel").innerHTML = "

"+ G_STRING.ID_RELATED_GROUPS +"

"; - var graph = new LineChart(dataIndicator.dataToDraw, ueiParams, null, null); - graph.drawChart(); - } - - //Data by process - for (i in dataIndicator.data){ - var proUid = dataIndicator.data[i].uid; - var proDataName = dataIndicator.data[i].name; - var proDataEfficiency = validaNull(dataIndicator.data[i].efficiencyIndex); - var proDataEfficCost = validaNull(dataIndicator.data[i].inefficiencyCost); - var x = 0; - if(i % 2 == 0){ - x = 6; - } - - widgetDetailDom = $(widgetDetail); - widgetDetailDom.attr('id', proUid); - - gridProcess.add_widget(widgetDetailDom, x, 15, 6, 2, true); - - if(comparative<0){ - $(document.getElementsByClassName("green")).removeClass("green").addClass("blue"); - } else if(comparative>=0){ - //$(document.getElementsByClassName("blue")).removeClass("blue").addClass("green"); - } - - if(proDataName.length>25){ - proDataName = proDataName.substring( -25, 25 ); - proDataName = proDataName+"..."; - } - - //charging data by process - //Process Title - $("#procGreyTitle").attr('id', "procGreyTitle"+proUid);//changin the id - document.getElementById("procGreyTitle"+proUid).innerHTML = ""+proDataName+""; - //'+ G_STRING.ID_PRO_EFFICIENCY_INDEX +' - $("#proIndex").attr('id', "proIndex"+proUid);//changin the id - document.getElementById("proIndex"+proUid).innerHTML = proDataEfficiency; - //Process Efficiency Cost - $("#proCost").attr('id', "proCost"+proUid);//changin the id - document.getElementById("proCost"+proUid).innerHTML = proDataEfficCost; - - widgetDetailDom.click(function(e){ - var proid = $(this).attr("id"); - var proname = $(this).find("#procGreyTitle"+proid).html(); - var proindex = validaNull($(this).find("#proIndex"+proid).html()); - var procost = validaNull($(this).find("#proCost"+proid).html()); - - gridIndicators.remove_all(); - gridProcess.remove_all(); - - //Drawing - gridIndicators.add_widget($(proEfficData), 0, 15, 20, 4.7, true); //General data of the process - if(comparative < 0){ - $(document.getElementsByClassName("greenbg")).removeClass("greenbg").addClass("redbg"); - $(document.getElementsByClassName("green")).removeClass("green").addClass("red"); - } else if(comparative > 0){ - $(document.getElementsByClassName("redbg")).removeClass("redbg").addClass("greenbg"); - //$(document.getElementsByClassName("red")).removeClass("red").addClass("green"); - } - - //adding data - //var name = $("#"+oType+"Span"+indUid).html(); - document.getElementById(type+"Title").innerHTML = name; - document.getElementById("proDetName").innerHTML = proname; - document.getElementById(type+"Index").innerHTML = proindex; - document.getElementById(type+"Cost").innerHTML = "$" +procost; - - //adding tasks - if(oType == "proEffic"){ - proxy.processTasksData(proid, dateActual, dateActualEnd, - function(dataTasks){ - tasksData(dataTasks, gridProcess, proid); - hideScrollIfAllDivsAreVisible(); - }); - } else { - proxy.userGroupData(proid, dateActual, dateActualEnd, - function(dataTasks){ - tasksData(dataTasks, gridProcess, proid); - hideScrollIfAllDivsAreVisible(); - }); - } - return false; - }); - } - hideScrollIfAllDivsAreVisible(); - } - //Adding the data by process - var name = $("#"+oType+"Span"+indUid).html(); - document.getElementById(type+"Title").innerHTML = name; - }; - - function tasksData(dataTasks, gridIndicators, proid){ - var i = 0; - if(oType == "proEffic"){ - document.getElementById("relatedLabel").innerHTML = "

"+ G_STRING.ID_RELATED_TASKS +"

"; - var graph = new LineChart(dataTasks.dataToDraw, peiDetailParams, null, null); - graph.drawChart(); - for (i in dataTasks.tasksData){ - var taskUid = dataTasks.tasksData[i].uid; - var taskName = dataTasks.tasksData[i].name; - var taskEffic = validaNull(dataTasks.tasksData[i].efficienceIndex); - var taskAverage = validaNull(dataTasks.tasksData[i].averageTime); - var taskDeviation = validaNull(dataTasks.tasksData[i].deviationTime); - var x = 0; - if(i % 2 == 0){ - x = 6; - } - - var widgetDetailTaskDom = $(proEfficTaskDetail); - widgetDetailTaskDom.attr('id', taskUid+"task"); - gridIndicators.add_widget(widgetDetailTaskDom, x, 15, 6, 2, true);//Drawing the task - - if($('.proGreen').hasClass('panel-red')){ - $(document.getElementsByClassName("greenbg")).removeClass("greenbg").addClass("redbg"); - }else { - $(document.getElementsByClassName("redbg")).removeClass("redbg").addClass("greenbg"); - } - - if(taskName.length>55){ - taskName = taskName.substring( -55, 55 ); - taskName = taskName+"..."; - } - - //Adding data to task - //Task Title - $("#taskName").attr('id', "taskName"+taskUid);//changin the id - document.getElementById("taskName"+taskUid).innerHTML = taskName; - //Task Efficiency Index - $("#taskEffic").attr('id', "taskEffic"+taskUid);//changin the id - document.getElementById("taskEffic"+taskUid).innerHTML = taskEffic; - //Task Average - $("#taskAver").attr('id', "taskAver"+taskUid);//changin the id - document.getElementById("taskAver"+taskUid).innerHTML = taskAverage; - //Task Deviation - $("#taskDeviat").attr('id', "taskDeviat"+taskUid);//changin the id - document.getElementById("taskDeviat"+taskUid).innerHTML = taskDeviation; - } - } else { - document.getElementById("relatedLabel").innerHTML = "

"+ G_STRING.ID_RELATED_USERS +"

"; - var graph = new LineChart(dataTasks.dataToDraw, ueiDetailParams, null, null); - graph.drawChart(); - for (i in dataTasks.tasksData){ - var usrUid = dataTasks.tasksData[i].userUid; - var usrName = dataTasks.tasksData[i].name; - var usrEffic = validaNull(dataTasks.tasksData[i].efficiencyIndex); - var usrCost = validaNull(dataTasks.tasksData[i].inefficiencyCost); - var x = 0; - if(i % 2 == 0){ - x = 6; - } - - var widgetDetailUsrDom = $(userTaskDetail); - widgetDetailUsrDom.attr('id', usrUid+"task"); - gridIndicators.add_widget(widgetDetailUsrDom, x, 15, 6, 2, true);//Drawing the task - - if($('.proRed').hasClass('panel-green')){ - $(document.getElementsByClassName("redbg")).removeClass("redbg").addClass("greenbg"); - } else{ - $(document.getElementsByClassName("greenbg")).removeClass("greenbg").addClass("redbg"); - } - - if(usrName.length>55){ - usrName = usrName.substring( -55, 55 ); - usrName = usrName+"..."; - } - - //Adding data to task - //Task Title - $("#usrName").attr('id', "usrName"+usrUid);//changin the id - document.getElementById("usrName"+usrUid).innerHTML = usrName; - //Task Efficiency Index - $("#usrEffic").attr('id', "usrEffic"+usrUid);//changin the id - document.getElementById("usrEffic"+usrUid).innerHTML = usrEffic; - //Task Deviation - $("#usrCost").attr('id', "usrCost"+usrUid);//changin the id - document.getElementById("usrCost"+usrUid).innerHTML = usrCost; - } - } - - - }; - - function hideScrollIfAllDivsAreVisible(){ - //For Debug: console.log('hidden ' + $('.hideme').length); - if ($('.hideme').length <= 0) { - $('#theImg').hide(); - } - else { - $('#theImg').show(); - } - } - - $( document ).ready(function() { - /* Show on scroll functionality... */ - $(window).scroll( function() { - /* Check the location of each desired element */ - $('.hideme').each( function(i){ - var bottom_of_object = $(this).offset().top + $(this).outerHeight(); - var bottom_of_window = $(window).scrollTop() + $(window).height(); - /* If the object is completely visible in the window, fade it in */ - if (bottom_of_window + 100 > bottom_of_object) { - $(this).animate({'opacity':'1'}, 500); - $(this).removeClass('hideme'); - } - }); - hideScrollIfAllDivsAreVisible(); - }); - - if(dateMonth == 0){ - document.getElementById('year').selectedIndex = 1; - document.getElementById('mounth').selectedIndex = 11; - }else{ - document.getElementById('mounth').selectedIndex = dateMonth-1; - } - - /*****calling the proxy*****/ - function getDashboardProxy(type) { - var ws = urlProxy.split('/'); - if (type.toLowerCase()=='test') - return new DashboardProxyTest(); - - if (type.toLowerCase()=='pro') - return new DashboardProxy(token, - urlProxy, - ws[3]); - }; - proxy = getDashboardProxy('pro'); - proxy.userDashboards(usrId, - function(dataDashboards){ - if(dataDashboards.length > 0){ - dashboardsButtons(dataDashboards); - }else{ - $(".indicators").append("

"+ G_STRING.ID_GRID_PAGE_NO_DASHBOARD_MESSAGE +"

"); - } - }); - - /*********************************/ - //ConfigurationObject - objConfigDashboards = [ - { - "dashUid": "15115651654654", - "favorite": 1, - "indicators":[ - { - /*"indUid": "15115651654654", - "indName": "Process Efficiency Index",*/ - "id": "proEffic", - "favorite": 1, - "x": 0, - "y": 6, - "height": "50px", - "width": "20px" - }, { - /*"indUid": "45165165165161", - "indName": "Completed Cases",*/ - "id": "compCases", - "favorite": 0, - "x": 6, - "y": 6, - "height": "50px", - "width": "20px" - } - ] - }, - { - "dashUid": "5645565165465", - "favorite": 0, - "indicators":[ - { - /*"indUid": "15115651654654", - "indName": "Number Cases",*/ - "id": "numCases", - "favorite": 0, - "x": 0, - "y": 6, - "height": "50px", - "width": "20px" - }, { - /*"indUid": "45165165165161", - "indName": "User Efficiency",*/ - "id": "userEffic", - "favorite": 1, - "x": 4, - "y": 6, - "height": "50px", - "width": "20px" - }, - { - /*"indUid": "45165165165161", - "indName": "Completed Cases",*/ - "id": "compCases", - "favorite": 0, - "x": 8, - "y": 6, - "height": "50px", - "width": "20px" - } - ] - } - ]; - - //When some item is moved - $('.grid-stack').on('change', function (e, items) { - var widgets = []; - _.map($('.grid-stack .grid-stack-item:visible'), function (el) { - el = $(el); - var item = el.data('_gridstack_node'); - var idWidGet = item.el[0].id.split('Item'); - if(favorite == actualDashId){ - favoriteData = 1; - } else { - favoriteData = 0; - } - if (typeof idWidGet[1] != "undefined") { - var widgetsObj = { - 'indicatorId': idWidGet[1], - 'x': item.x, - 'y': item.y, - 'width': item.width, - 'height': item.height <= 1 ? 2 : item.height - } - widgets.push(widgetsObj); - } - }); - - if (widgets.length != 0) { - var dashboard = { - 'dashId': actualDashId, - 'dashFavorite': favoriteData, - 'dashData': widgets - } - proxy.setPositionIndicator(dashboard); - } - }); - - - /*****Adding Buttons*****/ - function dashboardsButtons(dataDashboards){ - for( i in dataDashboards){ - var dashUid = dataDashboards[i].dashUid; - var dashName = dataDashboards[i].dashName; - var dashFavorite = dataDashboards[i].favorite; - - var domButton = $(dasButton); - - //adding a new button - $( "#dasbuttons" ).append( domButton ); - - //adding the UID like the id of the tag. - $("#dasB").attr('id', dashUid); - $("#favorite").attr('id', dashUid+'fav'); - - if(dashName.length>20){ - dashNameButton = dashName.substring( -20, 20 ); - dashNameButton = dashNameButton+"..."; - } else{ - dashNameButton = dashName; - } - - //addign the name - document.getElementById(dashUid).innerHTML = dashNameButton; - - //if it is favorite adding the selected class - if(dashFavorite == 1){ - actualDashId = dashUid; - favorite = actualDashId; - document.getElementById("titleH4").innerHTML = dashName; - $("#"+dashUid+"fav").addClass("selected"); - - //calling backend - proxy.dashboardIndicators(dashUid, dateActual, dateActualEnd, - function(widgetsObj) { - indicators(widgetsObj); - }); - } - - domButton.find("#"+dashUid+"fav").click(function() { - dashUid = $(this).siblings('.btn').attr("id"); - favorite = dashUid; - - $(".selected").removeClass("selected"); - $(this).addClass("selected"); - //call backend to save the favorite selection - var dashboard = { - 'dashId': dashUid, - 'dashFavorite': 1, - 'dashData': '' - } - proxy.setPositionIndicator(dashboard); - }); - - domButton.find("#"+dashUid).click(function() { - var btnid = $(this).attr("id"); - //first we have to get the divs empty - $('#indicatorsGridStack').gridstack(); - var gridDashboards = $('#indicatorsGridStack').data('gridstack'); - gridDashboards.remove_all(); - - $('#indicatorsDataGridStack').gridstack(); - var gridIndicators = $('#indicatorsDataGridStack').data('gridstack'); - gridIndicators.remove_all(); - - //changing the Name of the Dashboard - var btnName = $(this).html(); - document.getElementById("titleH4").innerHTML = btnName; - - actualDashId = btnid; - //calling backend - proxy.dashboardIndicators(btnid, dateActual, dateActualEnd, - function(widgetsObj) { - indicators(widgetsObj); - }); - }); - - } - }; - - - - /*****Adding the indicators*****/ - function indicators (widgetsObj){ - $('#indicatorsGridStack').gridstack(); - - serialization = GridStackUI.Utils.sort(widgetsObj); - var grid = $('#indicatorsGridStack').data('gridstack'); - //var width = 12 / widgetsObj.length; - var i = 1; - - _.each(serialization, function (node) { - if(node.x == 0){ - var x = 12 - (12/i); - }else { - var x = node.x; - } - if(node.y == 0){ - var y = 6; - }else { - var y = node.y; - } - - if(node.height == 0){ - node.height = 2; - } - if(node.width == 0){ - node.width = 12 / widgetsObj.length; - } - - node.comparative = validaNull(node.comparative); - - switch (node.id) { - case "1010": //Process Efficience Index - var widget = proEffic; - var id = "proEffic"; - break; - case "1030": //Employee Efficience Index - var widget = userEffic; - var id = "userEffic"; - break; - case "1020": - case "1040": - case "1050": - case "1060": - case "1070": - case "1080": - var indexI = parseFloat(node.index); - var comparativeI = parseFloat(node.comparative); - var condition = (node.direction == "1")? (indexI <= comparativeI) : (indexI >= comparativeI); - if(condition == true){ - var widget = numCases; //Great - var id = "generalGreat"; - } else { - var widget = compCases; //Low - var id = "generalLow"; - } - break; - } - - //var comparative = (parseFloat(node.comparative)).toFixed(2); - var widgetDom = $(widget); - - //Dibujando - grid.add_widget(widgetDom, x, y, node.width, node.height, true); //dibuja los elementos - - $("#"+id+"Item").attr('id', id+"Item"+node.indUid);//changin the id of the divs - $("#"+id+"Div").attr('id', id+"Div"+node.indUid); - $("#"+id+"Huge").attr('id', id+"Huge"+node.indUid); - $("#"+id+"Small").attr('id', id+"Small"+node.indUid); - $("#"+id+"M").attr('id', id+"M"+node.indUid); - $("#"+id+"Span").attr('id', id+"Span"+node.indUid); - - if(id =="generalGreat" || id == "generalLow"){ - $("#"+id).attr('id', id+node.indUid); - } - - //Showing the data panels if is the favorite - if(node.favorite == 1){ - //changing the class - if ($("#"+id+"M"+node.indUid).hasClass('panel-active')){ - //nada - }else{ - //changing classes to show selection - $(document.getElementsByClassName("panel-active")).removeClass("panel-active"); - $("#"+id+"M"+node.indUid).addClass("panel-active"); - } - - //Getting the data - if(id == "proEffic"){ - proxy.peiData(node.indUid, dateActual, dateActualEnd, - function(dataIndicator){ - indicatorsData(dataIndicator, "proEffic", node.indUid, node.comparative); - hideScrollIfAllDivsAreVisible(); - }); - } else if (id == "userEffic" ){ - proxy.ueiData(node.indUid, dateActual, dateActualEnd, - function(dataIndicator){ - indicatorsData(dataIndicator, "userEffic", node.indUid, node.comparative); - hideScrollIfAllDivsAreVisible(); - }); - } else { - proxy.generalIndicatorData(node.indUid, dateActual, dateActualEnd, - function(dataIndicator){ - var indexI = parseFloat(node.index); - var comparativeI = parseFloat(node.comparative); - var condition = (node.direction == "1")? (indexI <= comparativeI) : (indexI >= comparativeI); - if(condition == true){ //this are percentages - indicatorsData(dataIndicator, "generalGreat", node.indUid, node.comparative); - hideScrollIfAllDivsAreVisible(); - } else{ - indicatorsData(dataIndicator, "generalLow", node.indUid, node.comparative); - hideScrollIfAllDivsAreVisible(); - } - }); - } - } else { - $("#"+id+"M"+node.indUid).removeClass("panel-active"); - } - - //Animating the Indicators - animateprogress(id, node.index, node.comparative, node.indName, node.indUid, node.direction); //inserta datos en cada elemento - i++; - - hideScrollIfAllDivsAreVisible(); - /********Changing the class when the indicator item is selected********/ - widgetDom.click(function(){ - var oID = $(this).attr("id"); - - if(oID != undefined && oID.indexOf('Item') != -1){ - var comparative = 0; - var oIDs = oID.split('Item'); - var id = oIDs[0]; - var uid = oIDs[1]; - - if($(this).children().hasClass('panel-red')){ - var comparative = -1; - } else if($(this).children().hasClass('panel-green')){ - var comparative = +1; - } - - /*if ($("#"+id+"M"+uid).hasClass('panel-active')){ - //nada - }else{*/ - //changing classes to show selection - $(document.getElementsByClassName("panel-active")).removeClass("panel-active"); - $("#"+id+"M"+uid).addClass("panel-active"); - - //calling data of the indicator - if(id == "proEffic"){ - proxy.peiData(uid, dateActual, dateActualEnd, - function(dataIndicator){ - indicatorsData(dataIndicator, "proEffic", uid, comparative); - hideScrollIfAllDivsAreVisible(); - }); - } else if (id == "userEffic" ){ - proxy.ueiData(uid, dateActual, dateActualEnd, - function(dataIndicator){ - indicatorsData(dataIndicator, "userEffic", uid, comparative); - hideScrollIfAllDivsAreVisible(); - }); - } else { - proxy.generalIndicatorData(uid, dateActual, dateActualEnd, - function(dataIndicator){ - var index = $("#"+id+"Huge"+uid).html(); - index = parseInt(index); - var indexI = parseFloat(node.index); - var comparativeI = parseFloat(node.comparative); - var condition = (node.direction == "1")? (indexI <= comparativeI) : (indexI >= comparativeI); - if(condition == true){ //this are percentages - indicatorsData(dataIndicator, "generalGreat", uid, comparative); - } else{ - indicatorsData(dataIndicator, "generalLow", uid, comparative); - } - hideScrollIfAllDivsAreVisible(); - }); - } - - //} - } - }); - }); - }; - - $(".btn-compare").click(function(){ - var yearComp = $( "#year option:selected" ).text(); - var mounthComp = $( "#mounth option:selected" ).val(); - - dateActualEnd = "30-"+(mounthComp)+"-"+yearComp; - - //first we have to get the divs empty - $('#indicatorsGridStack').gridstack(); - var gridDashboards = $('#indicatorsGridStack').data('gridstack'); - gridDashboards.remove_all(); - - $('#indicatorsDataGridStack').gridstack(); - var gridIndicators = $('#indicatorsDataGridStack').data('gridstack'); - gridIndicators.remove_all(); - //For Debug: console.log(dateActualEnd); - //calling backend - proxy.dashboardIndicators(actualDashId, dateActual, dateActualEnd, - function(widgetsObj) { - indicators(widgetsObj); - }); - }); - - - }); - -$(function () { - var options = { - cell_height: 75, - vertical_margin: 12 - }; - $('.grid-stack').gridstack(options); -}); diff --git a/workflow/engine/js/strategicDashboard/dashboardProxy.js b/workflow/engine/js/strategicDashboard/dashboardProxy.js deleted file mode 100644 index b1669ecf7..000000000 --- a/workflow/engine/js/strategicDashboard/dashboardProxy.js +++ /dev/null @@ -1,500 +0,0 @@ - -var getKeyValue = -function getKeyValue(obj, key, undefined) { - var reg = /\./gi - , subKey - , keys - , context - , x - ; - - if (reg.test(key)) { - keys = key.split(reg); - context = obj; - - for (x = 0; x < keys.length; x++) { - subKey = keys[x]; - - //the values of all keys except for - //the last one should be objects - if (x < keys.length -1) { - if (!context.hasOwnProperty(subKey)) { - return undefined; - } - - context = context[subKey]; - } - else { - return context[subKey]; - } - } - } - else { - return obj[key]; - } -}; - -var setKeyValue = -function setKeyValue(obj, key, value) { - var reg = /\./gi - , subKey - , keys - , context - , x - ; - - //check to see if we need to process - //multiple levels of objects - if (reg.test(key)) { - keys = key.split(reg); - context = obj; - - for (x = 0; x < keys.length; x++) { - subKey = keys[x]; - - //the values of all keys except for - //the last one should be objects - if (x < keys.length -1) { - if (!context[subKey]) { - context[subKey] = {}; - } - - context = context[subKey]; - } - else { - context[subKey] = value; - } - } - } - else { - obj[key] = value; - } -}; - -var merge = -function merge(objFrom, objTo, propMap) { - var toKey - , fromKey - , x - , value - , def - , transform - , key - , keyIsArray - ; - - if (!objTo) { - objTo = {}; - } - - for(fromKey in propMap) { - if (propMap.hasOwnProperty(fromKey)) { - toKey = propMap[fromKey]; - - //force toKey to an array of toKeys - if (!Array.isArray(toKey)) { - toKey = [toKey]; - } - - for(x = 0; x < toKey.length; x++) { - def = null; - transform = null; - key = toKey[x]; - keyIsArray = Array.isArray(key); - - if (typeof(key) === "object" && !keyIsArray) { - def = key.default || null; - transform = key.transform || null; - key = key.key; - //evaluate if the new key is an array - keyIsArray = Array.isArray(key); - } - - if (keyIsArray) { - //key[toKeyName,transform,default] - def = key[2] || null; - transform = key[1] || null; - key = key[0]; - } - - if (def && typeof(def) === "function" ) { - def = def(objFrom, objTo); - } - - value = getKeyValue(objFrom, fromKey); - - if (transform) { - value = transform(value, objFrom, objTo); - } - - if (typeof value !== 'undefined') { - setKeyValue(objTo, key, value); - } - else if (typeof def !== 'undefined') { - setKeyValue(objTo, key, def); - } - } - } - } - - return objTo; -}; - -var DashboardProxy = function (oauthToken, server, workspace) { - this.server = server; - this.workspace = workspace; - this.baseUrl = "/api/1.0/" + workspace + "/"; - this.oauthToken = oauthToken; -}; - -DashboardProxy.prototype.userDashboards = function(userId, callBack) { - this.getJson('dashboard/ownerData/' + userId, - function (r) { - var returnList = []; - $.each(r, function(index, originalObject) { - var map = { - "DAS_TITLE" : "dashName", - "DAS_UID" : "dashUid", - "DAS_FAVORITE" : "favorite", - }; - - var newObject = merge(originalObject, {}, map); - returnList.push(newObject); - }); - callBack(returnList); - }); -}; - -DashboardProxy.prototype.dashboardIndicators = function(dashboardId, initDate, endDate, callBack) { - this.getJson('dashboard/' + dashboardId + '/indicator?dateIni=' + initDate + '&dateFin=' + endDate, - function (r) { - var returnList = []; - $.each(r, function(index, originalObject) { - var map = { - "DAS_IND_UID" : "indUid", - "DAS_IND_TITLE" : "indName", - "DAS_IND_TYPE" : "id", - "DAS_IND_VARIATION" : "comparative", - "DAS_IND_DIRECTION" : "direction", - "DAS_IND_VALUE" : "index", - "DAS_IND_X" : "x", - "DAS_IND_Y" : "y", - "DAS_IND_WIDTH" : "width", - "DAS_IND_HEIGHT" : "height", - "DAS_UID_PROCESS" : "process" - }; - - var newObject = merge(originalObject, {}, map); - //TODO do not burn this value. Data must come from the endpoint - newObject.favorite = ((returnList.length == 1) ? 1 : 0); - returnList.push(newObject); - }); - callBack(returnList); - }); -}; - -DashboardProxy.prototype.peiData = function(indicatorId, measureDate, compareDate, callBack) { - var endPoint = "ReportingIndicators/process-efficiency-data?" + - "indicator_uid=" + indicatorId + - "&measure_date=" + measureDate + - "&compare_date=" + compareDate + - "&language=en"; - this.getJson(endPoint, - function (r) { - var graphData = []; - $.each(r.data, function(index, originalObject) { - var map = { - "name" : "datalabel", - "inefficiencyCost" : "value" - }; - var newObject = merge(originalObject, {}, map); - var shortLabel = (newObject.datalabel == null) - ? "" - : newObject.datalabel.substring(0,15); - newObject.datalabel = shortLabel; - graphData.push(newObject); - }); - r.dataToDraw = graphData.splice(0,7); - callBack(r); - }); -} - -DashboardProxy.prototype.processTasksData = function(process, initDate, endDate, callBack) { - var endPoint = "ReportingIndicators/process-tasks?" + - "process_list=" + process + - "&init_date=" + initDate + - "&end_date=" + endDate + - "&language=en"; - this.getJson(endPoint, - function (r) { - var graphData = []; - $.each(r, function(index, originalObject) { - var map = { - "name" : "datalabel", - "averageTime" : "value", - "deviationTime" : "dispersion" - }; - var newObject = merge(originalObject, {}, map); - newObject.datalabel = newObject.datalabel.substring(0, 7); - graphData.push(newObject); - }); - var retval = {}; - retval.dataToDraw = graphData.splice(0,7); - retval.tasksData = r; - callBack(retval); - }); -} - -DashboardProxy.prototype.ueiData = function(indicatorId, measureDate, compareDate, callBack) { - var endPoint = "ReportingIndicators/employee-efficiency-data?" + - "indicator_uid=" + indicatorId + - "&measure_date=" + measureDate + - "&compare_date=" + compareDate + - "&language=en"; - this.getJson(endPoint, - function (r) { - var graphData = []; - $.each(r.data, function(index, originalObject) { - var map = { - "name" : "datalabel", - "averageTime" : "value", - "deviationTime" : "dispersion" - }; - var newObject = merge(originalObject, {}, map); - var shortLabel = (newObject.datalabel == null) - ? "" - : newObject.datalabel.substring(0,7); - - newObject.datalabel = shortLabel; - graphData.push(newObject); - }); - r.dataToDraw = graphData.splice(0,7); - callBack(r); - }); - - /*var retval = { - "efficiencyIndex":1.23, - "efficiencyVariation":0.23, - "inefficiencyCost":"$ 20112.23", - "employeeGroupsDataToDraw": - [ - {"value":"96", "datalabel":"User 1"}, - {"value":"84", "datalabel":"User 2"}, - {"value":"72", "datalabel":"User 3"}, - {"value":"18", "datalabel":"User 4"}, - {"value":"85", "datalabel":"User 5"} - ], - - "employeeGroupsData": [ - {"name": "User 1", "efficiencyIndex":"0.45", "innefficiencyCost":"$ 3404"}, - {"name": "User 2", "efficiencyIndex":"1.45", "innefficiencyCost":"$ 1404"}, - {"name": "User 3", "efficiencyIndex":"0.25", "innefficiencyCost":"$ 3304"}, - {"name": "User 4", "efficiencyIndex":"1.95", "innefficiencyCost":"$ 404"}, - {"name": "User 5", "efficiencyIndex":"1.25", "innefficiencyCost":"$ 13404"}, - {"name": "User 6", "efficiencyIndex":"0.75", "innefficiencyCost":"$ 4"} - ] - } - return retval;*/ -} - -DashboardProxy.prototype.userGroupData = function(groupId, initDate, endDate, callBack) { - var endPoint = "ReportingIndicators/group-employee-data?" + - "group_uid=" + groupId + - "&init_date=" + initDate + - "&end_date=" + endDate + - "&language=en"; - this.getJson(endPoint, - function (r) { - var graphData = []; - $.each(r, function(index, originalObject) { - var map = { - "name" : "datalabel", - "averageTime" : "value", - "deviationTime" : "dispersion" - }; - var newObject = merge(originalObject, {}, map); - newObject.datalabel = newObject.datalabel.substring(0, 7); - graphData.push(newObject); - }); - var retval = {}; - retval.dataToDraw = graphData.splice(0,7); - retval.tasksData = r; - callBack(retval); - }); -} - -DashboardProxy.prototype.generalIndicatorData = function(indicatorId, initDate, endDate, callBack) { - var method = ""; - var endPoint = "ReportingIndicators/general-indicator-data?" + - "indicator_uid=" + indicatorId + - "&init_date=" + initDate + - "&end_date=" + endDate + - "&language=en"; - this.getJson(endPoint, - function (r) { - $.each(r.graph1Data, function(index, originalObject) { - var label = (('YEAR' in originalObject) ? originalObject.YEAR : "") ; - label += (('MONTH' in originalObject) ? "/" + originalObject.MONTH : "") ; - label += (('QUARTER' in originalObject) ? "/" + originalObject.QUARTER : ""); - label += (('SEMESTER' in originalObject) ? "/" + originalObject.SEMESTER : ""); - originalObject.datalabel = label; - }); - - $.each(r.graph2Data, function(index, originalObject) { - var label = (('YEAR' in originalObject) ? originalObject.YEAR : "") ; - label += (('MONTH' in originalObject) ? "/" + originalObject.MONTH : "") ; - label += (('QUARTER' in originalObject) ? "/" + originalObject.QUARTER : ""); - label += (('SEMESTER' in originalObject) ? "/" + originalObject.SEMESTER : "") ; - originalObject.datalabel = label; - }); - callBack(r); - }); - - - - /*var retval = { - "index" : "23", - "graph1Data": [ - {"value":"96", "datalabel":"User 1"}, - {"value":"84", "datalabel":"User 2"}, - {"value":"72", "datalabel":"User 3"}, - {"value":"18", "datalabel":"User 4"}, - {"value":"85", "datalabel":"User 5"} - ], - "graph2Data": [ - {"value":"196", "datalabel":"User 1"}, - {"value":"184", "datalabel":"User 2"}, - {"value":"172", "datalabel":"User 3"}, - {"value":"118", "datalabel":"User 4"}, - {"value":"185", "datalabel":"User 5"} - ] - } - return retval;*/ -} - -DashboardProxy.prototype.userTasksData = function(processId, monthCompare, yearCompare) { - var retval = { - "tasksDataToDraw": [ - {"value":"96", "datalabel":"Task 1"}, - {"value":"84", "datalabel":"Task 2"}, - {"value":"72", "datalabel":"Task 3"}, - {"value":"18", "datalabel":"Task 4"}, - {"value":"85", "datalabel":"Task 5"} - ], - - "tasksData": [ - {"Name": "Task 1", "efficiencyIndex":"0.45", "deviationTime":"0.45", "averageTime":"34 days"}, - {"Name": "Task 2", "efficiencyIndex":"1.45", "deviationTime":"1.45", "averageTime":"14 days"}, - {"Name": "Task 3", "efficiencyIndex":"0.25", "deviationTime":"0.25", "averageTime":"3 days"}, - {"Name": "Task 4", "efficiencyIndex":"1.95", "deviationTime":"1.95", "averageTime":"4 days"}, - {"Name": "Task 5", "efficiencyIndex":"1.25", "deviationTime":"1.25", "averageTime":"14 days"}, - {"Name": "Task 6", "efficiencyIndex":"0.75", "deviationTime":"0.75", "averageTime":"4 days"} - ] - - } - return retval; -} - -DashboardProxy.prototype.getPositionIndicator = function(callBack) { - this.getJson('dashboard/config', function (r) { - var graphData = []; - $.each(r, function(index, originalObject) { - var map = { - "widgetId" : originalObject.widgetId, - "x" : originalObject.x, - "y" : originalObject.y, - "width" : originalObject.width, - "height" : originalObject.height - - }; - graphData.push(map); - }); - callBack(graphData); - }); -}; - -DashboardProxy.prototype.setPositionIndicator = function(data, callBack) { - var that = this; - - this.getPositionIndicator( - function(response){ - if (response.length != 0) { - that.putJson('dashboard/config', data, function (r) { - }); - } else { - that.postJson('dashboard/config', data, function (r) { - }); - } - } - ); -}; - - - -DashboardProxy.prototype.getJson = function (endPoint, callBack) { - var that = this; - var callUrl = this.baseUrl + endPoint - //For Debug: console.log('Llamando:'); - //For Debug: console.log(callUrl) - $.ajax({ - url: callUrl, - type: 'GET', - datatype: 'json', - success: function(response) { callBack(response); }, - error: function(jqXHR, textStatus, errorThrown) { - throw new Error(textStatus); - }, - beforeSend: function (xhr) { - xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken); - xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); - } - - }); -} - -DashboardProxy.prototype.postJson = function (endPoint, data, callBack) { - var that = this; - $.ajax({ - url : this.baseUrl + endPoint, - type : 'POST', - datatype : 'json', - contentType: "application/json; charset=utf-8", - data: JSON.stringify(data), - success: function(response) { - callBack(response); - }, - error: function(jqXHR, textStatus, errorThrown) { - throw new Error(textStatus); - }, - beforeSend: function (xhr) { - xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken); - xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); - } - }).fail(function () { - throw new Error('Fail server'); - }); -}; - - -DashboardProxy.prototype.putJson = function (endPoint, data, callBack) { - var that = this; - $.ajax({ - url : this.baseUrl + endPoint, - type : 'PUT', - datatype : 'json', - contentType: "application/json; charset=utf-8", - data: JSON.stringify(data), - success: function(response) { - callBack(response); - }, - error: function(jqXHR, textStatus, errorThrown) { - throw new Error(textStatus); - }, - beforeSend: function (xhr) { - xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken); - xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); - } - }).fail(function () { - throw new Error('Fail server'); - }); -}; diff --git a/workflow/engine/js/strategicDashboard/viewDashboardHelper.js b/workflow/engine/js/strategicDashboard/viewDashboardHelper.js new file mode 100644 index 000000000..82781ab9b --- /dev/null +++ b/workflow/engine/js/strategicDashboard/viewDashboardHelper.js @@ -0,0 +1,180 @@ + + +var ViewDashboardHelper = function () { +}; + +ViewDashboardHelper.prototype.userDashboards = function(userId, callBack) { +}; + +ViewDashboardHelper.prototype.stringIfNull = function (val){ + if(val === null || val == undefined || val == "?"){ + val = "?"; + } else { + val = (parseFloat(val)).toFixed(2); + } + return val; +}; + +ViewDashboardHelper.prototype.assert = function (condition, message) { + if (!condition) { + message = message || "Assertion failed"; + if (typeof Error !== "undefined") { + throw new Error(message); + } + throw message; // Fallback + } +} + +ViewDashboardHelper.prototype.truncateString = function (string, len) { + this.assert(len != null && len > 0, "Var len not valid. String must by truncated to a positive non zero length."); + this.assert(string != null, "var string can't be null."); + + var retval = ""; + if(string.length > len){ + retval = string.substring(0, len ) + "..."; + } + else{ + retval = string; + } + return retval; +} + +ViewDashboardHelper.prototype.getKeyValue = function (obj, key, undefined) { + var reg = /\./gi + , subKey + , keys + , context + , x + ; + + if (reg.test(key)) { + keys = key.split(reg); + context = obj; + + for (x = 0; x < keys.length; x++) { + subKey = keys[x]; + + //the values of all keys except for + //the last one should be objects + if (x < keys.length -1) { + if (!context.hasOwnProperty(subKey)) { + return undefined; + } + + context = context[subKey]; + } + else { + return context[subKey]; + } + } + } + else { + return obj[key]; + } +}; + +ViewDashboardHelper.prototype.setKeyValue = function (obj, key, value) { + var reg = /\./gi + , subKey + , keys + , context + , x + ; + + //check to see if we need to process + //multiple levels of objects + if (reg.test(key)) { + keys = key.split(reg); + context = obj; + + for (x = 0; x < keys.length; x++) { + subKey = keys[x]; + + //the values of all keys except for + //the last one should be objects + if (x < keys.length -1) { + if (!context[subKey]) { + context[subKey] = {}; + } + + context = context[subKey]; + } + else { + context[subKey] = value; + } + } + } + else { + obj[key] = value; + } +}; + +ViewDashboardHelper.prototype.merge = function (objFrom, objTo, propMap) { + var toKey + , fromKey + , x + , value + , def + , transform + , key + , keyIsArray + ; + + if (!objTo) { + objTo = {}; + } + + for(fromKey in propMap) { + if (propMap.hasOwnProperty(fromKey)) { + toKey = propMap[fromKey]; + + //force toKey to an array of toKeys + if (!Array.isArray(toKey)) { + toKey = [toKey]; + } + + for(x = 0; x < toKey.length; x++) { + def = null; + transform = null; + key = toKey[x]; + keyIsArray = Array.isArray(key); + + if (typeof(key) === "object" && !keyIsArray) { + def = key.default || null; + transform = key.transform || null; + key = key.key; + //evaluate if the new key is an array + keyIsArray = Array.isArray(key); + } + + if (keyIsArray) { + //key[toKeyName,transform,default] + def = key[2] || null; + transform = key[1] || null; + key = key[0]; + } + + if (def && typeof(def) === "function" ) { + def = def(objFrom, objTo); + } + + value = this.getKeyValue(objFrom, fromKey); + + if (transform) { + value = transform(value, objFrom, objTo); + } + + if (typeof value !== 'undefined') { + this.setKeyValue(objTo, key, value); + } + else if (typeof def !== 'undefined') { + this.setKeyValue(objTo, key, def); + } + } + } + } + + return objTo; +}; + + diff --git a/workflow/engine/js/strategicDashboard/viewDashboardModel.js b/workflow/engine/js/strategicDashboard/viewDashboardModel.js new file mode 100644 index 000000000..c2b63eca1 --- /dev/null +++ b/workflow/engine/js/strategicDashboard/viewDashboardModel.js @@ -0,0 +1,194 @@ +var ViewDashboardModel = function (oauthToken, server, workspace) { + this.server = server; + this.workspace = workspace; + this.baseUrl = "/api/1.0/" + workspace + "/"; + //this.baseUrl = "http://127.0.0.1:8080/api/1.0/workflow/"; + this.oauthToken = oauthToken; + this.helper = new ViewDashboardHelper(); + this.cache = []; + this.forceRemote=false; //if true, the next call will go to the remote server +}; + +ViewDashboardModel.prototype.userDashboards = function(userId) { + return this.getJson('dashboard/ownerData/' + userId); +}; + +ViewDashboardModel.prototype.dashboardIndicators = function(dashboardId, initDate, endDate) { + return this.getJson('dashboard/' + dashboardId + '/indicator?dateIni=' + initDate + '&dateFin=' + endDate); +}; + +ViewDashboardModel.prototype.peiData = function(indicatorId, compareDate, measureDate) { + var endPoint = "ReportingIndicators/process-efficiency-data?" + + "indicator_uid=" + indicatorId + + "&compare_date=" + compareDate + + "&measure_date=" + measureDate + + "&language=en"; + return this.getJson(endPoint); +} + +ViewDashboardModel.prototype.statusData = function() { + var endPoint = "ReportingIndicators/status-indicator"; + return this.getJson(endPoint); +} + +ViewDashboardModel.prototype.peiDetailData = function(process, initDate, endDate) { + var endPoint = "ReportingIndicators/process-tasks?" + + "process_list=" + process + + "&init_date=" + initDate + + "&end_date=" + endDate + + "&language=en"; + return this.getJson(endPoint); +} + +ViewDashboardModel.prototype.ueiData = function(indicatorId, compareDate, measureDate ) { + var endPoint = "ReportingIndicators/employee-efficiency-data?" + + "indicator_uid=" + indicatorId + + "&compare_date=" + compareDate + + "&measure_date=" + measureDate + + "&language=en"; + return this.getJson(endPoint); +} + +ViewDashboardModel.prototype.ueiDetailData = function(groupId, initDate, endDate) { + var endPoint = "ReportingIndicators/group-employee-data?" + + "group_uid=" + groupId + + "&init_date=" + initDate + + "&end_date=" + endDate + + "&language=en"; + return this.getJson(endPoint); +} + +ViewDashboardModel.prototype.generalIndicatorData = function(indicatorId, initDate, endDate) { + var method = ""; + var endPoint = "ReportingIndicators/general-indicator-data?" + + "indicator_uid=" + indicatorId + + "&init_date=" + initDate + + "&end_date=" + endDate + + "&language=en"; + return this.getJson(endPoint); +} + +ViewDashboardModel.prototype.getPositionIndicator = function(callBack) { + this.getJson('dashboard/config').done(function (r) { + var graphData = []; + $.each(r, function(index, originalObject) { + var map = { + "widgetId" : originalObject.widgetId, + "x" : originalObject.x, + "y" : originalObject.y, + "width" : originalObject.width, + "height" : originalObject.height + + }; + graphData.push(map); + }); + callBack(graphData); + }); +}; + +ViewDashboardModel.prototype.setPositionIndicator = function(data) { + var that = this; + + this.getPositionIndicator( + function(response){ + if (response.length != 0) { + that.putJson('dashboard/config', data); + } else { + that.postJson('dashboard/config', data); + } + } + ); +}; + +ViewDashboardModel.prototype.getJson = function (endPoint) { + var that = this; + var callUrl = this.baseUrl + endPoint + var requestFinished = $.Deferred(); + var itemInCache = that.getCacheItem(endPoint); + + if (itemInCache != null && !this.forceRemote) { + that.forceRemote = false; + requestFinished.resolve(itemInCache); + return requestFinished.promise(); + } + else { + return $.ajax({ + url: callUrl, + type: 'GET', + datatype: 'json', + success: function (data) { + that.forceRemote = false; + requestFinished.resolve(data); + that.putInCache(endPoint, data); + // return requestFinished.promise(); + }, + error: function(jqXHR, textStatus, errorThrown) { + throw new Error(callUrl + ' -- ' + errorThrown); + }, + beforeSend: function (xhr) { + xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken); + //xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); + } + }); + } +} + +ViewDashboardModel.prototype.postJson = function (endPoint, data) { + var that = this; + return $.ajax({ + url : this.baseUrl + endPoint, + type : 'POST', + datatype : 'json', + contentType: "application/json; charset=utf-8", + data: JSON.stringify(data), + error: function(jqXHR, textStatus, errorThrown) { + throw new Error(errorThrown); + }, + beforeSend: function (xhr) { + xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken); + xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); + } + }).fail(function () { + throw new Error('Fail server'); + }); +}; + +ViewDashboardModel.prototype.putJson = function (endPoint, data) { + var that = this; + return $.ajax({ + url : this.baseUrl + endPoint, + type : 'PUT', + datatype : 'json', + contentType: "application/json; charset=utf-8", + data: JSON.stringify(data), + error: function(jqXHR, textStatus, errorThrown) { + throw new Error(errorThrown); + }, + beforeSend: function (xhr) { + xhr.setRequestHeader('Authorization', 'Bearer ' + that.oauthToken); + //xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); + } + }).fail(function () { + throw new Error('Fail server'); + }); +}; + +ViewDashboardModel.prototype.getCacheItem = function (endPoint) { + var retval = null; + $.each(this.cache, function(index, objectItem) { + if (objectItem.key == endPoint) { + retval = objectItem.value; + } + }); + return retval; +} + +ViewDashboardModel.prototype.putInCache = function (endPoint, data) { + var cacheItem = this.getCacheItem(endPoint); + if (cacheItem == null) { + this.cache.push ({ key: endPoint, value:data }); + } + else { + cacheItem.value = data; + } +} diff --git a/workflow/engine/js/strategicDashboard/viewDashboardPresenter.js b/workflow/engine/js/strategicDashboard/viewDashboardPresenter.js new file mode 100644 index 000000000..703e3780e --- /dev/null +++ b/workflow/engine/js/strategicDashboard/viewDashboardPresenter.js @@ -0,0 +1,381 @@ + + +var ViewDashboardPresenter = function (model) { + this.helper = new ViewDashboardHelper(); + this.helper.assert(model != null, "A model must be passed for the presenter work.") + this.model = model; +}; + +ViewDashboardPresenter.prototype.getUserDashboards = function (userId) { + var that = this; + var requestFinished = $.Deferred(); + that.model.userDashboards(userId) + .done(function(modelData){ + var viewModel = that.userDashboardsViewModel(modelData) + requestFinished.resolve(viewModel); + }); + return requestFinished.promise(); +}; + +ViewDashboardPresenter.prototype.userDashboardsViewModel = function(data) { + var that = this; + //if null data is returned we default to an empty array + if (data == null) { data = []; } + var returnList = []; + $.each(data, function(index, originalObject) { + var map = { + "DAS_TITLE" : "title", + "DAS_UID" : "id", + "DAS_FAVORITE" : "isFavorite" + }; + var newObject = that.helper.merge(originalObject, {}, map); + returnList.push(newObject); + }); + return returnList; +}; + +ViewDashboardPresenter.prototype.getDashboardIndicators = function (dashboardId,initDate, endDate) { + if (dashboardId == null) {throw new Error ("getDashboardIndicators -> dashboardId can't be null");}; + var that = this; + var requestFinished = $.Deferred(); + this.model.dashboardIndicators (dashboardId, initDate, endDate) + .done(function (modelData) { + var viewModel = that.dashboardIndicatorsViewModel(modelData) + requestFinished.resolve(viewModel); + }); + return requestFinished.promise(); +}; + +ViewDashboardPresenter.prototype.dashboardIndicatorsViewModel = function(data) { + var that = this; + var returnList = []; + var i = 1; + $.each(data, function(index, originalObject) { + var map = { + "DAS_IND_UID" : "id", + "DAS_IND_TITLE" : "title", + "DAS_IND_TYPE" : "type", + "DAS_IND_VARIATION" : "comparative", + "DAS_IND_DIRECTION" : "direction", + "DAS_IND_VALUE" : "value", + "DAS_IND_X" : "x", + "DAS_IND_Y" : "y", + "DAS_IND_WIDTH" : "width", + "DAS_IND_HEIGHT" : "height", + "DAS_UID_PROCESS" : "process", + "PERCENTAGE_OVERDUE" : "percentageOverdue", + "PERCENTAGE_AT_RISK" : "percentageAtRisk", + "PERCENTAGE_ON_TIME" : "percentageOnTime" + }; + + var newObject = that.helper.merge(originalObject, {}, map); + newObject.toDrawX = newObject.x; + //newObject.toDrawX = (newObject.x == 0) ? 12 - 12/i : newObject.x; + + newObject.toDrawY = (newObject.y == 0) ? 6 : newObject.y; + newObject.toDrawHeight = (newObject.y == 0) ? 2 : newObject.height; + newObject.toDrawWidth = (newObject.y == 0) ? 12 / data.length : newObject.width; + newObject.comparative = ((newObject.comparative > 0)? "+": "") + that.helper.stringIfNull(newObject.comparative); + newObject.directionSymbol = (newObject.direction == "1") ? "<" : ">"; + newObject.isWellDone = (newObject.direction == "1") + ? parseFloat(newObject.value) <= parseFloat(newObject.comparative) + : parseFloat(newObject.value) >= parseFloat(newObject.comparative); + + newObject.category = (newObject.type == "1010" || newObject.type == "1030") + ? "special" + : "normal"; + + //round goals for normal indicators + newObject.comparative = (newObject.category == "normal") + ? Math.round(newObject.comparative) + "" + : newObject.comparative; + + newObject.value = (newObject.category == "normal") + ? Math.round(newObject.value) + "" + : Math.round(newObject.value*100)/100 + "" + + newObject.favorite = 0; + newObject.percentageOverdue = Math.round(newObject.percentageOverdue); + newObject.percentageAtRisk = Math.round(newObject.percentageAtRisk); + //to be sure that percentages sum up to 100 (the rounding will lost decimals)% + newObject.percentageOnTime = 100 - newObject.percentageOverdue - newObject.percentageAtRisk; + newObject.overdueVisibility = (newObject.percentageOverdue > 0)? "visible" : "hidden"; + newObject.atRiskVisiblity = (newObject.percentageAtRisk > 0)? "visible" : "hidden"; + newObject.onTimeVisibility = (newObject.percentageOnTime > 0)? "visible" : "hidden"; + returnList.push(newObject); + i++; + }); + + //sort the array for drawing in toDrawX order + returnList.sort(function (a, b) { + return ((a.toDrawX <= b.toDrawX) ? -1 : 1); + }); + if (returnList.length > 0) { + returnList[0].favorite = 1; + } + return returnList; +}; + +/*++++++++ FIRST LEVEL INDICATOR DATA +++++++++++++*/ +ViewDashboardPresenter.prototype.getIndicatorData = function (indicatorId, indicatorType, initDate, endDate) { + var that = this; + var requestFinished = $.Deferred(); + switch (indicatorType) { + case "1010": + this.model.peiData(indicatorId, initDate, endDate) + .done(function(modelData) { + var viewModel = that.peiViewModel(modelData) + requestFinished.resolve(viewModel); + }); + break; + case "1030": + this.model.ueiData(indicatorId, initDate, endDate) + .done(function(modelData) { + var viewModel = that.ueiViewModel(modelData) + requestFinished.resolve(viewModel); + }); + break; + case "1050": + this.model.statusData(indicatorId) + .done(function(modelData) { + var viewModel = that.statusViewModel(indicatorId, modelData) + requestFinished.resolve(viewModel); + }); + break; + default: + this.model.generalIndicatorData(indicatorId, initDate, endDate) + .done(function(modelData) { + var viewModel = that.indicatorViewModel(modelData) + requestFinished.resolve(viewModel); + }); + break; + } + return requestFinished.promise(); +}; + +ViewDashboardPresenter.prototype.peiViewModel = function(data) { + var that = this; + var graphData = []; + $.each(data.data, function(index, originalObject) { + var map = { + "name" : "datalabel", + "inefficiencyCost" : "value" + }; + var newObject = that.helper.merge(originalObject, {}, map); + var shortLabel = (newObject.datalabel == null) + ? "" + : newObject.datalabel.substring(0,15); + + newObject.datalabel = shortLabel; + graphData.push(newObject); + originalObject.inefficiencyCostToShow = "$ " + Math.round(originalObject.inefficiencyCost); + originalObject.efficiencyIndexToShow = Math.round(originalObject.efficiencyIndex * 100) / 100; + originalObject.indicatorId = data.id; + originalObject.json = JSON.stringify(originalObject); + }); + + var retval = {}; + retval = data; + graphData.sort(function(a,b) { + var retval = 0; + retval = ((a.value*1.0 <= b.value*1.0) ? 1 : -1); + return retval; + }) + retval.dataToDraw = graphData.splice(0,7); + //TODO aumentar el símbolo de moneda $ + retval.inefficiencyCostToShow = "$ " +Math.round(retval.inefficiencyCost); + retval.efficiencyIndexToShow = Math.round(retval.efficiencyIndex * 100) / 100; + return retval; +}; + +ViewDashboardPresenter.prototype.ueiViewModel = function(data) { + var that = this; + var graphData = []; + $.each(data.data, function(index, originalObject) { + var map = { + "name" : "datalabel", + "inefficiencyCost" : "value", + "deviationTime" : "dispersion" + }; + var newObject = that.helper.merge(originalObject, {}, map); + var shortLabel = (newObject.datalabel == null) + ? "" + : newObject.datalabel.substring(0,7); + + newObject.datalabel = shortLabel; + graphData.push(newObject); + originalObject.inefficiencyCostToShow = "$ " + Math.round(originalObject.inefficiencyCost); + originalObject.efficiencyIndexToShow = Math.round(originalObject.efficiencyIndex * 100) / 100; + originalObject.indicatorId = data.id; + originalObject.json = JSON.stringify(originalObject); + }); + + var retval = {}; + retval = data; + graphData.sort(function(a,b) { + var retval = 0; + retval = ((a.value*1.0 <= b.value*1.0) ? 1 : -1); + return retval; + }) + retval.dataToDraw = graphData.splice(0,7); + //TODO aumentar el símbolo de moneda $ + retval.inefficiencyCostToShow = "$ " + Math.round(retval.inefficiencyCost); + retval.efficiencyIndexToShow = Math.round(retval.efficiencyIndex * 100) / 100; + return retval; +}; + +ViewDashboardPresenter.prototype.statusViewModel = function(indicatorId, data) { + var that = this; + data.id = indicatorId; + var graph1Data = []; + var graph2Data = []; + var graph3Data = []; + $.each(data.dataList, function(index, originalObject) { + var title = (originalObject.taskTitle == null) + ? "" + : originalObject.taskTitle.substring(0,15); + var newObject1 = { + datalabel : title, + value : originalObject.percentageTotalOverdue + }; + var newObject2 = { + datalabel : title, + value : originalObject.percentageTotalAtRisk + }; + var newObject3 = { + datalabel : title, + value : originalObject.percentageTotalOnTime + }; + + graph1Data.push(newObject1); + graph2Data.push(newObject2); + graph3Data.push(newObject3); + //we add the indicator id for reference + originalObject.indicatorId = indicatorId; + }); + + var retval = data; + //TODO selecte de 7 worst cases no the first 7 + retval.graph1Data = graph1Data.splice(0,7) + retval.graph2Data = graph2Data.splice(0,7) + retval.graph3Data = graph3Data.splice(0,7) + + return retval; +}; + +ViewDashboardPresenter.prototype.indicatorViewModel = function(data) { + var that = this; + $.each(data.graph1Data, function(index, originalObject) { + var label = (('YEAR' in originalObject) ? originalObject.YEAR : "") ; + label += (('MONTH' in originalObject) ? "/" + originalObject.MONTH : "") ; + label += (('QUARTER' in originalObject) ? "/" + originalObject.QUARTER : ""); + label += (('SEMESTER' in originalObject) ? "/" + originalObject.SEMESTER : ""); + originalObject.datalabel = label; + }); + + $.each(data.graph2Data, function(index, originalObject) { + var label = (('YEAR' in originalObject) ? originalObject.YEAR : "") ; + label += (('MONTH' in originalObject) ? "/" + originalObject.MONTH : "") ; + label += (('QUARTER' in originalObject) ? "/" + originalObject.QUARTER : ""); + label += (('SEMESTER' in originalObject) ? "/" + originalObject.SEMESTER : "") ; + originalObject.datalabel = label; + }); + return data; +}; +/*-------FIRST LEVEL INDICATOR DATA */ + +/*++++++++ SECOND LEVEL INDICATOR DATA +++++++++++++*/ +ViewDashboardPresenter.prototype.getSpecialIndicatorSecondLevel = function (entityId, indicatorType, initDate, endDate) { + var that = this; + var requestFinished = $.Deferred(); + //if modelData is passed (because it was cached on the view) no call is made to the server. + //and just a order is applied to the list + + switch (indicatorType) { + case "1010": + this.model.peiDetailData(entityId, initDate, endDate) + .done(function (modelData) { + var viewModel = that.returnIndicatorSecondLevelPei(modelData); + requestFinished.resolve(viewModel); + }); + break; + case "1030": + this.model.ueiDetailData(entityId, initDate, endDate) + .done(function (modelData) { + var viewModel = that.returnIndicatorSecondLevelUei(modelData); + requestFinished.resolve(viewModel); + }); + break; + default: + throw new Error("Indicator type " + indicatorType + " has not detail data implemented of special indicator kind."); + } + return requestFinished.promise(); +}; + +ViewDashboardPresenter.prototype.returnIndicatorSecondLevelPei = function(modelData) { + //modelData arrives in format [{users/tasks}] + //returns object {dataToDraw[], entityData[] //user/tasks data} + var that = this; + var graphData = []; + + $.each(modelData, function(index, originalObject) { + var map = { + "name" : "datalabel", + "averageTime" : "value", + "deviationTime" : "dispersion" + }; + var newObject = that.helper.merge(originalObject, {}, map); + newObject.datalabel = ((newObject.datalabel == null) ? "" : newObject.datalabel.substring(0, 7)); + originalObject.inefficiencyCostToShow = "$ " + Math.round(originalObject.inefficiencyCost); + originalObject.efficiencyIndexToShow = Math.round(originalObject.efficiencyIndex * 100) / 100; + graphData.push(newObject); + }); + var retval = {}; + retval.dataToDraw = graphData.splice(0,7); + retval.entityData = modelData; + return retval; +}; + +ViewDashboardPresenter.prototype.returnIndicatorSecondLevelUei = function(modelData) { + //modelData arrives in format [{users/tasks}] + //returns object {dataToDraw[], entityData[] //user/tasks data} + var that = this; + var graphData = []; + + $.each(modelData, function(index, originalObject) { + var map = { + "name" : "datalabel", + "averageTime" : "value", + "deviationTime" : "dispersion" + }; + var newObject = that.helper.merge(originalObject, {}, map); + newObject.datalabel = ((newObject.datalabel == null) ? "" : newObject.datalabel.substring(0, 7)); + originalObject.inefficiencyCostToShow = "$ " +Math.round(originalObject.inefficiencyCost); + originalObject.efficiencyIndexToShow = Math.round(originalObject.efficiencyIndex * 100) / 100; + graphData.push(newObject); + }); + var retval = {}; + retval.dataToDraw = graphData.splice(0,7); + retval.entityData = modelData; + return retval; +}; +/*-------SECOND LEVEL INDICATOR DATA*/ + +ViewDashboardPresenter.prototype.orderDataList = function(listData, orderDirection, orderFunction) { + //orderDirection is passed in case no order FUnction is passed (to use in the default ordering) + var orderToUse = orderFunction; + if (orderFunction == undefined) { + orderToUse = function (a ,b) { + var retval = 0; + if (orderDirection == "down") { + retval = ((a.inefficiencyCost*1.0 <= b.inefficiencyCost*1.0) ? 1 : -1); + } + else { + //the 1,-1 are flipped + retval = ((a.inefficiencyCost*1.0 <= b.inefficiencyCost*1.0) ? -1 : 1); + } + return retval; + } + } + return listData.sort(orderToUse); +} diff --git a/workflow/engine/js/strategicDashboard/viewDashboardView.js b/workflow/engine/js/strategicDashboard/viewDashboardView.js new file mode 100644 index 000000000..a7ced8a77 --- /dev/null +++ b/workflow/engine/js/strategicDashboard/viewDashboardView.js @@ -0,0 +1,904 @@ +/**************************************************************/ +var WidgetBuilder = function () { + this.helper = new ViewDashboardHelper(); +} + +WidgetBuilder.prototype.getIndicatorWidget = function (indicator) { + var retval = null; + switch(indicator.type) { + case "1010": retval = this.buildSpecialIndicatorButton(indicator); break; + case "1030": retval = this.buildSpecialIndicatorButton(indicator); break; + case "1050": retval = this.buildStatusIndicatorButton(indicator); break; + case "1020": + case "1040": + case "1060": + case "1070": + case "1080": + retval = this.buildIndicatorButton(indicator); break; + } + if(retval == null) {throw new Error(indicator.type + " has not associated a widget.");} + return retval; +}; + +WidgetBuilder.prototype.buildSpecialIndicatorButton = function (indicator) { + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.specialIndicatorButtonTemplate").html()); + var $retval = $(template(indicator)); + + if(indicator.comparative < 0){ + $retval.find(".ind-container-selector").removeClass("panel-green").addClass("panel-red"); + $retval.find(".ind-symbol-selector").removeClass("fa-chevron-up").addClass("fa-chevron-down"); + } + + if(indicator.comparative > 0){ + $retval.find(".ind-container-selector").removeClass("panel-red").addClass("panel-green"); + $retval.find(".ind-symbol-selector").removeClass("fa-chevron-down").addClass("fa-chevron-up"); + } + + if(indicator.comparative == 0){ + $retval.find(".ind-symbol-selector").removeClass("fa-chevron-up"); + $retval.find(".ind-symbol-selector").removeClass("fa-chevron-down"); + $retval.find(".ind-symbol-selector").addClass("fa-circle-o"); + $retval.find(".ind-container-selector").removeClass("panel-red").addClass("panel-green"); + } + return $retval; +} + +WidgetBuilder.prototype.buildStatusIndicatorButton = function (indicator) { + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.statusIndicatorButtonTemplate").html()); + var $retval = $(template(indicator)); + return $retval; +} + +WidgetBuilder.prototype.buildIndicatorButton = function (indicator) { + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.statusIndicatorButtonTemplate").html()); + var $retval = $(template(indicator)); + var $comparative = $retval.find('.ind-comparative-selector'); + var $title = $retval.find('.ind-title-selector'); + if (indicator.isWellDone) { + $comparative.text("(" + indicator.directionSymbol + " " + indicator.comparative + "%)-"+ G_STRING.ID_WELL_DONE); + $retval.find(".ind-container-selector").removeClass("panel-low").addClass("panel-high"); + } + else { + $comparative.text("Goal: " + indicator.directionSymbol + " " + indicator.comparative + "%"); + $retval.find(".ind-container-selector").removeClass("panel-high").addClass("panel-low"); + } + return $retval; +} + +WidgetBuilder.prototype.buildSpecialIndicatorFirstView = function (indicatorData) { + if (indicatorData == null) { throw new Error ("indicatorData is null."); } + if (!indicatorData.hasOwnProperty("id")) { throw new Error ("indicatorData has no id."); } + + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.specialIndicatorMainPanel").html()); + var $retval = $(template(indicatorData)); + var indicatorPrincipalData = this.getIndicatorLoadedById(indicatorData.id) + $retval.find('.breadcrumb').find('li').remove() + $retval.find('.breadcrumb').append ('
  • '+indicatorPrincipalData.title+'
  • ') + $retval.find(".sind-index-selector").text(G_STRING.ID_EFFICIENCY_INDEX); + $retval.find(".sind-cost-selector").text(G_STRING.ID_INEFFICIENCY_COST); + this.setColorForInefficiency($retval.find(".sind-cost-number-selector"), indicatorData); + return $retval; +} + +WidgetBuilder.prototype.buildSpecialIndicatorFirstViewDetail = function (oneItemDetail) { + //detailData = {indicatorId, uid, name, averateTime...} + if (oneItemDetail == null){throw new Error("oneItemDetail is null ");} + if (!typeof(oneItemDetail) === 'object'){throw new Error( "detailData is not and object ->" + oneItemDetail);} + if (!oneItemDetail.hasOwnProperty("name")){throw new Error("buildSpecialIndicatorFirstViewDetail -> detailData has not the name param. Has it the correct Type? ->" + oneItemDetail);} + + _.templateSettings.variable = "detailData"; + var template = _.template ($("script.specialIndicatorDetail").html()); + var $retval = $(template(oneItemDetail)); + $retval.find(".detail-efficiency-selector").text(G_STRING.ID_EFFICIENCY_INDEX); + $retval.find(".detail-cost-selector").text(G_STRING.ID_INEFFICIENCY_COST); + this.setColorForInefficiency($retval.find(".detail-cost-number-selector"), oneItemDetail); + return $retval; +} + +WidgetBuilder.prototype.buildStatusIndicatorFirstView = function (indicatorData) { + if (indicatorData == null) { throw new Error ("indicatorData is null."); } + if (!indicatorData.hasOwnProperty("id")) { throw new Error ("indicatorData has no id."); } + + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.statusIndicatorMainPanel").html()); + var $retval = $(template(indicatorData)); + var indicatorPrincipalData = this.getIndicatorLoadedById(indicatorData.id) + $retval.find('.breadcrumb').find('li').remove() + $retval.find('.breadcrumb').append ('
  • '+indicatorPrincipalData.title+'
  • ') + return $retval; +} + +WidgetBuilder.prototype.buildStatusIndicatorFirstViewDetail = function (oneItemDetail) { + //detailData = {indicatorId, uid, name, averateTime...} + if (oneItemDetail == null){throw new Error("oneItemDetail is null ");} + if (!typeof(oneItemDetail) === 'object'){throw new Error( "detailData is not and object ->" + oneItemDetail);} + if (!oneItemDetail.hasOwnProperty("taskTitle")){throw new Error("detailData has not the name param. Has it the correct Type? ->" + oneItemDetail);} + + _.templateSettings.variable = "detailData"; + var template = _.template ($("script.statusDetail").html()); + var $retval = $(template(oneItemDetail)); + return $retval; +} + +WidgetBuilder.prototype.buildSpecialIndicatorSecondView = function (secondViewData) { + //presenterData= object {dataToDraw[], entityData[] //user/tasks data} + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.specialIndicatorMainPanel").html()); + var $retval = $(template(window.currentEntityData)); + //var indicatorPrincipalData = this.getIndicatorLoadedById(indicatorId); + //$retval.find(".sind-title-selector").text(indicatorPrincipalData.title); + $retval.find(".sind-index-selector").text(G_STRING.ID_EFFICIENCY_INDEX); + $retval.find(".sind-cost-selector").text(G_STRING.ID_INEFFICIENCY_COST); + + + $retval.find('.breadcrumb').find('li').remove(); + $retval.find('.breadcrumb').append ('
  • ' + window.currentIndicator.title + '
  • '); + $retval.find('.breadcrumb').append ('
  • ' + window.currentEntityData.name + '
  • '); + this.setColorForInefficiency($retval.find(".sind-cost-number-selector"), window.currentEntityData); + return $retval; +}; + +WidgetBuilder.prototype.buildSpecialIndicatorSecondViewDetail = function (oneItemDetail) { + if (oneItemDetail == null){throw new Error("oneItemDetail is null ");} + if (!typeof(oneItemDetail) === 'object'){throw new Error( "detailData is not and object ->" + oneItemDetail);} + if (!oneItemDetail.hasOwnProperty("name")){throw new Error("buildSpecialIndicatorFirstViewDetail -> detailData has not the name param. Has it the correct Type? ->" + oneItemDetail);} + + _.templateSettings.variable = "detailData"; + var template = _.template ($("script.specialIndicatorSencondViewDetail").html()); + var $retval = $(template(oneItemDetail)); + $retval.find(".detail-efficiency-selector").text(G_STRING.ID_EFFICIENCY_INDEX); + $retval.find(".detail-cost-selector").text(G_STRING.ID_INEFFICIENCY_COST); + this.setColorForInefficiency($retval.find(".detail-cost-number-selector"), oneItemDetail); + return $retval; +} + +WidgetBuilder.prototype.getIndicatorLoadedById = function (searchedIndicatorId) { + var retval = null; + for (key in window.loadedIndicators) { + var indicator = window.loadedIndicators[key]; + if (indicator.id == searchedIndicatorId) { + retval = indicator; + } + } + if (retval == null) { throw new Error(searchedIndicatorId + " was not found in the loaded indicators.");} + return retval; +} + +WidgetBuilder.prototype.buildGeneralIndicatorFirstView = function (indicatorData) { + _.templateSettings.variable = "indicator"; + var template = _.template ($("script.generalIndicatorMainPanel").html()); + var $retval = $(template(indicatorData)); + $retval.find(".ind-title-selector").text(window.currentIndicator.title); + return $retval; +} + + +WidgetBuilder.prototype.setColorForInefficiency = function ($widget, indicatorData) { + //turn red/gree the font according if is positive or negative: var $widget = $retval.find(".sind-cost-number-selector"); + $widget.removeClass("red"); + $widget.removeClass("green"); + if (indicatorData.inefficiencyCost >= 0) { + $widget.addClass("green"); + } + else { + $widget.addClass("red"); + } +} + +/**********************************************************************/ +helper = new ViewDashboardHelper(); +var ws = urlProxy.split('/'); +model = new ViewDashboardModel(token, urlProxy, ws[3]); +presenter = new ViewDashboardPresenter(model); + +window.loadedIndicators = []; //updated in das-title-selector.click->fillIndicatorWidgets, ready->fillIndicatorWidgets +window.currentEntityData = null; +window.currentIndicator = null;//updated in ind-button-selector.click ->loadIndicator, ready->loadIndicator +window.currentDashboardId = null; +window.currentDetailFunction = null; +window.currentDetailList = null; + +$(document).ready(function() { + $('#indicatorsGridStack').gridstack(); + $('#indicatorsDataGridStack').gridstack(); + $('#relatedDetailGridStack').gridstack(); + + $('#sortListButton').click(function() { + var btn = $(this); + if (btn.hasClass('fa-chevron-up')) { + btn.removeClass('fa-chevron-up'); + btn.addClass('fa-chevron-down'); + } + else { + btn.removeClass('fa-chevron-down'); + btn.addClass('fa-chevron-up'); + } + + window.currentDetailFunction (presenter.orderDataList ( + window.currentDetailList, + selectedOrderOfDetailList())); + //send scroll +1 and -1 to activate the show/hide event. + //both scrolls are sent cause if the scroll at the end + //scroll +1 has no effect but -1 yes + $(window).scrollTop($(window).scrollTop() + 1); + $(window).scrollTop($(window).scrollTop() - 1); + return false; + }); + + /* Show on scroll functionality */ + $(window).scroll( function() { + /* Check the location of each desired element */ + $('.hideme').each( function(i){ + var bottom_of_object = $(this).offset().top + $(this).outerHeight(); + var bottom_of_window = $(window).scrollTop() + $(window).height(); + /* If the object is completely visible in the window, fade it in */ + if (bottom_of_window + 100 > bottom_of_object) { + $(this).animate({'opacity':'1'}, 500); + $(this).removeClass('hideme'); + } + }); + hideScrollIfAllDivsAreVisible(); + }); + + var isHover = false; + $('#scrollImg').mouseover(function() { + isHover = true; + var interval = window.setInterval(function () { + var newPos = $(window).scrollTop() + 100; + $(window).scrollTop(newPos); + if (isHover == false) { + window.clearInterval(interval); + } + }, 200); + }); + + $('#scrollImg').mouseleave(function() { + isHover = false; + }); + + + //When some item is moved + $('.grid-stack').on('change', function (e, items) { + var widgets = []; + _.map($('.grid-stack .grid-stack-item:visible'), function (el) { + el = $(el); + var item = el.data('_gridstack_node'); + var idWidGet = el.data("indicator-id"); + /*if(favorite == actualDashId){ + favoriteData = 1; + } else { + favoriteData = 0; + }*/ + if (typeof idWidGet != "undefined") { + var widgetsObj = { + 'indicatorId': idWidGet, + 'x': item.x, + 'y': item.y, + 'width': item.width, + 'height': item.height <= 1 ? 2 : item.height + } + widgets.push(widgetsObj); + } + }); + + var favoriteDasbhoardId = $('.das-icon-selector.selected').parent().data('dashboard-id'); + if (favoriteDasbhoardId == null || favoriteDasbhoardId == 'undefined') {throw new Error ('No favorite dashboard detected');} + + if (widgets.length != 0) { + var dashboard = { + 'dashId': window.currentDashboardId, + 'dashFavorite': ((window.currentDashboardId == favoriteDasbhoardId) ? 1 : 0), + 'dashData': widgets + } + model.setPositionIndicator(dashboard); + } + }); + + $('body').on('click', '.das-icon-selector', function() { + var dashboardId = $(this).parent().data('dashboard-id'); + $('.das-icon-selector').removeClass("selected"); + $(this).addClass('selected'); + var dashboard = { + 'dashId': dashboardId, + 'dashFavorite': 1, + 'dashData': '' + } + model.setPositionIndicator(dashboard); + }); + + + /*-------------------------------clicks----------------------------*/ + $('body').on('click','.btn-compare', function() { + presenter.getDashboardIndicators(window.currentDashboardId, defaultInitDate(), defaultEndDate()) + .done(function(indicatorsVM) { + fillIndicatorWidgets(indicatorsVM); + loadIndicator(getFavoriteIndicator().id, defaultInitDate(), defaultEndDate()); + }); + }); + + $('#dashboardsList').on('click','.das-title-selector', function() { + var dashboardId = $(this).parent().data('dashboard-id'); + window.currentDashboardId = dashboardId; + presenter.getDashboardIndicators(dashboardId, defaultInitDate(), defaultEndDate()) + .done(function(indicatorsVM) { + fillIndicatorWidgets(indicatorsVM); + //TODO use real data + loadIndicator(getFavoriteIndicator().id, defaultInitDate(), defaultEndDate()); + }); + }); + + $('#indicatorsGridStack').on('click','.ind-button-selector', function() { + var indicatorId = $(this).data('indicator-id'); + //TODO use real data + loadIndicator(indicatorId, defaultInitDate(), defaultEndDate()); + }); + + $('body').on('click','.bread-back-selector', function() { + var indicatorId = window.currentIndicator.id; + //TODO use real data + loadIndicator(indicatorId, defaultInitDate(), defaultEndDate()); + return false; + }); + + $('#relatedDetailGridStack').on('click','.detail-button-selector', function() { + var detailId = $(this).data('detail-id'); + window.currentEntityData = {"entityId":$(this).data('detail-id'), + "indicatorId":$(this).data('indicator-id'), + "efficiencyIndexToShow":$(this).data('detail-index'), + "inefficiencyCostToShow":$(this).data('detail-cost-to-show'), + "inefficiencyCost":$(this).data('detail-cost'), + "name":$(this).data('detail-name') + }; + //TODO PASS REAL VALUES + presenter.getSpecialIndicatorSecondLevel(detailId, window.currentIndicator.type, defaultInitDate(), defaultEndDate()) + .done(function (viewModel) { + fillSpecialIndicatorSecondView(viewModel); + }); + }); + initialDraw(); +}); + +var hideScrollIfAllDivsAreVisible = function(){ + if ($('.hideme').length <= 0) { + $('#scrollImg').hide(); + } + else { + $('#scrollImg').show(); + } +} + +var selectedOrderOfDetailList = function () { + return ($('#sortListButton').hasClass('fa-chevron-up') ? "up" : "down"); +} + +var initialDraw = function () { + presenter.getUserDashboards(pageUserId) + .then(function(dashboardsVM) { + fillDashboardsList(dashboardsVM); + /**** window initialization with favorite dashboard*****/ + presenter.getDashboardIndicators(window.currentDashboardId, defaultInitDate(), defaultEndDate()) + .done(function(indicatorsVM) { + fillIndicatorWidgets(indicatorsVM); + loadIndicator(getFavoriteIndicator().id, defaultInitDate(), defaultEndDate()); + }); + }); +} + +var loadIndicator = function (indicatorId, initDate, endDate) { + var builder = new WidgetBuilder(); + window.currentIndicator = builder.getIndicatorLoadedById(indicatorId); + presenter.getIndicatorData(indicatorId, window.currentIndicator.type, initDate, endDate) + .done(function (viewModel) { + switch (window.currentIndicator.type) { + case "1010": + case "1030": + fillSpecialIndicatorFirstView(viewModel); + break; + case "1050": + fillStatusIndicatorFirstView(viewModel); + break; + default: + fillGeneralIndicatorFirstView(viewModel); + break; + } + }); +} + +var setIndicatorActiveMarker = function () { + $('.panel-footer').each (function () { + $(this).removeClass('panel-active'); + var indicatorId = $(this).parents('.ind-button-selector').data('indicator-id'); + if (window.currentIndicator.id == indicatorId) { + $(this).addClass('panel-active'); + } + }); +} + +var getFavoriteIndicator = function() { + var retval = (window.loadedIndicators.length > 0) + ? window.loadedIndicators[0] + : null; + for (key in window.loadedIndicators) { + var indicator = window.loadedIndicators[key]; + if (indicator.favorite == 1) { + retval = indicator; + } + } + if (retval==null) {throw new Error ('No favorites found.');} + return retval; +} + +var defaultInitDate = function() { + var date = new Date(); + var dateMonth = date.getMonth(); + var dateYear = date.getFullYear(); + var initDate = $('#year').val() + '-' + $('#month').val() + '-' + '01'; + return initDate; +} + +var defaultEndDate = function () { + var date = new Date(); + var dateMonth = date.getMonth(); + var dateYear = date.getFullYear(); + return dateYear + "-" + (dateMonth + 1) + "-30"; +} + +var fillDashboardsList = function (presenterData) { + if (presenterData == null || presenterData.length == 0) { + $('#dashboardsList').append(G_STRING['ID_NO_DATA_TO_DISPLAY']); + } + _.templateSettings.variable = "dashboard"; + var template = _.template ($("script.dashboardButtonTemplate").html()) + for (key in presenterData) { + var dashboard = presenterData[key]; + $('#dashboardsList').append(template(dashboard)); + if (dashboard.isFavorite == 1) { + window.currentDashboardId = dashboard.id; + $('#dashboardButton-' + dashboard.id) + .find('.das-icon-selector') + .addClass('selected'); + } + } + +}; + +var fillIndicatorWidgets = function (presenterData) { + var widgetBuilder = new WidgetBuilder(); + var grid = $('#indicatorsGridStack').data('gridstack'); + grid.remove_all(); + window.loadedIndicators = presenterData; + $.each(presenterData, function(key, indicator) { + var $widget = widgetBuilder.getIndicatorWidget(indicator); + grid.add_widget($widget, indicator.toDrawX, indicator.toDrawY, indicator.toDrawWidth, indicator.toDrawHeight, true); + //TODO will exist animation? + /*if (indicator.category == "normal") { + animateProgress(indicator, $widget); + }*/ + var $title = $widget.find('.ind-title-selector'); + if (indicator.favorite == "1") { + $title.addClass("panel-active"); + } + }); +} + +var fillStatusIndicatorFirstView = function (presenterData) { + var widgetBuilder = new WidgetBuilder(); + var panel = $('#indicatorsDataGridStack').data('gridstack'); + panel.remove_all(); + $('#relatedDetailGridStack').data('gridstack').remove_all(); + + var $widget = widgetBuilder.buildStatusIndicatorFirstView(presenterData); + panel.add_widget($widget, 0, 15, 20, 4.7, true); + + var graphParams1 = { + canvas : { + containerId:'graph1', + width:300, + height:300, + stretch:true + }, + graph: { + allowDrillDown:false, + allowTransition:true, + showTip: true, + allowZoom: false, + gapWidth:0.2, + useShadows: true, + thickness: 30, + showLabels: true, + colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a'] + } + }; + + var graph1 = new PieChart(presenterData.graph1Data, graphParams1, null, null); + graph1.drawChart(); + + var graphParams2 = graphParams1; + graphParams2.canvas.containerId = "graph2"; + var graph2 = new PieChart(presenterData.graph2Data, graphParams2, null, null); + graph2.drawChart(); + var graphParams3 = graphParams1; + graphParams3.canvas.containerId = "graph3"; + var graph3 = new PieChart(presenterData.graph3Data, graphParams3, null, null); + graph3.drawChart(); + + var indicatorPrincipalData = widgetBuilder.getIndicatorLoadedById(presenterData.id) + setIndicatorActiveMarker(); +} + +var fillStatusIndicatorFirstViewDetail = function(presenterData) { + var widgetBuilder = new WidgetBuilder(); + var gridDetail = $('#relatedDetailGridStack').data('gridstack'); + //gridDetail.remove_all(); + $.each(presenterData.dataList, function(index, dataItem) { + var $widget = widgetBuilder.buildStatusIndicatorFirstViewDetail(dataItem); + var x = (index % 2 == 0) ? 6 : 0; + gridDetail.add_widget($widget, x, 15, 6, 2, true); + }); + if (window.currentIndicator.type == "1010") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_PROCESS']); + } + if (window.currentIndicator.type == "1030") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_GROUPS']); + } + if (window.currentIndicator.type == "1050") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_PROCESS']); + } +} + +var fillSpecialIndicatorFirstView = function(presenterData) { + var widgetBuilder = new WidgetBuilder(); + var panel = $('#indicatorsDataGridStack').data('gridstack'); + panel.remove_all(); + $('#relatedDetailGridStack').data('gridstack').remove_all(); + + var $widget = widgetBuilder.buildSpecialIndicatorFirstView(presenterData); + panel.add_widget($widget, 0, 15, 20, 4.7, true); + var peiParams = { + canvas : { + containerId:'specialIndicatorGraph', + width:300, + height:300, + stretch:true + }, + graph: { + allowDrillDown:false, + allowTransition:true, + showTip: true, + allowZoom: false, + gapWidth:0.3, + useShadows: true, + thickness: 30, + showLabels: true, + colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a'] + } + }; + + var ueiParams = { + canvas : { + containerId:'specialIndicatorGraph', + width:500, + height:300, + stretch:true + }, + graph: { + allowDrillDown:false, + allowTransition:true, + axisX:{ showAxis: true, label: G_STRING.ID_YEAR }, + axisY:{ showAxis: true, label: "Q" }, + gridLinesX:false, + gridLinesY:true, + showTip: true, + allowZoom: false, + useShadows: true, + paddingTop: 50, + colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a','#74a9a9'] + } + }; + + var indicatorPrincipalData = widgetBuilder.getIndicatorLoadedById(presenterData.id) + + if (indicatorPrincipalData.type == "1010") { + var graph = new Pie3DChart(presenterData.dataToDraw, peiParams, null, null); + graph.drawChart(); + //the pie chart goes to much upwards,so a margin is added: + $('#specialIndicatorGraph').css('margin-top','60px'); + } + + if (indicatorPrincipalData.type == "1030") { + var graph = new BarChart(presenterData.dataToDraw, ueiParams, null, null); + graph.drawChart(); + } + + + this.fillSpecialIndicatorFirstViewDetail(presenter.orderDataList(presenterData.data, selectedOrderOfDetailList())); + setIndicatorActiveMarker(); +} + +var fillSpecialIndicatorFirstViewDetail = function (list) { + //presenterData = { id: "indId", efficiencyIndex: "0.11764706", efficiencyVariation: -0.08235294, + // inefficiencyCost: "-127.5000", inefficiencyCostToShow: -127, efficiencyIndexToShow: 0.12 + // data: {indicatorId, uid, name, averateTime...}, dataToDraw: [{datalabe, value}] } + var widgetBuilder = new WidgetBuilder(); + var gridDetail = $('#relatedDetailGridStack').data('gridstack'); + gridDetail.remove_all(); + + window.currentDetailList = list; + window.currentDetailFunction = fillSpecialIndicatorFirstViewDetail; + + $.each(list, function(index, dataItem) { + var $widget = widgetBuilder.buildSpecialIndicatorFirstViewDetail(dataItem); + var x = (index % 2 == 0) ? 6 : 0; + //the first 2 elements are not hidden + if (index < 2) { + $widget.removeClass("hideme"); + } + gridDetail.add_widget($widget, x, 15, 6, 2, true); + }); + if (window.currentIndicator.type == "1010") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_PROCESS']); + } + if (window.currentIndicator.type == "1030") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_GROUPS']); + } + hideScrollIfAllDivsAreVisible(); +} + +var fillSpecialIndicatorSecondView = function(presenterData) { + //presenterData= object {dataToDraw[], entityData[] //user/tasks data} + var widgetBuilder = new WidgetBuilder(); + var panel = $('#indicatorsDataGridStack').data('gridstack'); + panel.remove_all(); + var $widget = widgetBuilder.buildSpecialIndicatorSecondView(presenterData); + panel.add_widget($widget, 0, 15, 20, 4.7, true); + var detailParams = { + canvas : { + containerId:'specialIndicatorGraph', + width:300, + height:300, + stretch:true + }, + graph: { + allowTransition: false, + allowDrillDown: true, + showTip: true, + allowZoom: false, + useShadows: false, + gridLinesX: true, + gridLinesY: true, + area: {visible: false, css:"area"}, + axisX:{ showAxis: true, label: G_STRING.ID_USERS }, + axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, + showErrorBars: true + + } + }; + + var indicatorPrincipalData = widgetBuilder.getIndicatorLoadedById(window.currentEntityData.indicatorId); + + if (window.currentIndicator.type == "1010") { + var graph = new BarChart(presenterData.dataToDraw, detailParams, null, null); + graph.drawChart(); + } + + if (window.currentIndicator.type == "1030") { + var graph = new BarChart(presenterData.dataToDraw, detailParams, null, null); + graph.drawChart(); + } + this.fillSpecialIndicatorSecondViewDetail(presenter.orderDataList(presenterData.entityData, selectedOrderOfDetailList())); +} + +var fillSpecialIndicatorSecondViewDetail = function (list) { + //presenterData = { entityData: Array[{name,uid,inefficiencyCost, + // inefficiencyIndex, deviationTime, + // averageTime}], + // dataToDraw: Array[{datalabel, value}] } + var widgetBuilder = new WidgetBuilder(); + var gridDetail = $('#relatedDetailGridStack').data('gridstack'); + gridDetail.remove_all(); + + window.currentDetailList = list; + window.currentDetailFunction = fillSpecialIndicatorSecondViewDetail; + + $.each(list, function(index, dataItem) { + var $widget = widgetBuilder.buildSpecialIndicatorSecondViewDetail(dataItem); + var x = (index % 2 == 0) ? 6 : 0; + //the first 2 elements are not hidden + if (index < 2) { + $widget.removeClass("hideme"); + } + gridDetail.add_widget($widget, x, 15, 6, 2, true); + }); + + if (window.currentIndicator.type == "1010") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_TASKS']); + } + if (window.currentIndicator.type == "1030") { + $('#relatedLabel').find('h3').text(G_STRING['ID_RELATED_USERS']); + } + hideScrollIfAllDivsAreVisible(); +} + +var fillGeneralIndicatorFirstView = function (presenterData) { + var widgetBuilder = new WidgetBuilder(); + var panel = $('#indicatorsDataGridStack').data('gridstack'); + panel.remove_all(); + $('#relatedDetailGridStack').data('gridstack').remove_all(); + + var $widget = widgetBuilder.buildGeneralIndicatorFirstView(presenterData); + panel.add_widget($widget, 0, 15, 20, 4.7, true); + + $('#relatedLabel').find('h3').text(''); + + var generalLineParams1 = { + canvas : { + containerId:'generalGraph1', + width:300, + height:300, + stretch:true + }, + graph: { + allowTransition: false, + allowDrillDown: true, + showTip: true, + allowZoom: false, + useShadows: false, + gridLinesX: true, + gridLinesY: true, + area: {visible: false, css:"area"}, + axisX:{ showAxis: true, label: G_STRING.ID_PROCESS_TASKS }, + axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, + showErrorBars: false + } + }; + + var generalLineParams2 = { + canvas : { + containerId:'generalGraph2', + width:300, + height:300, + stretch:true + }, + graph: { + allowTransition: false, + allowDrillDown: true, + showTip: true, + allowZoom: false, + useShadows: false, + gridLinesX: true, + gridLinesY: true, + area: {visible: false, css:"area"}, + axisX:{ showAxis: true, label: G_STRING.ID_PROCESS_TASKS }, + axisY:{ showAxis: true, label: G_STRING.ID_TIME_HOURS }, + showErrorBars: false + } + }; + + var generalBarParams1 = { + canvas : { + containerId:'generalGraph1', + width:300, + height:300, + stretch:true + }, + graph: { + allowDrillDown:false, + allowTransition:true, + axisX:{ showAxis: true, label: G_STRING.ID_YEAR }, + axisY:{ showAxis: true, label: "Q" }, + gridLinesX:false, + gridLinesY:true, + showTip: true, + allowZoom: false, + useShadows: true, + paddingTop: 50, + colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a','#74a9a9'] + } + }; + + var generalBarParams2 = { + canvas : { + containerId:'generalGraph2', + width:300, + height:300, + stretch:true + }, + graph: { + allowDrillDown:false, + allowTransition:true, + axisX:{ showAxis: true, label: G_STRING.ID_YEAR }, + axisY:{ showAxis: true, label: "Q" }, + gridLinesX:false, + gridLinesY:true, + showTip: true, + allowZoom: false, + useShadows: true, + paddingTop: 50, + colorPalette: ['#5486bf','#bf8d54','#acb30c','#7a0c0c','#bc0000','#906090','#007efb','#62284a','#0c7a7a','#74a9a9'] + } + }; + + var graph1 = null; + if (presenterData.graph1Type == '10') { + generalBarParams1.graph.axisX.label = presenterData.graph1XLabel; + generalBarParams1.graph.axisY.label = presenterData.graph1YLabel; + graph1 = new BarChart(presenterData.graph1Data, generalBarParams1, null, null); + } else { + generalLineParams1.graph.axisX.label = presenterData.graph1XLabel; + generalLineParams1.graph.axisY.label = presenterData.graph1YLabel; + graph1 = new LineChart(presenterData.graph1Data, generalLineParams1, null, null); + } + graph1.drawChart(); + + var graph2 = null; + if (presenterData.graph2Type == '10') { + generalBarParams2.graph.axisX.label = presenterData.graph2XLabel; + generalBarParams2.graph.axisY.label = presenterData.graph2YLabel; + graph2 = new BarChart(presenterData.graph2Data, generalBarParams2, null, null); + } else { + generalLineParams2.graph.axisX.label = presenterData.graph2XLabel; + generalLineParams2.graph.axisY.label = presenterData.graph2YLabel; + graph2 = new LineChart(presenterData.graph2Data, generalLineParams2, null, null); + } + graph2.drawChart(); + + setIndicatorActiveMarker(); +} + +var animateProgress = function (indicatorItem, widget){ + var getRequestAnimationFrame = function () { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function ( callback ){ + window.setTimeout(enroute, 1 / 60 * 1000); + }; + }; + + var fpAnimationFrame = getRequestAnimationFrame(); + var i = 0; + var j = 0; + + var indicator = indicatorItem; + var animacion = function () { + var intComparative = parseInt(indicator.comparative); + var divId = "#indicatorButton" + indicator.id; + var $valueLabel = widget + .find('.ind-value-selector'); + var $progressBar = widget + .find('.ind-progress-selector'); + + if (!($valueLabel.length > 0)) {throw new Error ('"No ind-value-selector found for " + divId');} + this.helper.assert($progressBar.length > 0, "No ind-progress-selector found for " + divId); + $progressBar.attr('aria-valuemax', intComparative); + var indexToPaint = Math.min(indicator.value * 100 / intComparative, 100); + + if (i <= indexToPaint) { + $progressBar.css('width', i+'%').attr('aria-valuenow', i); + i++; + fpAnimationFrame(animacion); + } + + if(j <= indicator.value){ + $valueLabel.text(j + "%"); + j++; + fpAnimationFrame(animacion); + } + + } + fpAnimationFrame(animacion); +}; + +/*var dashboardButtonTemplate = '
    \ + \ + \ +
    ';*/ + + + diff --git a/workflow/engine/methods/setup/setupSchemas/triggerFillReportByProcess.sql b/workflow/engine/methods/setup/setupSchemas/triggerFillReportByProcess.sql index eb3dc4808..e62d919e3 100644 --- a/workflow/engine/methods/setup/setupSchemas/triggerFillReportByProcess.sql +++ b/workflow/engine/methods/setup/setupSchemas/triggerFillReportByProcess.sql @@ -42,7 +42,7 @@ GROUP BY APPLICATION.PRO_UID; UPDATE PRO_REPORTING SET PRO_REPORTING.CONFIGURED_PROCESS_TIME = ( - SELECT SUM(if (TASK.TAS_TIMEUNIT = "DAYS", (TASK.TAS_DURATION*8), TASK.TAS_DURATION)) + SELECT SUM(if (TASK.TAS_TIMEUNIT = "DAYS", (TASK.TAS_DURATION*24), TASK.TAS_DURATION)) FROM TASK WHERE PRO_REPORTING.PRO_UID = TASK.PRO_UID ); diff --git a/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql b/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql index 9ffb5b5ea..114565856 100644 --- a/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql +++ b/workflow/engine/methods/setup/setupSchemas/triggerFillReportByUser.sql @@ -55,7 +55,7 @@ UPDATE USR_REPORTING INNER JOIN TASK ON USR_REPORTING.TAS_UID = TASK.TAS_UID -SET USR_REPORTING.CONFIGURED_TASK_TIME = if (TASK.TAS_TIMEUNIT = "DAYS", (TASK.TAS_DURATION*8), TASK.TAS_DURATION) +SET USR_REPORTING.CONFIGURED_TASK_TIME = if (TASK.TAS_TIMEUNIT = "DAYS", (TASK.TAS_DURATION*24), TASK.TAS_DURATION) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php b/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php index 37bd2b45b..2491b49cb 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/ReportingIndicators.php @@ -18,7 +18,7 @@ class ReportingIndicators * * return decimal value */ - public function getPeiCompleteData($indicatorUid, $measureDate, $compareDate, $language) + public function getPeiCompleteData($indicatorUid, $compareDate, $measureDate, $language) { G::loadClass('indicatorsCalculator'); $calculator = new \IndicatorsCalculator(); @@ -30,7 +30,10 @@ class ReportingIndicators $peiCost = current(reset($calculator->peiCostHistoric($processesId, $measureDate, $measureDate, \ReportingPeriodicityEnum::NONE))); $peiCompare = current(reset($calculator->peiHistoric($processesId, $compareDate, $compareDate, \ReportingPeriodicityEnum::NONE))); - $retval = array("efficiencyIndex" => $peiValue, + $retval = array( + "id" => $indicatorUid, + "efficiencyIndex" => $peiValue, + "efficiencyIndexCompare" => $peiCompare, "efficiencyVariation" => ($peiValue-$peiCompare), "inefficiencyCost" => $peiCost, "data"=>$processes); @@ -47,32 +50,22 @@ class ReportingIndicators * * return decimal value */ - public function getUeiCompleteData($indicatorUid, $measureDate, $compareDate, $language) + public function getUeiCompleteData($indicatorUid, $compareDate, $measureDate,$language) { G::loadClass('indicatorsCalculator'); $calculator = new \IndicatorsCalculator(); $groups = $calculator->ueiUserGroups($indicatorUid, $measureDate, $measureDate, $language); - $groupIds = array(); - foreach($groups as $p) { - array_push($groupIds, $p['uid']); - } - - if (sizeof($groupIds) == 0) { - $groupIds = null; - } - //TODO think what if each indicators has a group or user subset assigned. Now are all $ueiValue = current(reset($calculator->ueiHistoric(null, $measureDate, $measureDate, \ReportingPeriodicityEnum::NONE))); $arrCost = $calculator->ueiUserGroups($indicatorUid, $measureDate, $measureDate, $language); - $ueiCost = (sizeof($arrCost) > 0) - ? $arrCost[0]['inefficiencyCost'] - : null; - + $ueiCost = current(reset($calculator->ueiCostHistoric(null, $measureDate, $measureDate, \ReportingPeriodicityEnum::NONE))); $ueiCompare = current(reset($calculator->ueiHistoric(null, $compareDate, $compareDate, \ReportingPeriodicityEnum::NONE))); - $retval = array("efficiencyIndex" => $ueiValue, + $retval = array( + "id" => $indicatorUid, + "efficiencyIndex" => $ueiValue, "efficiencyVariation" => ($ueiValue-$ueiCompare), "inefficiencyCost" => $ueiCost, "data"=>$groups); @@ -296,5 +289,27 @@ class ReportingIndicators ); return $returnValue; } + + /** + * Get list status indicator + * + * @access public + * @param array $options, Data for list + * @return array + * + * @author Marco Antonio Nina + * @copyright Colosa - Bolivia + */ + public function getStatusIndicator($options = array()) + { + Validator::isArray($options, '$options'); + + $usrUid = isset( $options["usrUid"] ) ? $options["usrUid"] : ""; + + G::loadClass('indicatorsCalculator'); + $calculator = new \IndicatorsCalculator(); + $result = $calculator->statusIndicator($usrUid); + return $result; + } } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php b/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php index 3df2ef4d3..23a5190c9 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/ReportingIndicators.php @@ -71,223 +71,6 @@ class ReportingIndicators extends Api } } -// /** -// * Returns the aggregate Efficiency of a employee or set of employees -// * -// * @param string $employee_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @return array -// * -// * @url GET /employee-efficiency-index -// */ -// public function doGetEmployeeEfficiencyIndex($employee_list, $init_date, $end_date) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($employee_list) > 1) -// ? $listArray = explode(',', $employee_list) -// : null; -// $response = $indicatorsObj->getEmployeeEfficiencyIndex($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date)); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Lists tasks of a employee and it's statistics (efficiency, average times, etc.) -// * -// * @param string $employee_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @param string $language {@from path} -// * @return array -// * -// * @url GET /employee-tasks -// */ -// public function doGetEmployeeTasksInfo($employee_list, $init_date, $end_date, $language) -// { -// if ($employee_list == null || strlen($employee_list) <= 1) -// throw new InvalidArgumentException ('employee_list must have at least a value', 0); -// -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = $listArray = explode(',', $employee_list); -// $response = $indicatorsObj->getEmployeeTasksInfoList($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date), -// $language); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Returns the percent of Cases with Overdue time -// * -// * @param string $$process_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @return array -// * -// * @url GET /percent-overdue-cases -// */ -// public function doGetPercentOverdueByProcess($process_list, $init_date, $end_date) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($process_list) > 1) -// ? $listArray = explode(',', $process_list) -// : null; -// $response = $indicatorsObj->getPercentOverdueCasesByProcess($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date)); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Returns the percent of Cases with Overdue time with the selected periodicity -// * -// * @param string $$process_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @param string $periodicity {@from path} -// * @return array -// * -// * @url GET /percent-overdue-cases-history -// */ -// public function doGetPercentOverdueByProcessHistory($process_list, $init_date, $end_date, $periodicity) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($process_list) > 1) -// ? $listArray = explode(',', $process_list) -// : null; -// $response = $indicatorsObj->getPercentOverdueCasesByProcessHistory($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date), -// $periodicity); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Returns the total of Cases with New time -// * -// * @param string $$process_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @return array -// * -// * @url GET /total-new-cases -// */ -// public function doGetTotalNewByProcess($process_list, $init_date, $end_date) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($process_list) > 1) -// ? $listArray = explode(',', $process_list) -// : null; -// $response = $indicatorsObj->getPercentNewCasesByProcess($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date)); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Returns the total of Cases with New time with the selected periodicity -// * -// * @param string $$process_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @param string $periodicity {@from path} -// * @return array -// * -// * @url GET /total-new-cases-history -// */ -// public function doGetTotalNewByProcessHistory($process_list, $init_date, $end_date, $periodicity) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($process_list) > 1) -// ? $listArray = explode(',', $process_list) -// : null; -// $response = $indicatorsObj->getPercentNewCasesByProcessHistory($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date), -// $periodicity); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Returns the total of Cases with Completed time -// * -// * @param string $$process_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @return array -// * -// * @url GET /total-completed-cases -// */ -// public function doGetTotalCompletedByProcess($process_list, $init_date, $end_date) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($process_list) > 1) -// ? $listArray = explode(',', $process_list) -// : null; -// $response = $indicatorsObj->getPercentCompletedCasesByProcess($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date)); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// -// /** -// * Returns the total of Cases with Completed time with the selected periodicity -// * -// * @param string $$process_list {@from path} -// * @param string $init_date {@from path} -// * @param string $end_date {@from path} -// * @param string $periodicity {@from path} -// * @return array -// * -// * @url GET /total-completed-cases-history -// */ -// public function doGetTotalCompletedByProcessHistory($process_list, $init_date, $end_date, $periodicity) -// { -// try { -// $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); -// $listArray = (strlen($process_list) > 1) -// ? $listArray = explode(',', $process_list) -// : null; -// $response = $indicatorsObj->getPercentCompletedCasesByProcessHistory($listArray, -// new \DateTime($init_date), -// new \DateTime($end_date), -// $periodicity); -// return $response; -// } catch (\Exception $e) { -// throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); -// } -// } -// /** * Returns the total of Cases with Completed time with the selected periodicity * @@ -299,7 +82,7 @@ class ReportingIndicators extends Api * * @url GET /process-efficiency-data */ - public function doGetProcessEficciencyData($indicator_uid, $measure_date, $compare_date, $language) + public function doGetProcessEficciencyData($indicator_uid, $compare_date, $measure_date, $language) { try { $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); @@ -324,7 +107,7 @@ class ReportingIndicators extends Api * * @url GET /employee-efficiency-data */ - public function doGetEmployeeEficciencyData($indicator_uid, $measure_date, $compare_date, $language) + public function doGetEmployeeEficciencyData($indicator_uid, $compare_date, $measure_date, $language) { try { $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); @@ -390,6 +173,29 @@ class ReportingIndicators extends Api throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } + + /** + * Get list Status indicator + * + * @return array + * + * @author Marco Antonio Nina + * @copyright Colosa - Bolivia + * + * @url GET /status-indicator + */ + public function doGetStatusIndicator() { + try { + $options['usrUid'] = $this->getUserId(); + + $indicatorsObj = new \ProcessMaker\BusinessModel\ReportingIndicators(); + $response = $indicatorsObj->getStatusIndicator($options); + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + } diff --git a/workflow/engine/templates/strategicDashboard/formDashboard.js b/workflow/engine/templates/strategicDashboard/formDashboard.js index 950714d06..ab4025611 100644 --- a/workflow/engine/templates/strategicDashboard/formDashboard.js +++ b/workflow/engine/templates/strategicDashboard/formDashboard.js @@ -504,7 +504,7 @@ Ext.onReady( function() { enableTabScroll : true, //anchor : '98%', width : '100%', - height : 315, + height : 260, defaults : { autoScroll :true }, @@ -574,7 +574,13 @@ Ext.onReady( function() { if (typeof dataIndicator[id-1]['DAS_IND_DIRECTION'] != 'undefined') { Ext.getCmp('DAS_IND_DIRECTION_'+id).setValue(idDirection); } - if (dataIndicator[id-1]['DAS_IND_TYPE'] != '1010' && dataIndicator[id-1]['DAS_IND_TYPE'] != '1030') { + var field = ''; + if (dataIndicator[id-1]['DAS_IND_TYPE'] != '1050') { + field = Ext.getCmp('IND_PROCESS_'+id); + field.enable(); + field.show(); + } + if (dataIndicator[id-1]['DAS_IND_TYPE'] != '1010' && dataIndicator[id-1]['DAS_IND_TYPE'] != '1030' && dataIndicator[id-1]['DAS_IND_TYPE'] != '1050') { var fields = ['DAS_IND_FIRST_FIGURE_'+id,'DAS_IND_FIRST_FREQUENCY_'+ id,'DAS_IND_SECOND_FIGURE_'+id, 'DAS_IND_SECOND_FREQUENCY_'+ id]; for (var k=0; k