Thu, 18 Apr 2024 14:20:19 +0200
Devices list grid added.
685 | 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 source = { | |
26 | datatype: 'json', | |
27 | cache: false, | |
28 | datafields: [ | |
29 | { name: 'uuid', type: 'string' }, | |
30 | { name: 'type', type: 'string' }, | |
31 | { name: 'address', type: 'string' }, | |
32 | { name: 'subdevice', type: 'int' }, | |
33 | { name: 'inuse', type: 'int' }, | |
34 | { name: 'description', type: 'string' }, | |
35 | { name: 'direction', type: 'string' }, | |
36 | { name: 'value', type: 'int' }, | |
37 | { name: 'timestamp', type: 'int' } | |
38 | ], | |
39 | id: 'uuid', | |
40 | url: 'getdevices.php' | |
41 | }, | |
42 | dataAdapter = new $.jqx.dataAdapter(source); | |
43 | ||
44 | // initialize jqxGrid | |
45 | $('#jqxgrid').jqxGrid({ | |
46 | width: 1280, | |
47 | height: 630, | |
48 | source: dataAdapter, | |
49 | theme: theme, | |
50 | columns: [ | |
51 | { text: 'Address', datafield: 'address', width: 200 }, | |
52 | { text: 'Subdevice', datafield: 'subdevice', width: 100 }, | |
53 | { text: 'Direction', datafield: 'direction', width: 120 }, | |
54 | { text: 'Value', datafield: 'value', width: 80 }, | |
55 | { text: 'Description', datafield: 'description' }, | |
56 | { text: 'Last change', datafield: 'timestamp', width: 200, | |
57 | cellsrenderer: function(index, datafield, value, defaultvalue, column, rowdata) { | |
58 | var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds | |
59 | var date = new Date((value * 1000) - tzoffset).toISOString().slice(0, 19).replace("T", " ");; | |
60 | return '<span style="margin: 3px; margin-top: 6px; float: left;">' + date + '</span>'; | |
61 | } | |
62 | }, | |
63 | { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function() { | |
64 | return 'Bekijk'; | |
65 | }, buttonclick: function(row) { | |
66 | var datarecord = dataAdapter.records[row]; | |
67 | window.location.href = 'edit_device.php?uuid=' + datarecord.uuid; | |
68 | } | |
69 | } | |
70 | ], | |
71 | }); | |
72 | ||
73 | websocket.onmessage = function(evt) { | |
74 | var msg = evt.data; | |
75 | var obj = JSON.parse(msg); | |
76 | ||
77 | if (obj.ping) { | |
78 | websocket.send('{"pong":' + obj.ping + '}'); | |
79 | } | |
80 | ||
81 | if (obj.type == 'device') { | |
82 | // Use the message to trigger update. | |
83 | $('#jqxgrid').jqxGrid('updatebounddata'); | |
84 | } | |
85 | } | |
86 | }); |