<%@ language="javascript"%> <% /* $Revision$ $Id$ File: ins_state_history.asp Beschrijving: Toont de state-history van een object met verplicht gegeven key Kan later nog wel worden verfraaid met statistieken enzo. Een datumfilter (van/tot) is ook te verwachten */%> <% var ins_key = getQParamInt("ins_key"); var this_ins = ins.func_enabled_deel(ins_key); var authparams = user.checkAutorisation("WEB_INSUSE"); var outputmode = getQParamInt("outputmode", 0); var canTamperData = user.has("WEB_PRSSYS") && user.has("WEB_INSMSU"); %>
<% FCLTHeader.Generate({ outputmode: outputmode }); %>
<% var sql0 = "SELECT ins_srtdeel_sensortype" + " FROM ins_srtdeel" + " WHERE ins_srtdeel_key = (SELECT ins_srtdeel_key FROM ins_deel" + " WHERE ins_deel_key = " + ins_key+")"; var oRs0 = Oracle.Execute(sql0); var sensortype = oRs0("ins_srtdeel_sensortype").Value; /* bitwise: 0=no sensor, &1=discrete values sensor, &2=continuous values sensor, rest tbd */ oRs0.close(); if ((sensortype&2)==2) { var sql = "SELECT fac.safe_to_number (REPLACE (ins_deel_state, ',', '.')) ins_deel_state" + ", ins_deel_statedate" + ", ins_deel_state_history_opmerk" + ", ins_deel_state_history_key" + ", ins_deel_statedate - LEAD(ins_deel_statedate) OVER (ORDER BY ins_deel_statedate) AS interval" + ", fac.safe_to_number (REPLACE (ins_deel_state, ',', '.')) " + " - LAG (fac.safe_to_number (REPLACE (ins_deel_state, ',', '.'))) OVER (ORDER BY ins_deel_statedate) AS verschil" + " FROM ins_deel_state_history" + " WHERE ins_deel_key = " + ins_key + " ORDER BY ins_deel_statedate DESC"; } else { var sql = "SELECT ins_deel_state" + ", ins_deel_statedate" + ", ins_deel_state_history_opmerk" + ", ins_deel_state_history_key" + ", ins_deel_statedate - LEAD(ins_deel_statedate) OVER (ORDER BY ins_deel_statedate) AS interval" + ", '' AS verschil" // discrete waarden kennen geen delta + " FROM ins_deel_state_history" + " WHERE ins_deel_key = " + ins_key + " ORDER BY ins_deel_statedate DESC"; } var addurl = "appl/ins/ins_add_state_history.asp"; var buttons = [{ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: "FcltMgr.reload()" }]; if (canTamperData) { var addurl = "ins_edit_deel_state.asp?ins_key=" + ins_key; buttons.push({ icon: "fa-gauge-circle-plus", title: L("lcl_ins_sensor_manual"), action: "FcltMgr.openModalDetail('" + addurl + "', '" + safe.jsstring(L("lcl_ins_add_sensor_value")) + "', { callback: FcltMgr.reload })" }); } function formatDaysHoursMinutesSeconds(decimalDuration) { var totalSeconds = Math.floor(decimalDuration * 60 * 60 * 24); var days = Math.floor(totalSeconds / (60 * 60 * 24)); var hours = Math.floor((totalSeconds % (60 * 60 * 24)) / (60 * 60)); var minutes = Math.floor((totalSeconds % (60 * 60)) / 60); var seconds = totalSeconds % 60; return "{0}d {1}h {2}m {3}s".format(days, hours, ("0"+minutes).slice(-2), ("0"+seconds).slice(-2)); } function formatInterval (oRs) { if (oRs("interval").Value != null) return formatDaysHoursMinutesSeconds(-oRs("interval").Value); } function formatIntervalSeconds (oRs) { if (oRs("interval").Value != null) return (-1*oRs("interval").Value*24*60*60).toFixed(0); } function formatUpOrDown (oRs) { var retval = ""; if (oRs("verschil").Value != null) { if (oRs("verschil").Value > 0) retval = I("fa-caret-up fa-2x"); else if (oRs("verschil").Value < 0) retval = I("fa-caret-down fa-2x"); else if (oRs("verschil").Value == 0) retval = I("fa-dash fa-2x"); } return retval; } var rst = new ResultsetTable({ sql:sql, keyColumn: "ins_deel_state_history_key", ID: "insstatetable", outputmode: outputmode, showAll: getQParamInt("showall", 0), buttons: buttons }); // Het tijdstip niet in 2 kolommen, dat maakt sorteren (in Excel) raar rst.addColumn(new Column({caption: L("lcl_date_time"), content: "ins_deel_statedate", datatype: "datetime"})); rst.addColumn(new Column({caption: L("lcl_deel_state"), content: "ins_deel_state", datatype: ((sensortype&2)==2 ? "number" : "string"), align: ((sensortype&2)==2 ? "right" : "center")})); if ((sensortype&2)==2) // alleen voor meetwaarden { rst.addColumn(new Column({caption: L("lcl_deel_statedir"), content: formatUpOrDown, align: "center"})); rst.addColumn(new Column({caption: L("lcl_deel_statediff"), content: "verschil", datatype: "number"})); } rst.addColumn(new Column({caption: L("lcl_deel_stateinterval"), content: formatInterval})); rst.addColumn(new Column({caption: L("lcl_deel_stateintervalsec"), content: formatIntervalSeconds, datatype: "number", purpose: PRINTING_ONLY})); rst.addColumn(new Column({caption: L("lcl_remark"), content: "ins_deel_state_history_opmerk"})); if (canTamperData) rst.addAction({ action: "insDelete", caption: L("lcl_delete"), multi: true, multiOnce: true }); var cnt = rst.processResultset(); %>
<% ASPPAGE_END(); %>