Announcement backend index page filter
This commit is contained in:
parent
804caaa091
commit
4ae1040fc8
|
@ -8,13 +8,9 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
@app_title = "announcement"
|
@app_title = "announcement"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tags = @module_app.tags
|
@tags = @module_app.tags
|
||||||
@categories = @module_app.categories
|
@categories = @module_app.categories
|
||||||
@statuses = []
|
|
||||||
@bulletins = Kaminari.paginate_array(Bulletin.order_by(sort).all).page(params[:page]).per(10)
|
|
||||||
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
|
||||||
|
|
||||||
@filter_fields = {
|
@filter_fields = {
|
||||||
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
|
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
|
||||||
|
@ -23,6 +19,19 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def index_table
|
||||||
|
status = params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
|
||||||
|
categories = params[:filters][:category].blank? ? [] : params[:filters][:category] rescue []
|
||||||
|
tags = params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue []
|
||||||
|
|
||||||
|
@bulletins = Kaminari.paginate_array(
|
||||||
|
Bulletin.order_by(sort).with_categories(categories).with_tags(tags).with_status(status)
|
||||||
|
).page(params[:page]).per(10)
|
||||||
|
|
||||||
|
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
def sort
|
def sort
|
||||||
unless params[:sort].blank?
|
unless params[:sort].blank?
|
||||||
case params[:sort]
|
case params[:sort]
|
||||||
|
@ -47,7 +56,6 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
@sort
|
@sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@tags =@module_app.tags
|
@tags =@module_app.tags
|
||||||
@categories = @module_app.categories
|
@categories = @module_app.categories
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class AnnouncementsController < ApplicationController
|
class AnnouncementsController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
announcements = Bulletin.order_by(:created_at=>'desc').filter_by_categories
|
announcements = Bulletin.can_display.order_by(:created_at=>'desc').filter_by_categories
|
||||||
anns = announcements.collect do |a|
|
anns = announcements.collect do |a|
|
||||||
{
|
{
|
||||||
"title" => a.title,
|
"title" => a.title,
|
||||||
|
@ -17,7 +17,7 @@ class AnnouncementsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def widget
|
def widget
|
||||||
announcements = Bulletin.order_by(:created_at=>'desc').filter_by_categories
|
announcements = Bulletin.can_display.order_by(:created_at=>'desc').filter_by_categories
|
||||||
anns = announcements.collect do |a|
|
anns = announcements.collect do |a|
|
||||||
{
|
{
|
||||||
"title" => a.title,
|
"title" => a.title,
|
||||||
|
@ -27,7 +27,6 @@ class AnnouncementsController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
"extras" => {"link_to_index" => "index","name" => "Harry"},
|
|
||||||
"data" => anns
|
"data" => anns
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -35,7 +34,7 @@ class AnnouncementsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
announcement = Bulletin.find_by(:uid=>params[:uid])
|
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
|
||||||
{
|
{
|
||||||
"title" => announcement.title,
|
"title" => announcement.title,
|
||||||
"image" => (announcement.image.blank? ? "" : announcement.image.url),
|
"image" => (announcement.image.blank? ? "" : announcement.image.url),
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
module Admin::AnnouncementsHelper
|
module Admin::AnnouncementsHelper
|
||||||
|
def page_for_bulletin(bulletin)
|
||||||
|
request.protocol+(request.host_with_port+Page.where(:categories.in=>[bulletin.category.id.to_s]).first.url+'/'+bulletin.to_param).gsub('//','/')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,4 +38,13 @@ class Bulletin
|
||||||
self.update_user_id = user.id
|
self.update_user_id = user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.with_status(status)
|
||||||
|
status = [status].flatten
|
||||||
|
self.any_of(status.map{|s| {s.to_sym=>true}})
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.can_display()
|
||||||
|
self.any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil})
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,34 +1,3 @@
|
||||||
<script type="text/javascript">
|
|
||||||
url = "";
|
|
||||||
filters = [];
|
|
||||||
filter = "";
|
|
||||||
|
|
||||||
$(".accordion-inner a").click(function(){
|
|
||||||
if(window.location.search==""){
|
|
||||||
filters = [];
|
|
||||||
}else{
|
|
||||||
filters = window.location.search.replace('?','').split('&');
|
|
||||||
}
|
|
||||||
|
|
||||||
filter = $(this).attr("href").split('?')[1];
|
|
||||||
|
|
||||||
if( (index = filters.indexOf(filter) ) > -1){
|
|
||||||
filters.splice(index,1);
|
|
||||||
}else{
|
|
||||||
filters.push(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(filters.length==0){
|
|
||||||
url = window.location.origin+window.location.pathname
|
|
||||||
}else{
|
|
||||||
url = window.location.origin+window.location.pathname+'?'+filters.join('&');
|
|
||||||
}
|
|
||||||
|
|
||||||
window.location.assign(url);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<% content_for :right_nav do %>
|
<% content_for :right_nav do %>
|
||||||
<ul class="nav nav-pills filter-nav pull-right">
|
<ul class="nav nav-pills filter-nav pull-right">
|
||||||
<% @filter_fields.keys.each do |field| %>
|
<% @filter_fields.keys.each do |field| %>
|
||||||
|
@ -44,7 +13,7 @@
|
||||||
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
||||||
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
||||||
<% @filter_fields[field].each do |val| %>
|
<% @filter_fields[field].each do |val| %>
|
||||||
<%= link_to t(val[:title]), "?filters[#{field}][]=#{val[:id]}", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
<%= link_to t(val[:title]), "#", :onclick => "addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="filter-clear">
|
<div class="filter-clear">
|
||||||
|
@ -55,41 +24,66 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<table class="table main-list">
|
<span id="index_table">
|
||||||
<thead>
|
</span>
|
||||||
<tr class="sort-header">
|
|
||||||
<% @table_fields.each do |f| %>
|
|
||||||
<%= thead(f) %>
|
|
||||||
<% end %>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% @bulletins.each do |b| %>
|
|
||||||
<tr>
|
|
||||||
<td><%= b.status_for_table %></td>
|
|
||||||
<td><%= b.category.title %></td>
|
|
||||||
<td>
|
|
||||||
<a href="/news/<%=b.id.to_s%>"><%= b.title %></a>
|
|
||||||
<div class="quick-edit">
|
|
||||||
<ul class="nav nav-pills">
|
|
||||||
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
|
||||||
<li><a href="#" class="detail-row"><%= t(:detail) %></a></li>
|
|
||||||
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td><%= format_value b.postdate %></td>
|
|
||||||
<td><%= format_value b.deadline %></td>
|
|
||||||
<td><%= b.update_user.user_name %></td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<%=
|
|
||||||
content_tag :div, class: "bottomnav clearfix" do
|
|
||||||
content_tag :div, paginate(@bulletins), class: "pagination pagination-centered"
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
|
|
||||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
filters=[];
|
||||||
|
table_url="";
|
||||||
|
|
||||||
|
$(function(){
|
||||||
|
init();
|
||||||
|
update_table();
|
||||||
|
});
|
||||||
|
|
||||||
|
var init = function(){
|
||||||
|
filters = window.location.search.replace('?','').split('&');
|
||||||
|
table_url = "";
|
||||||
|
if(window.location.search==""){
|
||||||
|
filters = [];
|
||||||
|
table_url = window.location.pathname+'/index_table';
|
||||||
|
}else{
|
||||||
|
table_url = window.location.pathname+'/index_table';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var update_table = function(url){
|
||||||
|
if(url==null){
|
||||||
|
if(filters.length==0){
|
||||||
|
url = table_url;
|
||||||
|
}else{
|
||||||
|
url = table_url+'?'+filters.join('&');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$.get(url,function(data){
|
||||||
|
history.pushState(null, null, decodeURIComponent(url.replace('/index_table','')) );
|
||||||
|
init();
|
||||||
|
$("#index_table").html(data);
|
||||||
|
|
||||||
|
$(".pagination a").click(function(){
|
||||||
|
update_table($(this).attr('href'));
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var addFilter = function(filter){
|
||||||
|
url = "";
|
||||||
|
$.each(filters,function(idx,data){
|
||||||
|
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
||||||
|
});
|
||||||
|
|
||||||
|
if( (index = filters.indexOf(filter) ) > -1){
|
||||||
|
table_url = table_url.replace(filter,'');
|
||||||
|
filters.splice(index,1);
|
||||||
|
}else{
|
||||||
|
filters.push(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
update_table();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -0,0 +1,36 @@
|
||||||
|
<table class="table main-list">
|
||||||
|
<thead>
|
||||||
|
<tr class="sort-header">
|
||||||
|
<% @table_fields.each do |f| %>
|
||||||
|
<%= thead(f) %>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @bulletins.each do |b| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= b.status_for_table %></td>
|
||||||
|
<td><%= b.category.title %></td>
|
||||||
|
<td>
|
||||||
|
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title %></a>
|
||||||
|
<div class="quick-edit">
|
||||||
|
<ul class="nav nav-pills">
|
||||||
|
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
||||||
|
<li><a href="#" class="detail-row"><%= t(:detail) %></a></li>
|
||||||
|
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><%= format_value b.postdate %></td>
|
||||||
|
<td><%= format_value b.deadline %></td>
|
||||||
|
<td><%= b.update_user.user_name %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%=
|
||||||
|
content_tag :div, class: "bottomnav clearfix" do
|
||||||
|
content_tag :div, paginate(@bulletins), class: "pagination pagination-centered"
|
||||||
|
end
|
||||||
|
%>
|
|
@ -4,12 +4,13 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
|
get 'announcements/index_table' => 'announcements#index_table'
|
||||||
resources :announcements
|
resources :announcements
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :announcements do
|
resources :announcements do
|
||||||
collection do
|
collection do
|
||||||
get ':uid/:title', to: 'announcements#show', as: :display
|
get ':slug_title-:uid', to: 'announcements#show', as: :display
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue