diff options
author | Ted Trask <ttrask01@yahoo.com> | 2011-10-10 18:25:19 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2011-10-10 18:25:19 +0000 |
commit | b802504e41cccda64b8f903973d01897bbec7451 (patch) | |
tree | c5ced769d4b328fc3bd5d0077039f23881f8c119 /provisioning-model.lua | |
parent | 6e029cd625261b77c94cdf3c38139a7d0fc381c4 (diff) | |
download | acf-provisioning-b802504e41cccda64b8f903973d01897bbec7451.tar.bz2 acf-provisioning-b802504e41cccda64b8f903973d01897bbec7451.tar.xz |
Change viewclassparams to getclassvalues
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r-- | provisioning-model.lua | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua index 292082c..4ada401 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -1430,60 +1430,53 @@ get_device_params = function(device_id, editable) return output end -get_class_params = function(class_id) +get_class_options = function(class_id) local retval = {} - retval.class_id = cfe({value=class_id or "", label="Class ID", readonly=true, seq=0}) - local errtxt = "Cannot find class" - if class_id and class_id ~= "" then + retval.class_id = cfe({value=class_id or "", label="Class ID", seq=1}) + return cfe({ type="group", value=retval, label="Provisioning Class Values" }) +end + +get_class_values = function(retval) + retval.errtxt = "Failed to find class" + if not validator.is_integer(retval.value.class_id.value) then + retval.value.class_id.errtxt = "Invalid class ID" + else local res, err = pcall(function() local connected = databaseconnect() -- First, just check to see if class_id exists - local sql = "SELECT * FROM provisioning_classes WHERE class_id='"..escape(class_id).."'" + local sql = "SELECT * FROM provisioning_classes WHERE class_id='"..escape(retval.value.class_id.value).."'" local tmp = getselectresponse(sql) if tmp and #tmp > 0 then - errtxt = nil - -- Next, get all of the param groups - sql = "SELECT * FROM provisioning_groups" - local tmp = getselectresponse(sql) - -- Loop through the groups and put them into the result - for i,g in ipairs(tmp) do - retval[g.name] = g - retval[g.name].label = g.name - retval[g.name].type="group" - end - -- Then, get all of the parameters for this class - sql = "SELECT g.name AS group, g.label AS grouplabel, p.param_id, p.name, p.type, p.label, p.descr, p.seq, p.regexp, p.validate, CASE WHEN g2p.value IS NOT NULL THEN g2p.value ELSE p.value END AS value ".. - "FROM (provisioning_classes t JOIN classes_to_param_groups t2g USING (class_id) JOIN provisioning_groups g USING(group_id) ".. + retval.errtxt = nil + retval.value.label = cfe({ value=tmp[1].label or "", label="Label", seq=3}) + retval.value.values = cfe({type="structure", value={}, label="Parameter Values"}) + + local sql = "SELECT g.name AS group, p.name, p.type, CASE WHEN g2p.value IS NOT NULL THEN g2p.value ELSE p.value END AS value ".. + "FROM (provisioning_classes t JOIN classes_to_param_groups t2g USING(class_id) JOIN provisioning_groups g USING(group_id) ".. "JOIN param_groups_to_params g2p USING(group_id) JOIN provisioning_params p USING(param_id)) ".. - "WHERE t.class_id='"..escape(class_id).."'" + "WHERE t.class_id='"..escape(retval.value.class_id.value).."'" local tmp = getselectresponse(sql) - -- Loop through the params to figure out options and put them into the groups + -- Loop through the params and put them into the groups for i,p in ipairs(tmp) do - p.type = "text" - p.readonly = true - -- Groups - if not retval[p.group].value then - retval[p.group].value = {} + if p.type == "boolean" then + p.value = (p.value == "true") end - retval[p.group].label = p.grouplabel - local value = retval[p.group].value - value[p.name] = p - end - -- Finally, loop through the result and remove empty groups - for name,val in pairs(retval) do - if not val.value then - retval[name] = nil + if not retval.value.values.value[p.group] then + retval.value.values.value[p.group] = {} end + retval.value.values.value[p.group][p.name] = p.value end + else + retval.value.class_id.errtxt = "Failed to find Class ID" end if connected then databasedisconnect() end end) if not res and err then - errtxt = err + retval.errtxt = err end end - local output = cfe({ type="group", value=retval, label="Provisioning Class Parameters", errtxt=errtxt }) - return output + + return retval end set_editable_device_params = function(params) @@ -1902,9 +1895,9 @@ function get_file(mac, ip, agent) local class = callscript(determineclassscriptfile, agent, c) if class then - result.errtxt = nil - result.value.values = get_class_params(class) - result.value.values.seq = 5 + local options = get_class_options() + options.value.class_id.value = class + result = get_class_values(options) else result.errtxt = "Unknown device" end |