diff options
author | Ted Trask <ttrask01@yahoo.com> | 2010-11-26 17:44:27 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2010-11-26 17:44:27 +0000 |
commit | a7001d559885b3d494777f0b2d98d1b75b6557b3 (patch) | |
tree | 47fed18a96ac297a2bb75163f7d68202400ada8e | |
parent | 335a55e50948dfb9721986482cbe6c7221b84019 (diff) | |
download | acf-provisioning-a7001d559885b3d494777f0b2d98d1b75b6557b3.tar.bz2 acf-provisioning-a7001d559885b3d494777f0b2d98d1b75b6557b3.tar.xz |
Broke up get_device_values into two functions, one by name, one by device_id.
-rw-r--r-- | provisioning-controller.lua | 2 | ||||
-rw-r--r-- | provisioning-model.lua | 54 |
2 files changed, 38 insertions, 18 deletions
diff --git a/provisioning-controller.lua b/provisioning-controller.lua index 3531514..cf8272e 100644 --- a/provisioning-controller.lua +++ b/provisioning-controller.lua @@ -97,7 +97,7 @@ overridedeviceparams = function( self ) end getdevicevalues = function( self ) - return self.model.get_device_values(self.clientdata.name) + return self.model.get_device_values_by_name(self.clientdata.name) end searchdevices = function( self ) diff --git a/provisioning-model.lua b/provisioning-model.lua index 346eef3..e517907 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -1193,7 +1193,7 @@ set_device_params = function(params, editable) return params end -get_device_values = function(name) +get_device_values_by_name = function(name) local retval = {} retval.device_id = cfe({label="Device ID", seq=1}) retval.name = cfe({value=name or "", label="Name", seq=2}) @@ -1213,22 +1213,9 @@ get_device_values = function(name) end end - -- Next, get all of the parameters for this device - sql = "SELECT g.name AS group, p.name, p.type, 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 (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) 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)) LEFT JOIN provisioning_values v ON(d2t.device_id=v.device_id AND p.param_id=v.param_id AND g.name=v.group_name ) ".. - "WHERE d2t.device_id='"..escape(tmp[1].device_id).."'" - local tmp = getselectresponse(sql) - -- Loop through the params and put them into the groups - for i,p in ipairs(tmp) do - if p.type == "boolean" then - p.value = (p.value == "true") - end - if not retval.values.value[p.group] then - retval.values.value[p.group] = {} - end - retval.values.value[p.group][p.name] = p.value - end + -- Next, get all of the parameter values for this device + retval.values = get_device_values(tmp[1].device_id) + retval.values.seq = 5 else errtxt = "Invalid device name" end @@ -1244,6 +1231,39 @@ get_device_values = function(name) return cfe({ type="group", value=retval, label="Provisioning Device Parameter Values", errtxt=errtxt }) end +get_device_values = function(device_id) + local retval = {} + local errtxt + if device_id and device_id ~= "" then + local res, err = pcall(function() + local connected = databaseconnect() + local sql = "SELECT g.name AS group, p.name, p.type, 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 (devices_to_classes d2t JOIN provisioning_classes t USING(class_id) 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)) LEFT JOIN provisioning_values v ON(d2t.device_id=v.device_id AND p.param_id=v.param_id AND g.name=v.group_name ) ".. + "WHERE d2t.device_id='"..escape(device_id).."'" + local tmp = getselectresponse(sql) + -- Loop through the params and put them into the groups + for i,p in ipairs(tmp) do + if p.type == "boolean" then + p.value = (p.value == "true") + end + if not retval[p.group] then + retval[p.group] = {} + end + retval[p.group][p.name] = p.value + end + if connected then databasedisconnect() end + end) + if not res and err then + errtxt = err + end + else + errtxt = "Invalid device id" + end + + return cfe({type="structure", value=retval, label="Parameter Values", errtxt=errtxt}) +end + search_device_values = function(parameter_id, parameter_value, comparison) local errtxt retval = {} |