From faa1f56aec672244ea064b098c66d71eefbe9cf4 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 20 Oct 2015 19:27:59 -0400 Subject: [PATCH] Finish up stattypes --- .../javascripts/admin/stat_types.coffee | 3 + app/assets/stylesheets/admin/stat_types.scss | 3 + .../admin/stat_types_controller.rb | 63 +++++++++++++++++++ app/helpers/admin/stat_types_helper.rb | 2 + app/models/stat_type.rb | 5 ++ app/policies/stat_type_policy.rb | 17 +++++ app/views/admin/_navbar.html.slim | 2 + app/views/admin/stat_types/_form.html.slim | 6 ++ app/views/admin/stat_types/edit.html.slim | 1 + app/views/admin/stat_types/index.html.slim | 29 +++++++++ app/views/admin/stat_types/new.html.slim | 1 + config/routes.rb | 1 + 12 files changed, 133 insertions(+) create mode 100644 app/assets/javascripts/admin/stat_types.coffee create mode 100644 app/assets/stylesheets/admin/stat_types.scss create mode 100644 app/controllers/admin/stat_types_controller.rb create mode 100644 app/helpers/admin/stat_types_helper.rb create mode 100644 app/policies/stat_type_policy.rb create mode 100644 app/views/admin/stat_types/_form.html.slim create mode 100644 app/views/admin/stat_types/edit.html.slim create mode 100644 app/views/admin/stat_types/index.html.slim create mode 100644 app/views/admin/stat_types/new.html.slim diff --git a/app/assets/javascripts/admin/stat_types.coffee b/app/assets/javascripts/admin/stat_types.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/admin/stat_types.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/admin/stat_types.scss b/app/assets/stylesheets/admin/stat_types.scss new file mode 100644 index 0000000..e0ebe9e --- /dev/null +++ b/app/assets/stylesheets/admin/stat_types.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Admin::StatTypes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admin/stat_types_controller.rb b/app/controllers/admin/stat_types_controller.rb new file mode 100644 index 0000000..81c1db9 --- /dev/null +++ b/app/controllers/admin/stat_types_controller.rb @@ -0,0 +1,63 @@ +class Admin::StatTypesController < Admin::BaseController + before_action :set_stat_type, only: [:show, :edit, :update, :destroy] + after_action :verify_authorized + + def index + @stat_types = StatType.all + authorize StatType + end + + def show + authorize @stat_type + end + + def new + @stat_type = StatType.new + + authorize @stat_type + end + + def create + @stat_type = StatType.new(stat_type_params) + + authorize @stat_type + + if @stat_type.save + redirect_to admin_stat_types_path, notice: 'StatType was created' + else + render :new + end + end + + def edit + authorize @stat_type + end + + def update + authorize @stat_type + + if @stat_type.update(stat_type_params) + redirect_to admin_stat_types_path, notice: 'StatType was updated' + else + render :edit + end + end + + def destroy + authorize @stat_type + + @stat_type.destroy + + redirect_to admin_stat_types_path, notice: 'StatType was deleted' + end + + private + + def stat_type_params + params.require(:stat_type).permit(:name, :description) + end + + def set_stat_type + @stat_type = StatType.find(params[:id]) + end +end diff --git a/app/helpers/admin/stat_types_helper.rb b/app/helpers/admin/stat_types_helper.rb new file mode 100644 index 0000000..bc8e483 --- /dev/null +++ b/app/helpers/admin/stat_types_helper.rb @@ -0,0 +1,2 @@ +module Admin::StatTypesHelper +end diff --git a/app/models/stat_type.rb b/app/models/stat_type.rb index b056354..25915b6 100644 --- a/app/models/stat_type.rb +++ b/app/models/stat_type.rb @@ -1,2 +1,7 @@ class StatType < ActiveRecord::Base + has_paper_trail + + validates :name, presence: true, + uniqueness: { case_sensitive: false } + validates :description, presence: true end diff --git a/app/policies/stat_type_policy.rb b/app/policies/stat_type_policy.rb new file mode 100644 index 0000000..874b067 --- /dev/null +++ b/app/policies/stat_type_policy.rb @@ -0,0 +1,17 @@ +class StatTypePolicy < ApplicationPolicy + def index? + true + end + + def create? + user.admin? + end + + def update? + user.admin? + end + + def destroy? + user.admin? + end +end diff --git a/app/views/admin/_navbar.html.slim b/app/views/admin/_navbar.html.slim index e00af1e..581acf0 100644 --- a/app/views/admin/_navbar.html.slim +++ b/app/views/admin/_navbar.html.slim @@ -41,6 +41,8 @@ li= link_to 'Awaken Types', admin_awaken_types_path - if policy(:rarity).index? li= link_to 'Rarities', admin_rarities_path + - if policy(:stat_type).index? + li= link_to 'Stat Types', admin_stat_types_path - if policy(:type).index? li= link_to 'Types', admin_types_path - if policy(:user).index? diff --git a/app/views/admin/stat_types/_form.html.slim b/app/views/admin/stat_types/_form.html.slim new file mode 100644 index 0000000..5fc5eac --- /dev/null +++ b/app/views/admin/stat_types/_form.html.slim @@ -0,0 +1,6 @@ += simple_form_for [:admin, @stat_type] do |f| + .form-inputs + = f.input :name + = f.input :description + .form-actions + = f.button :button diff --git a/app/views/admin/stat_types/edit.html.slim b/app/views/admin/stat_types/edit.html.slim new file mode 100644 index 0000000..fbedb45 --- /dev/null +++ b/app/views/admin/stat_types/edit.html.slim @@ -0,0 +1 @@ +== render 'form' diff --git a/app/views/admin/stat_types/index.html.slim b/app/views/admin/stat_types/index.html.slim new file mode 100644 index 0000000..830aca2 --- /dev/null +++ b/app/views/admin/stat_types/index.html.slim @@ -0,0 +1,29 @@ +- if policy(:stat_type).new? + .row + .col-md-12 + .pull-right + = link_to 'New Stat Type', new_admin_stat_type_path, class: 'btn btn-primary' + +.row + .col-md-12 + table.table.table-striped.table-hover + thead + tr + th Name + th Description + th Actions + tbody + - @stat_types.each do |stat_type| + tr + td= stat_type.name + td= stat_type.description + td + - if policy(:stat_type).edit? + = link_to glyph('edit', classes: 'control-icon'), edit_admin_stat_type_path(stat_type) + - if policy(:stat_type).destroy? + = link_to glyph('trash', classes: 'control-icon'), admin_stat_type_path(stat_type), method: :delete + +- if policy(:stat_type).new? + .row + .col-md-12 + = link_to 'New Stat Type', new_admin_stat_type_path, class: 'btn btn-primary' diff --git a/app/views/admin/stat_types/new.html.slim b/app/views/admin/stat_types/new.html.slim new file mode 100644 index 0000000..fbedb45 --- /dev/null +++ b/app/views/admin/stat_types/new.html.slim @@ -0,0 +1 @@ +== render 'form' diff --git a/config/routes.rb b/config/routes.rb index 6712801..3d9b626 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,7 @@ Rails.application.routes.draw do resources :links resources :passive_skills resources :rarities + resources :stat_types resources :super_attacks resources :types resources :users, except: [:new, :create]