Add mongoid-tree to Item

This commit is contained in:
Christophe Vilayphiou committed 2012-05-11 16:16:09 +08:00
1 parent fd52d00187
commit 6a443f0976
13 files changed
+60 -95

No files matched your search

+1 -1
View File
@@ -14,7 +14,7 @@ module ParserBackEnd
# }.join(' | ')
# end
# c.define_tag 'link' do |tag|
# item = Item.first(:conditions => { :full_name => tag.attr['name'] })
# item = Item.first(:conditions => { :path => tag.attr['name'] })
# ret = ''
# ret << "<a href='"
# ret << eval("admin_#{item._type.downcase}_path(item.id)")
+9 -9
View File
@@ -3,7 +3,7 @@ module ParserCommon
def menu_level(page, current_page, current, menu, edit = false)
res = ''
if page.ordered_and_visible_children.size > 0
if page.visible_children.size > 0
res << "<ul class='"
res << menu.values["class_#{current}"] rescue nil
res << "'>"
@@ -12,7 +12,7 @@ module ParserCommon
if menu.values['home'] && current == 1
res << menu_li(page, current_page, current, menu, i, edit)
end
page.ordered_and_visible_children.each do |child|
page.visible_children.each do |child|
res << menu_li(child, current_page, current, menu, i, edit)
i += 1 if i
end
@@ -25,13 +25,13 @@ module ParserCommon
res = "<li class='"
res << menu.values["li_class_#{current}"] rescue nil
res << "_#{i}" if i
res << " active" if (current_page.id.eql?(page.id) || current_page.ancestor_ids.include?(page.id))
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
res << "'>"
res << "<a href='/#{edit ? admin_page_path(page.id) : page.full_name}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
if page.ordered_and_visible_children.size > 0 && current <= menu.levels
res << "<a href='/#{edit ? admin_page_path(page.id) : page.path}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
if page.visible_children.size > 0 && current <= menu.levels
res << "<span class='dot'></span>"
res << menu_level(page, current_page, current + 1, menu, edit)
end unless (page.is_home? rescue nil)
end unless (page.root? rescue nil)
res << "</li>"
end
@@ -113,13 +113,13 @@ module ParserCommon
body.css('sub_menu').each do |sub_menu|
menu_page = Page.find(sub_menu['id']) rescue nil
res = ''
if menu_page && menu_page.ordered_and_visible_children.size > 0
if menu_page && menu_page.visible_children.size > 0
res << "<div class='category_list'>"
res << "<h3 class='h3'>#{menu_page.i18n_variable[I18n.locale]}</h3>"
res << "<ul class='list'>"
menu_page.ordered_and_visible_children.each do |child|
menu_page.visible_children.each do |child|
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
res << "<a href='/#{edit ? admin_page_path(child.id) : child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
res << "<a href='/#{edit ? admin_page_path(child.id) : child.path}'>#{child.i18n_variable[I18n.locale]}</a>"
res << "</li>"
end
res << "</ul>"
+1 -1
View File
@@ -11,7 +11,7 @@ module ParserFrontEnd
# }.join(' | ')
# end
# c.define_tag 'link' do |tag|
# item = Item.first(:conditions => { :full_name => tag.attr['name'] })
# item = Item.first(:conditions => { :path => tag.attr['name'] })
# ret = ''
# ret << "<a href='#{tag.attr['name']}'>"
# ret << item.i18n_variable[I18n.locale]
+19
View File
@@ -0,0 +1,19 @@
# encoding: utf-8
namespace :items do
task :tree_changes => :environment do
Item.all.each do |item|
item.position -= 1
item.parent_ids = ancestors(item)
item.rename(:full_name, :path)
item.save
end
end
def ancestors(item)
node, nodes = item, []
nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
end