links/app/controllers/admin/web_resources_controller.rb

67 lines
1.6 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.enabled
@filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title]
@links = WebLink.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
.with_status(filters("status"))
@links = search_data(@links,[:title]).page(params[:page]).per(10)
render :partial => "index" if request.xhr?
end
def new
@tags =@module_app.tags
@categories = @module_app.categories.enabled
@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
if can_edit_or_delete?(@link)
@tags =@module_app.tags
@categories = @module_app.categories.enabled
@statuses = []
else
render_401
end
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