Skip to content

Commit

Permalink
Sort cars by multiplier & add author's field (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickskyline committed May 13, 2024
1 parent 1bee6ad commit b1263a1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
16 changes: 8 additions & 8 deletions app/controllers/cars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index
# GET /cars/rookie or /cars/rookie.json
def rookie
@cars = Rails.cache.fetch('rookie_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::ROOKIE)
@cars = cars_of_category(SYS::CATEGORY::ROOKIE).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand All @@ -30,7 +30,7 @@ def rookie
# GET /cars/amateur or /cars/amateur.json
def amateur
@cars = Rails.cache.fetch('amateur_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::AMATEUR)
@cars = cars_of_category(SYS::CATEGORY::AMATEUR).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand All @@ -41,7 +41,7 @@ def amateur
# GET /cars/advanced or /cars/advanced.json
def advanced
@cars = Rails.cache.fetch('advanced_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::ADVANCED)
@cars = cars_of_category(SYS::CATEGORY::ADVANCED).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand All @@ -52,7 +52,7 @@ def advanced
# GET /cars/semipro or /cars/semipro.json
def semipro
@cars = Rails.cache.fetch('semipro_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::SEMI_PRO)
@cars = cars_of_category(SYS::CATEGORY::SEMI_PRO).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand All @@ -63,7 +63,7 @@ def semipro
# GET /cars/pro or /cars/pro.json
def pro
@cars = Rails.cache.fetch('pro_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::PRO)
@cars = cars_of_category(SYS::CATEGORY::PRO).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand All @@ -74,7 +74,7 @@ def pro
# GET /cars/superpro or /cars/superpro.json
def superpro
@cars = Rails.cache.fetch('superpro_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::SUPER_PRO)
@cars = cars_of_category(SYS::CATEGORY::SUPER_PRO).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand All @@ -85,7 +85,7 @@ def superpro
# GET /cars/clockwork or /cars/clockwork.json
def clockwork
@cars = Rails.cache.fetch('clockwork_cars', :expires_in => 1.month) do
@cars = cars_of_category(SYS::CATEGORY::CLOCKWORK)
@cars = cars_of_category(SYS::CATEGORY::CLOCKWORK).sort_by { |car| [car.multiplier, car.stock? ? 0 : 1] }
end

respond_with @cars do |format|
Expand Down Expand Up @@ -211,6 +211,6 @@ def set_car

# Only allow a list of trusted parameters through.
def car_params
params.require(:car).permit(:name, :speed, :accel, :weight, :multiplier, :folder_name, :category, :stock, :season)
params.require(:car).permit(:name, :speed, :accel, :weight, :multiplier, :folder_name, :category, :author, :stock, :season)
end
end
2 changes: 2 additions & 0 deletions app/models/car.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Car
field :multiplier, :type => Float
field :folder_name, :type => String
field :category, :type => Integer
field :author, :type => String
field :stock, :type => Boolean, :default => false

validates_presence_of :name
Expand All @@ -22,6 +23,7 @@ class Car
validates_presence_of :multiplier
validates_presence_of :folder_name
validates_presence_of :category
validates_presence_of :author
validates_presence_of :stock

def thumbnail_url
Expand Down
3 changes: 2 additions & 1 deletion app/services/csv_import_cars_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def call
:weight => row[3],
:multiplier => row[4],
:folder_name => row[5],
:stock => true?(row[6])
:author => row[6],
:stock => true?(row[7])
}

cars << Car.new(car_hash)
Expand Down
2 changes: 1 addition & 1 deletion app/views/cars/_car.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
json.extract! car, :id, :name, :speed, :accel, :weight, :multiplier, :category, :stock, :folder_name, :created_at,
json.extract! car, :id, :name, :speed, :accel, :weight, :multiplier, :category, :author, :stock, :folder_name, :created_at,
:updated_at
json.url car_url(car, :format => :json)
3 changes: 3 additions & 0 deletions app/views/cars/edit.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
.field.form-group
= f.label :folder_name, t("rva.cars.edit.folder-name")
= f.text_field :folder_name, :class => "form-control"
.field-form-group
= f.label :author, t("rva.cars.features.author")
= f.text_field :author, :class => "form-control"
.field.form-group
= f.label :stock, t("rva.cars.features.stock")
= f.check_box :stock
Expand Down
4 changes: 4 additions & 0 deletions app/views/cars/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
= t("rva.cars.features.category")
%dd
= category_name(@car.category)
%dt
= t("rva.cars.features.author")
%dd
= @car.author
%dt{:style => "cursor: help;", :"data-toggle" => "tooltip", :"data-placement" => "top", :title => t("rva.cars.features.stock-tooltip.tooltip")}
= t("rva.shared.stock.title")
%dd
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ en:
weight: "Weight"
multiplier: "Multiplier"
category: "Category"
author: "Author"
stock: "Stock"
stock-tooltip:
tooltip: "Original Re-Volt Content"
Expand Down

0 comments on commit b1263a1

Please sign in to comment.