1
0
Fork 0

Add evidence creation and association

This commit is contained in:
Andrew Tomaka 2015-10-14 11:24:15 -04:00
parent ffd01cee11
commit 0a628a6a6e
23 changed files with 186 additions and 2 deletions

1
.gitignore vendored
View file

@ -19,3 +19,4 @@
# mine
.env
erd.pdf
public/system

View file

@ -17,6 +17,7 @@ gem 'omniauth-reddit', :git => 'git://github.com/jackdempsey/omniauth-reddit.git
gem 'active_model_serializers'
gem 'paper_trail'
gem 'paperclip', '~> 4.3'
# AUTHORIZATION
gem 'pundit'

View file

@ -64,6 +64,10 @@ GEM
uniform_notifier (~> 1.9.0)
byebug (6.0.2)
choice (0.2.0)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.7)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
@ -99,6 +103,7 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.6.2)
mimemagic (0.3.0)
mini_portile (0.6.2)
minitest (5.8.1)
multi_json (1.11.2)
@ -122,6 +127,12 @@ GEM
activerecord (>= 3.0, < 6.0)
activesupport (>= 3.0, < 6.0)
request_store (~> 1.1)
paperclip (4.3.1)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
pg (0.18.3)
puma (2.14.0)
pundit (1.0.1)
@ -231,6 +242,7 @@ DEPENDENCIES
jquery-rails
omniauth-reddit!
paper_trail
paperclip (~> 4.3)
pg
puma
pundit

View file

@ -1,3 +1,16 @@
# 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/
$ ->
$('a.img-preview').hover ((e) ->
$('body').append '<p id="preview"><img src="' + @href + '" />'
$('#preview')
.css('top', e.pageY - 200 + 'px')
.css('left', e.pageX + 30 + 'px')
.fadeIn 'fast'
), ->
$('#preview').remove()
$('a.img-preview').mousemove (e) ->
$('#preview')
.css('top', e.pageY - 200 + 'px')
.css 'left', e.pageX + 30 + 'px'

View file

@ -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/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the Admin::Evidences controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -70,3 +70,13 @@
.panel-yellow a:hover {
color: #df8a13;
}
.img-full {
position: absolute;
left: -9999px;
}
#preview {
position: absolute;
display: none;
}

View file

@ -63,7 +63,8 @@ class Admin::CardsController < Admin::BaseController
params.require(:card).permit(:title, :character_id, :rarity_id, :type_id,
:leader_skill_id, :passive_skill_id, :verified,
:super_attack_id, :dokkan_id, :gameid,
:awaken_type_id, :dokkan_id, link_ids: [])
:awaken_type_id, :dokkan_id,
evidence_ids: [], link_ids: [])
end
def set_card

View file

@ -0,0 +1,33 @@
class Admin::EvidencesController < Admin::BaseController
def index
@evidences = Evidence.all
end
def new
@evidence = Evidence.new
end
def create
@evidence = Evidence.new(evidence_params)
if @evidence.save
redirect_to admin_evidences_path, notice: 'Evidence was created'
else
render :new
end
end
def destroy
@evidence = Evidence.find(params[:id])
@evidence.destroy
redirect_to admin_evidences_path, notice: 'Evidence was deleted'
end
private
def evidence_params
params.require(:evidence).permit(:screenshot)
end
end

View file

@ -0,0 +1,2 @@
module Admin::EvidencesHelper
end

View file

@ -1,2 +1,6 @@
module CardsHelper
def evidence_checkbox_label(evidence)
link_to image_tag(evidence.screenshot.url(:thumb)),
evidence.screenshot.url(:medium), class: 'img-preview'
end
end

View file

@ -12,6 +12,8 @@ class Card < ActiveRecord::Base
has_and_belongs_to_many :links
has_many :evidences
delegate :name, to: :character, prefix: false
validates :title, presence: true

15
app/models/evidence.rb Normal file
View file

