cleanup iforte index

This commit is contained in:
2023-03-03 01:01:31 +01:00
parent 8462977fc3
commit 7c0fd5e440
2 changed files with 172 additions and 162 deletions

View File

@@ -1,4 +1,10 @@
$(document).ready(function() {
// Sets the proper fixture name in the header and title
var fixturename = "Robin iForte - Simulated";
$('#pth').html(fixturename)
$(document).prop('title', fixturename)
$('body').prepend(generateNavBar());
var am = 0;
var mip = 0;
@@ -9,7 +15,7 @@ $(document).ready(function() {
if (href.indexOf('sensors') != -1) am = 3;
if (href.indexOf('discovery') != -1) am = (3 + mip);
$('#navbar ul li').eq(am).addClass('active');
//handle settings
$(document).on('click','#scfg',function() {
mhdr_status('');
@@ -37,62 +43,11 @@ $(document).ready(function() {
});
});
});
//periodicly get status
var bsy = false;
var ebli = 0;
var eblio = 255;
// handle RDM ident
var idntb = $('#idnt img');
function sta() {
do_ajax('/serr',{},function (json) {
// console.log(json);
dmxsnf = '';
if (json ) {
if (json['err'] == 1) ebli = 0x80;
else ebli = 0;
if (json['dmxsnf'] == 1) dmxsnf = ' [sniffing DMX]';
if (json['idnt'] == 1) idntb.addClass('a');
else idntb.removeClass('a');
if (json['dls'] && json['dls'] == 1) {
$('.snz').show();
}
} else if (json == undefined) {
ebli = 0x40;
} else ebli = 0;
bsy = false;
});
}
setInterval(function() {
if (!bsy) {
bsy = true;
sta();
}
},3000);
sta();
setInterval(function() {
if (ebli == eblio) return;
var opre = pre;
if (ebli & 0x80) {
ebli ^= 0x01;
if (ebli & 0x01) pre = '(!) ';
$('#pth').removeClass('stou');
$('#pth').addClass('serr');
} else if (ebli & 0x40) {
ebli ^= 0x01;
if (ebli & 0x01) pre = '(?) ';
$('#pth').removeClass('serr');
$('#pth').addClass('stou');
} else {
ebli = 0;
$('#pth').removeClass('serr stou');
pre = '';
}
//$('#pt_v').html(pre + $('#pth').data('title') + dmxsnf);
if (opre != pre) ptit('');
eblio = ebli;
},1000);
$('#idnt').click(function() {
idntb.toggleClass('a');
do_ajax('/rdmi',{s:idntb.hasClass('a') ? 1:0},function(json) {});
});
});
@@ -115,38 +70,26 @@ function get_cookie(n,d,ti=false) {
}
function mhdr_status(c) {
if (c.length == 0) $('#cfg-modal .modal-header').removeClass('suc err');
else $('#cfg-modal .modal-header').addClass(c);
}
function loader(a) {
if (a) $('#cfg-modal .modal-header img').addClass('loader');
function loader(showheader) {
if (showheader) $('#cfg-modal .modal-header img').addClass('loader');
else $('#cfg-modal .modal-header img').removeClass('loader');
}
function do_ajax(p_url,p_data,f,i = -1,a = true) {
$.ajax({
url: p_url,
type: 'POST',
data: p_data,
dataType: 'json',
async: a,
success: function (json) {
f(json,i);
},
error: function () {
// console.log('do_ajax error');
f();
},
timeout:2000
});
console.log("url : " + p_url);
console.log("data : " + p_data);
console.log("callback function : " + f);
console.log("callback params : " + i);
console.log("async : " + a);
}
function copy_form_values(dir) {
function copy_form_values(dir) {
$('#m-b input:text, #m-b input[type=range]').each(function() {
var id = $(this).attr('id');
if (dir == 0) $('#' + id + '_v').html($('#' + id).val());
@@ -170,7 +113,7 @@ function copy_form_values(dir) {
} else {
if ($(this).is(':checked')) $('#' + id + '_v').html(label);
}
});
if (dir == 1) {
$('#m-b div.form-group').each(function() {
@@ -183,14 +126,14 @@ function copy_form_values(dir) {
}
function fill_values(d,ids) {
for (i = 0; i < ids.length; i++) {
$('#' + ids[i] + '_v').html(d[ids[i]]);
}
}
function show_errors(s,ids) {
if (s) mhdr_status('err');
for (i = 0; i < ids.length; i++) {
if (s & (1 << i)) $('#' + ids[i]).addClass('is-invalid').removeClass('is-valid');
@@ -207,9 +150,9 @@ function close_modal() {
}
function pv(p) {
var s = '';
for (var i in p) {
var o = p[i];
if (i == 0) s += o + '=';
@@ -217,12 +160,12 @@ function pv(p) {
if ($('#' + o).val() != undefined) s += $('#' + o).val();
else if ($('input[name=' + o + ']:checked').val() != undefined) s += $('input[name=' + o + ']:checked').val();
}
return s;
}
function c_txt(n,t,e,c = '',it = 'text') {
var html = '<div class="form-group' + c + '">';
html += '<label for="' + n + '" class="col-form-label">' + t + '</label>';
html += '<input type="'+ it +'" class="form-control" id="' + n + '">';
@@ -233,12 +176,12 @@ function c_txt(n,t,e,c = '',it = 'text') {
}
function c_btn(t,v,c) {
return '<button class="btn btn-primary btn-block' + c + '" value="' + v + '">' + t + '</button>';
}
function c_opt(n,t,o,pl,vp,lp,e) {
var html = '<div class="form-group">';
html += '<label for="' + n + '" class="col-form-label">' + t + '</label>';
html += '<select class="form-control" id="' + n + '">';
@@ -252,12 +195,12 @@ function c_opt(n,t,o,pl,vp,lp,e) {
html += '</select>';
html += e.length > 0 ? '<div class="invalid-feedback">' + e + '</div>' : '';
html += '</div>';
return html;
}
function c_rad(n,t,r,e,c) {
var html = '<div class="form-group' + c + '">';
html += '<legend class="col-form-label">' + t + '</legend>';
for (i = 0; i < r.length; i++) {
@@ -268,12 +211,12 @@ function c_rad(n,t,r,e,c) {
}
html += e.length > 0 ? '<div class="invalid-feedback">' + e + '</div>' : '';
html += '</div>';
return html;
}
function box(t,id,p,su = '',vid = '',bc = '') {
var s = '';
s += '<div class="col-md-6 col-xl-4 box-c' + bc + '">';
@@ -310,7 +253,7 @@ function box(t,id,p,su = '',vid = '',bc = '') {
function generateNavBar() {
var o = '<nav class="navbar fixed-top navbar-expand-md navbar-dark bg-dark">';
o += '<div class="container">';
o += '<a class="navbar-brand" href="./index.html"><img src="../files/robe_logo_white.svg"></a>';
o += '<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar">';
@@ -326,12 +269,12 @@ function generateNavBar() {
o += '</li>';
o += '<li class="nav-item">';
o += '<a class="nav-link" href="./logs.html">Logs</a>';
o += '</li>';
o += '<li class="nav-item snz">';
o += '<a class="nav-link" href="./sensors.html">RAINS logs</a>';
o += '</li>';
o += '<li class="nav-item">';
o += '<a class="nav-link" href="./discovery.html">Discovery</a>';
o += '</li>';
@@ -342,18 +285,11 @@ function generateNavBar() {
o += '<a class="nav-link" href="#" id="idnt"><img class="rdmi" src="../files/identify.svg"></a>';
o += '</li>';
o += '</ul>';
o += '</div>';
o += '</div>';
o += '</nav>';
o += '<div class="fixed-top text-center device-label" id="pth"></div>';
o += '<div class="container-fluid in">';
o += '<h1></h1>';
o += '<div class="row" id="boxes"></div>';
o += '</div>';
o += '<div id="cfg-modal" class="modal fade" tabindex="-1" role="dialog">';
o += '<div class="modal-dialog" role="document">';
o += '<div class="modal-content">';
@@ -372,7 +308,7 @@ function generateNavBar() {
o += '</div>';
o += '</div>';
o += '</div>';
return o;
}
@@ -381,21 +317,21 @@ var pre = '';
var dmxsnf = '';
function ptit(t) {
// console.log('setting title to ' + t);
// console.log('setting title to ' + t);
if (t == $('#pth').data('title')) return;
// console.log('set');
// console.log('set');
if (t.length) $('#pth').data('title',t);
$('#pth').html($('#pth').data('title') + dmxsnf);
$('#pt_v').html(pre + $('#pth').html());
// console.log($('#pth').html());
// console.log($('#pth').html());
}
function c_dt(n,t,e,c,it) {
var html = '<div class="form-group' + c + '">';
html += '<label for="' + n + '" class="col-form-label">' + t + '</label>';
html += '</div><div class="form-group' + c + '">';
@@ -407,7 +343,7 @@ function c_dt(n,t,e,c,it) {
}
function c_fsens(i,t,u) {
var html = '';
html += '<div class="form-row">';
html += '<div class="form-group col-auto"><label class="col-form-label" id="tl' + i + '" for="fts' + i + '">' + t + '</label></div>';
@@ -418,6 +354,6 @@ function c_fsens(i,t,u) {
html += '<div class="form-group col-auto"><input type="text" class="form-control" size="5" id="ftv' + i + '"></div>';
html += '<div class="form-group col-auto"><label class="col-form-label" for="ftv' + i + '">' + u + '</label></div>';
html += '</div>';
return html;
}