summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--provisioning-model.lua22
-rw-r--r--provisioning-searchdevices-html.lsp26
2 files changed, 36 insertions, 12 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua
index 24862aa..6c60ace 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -1920,6 +1920,7 @@ mymodule.get_search_options = function()
retval.id = cfe({type="select", value="device_id", label="Parameter", option={"device_id"}, seq=1})
retval.comparison = cfe({type="select", value="=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!~*"}, seq=2})
retval.value = cfe({label="Parameter Value", descr="Parameter value or SQL regular expression", seq=3})
+ retval.display = cfe({type="multi", value={"group", "param", "value"}, label="Display Parameters", descr="Parameters to display for each device", option={"group", "param", "value"}, seq=4})
local res, err = pcall(function()
connected = databaseconnect(true)
-- Get the group/parameter options
@@ -1929,6 +1930,7 @@ mymodule.get_search_options = function()
local blankexists = {}
for i,v in ipairs(tmp) do
retval.id.option[#retval.id.option + 1] = v.group_name.."."..v.param_name
+ retval.display.option[#retval.display.option + 1] = v.group_name.."."..v.param_name
if not blankexists[v.param_name] then
blankopt[#blankopt+1] = "."..v.param_name
blankexists[v.param_name] = true
@@ -1952,6 +1954,7 @@ mymodule.search_device_values = function(self, search)
local success = true
success = modelfunctions.validateselect(search.value.id) and success
success = modelfunctions.validateselect(search.value.comparison) and success
+ success = modelfunctions.validatemulti(search.value.display) and success
if search.value.id.value == "device_id" then
if string.match(search.value.comparison.value, "~") then
success = false
@@ -1970,7 +1973,9 @@ mymodule.search_device_values = function(self, search)
sql = "SELECT d2t.device_id, "
local group, param = string.match(search.value.id.value, "([^%.]*)%.(.*)")
if not group then
- sql = sql.."'"..provdb.escape(search.value.id.value).."' AS param, d2t."..provdb.escape(search.value.id.value).." AS value FROM devices_to_classes d2t WHERE d2t."..provdb.escape(search.value.id.value)..
+ param = search.value.id.value
+ -- This handles searching by device_id, the only option that doesn't have a '.'
+ sql = sql.."'"..provdb.escape(param).."' AS param, d2t."..provdb.escape(param).." AS value FROM devices_to_classes d2t WHERE d2t."..provdb.escape(param)..
provdb.escape(search.value.comparison.value).."'"..provdb.escape(search.value.value.value).."' GROUP BY device_id"
else
sql = sql.."g.name as group, p.name as param, CASE WHEN v.value IS NOT NULL THEN v.value WHEN g2p.value IS NOT NULL THEN g2p.value ELSE p.value END as value FROM "..
@@ -1986,6 +1991,21 @@ mymodule.search_device_values = function(self, search)
end
sql = sql.." ORDER BY d2t.device_id ASC"
search.value.result.value = getselectresponse(sql)
+ -- The current sql will return device_id, group (if exists), param, and value for the search
+ -- Now we add to the result any additional display parameters if requested
+ for i,dev in ipairs(search.value.result.value) do
+ local values = nil
+ for j,disp in ipairs(search.value.display.value) do
+ local g,p = string.match(disp, "([^%.]*)%.(.*)")
+ if g then
+ values = values or get_device_values(dev.device_id).value
+ if values[g] then
+ dev[disp] = values[g][p]
+ end
+ end
+ end
+ if values == nil then break end
+ end
if connected then databasedisconnect() end
end)
if not res and err then
diff --git a/provisioning-searchdevices-html.lsp b/provisioning-searchdevices-html.lsp
index eb99fd0..2f5ae17 100644
--- a/provisioning-searchdevices-html.lsp
+++ b/provisioning-searchdevices-html.lsp
@@ -46,20 +46,24 @@ if form.value.values then
form.value.values = nil
-- And here we display the list of devices in the result
elseif form.value.result then
- -- Determine all of the columns
- local tmp = {}
- for k,v in ipairs( form.value.result.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
+ if form.value.display then
+ display = form.value.display.value
+ else
+ -- Determine all of the columns
+ local tmp = {}
+ for k,v in ipairs( form.value.result.value ) do
+ for g,c in pairs(v) do
+ if not tmp[g] then tmp[g] = true end
+ end
+ end
+ for n in pairs(tmp) do
+ if n ~= "device_id" then
+ display[#display+1] = n
+ end
end
+ table.sort(display)
end
- table.sort(display)
local header_level = htmlviewfunctions.displaysectionstart(form.value.result, page_info)
%>