about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-03-12 21:50:00 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-03-12 21:50:00 -0400
commit7789e2138fc0479846c20bc68d68973636a4a760 (patch)
treeef14af7a0a6e0de8f086a2b2db877840eb48904c
parent7a2d945f581c8ce9e322883ec597366143fe10cb (diff)
downloadthoughts-7789e2138fc0479846c20bc68d68973636a4a760.tar.gz
thoughts-7789e2138fc0479846c20bc68d68973636a4a760.tar.bz2
thoughts-7789e2138fc0479846c20bc68d68973636a4a760.zip
Started game tracker
-rw-r--r--.gitignore2
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock4
-rw-r--r--app/assets/stylesheets/main/games.scss25
-rw-r--r--app/controllers/admin/games_controller.rb56
-rw-r--r--app/controllers/games_controller.rb5
-rw-r--r--app/helpers/admin/games_helper.rb2
-rw-r--r--app/helpers/games_helper.rb2
-rw-r--r--app/models/game.rb13
-rw-r--r--app/views/admin/games/_form.html.haml23
-rw-r--r--app/views/admin/games/edit.html.haml3
-rw-r--r--app/views/admin/games/index.html.haml13
-rw-r--r--app/views/admin/games/new.html.haml3
-rw-r--r--app/views/games/index.html.haml14
-rw-r--r--app/views/layouts/admin.html.haml4
-rw-r--r--config/routes.rb4
-rw-r--r--db/migrate/20190312193025_install_audited.rb30
-rw-r--r--db/migrate/20190312193154_create_games.rb13
-rw-r--r--db/schema.rb34
19 files changed, 251 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index 702ff9b..ae472fd 100644 --- a/.gitignore +++ b/.gitignore
@@ -29,3 +29,5 @@ tags
29*.swo 29*.swo
30/public/uploads 30/public/uploads
31config/database.yml 31config/database.yml
32
33misc
diff --git a/Gemfile b/Gemfile index 0bf9828..d57baba 100644 --- a/Gemfile +++ b/Gemfile
@@ -72,3 +72,5 @@ gem 'pokeviewer', github: "hatkirby/pokeviewer"
72gem 'acts-as-taggable-on' 72gem 'acts-as-taggable-on'
73gem 'jquery-ui-rails' 73gem 'jquery-ui-rails'
74gem 'js-routes' 74gem 'js-routes'
75gem 'audited', '~> 4.7'
76gem 'enumerize'
diff --git a/Gemfile.lock b/Gemfile.lock index 8fccc7c..62cb538 100644 --- a/Gemfile.lock +++ b/Gemfile.lock
@@ -66,6 +66,8 @@ GEM
66 airbrussh (1.3.1) 66 airbrussh (1.3.1)
67 sshkit (>= 1.6.1, != 1.7.0) 67 sshkit (>= 1.6.1, != 1.7.0)
68 arel (9.0.0) 68 arel (9.0.0)
69 audited (4.8.0)
70 activerecord (>= 4.0, < 5.3)
69 bcrypt (3.1.12) 71 bcrypt (3.1.12)
70 bindex (0.5.0) 72 bindex (0.5.0)
71 builder (3.2.3) 73 builder (3.2.3)
@@ -279,6 +281,7 @@ PLATFORMS
279 281
280DEPENDENCIES 282DEPENDENCIES
281 acts-as-taggable-on 283 acts-as-taggable-on
284 audited (~> 4.7)
282 byebug 285 byebug
283 capistrano (~> 3.0) 286 capistrano (~> 3.0)
284 capistrano-bundler 287 capistrano-bundler
@@ -289,6 +292,7 @@ DEPENDENCIES
289 ckeditor 292 ckeditor
290 coffee-rails (~> 4.2) 293 coffee-rails (~> 4.2)
291 devise 294 devise
295 enumerize
292 haml 296 haml
293 highline 297 highline
294 jbuilder (~> 2.5) 298 jbuilder (~> 2.5)
diff --git a/app/assets/stylesheets/main/games.scss b/app/assets/stylesheets/main/games.scss new file mode 100644 index 0000000..5c39701 --- /dev/null +++ b/app/assets/stylesheets/main/games.scss
@@ -0,0 +1,25 @@
1// Place all the styles related to the GamesController controller here.
2// They will automatically be included in application.css.
3// You can use Sass (SCSS) here: http://sass-lang.com/
4#games-table {
5 border-spacing: 0;
6 width: 100%;
7
8 tr {
9 &.even {
10 background-color: #fff;
11 }
12
13 &.odd {
14 background-color: #edf;
15 }
16 }
17
18 td {
19 padding: 0.5em;
20 }
21}
22
23.game-progress p {
24 margin: 0;
25}
diff --git a/app/controllers/admin/games_controller.rb b/app/controllers/admin/games_controller.rb new file mode 100644 index 0000000..5bc6de9 --- /dev/null +++ b/app/controllers/admin/games_controller.rb
@@ -0,0 +1,56 @@
1class Admin::GamesController < Admin::AdminController
2 before_action :set_section
3
4 def index
5 @games = Game.order(created_at: :desc)
6 end
7
8 def drafts
9 @games = Game.where(created_at: :desc)
10 end
11
12 def new
13 @game = Game.new
14 end
15
16 def create
17 @game = Game.new(game_params)
18
19 if @game.save
20 flash.notice = "Game created successfully!"
21
22 render :edit
23 else
24 flash.alert = "Error creating game."
25
26 render :new
27 end
28 end
29
30 def edit
31 @game = Game.find(params[:id])
32 end
33
34 def update
35 @game = Game.find(params[:id])
36
37 if @game.update_attributes(game_params)
38 flash.notice = "Game updated successfully!"
39 else
40 flash.alert = "Error updating game."
41 end
42
43 render :edit
44 end
45
46 private
47
48 def game_params
49 params.require(:game).permit(:title, :description, :status, :progress, :score)
50 end
51
52 def set_section
53 @section = "games"
54 end
55
56end
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb new file mode 100644 index 0000000..7d95b2c --- /dev/null +++ b/app/controllers/games_controller.rb
@@ -0,0 +1,5 @@
1class GamesController < ApplicationController
2 def index
3 @games = Game.all
4 end
5end
diff --git a/app/helpers/admin/games_helper.rb b/app/helpers/admin/games_helper.rb new file mode 100644 index 0000000..ab083dc --- /dev/null +++ b/app/helpers/admin/games_helper.rb
@@ -0,0 +1,2 @@
1module Admin::GamesHelper
2end
diff --git a/app/helpers/games_helper.rb b/app/helpers/games_helper.rb new file mode 100644 index 0000000..2ef8c1f --- /dev/null +++ b/app/helpers/games_helper.rb
@@ -0,0 +1,2 @@
1module GamesHelper
2end
diff --git a/app/models/game.rb b/app/models/game.rb new file mode 100644 index 0000000..de33377 --- /dev/null +++ b/app/models/game.rb
@@ -0,0 +1,13 @@
1class Game < ApplicationRecord
2 extend Enumerize
3
4 audited only: [:status, :progress]
5
6 validates :title, presence: true
7 validates :status, presence: true
8
9 enumerize :status,
10 in: [:playing, :upcoming, :held, :dropped, :finished],
11 default: :upcoming
12
13end
diff --git a/app/views/admin/games/_form.html.haml b/app/views/admin/games/_form.html.haml new file mode 100644 index 0000000..4b17664 --- /dev/null +++ b/app/views/admin/games/_form.html.haml
@@ -0,0 +1,23 @@
1%fieldset#content
2 .title-field
3 = f.label :title
4 = f.text_field :title, placeholder: "Title"
5 .description-field
6 = f.label :description
7 = f.cktext_area :description
8%fieldset#details
9 - if f.object.errors.any?
10 #errors.details-module
11 %h3 Error!
12 %ul
13 - f.object.errors.full_messages.each do |error|
14 %li= error
15 .details-module
16 .progress-field
17 = f.label :progress
18 = f.text_area :progress
19 .details-module
20 .status-field
21 = f.select :status, options_for_select(Game.status.values)
22 = f.label :status
23 .details-module= f.submit
diff --git a/app/views/admin/games/edit.html.haml b/app/views/admin/games/edit.html.haml new file mode 100644 index 0000000..d7a480b --- /dev/null +++ b/app/views/admin/games/edit.html.haml
@@ -0,0 +1,3 @@
1- title "Editing #{@game.title}"
2= form_for @game, url: admin_game_url(@game), html: { id: "entry-form" } do |f|
3 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/games/index.html.haml b/app/views/admin/games/index.html.haml new file mode 100644 index 0000000..96c69b8 --- /dev/null +++ b/app/views/admin/games/index.html.haml
@@ -0,0 +1,13 @@
1- title "Games"
2%table#entries
3 %tr
4 %th Title
5 %th Date published
6 %th
7 - @games.each do |game|
8 %tr{ class: cycle("even", "odd") }
9 %td= game.title
10 %td= game.created_at.strftime("%B %d, %Y, %l:%M%P")
11 %td
12 %ul.admin-actions
13 %li= link_to "Edit", edit_admin_game_url(game)
diff --git a/app/views/admin/games/new.html.haml b/app/views/admin/games/new.html.haml new file mode 100644 index 0000000..00dfb92 --- /dev/null +++ b/app/views/admin/games/new.html.haml
@@ -0,0 +1,3 @@
1- title "New game"
2= form_for @game, url: admin_games_url, html: { id: "entry-form" } do |f|
3 = render partial: "form", locals: { f: f }
diff --git a/app/views/games/index.html.haml b/app/views/games/index.html.haml new file mode 100644 index 0000000..64fbfd9 --- /dev/null +++ b/app/views/games/index.html.haml
@@ -0,0 +1,14 @@
1- title "Games"
2%h2 Games
3%table#games-table
4 %tr
5 %th Title
6 %th Status
7 %th Score
8 %th Progress
9 - @games.each do |game|
10 %tr{ class: cycle("even", "odd") }
11 %td= game.title
12 %td= game.status
13 %td= game.score
14 %td.game-progress= simple_format game.progress
diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 4bfe60a..1c865b0 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml
@@ -33,5 +33,9 @@
33 = link_to "Links", admin_links_url, class: "major-link" 33 = link_to "Links", admin_links_url, class: "major-link"
34 %ul.minors 34 %ul.minors
35 %li.minor= link_to "New link", new_admin_link_url 35 %li.minor= link_to "New link", new_admin_link_url
36 %li{major_sidebar_attrs("games")}
37 = link_to "Games", admin_games_url, class: "major-link"
38 %ul.minors
39 %li.minor= link_to "New game", new_admin_game_url
36 #main 40 #main
37 = yield 41 = yield
diff --git a/config/routes.rb b/config/routes.rb index 512c319..240beae 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -13,6 +13,8 @@ Rails.application.routes.draw do
13 end 13 end
14 14
15 resources :links, except: [:show] 15 resources :links, except: [:show]
16
17 resources :games, except: [:show]
16 end 18 end
17 19
18 mount Ckeditor::Engine => '/ckeditor' 20 mount Ckeditor::Engine => '/ckeditor'
@@ -28,6 +30,8 @@ Rails.application.routes.draw do
28 30
29 get 'thinks/:slug', to: 'streams#show', as: :stream 31 get 'thinks/:slug', to: 'streams#show', as: :stream
30 32
33 get 'plays', to: 'games#index'
34
31 resources :tags, only: [], param: :name do 35 resources :tags, only: [], param: :name do
32 collection do 36 collection do
33 get 'suggest' 37 get 'suggest'
diff --git a/db/migrate/20190312193025_install_audited.rb b/db/migrate/20190312193025_install_audited.rb new file mode 100644 index 0000000..ef5487e --- /dev/null +++ b/db/migrate/20190312193025_install_audited.rb
@@ -0,0 +1,30 @@
1class InstallAudited < ActiveRecord::Migration[5.2]
2 def self.up
3 create_table :audits, :force => true do |t|
4 t.column :auditable_id, :integer
5 t.column :auditable_type, :string
6 t.column :associated_id, :integer
7 t.column :associated_type, :string
8 t.column :user_id, :integer
9 t.column :user_type, :string
10 t.column :username, :string
11 t.column :action, :string
12 t.column :audited_changes, :text
13 t.column :version, :integer, :default => 0
14 t.column :comment, :string
15 t.column :remote_address, :string
16 t.column :request_uuid, :string
17 t.column :created_at, :datetime
18 end
19
20 add_index :audits, [:auditable_type, :auditable_id, :version], :name => 'auditable_index'
21 add_index :audits, [:associated_type, :associated_id], :name => 'associated_index'
22 add_index :audits, [:user_id, :user_type], :name => 'user_index'
23 add_index :audits, :request_uuid
24 add_index :audits, :created_at
25 end
26
27 def self.down
28 drop_table :audits
29 end
30end
diff --git a/db/migrate/20190312193154_create_games.rb b/db/migrate/20190312193154_create_games.rb new file mode 100644 index 0000000..de30492 --- /dev/null +++ b/db/migrate/20190312193154_create_games.rb
@@ -0,0 +1,13 @@
1class CreateGames < ActiveRecord::Migration[5.2]
2 def change
3 create_table :games do |t|
4 t.string :title
5 t.string :status
6 t.text :progress
7 t.text :description
8 t.integer :score
9
10 t.timestamps
11 end
12 end
13end
diff --git a/db/schema.rb b/db/schema.rb index 93085f3..c5c794f 100644 --- a/db/schema.rb +++ b/db/schema.rb
@@ -10,7 +10,29 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema.define(version: 2018_08_11_215146) do 13ActiveRecord::Schema.define(version: 2019_03_12_193154) do
14
15 create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
16 t.integer "auditable_id"
17 t.string "auditable_type"
18 t.integer "associated_id"
19 t.string "associated_type"
20 t.integer "user_id"
21 t.string "user_type"
22 t.string "username"
23 t.string "action"
24 t.text "audited_changes"
25 t.integer "version", default: 0
26 t.string "comment"
27 t.string "remote_address"
28 t.string "request_uuid"
29 t.datetime "created_at"
30 t.index ["associated_type", "associated_id"], name: "associated_index"
31 t.index ["auditable_type", "auditable_id", "version"], name: "auditable_index"
32 t.index ["created_at"], name: "index_audits_on_created_at"
33 t.index ["request_uuid"], name: "index_audits_on_request_uuid"
34 t.index ["user_id", "user_type"], name: "user_index"
35 end
14 36
15 create_table "blogs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", force: :cascade do |t| 37 create_table "blogs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", force: :cascade do |t|
16 t.string "title" 38 t.string "title"
@@ -35,6 +57,16 @@ ActiveRecord::Schema.define(version: 2018_08_11_215146) do
35 t.index ["type"], name: "index_ckeditor_assets_on_type" 57 t.index ["type"], name: "index_ckeditor_assets_on_type"
36 end 58 end
37 59
60 create_table "games", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
61 t.string "title"
62 t.string "status"
63 t.text "progress"
64 t.text "description"
65 t.integer "score"
66 t.datetime "created_at", null: false
67 t.datetime "updated_at", null: false
68 end
69
38 create_table "links", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t| 70 create_table "links", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t|
39 t.string "title", null: false 71 t.string "title", null: false
40 t.string "url", null: false 72 t.string "url", null: false