diff options
-rw-r--r-- | lbu-controller.lua | 2 | ||||
-rw-r--r-- | lbu-expert-html.lsp | 14 | ||||
-rw-r--r-- | lbu-model.lua | 62 |
3 files changed, 50 insertions, 28 deletions
diff --git a/lbu-controller.lua b/lbu-controller.lua index 304b0ac..6bca902 100644 --- a/lbu-controller.lua +++ b/lbu-controller.lua @@ -183,7 +183,7 @@ function commit(self) url = url, } ) end expert = function (self) - local modifications = self.clientdata.modifications or "" + local modifications = self.clientdata.filecontent or "" if ( self.clientdata.cmdsave) then modifications = self.model:update_filecontent(modifications) end diff --git a/lbu-expert-html.lsp b/lbu-expert-html.lsp index cea7e4c..219d748 100644 --- a/lbu-expert-html.lsp +++ b/lbu-expert-html.lsp @@ -42,21 +42,19 @@ displayinfo(myform,tags,"viewonly") <h1>CONFIGURATION</h1> -<H2>Expert config</H2> -<h3>File details</h3> +<form name="myform" action="" method="POST"> +<H2>EXPERT CONFIGURATION</H2> +<H3>FILE DETAILS</H3> <? local myform = form.file -local tags = { "name", "size", "mtime", } +local tags = { "filename", "filesize", "mtime", "sumerrors" } displayinfo(myform,tags,"viewonly") ?> - -<h3>File content</h3> -<form name="myform" action="" method="POST"> +<H3>FILE CONTENT</H3> <? -local myform = form.file.modifications -io.write(html.form[myform.type](myform)) +io.write(html.form[myform.filecontent.type](myform.filecontent)) ?> <H2>Save and apply above settings</H2> diff --git a/lbu-model.lua b/lbu-model.lua index 044d877..da5e22c 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -287,35 +287,59 @@ function editconfig (self,variable,value) return value end function get_filedetails() - local filedetails = {} local path = configfile - local filestats = fs.stat(path) - filedetails.name = cfe ({ - name="name", + local file = {} + local filedetails = {} + local config = {} + local filenameerrtxt + if (fs.is_file(path)) then + filedetails = fs.stat(path) + config = getconfig(path) + else + config = {} + config.filename = {} + config["filename"]["errtxt"]="Config file '".. path .. "' is missing!" + end + + file["filename"] = cfe({ + name="filename", + label="File name", value=path, - label="File name" + errtxt=filenameerrtxt }) - - filedetails.size = cfe ({ - name="size", - value=filestats.size or "0", + file["filesize"] = cfe({ + name="filesize", label="File size", + value=filedetails.size or 0, }) - - filedetails.mtime = cfe ({ + file["mtime"] = cfe({ name="mtime", - value=filestats.mtime or "---", - label="File modified", + label="File date", + value=filedetails.mtime or "---", }) - - filedetails.modifications = cfe ({ - name="modifications", - value=fs.read_file(path), - label="File content", + file["filecontent"] = cfe({ type="longtext", + name="filecontent", + label="File content", + value=fs.read_file(path), }) - return filedetails + -- Sum all errors into one cfe + local sumerrors = "" + for k,v in pairs(config) do + if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then + sumerrors = sumerrors .. config[k]["errtxt"] .. "\n" + end + end + if (sumerrors ~= "") then + file["sumerrors"] = cfe ({ + name="sumerrors", + label = "Configuration errors", + errtxt = string.match(sumerrors, "(.-)\n$"), + }) + end + + return file end function update_filecontent (self, modifications) local path = configfile |