Fix matt's code and add it to filters
This commit is contained in:
parent
dc4116bc3d
commit
815e6a8361
|
@ -32,13 +32,7 @@ class OrbitBackendController< ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_sorted_and_filtered(object_class, query=nil)
|
def get_sorted_and_filtered(object_class, query=nil)
|
||||||
object_class = object_class.classify.constantize
|
objects = get_objects(object_class, query)
|
||||||
if query
|
|
||||||
objects = object_class.all.where(query)
|
|
||||||
else
|
|
||||||
objects = object_class.all
|
|
||||||
end
|
|
||||||
|
|
||||||
if !params[:sort].blank?
|
if !params[:sort].blank?
|
||||||
options = params[:sort_options]
|
options = params[:sort_options]
|
||||||
options = [options] if !options.class.eql?(Array)
|
options = [options] if !options.class.eql?(Array)
|
||||||
|
@ -158,4 +152,26 @@ class OrbitBackendController< ApplicationController
|
||||||
a.flatten
|
a.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def get_viewable(object_class)
|
||||||
|
objects = get_objects(object_class)
|
||||||
|
Kaminari.paginate_array(objects).page(params[:page]).per(10)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_objects(object_class, query=nil)
|
||||||
|
|
||||||
|
object_class = object_class.classify.constantize
|
||||||
|
if query
|
||||||
|
objects = object_class.all.where(query).entries
|
||||||
|
else
|
||||||
|
objects = object_class.all.entries
|
||||||
|
end
|
||||||
|
if(!is_admin? || !is_manager?)
|
||||||
|
objects.delete_if{ |object|
|
||||||
|
(object.is_pending == true) && ((!object.send("#{object.class.to_s.underscore}_category").authed_users('fact_check').include?(current_user) rescue nil) || object.create_user_id!=current_user.id)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
objects
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -34,7 +34,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
|
|
||||||
|
|
||||||
# @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_bulletins : Bulletin.all.page(params[:page]).per(10)
|
# @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_bulletins : Bulletin.all.page(params[:page]).per(10)
|
||||||
@bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin") : Bulletin.all.page(params[:page]).per(10)
|
@bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin") : get_viewable("bulletin")
|
||||||
@bulletin_categories = BulletinCategory.all
|
@bulletin_categories = BulletinCategory.all
|
||||||
|
|
||||||
@bulletin_link = BulletinLink.new
|
@bulletin_link = BulletinLink.new
|
||||||
|
@ -43,12 +43,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
@bulletin_file = BulletinFile.new
|
@bulletin_file = BulletinFile.new
|
||||||
@file_url = panel_announcement_back_end_bulletins_path
|
@file_url = panel_announcement_back_end_bulletins_path
|
||||||
|
|
||||||
if(!is_admin? || !is_manager?)
|
|
||||||
@bulletins.delete_if{ |bulletin|
|
|
||||||
bulletin.is_pending == true && ((!bulletin.bulletin_category.authed_users('fact_check').include?(current_user) rescue nil) || bulletin.create_user_id!=current_user.id)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.js { }
|
format.js { }
|
||||||
|
|
Reference in New Issue