Remove group prefix when showing params in web interface

Make groups collapsable
This commit is contained in:
Florian Festi 2016-10-31 22:08:23 +01:00
parent c816de811b
commit 6d39db75e1
1 changed files with 23 additions and 4 deletions

View File

@ -74,12 +74,16 @@ class BServer:
def __init__(self): def __init__(self):
self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface} self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface}
def arg2html(self, a): def arg2html(self, a, prefix):
name = a.option_strings[0].replace("-", "") name = a.option_strings[0].replace("-", "")
if isinstance(a, argparse._HelpAction): if isinstance(a, argparse._HelpAction):
return "" return ""
viewname = name
if prefix and name.startswith(prefix + '_'):
viewname = name[len(prefix)+1:]
row = """<tr><td>%s</td><td>%%s</td><td>%s</td></tr>\n""" % \ row = """<tr><td>%s</td><td>%%s</td><td>%s</td></tr>\n""" % \
(name, a.help or "") (viewname, a.help or "")
if (isinstance(a, argparse._StoreAction) and if (isinstance(a, argparse._StoreAction) and
isinstance(a.type, boxes.ArgparseEdgeType)): isinstance(a.type, boxes.ArgparseEdgeType)):
input = a.type.html(name, a.default) input = a.type.html(name, a.default)
@ -111,6 +115,18 @@ class BServer:
</style> </style>
<script type="text/javascript">
function showHide(id) {
var e = document.getElementById(id);
if(e.style.display == null || e.style.display == "none") {
e.style.display = "block";
} else {
e.style.display = "none";
}
}
</script>
</head> </head>
<body> <body>
@ -143,14 +159,17 @@ flex cuts, holes and slots for screws and more high level functions.
<p>""", box.__doc__ or "", """</p> <p>""", box.__doc__ or "", """</p>
<form action="%s" method="GET" target="_blank"> <form action="%s" method="GET" target="_blank">
""" % (action)] """ % (action)]
groupid = 0
for group in box.argparser._action_groups[2:] + box.argparser._action_groups[:2]: for group in box.argparser._action_groups[2:] + box.argparser._action_groups[:2]:
groupid += 1
if not group._group_actions: if not group._group_actions:
continue continue
result.append("<h3>%s</h3>\n<table>\n" % group.title) prefix = getattr(group, "prefix", None)
result.append('<h3 onclick="showHide(%s)">%s ></h3>\n<table id="%s">\n' % (groupid, group.title, groupid))
for a in group._group_actions: for a in group._group_actions:
if a.dest in ("input", "output"): if a.dest in ("input", "output"):
continue continue
result.append(self.arg2html(a)) result.append(self.arg2html(a, prefix))
result.append("</table>") result.append("</table>")
result.append(""" result.append("""
<p><button name="render" value="1">Generate</button></p> <p><button name="render" value="1">Generate</button></p>