Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
updates for settings page in web UI
  • Loading branch information
jgyates authored Feb 11, 2018
1 parent b9fcc80 commit a23f018
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
9 changes: 7 additions & 2 deletions static/genmon.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
Expand Down Expand Up @@ -42,6 +42,11 @@ table {
border-collapse: collapse;
border-spacing: 0;
}
input {
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* END RESET*/
body {
font-size: 18px;
Expand Down Expand Up @@ -97,7 +102,7 @@ div {
margin-top: 10px;
}

#setexercisebutton{
#setexercisebutton, #setsettingsbutton{
font-weight: bold;
font-family: Arial;
font-size: 16px;
Expand Down
93 changes: 92 additions & 1 deletion static/genmon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ document.getElementById("navMenu").innerHTML =
'<li><a id="outage" >Outage</a></li> ' +
'<li><a id="logs" >Logs</a></li> ' +
'<li ><a id="monitor" >Monitor</a></li> ' +
'<li ><a id="settings" >Settings</a></li> ' +
'</ul>' ;

// global base state
Expand Down Expand Up @@ -512,6 +513,90 @@ function SetExerciseChoice(bSetRadio){

}

//*****************************************************************************
// Display the Settings Tab
//*****************************************************************************
function DisplaySettings(){

var url = baseurl.concat("settings");
$.getJSON(url,function(result){

var outstr = "Settings:<br><br><form id=\"formSettings\"><table border=\"0\">";
// var outstr = JSON.stringify(result, null, 4);
// outstr = replaceAll(outstr,'\n','<br/>')
// outstr = replaceAll(outstr,' ','&nbsp')
var settings = getSortedKeys(result);
for (var index = 0; index < settings.length; ++index) {
var key = settings[index];
outstr += "<tr><td style=\"padding: 5px;\"> "+result[key][1]+"</td><td style=\"padding: 5px;\">";
switch (result[key][0]) {
case "string":
outstr += "<input style=\"width: 400px;\" name=\"" + key + "\" type=\"text\" value=\"" + result[key][3] + "\">";
break;
case "int":
outstr += "<input name=\"" + key + "\" type=\"text\" value=\"" + result[key][3] + "\">";
break;
case "boolean":
outstr += "<input name=\"" + key + "\" type=\"checkbox\" value=\"true\" " + ((typeof result[key][3] !== 'undefined') && (result[key][3].toLowerCase() == "true") ? "checked" : "") + ">";
break;
default:
break;
}
outstr += "</td>";
}
outstr += "</table></form>";
outstr += "<button id=\"setsettingsbutton\" onClick=\"saveSettings()\">Save</button>";
document.getElementById("mydisplay").innerHTML = outstr;

});

}

function getSortedKeys(obj) {
var keys = []; for (var key in obj) keys.push(key);
return keys.sort(function(a,b){return obj[a][2]-obj[b][2]});
}

//*****************************************************************************
// called when Save Settings is clicked
//*****************************************************************************
function saveSettings(){

var DisplayStr = "Save settings? Note: Genmon must be restarted for this change to take effect.";

var r = confirm(DisplayStr);
if (r == false) {
return
}

try {
var fields = $('#formSettings').serialize();

// include unchecked checkboxes. use filter to only include unchecked boxes.
$.each($('#formSettings input[type=checkbox]').filter(function(idx){
return $(this).prop('checked') === false
}),
function(idx, el){
// attach matched element names to the formData with a chosen value.
var emptyVal = "false";
fields += '&' + $(el).attr('name') + '=' + emptyVal;
}
);

// save settings
var url = baseurl.concat("setsettings");
$.getJSON( url,
{setsettings: fields},
function(result){
});

}
catch(err) {
alert("Error: invalid selection");
}
}


//*****************************************************************************
// called when menu is clicked
//*****************************************************************************
Expand All @@ -538,6 +623,10 @@ function MenuClick(e)
SetExerciseChoice(true)
}
break;
case "settings":
window.scrollTo(0,0);
menuElementID = e.target;
DisplaySettings();
default:
break;
}
Expand Down Expand Up @@ -650,7 +739,9 @@ function GetHeaderValues()
//*****************************************************************************
function UpdateDisplay()
{
GetDisplayValues(menuElementID.id);
if (menuElementID.id != "settings") {
GetDisplayValues(menuElementID.id);
}
}

//*****************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<!-- Menu -->
<header id="myheader"></header>
<nav id="navMenu"></nav>
<script type="text/javascript" src="genmon.js?version=2.099"></script>
<script type="text/javascript" src="genmon.js?version=2.101"></script>
<!-- <script src="http://code.jquery.com/jquery-1.12.4.min.js"></script> -->
<script src="jquery-1.12.4.min.js"></script>
<link rel="stylesheet" type="text/css" href="genmon.css?version=1.444">
<link rel="stylesheet" type="text/css" href="genmon.css?version=1.445">
<link rel="icon" href="favicon.ico">
</head>

Expand Down

0 comments on commit a23f018

Please sign in to comment.