diff -r ea20d8adbcaa -r fe042f9484ac www/js/list_onewire.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/js/list_onewire.js Mon Apr 22 15:12:27 2024 +0200 @@ -0,0 +1,83 @@ +/***************************************************************************** + * Copyright (C) 2024 + * + * Michiel Broek + * + * This file is part of mbsePi-apps + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * BrewCloud is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ThermFerm; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + + +$(document).ready(function() { + var dataRecord = {}, + source = { + datatype: 'json', + cache: false, + datafields: [ + { name: 'address', type: 'string' }, + { name: 'family', type: 'string' }, + { name: 'value', type: 'int' }, + { name: 'present', type: 'string' }, + { name: 'timestamp', type: 'int' } + ], + id: 'address', + url: 'getonewire.php' + }, + dataAdapter = new $.jqx.dataAdapter(source), + tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds + + // initialize jqxGrid + $('#jqxgrid').jqxGrid({ + width: 1280, + height: 630, + source: dataAdapter, + theme: theme, + showstatusbar: true, + renderstatusbar: function(statusbar) { + var rowCount = $("#jqxgrid").jqxGrid('getrows').length; + statusbar.append('
Total items: ' + rowCount + '
'); + var container; + container = $('
'); + statusbar.append(container); + }, + columns: [ + { text: 'Address', datafield: 'address' }, + { text: 'Family', datafield: 'family', width: 100 }, + { text: 'Present', datafield: 'present', width: 120 }, + { text: 'Value', datafield: 'value', width: 100 }, + { text: 'Last change', datafield: 'timestamp', width: 200, + cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { + var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " "); + return '' + date + ''; + } + } + ], + }); + + websocket.onmessage = function(evt) { + var msg = evt.data; + var obj = JSON.parse(msg); + + if (obj.ping) { + websocket.send('{"pong":' + obj.ping + '}'); + } + + if (obj.type == 'onewire') { + // Use the message to trigger update. + $('#jqxgrid').jqxGrid('updatebounddata'); + } + } +});