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/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/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/models/pilot.rb b/web/app/models/pilot.rb index 22f254f..1dfc8d4 100644 --- a/web/app/models/pilot.rb +++ b/web/app/models/pilot.rb @@ -6,6 +6,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/models/race_session.rb b/web/app/models/race_session.rb index 73ca3aa..f2f5fb5 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/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..0df4a42 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"} + 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') 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 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/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