95 lines
2.5 KiB
Ruby
95 lines
2.5 KiB
Ruby
|
class Admin::WebResourcesController < OrbitAdminController
|
||
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
||
|
before_action :set_link, only: [:edit, :update, :destroy]
|
||
|
|
||
|
def index
|
||
|
@tags = @module_app.tags
|
||
|
@categories = @module_app.categories
|
||
|
|
||
|
@filter_fields = {
|
||
|
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
|
||
|
:category=>@categories.map{|c| {:title=>c.title, :id=>c.id}},
|
||
|
:tags=>@tags.map{|tag| {:title=>tag.name, :id=>tag.id}}
|
||
|
}
|
||
|
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 []
|
||
|
|
||
|
@links = Kaminari.paginate_array(
|
||
|
WebLink.order_by(sort).with_categories(categories).with_tags(tags).with_status(status)
|
||
|
).page(params[:page]).per(10)
|
||
|
|
||
|
@table_fields = [:status, :category, :title]
|
||
|
render :layout => false
|
||
|
end
|
||
|
|
||
|
def sort
|
||
|
unless params[:sort].blank?
|
||
|
case params[:sort]
|
||
|
when "status"
|
||
|
@sort = [[:is_top, params[:order]],
|
||
|
[:is_hot, params[:order]],
|
||
|
[:is_hidden,params[:order]]]
|
||
|
when "category"
|
||
|
@sort = {:category_id=>params[:order]}
|
||
|
when "title"
|
||
|
@sort = {:title=>params[:order]}
|
||
|
when "start_date"
|
||
|
@sort = {:postdate=>params[:order]}
|
||
|
when "end_date"
|
||
|
@sort = {:deadline=>params[:order]}
|
||
|
when "last_modified"
|
||
|
@sort = {:update_user_id=>params[:order]}
|
||
|
end
|
||
|
else
|
||
|
@sort = {:created_at=>'desc'}
|
||
|
end
|
||
|
@sort
|
||
|
end
|
||
|
|
||
|
def new
|
||
|
@tags =@module_app.tags
|
||
|
@categories = @module_app.categories
|
||
|
@statuses = []
|
||
|
@link = WebLink.new
|
||
|
end
|
||
|
|
||
|
def create
|
||
|
link = WebLink.new(link_params)
|
||
|
link.create_user_id = current_user.id
|
||
|
link.update_user_id = current_user.id
|
||
|
link.save
|
||
|
redirect_to admin_web_resources_path
|
||
|
end
|
||
|
|
||
|
def edit
|
||
|
@tags =@module_app.tags
|
||
|
@categories = @module_app.categories
|
||
|
@statuses = []
|
||
|
end
|
||
|
|
||
|
def update
|
||
|
@link.update_attributes(link_params)
|
||
|
@link.save
|
||
|
redirect_to admin_web_resources_path
|
||
|
end
|
||
|
|
||
|
def destroy
|
||
|
@link.destroy
|
||
|
redirect_to admin_web_resources_path
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def set_link
|
||
|
@link = WebLink.find(params[:id])
|
||
|
end
|
||
|
|
||
|
def link_params
|
||
|
params.require(:web_link).permit!
|
||
|
end
|
||
|
end
|