mirror of
https://github.com/TangentFoxy/lovebird.git
synced 2025-07-28 19:12:19 +00:00
Replaced page "tree" with "env.json" + javascript
This commit is contained in:
109
lovebird.lua
109
lovebird.lua
@@ -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 ●");
|
updateDivContent("status", "connected ●");
|
||||||
@@ -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,42 +259,28 @@ 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
|
||||||
<?lua for x in p:gmatch("[^%.]+") do ?>
|
local keys = {}
|
||||||
<?lua acc = acc .. "." .. x ?>
|
for k in pairs(t) do table.insert(keys, k) end
|
||||||
<a href="#" onclick="onTreeLink('<?lua echo(acc)?>')">
|
table.sort(keys)
|
||||||
<?lua echo(x) ?>
|
for _, k in pairs(keys) do
|
||||||
</a>
|
local v = t[k]
|
||||||
<?lua end ?>
|
?>
|
||||||
</div>
|
{
|
||||||
|
"key": "<?lua echo(k) ?>",
|
||||||
<table>
|
"value": <?lua echo(
|
||||||
<?lua
|
string.format("%q",
|
||||||
local keys = {}
|
lovebird.truncate(
|
||||||
for k in pairs(t) do table.insert(keys, k) end
|
lovebird.htmlescape(
|
||||||
table.sort(keys)
|
tostring(v)), 26))) ?>,
|
||||||
for _, k in pairs(keys) do
|
"type": "<?lua echo(type(v)) ?>",
|
||||||
local v = t[k]
|
},
|
||||||
?>
|
<?lua end ?>
|
||||||
<tr>
|
]
|
||||||
<td>
|
}
|
||||||
<?lua if type(v) == "table" then ?>
|
|
||||||
<a href="#" onclick="onTreeLink('<?lua echo(p.."."..k)?>')">
|
|
||||||
<?lua echo(k) ?>
|
|
||||||
</a>
|
|
||||||
<?lua else ?>
|
|
||||||
<?lua echo(k) ?>
|
|
||||||
<?lua end ?>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<?lua echo(lovebird.htmlescape(lovebird.truncate(tostring(v), 30))) ?>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<?lua end ?>
|
|
||||||
</table>
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user