add config editor elements to ihr web

workspace
Brendan Howell 5 years ago
parent c80f692089
commit 51a2cc9a45

@ -4,6 +4,7 @@ import configparser
import os
from bottle import Bottle, request
import mako
class IhrApp(Bottle):
def __init__(self):
@ -13,10 +14,12 @@ class IhrApp(Bottle):
self.route("/config/<bureau>", callback=self.bureau_config)
self.route("/config/<bureau>", callback=self.bureau_config, method="POST")
self.bureaus = []
self.tdir =
def index(self):
# return a list of active bureaus with links
# TODO: allow (de)activation of non-essential bureaus
templfile = "web_index.html"
out = """
<h3>The Screenless Office</h3>
<h4><em>Config Manager</em></h4>
@ -34,14 +37,18 @@ class IhrApp(Bottle):
def bureau_config(self, bureau):
# parse the config and make it into a form
out = "<h3>config file for " + bureau + "</h3>\n"
templfile = "web_config.html"
template = mako.template.Template(filename=templfile)
basedir = os.path.expanduser("~/.screenless")
if bureau == "mgmt":
cfgfile = "mgmt.ini"
mode = "ini"
elif bureau == "printers":
cfgfile = printers.cfg
cfgfile = "printers.cfg"
mode = "ini"
else:
cfgfile = bureau + ".yml"
mode = "yaml"
cfgfile = os.path.join(basedir, cfgfile)
if request.method == "POST":
#save all the request.forms stuff to the config
@ -51,8 +58,8 @@ class IhrApp(Bottle):
pass
#parse and show the config as a form
with open(cfgfile) as cfg:
out += cfg.read()
return out
cfgdata += cfg.read()
return template.render_unicode(bureau=bureau, cfgfile=cfgfile, mode=mode, cfgdata=cfgdata)
def register_bureau(self, bureau):
self.bureaus.append(bureau)

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Screenless Office - config file editor</title>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<h3>The Screenless Office</h3>
<h4> edit config file <em>$cfgfile</em></h4>
<div id="editor">$cfgdata</div>
<form id="cfgform" action="/config/$bureau" method="post">
<input type="hidden" value="$cfgdata" name="cfgdata_field" id="cfgdata_field" />
<input type="submit" value="Save" name="operation" onclick="saveConfig()">
</form>
#BUTTON
#FIELD for CFGDATA and CFGFILE
#JAVASCRIPT to confirm and submit data
<script src="/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/$mode");
function saveConfig(){
let cfgdata_field = document.getElementById("cfgdata_field");
cfgdata_field.value = editor.getValue();
if(confirm("Really overwrite $cfgfile?")){
document.forms[0].submit();
}
}
</script>
</body>
</html>
Loading…
Cancel
Save