From 7789e2138fc0479846c20bc68d68973636a4a760 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 12 Mar 2019 21:50:00 -0400 Subject: Started game tracker --- app/assets/stylesheets/main/games.scss | 25 ++++++++++++++ app/controllers/admin/games_controller.rb | 56 +++++++++++++++++++++++++++++++ app/controllers/games_controller.rb | 5 +++ app/helpers/admin/games_helper.rb | 2 ++ app/helpers/games_helper.rb | 2 ++ app/models/game.rb | 13 +++++++ app/views/admin/games/_form.html.haml | 23 +++++++++++++ app/views/admin/games/edit.html.haml | 3 ++ app/views/admin/games/index.html.haml | 13 +++++++ app/views/admin/games/new.html.haml | 3 ++ app/views/games/index.html.haml | 14 ++++++++ app/views/layouts/admin.html.haml | 4 +++ 12 files changed, 163 insertions(+) create mode 100644 app/assets/stylesheets/main/games.scss create mode 100644 app/controllers/admin/games_controller.rb create mode 100644 app/controllers/games_controller.rb create mode 100644 app/helpers/admin/games_helper.rb create mode 100644 app/helpers/games_helper.rb create mode 100644 app/models/game.rb create mode 100644 app/views/admin/games/_form.html.haml create mode 100644 app/views/admin/games/edit.html.haml create mode 100644 app/views/admin/games/index.html.haml create mode 100644 app/views/admin/games/new.html.haml create mode 100644 app/views/games/index.html.haml (limited to 'app') 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 @@ +// Place all the styles related to the GamesController controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +#games-table { + border-spacing: 0; + width: 100%; + + tr { + &.even { + background-color: #fff; + } + + &.odd { + background-color: #edf; + } + } + + td { + padding: 0.5em; + } +} + +.game-progress p { + margin: 0; +} 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 @@ +class Admin::GamesController < Admin::AdminController + before_action :set_section + + def index + @games = Game.order(created_at: :desc) + end + + def drafts + @games = Game.where(created_at: :desc) + end + + def new + @game = Game.new + end + + def create + @game = Game.new(game_params) + + if @game.save + flash.notice = "Game created successfully!" + + render :edit + else + flash.alert = "Error creating game." + + render :new + end + end + + def edit + @game = Game.find(params[:id]) + end + + def update + @game = Game.find(params[:id]) + + if @game.update_attributes(game_params) + flash.notice = "Game updated successfully!" + else + flash.alert = "Error updating game." + end + + render :edit + end + + private + + def game_params + params.require(:game).permit(:title, :description, :status, :progress, :score) + end + + def set_section + @section = "games" + end + +end 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 @@ +class GamesController < ApplicationController + def index + @games = Game.all + end +end 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 @@ +module Admin::GamesHelper +end 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 @@ +module GamesHelper +end 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 @@ +class Game < ApplicationRecord + extend Enumerize + + audited only: [:status, :progress] + + validates :title, presence: true + validates :status, presence: true + + enumerize :status, + in: [:playing, :upcoming, :held, :dropped, :finished], + default: :upcoming + +end 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 @@ +%fieldset#content + .title-field + = f.label :title + = f.text_field :title, placeholder: "Title" + .description-field + = f.label :description + = f.cktext_area :description +%fieldset#details + - if f.object.errors.any? + #errors.details-module + %h3 Error! + %ul + - f.object.errors.full_messages.each do |error| + %li= error + .details-module + .progress-field + = f.label :progress + = f.text_area :progress + .details-module + .status-field + = f.select :status, options_for_select(Game.status.values) + = f.label :status + .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 @@ +- title "Editing #{@game.title}" += form_for @game, url: admin_game_url(@game), html: { id: "entry-form" } do |f| + = 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 @@ +- title "Games" +%table#entries + %tr + %th Title + %th Date published + %th + - @games.each do |game| + %tr{ class: cycle("even", "odd") } + %td= game.title + %td= game.created_at.strftime("%B %d, %Y, %l:%M%P") + %td + %ul.admin-actions + %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 @@ +- title "New game" += form_for @game, url: admin_games_url, html: { id: "entry-form" } do |f| + = 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 @@ +- title "Games" +%h2 Games +%table#games-table + %tr + %th Title + %th Status + %th Score + %th Progress + - @games.each do |game| + %tr{ class: cycle("even", "odd") } + %td= game.title + %td= game.status + %td= game.score + %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 @@ = link_to "Links", admin_links_url, class: "major-link" %ul.minors %li.minor= link_to "New link", new_admin_link_url + %li{major_sidebar_attrs("games")} + = link_to "Games", admin_games_url, class: "major-link" + %ul.minors + %li.minor= link_to "New game", new_admin_game_url #main = yield -- cgit 1.4.1