From dcc64a20d21cbbf237380538f58dd1dd22e37320 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Fri, 24 Feb 2012 15:30:49 +0800 Subject: [PATCH] Finish sorting for announcements --- Gemfile.lock | 4 --- app/models/user/user.rb | 4 +++ .../back_end/bulletins_controller.rb | 26 ++++++++++++++----- .../announcement/app/models/bulletin.rb | 11 ++++++++ .../back_end/bulletins/_bulletin.html.erb | 4 +-- .../back_end/bulletins/_bulletins.html.erb | 25 ++++++++++-------- 6 files changed, 51 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a34c3634..18f66fbf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,10 +84,6 @@ GEM railties (~> 3.0) thor (~> 0.14) json (1.6.5) - kaminari (0.13.0) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) - railties (>= 3.0.0) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) mail (2.3.0) diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 13d282bb..d74a543b 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -48,5 +48,9 @@ class User value = values.detect {|value| value.attribute_field_id == field_id} rescue nil value ? value : self.attribute_values.build end + + def self.from_id(id) + User.find(id) rescue nil + end end 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 919fc387..7e66179a 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 @@ -18,7 +18,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController @bulletin_categories = BulletinCategory.all module_app = ModuleApp.first(:conditions => {:key => 'announcement'}) - @tags = Tag.all(:conditions => {:module_app_id => module_app.id}) + @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) respond_to do |format| format.html # index.html.erb @@ -156,7 +156,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController bulletins.order_by([params[:sort], params[:direction]]) when 'category' category_ids = bulletins.distinct(:bulletin_category_id) - categories = BulletinCategory.find(category_ids) if category_ids + categories = BulletinCategory.find(category_ids) rescue nil if categories h = Hash.new categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id } @@ -172,10 +172,24 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! sorted.collect {|a| a[1] } when 'status' - # a << bulletins.order_by(:is_top, params[:direction]).order_by - # a << bulletins.where(:is_hot => true).entries - # a << bulletins.where(:is_hidden => true).entries - # a.flatten.uniq + bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]) + when 'update_user_id' + user_ids = bulletins.distinct(:update_user_id) + users = User.find(user_ids) rescue nil + if users + h = Hash.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 } + sorted_users.flatten + else + nil + end + when 'tags' + a = Array.new + AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins } + a.flatten! + a.uniq end end diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index d086d531..7c258f23 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -106,6 +106,17 @@ class Bulletin def text @text ||= I18nVariable.first(:conditions => {:key => 'text', :language_value_id => self.id, :language_value_type => self.class}) rescue nil end + + def self.filter(bulletins) + bulletins.each do |bulletin| + p "#{bulletin.id}/#{bulletin.is_top}/#{bulletin.is_hot}/#{bulletin.is_hidden}" + end + return nil + end + + def sorted_tags + tags.order_by(I18n.locale, :asc) + end protected diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb index dcfa7485..3f6f50e1 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb @@ -32,11 +32,11 @@ <%= bulletin.postdate %> <%= (bulletin.deadline) ? bulletin.deadline : t('bulletin.no_deadline') %> - <% bulletin.tags.each do |tag| %> + <% bulletin.sorted_tags.each do |tag| %> <%= tag[I18n.locale] %> <% end %> - rulingcom + <%= User.from_id(bulletin.update_user_id).name %> <%= render :partial => 'quick_edit', :locals => {:bulletin => bulletin} %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb index e5559f46..9fec31f3 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb @@ -4,30 +4,33 @@ - - <%= link_to (t('bulletin.status') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('status')) %> + + <%= t('bulletin.status') %> + <%= content_tag(:b, nil, :class => is_sort?('status')) %> - + <%= t('bulletin.category') %> <%= content_tag(:b, nil, :class => is_sort?('category')) %> - + <%= t('bulletin.title') %> <%= content_tag(:b, nil, :class => is_sort?('title')) %> - + <%= t('bulletin.start_date') %> <%= content_tag(:b, nil, :class => is_sort?('postdate')) %> - + <%= t('bulletin.end_date') %> <%= content_tag(:b, nil, :class => is_sort?('deadline')) %> - - <%= link_to (t('bulletin.tags') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('tags')) %> - - - <%= link_to (t('bulletin.last_modified') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %> + + <%= t('bulletin.tags') %> + <%= content_tag(:b, nil, :class => is_sort?('tags')) %> + + + <%= t('bulletin.last_modified') %> + <%= content_tag(:b, nil, :class => is_sort?('update_user_id')) %>