diff --git a/app/controllers/alt_styles_controller.rb b/app/controllers/alt_styles_controller.rb index 742034d7..e7777799 100644 --- a/app/controllers/alt_styles_controller.rb +++ b/app/controllers/alt_styles_controller.rb @@ -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 diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index 857f0e9f..583ea0ac 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -101,6 +101,18 @@ class AltStyle < ApplicationRecord "" 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)