From f190ce18ee4ac8a99b9508c9289e43d8f8454eaa Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Sat, 5 May 2012 21:20:20 +0800 Subject: [PATCH] Put sorting in web_link, page_context and design --- app/controllers/admin/designs_controller.rb | 11 ++- app/controllers/orbit_backend_controller.rb | 8 +- app/helpers/orbit_backend_helper.rb | 2 +- app/models/design/design.rb | 8 +- app/views/admin/designs/_design.html.erb | 14 ++++ app/views/admin/designs/_designs.html.erb | 12 +++ app/views/admin/designs/_filter.html.erb | 11 +++ .../admin/designs/_sort_headers.html.erb | 3 + app/views/admin/designs/index.html.erb | 54 ++---------- app/views/admin/designs/index.js.erb | 3 + config/routes.rb | 1 + .../back_end/bulletins_controller.rb | 82 ------------------- .../back_end/news_bulletins_controller.rb | 82 ------------------- .../back_end/page_contexts_controller.rb | 3 +- .../back_end/page_contexts/_filter.html.erb | 11 +++ .../page_contexts/_sort_headers.html.erb | 4 + .../back_end/page_contexts/index.html.erb | 26 ++---- .../back_end/page_contexts/index.js.erb | 3 + .../back_end/web_links_controller.rb | 7 ++ .../back_end/web_links/_sort_headers.html.erb | 2 +- .../back_end/web_links/_web_link.html.erb | 5 ++ .../back_end/web_links/index.html.erb | 31 +++---- .../web_resource/config/routes.rb | 6 +- 23 files changed, 130 insertions(+), 259 deletions(-) create mode 100644 app/views/admin/designs/_design.html.erb create mode 100644 app/views/admin/designs/_designs.html.erb create mode 100644 app/views/admin/designs/_filter.html.erb create mode 100644 app/views/admin/designs/_sort_headers.html.erb create mode 100644 app/views/admin/designs/index.js.erb create mode 100644 vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_filter.html.erb create mode 100644 vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb create mode 100644 vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.js.erb diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index ff41c0b4..84f2b770 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -1,4 +1,4 @@ -class Admin::DesignsController < ApplicationController +class Admin::DesignsController < OrbitBackendController require "net/http" require "uri" require 'zip/zip' @@ -25,7 +25,7 @@ class Admin::DesignsController < ApplicationController end def index - @designs = Design.all.entries + @designs = params[:sort] ? get_sorted_and_filtered("designs") : Design.all end def new @@ -84,6 +84,13 @@ class Admin::DesignsController < ApplicationController render :action => 'new' end end + + def delete + if params[:to_delete] + designs = Design.any_in(:_id => params[:to_delete]).delete_all + end + redirect_to admin_designs_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end protected diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 8655e93f..a03a1f6c 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -27,9 +27,13 @@ class OrbitBackendController< ApplicationController end end - def get_sorted_and_filtered(object_class) + def get_sorted_and_filtered(object_class, query=nil) object_class = object_class.classify.constantize - objects = object_class.all + if query + objects = object_class.all.where(query) + else + objects = object_class.all + end if !params[:sort].blank? options = params[:sort_options] diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index 55f44d61..5d47e414 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -27,7 +27,7 @@ module OrbitBackendHelper concat (content_tag :th, :class => "span1 strong" do concat check_box_tag :check_all concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove" - end) if delete_all && is_manager? + end) if (delete_all && (is_admin? || (is_manager? rescue nil))) titles.each do |title| concat render_title(title[0], title[1], title[2], title[3]) end diff --git a/app/models/design/design.rb b/app/models/design/design.rb index 2a25dd11..58f95bd4 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -3,10 +3,10 @@ class Design include Mongoid::Timestamps include ParserLayout - field :title - field :author - field :intro - field :version + field :title, :type => String + field :author, :type => String + field :intro, :type => String + field :version, :type => String has_many :pages diff --git a/app/views/admin/designs/_design.html.erb b/app/views/admin/designs/_design.html.erb new file mode 100644 index 00000000..e7aec0ba --- /dev/null +++ b/app/views/admin/designs/_design.html.erb @@ -0,0 +1,14 @@ + + <%= check_box_tag 'to_delete[]', design.id, false, :class => "checkbox_in_list" %> + + <%= design.title %> +
+ +
+ + <%= design.author %> + <%= design.intro %> + \ No newline at end of file diff --git a/app/views/admin/designs/_designs.html.erb b/app/views/admin/designs/_designs.html.erb new file mode 100644 index 00000000..838057f2 --- /dev/null +++ b/app/views/admin/designs/_designs.html.erb @@ -0,0 +1,12 @@ + + + + + + + + + + + <%= render :partial => 'design', :collection => @designs %> + \ No newline at end of file diff --git a/app/views/admin/designs/_filter.html.erb b/app/views/admin/designs/_filter.html.erb new file mode 100644 index 00000000..02ba839b --- /dev/null +++ b/app/views/admin/designs/_filter.html.erb @@ -0,0 +1,11 @@ + + +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "sort_header" %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/designs/_sort_headers.html.erb b/app/views/admin/designs/_sort_headers.html.erb new file mode 100644 index 00000000..15f5481f --- /dev/null +++ b/app/views/admin/designs/_sort_headers.html.erb @@ -0,0 +1,3 @@ +<%= render_sort_bar(true, ['title', 'title','span7', 'admin.title'], + ['author', 'author', 'span2', 'admin.author'], + ['intro', 'intro', 'span2', 'admin.intro']).html_safe %> diff --git a/app/views/admin/designs/index.html.erb b/app/views/admin/designs/index.html.erb index 13837003..8c4608d8 100644 --- a/app/views/admin/designs/index.html.erb +++ b/app/views/admin/designs/index.html.erb @@ -1,52 +1,10 @@ -<%= flash_messages %> - +<%= form_for :news_bulletins, :url => delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> + <%= render 'filter' %> + + <%= render 'designs' %> +
+<% end %> - - - - - - - - - - - <% @designs.each do |design| %> - - - - - - - <% end %> - -
- <%= design.title %> -
- -
-
<%= design.author %><%= design.intro %>
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_admin_design_path, :class => 'btn btn-primary' %>
\ No newline at end of file diff --git a/app/views/admin/designs/index.js.erb b/app/views/admin/designs/index.js.erb new file mode 100644 index 00000000..5c61066b --- /dev/null +++ b/app/views/admin/designs/index.js.erb @@ -0,0 +1,3 @@ +$("#delete_all").attr("action", "<%= delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) %>"); +$("#sort_headers").html("<%= j render 'sort_headers' %>"); +$("#tbody_designs").html("<%= j render :partial => 'design', :collection => @designs %>"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c90a5ae0..6ded5149 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,7 @@ Orbit::Application.routes.draw do resources :designs do collection do get 'upload_package' + post 'delete' post 'upload_package' end member do diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 5f210f3c..8700283a 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -331,87 +331,5 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController module_app = ModuleApp.first(:conditions => {:key => 'announcement'}) @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) end - - def get_sorted_and_filtered_bulletins - bulletins = Bulletin.all - case params[:sort] - when 'postdate', 'deadline' - bulletins = bulletins.order_by([params[:sort], params[:direction]]) - when 'category' - category_ids = bulletins.distinct(:bulletin_category_id) - categories = BulletinCategory.find(category_ids) rescue nil - if categories - h = Hash.new - categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id } - sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - sorted_categorys = sorted.collect {|a| bulletins.where(:bulletin_category_id => a[1]).entries } - bulletins = sorted_categorys.flatten! - end - when 'title' - h = Array.new - bulletins.each { |bulletin| h << [bulletin.title[I18n.locale].downcase, bulletin] } - sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - bulletins = sorted.collect {|a| a[1] } - when 'status' - bulletins = bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction]) - when 'update_user_id' - user_ids = bulletins.distinct(:update_user_id) - users = User.find(user_ids) rescue nil - if users - h = Array.new - users.each { |user| h << [user.name, user.id] } - sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - sorted_users = sorted.collect {|a| bulletins.where(:update_user_id => a[1]).entries } - bulletins = sorted_users.flatten - end - when 'tags' - a = Array.new - AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins } - a.flatten! - a.uniq! - tmp = Array.new - bulletins.where(:tag_ids => []).each { |bulletin| tmp << [bulletin.title[I18n.locale].downcase, bulletin] } - sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse! - sorted_titles = sorted.collect {|a| a[1] } - a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles) - bulletins = a.flatten - end - if @filter - @filter.each do |key, value| - case key - when 'status' - a = Array.new - bulletins.each do |bulletin| - value.each do |v| - case v - when 'pending' - a << bulletin if bulletin.is_checked.nil? - when 'rejected' - a << bulletin if bulletin.is_checked.eql?(false) - else - a << bulletin if bulletin[v] - end - end - end - bulletins = a.uniq - when 'categories' - a = Array.new - bulletins.each do |bulletin| - a << bulletin if value.include?(bulletin.bulletin_category.id.to_s) - end - bulletins = a.uniq - when 'tags' - a = Array.new - bulletins.each do |bulletin| - bulletin.tags.each do |tag| - a << bulletin if value.include?(tag.id.to_s) - end - end - bulletins = a.uniq - end if value.size > 0 - end - end - Kaminari.paginate_array(bulletins).page(params[:page]).per(10) - end end diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb index a2a1a881..e845cbd1 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb @@ -333,86 +333,4 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) end - def get_sorted_and_filtered_news_bulletins - news_bulletins = NewsBulletin.all - case params[:sort] - when 'postdate', 'deadline' - news_bulletins = news_bulletins.order_by([params[:sort], params[:direction]]) - when 'category' - category_ids = news_bulletins.distinct(:news_bulletin_category_id) - categories = NewsBulletinCategory.find(category_ids) rescue nil - if categories - h = Hash.new - categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id } - sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - sorted_categorys = sorted.collect {|a| news_bulletins.where(:news_bulletin_category_id => a[1]).entries } - news_bulletins = sorted_categorys.flatten! - end - when 'title' - h = Array.new - news_bulletins.each { |news_bulletin| h << [news_bulletin.title[I18n.locale].downcase, news_bulletin] } - sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - news_bulletins = sorted.collect {|a| a[1] } - when 'status' - news_bulletins = news_bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).order_by(:is_pending, params[:direction]).order_by(:is_checked, params[:direction]).order_by(:is_rejected, params[:direction]) - when 'update_user_id' - user_ids = news_bulletins.distinct(:update_user_id) - users = User.find(user_ids) rescue nil - if users - h = Array.new - users.each { |user| h << [user.name, user.id] } - sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - sorted_users = sorted.collect {|a| news_bulletins.where(:update_user_id => a[1]).entries } - news_bulletins = sorted_users.flatten - end - when 'tags' - a = Array.new - NewsTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.news_bulletins } - a.flatten! - a.uniq! - tmp = Array.new - news_bulletins.where(:tag_ids => []).each { |news_bulletin| tmp << [news_bulletin.title[I18n.locale].downcase, news_bulletin] } - sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse! - sorted_titles = sorted.collect {|a| a[1] } - a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles) - news_bulletins = a.flatten - end - if @filter - @filter.each do |key, value| - case key - when 'status' - a = Array.new - news_bulletins.each do |news_bulletin| - value.each do |v| - case v - when 'pending' - a << news_bulletin if news_bulletin.is_checked.nil? - when 'rejected' - a << news_bulletin if news_bulletin.is_checked.eql?(false) - else - a << news_bulletin if news_bulletin[v] - end - end - end - news_bulletins = a.uniq - when 'categories' - a = Array.new - news_bulletins.each do |news_bulletin| - a << news_bulletin if value.include?(news_bulletin.news_bulletin_category.id.to_s) - end - news_bulletins = a.uniq - when 'tags' - a = Array.new - news_bulletins.each do |news_bulletin| - news_bulletin.tags.each do |tag| - a << news_bulletin if value.include?(tag.id.to_s) - end - end - news_bulletins = a.uniq - end if value.size > 0 - end - end - Kaminari.paginate_array(news_bulletins).page(params[:page]).per(10) - end - end diff --git a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb index 87f3447c..6ae315fb 100644 --- a/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb +++ b/vendor/built_in_modules/page_content/app/controllers/panel/page_content/back_end/page_contexts_controller.rb @@ -5,11 +5,12 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll def index - @page_contexts = PageContext.where(:archived => false).desc(:updated_at).page(params[:page]).per(10) + @page_contexts = params[:sort] ? get_sorted_and_filtered("page_contexts", {:archived => false}) : PageContext.where(:archived => false).page(params[:page]).per(10) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @page_contexts } + format.js {} end end diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_filter.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_filter.html.erb new file mode 100644 index 00000000..02ba839b --- /dev/null +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_filter.html.erb @@ -0,0 +1,11 @@ + + +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "sort_header" %> +<% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb new file mode 100644 index 00000000..7a37d4a7 --- /dev/null +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb @@ -0,0 +1,4 @@ +<%= render_sort_bar(false, ['name', 'page','span7', 'page_context.name'], + ['version', 'version', 'span2', 'page_context.version'], + ['update_time', 'updated_at', 'span2', 'page_context.update_time'], + ['last_modified', 'update_user_id', 'span2', 'page_context.last_modified']).html_safe %> diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.html.erb index a71c45eb..1ab0f27a 100644 --- a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.html.erb +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.html.erb @@ -1,22 +1,6 @@ <%= flash_messages %> - - +<%= render 'filter' %> @@ -27,13 +11,13 @@ - + <%= render :partial => 'page_context', :collection => @page_contexts %>
-<%= paginate @page_contexts %> - - +
+ <%= paginate @page_contexts, :params => {:direction => params[:direction], :sort => params[:sort]} %> +
diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.js.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.js.erb new file mode 100644 index 00000000..aba5dd93 --- /dev/null +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/index.js.erb @@ -0,0 +1,3 @@ +$("#sort_headers").html("<%= j render 'sort_headers' %>"); +$("#tbody_page_contexts").html("<%= j render :partial => 'page_context', :collection => @page_contexts %>"); +$("#page_context_pagination").html("<%= j paginate @page_contexts, :params => {:direction => params[:direction], :sort => params[:sort]} %>"); \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb index 25c41606..69aa8c1a 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb @@ -122,6 +122,13 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController format.js end end + + def delete + if params[:to_delete] + web_links = WebLink.any_in(:_id => params[:to_delete]).delete_all + end + redirect_to panel_web_resource_back_end_web_links_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) + end protected diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb index e405811c..8873ed20 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb @@ -1,4 +1,4 @@ -<%= render_sort_bar(false, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'], +<%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'], ['category', 'bulletin_category', 'span2', 'bulletin.category'], ['name', 'name','span3', 'bulletin.title'], ['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %> \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb index ad8f5ade..457a05a8 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb @@ -1,4 +1,9 @@ + + <% if (web_link.create_user_id == current_user.id) || is_manager? %> + <%= check_box_tag 'to_delete[]', web_link.id, false, :class => "checkbox_in_list" %> + <% end -%> +
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb index aa867034..da1e287b 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb @@ -1,17 +1,20 @@ -<%= render 'filter' %> - - - - - - - - - - - <%= render :partial => 'web_link', :collection => @web_links %> - -
+<%= form_for :news_bulletins, :url => delete_panel_web_resource_back_end_web_links_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> + <%= render 'filter' %> + + + + + + + + + + + + <%= render :partial => 'web_link', :collection => @web_links %> + +
+<% end %>