summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--provisioning-controller.lua4
-rw-r--r--provisioning-editoptions-html.lsp11
-rw-r--r--provisioning-editparam-html.lsp9
-rw-r--r--provisioning-model.lua121
-rw-r--r--provisioning.roles4
5 files changed, 141 insertions, 8 deletions
diff --git a/provisioning-controller.lua b/provisioning-controller.lua
index cf8272e..b71589a 100644
--- a/provisioning-controller.lua
+++ b/provisioning-controller.lua
@@ -103,3 +103,7 @@ end
searchdevices = function( self )
return self.model.search_device_values(self.clientdata.id, self.clientdata.value, self.clientdata.comparison)
end
+
+editoptions = function( self )
+ return controllerfunctions.handle_form(self, function() return self.model.get_param_options(self.clientdata.param_id) end, self.model.set_param_options, self.clientdata, "Save", "Edit Parameter Options", "Parameter Options Saved")
+end
diff --git a/provisioning-editoptions-html.lsp b/provisioning-editoptions-html.lsp
new file mode 100644
index 0000000..10cf9e5
--- /dev/null
+++ b/provisioning-editoptions-html.lsp
@@ -0,0 +1,11 @@
+<% local form, viewlibrary, page_info = ...
+require("viewfunctions")
+%>
+
+<H1><%= html.html_escape(form.label) %></H1>
+<%
+ form.value.param_id.readonly = "true"
+ form.value.name.readonly = "true"
+ form.value.label.readonly = "true"
+ displayform(form, nil, nil, page_info, 2)
+%>
diff --git a/provisioning-editparam-html.lsp b/provisioning-editparam-html.lsp
index 73fca08..e9e8334 100644
--- a/provisioning-editparam-html.lsp
+++ b/provisioning-editparam-html.lsp
@@ -11,3 +11,12 @@ require("viewfunctions")
end
displayform(form, nil, nil, page_info, 2)
%>
+
+<% if page_info.action == "editparam" then %>
+<H2>Options</H2>
+<dl>
+<dt></dt><dd><form action="<%= page_info.script .. page_info.prefix .. page_info.controller %>/editoptions" method="POST">
+<input type="hidden" name="param_id" value="<%= form.value.param_id.value %>">
+<input type="submit" class="submit" value="Edit Options">
+</form></dd></dl>
+<% end %>
diff --git a/provisioning-model.lua b/provisioning-model.lua
index 1c063fd..1791ffd 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -172,6 +172,7 @@ local runscript = function(script)
end
end
+local runsqlcommand
runsqlcommand = function(sql, in_transaction)
logevent(sql)
if in_transaction then assert(con:execute("SAVEPOINT before_command")) end
@@ -192,6 +193,7 @@ logevent(err)
end
end
+local getselectresponse
getselectresponse = function(sql, in_transaction)
local retval = {}
if in_transaction then assert(con:execute("SAVEPOINT before_select")) end
@@ -226,6 +228,20 @@ logevent(err)
return retval
end
+local validateparam
+validateparam = function(p)
+ if p.type == "group" then
+ local success = true
+ for n,p2 in pairs(p.value) do
+ success = validateparam(p2) and success
+ end
+ return success
+ elseif p.type == "select" then
+ return modelfunctions.validateselect(p)
+ end
+ return true
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -590,6 +606,10 @@ get_group = function(group_id)
retval.params.option[#retval.params.option + 1] = {value=p.param_id, label=p.label}
retval.editable.option[#retval.editable.option + 1] = {value=p.param_id, label=p.label}
p.seq = i
+ if p.type == "select" then
+ sql = "SELECT * FROM provisioning_options WHERE param_id='"..escape(p.param_id).."' ORDER BY seq ASC"
+ p.option = getselectresponse(sql) or {}
+ end
if p.type == "boolean" then
p.value = (p.value == "true")
end
@@ -654,6 +674,8 @@ update_group = function(group, create)
success = false
group.value.seq.errtxt = "Must be an integer"
end
+ -- Validate the param defaults
+ success = validateparam(group.value.defaults) and success
if success then
local res, err = pcall(function()
local connected = databaseconnect()
@@ -765,7 +787,7 @@ get_param = function(param_id)
local retval = {}
retval.param_id = cfe({value=param_id or "", label="Param ID", seq=1})
retval.name = cfe({label="Name", seq=2})
- retval.type = cfe({type="select", label="Type", option={"text", "boolean"}, seq=3})
+ retval.type = cfe({type="select", label="Type", option={"text", "boolean", "select"}, seq=3})
retval.label = cfe({label="Label", seq=4})
retval.descr = cfe({label="Description", seq=5})
retval.value = cfe({label="Default Value", seq=6})
@@ -1105,8 +1127,14 @@ get_device_params = function(device_id, editable)
sql = sql.." AND g2p.editable='t'"
end
local tmp = getselectresponse(sql)
- -- Loop through the params and put them into the groups
+ -- Loop through the params to figure out options and put them into the groups
for i,p in ipairs(tmp) do
+ -- Options
+ if (p.type == "select") then
+ sql = "SELECT * FROM provisioning_options WHERE param_id='"..escape(p.param_id).."' ORDER BY seq ASC"
+ p.option = getselectresponse(sql) or {}
+ end
+ -- Groups
if not retval[p.group].value then
retval[p.group].value = {}
end
@@ -1137,10 +1165,9 @@ set_editable_device_params = function(params)
end
set_device_params = function(params, editable)
- local success = true
- local errtxt
-- Validate the settings
--- FIXME
+ local success = validateparam(params)
+ local errtxt
if success then
local res, err = pcall(function()
local connected = databaseconnect()
@@ -1156,7 +1183,7 @@ set_device_params = function(params, editable)
local sql = "BEGIN TRANSACTION"
runsqlcommand(sql)
if not editable then
- -- Delete all values fro this device (can't do this if only updating editable)
+ -- Delete all values for this device (can't do this if only updating editable)
sql = "DELETE FROM provisioning_values WHERE device_id='"..escape(params.value.device_id.value).."'"
runsqlcommand(sql, true)
end
@@ -1327,3 +1354,85 @@ search_device_values = function(parameter_id, parameter_value, comparison)
end
return cfe({type="group", value=retval, label="Device Search", errtxt=errtxt})
end
+
+get_param_options = function(param_id)
+ local retval = {}
+ retval.param_id = cfe({value=param_id or "", label="Parameter ID", seq=0})
+ retval.name = cfe({label="Name", seq=1})
+ retval.label = cfe({label="Label", seq=2})
+ retval.options = cfe({type="list", value={}, label="Value Options", descr="Ordered list of options where each option is made up of 'value' or 'value,label'", seq=3})
+ local errtxt = "Cannot find parameter"
+ if param_id and param_id ~= "" then
+ local res, err = pcall(function()
+ local connected = databaseconnect()
+ -- First, just check to see if param_id exists
+ local sql = "SELECT * FROM provisioning_params WHERE param_id='"..escape(param_id).."'"
+ local tmp = getselectresponse(sql)
+ if tmp and #tmp > 0 then
+ errtxt = nil
+ retval.name.value = tmp[1].name
+ retval.label.value = tmp[1].label
+ -- Next, get all of the param options
+ sql = "SELECT * FROM provisioning_options WHERE param_id='"..escape(param_id).."' ORDER BY seq ASC"
+ local tmp = getselectresponse(sql) or {}
+ for i,t in ipairs(tmp) do
+ retval.options.value[#retval.options.value + 1] = t.value..","..t.label
+ end
+ end
+ if connected then databasedisconnect() end
+ end)
+ if not res and err then
+ errtxt = err
+ end
+ end
+ return cfe({ type="group", value=retval, label="Provisioning Parameter Options", errtxt=errtxt })
+end
+
+set_param_options = function(options)
+ local success = true
+ local errtxt
+ -- Validate the settings
+--FIXME
+ if success then
+ local res, err = pcall(function()
+ local connected = databaseconnect()
+ local sql = "SELECT * FROM provisioning_params WHERE param_id='"..escape(options.value.param_id.value).."'"
+ local tmp = getselectresponse(sql)
+ if not tmp or #tmp == 0 then
+ success = false
+ errtxt = "Parameter does not exist"
+ end
+ if success then
+ local sql = "BEGIN TRANSACTION"
+ runsqlcommand(sql)
+ -- Delete all options for this device
+ sql = "DELETE FROM provisioning_options WHERE param_id='"..escape(options.value.param_id.value).."'"
+ runsqlcommand(sql, true)
+ -- Loop through the options
+ for i,o in ipairs(options.value.options.value) do
+ local v,l = string.match(o, "^%s*([^,]+),%s*(.*%S)%s*$")
+ if v then
+ v = string.match(v, "^(.*%S)%s*$")
+ else
+ v = string.match(o, "^%s*(.*%S)%s*$")
+ l = v
+ end
+ sql = "INSERT INTO provisioning_options VALUES('"..escape(options.value.param_id.value).."', '"..escape(l).."', '"..escape(v).."', '"..i.."')"
+ runsqlcommand(sql, true)
+ end
+ sql = "COMMIT"
+ runsqlcommand(sql)
+ end
+ if connected then databasedisconnect() end
+ end)
+ if not res and err then
+ pcall(function() con:execute("ROLLBACK") end)
+ success = false
+ errtxt = err
+ end
+ end
+ if not success then
+ options.errtxt = errtxt or "Failed to save options"
+ end
+ return options
+end
diff --git a/provisioning.roles b/provisioning.roles
index 0e7e57d..dca63b2 100644
--- a/provisioning.roles
+++ b/provisioning.roles
@@ -1,5 +1,5 @@
GUEST=provisioning:getdevicevalues
USER=
EDITOR=provisioning:searchdevices,provisioning:listdevices,provisioning:editdevice,provisioning:createdevice,provisioning:duplicatedevice,provisioning:deletedevice
-EXPERT=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:overridedeviceparams
-ADMIN=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:searchdevices,provisioning:listdevices,provisioning:editdevice,provisioning:createdevice,provisioning:duplicatedevice,provisioning:deletedevice,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:editdeviceparams,provisioning:overridedeviceparams
+EXPERT=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:overridedeviceparams,provisioning:editoptions
+ADMIN=provisioning:listtemplates,provisioning:edittemplate,provisioning:createtemplate,provisioning:deletetemplate,provisioning:searchdevices,provisioning:listdevices,provisioning:editdevice,provisioning:createdevice,provisioning:duplicatedevice,provisioning:deletedevice,provisioning:listclasses,provisioning:editclass,provisioning:createclass,provisioning:deleteclass,provisioning:listgroups,provisioning:editgroup,provisioning:creategroup,provisioning:deletegroup,provisioning:listparams,provisioning:editparam,provisioning:createparam,provisioning:deleteparam,provisioning:editdeviceparams,provisioning:overridedeviceparams,provisioning:editoptions