about summary refs log tree commit diff stats
path: root/app
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 /app
parent7a2d945f581c8ce9e322883ec597366143fe10cb (diff)
downloadthoughts-7789e2138fc0479846c20bc68d68973636a4a760.tar.gz
thoughts-7789e2138fc0479846c20bc68d68973636a4a760.tar.bz2
thoughts-7789e2138fc0479846c20bc68d68973636a4a760.zip
Started game tracker
Diffstat (limited to 'app')
-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
12 files changed, 163 insertions, 0 deletions
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