From fc0cc711e84e211c818e7c6f034d13992aa05da1 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 24 Apr 2008 20:31:58 +0000 Subject: Replaced all list_redir functions with redirect in mvc.lua, implemented a default_action string in each controller, removing the on_load functions git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1037 ab2d0c66-481e-0410-8bed-d214d4d58bed --- alpineversion-controller.lua | 19 +------------------ cron-controller.lua | 22 ++-------------------- health-controller.lua | 5 +---- hostname-controller.lua | 21 +-------------------- interfaces-controller.lua | 45 ++++++-------------------------------------- logfiles-controller.lua | 20 +++----------------- password-controller.lua | 19 +------------------ skins-controller.lua | 20 +++----------------- syslog-controller.lua | 13 +------------ 9 files changed, 19 insertions(+), 165 deletions(-) diff --git a/alpineversion-controller.lua b/alpineversion-controller.lua index 228f306..a90c306 100644 --- a/alpineversion-controller.lua +++ b/alpineversion-controller.lua @@ -2,24 +2,7 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "read" - self.conf.type = "redir" - error (self.conf) -end - -mvc={} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end - - --logit ("hostname.mvc.on_load activated") - -end +default_action = "read" read = function (self ) return self.model:get() diff --git a/cron-controller.lua b/cron-controller.lua index c02b06c..43a76d3 100644 --- a/cron-controller.lua +++ b/cron-controller.lua @@ -2,28 +2,10 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "read" - self.conf.type = "redir" - error (self.conf) -end - -mvc={} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end - - --logit ("cron.mvc.on_load activated") - -end - - -- Public methods +default_action = "read" + read = function (self) return ({ crontab = self.model:get()} ) end diff --git a/health-controller.lua b/health-controller.lua index c1ab2c0..fb7d4fb 100644 --- a/health-controller.lua +++ b/health-controller.lua @@ -1,9 +1,6 @@ module (..., package.seeall) -mvc={} -mvc.on_load = function(self, parent) - self.conf.default_action = "system" -end +default_action = "system" -- Public methods diff --git a/hostname-controller.lua b/hostname-controller.lua index 57506a5..8a6ead8 100644 --- a/hostname-controller.lua +++ b/hostname-controller.lua @@ -2,29 +2,10 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "read" - self.conf.type = "redir" - error (self.conf) -end - -mvc={} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end - - --logit ("hostname.mvc.on_load activated") - -end - - -- Public methods -- /hostname/get +default_action = "read" read = function (self ) return ({hostname = self.model:get()} ) diff --git a/interfaces-controller.lua b/interfaces-controller.lua index 90f0fe7..4c8c2dd 100644 --- a/interfaces-controller.lua +++ b/interfaces-controller.lua @@ -2,40 +2,7 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "config" - self.conf.type = "redir" - error (self.conf) -end - -local pvt = {} -mvc= {} -mvc.on_load = function(self, parent) - -- If they try to run a bogus action, send them to read - if ( rawget(self.worker, self.conf.action) == nil ) then - list_redir(self) - end - - pvt.parent_on_exec = parent.worker.mvc.post_exec - - --logit ("interfaces controller on_load has finished") - -end - - -mvc.pre_exec = function (self) - --logit ("interfaces-controller pre_exec activated") - -- pvt.parent_on_exec () - -end - -mvc.post_exec = function ( self ) - --logit ("interfaces-controller post_exec activated") - return pvt.parent_on_exec() -end +default_action = "read" read = function (self ) local iface = self.model.get_all_interfaces() @@ -74,7 +41,7 @@ update = function(self) -- If interface is not found, return to list result, data = self.model.get_iface_by_name ( iface ) if result == false then - list_redir(self) + redirect(self) end -- If the "cmd" button was used, then attempt to do the update @@ -90,7 +57,7 @@ update = function(self) -- If validation worked then return to list if result == true then - list_redir(self) + redirect(self) end end @@ -134,7 +101,7 @@ delete = function(self) -- If the interface doesn't exist, return to the list now result, data = self.model.get_iface_by_name ( iface ) if result == false then - list_redir(self) + redirect(self) end @@ -143,7 +110,7 @@ delete = function(self) if self.clientdata.cmd == "delete" then self.model.delete_iface_by_name (iface) end - list_redir(self) + redirect(self) end -- Otherwise, return a form @@ -181,7 +148,7 @@ create = function(self) result, data = self.model.create_iface_by_name ( iface, data ) if result then - list_redir(self) + redirect(self) end end diff --git a/logfiles-controller.lua b/logfiles-controller.lua index c5a5896..ad8bbe3 100644 --- a/logfiles-controller.lua +++ b/logfiles-controller.lua @@ -1,20 +1,6 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "status" - self.conf.type = "redir" - error (self.conf) -end - -mvc={} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end -end +default_action = "status" -- Public methods @@ -28,7 +14,7 @@ delete = function (self) if (me.deletestatus.errtxt) then return me else - list_redir(self) + redirect(self) end end @@ -38,7 +24,7 @@ view = function (self) if (filetoview ~= "") and (content.logfile.name ~= nil) then return content else - list_redir(self) + redirect(self) end end diff --git a/password-controller.lua b/password-controller.lua index 30a6f07..a9e28c7 100644 --- a/password-controller.lua +++ b/password-controller.lua @@ -2,24 +2,7 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "read" - self.conf.type = "redir" - error (self.conf) -end - -mvc={} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end - - --logit ("password.mvc.on_load activated") - -end +default_action = "update" update = function (self,self.sessionid.userid) return ( {report = self.model:set() }) diff --git a/skins-controller.lua b/skins-controller.lua index bf7a02a..9becde9 100644 --- a/skins-controller.lua +++ b/skins-controller.lua @@ -1,23 +1,9 @@ module (..., package.seeall) --- Cause an http redirect to our "read" action --- We use the self.conf table because it already has prefix,controller,etc --- The redir code is defined in the application error handler (acf-controller) -local list_redir = function (self) - self.conf.action = "read" - self.conf.type = "redir" - error (self.conf) -end - -mvc={} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end -end - -- Public methods +default_action = "read" + read = function (self ) return ({skin = self.model:get(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end @@ -25,7 +11,7 @@ end update = function (self ) local newskin = self.clientdata.skin or "" local updated = self.model:update(newskin) - list_redir(self) + redirect(self) -- return ({skin = self.model:get(), updated=self.model:update(newskin), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} ) end diff --git a/syslog-controller.lua b/syslog-controller.lua index e4b8d4d..f0fb343 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -1,17 +1,6 @@ module(..., package.seeall) -local list_redir = function (self) - self.conf.action = "status" - self.conf.type = "redir" - error (self.conf) -end - -mvc = {} -mvc.on_load = function(self, parent) - if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then - self.worker[self.conf.action] = list_redir(self) - end -end +default_action = "status" local function getstatus(self) local status = self.model.getstatus() -- cgit v1.2.3