Skip to content

Commit

Permalink
Merge pull request #6 from FRC85Programming/feature/seasons
Browse files Browse the repository at this point in the history
Seasons
  • Loading branch information
mattmichielsen authored Apr 21, 2023
2 parents 76bdf4a + 21a3c7e commit 39ed363
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 23 deletions.
2 changes: 1 addition & 1 deletion web/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,4 @@ DEPENDENCIES
wicked_pdf

BUNDLED WITH
2.2.15
2.4.6
10 changes: 5 additions & 5 deletions web/app/controllers/pilots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/app/controllers/system_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions web/app/models/pilot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions web/app/models/race_session.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 3 additions & 0 deletions web/app/models/season.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Season < ActiveRecord::Base
has_many :race_session
end
4 changes: 4 additions & 0 deletions web/app/views/history/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
%tr
%th
%th
%th Season
%th Session
%th Mode
%th Participants
Expand All @@ -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})
Expand Down
7 changes: 7 additions & 0 deletions web/app/views/shared/_panel_race_session_control.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
16 changes: 8 additions & 8 deletions web/bin/rails
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 8 additions & 8 deletions web/bin/rake
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions web/db/migrate/20220301223722_create_seasons.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions web/db/migrate/20220301225144_add_season_to_race_session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSeasonToRaceSession < ActiveRecord::Migration
def change
add_reference :race_sessions, :season, index: true, foreign_key: true
end
end
5 changes: 5 additions & 0 deletions web/spec/models/season_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Season, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 39ed363

Please sign in to comment.