Browse code

added custom charts

Gandolf authored on 06/12/2021 06:28:37
Showing 1 changed files
... ...
@@ -95,6 +95,11 @@ text.chartNav {
95 95
     display: inline-block;
96 96
     padding: 8px 12px;
97 97
 }
98
+#iframe_a {
99
+    border:none;
100
+    width:100%;
101
+    height:1075px;
102
+}
98 103
 </style>
99 104
 </head>
100 105
 
... ...
@@ -179,10 +184,34 @@ Status:
179 184
 4 weeks</text></li>
180 185
 <li class="chartNav"><text class="chartNav" onclick="setChartPeriod(3)">
181 186
 12 months</text></li>
187
+
188
+<li id="customSelector" class="chartNav">
189
+<text  class="chartNav"
190
+ onclick="setChartPeriod(0)">Custom…</text></li>
191
+
182 192
 </ul>
183 193
 </span>
194
+
195
+<div class="rowContainer" id="customChartsContainer" style="display:none;">
196
+<div class="currentDataCell">
197
+<form id="fmDateSelector" action="power.php" method="post"
198
+ target="iframe_a">
199
+<label for="beginDate">Begin Date: </label>
200
+<input id="beginDate" name="beginDate" type="date" value="mm/dd/yyyy" />
201
+<label for="endDate">End Date: </label>
202
+<input id="endDate" name="endDate" type="date" value="mm/dd/yyyy" />
203
+<br><br>
204
+<input type="button" onclick="getCustomCharts()" value="Get Charts">
205
+</form>
206
+<span id="errorMsg"></span><br>
207
+<iframe id="iframe_a" name="iframe_a"></iframe>
208
+</div>
209
+</div>
210
+
184 211
 <br>
185 212
 
213
+<div class="rowContainer" id="stockChartsContainer">
214
+
186 215
 <div class="chartContainer">
187 216
 <img class="chart" id="current_g">
188 217
 </div>
... ...
@@ -203,6 +232,8 @@ Status:
203 232
 <img class="chart" id="ambtemp_g">
204 233
 </div>
205 234
 
235
+</div>
236
+
206 237
 <div id="notes">
207 238
 <b>NOTES:</b>
208 239
 <ul>
... ...
@@ -253,16 +284,27 @@ var status_t = document.getElementById("status");
253 284
 var period_t = document.getElementById("period");
254 285
 var alertmsg_t = document.getElementById("alertmsg");   
255 286
 
287
+var customChartsContainer = document.getElementById("customChartsContainer");
288
+var stockChartsContainer = document.getElementById("stockChartsContainer");
289
+var fmDateSelector = document.getElementById("fmDateSelector");
290
+var errorMsg = document.getElementById("errorMsg");
291
+var customSelector = document.getElementById("customSelector");
292
+
256 293
 /* Global objects */
257 294
 
258 295
 var httpRequest = new XMLHttpRequest();
259 296
 
260 297
 /* Global variables */
261 298
 
262
-var graphPeriod;
299
+var chartPeriod = 1;
263 300
 var objBlink;
264 301
 
265 302
 function main() {
303
+
304
+    if (location.hostname.match(/.local/g) == null) {
305
+        customSelector.style.visibility = "hidden";
306
+    }
307
+
266 308
     // Register call back function to process client http requests
267 309
     httpRequest.onreadystatechange = function() {
268 310
         if (httpRequest.readyState == 4 && httpRequest.status == 200) {
... ...
@@ -276,8 +318,8 @@ function main() {
276 318
         displayOfflineStatus();
277 319
     };
278 320
 
321
+    initializeDateSelector();
279 322
     getSensorData();
280
-    graphPeriod = 1;
281 323
     getSensorGraphs();
282 324
     setInterval(getSensorData, 2000);
283 325
     setInterval(getSensorGraphs, 600000);
... ...
@@ -290,15 +332,22 @@ function getSensorData() {
290 332
 }
291 333
 
292 334
 function setChartPeriod(n) {
293
-    graphPeriod = n;
294
-    getSensorGraphs();
335
+    chartPeriod = n;
336
+    if (n == 0) {
337
+        customChartsContainer.style.display = "block";
338
+        stockChartsContainer.style.display = "none";
339
+    } else {
340
+        customChartsContainer.style.display = "none";
341
+        stockChartsContainer.style.display = "block";
342
+        getSensorGraphs();
343
+    }
295 344
 }
296 345
 
297 346
 function getSensorGraphs() {
298 347
     var d = new Date;
299 348
     var pfx;
300 349
 
301
-    switch(graphPeriod) {
350
+    switch(chartPeriod) {
302 351
         case 1:
303 352
             pfx = "24hr_";
304 353
             break;
... ...
@@ -403,6 +452,23 @@ function displayHostTime() {
403 452
         "  <small>(UTC" + timeZoneShift + localTimeZone + ")</small>";
404 453
 }
405 454
 
455
+function initializeDateSelector() {
456
+    var d = new Date();
457
+
458
+    var dEnd = new Date(d.getFullYear(),
459
+               d.getMonth(), d.getDate() - 0);
460
+
461
+    var dBegin = new Date(d.getFullYear(),
462
+               d.getMonth(), d.getDate() - 1);
463
+
464
+    document.getElementById("beginDate").valueAsDate = dBegin;
465
+    document.getElementById("endDate").valueAsDate = dEnd;
466
+}
467
+
468
+function getCustomCharts() {
469
+    fmDateSelector.submit();
470
+}
471
+
406 472
 </script>
407 473
 
408 474
 </body>