From 9befed193ae828c2b58390e8c0efafdab37f45b8 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sat, 6 Sep 2008 14:59:48 +0000 Subject: [PATCH 1/1] cbi: Increare responsiveness of "Save & Apply" --- i18n/english/luasrc/i18n/cbi.en.lua | 1 + i18n/english/luasrc/i18n/cbi.en.xml | 1 + i18n/german/luasrc/i18n/cbi.de.lua | 1 + i18n/german/luasrc/i18n/cbi.de.xml | 2 ++ libs/cbi/luasrc/cbi.lua | 19 ++++++++++++++++++- libs/cbi/luasrc/view/cbi/map.htm | 13 +++++++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/i18n/english/luasrc/i18n/cbi.en.lua b/i18n/english/luasrc/i18n/cbi.en.lua index d302ee52a..42f93d4cc 100644 --- a/i18n/english/luasrc/i18n/cbi.en.lua +++ b/i18n/english/luasrc/i18n/cbi.en.lua @@ -11,3 +11,4 @@ cbi_sectempty = 'This section contains no values yet' cbi_manual = '-- custom --' cbi_select = '-- Please choose --' cbi_gorel = 'Go to relevant configuration page' +cbi_applying = 'Applying changes' diff --git a/i18n/english/luasrc/i18n/cbi.en.xml b/i18n/english/luasrc/i18n/cbi.en.xml index 89484e4ae..4766ad155 100644 --- a/i18n/english/luasrc/i18n/cbi.en.xml +++ b/i18n/english/luasrc/i18n/cbi.en.xml @@ -15,5 +15,6 @@ -- custom -- -- Please choose -- Go to relevant configuration page +Applying changes diff --git a/i18n/german/luasrc/i18n/cbi.de.lua b/i18n/german/luasrc/i18n/cbi.de.lua index a8d68244e..9e6907537 100644 --- a/i18n/german/luasrc/i18n/cbi.de.lua +++ b/i18n/german/luasrc/i18n/cbi.de.lua @@ -10,3 +10,4 @@ cbi_sectempty = 'Diese Sektion enthält noch keine Einträge' cbi_manual = '-- benutzerdefiniert --' cbi_select = '-- Bitte auswählen --' cbi_gorel = 'Gehe zu relevanter Konfigurationsseite' +cbi_applying = 'Änderungen werden angewandt' diff --git a/i18n/german/luasrc/i18n/cbi.de.xml b/i18n/german/luasrc/i18n/cbi.de.xml index dd37f2f49..c989f8d8d 100644 --- a/i18n/german/luasrc/i18n/cbi.de.xml +++ b/i18n/german/luasrc/i18n/cbi.de.xml @@ -14,4 +14,6 @@ -- benutzerdefiniert -- -- Bitte auswählen -- Gehe zu relevanter Konfigurationsseite +Änderungen werden angewandt + diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index b00ccf8d2..09ba553ec 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -211,6 +211,7 @@ function Map.__init__(self, config, ...) self.config = config self.parsechain = {self.config} self.template = "cbi/map" + self.apply_on_parse = nil self.uci = uci.cursor() self.save = true if not self.uci:load(self.config) then @@ -252,7 +253,14 @@ function Map.parse(self, ...) -- Refresh data because commit changes section names self.uci:load(config) end - self.uci:apply(self.parsechain) + if self.apply_on_parse then + self.uci:apply(self.parsechain) + else + self._apply = function() + local cmd = self.uci:apply(self.parsechain, true) + return io.popen(cmd) + end + end -- Reparse sections Node.parse(self, ...) @@ -264,6 +272,15 @@ function Map.parse(self, ...) end end +function Map.render(self, ...) + Node.render(self, ...) + if self._apply then + local fp = self._apply() + fp:read("*a") + fp:close() + end +end + -- Creates a child section function Map.section(self, class, ...) if instanceof(class, AbstractSection) then diff --git a/libs/cbi/luasrc/view/cbi/map.htm b/libs/cbi/luasrc/view/cbi/map.htm index e29b4fc74..e61f8543a 100644 --- a/libs/cbi/luasrc/view/cbi/map.htm +++ b/libs/cbi/luasrc/view/cbi/map.htm @@ -16,6 +16,19 @@ $Id$

<%=self.title%>

<%=self.description%>
+ <%- if self._apply then -%><%:cbi_applying%>: + + <% + local fp = self._apply() + self._apply = nil + local line = fp:read() + while line do + write(line) + line = fp:read() + end + fp:close() + -%> + <%- end -%> <%- self:render_children() %>
-- 2.11.0