From bcf6445d92f1a57dff0b97bd9309f40b70088448 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 13 Mar 2019 10:18:45 -0400 Subject: Added started/finished on dates to Game --- app/assets/javascripts/admin/dashboard.coffee | 5 +++++ app/controllers/admin/games_controller.rb | 2 +- app/controllers/games_controller.rb | 2 +- app/views/admin/games/_form.html.haml | 10 +++++++++- db/migrate/20190313123149_add_start_and_end_dates_to_game.rb | 8 ++++++++ db/schema.rb | 4 +++- 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20190313123149_add_start_and_end_dates_to_game.rb diff --git a/app/assets/javascripts/admin/dashboard.coffee b/app/assets/javascripts/admin/dashboard.coffee index 24f83d1..4fa6cd8 100644 --- a/app/assets/javascripts/admin/dashboard.coffee +++ b/app/assets/javascripts/admin/dashboard.coffee @@ -1,3 +1,8 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://coffeescript.org/ +dash_ready = -> + $(".datepicker").datepicker({"dateFormat": "yy-mm-dd"}) + +$(document).ready(dash_ready) +$(document).on('turbolinks:load', dash_ready) diff --git a/app/controllers/admin/games_controller.rb b/app/controllers/admin/games_controller.rb index 5bc6de9..ee5fe59 100644 --- a/app/controllers/admin/games_controller.rb +++ b/app/controllers/admin/games_controller.rb @@ -46,7 +46,7 @@ class Admin::GamesController < Admin::AdminController private def game_params - params.require(:game).permit(:title, :description, :status, :progress, :score) + params.require(:game).permit(:title, :description, :status, :progress, :score, :started_on, :finished_on) end def set_section diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 490e0b0..8ddcf24 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -1,6 +1,6 @@ class GamesController < ApplicationController def index - @games = Game.all + @games = Game.order(started_on: :desc) if params[:status] @games = @games.where(status: params[:status]) diff --git a/app/views/admin/games/_form.html.haml b/app/views/admin/games/_form.html.haml index 4b17664..ed0982e 100644 --- a/app/views/admin/games/_form.html.haml +++ b/app/views/admin/games/_form.html.haml @@ -16,8 +16,16 @@ .progress-field = f.label :progress = f.text_area :progress + .details-module + .started-field + = f.label :started_on + = f.text_field :started_on, class: "datepicker" + .details-module + .finished-field + = f.label :finished_on + = f.text_field :finished_on, class: "datepicker" .details-module .status-field - = f.select :status, options_for_select(Game.status.values) + = f.select :status, options_for_select(Game.status.values, f.object.status) = f.label :status .details-module= f.submit diff --git a/db/migrate/20190313123149_add_start_and_end_dates_to_game.rb b/db/migrate/20190313123149_add_start_and_end_dates_to_game.rb new file mode 100644 index 0000000..7803344 --- /dev/null +++ b/db/migrate/20190313123149_add_start_and_end_dates_to_game.rb @@ -0,0 +1,8 @@ +class AddStartAndEndDatesToGame < ActiveRecord::Migration[5.2] + def change + change_table :games do |c| + c.date :started_on + c.date :finished_on + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c5c794f..0ae9b11 100644 --- a/db/schema.rb +++ b/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: 2019_03_12_193154) do +ActiveRecord::Schema.define(version: 2019_03_13_123149) do create_table "audits", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t| t.integer "auditable_id" @@ -65,6 +65,8 @@ ActiveRecord::Schema.define(version: 2019_03_12_193154) do t.integer "score" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.date "started_on" + t.date "finished_on" end create_table "links", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", force: :cascade do |t| -- cgit 1.4.1