2014-05-05 11:33:35 +00:00
|
|
|
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
|
2014-05-14 02:58:41 +00:00
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
|
|
|
@table_fields = [:status, :category, :title]
|
2014-05-05 11:33:35 +00:00
|
|
|
|
|
|
|
@links = Kaminari.paginate_array(
|
2014-05-14 02:58:41 +00:00
|
|
|
WebLink.order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status"))
|
2014-05-05 11:33:35 +00:00
|
|
|
).page(params[:page]).per(10)
|
|
|
|
|
2014-05-14 02:58:41 +00:00
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index"
|
2014-05-05 11:33:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@tags =@module_app.tags
|
2014-05-14 02:58:41 +00:00
|
|
|
@categories = @module_app.categories.enabled
|
2014-05-05 11:33:35 +00:00
|
|
|
@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
|
2014-05-14 02:58:41 +00:00
|
|
|
@categories = @module_app.categories.enabled
|
2014-05-05 11:33:35 +00:00
|
|
|
@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
|