Only show *relevant* colors in Alt Styles filters

That is, there is no 8-bit alt style, so don't bother including it in
the filter form; same for most other colors.
This commit is contained in:
Emi Matchu 2024-09-30 16:35:58 -07:00
parent a99fb3ec02
commit 86e1f31231
2 changed files with 11 additions and 4 deletions

View file

@ -1,15 +1,22 @@
class AltStylesController < ApplicationController class AltStylesController < ApplicationController
def index def index
@alt_styles = AltStyle.includes(:species, :color, :swf_assets). @all_alt_styles = AltStyle.includes(:species, :color).
order(:species_id, :color_id) order(:species_id, :color_id)
@all_colors = @all_alt_styles.map(&:color).uniq.sort_by(&:name)
@all_species = @all_alt_styles.map(&:species).uniq.sort_by(&:name)
@all_color_names = @all_colors.map(&:human_name)
@all_species_names = @all_species.map(&:human_name)
@color = find_color @color = find_color
@species = find_species @species = find_species
@alt_styles = @all_alt_styles.includes(:swf_assets)
@alt_styles.merge!(@color.alt_styles) if @color @alt_styles.merge!(@color.alt_styles) if @color
@alt_styles.merge!(@species.alt_styles) if @species @alt_styles.merge!(@species.alt_styles) if @species
# We're going to link to the HTML5 image URL, so make sure we have all the # We're using the HTML5 image for our preview, so make sure we have all the
# manifests ready! # manifests ready!
SwfAsset.preload_manifests @alt_styles.map(&:swf_assets).flatten SwfAsset.preload_manifests @alt_styles.map(&:swf_assets).flatten

View file

@ -18,9 +18,9 @@
class: "rainbow-pool-filters" do |f| class: "rainbow-pool-filters" do |f|
%fieldset %fieldset
%legend Filter by: %legend Filter by:
= f.select :color, Color.order(:name).map(&:human_name), = f.select :color, @all_color_names,
selected: @color&.human_name, include_blank: "Color…" selected: @color&.human_name, include_blank: "Color…"
= f.select :species, Species.order(:name).map(&:human_name), = f.select :species, @all_species_names,
selected: @species&.human_name, include_blank: "Species…" selected: @species&.human_name, include_blank: "Species…"
= f.submit "Go" = f.submit "Go"