1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# frozen_string_literal: true
class Admin::LabelsController < Admin::ApplicationController
before_action :set_label, only: [:show, :edit, :update, :destroy]
feature_category :team_planning
urgency :low
def index
@labels = Label.templates.page(pagination_params[:page])
end
def show; end
def new
@label = Label.new
end
def edit; end
def create
@label = Labels::CreateService.new(label_params).execute(template: true)
if @label.persisted?
redirect_to admin_labels_url, notice: _("Label was created")
else
render :new
end
end
def update
@label = Labels::UpdateService.new(label_params).execute(@label)
if @label.valid?
redirect_to admin_labels_path, notice: _('Label was successfully updated.')
else
render :edit
end
end
def destroy
respond_to do |format|
if @label.destroy
format.html do
redirect_to admin_labels_path, status: :found,
notice: format(_('%{label_name} was removed'), label_name: @label.name)
end
format.js { head :ok }
else
format.html do
redirect_to admin_labels_path, status: :found,
alert: @label.errors.full_messages.to_sentence
end
format.js { head :unprocessable_entity }
end
end
end
private
def set_label
@label = Label.find(params.permit(:id)[:id])
end
def label_params
params[:label].permit(:title, :description, :color) # rubocop:disable Rails/StrongParams -- hash access is safely followed by permit
end
end
|