This commit is contained in:
BoHung Chiu 2022-11-15 16:31:50 +08:00
parent 09a1772f46
commit 5b54171b32
1 changed files with 48 additions and 1 deletions

View File

@ -1,9 +1,42 @@
class SiteMenuWidgetsController < ApplicationController class SiteMenuWidgetsController < ApplicationController
def create_json_process_ip_later(pages)
items = []
pages.each do |page|
item = {}
item["obj"] = page
is_ip = (page.access_level == 'ip')
next if !page.user_can_access?(current_user) && !is_ip
if page.child_page.size > 0
item["page_name"] = page.name
item['dropdown'] = 'dropdown-menu'
item["children"] = create_json_process_ip_later(page.sorted_published_child_pages)
else
item["page_name"] = page.name
item['dropdown'] = ''
item["children"] = []
end
if page.page_type == "link"
item["url"] = page.external_url
item["target"] = (is_internal_url?(page.external_url) ? "_self" : "_blank") rescue "_blank"
else
item["url"] = "/#{locale.to_s}" + page.url
item["target"] = "_self"
end
item['active_class'] = (@page_id==page.id ? 'active' : '')
if is_ip
item['url'] = "#{item['url']}\" data-ip=\"true"
item['dropdown'] = "#{item['dropdown']}\" data-ip=\"true"
end
items << item
end
items
end
def create_json(pages) def create_json(pages)
items = [] items = []
pages.each do |page| pages.each do |page|
item = {} item = {}
item["obj"] = page item["obj"] = page
next if !page.user_can_access?(current_user)
if page.child_page.size > 0 if page.child_page.size > 0
item["page_name"] = page.name item["page_name"] = page.name
item['dropdown'] = 'dropdown-menu' item['dropdown'] = 'dropdown-menu'
@ -55,6 +88,16 @@ class SiteMenuWidgetsController < ApplicationController
@expand_layer = false @expand_layer = false
@expand_next_layer = false @expand_next_layer = false
@expand_current_layer = false @expand_current_layer = false
@site = (current_site rescue Site.first)
@need_process_ip = (@site.need_process_ip rescue false)
@has_privileged_page = (@site.has_privileged_page rescue false)
@process_ip_later = false
if @need_process_ip
@process_ip_later = OrbitHelper.current_user.nil? && @site.enable_cache unless @no_cache_for_this_request
unless @process_ip_later
@need_process_ip = @site.check_ip_is_privileged?((OrbitHelper.request.remote_ip rescue ""))
end
end
if page.parent_page == Page.root if page.parent_page == Page.root
@pages = page.sorted_published_child_pages @pages = page.sorted_published_child_pages
else else
@ -95,7 +138,11 @@ class SiteMenuWidgetsController < ApplicationController
@count1 = -1 @count1 = -1
@li_index = [] @li_index = []
title = subpart.title title = subpart.title
if @process_ip_later
items = create_json_process_ip_later(@pages)
else
items = create_json(@pages) items = create_json(@pages)
end
if @expand_layer if @expand_layer
create_menu_bool_object(items) create_menu_bool_object(items)
temp = @ul_index.reverse.collect do |ul_index| temp = @ul_index.reverse.collect do |ul_index|