diff options
Diffstat (limited to 'opennhrp-controller.lua')
-rw-r--r-- | opennhrp-controller.lua | 90 |
1 files changed, 81 insertions, 9 deletions
diff --git a/opennhrp-controller.lua b/opennhrp-controller.lua index e592bbc..f59ac0a 100644 --- a/opennhrp-controller.lua +++ b/opennhrp-controller.lua @@ -19,19 +19,91 @@ mvc.on_load = function(self, parent) end end -local function getstatus(self) - local status = self.model.getstatus() - if (#status.status.value > 0) then - status.status.value = "Enabled" - else - status.status.value = "Disabled" - end +local function displaycmdmanagement(disablestart,disablestop,disablerestart) + -- Add a management buttons + local management = {} + management.start = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Start", + type="submit", + }) + management.stop = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Stop", + type="submit", + }) + management.restart = cfe({ name="cmdmanagement", + label="Program control-panel", + value="Restart", + type="submit", + }) - return status + -- 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 + + return management end + -- ################################################################################ -- PUBLIC FUNCTIONS function status(self) - return { status=getstatus(self) } + return { status=self.model.getstatus() } end +expert = function (self) + local modifications = self.clientdata.filecontent or "" + if ( self.clientdata.cmdsave ) then + modifications = self.model:update_filecontent(modifications) + end + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller + + -- Start/Stop/Restart process + local cmdmanagement + if ( self.clientdata.cmdmanagement) then + cmdmanagement = cfe({ + name="cmdmanagement", + label="Previous action result", + action=cfe({ + name="cmdmanagement", + 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 ) + end + + local status=self.model.getstatus() + local file = self.model:get_filedetails() + + -- Add buttons + file.cmdsave = cfe ({ + name="cmdsave", + label="Apply settings", + value="Apply", + type="submit", + }) + if (self.clientdata.cmdsave) then + 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" + end + -- Display management buttons + management = displaycmdmanagement(disablestart,disablestop,disablerestart) + + return ( { + status = status, + file = file, + modifications = modifications, + management = management, + cmdmanagement = cmdmanagement, + url = url, } ) +end |