Add scenes as a content type

This commit is contained in:
Andrew Brown 2016-10-17 00:15:38 +02:00
parent 618c791377
commit 8d3e7ecbad
10 changed files with 167 additions and 9 deletions

View File

@ -0,0 +1,15 @@
class ScenesController < ContentController
private
def content_params
params.require(:scene).permit(content_param_list)
end
def content_param_list
%i(
name summary universe_id
cause description results
notes private_notes
)
end
end

View File

@ -0,0 +1,53 @@
class Scene < ActiveRecord::Base
validates :name, presence: true
belongs_to :user
validates :user_id, presence: true
belongs_to :universe
include HasPrivacy
include HasContentGroupers
include Serendipitous::Concern
# Characters
# relates :notable_figures, with: :something
# relates :dieties, with: :something
# Locations
# relates :practicing_locations, with: :something
# Items
# relates :artifacts, with: :something
scope :is_public, -> { eager_load(:universe).where('creatures.privacy = ? OR universes.privacy = ?', 'public', 'public') }
def self.color
'silver'
end
def self.icon
'local_movies'
end
def self.attribute_categories
{
overview: {
icon: 'info',
attributes: %w(name summary universe_id)
},
# contents: {
# icon: 'face',
# attributes: %w()
# },
prompts: {
icon: 'fingerprint',
attributes: %w(cause description results)
},
notes: {
icon: 'edit',
attributes: %w(notes private_notes)
}
}
end
end

View File

@ -24,6 +24,8 @@ class Universe < ActiveRecord::Base
has_many :magics
has_many :languages
has_many :scenes
scope :is_public, -> { where(privacy: 'public') }
def content

View File

@ -24,6 +24,8 @@ class User < ActiveRecord::Base
has_many :magics
has_many :languages
has_many :scenes
# as_json creates a hash structure, which you then pass to ActiveSupport::json.encode to actually encode the object as a JSON string.
# This is different from to_json, which converts it straight to an escaped JSON string,
# which is undesireable in a case like this, when we want to modify it
@ -77,7 +79,8 @@ class User < ActiveRecord::Base
def recent_content
[
characters, locations, items, universes,
creatures, races, religions, magics, languages
creatures, races, religions, magics, languages,
scenes
].flatten
.sort_by(&:updated_at)
.last(10)

View File

@ -72,6 +72,30 @@
<li class="divider"></li>
<%
[Scene].each do |extended_content_type|
%>
<li>
<%= link_to polymorphic_path(extended_content_type) do %>
<i class="material-icons <%= extended_content_type.color %>-text">
<%= extended_content_type.icon %>
</i>
<%= extended_content_type.name.pluralize %>
<span class="badge">
<%=
if @universe_scope
@universe_scope.send(extended_content_type.name.downcase.pluralize).count
else
current_user.send(extended_content_type.name.downcase.pluralize).count
end
%>
</span>
<% end %>
</li>
<%
end
%>
<li>
<a href="<%= locations_url %>">
<i class="material-icons black-text">wc</i>
@ -79,13 +103,6 @@
<span class="badge">29</span>
</a>
</li>
<li>
<a href="<%= items_url %>">
<i class="material-icons black-text">local_movies</i>
Scenes
<span class="badge">16</span>
</a>
</li>
</ul>

View File

@ -42,6 +42,9 @@ Rails.application.routes.draw do
resources :magics
resources :languages
# Content usage
resources :scenes
# Coming Soon TM
get '/plots', to: 'main#comingsoon'
end

View File

@ -0,0 +1,19 @@
class CreateScenes < ActiveRecord::Migration
def change
create_table :scenes do |t|
t.integer :scene_number
t.string :name
t.string :summary
t.integer :universe_id
t.integer :user_id
t.string :cause
t.string :description
t.string :results
t.string :prose
t.string :notes
t.string :private_notes
t.timestamps null: false
end
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: 20161016213335) do
ActiveRecord::Schema.define(version: 20161016220220) do
create_table "archenemyships", force: :cascade do |t|
t.integer "user_id"
@ -346,6 +346,22 @@ ActiveRecord::Schema.define(version: 20161016213335) do
t.datetime "updated_at", null: false
end
create_table "scenes", force: :cascade do |t|
t.integer "scene_number"
t.string "name"
t.string "summary"
t.integer "universe_id"
t.integer "user_id"
t.string "cause"
t.string "description"
t.string "results"
t.string "prose"
t.string "notes"
t.string "private_notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "sessions", force: :cascade do |t|
t.string "username", null: false
t.string "password", null: false

23
test/fixtures/scenes.yml vendored Normal file
View File

@ -0,0 +1,23 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
scene_number: 1
name: MyString
description: MyString
universe_id: 1
user_id: 1
cause: MyString
description: MyString
results: MyString
prose: MyString
two:
scene_number: 1
name: MyString
description: MyString
universe_id: 1
user_id: 1
cause: MyString
description: MyString
results: MyString
prose: MyString

View File

@ -0,0 +1,7 @@
require 'test_helper'
class SceneTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end