From 21bee1e4d804d2d75a8880e1b9c65bab736358d6 Mon Sep 17 00:00:00 2001 From: Matt Michielsen Date: Tue, 1 Mar 2022 17:56:36 -0500 Subject: [PATCH 1/5] Added season model --- web/app/models/race_session.rb | 1 + web/app/models/season.rb | 3 +++ web/config/initializers/column_dumper.rb | 22 +++++++++++++++++++ .../migrate/20220301223722_create_seasons.rb | 9 ++++++++ ...220301225144_add_season_to_race_session.rb | 5 +++++ web/db/schema.rb | 10 ++++++++- web/spec/models/season_spec.rb | 5 +++++ 7 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 web/app/models/season.rb create mode 100644 web/config/initializers/column_dumper.rb create mode 100644 web/db/migrate/20220301223722_create_seasons.rb create mode 100644 web/db/migrate/20220301225144_add_season_to_race_session.rb create mode 100644 web/spec/models/season_spec.rb diff --git a/web/app/models/race_session.rb b/web/app/models/race_session.rb index 4d9559d..b112a36 100644 --- a/web/app/models/race_session.rb +++ b/web/app/models/race_session.rb @@ -1,6 +1,7 @@ class RaceSession < ActiveRecord::Base acts_as_paranoid + belongs_to :season has_many :pilot_race_laps has_many :race_attendees enum mode:[:standard,:competition] diff --git a/web/app/models/season.rb b/web/app/models/season.rb new file mode 100644 index 0000000..1699308 --- /dev/null +++ b/web/app/models/season.rb @@ -0,0 +1,3 @@ +class Season < ActiveRecord::Base + has_many :race_session +end diff --git a/web/config/initializers/column_dumper.rb b/web/config/initializers/column_dumper.rb new file mode 100644 index 0000000..2f42d83 --- /dev/null +++ b/web/config/initializers/column_dumper.rb @@ -0,0 +1,22 @@ +module ActiveRecord + module ConnectionAdapters + module ColumnDumper + def prepare_column_options(column, types) + spec = {} + spec[:name] = column.name.inspect + spec[:type] = column.type.to_s + spec[:null] = 'false' unless column.null + + limit = column.limit || types[column.type][:limit] + spec[:limit] = limit.inspect if limit + spec[:precision] = column.precision.inspect if column.precision + spec[:scale] = column.scale.inspect if column.scale + + default = schema_default(column).dup if column.has_default? + spec[:default] = default unless default.nil? + + spec + end + end + end +end \ No newline at end of file diff --git a/web/db/migrate/20220301223722_create_seasons.rb b/web/db/migrate/20220301223722_create_seasons.rb new file mode 100644 index 0000000..104900f --- /dev/null +++ b/web/db/migrate/20220301223722_create_seasons.rb @@ -0,0 +1,9 @@ +class CreateSeasons < ActiveRecord::Migration + def change + create_table :seasons do |t| + t.string :name + + t.timestamps null: false + end + end +end diff --git a/web/db/migrate/20220301225144_add_season_to_race_session.rb b/web/db/migrate/20220301225144_add_season_to_race_session.rb new file mode 100644 index 0000000..4615fcb --- /dev/null +++ b/web/db/migrate/20220301225144_add_season_to_race_session.rb @@ -0,0 +1,5 @@ +class AddSeasonToRaceSession < ActiveRecord::Migration + def change + add_reference :race_sessions, :season, index: true, foreign_key: true + end +end diff --git a/web/db/schema.rb b/web/db/schema.rb index 502a9ca..be17f6d 100755 --- a/web/db/schema.rb +++ b/web/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160502142410) do +ActiveRecord::Schema.define(version: 20220301225144) do create_table "config_values", force: :cascade do |t| t.string "name" @@ -69,9 +69,11 @@ t.integer "time_penalty_per_satellite", default: 2500 t.boolean "hot_seat_enabled", default: false t.integer "idle_time_in_seconds", default: 0 + t.integer "season_id" end add_index "race_sessions", ["deleted_at"], name: "index_race_sessions_on_deleted_at" + add_index "race_sessions", ["season_id"], name: "index_race_sessions_on_season_id" create_table "roles", force: :cascade do |t| t.string "name" @@ -95,6 +97,12 @@ add_index "satellite_check_points", ["race_attendee_id"], name: "index_satellite_check_points_on_race_attendee_id" add_index "satellite_check_points", ["race_session_id"], name: "index_satellite_check_points_on_race_session_id" + create_table "seasons", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "soundfiles", force: :cascade do |t| t.string "name" t.string "file" diff --git a/web/spec/models/season_spec.rb b/web/spec/models/season_spec.rb new file mode 100644 index 0000000..e1ddeac --- /dev/null +++ b/web/spec/models/season_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Season, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 3b1d4d447854d9251724e434397f8e39058c602c Mon Sep 17 00:00:00 2001 From: Matt Michielsen Date: Tue, 1 Mar 2022 20:34:41 -0500 Subject: [PATCH 2/5] Permissions and file endings on rails and rake command --- web/bin/rails | 16 ++++++++-------- web/bin/rake | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) mode change 100644 => 100755 web/bin/rails mode change 100644 => 100755 web/bin/rake diff --git a/web/bin/rails b/web/bin/rails old mode 100644 new mode 100755 index b1043b9..4d608ed --- a/web/bin/rails +++ b/web/bin/rails @@ -1,8 +1,8 @@ -#!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/web/bin/rake b/web/bin/rake old mode 100644 new mode 100755 index b9cc113..8017a02 --- a/web/bin/rake +++ b/web/bin/rake @@ -1,8 +1,8 @@ -#!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -require_relative '../config/boot' -require 'rake' -Rake.application.run +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +require_relative '../config/boot' +require 'rake' +Rake.application.run From 40d9d586e43a9318f5ced70a0f4e3828e4e5ae6d Mon Sep 17 00:00:00 2001 From: Matt Michielsen Date: Wed, 2 Mar 2022 20:38:41 -0500 Subject: [PATCH 3/5] Made scope for to filter out participants without transponder tokens --- web/app/controllers/pilots_controller.rb | 10 +++++----- web/app/models/pilot.rb | 2 ++ web/app/views/system/pilot/edit.html.haml | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/web/app/controllers/pilots_controller.rb b/web/app/controllers/pilots_controller.rb index 998afe2..d722f9d 100644 --- a/web/app/controllers/pilots_controller.rb +++ b/web/app/controllers/pilots_controller.rb @@ -2,21 +2,21 @@ class PilotsController < ApplicationController before_action :filter_needs_login def index - @pilots = Pilot.order("name ASC") - @total_laps = Pilot.all_laps + @pilots = Pilot.registered.order("name ASC") + @total_laps = Pilot.registered.all_laps end def laps - @pilot = Pilot.find(params[:id]) + @pilot = Pilot.registered.find(params[:id]) end def teams - @teams = Pilot.select('distinct(team)').map(&:team) + @teams = Pilot.registered.select('distinct(team)').map(&:team) render :json => @teams end def filter_by_team - @pilots = Pilot.where(team: params[:team]) + @pilots = Pilot.registered.where(team: params[:team]) @total_laps = 0 @pilots.each do |p| @total_laps += p.total_laps diff --git a/web/app/models/pilot.rb b/web/app/models/pilot.rb index 0eccf0e..477d118 100644 --- a/web/app/models/pilot.rb +++ b/web/app/models/pilot.rb @@ -5,6 +5,8 @@ class Pilot < ActiveRecord::Base acts_as_paranoid mount_uploader :image, PilotImageUploader + scope :registered, -> {where.not(transponder_token: [nil, ''])} + def total_races return self.pilot_race_laps.group(:race_session_id).count.count end diff --git a/web/app/views/system/pilot/edit.html.haml b/web/app/views/system/pilot/edit.html.haml index a90e411..6c9b31a 100644 --- a/web/app/views/system/pilot/edit.html.haml +++ b/web/app/views/system/pilot/edit.html.haml @@ -19,7 +19,7 @@ .form-group %label{:for => "exampleInputEmail2"} = t('pilot.quad') - = f.text_field(:quad, placeholder: "ZMR 250 4S", class: 'form-control', required: true) + = f.text_field(:quad, placeholder: "ZMR 250 4S", class: 'form-control', required: false) .form-group %label{:for => "exampleInputEmail2"} = t('pilot.team') From 93bb96c541a13a14e6799d055a96cdf17537443d Mon Sep 17 00:00:00 2001 From: Matt Michielsen Date: Sat, 18 Mar 2023 14:37:12 -0400 Subject: [PATCH 4/5] Some progress on seasons --- web/Gemfile.lock | 2 +- web/app/views/history/index.html.haml | 4 ++++ web/app/views/shared/_panel_race_session_control.html.haml | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/web/Gemfile.lock b/web/Gemfile.lock index 2ef6f54..2bad941 100644 --- a/web/Gemfile.lock +++ b/web/Gemfile.lock @@ -294,4 +294,4 @@ DEPENDENCIES wicked_pdf BUNDLED WITH - 2.2.15 + 2.4.6 diff --git a/web/app/views/history/index.html.haml b/web/app/views/history/index.html.haml index 5145624..1959bea 100644 --- a/web/app/views/history/index.html.haml +++ b/web/app/views/history/index.html.haml @@ -7,6 +7,7 @@ %tr %th %th + %th Season %th Session %th Mode %th Participants @@ -24,6 +25,9 @@ %td.smalltd %strong = session.created_at().to_s(:long) + %td + %strong + = session.season&.name %td %strong = link_to(session.title,{action: 'show', id: session.id}) diff --git a/web/app/views/shared/_panel_race_session_control.html.haml b/web/app/views/shared/_panel_race_session_control.html.haml index 03f6342..d08f6d9 100644 --- a/web/app/views/shared/_panel_race_session_control.html.haml +++ b/web/app/views/shared/_panel_race_session_control.html.haml @@ -12,6 +12,9 @@ %label{:for => "exampleInputName2"} Active Session: = RaceSession::get_open_session.title + %label{:for => "exampleInputName2"} + Season: + = RaceSession::get_open_session.season&.name %label{:for => "exampleInputName2"} Mode: = RaceSession::get_open_session.mode @@ -34,6 +37,10 @@ .row .col-xs-12 = form_for(@race_session_prototype,url: {action: 'start_race_session',controller: '/system'},html: {class: 'form-inline'}) do |f| + .form-group + %label{:for => "exampleInputName2"} + = t('season.name') + = f.collection_select(:season_id, Season.all, :id, :name, {include_blank: true}, {class: 'form-control'}) .form-group %label{:for => "exampleInputName2"} = t('race_session.title') From 77e700cae1e6ee4d1a9a3b2af4fed88e76d58f62 Mon Sep 17 00:00:00 2001 From: Matt Michielsen Date: Sat, 18 Mar 2023 18:46:01 -0400 Subject: [PATCH 5/5] Added season selection at start of race --- web/app/controllers/system_controller.rb | 2 +- web/app/views/shared/_panel_race_session_control.html.haml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app/controllers/system_controller.rb b/web/app/controllers/system_controller.rb index 14ad829..eda0d93 100644 --- a/web/app/controllers/system_controller.rb +++ b/web/app/controllers/system_controller.rb @@ -54,7 +54,7 @@ def get_style_settings end def strong_params_race_session - params.require(:race_session).permit(:title,:idle_time_in_seconds) + params.require(:race_session).permit(:title, :idle_time_in_seconds, :season_id) end def strong_params_style_settings diff --git a/web/app/views/shared/_panel_race_session_control.html.haml b/web/app/views/shared/_panel_race_session_control.html.haml index d08f6d9..0df4a42 100644 --- a/web/app/views/shared/_panel_race_session_control.html.haml +++ b/web/app/views/shared/_panel_race_session_control.html.haml @@ -39,8 +39,8 @@ = form_for(@race_session_prototype,url: {action: 'start_race_session',controller: '/system'},html: {class: 'form-inline'}) do |f| .form-group %label{:for => "exampleInputName2"} - = t('season.name') - = f.collection_select(:season_id, Season.all, :id, :name, {include_blank: true}, {class: 'form-control'}) + Season + = f.collection_select(:season_id, Season.all, :id, :name, {:selected => Season.last&.id}, {class: 'form-control'}) .form-group %label{:for => "exampleInputName2"} = t('race_session.title')