diff options
author | Ted Trask <ttrask01@yahoo.com> | 2011-10-14 14:35:27 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2011-10-14 14:35:27 +0000 |
commit | 0501a13026838f688eb8822bf080b0040672190a (patch) | |
tree | 63ffdc84867d74efc6eebe96a902a95ab384e43e | |
parent | 102f3e62cedd0ff6cc6f556c3e506951ccb25c1a (diff) | |
download | acf-provisioning-0501a13026838f688eb8822bf080b0040672190a.tar.bz2 acf-provisioning-0501a13026838f688eb8822bf080b0040672190a.tar.xz |
Modify listdevices to also display the class values for each device
-rw-r--r-- | provisioning-listdevices-html.lsp | 32 | ||||
-rw-r--r-- | provisioning-model.lua | 12 |
2 files changed, 30 insertions, 14 deletions
diff --git a/provisioning-listdevices-html.lsp b/provisioning-listdevices-html.lsp index c19f281..b203368 100644 --- a/provisioning-listdevices-html.lsp +++ b/provisioning-listdevices-html.lsp @@ -26,18 +26,30 @@ require("viewfunctions") <% displaycommandresults({"deletedevice", "editdevice", "editdeviceparams", "overridedeviceparams"}, session) %> <% displaycommandresults({"createdevice"}, session, true) %> +<% -- Determine all of the groups +local tmp = {} +for k,v in ipairs( view.value ) do + for g,c in pairs(v) do + if not tmp[g] then tmp[g] = true end + end +end +local display = {} +for n in pairs(tmp) do + if n ~= "device_id" then + display[#display+1] = n + end +end +table.sort(display) +%> + <h1>Devices</h1> <DL> <TABLE id="list" class="tablesorter"><THEAD> <TR style="background:#eee;font-weight:bold;"> <TH>Action</TH> <TH>Device ID</TH> - <% if page_info.action ~= "listdevices" then %> - <% if view.value[1] and view.value[1].group and view.value[1].group ~= "" then %> - <TH>Group</TH> - <% end %> - <TH>Param</TH> - <TH>Value</TH> + <% for i,n in ipairs(display) do %> + <TH><%= string.gsub(n, "^.", string.upper) %> <% end %> </TR> </THEAD><TBODY> @@ -60,12 +72,8 @@ require("viewfunctions") <% end %> </TD> <TD><%= html.html_escape(v.device_id) %></TD> - <% if page_info.action ~= "listdevices" then %> - <% if v.group and v.group ~= "" then %> - <TD><%= html.html_escape(v.group) %></TD> - <% end %> - <TD><%= html.html_escape(v.param) %></TD> - <TD><%= html.html_escape(v.value) %></TD> + <% for i,n in ipairs(display) do %> + <TD><%= html.html_escape(v[n]) %></TD> <% end %> </TR> <% end %> diff --git a/provisioning-model.lua b/provisioning-model.lua index f96da7e..61633d6 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -1191,8 +1191,16 @@ list_devices = function() -- Get the devices from the DB local res, err = pcall(function() local connected = databaseconnect() - local sql = "SELECT device_id FROM devices_to_classes GROUP BY device_id ORDER BY device_id ASC" - retval = getselectresponse(sql) + local sql = "SELECT device_id, c.label AS class, g.label AS group FROM devices_to_classes d2c JOIN provisioning_classes c USING(class_id) JOIN provisioning_class_groups g USING(class_group_id) ORDER BY device_id" + local tmp = getselectresponse(sql) + local reverse_device_id = {} + for i,d in ipairs(tmp) do + if not reverse_device_id[d.device_id] then + retval[#retval+1] = {device_id=d.device_id} + reverse_device_id[d.device_id] = #retval + end + retval[reverse_device_id[d.device_id]][d.group] = d.class + end if connected then databasedisconnect() end end) if not res and err then |