From 42029e2ecdb3c68f10a567e0724490c726f70f14 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 10 Apr 2014 07:23:16 +0000 Subject: Changes to use new htmlviewfunctions functions and make searchdatabase a proper form --- kamailio-controller.lua | 2 +- kamailio-listfiles-html.lsp | 36 +++++++++++++++++++++++++++++------- kamailio-listusers-html.lsp | 10 +++++++--- kamailio-model.lua | 39 ++++++++++++++++++++++++++------------- kamailio-searchdatabase-html.lsp | 3 +-- 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/kamailio-controller.lua b/kamailio-controller.lua index 9397359..985eb39 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -40,7 +40,7 @@ function mymodule.createdatabase(self) end function mymodule.searchdatabase(self) - return self.model.search_database(self.clientdata.id, self.clientdata.value, self.clientdata.comparison) + return self.handle_form(self, self.model.get_search_database, self.model.search_database, self.clientdata, "Search", "Search Database") end -- Use acf-db to allow editing of the database diff --git a/kamailio-listfiles-html.lsp b/kamailio-listfiles-html.lsp index 564dcce..c2ebfb2 100644 --- a/kamailio-listfiles-html.lsp +++ b/kamailio-listfiles-html.lsp @@ -3,6 +3,20 @@ htmlviewfunctions = require("htmlviewfunctions") html = require("acf.html") %> +<% +function convertsize(size) + if string.find(size, "k$") then + return tonumber(string.match(size, "[%d.]*")) * 1024.0 + elseif string.find(size, "M$") then + return tonumber(string.match(size, "[%d.]*")) * 1024.0 * 1024.0 + elseif string.find(size, "G$") then + return tonumber(string.match(size, "[%d.]*")) + 1024.0 * 1024.0 * 1024.0 + else + return tonumber(string.match(size, "[%d.]*")) + end +end +%> + @@ -27,17 +41,25 @@ html = require("acf.html") viewlibrary.dispatch_component("status") end %> -

Configuration

+<% local header_level = htmlviewfunctions.displaysectionstart(cfe({label="Configuration"}), page_info) %> + -<% - for k,v in ipairs( view.value ) do - io.write( "\n" ) - end -%> +<% local filename = cfe({ type="hidden", value="" }) %> +<% local redir = cfe({ type="hidden", value=page_info.orig_action }) %> +<% for i,file in ipairs( view.value ) do %> + <% filename.value = file.filename %> + + + + + + +<% end %>
Action File Size Last Modified
" .. html.html_escape(v.filename) .. "" .. html.html_escape(v.size) .."" .. html.html_escape(v.mtime) .."
<% htmlviewfunctions.displayitem(cfe({type="link", value={filename=filename, redir=redir}, label="", option="Edit", action="edit"}), page_info, -1) %><%= html.html_escape(file.filename) %><%= convertsize(file.size) %>b<%= html.html_escape(file.size) %><%= html.html_escape(file.mtime) %>
+<% htmlviewfunctions.displaysectionend(header_level) %> diff --git a/kamailio-listusers-html.lsp b/kamailio-listusers-html.lsp index 0b7183f..47b7c2d 100644 --- a/kamailio-listusers-html.lsp +++ b/kamailio-listusers-html.lsp @@ -27,7 +27,7 @@ <% htmlviewfunctions.displaycommandresults({"deleteuser", "updateuser"}, session) %> <% htmlviewfunctions.displaycommandresults({"createuser"}, session, true) %> -

<%= html.html_escape(form.label) %>

