X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-mwan3%2Fluasrc%2Fmodel%2Fcbi%2Fmwan%2Fpolicy.lua;h=44585d75efd228cb473ab77f3aaed8289ca37da2;hp=6640564d50cb7b7a206ff7548a3e313ee8a83365;hb=b4350f21ff2f31b7dbcdbc5f034659ba580c059f;hpb=f7cf1dae69a164f4e46daa0c167636f4879b97a0 diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua index 6640564d5..44585d75e 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/policy.lua @@ -1,40 +1,39 @@ --- ------ extra functions ------ -- +ds = require "luci.dispatcher" +sys = require "luci.sys" + +function policyCheck() + local policy_error = {} -function policyCheck() -- check to see if any policy names exceed the maximum of 15 characters uci.cursor():foreach("mwan3", "policy", function (section) + policy_error[section[".name"]] = false if string.len(section[".name"]) > 15 then - nameTooLong = 1 - err_name_list = err_name_list .. section[".name"] .. " " + policy_error[section[".name"]] = true end end ) -end -function policyWarn() -- display status and warning messages at the top of the page - if nameTooLong == 1 then - return "" .. translate("WARNING: Some policies have names exceeding the maximum of 15 characters!") .. "" - else - return "" - end + return policy_error end --- ------ policy configuration ------ -- - -ds = require "luci.dispatcher" -sys = require "luci.sys" - -nameTooLong = 0 -err_name_list = " " -policyCheck() +function policyError(policy_error) + local warnings = "" + for i, k in pairs(policy_error) do + if policy_error[i] == true then + warnings = warnings .. string.format("%s
", + translatef("WARNING: Policie %s has exceeding the maximum name of 15 characters", i) + ) + end + end + return warnings +end -m5 = Map("mwan3", translate("MWAN Policy Configuration"), - policyWarn()) - m5:append(Template("mwan/config_css")) +m5 = Map("mwan3", translate("MWAN - Policies"), + policyError(policyCheck())) -mwan_policy = m5:section(TypedSection, "policy", translate("Policies"), +mwan_policy = m5:section(TypedSection, "policy", nil, translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic
" .. "Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance
" .. "Load-balanced member interfaces distribute more traffic out those with higher weights
" .. @@ -45,11 +44,11 @@ mwan_policy = m5:section(TypedSection, "policy", translate("Policies"), mwan_policy.sectionhead = translate("Policy") mwan_policy.sortable = true mwan_policy.template = "cbi/tblsection" - mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "configuration", "policy", "%s") + mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "policy", "%s") function mwan_policy.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(ds.build_url("admin", "network", "mwan", "configuration", "policy", section)) + luci.http.redirect(ds.build_url("admin", "network", "mwan", "policy", section)) end @@ -80,15 +79,4 @@ last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last reso end end -errors = mwan_policy:option(DummyValue, "errors", translate("Errors")) - errors.rawhtml = true - function errors.cfgvalue(self, s) - if not string.find(err_name_list, " " .. s .. " ") then - return "" - else - return "\"error\"" - end - end - - return m5