From a08c1bd2894983d7453af0118795edf85788cf0f Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 9 Jul 2009 11:54:27 +0000 Subject: Edit existing and create new graph-files Putting back full path on graph-files to get standard functions to work propperly --- rrdtool-controller.lua | 12 +++++++++--- rrdtool-listgraphcfg-html.lsp | 2 +- rrdtool-model.lua | 24 ++++++++++++++++++------ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/rrdtool-controller.lua b/rrdtool-controller.lua index 28a94f0..7efd8fa 100644 --- a/rrdtool-controller.lua +++ b/rrdtool-controller.lua @@ -63,8 +63,14 @@ function config(self) end function editgraphcfg(self) - return controllerfunctions.handle_form(self, + config = controllerfunctions.handle_form(self, function() return self.model.getgraphfile(self.clientdata.filename) end, - function() return self.model.setgraphfile() end, - self.clientdata, "Save", "Edit Config", "Configuration Saved") + function(value) + return self.model.set_filedetails(self, value, sessiondata.userinfo.userid) + end, self.clientdata, "Save", "Edit Config File", "Config File Saved") + + if self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then + config.value.filecontent.linenumber = self.clientdata.linenumber + end + return config end diff --git a/rrdtool-listgraphcfg-html.lsp b/rrdtool-listgraphcfg-html.lsp index 7ca6df5..e4c4a84 100644 --- a/rrdtool-listgraphcfg-html.lsp +++ b/rrdtool-listgraphcfg-html.lsp @@ -39,7 +39,7 @@ function javascript_confirm_graph(formID,filename) { Delete <% end %> <% - if session.permissions[page_info.controller].edit then io.write(html.link{value = "editgraphcfg?filename=" .. string.gsub(file.value.filename.value, "^.*/", "").."&redir="..page_info.orig_action, label="Edit " }) end + if session.permissions[page_info.controller].edit then io.write(html.link{value = "editgraphcfg?filename=" .. file.value.filename.value, label="Edit " }) end %> <%= html.html_escape(file.value.filesize.value) %> diff --git a/rrdtool-model.lua b/rrdtool-model.lua index 16ba2be..e915a4a 100644 --- a/rrdtool-model.lua +++ b/rrdtool-model.lua @@ -228,21 +228,33 @@ function getgraphlist() end function getgraphfile(path) - if (path) then - path = graphpath .. "/" .. path - end if (path) and not (validfilename(path)) then path = nil end local filedetails = modelfunctions.getfiledetails(path) local output = {value={filename=filedetails.value.filename, filecontent=filedetails.value.filecontent,}} - output.value.filename.value = string.gsub(filedetails.value.filename.value, "^.*/", "") -- output.value.filecontent.rows="30" -- FIXME: For some reason I can't control the size of a textarea if not (path) then output.value.filename.errtxt=nil - else - output.value.filename.disabled="true" end return output end + +function set_filedetails (self, filedetails, userid) + if not (string.match(filedetails.value.filename.value, "^" .. graphpath)) then + filedetails.value.filename.value = graphpath .. "/" .. string.gsub(filedetails.value.filename.value,"^.*/", "") + end + if not (string.match(filedetails.value.filename.value, "\.graph$")) then + filedetails.value.filename.value = filedetails.value.filename.value .. ".graph" + end + + filedetails = modelfunctions.setfiledetails(filedetails, getgraphlist) + filedetails.value.filesize = nil + filedetails.value.mtime = nil + return filedetails +end + +function setgraphfile(filedetails,file) + return modelfunctions.setfiledetails(filedetails, {file}) +end -- cgit v1.2.3