From 15b9839b769ecdd243037a5f481d887c1a17facc Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Mon, 4 Mar 2013 14:40:29 +0800 Subject: [PATCH 1/4] fix archive category fix page adding failed --- app/views/admin/pages/_data_count_field.html.erb | 2 +- app/views/admin/pages/reload_frontend_pages.js.erb | 2 +- vendor/built_in_modules/archive/init.rb | 2 +- vendor/built_in_modules/gallery/init.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/pages/_data_count_field.html.erb b/app/views/admin/pages/_data_count_field.html.erb index 48f355f0..1934b067 100644 --- a/app/views/admin/pages/_data_count_field.html.erb +++ b/app/views/admin/pages/_data_count_field.html.erb @@ -2,5 +2,5 @@ <%= t("default_widget.widget_data_count") %>
- <%= select_tag(field_name,options_for_select(@module_app.get_registration.get_data_count,field_value )) %> + <%= select_tag(field_name,options_for_select((@module_app.get_registration.get_data_count rescue []),field_value )) %>
\ No newline at end of file diff --git a/app/views/admin/pages/reload_frontend_pages.js.erb b/app/views/admin/pages/reload_frontend_pages.js.erb index 215ec3fb..f262a753 100644 --- a/app/views/admin/pages/reload_frontend_pages.js.erb +++ b/app/views/admin/pages/reload_frontend_pages.js.erb @@ -1,7 +1,7 @@ <% if @module_app %> $('#app_page_category').html("<%= j render :partial => 'admin/page_parts/widget_data_source_category' ,:locals=>{:object=>@page}%>"); $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@page} %>"); - $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>@page.frontend_data_count} %>"); + $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>(@page.frontend_data_count rescue nil)} %>"); <% if !@module_app.app_pages.blank? %> $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, @app_frontend_urls.first)) %>"); diff --git a/vendor/built_in_modules/archive/init.rb b/vendor/built_in_modules/archive/init.rb index eaac9765..7e32c041 100644 --- a/vendor/built_in_modules/archive/init.rb +++ b/vendor/built_in_modules/archive/init.rb @@ -35,7 +35,7 @@ module Archive head_label_i18n 'archive.archive',:icon_class=>"icons-archive" available_for [:admin,:guest,:manager,:sub_manager] active_for_controllers ({:private=>['archive_file_categorys','archive_files'],:public=>['panel/archive/back_end/tags']}) - active_for_object_auth ['BulletinCategory'] + # active_for_object_auth ['BulletinCategory'] head_link_path "panel_archive_back_end_archive_files_path" diff --git a/vendor/built_in_modules/gallery/init.rb b/vendor/built_in_modules/gallery/init.rb index d71b8af5..4bf15d27 100644 --- a/vendor/built_in_modules/gallery/init.rb +++ b/vendor/built_in_modules/gallery/init.rb @@ -44,7 +44,7 @@ module Gallery head_label_i18n 'gallery.gallery',:icon_class=>"icons-pictures" available_for [:admin,:guest,:manager,:sub_manager] active_for_controllers ({:private=>['albums','album_images','gallery_categories','/panel/gallery/back_end/tags']}) - active_for_object_auth ['BulletinCategory'] + active_for_object_auth ['GalleryCategory'] head_link_path "panel_gallery_back_end_albums_path" From 285119a5f37a27de89cf40399b77c350cc7716f9 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Mon, 4 Mar 2013 19:29:45 +0800 Subject: [PATCH 2/4] fix for multi select cates and tags --- app/controllers/admin/page_parts_controller.rb | 2 +- app/controllers/default_widget_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index fea1bf3f..4f72f97e 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -73,7 +73,7 @@ class Admin::PagePartsController < ApplicationController params[:page_part][:category] = [] end - params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} + params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page_part][:widget_field].blank? if @part.update_attributes(params[:page_part]) set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu') diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index 686a0316..e938ca45 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -20,13 +20,13 @@ class DefaultWidgetController< OrbitWidgetController if params["category_id"].blank? result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}}.flatten else - result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:category_id=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten + result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:category_id.in=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten end result = eval("#{ori_class_name}.where(:id=>result_ids)") elsif params["category_id"].blank? result = eval(@default_widget["query"]) else - result = eval("#{ori_class_name}.where(:category_id=>params['category_id'])") + result = eval("#{ori_class_name}.where(:category_id.in=>params['category_id'])") end result.available_for_lang(I18n.locale).can_display end From 626b2a7bca7dc4d7d65d8c0f7890afe83b8ee882 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Tue, 5 Mar 2013 11:48:20 +0800 Subject: [PATCH 3/4] fix default failed when cate or tags set to empty --- app/controllers/default_widget_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index e938ca45..d9fb8af0 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -14,6 +14,9 @@ class DefaultWidgetController< OrbitWidgetController ori_class_name = @default_widget["query"].split('.')[0] result = nil result_objects = nil + params["tag_id"] = [] if params["tag_id"]=="[]" + params["category_id"] = [] if params["category_id"]=="[]" + if !params["tag_id"].blank? @tags = Tag.find(params["tag_id"]) rescue nil result_ids = nil @@ -32,7 +35,6 @@ class DefaultWidgetController< OrbitWidgetController end def default_widget - if !params[:id].blank? redirect_to eval("#{@page_part.module_app.widget_fields_link_method['title']['method']}('#{params[:id]}', {inner: #{params[:inner] || true}})") else @@ -50,10 +52,10 @@ class DefaultWidgetController< OrbitWidgetController @data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) end if @paginate - @data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit) + @data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at) # @data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field) else - @data = eval(@default_widget["query"]).includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at) + @data = query_for_default_widget.includes(@widget_image_field).desc(:created_at) # @data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at) end case params[:type] From dc3966be8152097035192235988fb1d3bbfbe4ed Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Tue, 5 Mar 2013 18:34:41 +0800 Subject: [PATCH 4/4] fix cates and tags --- app/controllers/application_controller.rb | 8 ++++- app/controllers/default_widget_controller.rb | 32 ++++++++++++++------ lib/parsers/parser_common.rb | 16 ++++++++-- lib/parsers/parser_front_end.rb | 17 +++++++++-- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7f4ea0fa..6e5f80e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -234,7 +234,13 @@ class ApplicationController < ActionController::Base ret = '' ret << "/panel/#{@item.module_app.key}/front_end/#{@item.app_frontend_url}.rss" ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(@item.id.to_s) - ret << "?inner=true&category_id=#{params[:category]}&tag_id=#{params[:tag]}&page_main=#{params[:page_main]}" + + categories_str=params[:category].collect{|t| "category_id[]=#{t}"}.join('&') + tags_str=params[:tag].collect{|t| "tag_id[]=#{t}"}.join('&') + categories_str = "&#{categories_str}" unless categories_str.blank? + tags_str = "&#{tags_str}" unless tags_str.blank? + + ret << "?inner=true#{categories_str}#{tags_str}&page_main=#{params[:page_main]}" redirect_to ret end diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index d9fb8af0..0bff5ebc 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -11,26 +11,32 @@ class DefaultWidgetController< OrbitWidgetController end def query_for_default_widget + ori_class_name = @default_widget["query"].split('.')[0] result = nil result_objects = nil - params["tag_id"] = [] if params["tag_id"]=="[]" - params["category_id"] = [] if params["category_id"]=="[]" if !params["tag_id"].blank? @tags = Tag.find(params["tag_id"]) rescue nil result_ids = nil - if params["category_id"].blank? - result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}}.flatten - else - result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:category_id.in=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten + + result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}} + if params["category_id"].blank? #has tag no cate + #nothing + else #has tag and cate + # result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:#{get_category_field_name(ori_class_name)}.in=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten + result_ids << eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id']).entries.collect{|t| t.id}") + result_ids.flatten! + end result = eval("#{ori_class_name}.where(:id=>result_ids)") - elsif params["category_id"].blank? + elsif params["category_id"].blank? #no tag no cate + result = eval(@default_widget["query"]) - else - result = eval("#{ori_class_name}.where(:category_id.in=>params['category_id'])") + else #no tag has cate + result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'])") end + result.available_for_lang(I18n.locale).can_display end @@ -72,4 +78,12 @@ class DefaultWidgetController< OrbitWidgetController end end + def get_category_field_name(ori_class_name) + ori_class_name = ori_class_name.constantize + ori_class_name.fields.each_key do |key| + return key if key.include?('category_id') + end + nil + end + end diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 7d858686..d2f8b7b2 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -236,7 +236,13 @@ module ParserCommon end ret << "
" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil @@ -258,7 +264,13 @@ module ParserCommon raise ModuleAppError,"PagePart can't find ModuleApp" if part.module_app.nil? "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" end - options = "&part_id=#{part.id}&category_id=#{!part[:category].blank? ? part[:category] : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part" + + categories_str=(!part[:category].blank? ? part[:category] : category).collect{|t| "category_id[]=#{t}"}.join('&') + tags_str=(!part[:tag].blank? ? part[:tag] : tag).collect{|t| "tag_id[]=#{t}"}.join('&') + categories_str = "&#{categories_str}" unless categories_str.blank? + tags_str = "&#{tags_str}" unless tags_str.blank? + + options = "&part_id=#{part.id}#{categories_str}#{tags_str}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part" ret << "
" when 'public_r_tag' ret << "" diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 2ab10cdd..ff463f81 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -110,6 +110,7 @@ module ParserFrontEnd public_r_tags = [] url = '' body.css('.page_content').each do |content| + ret = '' if (content["main"] == "true" && !page.module_app.nil?) if page.app_frontend_url == 'default_widget' @@ -119,8 +120,12 @@ module ParserFrontEnd url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}\#{(\"/\" + params[:id]) if params[:id] && !params[:id].eql?(page.id.to_s)}\#{(\"/\" + params[:controller_action]) if params[:controller_action] && params[:id]}?inner=true" end - - options = "&page_id=#{page.id}&category_id=\#{category}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page" + categories_str=category.collect{|t| "category_id[]=#{t}"}.join('&') + tags_str=tag.collect{|t| "tag_id[]=#{t}"}.join('&') + categories_str = "&#{categories_str}" unless categories_str.blank? + tags_str = "&#{tags_str}" unless tags_str.blank? + + options = "&page_id=\#{page.id}#{categories_str}#{tags_str}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page" ret << "" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil @@ -137,7 +142,13 @@ module ParserFrontEnd else "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" end - options = "&part_id=\#{part.id}&category_id=\#{part[:category]}&tag_id=\#{part[:tag]}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part" + + categories_str=part[:category].collect{|t| "category_id[]=#{t}"}.join('&') + tags_str=part[:tag].collect{|t| "tag_id[]=#{t}"}.join('&') + categories_str = "&#{categories_str}" unless categories_str.blank? + tags_str = "&#{tags_str}" unless tags_str.blank? + + options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part" ret << "" when 'public_r_tag'