Fix filter and sort for status in announcement
This commit is contained in:
parent
834cbe3a11
commit
b502bedd0f
|
@ -243,12 +243,14 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
# end
|
# end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @bulletin.update_attributes(params[:bulletin]) && @bulletin.save
|
if @bulletin.update_attributes(params[:bulletin])
|
||||||
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
|
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
|
||||||
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
||||||
format.js { render 'toggle_enable' }
|
format.js { render 'toggle_enable' }
|
||||||
format.xml { head :ok }
|
format.xml { head :ok }
|
||||||
else
|
else
|
||||||
|
get_tags
|
||||||
|
get_categorys
|
||||||
format.html { render :action => "edit" }
|
format.html { render :action => "edit" }
|
||||||
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
|
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
|
||||||
end
|
end
|
||||||
|
@ -335,7 +337,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
|
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
|
||||||
bulletins = sorted.collect {|a| a[1] }
|
bulletins = sorted.collect {|a| a[1] }
|
||||||
when 'status'
|
when 'status'
|
||||||
bulletins = bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction])
|
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'
|
when 'update_user_id'
|
||||||
user_ids = bulletins.distinct(:update_user_id)
|
user_ids = bulletins.distinct(:update_user_id)
|
||||||
users = User.find(user_ids) rescue nil
|
users = User.find(user_ids) rescue nil
|
||||||
|
@ -357,7 +359,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
sorted_titles = sorted.collect {|a| a[1] }
|
sorted_titles = sorted.collect {|a| a[1] }
|
||||||
a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles)
|
a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles)
|
||||||
bulletins = a.flatten
|
bulletins = a.flatten
|
||||||
end
|
end
|
||||||
if @filter
|
if @filter
|
||||||
@filter.each do |key, value|
|
@filter.each do |key, value|
|
||||||
case key
|
case key
|
||||||
|
@ -365,16 +367,23 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
a = Array.new
|
a = Array.new
|
||||||
bulletins.each do |bulletin|
|
bulletins.each do |bulletin|
|
||||||
value.each do |v|
|
value.each do |v|
|
||||||
a << bulletin if bulletin[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
|
||||||
end
|
end
|
||||||
bulletins = a
|
bulletins = a.uniq
|
||||||
when 'categories'
|
when 'categories'
|
||||||
a = Array.new
|
a = Array.new
|
||||||
bulletins.each do |bulletin|
|
bulletins.each do |bulletin|
|
||||||
a << bulletin if value.include?(bulletin.bulletin_category.id.to_s)
|
a << bulletin if value.include?(bulletin.bulletin_category.id.to_s)
|
||||||
end
|
end
|
||||||
bulletins = a
|
bulletins = a.uniq
|
||||||
when 'tags'
|
when 'tags'
|
||||||
a = Array.new
|
a = Array.new
|
||||||
bulletins.each do |bulletin|
|
bulletins.each do |bulletin|
|
||||||
|
@ -382,7 +391,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
a << bulletin if value.include?(tag.id.to_s)
|
a << bulletin if value.include?(tag.id.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
bulletins = a
|
bulletins = a.uniq
|
||||||
end if value.size > 0
|
end if value.size > 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,10 @@ class Bulletin
|
||||||
field :is_top, :type => Boolean, :default => false
|
field :is_top, :type => Boolean, :default => false
|
||||||
field :is_hot, :type => Boolean, :default => false
|
field :is_hot, :type => Boolean, :default => false
|
||||||
field :is_hidden, :type => Boolean, :default => false
|
field :is_hidden, :type => Boolean, :default => false
|
||||||
field :is_checked, :type => Boolean, :default => nil
|
field :is_checked, :type => Boolean, :default => false
|
||||||
|
field :is_pending, :type => Boolean, :default => true
|
||||||
|
field :is_rejected, :type => Boolean, :default => false
|
||||||
|
|
||||||
|
|
||||||
field :not_checked_reason
|
field :not_checked_reason
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ class Bulletin
|
||||||
|
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
|
|
||||||
before_save :set_key
|
before_save :set_key, :update_status
|
||||||
|
|
||||||
after_save :save_bulletin_links
|
after_save :save_bulletin_links
|
||||||
after_save :save_bulletin_files
|
after_save :save_bulletin_files
|
||||||
|
@ -79,17 +82,6 @@ class Bulletin
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
|
||||||
case self.is_checked
|
|
||||||
when nil
|
|
||||||
I18n.t('announcement.bulletin.fact_check_pending')
|
|
||||||
when true
|
|
||||||
I18n.t('announcement.bulletin.fact_check_pass')
|
|
||||||
when false
|
|
||||||
I18n.t('announcement.bulletin.fact_check_not_pass')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_expired?
|
def is_expired?
|
||||||
Date.today > self.deadline ? true : false rescue false
|
Date.today > self.deadline ? true : false rescue false
|
||||||
#some dates might sat as nil so rescue false
|
#some dates might sat as nil so rescue false
|
||||||
|
@ -110,9 +102,13 @@ class Bulletin
|
||||||
def is_checked?
|
def is_checked?
|
||||||
self.is_checked
|
self.is_checked
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_check_rejected?
|
def is_pending?
|
||||||
self.is_checked == false
|
self.is_pending
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_rejected?
|
||||||
|
self.is_rejected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,6 +165,18 @@ class Bulletin
|
||||||
text.key = 'text'
|
text.key = 'text'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_status
|
||||||
|
if !self.is_pending && !self.is_checked
|
||||||
|
self.is_pending = false
|
||||||
|
self.is_rejected = true
|
||||||
|
self.is_checked = false
|
||||||
|
elsif self.is_checked
|
||||||
|
self.is_pending = false
|
||||||
|
self.is_rejected = false
|
||||||
|
self.is_checked = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
|
@ -10,14 +10,22 @@
|
||||||
<% if bulletin.is_hidden? %>
|
<% if bulletin.is_hidden? %>
|
||||||
<span class="label"><%= t(:hidden) %></span>
|
<span class="label"><%= t(:hidden) %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= bulletin.status %>
|
<% if bulletin.is_pending? %>
|
||||||
|
<span class="label"><%= t(:pending) %></span>
|
||||||
|
<% end %>
|
||||||
|
<% if bulletin.is_checked? %>
|
||||||
|
<span class="label"><%= t(:checked) %></span>
|
||||||
|
<% end %>
|
||||||
|
<% if bulletin.is_rejected? %>
|
||||||
|
<span class="label"><%= t(:rejected) %></span>
|
||||||
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= bulletin.bulletin_category.i18n_variable[I18n.locale] %></td>
|
<td><%= bulletin.bulletin_category.i18n_variable[I18n.locale] %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%>
|
<%= link_to bulletin.title[I18n.locale], panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.bulletin_category.id) rescue ''%>
|
||||||
<div class="quick-edit">
|
<div class="quick-edit">
|
||||||
<ul class="nav nav-pills hide">
|
<ul class="nav nav-pills hide">
|
||||||
<% unless bulletin.is_check_rejected?%>
|
<% unless bulletin.is_rejected?%>
|
||||||
<li><%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(bulletin) %></li>
|
<li><%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(bulletin) %></li>
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t(:quick_edit) %><b class="caret"></b></a>
|
<a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t(:quick_edit) %><b class="caret"></b></a>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<div class="accordion-inner" data-toggle="buttons-checkbox">
|
<div class="accordion-inner" data-toggle="buttons-checkbox">
|
||||||
<%= link_to t(:is_top), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_top'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_top')}" %>
|
<%= link_to t(:top), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_top'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_top')}" %>
|
||||||
<%= link_to t(:is_hot), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_hot'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_hot')}" %>
|
<%= link_to t(:hot), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_hot'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_hot')}" %>
|
||||||
<%= link_to t(:is_hidden), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_hidden'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_hidden')}" %>
|
<%= link_to t(:hidden), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_hidden'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_hidden')}" %>
|
||||||
<%= link_to t(:is_checked), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_checked'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_checked')}" %>
|
<%= link_to t(:pending), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'pending'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'pending')}" %>
|
||||||
|
<%= link_to t(:passed), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'is_checked'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'is_checked')}" %>
|
||||||
|
<%= link_to t(:rejected), panel_announcement_back_end_bulletins_path(:filter => @filter, :new_filter => {:type => 'status', :id => 'rejected'}, :sort => params[:sort], :direction => params[:direction]), :class => "btn js_history#{is_filter_active?('status', 'rejected')}" %>
|
||||||
</div>
|
</div>
|
||||||
<%= render :partial => 'clear_filters', :locals => {:type => 'status'} %>
|
<%= render :partial => 'clear_filters', :locals => {:type => 'status'} %>
|
|
@ -106,7 +106,7 @@
|
||||||
<%= t('announcement.bulletin.fact_check_pass') %>
|
<%= t('announcement.bulletin.fact_check_pass') %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<%= content_tag :label,:class => "radio inline" do -%>
|
<%= content_tag :label,:class => "radio inline" do -%>
|
||||||
<%= f.radio_button :is_checked, false, (@bulletin.is_checked.nil?? {:checked => true, :class => 'privacy'} : {})%>
|
<%= f.radio_button :is_checked, false, (!@bulletin.is_checked ? {:checked => true, :class => 'privacy'} : {})%>
|
||||||
<%= t('announcement.bulletin.fact_check_not_pass') %>
|
<%= t('announcement.bulletin.fact_check_not_pass') %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<div class="select-role">
|
<div class="select-role">
|
||||||
|
|
Loading…
Reference in New Issue