From a8cc58127955a9b906910cac24a556a3cb2e60ca Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Fri, 27 Jul 2012 16:53:12 +0800 Subject: [PATCH] Sitemap done for backend and fronted --- app/controllers/admin/sites_controller.rb | 9 ++++++-- app/models/item.rb | 2 +- .../admin/page_parts/_public_r_tag.html.erb | 3 ++- app/views/admin/sites/_side_bar.html.erb | 1 + app/views/admin/sites/_sitemap_block.html.erb | 12 ++++++---- .../admin/sites/sitemap_frontend.html.erb | 23 +++++++++++++++++++ config/list.yml | 1 + config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + config/routes.rb | 1 + lib/parsers/parser_common.rb | 9 ++++++++ 11 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 app/views/admin/sites/sitemap_frontend.html.erb diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index e926f7ea..ffdec04a 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,8 +1,8 @@ class Admin::SitesController < ApplicationController layout "new_admin" - before_filter :authenticate_user! - before_filter :is_admin? + before_filter :authenticate_user!, :except => [:sitemap_frontend] + before_filter :is_admin?, :except => [:sitemap_frontend] before_filter :get_site # def index @@ -31,6 +31,11 @@ class Admin::SitesController < ApplicationController @items = get_homepage.children rescue [] end + def sitemap_frontend + @items = get_homepage.children.excludes(sitemap_enabled: false) rescue [] + render :layout => false + end + def sitemap_toggle @item = Item.find(params[:id]) @item.sitemap_enabled = !@item.sitemap_enabled diff --git a/app/models/item.rb b/app/models/item.rb index 0785b989..f43421af 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -21,7 +21,7 @@ class Item validates_associated :parent, :children before_destroy :destroy_children - after_rearrange :rebuild_path + after_rearrange :rebuild_path, :if => "parent_id_changed?" def self.find_by_name(item_name) diff --git a/app/views/admin/page_parts/_public_r_tag.html.erb b/app/views/admin/page_parts/_public_r_tag.html.erb index d2d4d9b9..68f91dbc 100644 --- a/app/views/admin/page_parts/_public_r_tag.html.erb +++ b/app/views/admin/page_parts/_public_r_tag.html.erb @@ -5,7 +5,8 @@ <% if @r_tag.eql?('sub_menu') %> <%= f.hidden_field :public_r_tag_object_id, :value => @part.page.id %> - <%#= f.select :public_r_tag_object_id, options_for_select([t(:horizontal), t(:vertical)], t(:horizontal)) %> + <%#= f.select :public_r_tag_object_id, options_for_select([t(:horizontal), t(:vertical)], t(:horizontal)) %> + <% elsif @r_tag.eql?('sitemap') %> <% else %> <%= f.select :public_r_tag_object_id, options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %> <% end %> diff --git a/app/views/admin/sites/_side_bar.html.erb b/app/views/admin/sites/_side_bar.html.erb index 1b6b8ba4..bf214a0e 100644 --- a/app/views/admin/sites/_side_bar.html.erb +++ b/app/views/admin/sites/_side_bar.html.erb @@ -7,6 +7,7 @@ <%#= content_tag :li, link_to(t('admin.site_language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %> <%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %> <%#= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %> + <%= content_tag :li, link_to(t('site_map'), admin_site_sitemap_path(@site)), :class => active_for_action('sites', 'sitemap') %> <% end -%> <% end -%> diff --git a/app/views/admin/sites/_sitemap_block.html.erb b/app/views/admin/sites/_sitemap_block.html.erb index d5e3b2ab..1d91f5ac 100644 --- a/app/views/admin/sites/_sitemap_block.html.erb +++ b/app/views/admin/sites/_sitemap_block.html.erb @@ -1,14 +1,16 @@

- <%= sitemap_block.i18n_variable[I18n.locale] %> + <%= sitemap_block_counter + 1 %> <%= sitemap_block.title %>

    - <% sitemap_block.children.each do |child| %> + <% sitemap_block.children.each_with_index do |child, i| %>
  • - - <%= child.i18n_variable[I18n.locale] %> + <%= content_tag :button, :id => child.id, :class => "onoff pull-right", :disabled => !sitemap_block.sitemap_enabled do %> + <%= child.sitemap_enabled ? t('on_upcase') : t('off_upcase') %> + <% end %> + <%= "#{sitemap_block_counter + 1}-#{i + 1}" %> <%= child.title %>
  • <% end if sitemap_block.children %>
-
\ No newline at end of file + diff --git a/app/views/admin/sites/sitemap_frontend.html.erb b/app/views/admin/sites/sitemap_frontend.html.erb new file mode 100644 index 00000000..3656bb2d --- /dev/null +++ b/app/views/admin/sites/sitemap_frontend.html.erb @@ -0,0 +1,23 @@ +
+ <% @items.each_with_index do |item, i| %> +
+

<%= i+1 %> <%= item.title %>

+
    + <% item.children.each_with_index do |child, ii| %> +
  • <%= "#{i+1}-#{ii+1}" %> <%= child.title %>
  • + <% end if item.children %> +
+
+ <% end %> +
+ +<%= javascript_include_tag "lib/jquery.masonry.min.js" %> + \ No newline at end of file diff --git a/config/list.yml b/config/list.yml index ef95ba31..8d1ca9fc 100644 --- a/config/list.yml +++ b/config/list.yml @@ -10,6 +10,7 @@ markups: public_r_tags: - ad_banner - sub_menu + - sitemap page_part_kinds: - text diff --git a/config/locales/en.yml b/config/locales/en.yml index 508adf4c..23b682cb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -68,6 +68,7 @@ en: role: Role site_info: Site Info site_name: Site Name + sitemap: Sitemap statistics: Statistics title: Title total_visitors: Total Visitors diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 7cd0b6a3..15b1c63d 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -66,6 +66,7 @@ zh_tw: role: 角色 site_info: 網站資訊 site_name: 網站名稱 + sitemap: 網站地圖 statistics: 統計 title: 標題 total_visitors: 造訪次數 diff --git a/config/routes.rb b/config/routes.rb index c388d638..b281dd33 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,6 +117,7 @@ Orbit::Application.routes.draw do get 'mail_setting' get 'site_info' get 'sitemap' + get 'sitemap_frontend' get 'sitemap_toggle', :on => :member get 'system_info' get 'ui_theme' diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index c0297699..2c57f3f4 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -161,6 +161,15 @@ module ParserCommon end end + # sitemap + def parse_sitemaps(body = nil, page = nil, edit=nil) + sitemap = body.css('sitemap').first + url = admin_site_sitemap_frontend_path(@site) + options = "?inner=true" + fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") + sitemap.swap(fragment) + end + # page_contents def parse_contents(body, page, edit=nil) public_r_tags = []