From 0501a13026838f688eb8822bf080b0040672190a Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 14 Oct 2011 14:35:27 +0000 Subject: Modify listdevices to also display the class values for each device --- provisioning-listdevices-html.lsp | 32 ++++++++++++++++++++------------ 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) +%> +

Devices

- <% if page_info.action ~= "listdevices" then %> - <% if view.value[1] and view.value[1].group and view.value[1].group ~= "" then %> - - <% end %> - - + <% for i,n in ipairs(display) do %> + @@ -60,12 +72,8 @@ require("viewfunctions") <% end %> - <% if page_info.action ~= "listdevices" then %> - <% if v.group and v.group ~= "" then %> - - <% end %> - - + <% for i,n in ipairs(display) do %> + <% end %> <% 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 -- cgit v1.2.3
Action Device IDGroupParamValue<%= string.gsub(n, "^.", string.upper) %> <% end %>
<%= html.html_escape(v.device_id) %><%= html.html_escape(v.group) %><%= html.html_escape(v.param) %><%= html.html_escape(v.value) %><%= html.html_escape(v[n]) %>