* feat: Add a pack file that pulls in the MultiSelect Component * feat: move the tags to its own component * save tags * refactor: create a getCSRFToken function in the packs files so that it can be used in the admin * feat: import the new module in request.js * feat: remove unnecessary id * feat: first pass of csrf token test * chore: update the test * fix: csrf token * feat: hide the enw functionality behinda feature flag * fix: loading form twice * refactor: import for csrftoken * chore: update the description of the function * feat: use acts_on_taggable to craete a relationship between display_ad and tag * feat: add a tag field to the display_ad form * feat: add the selected tags from the multiselect autocomplete component to the input text field that references the tag_list * feat: add the tag_list to the controller so that we can save it to the db with the display ad parameters * feat: pull out the tag validation from the article and the display_ads into a concern * feat: write soem tests for validating the tag on the display_ads model * feat: add the tag_list as a hidden field * feat: set the selected tags on edit
73 lines
1.8 KiB
Ruby
73 lines
1.8 KiB
Ruby
module Admin
|
|
class DisplayAdsController < Admin::ApplicationController
|
|
layout "admin"
|
|
|
|
after_action :bust_ad_caches, only: %i[create update destroy]
|
|
|
|
def index
|
|
@display_ads = DisplayAd.order(id: :desc)
|
|
.page(params[:page]).per(50)
|
|
|
|
return if params[:search].blank?
|
|
|
|
@display_ads = @display_ads.search_ads(params[:search])
|
|
end
|
|
|
|
def new
|
|
@display_ad = DisplayAd.new
|
|
end
|
|
|
|
def edit
|
|
@display_ad = DisplayAd.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@display_ad = DisplayAd.new(display_ad_params)
|
|
|
|
if @display_ad.save
|
|
flash[:success] = I18n.t("admin.display_ads_controller.created")
|
|
redirect_to edit_admin_display_ad_path(@display_ad.id)
|
|
else
|
|
flash[:danger] = @display_ad.errors_as_sentence
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
@display_ad = DisplayAd.find(params[:id])
|
|
|
|
if @display_ad.update(display_ad_params)
|
|
flash[:success] = I18n.t("admin.display_ads_controller.updated")
|
|
redirect_to edit_admin_display_ad_path(params[:id])
|
|
else
|
|
flash[:danger] = @display_ad.errors_as_sentence
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@display_ad = DisplayAd.find(params[:id])
|
|
|
|
if @display_ad.destroy
|
|
render json: { message: I18n.t("admin.display_ads_controller.deleted") }, status: :ok
|
|
else
|
|
render json: { error: I18n.t("admin.display_ads_controller.wrong") }, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def display_ad_params
|
|
params.permit(:organization_id, :body_markdown, :placement_area, :published, :approved, :name, :display_to,
|
|
:tag_list)
|
|
end
|
|
|
|
def authorize_admin
|
|
authorize DisplayAd, :access?, policy_class: InternalPolicy
|
|
end
|
|
|
|
def bust_ad_caches
|
|
EdgeCache::BustSidebar.call
|
|
end
|
|
end
|
|
end
|