Bug fix - some values weren't passed back in the command call - release

This commit is contained in:
Sebastien
2020-09-08 16:46:50 -04:00
parent 6195750b41
commit 573ddb6fda
3 changed files with 174 additions and 135 deletions

View File

@@ -1024,34 +1024,37 @@ function checkStatus(){
function runCommand(button,reboot) {
pardiv = button.parentNode.parentNode;
fields=document.getElementById("flds-"+button.value);
cmdstring=button.value+' ';
cmdstring = button.attributes.cmdname.value;
fields=document.getElementById("flds-"+cmdstring);
cmdstring+=' ';
if(fields){
hint = pardiv.hint;
allfields=fields.getElementsByTagName("input");
allfields=fields.querySelectorAll("select,input");
for (i = 0; i < allfields.length; i++) {
attr=allfields[i].attributes;
qts='';
opt='';
optspacer=' ';
if (attr.longopts.value!== "undefined"){
opt+= '--' + attr.longopts.value;
optspacer='=';
}
else if(attr.shortopts.value!== "undefined"){
opt= '-' + attr.shortopts.value;
}
if(attr.hasvalue.value== "true" ){
if(allfields[i].value!=''){
qts = (/\s/.test(allfields[i].value))?'"':'';
cmdstring+=opt+optspacer+qts +allfields[i].value +qts+ ' ';
isSelect=allfields[i].attributes?.class?.value=="custom-select";
if(( isSelect && allfields[i].selectedIndex != 0 )|| !isSelect ){
if (attr.longopts.value!== "undefined"){
opt+= '--' + attr.longopts.value;
optspacer='=';
}
else if(attr.shortopts.value!== "undefined"){
opt= '-' + attr.shortopts.value;
}
if(attr.hasvalue.value== "true" ){
if(allfields[i].value!=''){
qts = (/\s/.test(allfields[i].value))?'"':'';
cmdstring+=opt+optspacer+qts +allfields[i].value +qts+ ' ';
}
}
else {
// this is a checkbox
if(allfields[i].checked) cmdstring+=opt+ ' ';
}
}
else {
// this is a checkbox
if(allfields[i].checked) cmdstring+=opt+ ' ';
}
}
}
@@ -1093,6 +1096,7 @@ function runCommand(button,reboot) {
},
complete: function(response) {
console.log('reboot call completed');
getCommands();
}
});
}
@@ -1106,77 +1110,94 @@ function getCommands() {
$.getJSON("/commands.json", function(data) {
console.log(data);
var advancedtabhtml='';
data.commands.forEach(function(command) {
isConfig=($('#'+command.name+'-list').length>0);
innerhtml='';
innerhtml+='<tr><td>'+(isConfig?'<h1>':'');
innerhtml+=escapeHTML(command.help).replace(/\n/g, '<br />')+(isConfig?'</h1>':'<br>');
innerhtml+='<div >';
if(command.hasOwnProperty("argtable")){
innerhtml+='<table class="table table-hover" id="flds-'+command.name+'"><tbody>';
command.argtable.forEach(function (arg){
placeholder=arg?.datatype || '';
ctrlname=command.name+'-'+arg.longopts;
curvalue=data.values?.[command.name]?.[arg.longopts] || '';
innerhtml+="<tr>";
var attributes ='datatype="'+arg.datatype+'" ';
attributes+='hasvalue='+arg.hasvalue+' ';
attributes+='longopts="'+arg.longopts+'" ';
attributes+='shortopts="'+arg.shortopts+'" ';
attributes+='checkbox='+arg.checkbox+' ';
if(placeholder.includes('|')){
placeholder = placeholder.replace('<','').replace('>','');
innerhtml+='<td><select name="'+ctrlname+'" ';
innerhtml+=attributes;
innerhtml+=' class="custom-select">';
innerhtml+='<option '+(curvalue.length>0?'value':'selected')+'>'+arg.glossary+'</option>'
placeholder.split('|').forEach(function(choice){
innerhtml+='<option '+(curvalue.length>0&&curvalue==choice?'selected':'value')+'="'+choice+'">'+choice+'</option>';
});
innerhtml+='</select></td>';
}
else {
ctrltype="text";
if(arg.checkbox){
ctrltype="checkbox";
}
innerhtml+='<td><label for="'+ctrlname+'">'+ arg.glossary+'</label></td>';
innerhtml+='<td><input type="'+ctrltype+'" id="'+ctrlname+'" name="'+ctrlname+'" placeholder="'+placeholder+'" hasvalue="'+arg.hasvalue+'" ';
innerhtml+=attributes;
if(arg.checkbox){
if(data.values?.[command.name]?.[arg.longopts] ){
innerhtml+='checked ';
}
if($("#flds-"+command.name).length == 0){
isConfig=($('#'+command.name+'-list').length>0);
innerhtml='';
innerhtml+='<tr><td>'+(isConfig?'<h1>':'');
innerhtml+=escapeHTML(command.help).replace(/\n/g, '<br />')+(isConfig?'</h1>':'<br>');
innerhtml+='<div >';
if(command.hasOwnProperty("argtable")){
innerhtml+='<table class="table table-hover" id="flds-'+command.name+'"><tbody>';
command.argtable.forEach(function (arg){
placeholder=arg?.datatype || '';
ctrlname=command.name+'-'+arg.longopts;
curvalue=data.values?.[command.name]?.[arg.longopts] || '';
innerhtml+="<tr>";
var attributes ='datatype="'+arg.datatype+'" ';
attributes+='hasvalue='+arg.hasvalue+' ';
attributes+='longopts="'+arg.longopts+'" ';
attributes+='shortopts="'+arg.shortopts+'" ';
attributes+='checkbox='+arg.checkbox+' ';
attributes+='cmdname="'+command.name+'" ';
attributes+= 'id="'+ctrlname+'" name="'+ctrlname+'" placeholder="'+placeholder+'" hasvalue="'+arg.hasvalue+'" ';
innerhtml+='></input></td>';
if(placeholder.includes('|')){
placeholder = placeholder.replace('<','').replace('>','');
innerhtml+='<td><select ';
innerhtml+=attributes;
innerhtml+=' class="custom-select">';
innerhtml+='<option '+(curvalue.length>0?'value':'selected')+'>'+arg.glossary+'</option>'
placeholder.split('|').forEach(function(choice){
innerhtml+='<option '+(curvalue.length>0&&curvalue==choice?'selected':'value')+'="'+choice+'">'+choice+'</option>';
});
innerhtml+='</select></td>';
}
else {
innerhtml+='value="'+curvalue+'" ';
innerhtml+='></input></td>'+ curvalue.length>0?'<td>last: '+curvalue+'</td>':'';
ctrltype="text";
if(arg.checkbox){
ctrltype="checkbox";
}
innerhtml+='<td><label for="'+ctrlname+'">'+ arg.glossary+'</label></td>';
innerhtml+='<td><input type="'+ctrltype+'"';
innerhtml+=attributes;
if(arg.checkbox){
if(data.values?.[command.name]?.[arg.longopts] ){
innerhtml+='checked ';
}
innerhtml+='></input></td>';
}
else {
innerhtml+='value="'+curvalue+'" ';
innerhtml+='></input></td>'+ curvalue.length>0?'<td>last: '+curvalue+'</td>':'';
}
}
}
innerhtml+="</tr>";
});
innerhtml+='</tbody></table>';
}
if(isConfig){
innerhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-success" value="Save" onclick="runCommand(this,false);">';
innerhtml+='<input id="btn-'+ command.name + '-apply" type="button" class="btn btn-success" value="Apply" onclick="runCommand(this,true);"></div></div><td></tr>';
$('#'+command.name+'-list').append(innerhtml);
}
else {
advancedtabhtml+='<br>'+innerhtml;
advancedtabhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-danger btn-sm" value="'+command.name+'" onclick="runCommand(this);"></div></div><td></tr>';
}
});
innerhtml+="</tr>";
});
innerhtml+='</tbody></table>';
}
if(isConfig){
innerhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-success" cmdname="'+command.name+'" value="Save" onclick="runCommand(this,false);">';
innerhtml+='<input id="btn-'+ command.name + '-apply" type="button" class="btn btn-success" cmdname="'+command.name+'" value="Apply" onclick="runCommand(this,true);"></div></div><td></tr>';
$('#'+command.name+'-list').append(innerhtml);
}
else {
advancedtabhtml+='<br>'+innerhtml;
advancedtabhtml+='<div class="buttons"><input id="btn-'+ command.name + '" type="button" class="btn btn-danger btn-sm" cmdname="'+command.name+'" value="'+command.name+'" onclick="runCommand(this);"></div></div><td></tr>';
}
}
});
$("#commands-list").append(advancedtabhtml);
data.commands.forEach(function(command) {
if(command.hasOwnProperty("argtable")){
command.argtable.forEach(function (arg){
ctrlselector='#'+command.name+'-'+arg.longopts;
if(arg.checkbox){
$(ctrlselector)[0].checked=data.values?.[command.name]?.[arg.longopts];
}
else {
$(ctrlselector)[0].value=data.values?.[command.name]?.[arg.longopts] || '';
}
});
}
});
})
.fail(function(xhr, ajaxOptions, thrownError) {
@@ -1244,7 +1265,6 @@ function getConfig() {
});
}
function showMessage(message, severity, age=0) {
if (severity == 'MESSAGING_INFO') {
$('#message').css('background', '#6af');
@@ -1255,7 +1275,7 @@ function showMessage(message, severity, age=0) {
} else {
$('#message').css('background', '#f00');
}
$('#message').html(message);
return new Promise(function(resolve, reject) {
$("#content").fadeTo("slow", 0.3, function() {
@@ -1274,5 +1294,5 @@ function inRange(x, min, max) {
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
return new Promise(resolve => setTimeout(resolve, ms));
}

View File

@@ -68,7 +68,7 @@
<a class="nav-link" data-toggle="tab" href="#tab-firmware">Firmware</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-setdisplay">Display</a>
<a class="nav-link" data-toggle="tab" href="#tab-setdisplay">Configuration</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-syslog">Syslog</a>
@@ -83,8 +83,7 @@
<a class="nav-link" data-toggle="tab" href="#tab-credits">Credits</a>
</li>
</ul>
<div id="message"></div>
<div id="message"></div>
<div id="content">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active show" id="tab-wifi">
@@ -199,10 +198,9 @@
</div>
</div> <!-- wifi -->
<div class="tab-pane fade" id="tab-setdisplay">
<table class="table table-hover" id="setdisplay-table">
<tbody id="setdisplay-list">
</tbody>
</table>
<table class="table table-hover" id="setdisplay-table"><tbody id="setdisplay-list"></tbody></table>
<table class="table table-hover" id="i2cconfig-table"><tbody id="i2cconfig-list"></tbody></table>
<table class="table table-hover" id="spiset-table"><tbody id="spiset-list"></tbody></table>
</div> <!-- display -->
<div class="tab-pane fade" id="tab-audio">