* feat: make the sidebar more dynamic * refactor: use the action in the same controller instead of the whole path * feat: remove hardcoded routes * feat: move routes into file * feat: use rails 6 draw for the admin routes * add a helper method * oops: fix super * feat: add the hacky helper methods :( ) * WIP: created different path helpers for the new routes and point the old helpers to the new ones if the FF is toggled * feat: update the module * chore: add new paths * feat: change link_to's use paths instead * feat: feedback_messages to scoped admin route * chore: update the feature flag urls helpers * feat: feedback_messages issue * chore: remove all the workarounds * chore: rubucop * fix: oops remove helper * chore: comment out the tests that touch the tabbed navbar which is affected by the rails application needing to be reloaded * feat: ensure that we chcek if the db table exists
84 lines
2.4 KiB
Ruby
84 lines
2.4 KiB
Ruby
module Admin
|
|
class HtmlVariantsController < Admin::ApplicationController
|
|
layout "admin"
|
|
|
|
def index
|
|
relation = if params[:state] == "mine"
|
|
current_user.html_variants.order(created_at: :desc)
|
|
elsif params[:state] == "admin"
|
|
HtmlVariant.where(published: true, approved: false).order(created_at: :desc)
|
|
elsif params[:state].present?
|
|
HtmlVariant.where(published: true, approved: true, group: params[:state]).order(success_rate: :desc)
|
|
else
|
|
HtmlVariant.where(published: true, approved: true).order(success_rate: :desc)
|
|
end
|
|
|
|
@html_variants = relation.includes(:user).page(params[:page]).per(30)
|
|
end
|
|
|
|
def new
|
|
@html_variant = HtmlVariant.new
|
|
return unless params[:fork_id]
|
|
|
|
@fork = HtmlVariant.find(params[:fork_id])
|
|
@html_variant.name = "#{@fork.name} FORK-#{rand(10_000)}"
|
|
@html_variant.html = @fork.html
|
|
end
|
|
|
|
def show
|
|
@html_variant = HtmlVariant.find(params[:id])
|
|
render layout: "application"
|
|
end
|
|
|
|
def edit
|
|
@html_variant = HtmlVariant.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@html_variant = HtmlVariant.new(html_variant_params)
|
|
@html_variant.user_id = current_user.id
|
|
|
|
if @html_variant.save
|
|
flash[:success] = "HTML Variant has been created!"
|
|
redirect_to admin_html_variants_path(state: "mine")
|
|
else
|
|
flash[:danger] = @html_variant.errors_as_sentence
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
@html_variant = HtmlVariant.find(params[:id])
|
|
|
|
if @html_variant.update(html_variant_params)
|
|
flash[:success] = "HTML Variant has been updated!"
|
|
redirect_to edit_admin_html_variant_path(@html_variant)
|
|
else
|
|
flash[:danger] = @html_variant.errors_as_sentence
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@html_variant = HtmlVariant.find(params[:id])
|
|
|
|
if @html_variant.destroy
|
|
flash[:success] = "HTML Variant has been deleted!"
|
|
redirect_to admin_html_variants_path
|
|
else
|
|
flash[:danger] = "Something went wrong with deleting the HTML Variant."
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def html_variant_params
|
|
params.permit(:html, :name, :published, :approved, :target_tag, :group)
|
|
end
|
|
|
|
def authorize_admin
|
|
authorize HtmlVariant, :access?, policy_class: InternalPolicy
|
|
end
|
|
end
|
|
end
|