-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from joelkoz/config-UI
Config ui
- Loading branch information
Showing
42 changed files
with
768 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Import("env") | ||
|
||
def make_c_header(inName, outName): | ||
|
||
print 'Writing ',inName,' to src/net/web/',outName,'.h' | ||
|
||
infile = open('web/docroot/' + inName, "r") | ||
outfile = open("src/net/web/" + outName + ".h","w") | ||
|
||
outfile.write("#include <pgmspace.h>\n") | ||
outfile.write("const char PAGE_") | ||
outfile.write(outName) | ||
outfile.write("[] PROGMEM = R\"=====(\n") | ||
|
||
for line in infile: | ||
outfile.write(line) | ||
|
||
outfile.write("\n)=====\";\n") | ||
|
||
infile.close() | ||
outfile.close() | ||
|
||
|
||
def build_webUI(*args, **kwargs): | ||
env.Execute("terser --compress --output web/docroot/js/sensesp.min.js -- web/docroot/js/sensesp.js") | ||
make_c_header("js/sensesp.min.js", "js_sensesp") | ||
make_c_header("js/jsoneditor.min.js", "js_jsoneditor") | ||
make_c_header("index.html", "index") | ||
make_c_header("setup/index.html", "setup") | ||
|
||
env.AlwaysBuild(env.Alias("webUI", None, build_webUI)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <pgmspace.h> | ||
const char PAGE_index[] PROGMEM = R"=====( | ||
<html> | ||
<head> | ||
<title>SensESP SignalK Sensor</title> | ||
</head> | ||
<body> | ||
<h1>SensESP SignalK Sensor</h1> | ||
Your options: | ||
<ul> | ||
<li><a href="/info">Device information</a></li> | ||
<li><a href="/setup">Configure device</a></li> | ||
<li><a href="/device/restart" onclick="return confirm('Restart the device?')">Restart sensor</a></li> | ||
<li><a href="/device/reset" onclick="return confirm('Are you sure you want to reset device to factory settings?')">Reset sensor</a></li> | ||
</ul> | ||
</body> | ||
</html> | ||
|
||
)====="; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include <pgmspace.h> | ||
const char PAGE_js_sensesp[] PROGMEM = R"=====( | ||
function ajax(method,url,data,contentType){return new Promise(function(resolve,reject){var request=new XMLHttpRequest;request.open(method,url,!0),request.onload=function(){200===request.status?resolve(request.response):reject(Error(request.statusText))},request.onerror=function(){reject(Error("Network Error"))},contentType&&request.setRequestHeader("Content-Type",contentType),request.send(data)})}class TreeList{constructor(main,pathList){this.main=main,this.main.appendChild(document.createElement("div")),this.root=document.createElement("ul"),this.root.id="tree",this.main.appendChild(this.root);for(var i=0;i<pathList.length;i++){var entry=pathList[i],fullPath=entry,parts=entry.split("/"),nodeName=parts.pop(),section=this.main;for(parts.shift();parts.length>0;){var sectionName=parts.shift();section=this.findNode(section,sectionName)}this.addEntry(section,nodeName,fullPath)}var toggler=document.getElementsByClassName("caret");for(i=0;i<toggler.length;i++)toggler[i].addEventListener("click",function(){this.parentElement.querySelector(".nested").classList.toggle("active"),this.classList.toggle("caret-down")})}makeSectionNode(name){var section=document.createElement("li"),caret=document.createElement("span");caret.className="caret",caret.innerHTML=name,section.appendChild(caret);var ul=document.createElement("ul");return ul.className="nested",section.appendChild(ul),section}addEntry(section,name,fullPath){var entry=document.createElement("li");entry.innerHTML=name,section.children[1].appendChild(entry),entry.className="selectable",entry.addEventListener("click",function(){editConfig(fullPath)})}findNode(sectionRoot,nodeName){if(""!=nodeName){var i,nextEntry,searchChildren=sectionRoot.children[1].childNodes;for(i=0;i<searchChildren.length;i++)if((nextEntry=searchChildren[i]).childNodes[0].textContent==nodeName)return nextEntry;return nextEntry=this.makeSectionNode(nodeName),sectionRoot.children[1].appendChild(nextEntry),nextEntry}return sectionRoot}}var globalEditor=null;function getEmptyMountDiv(){var main=document.getElementById("mountNode");return main.empty(),globalEditor=null,main}function editConfig(config_path){var main=getEmptyMountDiv();ajax("GET","/config"+config_path).then(response=>{var json=JSON.parse(response),config=json.config,schema=json.schema;if(0==Object.keys(schema).length)return alert(`No schema available for ${config_path}`),void showConfigTree();schema.title||(schema.title=`Configuration for ${config_path}`),main.innerHTML="\n <div class='row'>\n <div id='editor_holder' class='medium-12 columns'></div> \n </div>\n <div class='row'>\n <div class='medium-12-columns'>\n <button id='submit' class='tiny'>Save</button>\n <button id='cancel' class='tiny'>Cancel</button>\n <span id='valid_indicator' class='label'></span>\n </div>\n </div>\n ",globalEditor=new JSONEditor(document.getElementById("editor_holder"),{schema:schema,startval:config,no_additional_properties:!0,disable_collapse:!0,disable_properties:!0,disable_edit_json:!0,show_opt_in:!0}),document.getElementById("submit").addEventListener("click",function(){saveConfig(config_path,globalEditor.getValue())}),document.getElementById("cancel").addEventListener("click",function(){showConfigTree()}),globalEditor.on("change",function(){var errors=globalEditor.validate(),indicator=document.getElementById("valid_indicator");errors.length?(indicator.className="label alert",indicator.textContent="not valid"):(indicator.className="label success",indicator.textContent="valid")})}).catch(err=>{alert(`Error retrieving configuration ${config_path}: ${err.message}`),showConfigTree()})}function saveConfig(config_path,values){ajax("PUT","/config"+config_path,JSON.stringify(values),"application/json").then(response=>{showConfigTree()}).catch(err=>{alert(`Error saving configuration ${config_path}: ${err.message}`),showConfigTree()})}function showConfigTree(){var main=getEmptyMountDiv();ajax("GET","/config").then(response=>{var configList=JSON.parse(response).keys;return configList.sort(),configList}).then(configList=>{new TreeList(main,configList)}).catch(err=>{alert("Error: "+err.statusText)})}Element.prototype.empty=function(){for(var child=this.lastElementChild;child;)this.removeChild(child),child=this.lastElementChild}; | ||
)====="; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <pgmspace.h> | ||
const char PAGE_setup[] PROGMEM = R"=====( | ||
<html> | ||
<head> | ||
<title>Configure SensESP Sensor</title> | ||
|
||
<style> | ||
/* Remove default bullets */ | ||
ul, #tree { | ||
list-style-type: none; | ||
} | ||
|
||
/* Remove margins and padding from the parent ul */ | ||
#tree { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
/* Style the caret/arrow */ | ||
.caret, .selectable { | ||
cursor: pointer; | ||
user-select: none; /* Prevent text selection */ | ||
} | ||
|
||
|
||
/* Create the caret/arrow with a unicode, and style it */ | ||
.caret::before { | ||
content: "\25B6"; | ||
color: black; | ||
display: inline-block; | ||
margin-right: 6px; | ||
} | ||
|
||
/* Rotate the caret/arrow icon when clicked on (using JavaScript) */ | ||
.caret-down::before { | ||
transform: rotate(90deg); | ||
} | ||
|
||
/* Hide the nested list */ | ||
.nested { | ||
display: none; | ||
} | ||
|
||
/* Show the nested list when the user clicks on the caret/arrow (with JavaScript) */ | ||
.active { | ||
display: block; | ||
} | ||
</style> | ||
|
||
<script src="/js/jsoneditor.min.js"></script> | ||
<script src="/js/sensesp.js"></script> | ||
</head> | ||
|
||
<body onload="showConfigTree()"> | ||
<h1>SensESP Sensor</h1> | ||
<div id="mountNode"> | ||
</div> | ||
</body> | ||
</html> | ||
|
||
)====="; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.