Skip to content

Commit 85894df

Browse files
committed
searchable and sortable event table
1 parent ebc93f8 commit 85894df

File tree

4 files changed

+121
-19
lines changed

4 files changed

+121
-19
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "homematic-manager",
3-
"version": "2.6.3",
3+
"version": "2.7.0",
44
"private": true,
55
"dependencies": {
66
"async": "2.6.2",

www/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ <h3 id="console-rpc-method-heading"></h3>
6464
<div id="pager-messages"></div>
6565
</div>
6666
<div id="events">
67+
<table id="grid-events"></table>
68+
<div id="pager-events"></div>
69+
<!--
6770
<div id="grid-events" class="ui-jqgrid" style="display: block;">
6871
<div class="ui-jqgrid-titlebar ui-jqgrid-caption ui-widget-header ui-corner-top ui-helper-clearfix">
6972
<div class="">
@@ -90,7 +93,7 @@ <h3 id="console-rpc-method-heading"></h3>
9093
</table>
9194
</div>
9295
</div>
93-
96+
-->
9497
</div>
9598
</div>
9699
<div id="dialog-paramset">

www/js/homematic-manager.js

Lines changed: 115 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* global $, window, document, alert */
21
/* eslint-disable import/no-unassigned-import */
2+
/* global $, window, document, alert */
33

44
const ipc = require('electron').ipcRenderer;
55
const {shell} = require('electron');
@@ -85,6 +85,7 @@ const $gridDevices = $('#grid-devices');
8585
const $gridLinks = $('#grid-links');
8686
const $gridRssi = $('#grid-rssi');
8787
const $gridMessages = $('#grid-messages');
88+
const $gridEvents = $('#grid-events');
8889
const $gridInterfaces = $('#grid-interfaces');
8990

9091
const $tableEasymode = $('#table-easymode');
@@ -189,6 +190,17 @@ ipcRpc.on('connection', connected => {
189190
$('#connection-indicator').html(`${config.ccuAddress}<br><span style="font-size: 8px; font-weight: normal;">${connections}</span>`);
190191
});
191192

193+
let eventRow = 0;
194+
let newEvent = false;
195+
196+
function pushEvent(data) {
197+
newEvent = true;
198+
eventsData.push(data);
199+
if (eventsData.length > 8192) {
200+
eventsData.splice(0, 1);
201+
}
202+
}
203+
192204
// Incoming Events
193205
ipcRpc.on('rpc', data => {
194206
const [method, params] = data;
@@ -201,6 +213,8 @@ ipcRpc.on('rpc', data => {
201213
}
202214
switch (method) {
203215
case 'newDevices': {
216+
pushEvent({timestamp: ts(), method, value: JSON.stringify(params[1])});
217+
204218
const devArr = params[1];
205219
$('div.ui-dialog[aria-describedby="dialog-alert"] .ui-dialog-title').html(_('New devices'));
206220
let count = 0;
@@ -224,6 +238,8 @@ ipcRpc.on('rpc', data => {
224238
break;
225239
}
226240
case 'deleteDevices': {
241+
pushEvent({timestamp: ts(), method, value: JSON.stringify(params[1])});
242+
227243
const devArr = params[1];
228244
$('div.ui-dialog[aria-describedby="dialog-alert"] .ui-dialog-title').html(_('Devices deleted'));
229245
let count = 0;
@@ -249,6 +265,7 @@ ipcRpc.on('rpc', data => {
249265
break;
250266
}
251267
case 'replaceDevice': {
268+
pushEvent({timestamp: ts(), method, value: JSON.stringify(params[1])});
252269
getNames(() => {
253270
getDevices(() => {
254271
getLinks(() => {
@@ -260,18 +277,14 @@ ipcRpc.on('rpc', data => {
260277
}
261278
case 'event': {
262279
const [, address, param, value] = params;
263-
264-
const timestamp = new Date();
265-
const ts = timestamp.getFullYear() + '-' +
266-
('0' + (timestamp.getMonth() + 1).toString(10)).slice(-2) + '-' +
267-
('0' + (timestamp.getDate()).toString(10)).slice(-2) + ' ' +
268-
('0' + (timestamp.getHours()).toString(10)).slice(-2) + ':' +
269-
('0' + (timestamp.getMinutes()).toString(10)).slice(-2) + ':' +
270-
('0' + (timestamp.getSeconds()).toString(10)).slice(-2);
280+
const [device, channel] = address.split(':');
271281

272282
const name = names && names[address] ? names[address] : '';
273283

274-
$('#event-table').prepend('<tr class="ui-widget-content jqgrow ui-row-ltr "><td class="event-column-1 monospace">' + ts + '</td><td class="event-column-2">' + name + '</td><td class="event-column-3 monospace">' + address + '</td><td class="event-column-4 monospace">' + param + '</td><td class="event-column-5 monospace">' + value + '</td></tr>');
284+
//$('#event-table').prepend('<tr class="ui-widget-content jqgrow ui-row-ltr "><td class="event-column-1 monospace">' + ts + '</td><td class="event-column-2">' + name + '</td><td class="event-column-3 monospace">' + address + '</td><td class="event-column-4 monospace">' + param + '</td><td class="event-column-5 monospace">' + value + '</td></tr>');
285+
286+
pushEvent({timestamp: ts(), method: 'event', channel, device, name, param, value});
287+
275288

276289
// Service-Meldung?
277290
if (!listMessages) {
@@ -358,6 +371,8 @@ ipcRpc.on('rpc', data => {
358371
break;
359372
}
360373
default:
374+
pushEvent({timestamp: ts(), method, value: JSON.stringify(params[1])});
375+
361376
}
362377
});
363378

@@ -411,15 +426,17 @@ function getConfig() {
411426
translate();
412427

413428
initTabs();
414-
initDialogsMisc();
415-
initDialogParamset();
416-
initDialogLinkParamset();
429+
initGridEvents();
417430

418431
initGridDevices();
419432
initGridMessages();
420433
initGridLinks();
421434
initConsole();
422435

436+
initDialogsMisc();
437+
initDialogParamset();
438+
initDialogLinkParamset();
439+
423440
$('#loader').hide();
424441

425442
if (!config.ccuAddress) {
@@ -472,12 +489,30 @@ function getNames(callback) {
472489
}
473490
});
474491
}
492+
493+
let refreshEvents = false;
494+
495+
setInterval(() => {
496+
if (refreshEvents) {
497+
if (newEvent) {
498+
newEvent = false;
499+
$gridEvents.trigger('reloadGrid');
500+
}
501+
}
502+
}, 1000);
503+
475504
function initTabs() {
476505
$tabsMain.tabs({
477506

478507
activate(event, ui) {
479508
resizeGrids();
509+
480510
const tab = ui.newTab[0].children[0].hash.slice(1);
511+
512+
refreshEvents = tab === 'events';
513+
console.log('refreshEvents', refreshEvents);
514+
515+
481516
if (hash) {
482517
window.location.hash = '/' + hash + '/' + tab;
483518
}
@@ -606,6 +641,7 @@ function initDialogsMisc() {
606641
});
607642
}
608643
function initDaemon() {
644+
eventsData.length = 0;
609645
indexSourceRoles = {};
610646
indexTargetRoles = {};
611647
daemon = $('#select-bidcos-daemon option:selected').val();
@@ -643,6 +679,7 @@ function initDaemon() {
643679
firstLoad = false;
644680

645681
console.log('initDaemon', daemon);
682+
$gridEvents.trigger('reloadGrid');
646683

647684
if (daemon && config.daemons[daemon]) {
648685
const {type} = config.daemons[daemon];
@@ -3928,6 +3965,57 @@ function refreshGridInterfaces() {
39283965
$gridInterfaces.trigger('reloadGrid');
39293966
}
39303967

3968+
const eventsData = [];
3969+
3970+
function initGridEvents() {
3971+
$gridEvents.jqGrid({
3972+
colNames: ['Timestamp', 'Method', 'Name', 'Device', 'Channel', 'Param', 'Value'],
3973+
colModel: [
3974+
{name: 'timestamp', index: 'timestamp', width: 140, fixed: true, title: true, search: true},
3975+
{name: 'method', index: 'method', width: 80, fixed: true, title: true, align: 'center', search: true},
3976+
{name: 'name', index: 'name', width: 320, fixed: true, title: false, hidden: config.hideNameCols, search: true},
3977+
{name: 'device', index: 'device', width: 110, fixed: true, title: true, search: true},
3978+
{name: 'channel', index: 'channel', width: 60, fixed: true, title: false, align: 'right', search: true},
3979+
{name: 'param', index: 'param', width: 200, fixed: true, title: false, search: true},
3980+
{name: 'value', index: 'value', width: 80, fixed: false, title: false, align: 'right', search: true}
3981+
],
3982+
data: eventsData,
3983+
datatype: 'local',
3984+
rowNum: 100,
3985+
autowidth: true,
3986+
width: '1000',
3987+
height: 'auto',
3988+
rowList: [25, 50, 100, 500],
3989+
pager: $('#pager-events'),
3990+
sortname: 'timestamp',
3991+
viewrecords: true,
3992+
sortorder: 'desc',
3993+
caption: _('Events'),
3994+
3995+
}).navGrid('#pager-events', {
3996+
search: false,
3997+
edit: false,
3998+
add: false,
3999+
del: false,
4000+
refresh: false
4001+
})/*.jqGrid('navButtonAdd', '#pager-events', {
4002+
caption: '',
4003+
buttonicon: 'ui-icon-refresh',
4004+
onClickButton: () => {
4005+
$gridEvents.trigger('reloadGrid');
4006+
},
4007+
position: 'first',
4008+
id: 'refresh-events',
4009+
title: _('Refresh'),
4010+
cursor: 'pointer'
4011+
})*/.jqGrid('filterToolbar', {
4012+
defaultSearch: 'cn',
4013+
autosearch: true,
4014+
searchOnEnter: false,
4015+
enableClear: true
4016+
})
4017+
}
4018+
39314019
// Service Messages
39324020
function initGridMessages() {
39334021
$gridMessages.jqGrid({
@@ -4604,10 +4692,10 @@ function resizeGrids() {
46044692
y = 600;
46054693
}
46064694

4607-
$('#grid-devices, #grid-links, #grid-messages').setGridHeight(y - 144).setGridWidth(x - 18);
4695+
$('#grid-devices, #grid-links, #grid-messages, #grid-events').setGridHeight(y - 144).setGridWidth(x - 18);
46084696

4609-
$('#grid-events').css('height', (y - 80) + 'px').css('width', (x - 18) + 'px');
4610-
$('#grid-events-inner').css('height', (y - 100) + 'px');
4697+
// $('#grid-events').css('height', (y - 80) + 'px').css('width', (x - 18) + 'px');
4698+
// $('#grid-events-inner').css('height', (y - 100) + 'px');
46114699
$('#grid-interfaces')/* .setGridHeight(y - 99) */.setGridWidth(x - 18);
46124700
$('#grid-rssi').setGridHeight(y - (173 + $('#gbox_grid-interfaces').height())).setGridWidth(x - 18);
46134701

@@ -4784,3 +4872,14 @@ function convertHmIPKeyBase32ToBase16(valueString) {
47844872

47854873
return keyString.toUpperCase();
47864874
}
4875+
4876+
4877+
function ts() {
4878+
const timestamp = new Date();
4879+
return timestamp.getFullYear() + '-' +
4880+
('0' + (timestamp.getMonth() + 1).toString(10)).slice(-2) + '-' +
4881+
('0' + (timestamp.getDate()).toString(10)).slice(-2) + ' ' +
4882+
('0' + (timestamp.getHours()).toString(10)).slice(-2) + ':' +
4883+
('0' + (timestamp.getMinutes()).toString(10)).slice(-2) + ':' +
4884+
('0' + (timestamp.getSeconds()).toString(10)).slice(-2);
4885+
}

0 commit comments

Comments
 (0)