mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
add Vehicle page type
This commit is contained in:
parent
9994b6a246
commit
ed7fd504cb
13
app/controllers/vehicles_controller.rb
Normal file
13
app/controllers/vehicles_controller.rb
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
class VehiclesController < ContentController
|
||||
private
|
||||
|
||||
def content_param_list
|
||||
[
|
||||
:name, :universe_id, :privacy
|
||||
] + [ #<relations>
|
||||
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@ -44,6 +44,7 @@ class Universe < ApplicationRecord
|
||||
has_many :scenes
|
||||
has_many :technologies
|
||||
has_many :towns
|
||||
has_many :vehicles
|
||||
|
||||
has_many :contributors, dependent: :destroy
|
||||
|
||||
|
||||
31
app/models/content_types/vehicle.rb
Normal file
31
app/models/content_types/vehicle.rb
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
class Vehicle < ActiveRecord::Base
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :user
|
||||
validates :name, presence: true
|
||||
validates :user_id, presence: true
|
||||
|
||||
include BelongsToUniverse
|
||||
include HasAttributes
|
||||
include HasPrivacy
|
||||
include HasContentGroupers
|
||||
include HasImageUploads
|
||||
include HasChangelog
|
||||
include Serendipitous::Concern
|
||||
|
||||
include Authority::Abilities
|
||||
self.authorizer_name = 'ExtendedContentAuthorizer'
|
||||
|
||||
def self.color
|
||||
'brown'
|
||||
end
|
||||
|
||||
def self.icon
|
||||
'info'
|
||||
end
|
||||
|
||||
def self.content_name
|
||||
'vehicle'
|
||||
end
|
||||
end
|
||||
26
config/attributes/vehicle.yml
Normal file
26
config/attributes/vehicle.yml
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
:overview:
|
||||
:label: Overview
|
||||
:icon: info
|
||||
:attributes:
|
||||
- :name: name
|
||||
:label: Name
|
||||
- :name: universe_id
|
||||
:label: Universe
|
||||
- :name: privacy
|
||||
:label: Privacy
|
||||
:gallery:
|
||||
:label: Gallery
|
||||
:icon: photo_library
|
||||
:changelog:
|
||||
:label: Changelog
|
||||
:icon: history
|
||||
:notes:
|
||||
:label: Notes
|
||||
:icon: edit
|
||||
:attributes:
|
||||
- :name: notes
|
||||
:label: Notes
|
||||
- :name: private_notes
|
||||
:label: Private Notes
|
||||
:description: Private notes are <em>always</em> visible to only you, even if content is made public and shared.
|
||||
@ -3,7 +3,7 @@ Rails.application.config.content_types = {
|
||||
all: [
|
||||
Universe, Character, Location, Item, Country, Creature, Deity, Flora,
|
||||
Government, Group, Landmark, Language, Magic, Planet, Race, Religion, Scene,
|
||||
Technology, Town
|
||||
Technology, Town, Vehicle
|
||||
],
|
||||
|
||||
# These content types are always on for all users, and cannot be toggled off
|
||||
@ -15,7 +15,7 @@ Rails.application.config.content_types = {
|
||||
# These content types are available to be turned on
|
||||
available: [
|
||||
Country, Creature, Deity, Flora, Government, Group, Landmark, Language,
|
||||
Magic, Planet, Race, Religion, Scene, Technology, Town
|
||||
Magic, Planet, Race, Religion, Scene, Technology, Town, Vehicle
|
||||
],
|
||||
|
||||
# These content types can be created by any user
|
||||
@ -24,7 +24,7 @@ Rails.application.config.content_types = {
|
||||
# These content types require a premium subscription to create
|
||||
premium: [
|
||||
Country, Creature, Deity, Flora, Government, Group, Landmark, Language,
|
||||
Magic, Planet, Race, Religion, Scene, Technology, Town
|
||||
Magic, Planet, Race, Religion, Scene, Technology, Town, Vehicle
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ Rails.application.routes.draw do
|
||||
get :technologies, on: :member
|
||||
get :deities, on: :member
|
||||
get :governments, on: :member
|
||||
get :vehicles, on: :member
|
||||
#<users_page_types>
|
||||
end
|
||||
|
||||
@ -120,6 +121,7 @@ Rails.application.routes.draw do
|
||||
get :technologies, on: :member
|
||||
get :deities, on: :member
|
||||
get :governments, on: :member
|
||||
get :vehicles, on: :member
|
||||
#<universes_page_types>
|
||||
end
|
||||
resources :characters do
|
||||
@ -146,6 +148,7 @@ Rails.application.routes.draw do
|
||||
resources :technologies
|
||||
resources :deities
|
||||
resources :governments
|
||||
resources :vehicles
|
||||
#<page_type_resources>
|
||||
|
||||
# Content attributes
|
||||
|
||||
14
db/migrate/20181101205729_create_vehicles.rb
Normal file
14
db/migrate/20181101205729_create_vehicles.rb
Normal file
@ -0,0 +1,14 @@
|
||||
class CreateVehicles < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :vehicles do |t|
|
||||
t.string :name
|
||||
t.references :user, foreign_key: true
|
||||
t.references :universe, foreign_key: true
|
||||
t.datetime :deleted_at
|
||||
t.string :privacy
|
||||
t.string :page_type, default: 'Vehicle'
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
15
db/schema.rb
15
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_10_30_051214) do
|
||||
ActiveRecord::Schema.define(version: 2018_11_01_205729) do
|
||||
|
||||
create_table "api_keys", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
@ -2314,6 +2314,19 @@ ActiveRecord::Schema.define(version: 2018_10_30_051214) do
|
||||
t.index ["username"], name: "index_users_on_username", unique: true
|
||||
end
|
||||
|
||||
create_table "vehicles", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "user_id"
|
||||
t.integer "universe_id"
|
||||
t.datetime "deleted_at"
|
||||
t.string "privacy"
|
||||
t.string "page_type", default: "Vehicle"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["universe_id"], name: "index_vehicles_on_universe_id"
|
||||
t.index ["user_id"], name: "index_vehicles_on_user_id"
|
||||
end
|
||||
|
||||
create_table "votables", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
|
||||
@ -4,15 +4,14 @@ Checklist to create a new content type:
|
||||
- e.g. https://github.com/indentlabs/notebook/issues/258
|
||||
|
||||
- Generate models (with non-relation fields)
|
||||
- rails g model Planet name:string description:string ...
|
||||
- don't forget to add `privacy`, `notes`, `private_notes`, `user_id`, `universe_id`, `deleted_at`
|
||||
- probably want to just put core attributes here eventually, after de-systemizing other fields
|
||||
- `rails g model Planet name:string user:references universe:references deleted_at:datetime privacy:string`
|
||||
- `rake db:migrate`
|
||||
|
||||
- Run `rake page_type:create` and type "Planet" at the prompt
|
||||
|
||||
- Edit app/models/content_types/planet.rb to define color and icon
|
||||
|
||||
- Add has_many :planets to universe.rb
|
||||
- Add `has_many :planets` to universe.rb
|
||||
|
||||
- Add the content class to initializers/content_types.rb
|
||||
- most likely to :all, :available, and :free/:premium
|
||||
|
||||
15
test/fixtures/vehicles.yml
vendored
Normal file
15
test/fixtures/vehicles.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
user: one
|
||||
universe: one
|
||||
deleted_at: 2018-11-01 15:57:29
|
||||
privacy: MyString
|
||||
|
||||
two:
|
||||
name: MyString
|
||||
user: two
|
||||
universe: two
|
||||
deleted_at: 2018-11-01 15:57:29
|
||||
privacy: MyString
|
||||
7
test/models/vehicle_test.rb
Normal file
7
test/models/vehicle_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class VehicleTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user