<%-- * Licensed Materials - Property of IBM * * 5724-U18 * * (C) COPYRIGHT IBM CORP. 2006, 2017 All Rights Reserved. * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with * IBM Corp. --%><%-- This JSP is the handler for KPIGraph Portlet component. It provides the user interface for the KPIGraph portlet. Main Events fired by this component are - Update of KPIs - Open KPI(s) - Open Linked Report - Open Linked KPI --%><%@page import="psdi.app.kpi.KPIUtil.Trend"%> <%@page import="psdi.app.kpi.KPIUtil.Status"%> <%@include file="../common/simpleheader.jsp" %><%@page import="com.ibm.json.java.JSONArray" %><%@page import="psdi.webclient.beans.startcntr.KPIGraph" %><%@page import="psdi.webclient.beans.startcntr.ChartData" %><%@page import="psdi.webclient.beans.startcntr.BarChartData" %><%@page import="psdi.webclient.beans.startcntr.BarChartData.BarChartItem" %><%@page import="psdi.webclient.beans.startcntr.DialChartData" %><% String layoutId = component.getProperty("layoutid"); String servPath = wcs.getMaximoRequestContextURL(); KPIGraphPortlet portletControl = (KPIGraphPortlet)control; PortletStateImpl portletStateManager = portletControl.getStateManager(); String USERAGENTVERSION = request.getHeader("User-Agent"); String position = "position:initial"; if(USERAGENTVERSION.toUpperCase().indexOf("MSIE 8")>-1) position = "position:relative"; ///intially when the portlet has not been loaded //if the portlet has not been loaded ever call this. //once its loaded we do not clear the flag if(portletStateManager.isPortletNotLoaded(component)) { %><%@ include file="portletloader.jsp" %><% } else { synchronized (portletControl.getAppBean().getPortletLoadingSync()) { String[] dialchartvalues = portletControl.getDialChartValues(); String dialheight = dialchartvalues[0]; String dialwidth = dialchartvalues[1]; String dialradius = dialchartvalues[2]; String dialcx = dialchartvalues[3]; String dialcy = dialchartvalues[4]; String dialrangewidth = dialchartvalues[5]; String dialrangeoffset = dialchartvalues[6]; String dialhandwidth = dialchartvalues[7]; String dialhandlength = dialchartvalues[8]; String dialmajortickoffset = dialchartvalues[9]; Vector kpis = null; boolean isEmpty = false; boolean isBidiEnabled = BidiUtils.isBidiEnabled(); String dir = !langcode.equalsIgnoreCase("AR")? "dir='ltr'" : ""; ChartData chartData = null; String chartstyle = "width:100%; height:100%;"; int noOfKpis = 0;//so we dont call it many times boolean shortenText = Boolean.valueOf(WebClientRuntime.getWebClientProperty("webclient.shortenportlettext","true")).booleanValue(); boolean stateChanged = portletStateManager.isPortletStateChanged(); //if just porlet was minimised then don't re render as there is no need to redraw //but this flag had to be turned on when these events were fired so that jsp could be hit if(stateChanged) portletControl.setChangedFlag(false); if(portletStateManager.wasPortletLoadCalled() || (portletStateManager.isPortletLoaded() && component.hasChanged() && !stateChanged)) { Hashtable kpi = null; String sReportName = ""; String sLinkedKPI = ""; kpis = portletControl.getKPIs(); isEmpty = kpis.isEmpty(); noOfKpis = kpis.size();//so we dont call it many times String labels[] = portletControl.getLabels(); boolean displayList = portletControl.displayList(); holderId="portletbody_"+layoutId; %> <%=" <% //For all KPis selected, display data, with Trend and status depending on the respective values if(!isEmpty) { if(noOfKpis == 1) { kpi = (Hashtable)kpis.elementAt(0); sReportName = kpi.get("reportnum").toString(); sLinkedKPI = kpi.get("linkto").toString(); } String dojoTypeInput = ""; String userCalendar = s.getUserInfo().getCaltype().toLowerCase(); boolean isNational = !CalendarUtils.GREGORIAN.equalsIgnoreCase(userCalendar); Date date = null; if(isNational) { Locale userLocale = s.getUserInfo().getLocale(); try { if(kpis.size()==1) { date = MXFormat.stringToDateTime(kpi.get("lastupdated").toString(),userLocale); } else { date = MXFormat.stringToDateTime(portletControl.getLastDate(),userLocale); } String usrLocale = userLocale.toString().toLowerCase().replace('_', '-'); String dojoDatePattern = "constraints=\"{"; String dojoLang = "lang=\""+usrLocale+"\""; String dojoPackage = psdi.util.CalendarUtils.getDojoDatePackage(userCalendar); String datePackage = "datePackage=\""+dojoPackage+"\""; %> <% dojoDatePattern += "datePattern:'" + MXFormat.getDatePattern(userLocale).replace("'","\\'") + "', timePattern:'" + MXFormat.getDisplayTimePattern(userLocale).replace("'","\\'") + "'"; dojoDatePattern+=",locale:'"+usrLocale+"'}\""; dojoTypeInput = dojoTypeInput + " " + dojoDatePattern; dojoTypeInput = dojoTypeInput + " " + datePackage + " " +dojoLang; if(date != null) dojoTypeInput = dojoTypeInput + "dojovalue='" + date.getTime() +"'"; } catch(Exception e) { dojoTypeInput = ""; } } %> <% if(noOfKpis >= 1) { //KPI Header where there is just one KPI and the KPis is in the narrow section if(!displayList) { String statusColor = ""; String statusClass = ""; %> <% } //!displayList }//if more than one %> <% if((portletStateManager.wasPortletLoadCalled() || (portletStateManager.isPortletLoaded() && component.hasChanged())) && chartData != null) { String methodName = "makeChart" + id.replace('-','_'); String chartRef = "chart" + id.replace('-','_') + "_ref"; %> <% } //List of KPIs when the list has to be displayed. if(displayList) { %> <% }// displayList %> <% }//end if !isEmpty //If no kPIs were selected then display the portlet not setup message if(isEmpty) { %> <%@ include file="portletnotsetupmsg.jsp" %> <% } %> <%="]]>"%> <% portletStateManager.setStateLoaded(); } if(portletStateManager.isPortletUpdated()) { portletStateManager.setPortletUpdated(false); %> ><%="<%="]]>"%> <% //Render chart after the iframe has been written from the hidden frame String chartName = "portletchart_"+layoutId; KPIGraph kpiGraph = new KPIGraph(kpis, true, wcs); chartData = kpiGraph.makeChartData(); if (chartData != null) { %> dojo.addOnLoad(function() { dojo.addOnLoad(function() { var dJit = dijit.byId("kpiportletchart_<%= id %>"); if(dJit) dJit.destroyRecursive(true); }); }); <% if(chartData instanceof DialChartData) { DialChartData dialData = (DialChartData)chartData; %> dojo.require('ibm.tivoli.mbs.dijit.kpi.DialGauge'); document.makeKpiportletChart_<%= id %> = function() { var dJit = dijit.byId("kpiportletchart_<%= id %>"); if(dJit) dJit.destroyRecursive(true); var gauge = new ibm.tivoli.mbs.dijit.kpi.DialGauge({<% %>id: "kpiportletchart_<%= id %>", <% %>width: <%=dialwidth%>, <% %>height: <%=dialheight%>, <% %>radius: <%=dialradius%>, <% %>cx: <%=dialcx%>, <% %>cy: <%=dialcy%>, <% %>url: <%=dialData.url != null ? '"' + wcs.getMaximoRequestContextURL() + dialData.url + '"': null%>,<% %>startValue: <%=dialData.start%>, <% %>endValue: <%=dialData.end%>, <% %>hover: "<%=dialData.label%>", <% %>innerColor: "<%=dialData.innerColor%>", <% %>tickOffset: <%=dialmajortickoffset%>, <% %>tickInterval: <%=dialData.tickInterval%>, <% %>arc1Color: "<%=dialData.arc1Color%>", <% %>arc1Label: "<%=dialData.arc1Label%>", <% %>arc1Threshold: <%=dialData.arc1Threshold%>, <% %>arc2Color: "<%=dialData.arc2Color%>", <% %>arc2Label: "<%=dialData.arc2Label%>", <% %>arc2Threshold: <%=dialData.arc2Threshold%>, <% %>arc3Color: "<%=dialData.arc3Color%>", <% %>arc3Label: "<%=dialData.arc3Label%>", <% %>target: <%=dialData.target%>, <% %>targetColor: "<%=dialData.targetColor%>", <% %>targetLabel: "<%=dialData.targetLabel%>", <% %>value: <%=dialData.kpi%>, <% %>valueColor: "<%=dialData.kpiColor%>", <% %>valueLabel: "<%=dialData.kpiLabel%>"<% %>}, 'kpiportletchart_<%= id %>_holder'); gauge.startup(); }; dojo.addOnLoad(document.makeKpiportletChart_<%= id %>); <% } else if(chartData instanceof BarChartData) { BarChartData barChartData = (BarChartData)chartData; JSONArray barData = new JSONArray(); JSONArray urls = new JSONArray(); JSONArray xlabels = new JSONArray(); int length = barChartData.items.length; for(int i = 0; i < length; i++) { BarChartItem item = barChartData.items[rtl ? length - i - 1 : i]; JSONObject bar = new JSONObject(); bar.put("y", item.value); bar.put("fill", item.color); bar.put("tooltip", item.tooltip); barData.add(bar); urls.add(item.url); JSONObject xlabel = new JSONObject(); xlabel.put("value", i + 1); xlabel.put("text", item.text); xlabels.add(xlabel); } %> dojo.require('dojox.charting.Chart'); dojo.require('dojox.charting.action2d.Tooltip'); dojo.require('dojox.charting.axis2d.Default'); dojo.require('dojox.charting.plot2d.Columns'); dojo.require("dojox.charting.BidiSupport"); dojo.require("dojox.charting.widget.BidiSupport"); document.makeKpiportletChart_<%= id %> = function() { if (document.makeKpiportletChart_<%=id%>_ref) { document.makeKpiportletChart_<%=id%>_ref.destroy(); } var barurls = <%=urls.serialize()%>; var chart = new dojox.charting.Chart('kpiportletchart_<%= id %>_holder'); chart.addAxis("y", {vertical: true, includeZero: true, majorTicks: true, minorTicks: false, majorTickStep: <%=barChartData.tickInterval%><%=rtl?",leftBottom: false":""%>}); chart.addAxis("x", {natural: true, labels: <%=xlabels.serialize()%>}); chart.addPlot("default", {type: "Columns", font: "normal normal 11pt sans-serif", gap: 5}); chart.addSeries("Series 1" , <%=barData.serialize()%>); new dojox.charting.action2d.Tooltip(chart, "default"); chart.connectToPlot("default",this, function(evt) { if(evt.type == "onclick" && barurls[evt.index] != "") { parent.window.location = "<%=wcs.getMaximoRequestContextURL()%>" + barurls[evt.index]; } else if(evt.type == "onmouseover") { dojo.style("kpiportletchart_<%= id %>_holder", "cursor", "pointer"); } else if(evt.type == "onmouseout") { dojo.style("kpiportletchart_<%= id %>_holder", "cursor", null); } }); chart.render(); document.makeKpiportletChart_<%=id%>_ref = chart; } dojo.addOnLoad(document.makeKpiportletChart_<%= id %>); <% } } if (noOfKpis ==1) { %> var kpititleid = getElement("kpigraphtitle_<%=layoutId %>"); if(!undef(kpititleid )) { kpititleid.innerHTML = "<%=kpiGraph.getTitle()%>"; } <% } %> finishPortlet("<%=layoutId%>");<%="]]>"%><% } if(portletControl.hasChanged()) { portletControl.setChangedFlag(false); } // /If the portlet state is changed then fire the javascript to toggle its state if(portletStateManager.isPortletStateChanged()) { portletStateManager.setPortletStateChanged(false); %> ><%=" <%="]]>"%> <% } } } %><%@ include file="../common/componentfooter.jsp" %>