Replaced page "tree" with "env.json" + javascript

This commit is contained in:
rxi
2014-04-12 11:51:49 +01:00
parent 2638fa219a
commit 937670a92e

View File

@@ -119,12 +119,18 @@ end
position: absolute; position: absolute;
top: 40px; bottom: 0px; right: 0px; top: 40px; bottom: 0px; right: 0px;
width: 300px; width: 300px;
overflow-y: scroll;
} }
#envheader { #envheader {
padding: 5px; padding: 5px;
background: #E0E0E0; background: #E0E0E0;
} }
#envvars {
position: absolute;
left: 0px; right: 0px; top: 25px; bottom: 0px;
margin: 10px;
overflow-y: scroll;
font-size: 12px;
}
</style> </style>
</head> </head>
<body> <body>
@@ -145,7 +151,8 @@ end
</div> </div>
</div> </div>
<div id="env" class="greybordered"> <div id="env" class="greybordered">
<div id="envheader"></div>
<div id="envvars"></div>
</div> </div>
</div> </div>
<script> <script>
@@ -182,7 +189,7 @@ end
} }
scrolloutput() scrolloutput()
/* Refresh output buffer and status */ /* Output buffer and status */
var refreshOutput = function() { var refreshOutput = function() {
getPage("/buffer", function(text) { getPage("/buffer", function(text) {
updateDivContent("status", "connected &#9679;"); updateDivContent("status", "connected &#9679;");
@@ -196,14 +203,42 @@ end
} }
setInterval(refreshOutput, <?lua echo(lovebird.refreshrate) ?> * 1000); setInterval(refreshOutput, <?lua echo(lovebird.refreshrate) ?> * 1000);
/* Refresh env view */ /* Environment variable view */
var envPath = ""; var envPath = "";
var refreshEnv = function() { var refreshEnv = function() {
getPage("/tree?p=" + envPath, function(text) { getPage("/env.json?p=" + envPath, function(text) {
updateDivContent("env", text); var json = eval("(" + text + ")");
/* Header */
var html = "<a href='#' onclick=\"setEnvPath('')\">env</a>";
var acc = "";
var p = json.path != "" ? json.path.split(".") : [];
for (var i = 0; i < p.length; i++) {
acc += "." + p[i];
html += " <a href='#' onclick=\"setEnvPath('" + acc + "')\">" +
p[i] + "</a>";
}
updateDivContent("envheader", html);
/* Variables */
var html = "<table>";
for (var i = 0; json.vars[i]; i++) {
var x = json.vars[i];
var k = x.key;
if (x.type == "table") {
var p = "setEnvPath('" + json.path + "." + x.key + "');";
k = "<a href='#' onclick=\"" + p + "\">" + k + "</a>";
}
html += "<tr><td>" + k + "</td><td>" + x.value + "</td></tr>";
}
html += "</table>";
updateDivContent("envvars", html);
}); });
} }
var onTreeLink = function(p) { envPath = p; refreshEnv(); } var setEnvPath = function(p) {
envPath = p.replace(/^\.*/, "");
refreshEnv();
}
setInterval(refreshEnv, <?lua echo(lovebird.refreshrate) ?> * 1000); setInterval(refreshEnv, <?lua echo(lovebird.refreshrate) ?> * 1000);
</script> </script>
</body> </body>
@@ -214,7 +249,7 @@ end
lovebird.pages["buffer"] = [[ <?lua echo(lovebird.buffer) ?> ]] lovebird.pages["buffer"] = [[ <?lua echo(lovebird.buffer) ?> ]]
lovebird.pages["tree"] = [[ lovebird.pages["env.json"] = [[
<?lua <?lua
local t = _G local t = _G
local p = req.parsedurl.query.p or "" local p = req.parsedurl.query.p or ""
@@ -224,19 +259,9 @@ lovebird.pages["tree"] = [[
end end
end end
?> ?>
{
<div id="envheader"> "path": "<?lua echo(p) ?>",
<a href="#" onclick="onTreeLink('')">root</a> "vars": [
<?lua local acc = "" ?>
<?lua for x in p:gmatch("[^%.]+") do ?>
<?lua acc = acc .. "." .. x ?>
<a href="#" onclick="onTreeLink('<?lua echo(acc)?>')">
<?lua echo(x) ?>
</a>
<?lua end ?>
</div>
<table>
<?lua <?lua
local keys = {} local keys = {}
for k in pairs(t) do table.insert(keys, k) end for k in pairs(t) do table.insert(keys, k) end
@@ -244,22 +269,18 @@ lovebird.pages["tree"] = [[
for _, k in pairs(keys) do for _, k in pairs(keys) do
local v = t[k] local v = t[k]
?> ?>
<tr> {
<td> "key": "<?lua echo(k) ?>",
<?lua if type(v) == "table" then ?> "value": <?lua echo(
<a href="#" onclick="onTreeLink('<?lua echo(p.."."..k)?>')"> string.format("%q",
<?lua echo(k) ?> lovebird.truncate(
</a> lovebird.htmlescape(
<?lua else ?> tostring(v)), 26))) ?>,
<?lua echo(k) ?> "type": "<?lua echo(type(v)) ?>",
},
<?lua end ?> <?lua end ?>
</td> ]
<td> }
<?lua echo(lovebird.htmlescape(lovebird.truncate(tostring(v), 30))) ?>
</td>
</tr>
<?lua end ?>
</table>
]] ]]