From 448421b511b9630dadb0ebca5de29731d3c56ebf Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 8 Apr 2008 11:49:10 +0000 Subject: Cleaning up the code even more. Moving view-function from the view-files into a library instead. git-svn-id: svn://svn.alpinelinux.org/acf/quagga/trunk@953 ab2d0c66-481e-0410-8bed-d214d4d58bed --- quagga-controller.lua | 40 ++++++++++++++++++------------- quagga-expert-html.lsp | 63 +++++++------------------------------------------ quagga-logfile-html.lsp | 35 ++------------------------- quagga-status-html.lsp | 42 ++++++++------------------------- 4 files changed, 44 insertions(+), 136 deletions(-) diff --git a/quagga-controller.lua b/quagga-controller.lua index cb63668..fdaf6ad 100644 --- a/quagga-controller.lua +++ b/quagga-controller.lua @@ -15,13 +15,14 @@ local function list_redir(self) error (self.conf) end -local function displaycmdmanagement(disablestart,disablestop,disablerestart) +local function displaycmdmanagement(pidofstatus) -- Add a management buttons local management = {} management.start = cfe({ name="cmdmanagement", label="Program control-panel", value="Start", type="submit", + descr="When starting or restarting BGP, the web-page will freeze for some reason!", }) management.stop = cfe({ name="cmdmanagement", label="Program control-panel", @@ -33,11 +34,20 @@ local function displaycmdmanagement(disablestart,disablestop,disablerestart) value="Restart", type="submit", }) + -- next CFE can be used to present the result of the previous action + management.actionresult = cfe({ name="actionresult", + label="Previous action result", + descr="", --Content of this variable is displayed as
 ... 
in BLACK text + errtxt="", --Content of this variable is displayed as
 ... 
in RED text + }) -- Disable management buttons based on if the process is running or not - if (disablestart) then management.start.disabled = "yes" end - if (disablestop) then management.stop.disabled = "yes" end - if (disablerestart) then management.restart.disabled = "yes" end + if (pidofstatus) then + management.start.disabled = "yes" + else + management.stop.disabled = "yes" + management.restart.disabled = "yes" + end return management end @@ -63,7 +73,7 @@ function expert(self) local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller -- Start/Stop/Restart process - local cmdmanagement + local cmdmanagement, actionresult if ( self.clientdata.cmdmanagement) then cmdmanagement = cfe({ name="cmdmanagement", @@ -73,7 +83,7 @@ function expert(self) value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands) }), }) - local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) + actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) end local status=self.model.getstatus() @@ -90,24 +100,20 @@ function expert(self) file.cmdsave.descr="* Changes has been saved!" end - - -- Management buttons - local disablestart,disablestop,disablerestart - -- Disable management buttons based on if the process is running or not - if (string.lower(status.status.value) == "enabled" ) then - disablestart = "yes" - else - disablestop = "yes" + -- Management buttons (Hide/show buttons + local pidofstatus + if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end + management = displaycmdmanagement(pidofstatus) + if (actionresult) then + management.actionresult.descr=cmdmanagement.descr + management.actionresult.errtxt=cmdmanagement.errtxt end - -- Display management buttons - management = displaycmdmanagement(disablestart,disablestop,disablerestart) return ( { status = status, file = file, modifications = modifications, management = management, - cmdmanagement = cmdmanagement, url = url, } ) end diff --git a/quagga-expert-html.lsp b/quagga-expert-html.lsp index 19bda27..3f1fedc 100644 --- a/quagga-expert-html.lsp +++ b/quagga-expert-html.lsp @@ -1,36 +1,6 @@ 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "") - io.write("\n\t\t
") - if (viewtype == "viewonly") then - io.write(val.value) - elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then - io.write("") - for k1,v1 in pairs(val.option) do - io.write(tostring(v1.label) .. ":") - io.write("") - end - io.write("") - else - io.write(html.form[val.type](val)) - end - if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end - if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end +require("viewfunctions") ?>

SYSTEM INFO

@@ -69,30 +39,15 @@ displayinfo(myform,tags) ?> - -MANAGEMENT +
+') - io.write('

MANAGEMENT

') - io.write('
') - io.write('
' .. cmdform[tags[1]]["label"] .. '
') - io.write('
') - for k,v in pairs(tags) do - if (cmdform[v]) then - io.write(html.form[cmdform[v].type](cmdform[v])) - end - end - io.write('
') +displaymanagement(myform,tags) +?> +
- if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then - io.write('
' .. cmdresult.label .. '
') - io.write('
' .. cmdresult.action.descr .. '
') - end - io.write('
') -end ?> + diff --git a/quagga-logfile-html.lsp b/quagga-logfile-html.lsp index 2d2b1b7..aa0b6e5 100644 --- a/quagga-logfile-html.lsp +++ b/quagga-logfile-html.lsp @@ -1,36 +1,6 @@ 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "") - io.write("\n\t\t
") - if (viewtype == "viewonly") then - io.write(val.value) - elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then - io.write("") - for k1,v1 in pairs(val.option) do - io.write(tostring(v1.label) .. ":") - io.write("") - end - io.write("") - else - io.write(html.form[val.type](val)) - end - if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end - if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end +require("viewfunctions") ?>

SYSTEM INFO

@@ -42,13 +12,12 @@ displayinfo(myform,tags,"viewonly") ?> - -

LOGFILE

Details

diff --git a/quagga-status-html.lsp b/quagga-status-html.lsp index fb6172d..6b68a52 100644 --- a/quagga-status-html.lsp +++ b/quagga-status-html.lsp @@ -1,39 +1,8 @@ 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "") - io.write("\n\t\t
") - if (viewtype == "viewonly") then - io.write(val.value) - elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then - io.write("") - for k1,v1 in pairs(val.option) do - io.write(tostring(v1.label) .. ":") - io.write("") - end - io.write("") - else - io.write(html.form[val.type](val)) - end - if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end - if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end +require("viewfunctions") ?> -

SYSTEM INFO

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + -- cgit v1.2.3