Change names for page.

This commit is contained in:
BoHung Chiu 2021-05-11 12:31:58 +08:00
parent b5f80a0646
commit 2f839eb78d
1 changed files with 37 additions and 2 deletions

View File

@ -4,13 +4,48 @@ class BreadcrumbWidgetsController < ApplicationController
url = params["url"] url = params["url"]
crumbs = url.split("/") crumbs = url.split("/")
data = [] data = []
crumbs.each do |crumb| uid = nil
if params[:page].class == String && params[:page].include?("-")
uid = params[:page].split("-").last
end
crumbs.each_with_index do |crumb,i|
if crumb == "" if crumb == ""
p = Page.root p = Page.root
data << {"page_name" => p.name.gsub(/<br>|<BR>/,''), "url" => "/?locale=#{locale.to_s}"} data << {"page_name" => p.name.gsub(/<br>|<BR>/,''), "url" => "/?locale=#{locale.to_s}"}
else else
p = Page.where(:page_id => crumb).first p = Page.where(:page_id => crumb).first
data << {"page_name" => p.name.gsub(/<br>|<BR>/,''), "url" => "/#{locale.to_s}" + p.url} page_name = p.name.gsub(/<br>|<BR>/,'') rescue ""
if i == crumbs.count - 1
override_page_name = nil
if uid.present? && p.module.present?
module_app = ModuleApp.find_by_key(p.module) rescue nil
registration_module = OrbitApp::Module::Registration.find_by_key(p.module) rescue nil
taggable_model = registration_module.taggable_model.constantize rescue nil
puts p.module
if module_app && registration_module
model = taggable_model.where(:uid=>uid).first
if model
if (model.category.present? rescue false)
override_page_name = model.category.title rescue nil
end
if (model.tags.present? && model.tags.count == 1 rescue false)
override_page_name = model.tags.first.name rescue nil
end
end
end
else
if params[:category].present?
override_page_name = Category.find(Array(params[:category]).first).title rescue nil
end
if params[:tags].present?
override_page_name = Tag.find(Array(params['tags']).first).name rescue nil
end
end
if override_page_name.present?
page_name = override_page_name
end
end
data << {"page_name" => page_name, "url" => "/#{locale.to_s}" + p.url}
end end
end end
{ {