+<% local header_level = htmlviewfunctions.displaysectionstart(form, page_info) %> <% if viewlibrary.check_permission("deleteuser") or viewlibrary.check_permission("updateuser") then %> @@ -37,15 +37,18 @@ +<% local username = cfe({ type="hidden", value="" }) %> +<% local redir = cfe({ type="hidden", value=page_info.orig_action }) %> <% for i,user in ipairs(form.value) do %> + <% username.value = user.username %> <% if viewlibrary.check_permission("deleteuser") or viewlibrary.check_permission("updateuser") then %> <% end %> @@ -58,6 +61,7 @@ <% end %>
Password
<% if viewlibrary.check_permission("updateuser") then %> - <%= html.link{value = "updateuser?username=" .. user.username.."&redir="..page_info.orig_action, label="Update "} %> + <% htmlviewfunctions.displayitem(cfe({type="link", value={username=username, redir=redir}, label="", option="Update", action="updateuser"}), page_info, -1) %> <% end %> <% if viewlibrary.check_permission("deleteuser") then %> - <%= html.link{value = "deleteuser?submit=true&username=" .. user.username, label="Delete "} %> + <% htmlviewfunctions.displayitem(cfe({type="form", value={username=username}, label="", option="Delete", action="deleteuser"}), page_info, -1) %> <% end %>
+<% htmlviewfunctions.displaysectionend(header_level) %> <% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createuser") then viewlibrary.dispatch_component("createuser") diff --git a/kamailio-model.lua b/kamailio-model.lua index 089c465..587f7ad 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -285,12 +285,12 @@ function mymodule.create_database(self, create_db) return create_db end -function mymodule.search_database(id, value, comparison) +function mymodule.get_search_database(self, clientdata) local errtxt retval = {} - retval.id = cfe({type="select", value=id or "", label="Table.Column", option={}, seq=1}) - retval.comparison = cfe({type="select", value=comparison or "=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!*~"}, seq=2}) - retval.value = cfe({label="Value", value=value or "", descr="Value or SQL regular expression", seq=3}) + retval.id = cfe({type="select", value=clientdata.id or "", label="Table.Column", option={}, seq=1}) + retval.comparison = cfe({type="select", value=clientdata.comparison or "=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!*~"}, seq=2}) + retval.value = cfe({label="Value", value=clientdata.value or "", descr="Value or SQL regular expression", seq=3}) local res, err = pcall(function() local connected = databaseconnect() local tables = dbkam.listtables() or {} @@ -300,15 +300,6 @@ function mymodule.search_database(id, value, comparison) retval.id.option[#retval.id.option + 1] = t.."."..c end end - -- Get the rows from the DB - if id and modelfunctions.validateselect(retval.id) and modelfunctions.validateselect(retval.comparison) then - retval.result = cfe({type="structure", value={}, label="List of Rows", seq=4 }) - local table, column = string.match(id, "^([^.]*)%.(.*)") - if table then - local sql = "SELECT * FROM "..dbkam.escape(table).." WHERE "..dbkam.escape(column)..dbkam.escape(comparison).."'"..dbkam.escape(value).."'" - retval.result.value = getselectresponse(sql) - end - end if connected then databasedisconnect() end end) if not res and err then @@ -317,6 +308,28 @@ function mymodule.search_database(id, value, comparison) return cfe({type="group", value=retval, label="Database Search", errtxt=errtxt}) end +function mymodule.search_database(self, search) + if modelfunctions.validateselect(search.value.id) and modelfunctions.validateselect(search.value.comparison) then + local res, err = pcall(function() + local connected = databaseconnect() + -- Get the rows from the DB + search.value.result = cfe({type="structure", value={}, label="List of Rows", seq=4 }) + local table, column = string.match(search.value.id.value, "^([^.]*)%.(.*)") + if table then + local sql = "SELECT * FROM "..dbkam.escape(table).." WHERE "..dbkam.escape(column)..dbkam.escape(search.value.comparison.value).."'"..dbkam.escape(search.value.value.value).."'" + search.value.result.value = getselectresponse(sql) + end + if connected then databasedisconnect() end + end) + if not res and err then + search.errtxt = err + end + else + search.errtxt = "Failed to search database" + end + return search +end + for n,f in pairs(dbmodelfunctions) do mymodule[n] = function(...) databasecreate() diff --git a/kamailio-searchdatabase-html.lsp b/kamailio-searchdatabase-html.lsp index 257626d..2c2a71f 100644 --- a/kamailio-searchdatabase-html.lsp +++ b/kamailio-searchdatabase-html.lsp @@ -21,9 +21,8 @@ html = require("acf.html") form.value.fields = nil end %> -

<%= html.html_escape(form.label) %>

<% form.value.result = nil form.option = "Search" - htmlviewfunctions.displayform(form, nil, nil, page_info, 2) + htmlviewfunctions.displayitem(form, page_info) %> -- cgit v1.2.3