Compare commits

...

3 commits

Author SHA1 Message Date
7f62417294 Fix bug sorting pet styles by creation date
Before this change, the sort order when searching for
"Prismatic Pine: Nostalgic" showed:

- [Added Dec 18, 2024] Prismatic Pine: Nostalgic Christmas Flotsam
- [Added Dec 19, 2024] Prismatic Pine: Nostalgic Christmas Gelert
- [Added Dec 18, 2024] Prismatic Pine: Nostalgic Christmas Bruce
- [Added Dec 17, 2024] Prismatic Pine: Nostalgic Christmas Scorchio
- <more>

This is because the Gelert was created at 11:37 NST on Dec 19, whereas
the Flotsam was created at 18:11 NST on Dec 18—but in UTC, which is how
timestamps are stored in the database, these are both Dec 19, so the
Flotsam was sorting first alphabetically.

In this change, we do a hacky transform from UTC to NST-ish. I didn't
want to set up the deploy process to pull named time zones into MySQL,
and then have this as a potential gotcha for the dev environment
later—so instead, I pretend `-08:00` is a good-enough specification of
NST.

This will sometimes create slightly incorrect sort ordering when it
*is* Daylight Savings, and a record was created around midnight. I'm
okay with that!
2024-12-29 16:11:00 -08:00
fe6d42ef67 Remove "<New?>" from pet style search filters
When there's an unlabeled style, previously we'd include the placeholder
value "<New?>" in the search dropdown, even though we don't actually
support searching by it.

Now, we don't! I did this in part by just refactoring how we look this
stuff up, with queries that don't load *all* alt styles into memory,
which will help perf a bit as more of them are released.
2024-12-29 15:52:50 -08:00
b8772c3aad Add no results message for alt style searches 2024-12-29 15:47:12 -08:00
4 changed files with 28 additions and 16 deletions

View file

@ -2,20 +2,15 @@ class AltStylesController < ApplicationController
before_action :support_staff_only, except: [:index]
def index
@all_alt_styles = AltStyle.includes(:species, :color)
@all_colors = @all_alt_styles.map(&:color).uniq.sort_by(&:name)
@all_species = @all_alt_styles.map(&:species).uniq.sort_by(&:name)
@all_series_names = @all_alt_styles.map(&:series_name).uniq.sort
@all_color_names = @all_colors.map(&:human_name)
@all_species_names = @all_species.map(&:human_name)
@all_series_names = AltStyle.all_series_names
@all_color_names = AltStyle.all_supported_colors.map(&:human_name).sort
@all_species_names = AltStyle.all_supported_species.map(&:human_name).sort
@series_name = params[:series]
@color = find_color
@species = find_species
@alt_styles = @all_alt_styles.includes(:swf_assets)
@alt_styles = AltStyle.includes(:color, :species, :swf_assets)
@alt_styles.where!(series_name: @series_name) if @series_name.present?
@alt_styles.merge!(@color.alt_styles) if @color
@alt_styles.merge!(@species.alt_styles) if @species

View file

@ -20,7 +20,11 @@ class AltStyle < ApplicationRecord
where(series_name:, color_id: color.id, species_id: species.id)
}
scope :by_creation_date, -> {
order("DATE(created_at) DESC")
# HACK: Setting up named time zones in MySQL takes effort, so we assume
# it's not Daylight Savings. This will produce slightly incorrect
# sorting when it *is* Daylight Savings, and records happen to be
# created around midnight.
order(Arel.sql("DATE(CONVERT_TZ(created_at, '+00:00', '-08:00')) DESC"))
}
scope :unlabeled, -> { where(series_name: nil) }
scope :newest, -> { order(created_at: :desc) }
@ -101,6 +105,18 @@ class AltStyle < ApplicationRecord
"<New?>"
end
def self.all_series_names
distinct.where.not(series_name: nil).pluck(:series_name).sort
end
def self.all_supported_colors
Color.find(distinct.pluck(:color_id))
end
def self.all_supported_species
Species.find(distinct.pluck(:species_id))
end
# For convenience in the console!
def self.find_by_name(color_name, species_name)
color = Color.find_by_name(color_name)

View file

@ -34,11 +34,12 @@
selected: @species&.human_name, include_blank: "Species…"
= f.submit "Go", name: nil
= will_paginate @alt_styles, class: "rainbow-pool-pagination"
%ul.rainbow-pool-list= render @alt_styles
= will_paginate @alt_styles, class: "rainbow-pool-pagination"
- if @alt_styles.present?
= will_paginate @alt_styles, class: "rainbow-pool-pagination"
%ul.rainbow-pool-list= render @alt_styles
= will_paginate @alt_styles, class: "rainbow-pool-pagination"
- else
%p.rainbow-pool-no-results We don't have any styles matching that search.
- content_for :stylesheets do
= stylesheet_link_tag "application/breadcrumbs"

View file

@ -34,7 +34,7 @@
%ui.rainbow-pool-list= render @pet_types
= will_paginate @pet_types, class: "rainbow-pool-pagination"
- else
%p.rainbow-pool-no-results No matching pets found!
%p.rainbow-pool-no-results We don't have any pets matching that search.
- content_for :stylesheets do
= stylesheet_link_tag "application/rainbow-pool"