@ -0,0 +1,15 @@
class Evidence < ActiveRecord::Base
has_attached_file :screenshot, styles: {
thumb: 'x100',
small: 'x200',
medium: 'x400',
big: 'x600'
}
belongs_to :card
scope :unused, -> { where(card_id: nil) }
scope :for, -> (id) { where(card_id: id) }
validates_attachment_content_type :screenshot, content_type: /\Aimage\/.*\Z/
end

View file

@ -0,0 +1,13 @@
class EvidencePolicy < ApplicationPolicy
def index?
true
end
def create?
user.moderator? || user.admin?
end
def destroy?
user.moderator? || user.admin?
end
end

View file

@ -29,6 +29,8 @@
li= nav_link_to 'Cards', admin_cards_path
- if policy(:character).index?
li= nav_link_to 'Characters', admin_characters_path
- if policy(:evidence).index?
li= nav_link_to 'Evidence', admin_evidences_path
- if policy(:awaken_type).index? || policy(:rarity).index? || policy(:type).index?
li.dropdown
a href='#' class='dropdown-toggle' data-toggle='dropdown'

View file

@ -30,6 +30,16 @@
= f.label :links
div
= f.association :links, as: :check_boxes, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false
.row
.col-md-12
= f.label :evidences
- unless @card.new_record?
div
span Current
= f.association :evidences, as: :check_boxes, collection: Evidence.for(@card), item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false, label_method: lambda { |evidence| evidence_checkbox_label(evidence) }
div
span Unused
= f.association :evidences, as: :check_boxes, collection: Evidence.unused, item_wrapper_tag: nil, item_label_class: 'checkbox-inline', label: false, label_method: lambda { |evidence| evidence_checkbox_label(evidence) }
.row
.col-md-12
= f.label 'Verification'

View file

@ -0,0 +1,5 @@
= simple_form_for [:admin, @evidence] do |f|
.form-inputs
= f.input :screenshot, as: :file
.form-actions
= f.button :button

View file

@ -0,0 +1,26 @@
- if policy(:evidence).new?
.row
.col-md-12
.pull-right
= link_to 'New Evidence', new_admin_evidence_path, class: 'btn btn-primary'
.row
.col-md-12
table.table.table-striped.table-hover
thead
tr
th Screenshot
th Actions
tbody
- @evidences.each do |evidence|
tr
td= image_tag evidence.screenshot.url(:thumb)
td
= link_to glyph('eye-open', classes: 'control-icon'), evidence.screenshot.url(:original, false)
- if policy(:evidence).destroy?
= link_to glyph('trash', classes: 'control-icon'), admin_evidence_path(evidence), method: :delete
- if policy(:evidence).new?
.row
.col-md-12
= link_to 'New Evidence', new_admin_evidence_path, class: 'btn btn-primary'

View file

@ -0,0 +1 @@
== render 'form'

View file

@ -17,6 +17,7 @@ Rails.application.routes.draw do
resources :awaken_types
resources :cards
resources :characters
resources :evidences, except: [:show, :edit, :update]
resources :leader_skills
resources :links
resources :passive_skills

View file

@ -0,0 +1,9 @@
class CreateEvidences < ActiveRecord::Migration
def change
create_table :evidences do |t|
t.attachment :screenshot
t.timestamps null: false
end
end
end

View file

@ -0,0 +1,5 @@
class AddCardToEvidences < ActiveRecord::Migration
def change
add_reference :evidences, :card, index: true
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151014143908) do
ActiveRecord::Schema.define(version: 20151014155435) do
create_table "awaken_types", force: :cascade do |t|
t.string "name"
@ -38,6 +38,18 @@ ActiveRecord::Schema.define(version: 20151014143908) do
t.datetime "updated_at", null: false
end
create_table "evidences", force: :cascade do |t|
t.string "screenshot_file_name"
t.string "screenshot_content_type"
t.integer "screenshot_file_size"
t.datetime "screenshot_updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "card_id"
end
add_index "evidences", ["card_id"], name: "index_evidences_on_card_id"
create_table "leader_skills", force: :cascade do |t|
t.string "description"
t.datetime "created_at", null: false