2015-09-03 08:50:23 -04:00
|
|
|
class Admin::LabelsController < Admin::ApplicationController
|
|
|
|
before_action :set_label, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
|
|
def index
|
2016-03-19 17:37:54 -04:00
|
|
|
@labels = Label.templates.page(params[:page])
|
2015-09-03 08:50:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@label = Label.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-03-29 07:45:15 -04:00
|
|
|
@label = Labels::CreateService.new(label_params).execute(template: true)
|
2015-09-03 08:50:23 -04:00
|
|
|
|
2017-03-29 07:45:15 -04:00
|
|
|
if @label.persisted?
|
2015-09-03 08:50:23 -04:00
|
|
|
redirect_to admin_labels_url, notice: "Label was created"
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-03-29 07:45:15 -04:00
|
|
|
@label = Labels::UpdateService.new(label_params).execute(@label)
|
|
|
|
|
|
|
|
if @label.valid?
|
2015-09-03 08:50:23 -04:00
|
|
|
redirect_to admin_labels_path, notice: 'label was successfully updated.'
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@label.destroy
|
|
|
|
@labels = Label.templates
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
redirect_to(admin_labels_path, notice: 'Label was removed')
|
|
|
|
end
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_label
|
|
|
|
@label = Label.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def label_params
|
2016-02-17 08:52:12 -05:00
|
|
|
params[:label].permit(:title, :description, :color)
|
2015-09-03 08:50:23 -04:00
|
|
|
end
|
|
|
|
end
|