2026-07-22 18:36:02 +02:00
|
|
|
local util = require("util")
|
|
|
|
|
|
|
|
|
|
local data = util.merge({notification=''},{ opts = app.opts })
|
2026-07-23 15:20:25 +02:00
|
|
|
data.plugins = ""
|
2026-07-22 18:36:02 +02:00
|
|
|
|
2026-07-23 15:20:25 +02:00
|
|
|
function pluginInput(opt)
|
|
|
|
|
local html = ""
|
|
|
|
|
html = html .. [[
|
|
|
|
|
<tr>
|
|
|
|
|
<td>
|
|
|
|
|
]]
|
|
|
|
|
html = html .. opt.title
|
|
|
|
|
html = html .. [[
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
]]
|
|
|
|
|
if type(opt.values) == 'table' then
|
|
|
|
|
html = html .. util.template('<select name="${key}" value="${value}">\n', {
|
|
|
|
|
key = opt.key,
|
|
|
|
|
value = app.opts[key]
|
|
|
|
|
})
|
|
|
|
|
foreach( opt.values, function(k,v)
|
|
|
|
|
html = html .. util.template('<option value="${v}">${k}</option>\n',{
|
|
|
|
|
k=k,
|
|
|
|
|
v=v
|
|
|
|
|
})
|
|
|
|
|
end)
|
|
|
|
|
html = html .. "</select>\n"
|
2026-07-22 18:36:02 +02:00
|
|
|
else
|
2026-07-23 15:20:25 +02:00
|
|
|
html = html .. util.template('<input type="text" name="${key}" value="${value}"></input>',{
|
|
|
|
|
key = opt.key,
|
|
|
|
|
value = app.opts[key]
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
html = html .. util.template([[
|
|
|
|
|
</td>
|
|
|
|
|
<td class="col3">${info}</td>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
]],opt)
|
|
|
|
|
return html
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function pluginUI(name,plugin)
|
|
|
|
|
local plugindata = util.flatten(plugin,"plugin")
|
|
|
|
|
plugindata.opts = ""
|
|
|
|
|
foreach(plugin.opts, function(k,opt)
|
|
|
|
|
plugindata.opts = plugindata.opts .. pluginInput(opt)
|
|
|
|
|
end)
|
|
|
|
|
print_r(plugindata)
|
|
|
|
|
data.plugins = data.plugins .. util.template( LoadAsset('/page/admin/plugin.html'), plugindata)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function saveData()
|
|
|
|
|
if GetMethod() == 'POST' then
|
|
|
|
|
local params = GetParams()
|
|
|
|
|
local saveconfig = false
|
|
|
|
|
foreach(params, function(k,v)
|
|
|
|
|
if v[1]:match("^opts.") then
|
|
|
|
|
app.opts[ v[1]:gsub("^opts.","") ] = v[2] -- update
|
|
|
|
|
saveconfig = true
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
if saveconfig then
|
|
|
|
|
app.set('app.opts', app.opts )
|
|
|
|
|
data.notification = '<div class="notification">updated</div>'
|
|
|
|
|
else
|
|
|
|
|
data.notification = '<div class="notification">no changes detected</div>'
|
|
|
|
|
end
|
2026-07-22 18:36:02 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-07-23 15:20:25 +02:00
|
|
|
foreach( app.plugin, pluginUI )
|
|
|
|
|
saveData()
|
2026-07-22 18:36:02 +02:00
|
|
|
local html = util.template( LoadAsset("page/admin/index.html"),data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetStatus(200)
|
|
|
|
|
SetHeader('Content-Type', 'text/html; charset=utf-8')
|
|
|
|
|
Write( html )
|