";
- 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 ('