2016-09-24 03:00:53 +00:00
|
|
|
# frozen_string_literal: true
|
2017-11-25 19:23:47 +00:00
|
|
|
|
2014-05-17 18:57:03 +00:00
|
|
|
class MetacodesController < ApplicationController
|
2017-11-25 19:23:47 +00:00
|
|
|
before_action :require_admin, except: %i(index show)
|
|
|
|
before_action :set_metacode, only: %i(edit update)
|
2016-07-26 00:14:23 +00:00
|
|
|
|
2014-05-17 18:57:03 +00:00
|
|
|
# GET /metacodes
|
|
|
|
# GET /metacodes.json
|
|
|
|
def index
|
2016-07-26 00:14:23 +00:00
|
|
|
@metacodes = Metacode.order('name').all
|
2014-05-17 18:57:03 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2016-07-26 00:14:23 +00:00
|
|
|
format.html do
|
2016-09-24 03:00:53 +00:00
|
|
|
return unless require_admin
|
2016-02-09 04:43:34 +00:00
|
|
|
render :index
|
2016-07-26 00:14:23 +00:00
|
|
|
end
|
2014-05-17 18:57:03 +00:00
|
|
|
format.json { render json: @metacodes }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-26 02:12:32 +00:00
|
|
|
# GET /metacodes/1.json
|
|
|
|
# GET /metacodes/Action.json
|
|
|
|
# GET /metacodes/action.json
|
|
|
|
def show
|
|
|
|
@metacode = Metacode.where('DOWNCASE(name) = ?', downcase(params[:name])).first if params[:name]
|
2016-09-24 03:00:53 +00:00
|
|
|
set_metacode unless @metacode
|
2016-03-26 02:12:32 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: @metacode }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-17 18:57:03 +00:00
|
|
|
# GET /metacodes/new
|
|
|
|
# GET /metacodes/new.json
|
|
|
|
def new
|
|
|
|
@metacode = Metacode.new
|
|
|
|
|
|
|
|
respond_to do |format|
|
2016-09-24 03:00:53 +00:00
|
|
|
format.html
|
2014-05-17 18:57:03 +00:00
|
|
|
format.json { render json: @metacode }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /metacodes/1/edit
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /metacodes
|
|
|
|
# POST /metacodes.json
|
|
|
|
def create
|
2015-09-19 12:05:36 +00:00
|
|
|
@metacode = Metacode.new(metacode_params)
|
2014-05-17 18:57:03 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @metacode.save
|
|
|
|
format.html { redirect_to metacodes_url, notice: 'Metacode was successfully created.' }
|
|
|
|
format.json { render json: @metacode, status: :created, location: metacodes_url }
|
|
|
|
else
|
2016-02-09 04:43:34 +00:00
|
|
|
format.html { render :new }
|
2014-05-17 18:57:03 +00:00
|
|
|
format.json { render json: @metacode.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /metacodes/1
|
|
|
|
# PUT /metacodes/1.json
|
|
|
|
def update
|
|
|
|
respond_to do |format|
|
2016-02-09 04:43:34 +00:00
|
|
|
if @metacode.update(metacode_params)
|
2014-05-17 18:57:03 +00:00
|
|
|
format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' }
|
|
|
|
format.json { head :no_content }
|
|
|
|
else
|
2016-02-09 04:43:34 +00:00
|
|
|
format.html { render :edit }
|
2014-05-17 18:57:03 +00:00
|
|
|
format.json { render json: @metacode.errors, status: :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-19 08:26:34 +00:00
|
|
|
private
|
|
|
|
|
2016-02-09 04:43:34 +00:00
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
|
|
def metacode_params
|
2016-02-25 06:41:47 +00:00
|
|
|
params.require(:metacode).permit(:id, :name, :aws_icon, :manual_icon, :color)
|
2016-02-09 04:43:34 +00:00
|
|
|
end
|
2016-09-24 03:00:53 +00:00
|
|
|
|
|
|
|
def set_metacode
|
|
|
|
@metacode = Metacode.find(params[:id])
|
|
|
|
end
|
2014-05-17 18:57:03 +00:00
|
|
|
end
|