summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-12-23 16:51:17 +0000
committerTed Trask <ttrask01@yahoo.com>2009-12-23 16:51:17 +0000
commit17ecdf3680593a739bf32186e8ca1a0dcaf9ea10 (patch)
treebea1fda559cef53cc3a524f656ca6fdf52302b7c
parentda8d6a71739aa6e1eff39a099893b33b1ad51569 (diff)
downloadacf-core-17ecdf3680593a739bf32186e8ca1a0dcaf9ea10.tar.bz2
acf-core-17ecdf3680593a739bf32186e8ca1a0dcaf9ea10.tar.xz
Modified menus to allow multiple controllers to use same menu group.
Also, allow for symlinks when searching for menu files. Slight cleanup of roles.
-rw-r--r--app/acf_www-controller.lua18
-rw-r--r--app/template-html.lsp13
-rw-r--r--lib/menubuilder.lua11
-rw-r--r--lib/roles.lua6
4 files changed, 24 insertions, 24 deletions
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 12a7a43..ee7f344 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -34,19 +34,15 @@ local function build_menus(self)
local cat = cats[x]
for y = #cat.groups,1,-1 do
local group = cat.groups[y]
- if nil == permissions[group.prefix] or nil == permissions[group.prefix][group.controller] then
- table.remove(cat.groups, y)
- else
- for z = #group.tabs,1,-1 do
- local tab = group.tabs[z]
- if nil == permissions[group.prefix][group.controller][tab.action] then
- table.remove(group.tabs, z)
- end
- end
- if 0 == #group.tabs then
- table.remove(cat.groups, y)
+ for z = #group.tabs,1,-1 do
+ local tab = group.tabs[z]
+ if nil == permissions[tab.prefix] or nil == permissions[tab.prefix][tab.controller] or nil == permissions[tab.prefix][tab.controller][tab.action] then
+ table.remove(group.tabs, z)
end
end
+ if 0 == #group.tabs then
+ table.remove(cat.groups, y)
+ end
end
if 0 == #cat.groups then
table.remove(cats, x)
diff --git a/app/template-html.lsp b/app/template-html.lsp
index c1aeafd..2b0d58c 100644
--- a/app/template-html.lsp
+++ b/app/template-html.lsp
@@ -74,14 +74,13 @@ end
for x,cat in ipairs(session.menu.cats) do
io.write (string.format("\n\t\t\t\t<li>%s\n\t\t\t\t\t<ul>\n", html.html_escape(cat.name))) --start row
for y,group in ipairs(cat.groups) do
- if pageinfo.prefix == group.prefix and pageinfo.controller == group.controller then
+ class=""
+ if not tabs and group.controllers[pageinfo.prefix .. pageinfo.controller] then
class="class='selected'"
tabs = group.tabs
- else
- class=""
end
io.write (string.format("\t\t\t\t\t\t<li %s><a href=\"%s%s%s/%s\">%s</a></li>\n",
- class,html.html_escape(pageinfo.script),html.html_escape(group.prefix), html.html_escape(group.controller), html.html_escape(group.tabs[1].action), html.html_escape(group.name) ))
+ class,html.html_escape(pageinfo.script),html.html_escape(group.tabs[1].prefix), html.html_escape(group.tabs[1].controller), html.html_escape(group.tabs[1].action), html.html_escape(group.name) ))
end
io.write ( "\t\t\t\t\t</ul>" )
end
@@ -113,13 +112,13 @@ end
<ul>
<% local class="" %>
<% for x,tab in pairs(tabs or {}) do
- if tab.action == pageinfo.action then
+ if tab.prefix == pageinfo.prefix and tab.controller == pageinfo.controller and tab.action == pageinfo.action then
class="class='selected'"
else
class=""
end
- io.write (string.format('<li %s><a %s href="%s">%s</a></li>\n',
- class,class,html.html_escape(tab.action),html.html_escape(tab.name) ))
+ io.write (string.format('<li %s><a %s href="%s%s%s/%s">%s</a></li>\n',
+ class,class,html.html_escape(pageinfo.script),html.html_escape(tab.prefix),html.html_escape(tab.controller),html.html_escape(tab.action),html.html_escape(tab.name) ))
end
%>
</ul>
diff --git a/lib/menubuilder.lua b/lib/menubuilder.lua
index 975c31a..3922129 100644
--- a/lib/menubuilder.lua
+++ b/lib/menubuilder.lua
@@ -10,7 +10,7 @@ require("format")
-- returns a table of the "*.menu" tables
-- startdir should be the app dir.
local get_candidates = function (startdir)
- return fs.find_files_as_array(".*%.menu", startdir)
+ return fs.find_files_as_array(".*%.menu", startdir, true)
end
-- Split string into priority and name, convert '_' to space
@@ -87,16 +87,19 @@ get_menuitems = function (startdir)
if nil == cat.groups[cat.reversegroups[result.group]] then
table.insert ( cat.groups,
{ name = result.group,
- controller = controller,
- prefix = prefix,
+ controllers = {},
tabs = {} } )
cat.reversegroups[result.group] = #cat.groups
end
+ cat.groups[cat.reversegroups[result.group]].controllers[prefix..controller] = true
local group = cat.groups[cat.reversegroups[result.group]]
group.priority = group.priority or result.group_prio
-- Add the tab
if nil == result.tab or nil == result.action then break end
- local tab = { name = result.tab, action = result.action }
+ local tab = { name = result.tab,
+ controller = controller,
+ prefix = prefix,
+ action = result.action }
table.insert(group.tabs, tab)
end
end
diff --git a/lib/roles.lua b/lib/roles.lua
index 059ef59..9d89f0c 100644
--- a/lib/roles.lua
+++ b/lib/roles.lua
@@ -139,7 +139,6 @@ local determine_perms = function(self,roles)
for x,file in ipairs(rolesfiles) do
local prefix = string.match(file, "(/[^/]+/)[^/]+$") or "/"
- permissions[prefix] = permissions[prefix] or {}
f = fs.read_file_as_array(file) or {}
for y,line in pairs(f) do
if reverseroles[string.match(line,"^[%w_]+")] then
@@ -148,6 +147,9 @@ local determine_perms = function(self,roles)
-- we'll allow for : or / to not break old format
local control,action = string.match(perm,"([%w_]+)[:/]([%w_]+)")
if control then
+ if nil == permissions[prefix] then
+ permissions[prefix] = {}
+ end
if nil == permissions[prefix][control] then
permissions[prefix][control] = {}
end
@@ -182,7 +184,7 @@ local determine_perms = function(self,roles)
end
end
end
-
+
return permissions, permissions_array, default_permissions_array
end