|
1 /***************************************************************************** |
|
2 * Copyright (C) 2024 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of mbsePi-apps |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * BrewCloud is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 |
|
24 $(document).ready(function() { |
|
25 var dataRecord = {}, |
|
26 source = { |
|
27 datatype: 'json', |
|
28 cache: false, |
|
29 datafields: [ |
|
30 { name: 'address', type: 'string' }, |
|
31 { name: 'family', type: 'string' }, |
|
32 { name: 'value', type: 'int' }, |
|
33 { name: 'present', type: 'string' }, |
|
34 { name: 'timestamp', type: 'int' } |
|
35 ], |
|
36 id: 'address', |
|
37 url: 'getonewire.php' |
|
38 }, |
|
39 dataAdapter = new $.jqx.dataAdapter(source), |
|
40 tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds |
|
41 |
|
42 // initialize jqxGrid |
|
43 $('#jqxgrid').jqxGrid({ |
|
44 width: 1280, |
|
45 height: 630, |
|
46 source: dataAdapter, |
|
47 theme: theme, |
|
48 showstatusbar: true, |
|
49 renderstatusbar: function(statusbar) { |
|
50 var rowCount = $("#jqxgrid").jqxGrid('getrows').length; |
|
51 statusbar.append('<div style="float: left; margin: 8px; color: orange !important;">Total items: ' + rowCount + '</div>'); |
|
52 var container; |
|
53 container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); |
|
54 statusbar.append(container); |
|
55 }, |
|
56 columns: [ |
|
57 { text: 'Address', datafield: 'address' }, |
|
58 { text: 'Family', datafield: 'family', width: 100 }, |
|
59 { text: 'Present', datafield: 'present', width: 120 }, |
|
60 { text: 'Value', datafield: 'value', width: 100 }, |
|
61 { text: 'Last change', datafield: 'timestamp', width: 200, |
|
62 cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { |
|
63 var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); |
|
64 return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>'; |
|
65 } |
|
66 } |
|
67 ], |
|
68 }); |
|
69 |
|
70 websocket.onmessage = function(evt) { |
|
71 var msg = evt.data; |
|
72 var obj = JSON.parse(msg); |
|
73 |
|
74 if (obj.ping) { |
|
75 websocket.send('{"pong":' + obj.ping + '}'); |
|
76 } |
|
77 |
|
78 if (obj.type == 'onewire') { |
|
79 // Use the message to trigger update. |
|
80 $('#jqxgrid').jqxGrid('updatebounddata'); |
|
81 } |
|
82 } |
|
83 }); |