luci-app-dockerman: cbi/containers refactoring

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2020-07-23 10:27:30 +02:00
parent 076ad55c4a
commit 18ae86e458

View file

@ -89,7 +89,7 @@ function get_containers()
return data return data
end end
local c_lists = get_containers() local container_list = get_containers()
m = SimpleForm("docker", translate("Docker")) m = SimpleForm("docker", translate("Docker"))
m.submit=false m.submit=false
@ -103,55 +103,54 @@ if s.err then
docker:clear_status() docker:clear_status()
end end
c_table = m:section(Table, c_lists, translate("Containers")) s = m:section(Table, container_list, translate("Containers"))
c_table.nodescr=true s.nodescr=true
container_selecter = c_table:option(Flag, "_selected","") o = s:option(Flag, "_selected","")
container_selecter.disabled = 0 o.disabled = 0
container_selecter.enabled = 1 o.enabled = 1
container_selecter.default = 0 o.default = 0
container_selecter.write=function(self, section, value) o.write=function(self, section, value)
c_lists[section]._selected = value container_list[section]._selected = value
end end
container_id = c_table:option(DummyValue, "_id", translate("ID")) o = s:option(DummyValue, "_id", translate("ID"))
container_id.width="10%" o.width="10%"
container_name = c_table:option(DummyValue, "_name", translate("Container Name")) o = s:option(DummyValue, "_name", translate("Container Name"))
container_name.rawhtml = true o.rawhtml = true
container_status = c_table:option(DummyValue, "_status", translate("Status")) o = s:option(DummyValue, "_status", translate("Status"))
container_status.width="15%" o.width="15%"
container_status.rawhtml=true o.rawhtml=true
container_ip = c_table:option(DummyValue, "_network", translate("Network")) o = s:option(DummyValue, "_network", translate("Network"))
container_ip.width="15%" o.width="15%"
container_ports = c_table:option(DummyValue, "_ports", translate("Ports")) o = s:option(DummyValue, "_ports", translate("Ports"))
container_ports.width="10%" o.width="10%"
container_ports.rawhtml = true o.rawhtml = true
container_image = c_table:option(DummyValue, "_image", translate("Image")) o = s:option(DummyValue, "_image", translate("Image"))
container_image.width="10%" o.width="10%"
container_command = c_table:option(DummyValue, "_command", translate("Command")) o = s:option(DummyValue, "_command", translate("Command"))
container_command.width="20%" o.width="20%"
local start_stop_remove = function(m,cmd) local start_stop_remove = function(m,cmd)
local c_selected = {} local container_selected = {}
local c_table_sids = c_table:cfgsections() for k in pairs(container_list) do
for _, c_table_sid in ipairs(c_table_sids) do if container_list[k]._selected == 1 then
if c_lists[c_table_sid]._selected == 1 then container_selected[#container_selected + 1] = container_list[k].name
c_selected[#c_selected+1] = c_lists[c_table_sid].name
end end
end end
if #c_selected >0 then if #container_selected > 0 then
local success = true local success = true
docker:clear_status() docker:clear_status()
for _,cont in ipairs(c_selected) do for _, cont in ipairs(container_selected) do
docker:append_status("Containers: " .. cmd .. " " .. cont .. "...") docker:append_status("Containers: " .. cmd .. " " .. cont .. "...")
local res = dk.containers[cmd](dk, {id = cont}) local res = dk.containers[cmd](dk, {id = cont})
if res and res.code >= 300 then if res and res.code >= 300 then
@ -170,63 +169,62 @@ local start_stop_remove = function(m,cmd)
end end
end end
action_section = m:section(Table,{{}}) s = m:section(Table,{{}})
action_section.notitle=true s.notitle=true
action_section.rowcolors=false s.rowcolors=false
action_section.template="cbi/nullsection" s.template="cbi/nullsection"
btnnew=action_section:option(Button, "_new") o = s:option(Button, "_new")
btnnew.inputtitle= translate("New") o.inputtitle= translate("New")
btnnew.template = "dockerman/cbi/inlinebutton" o.template = "dockerman/cbi/inlinebutton"
btnnew.inputstyle = "add" o.inputstyle = "add"
btnnew.forcewrite = true o.forcewrite = true
btnnew.write = function(self, section) o.write = function(self, section)
luci.http.redirect(luci.dispatcher.build_url("admin/docker/newcontainer")) luci.http.redirect(luci.dispatcher.build_url("admin/docker/newcontainer"))
end end
btnstart=action_section:option(Button, "_start") o = s:option(Button, "_start")
btnstart.template = "dockerman/cbi/inlinebutton" o.template = "dockerman/cbi/inlinebutton"
btnstart.inputtitle=translate("Start") o.inputtitle=translate("Start")
btnstart.inputstyle = "apply" o.inputstyle = "apply"
btnstart.forcewrite = true o.forcewrite = true
btnstart.write = function(self, section) o.write = function(self, section)
start_stop_remove(m,"start") start_stop_remove(m,"start")
end end
btnrestart=action_section:option(Button, "_restart") o = s:option(Button, "_restart")
btnrestart.template = "dockerman/cbi/inlinebutton" o.template = "dockerman/cbi/inlinebutton"
btnrestart.inputtitle=translate("Restart") o.inputtitle=translate("Restart")
btnrestart.inputstyle = "reload" o.inputstyle = "reload"
btnrestart.forcewrite = true o.forcewrite = true
btnrestart.write = function(self, section) o.write = function(self, section)
start_stop_remove(m,"restart") start_stop_remove(m,"restart")
end end
btnstop=action_section:option(Button, "_stop") o = s:option(Button, "_stop")
btnstop.template = "dockerman/cbi/inlinebutton" o.template = "dockerman/cbi/inlinebutton"
btnstop.inputtitle=translate("Stop") o.inputtitle=translate("Stop")
btnstop.inputstyle = "reset" o.inputstyle = "reset"
btnstop.forcewrite = true o.forcewrite = true
btnstop.write = function(self, section) o.write = function(self, section)
start_stop_remove(m,"stop") start_stop_remove(m,"stop")
end end
o = s:option(Button, "_kill")
btnkill=action_section:option(Button, "_kill") o.template = "dockerman/cbi/inlinebutton"
btnkill.template = "dockerman/cbi/inlinebutton" o.inputtitle=translate("Kill")
btnkill.inputtitle=translate("Kill") o.inputstyle = "reset"
btnkill.inputstyle = "reset" o.forcewrite = true
btnkill.forcewrite = true o.write = function(self, section)
btnkill.write = function(self, section)
start_stop_remove(m,"kill") start_stop_remove(m,"kill")
end end
btnremove=action_section:option(Button, "_remove") o = s:option(Button, "_remove")
btnremove.template = "dockerman/cbi/inlinebutton" o.template = "dockerman/cbi/inlinebutton"
btnremove.inputtitle=translate("Remove") o.inputtitle=translate("Remove")
btnremove.inputstyle = "remove" o.inputstyle = "remove"
btnremove.forcewrite = true o.forcewrite = true
btnremove.write = function(self, section) o.write = function(self, section)
start_stop_remove(m,"remove") start_stop_remove(m,"remove")
end end