Finish sorting for announcements
This commit is contained in:
parent
8f531a6fe5
commit
dcc64a20d2
|
@ -84,10 +84,6 @@ GEM
|
||||||
railties (~> 3.0)
|
railties (~> 3.0)
|
||||||
thor (~> 0.14)
|
thor (~> 0.14)
|
||||||
json (1.6.5)
|
json (1.6.5)
|
||||||
kaminari (0.13.0)
|
|
||||||
actionpack (>= 3.0.0)
|
|
||||||
activesupport (>= 3.0.0)
|
|
||||||
railties (>= 3.0.0)
|
|
||||||
linecache19 (0.5.12)
|
linecache19 (0.5.12)
|
||||||
ruby_core_source (>= 0.1.4)
|
ruby_core_source (>= 0.1.4)
|
||||||
mail (2.3.0)
|
mail (2.3.0)
|
||||||
|
|
|
@ -49,4 +49,8 @@ class User
|
||||||
value ? value : self.attribute_values.build
|
value ? value : self.attribute_values.build
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.from_id(id)
|
||||||
|
User.find(id) rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
||||||
@bulletin_categories = BulletinCategory.all
|
@bulletin_categories = BulletinCategory.all
|
||||||
|
|
||||||
module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
|
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|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
|
@ -156,7 +156,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
||||||
bulletins.order_by([params[:sort], params[:direction]])
|
bulletins.order_by([params[:sort], params[:direction]])
|
||||||
when 'category'
|
when 'category'
|
||||||
category_ids = bulletins.distinct(:bulletin_category_id)
|
category_ids = bulletins.distinct(:bulletin_category_id)
|
||||||
categories = BulletinCategory.find(category_ids) if category_ids
|
categories = BulletinCategory.find(category_ids) rescue nil
|
||||||
if categories
|
if categories
|
||||||
h = Hash.new
|
h = Hash.new
|
||||||
categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
|
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 = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
|
||||||
sorted.collect {|a| a[1] }
|
sorted.collect {|a| a[1] }
|
||||||
when 'status'
|
when 'status'
|
||||||
# a << bulletins.order_by(:is_top, params[:direction]).order_by
|
bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction])
|
||||||
# a << bulletins.where(:is_hot => true).entries
|
when 'update_user_id'
|
||||||
# a << bulletins.where(:is_hidden => true).entries
|
user_ids = bulletins.distinct(:update_user_id)
|
||||||
# a.flatten.uniq
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,17 @@ class Bulletin
|
||||||
@text ||= I18nVariable.first(:conditions => {:key => 'text', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
|
@text ||= I18nVariable.first(:conditions => {:key => 'text', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def set_key
|
def set_key
|
||||||
|
|
|
@ -32,11 +32,11 @@
|
||||||
<td><%= bulletin.postdate %></td>
|
<td><%= bulletin.postdate %></td>
|
||||||
<td><%= (bulletin.deadline) ? bulletin.deadline : t('bulletin.no_deadline') %></td>
|
<td><%= (bulletin.deadline) ? bulletin.deadline : t('bulletin.no_deadline') %></td>
|
||||||
<td>
|
<td>
|
||||||
<% bulletin.tags.each do |tag| %>
|
<% bulletin.sorted_tags.each do |tag| %>
|
||||||
<span class="label label-tags"><%= tag[I18n.locale] %></span>
|
<span class="label label-tags"><%= tag[I18n.locale] %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td>rulingcom</td>
|
<td><%= User.from_id(bulletin.update_user_id).name %></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<%= render :partial => 'quick_edit', :locals => {:bulletin => bulletin} %>
|
<%= render :partial => 'quick_edit', :locals => {:bulletin => bulletin} %>
|
||||||
|
|
|
@ -4,30 +4,33 @@
|
||||||
<input type="checkbox">
|
<input type="checkbox">
|
||||||
<a href class="list-remove"><i class="icon-trash"></i></a>
|
<a href class="list-remove"><i class="icon-trash"></i></a>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-status" class="sort span1 <%= is_sort_active?('status') %>">
|
<th class="sort span1 <%= is_sort_active?('status') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('status')) %>">
|
||||||
<%= 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')) %>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-category" class="sort span1-2 <%= is_sort_active?('category') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('category')) %>">
|
<th class="sort span1-2 <%= is_sort_active?('category') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('category')) %>">
|
||||||
<%= t('bulletin.category') %>
|
<%= t('bulletin.category') %>
|
||||||
<%= content_tag(:b, nil, :class => is_sort?('category')) %>
|
<%= content_tag(:b, nil, :class => is_sort?('category')) %>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-title" class="sort span7 <%= is_sort_active?('title') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('title')) %>">
|
<th class="sort span7 <%= is_sort_active?('title') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('title')) %>">
|
||||||
<%= t('bulletin.title') %>
|
<%= t('bulletin.title') %>
|
||||||
<%= content_tag(:b, nil, :class => is_sort?('title')) %>
|
<%= content_tag(:b, nil, :class => is_sort?('title')) %>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-postdate" class="sort span1-2 <%= is_sort_active?('postdate') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('postdate')) %>">
|
<th class="sort span1-2 <%= is_sort_active?('postdate') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('postdate')) %>">
|
||||||
<%= t('bulletin.start_date') %>
|
<%= t('bulletin.start_date') %>
|
||||||
<%= content_tag(:b, nil, :class => is_sort?('postdate')) %>
|
<%= content_tag(:b, nil, :class => is_sort?('postdate')) %>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-deadline" class="sort span1-2 <%= is_sort_active?('deadline') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('deadline')) %>">
|
<th class="sort span1-2 <%= is_sort_active?('deadline') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('deadline')) %>">
|
||||||
<%= t('bulletin.end_date') %>
|
<%= t('bulletin.end_date') %>
|
||||||
<%= content_tag(:b, nil, :class => is_sort?('deadline')) %>
|
<%= content_tag(:b, nil, :class => is_sort?('deadline')) %>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-tags" class="sort span1-2">
|
<th class="sort span1-2 <%= is_sort_active?('tags') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('tags')) %>">
|
||||||
<%= link_to (t('bulletin.tags') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('tags')) %>
|
<%= t('bulletin.tags') %>
|
||||||
|
<%= content_tag(:b, nil, :class => is_sort?('tags')) %>
|
||||||
</th>
|
</th>
|
||||||
<th id="sort-update_user_id" class="sort span1-2">
|
<th class="sort span1-2 <%= is_sort_active?('update_user_id') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %>">
|
||||||
<%= link_to (t('bulletin.last_modified') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %>
|
<%= t('bulletin.last_modified') %>
|
||||||
|
<%= content_tag(:b, nil, :class => is_sort?('update_user_id')) %>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
Reference in New Issue