2024-01-24 06:53:37 -08:00
|
|
|
class AltStylesController < ApplicationController
|
|
|
|
def index
|
|
|
|
@alt_styles = AltStyle.includes(:species, :color, :swf_assets).
|
2024-01-28 07:30:06 -08:00
|
|
|
order(:species_id, :color_id)
|
|
|
|
|
2024-09-30 16:06:22 -07:00
|
|
|
@color = find_color
|
|
|
|
@species = find_species
|
|
|
|
|
|
|
|
@alt_styles.merge!(@color.alt_styles) if @color
|
|
|
|
@alt_styles.merge!(@species.alt_styles) if @species
|
2024-01-28 07:30:06 -08:00
|
|
|
|
2024-02-23 13:45:12 -08:00
|
|
|
# We're going to link to the HTML5 image URL, so make sure we have all the
|
|
|
|
# manifests ready!
|
|
|
|
SwfAsset.preload_manifests @alt_styles.map(&:swf_assets).flatten
|
|
|
|
|
2024-01-28 07:30:06 -08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render }
|
2024-01-29 03:20:48 -08:00
|
|
|
format.json {
|
2024-01-30 07:01:03 -08:00
|
|
|
render json: @alt_styles.includes(swf_assets: [:zone]).as_json(
|
2024-02-24 16:25:55 -08:00
|
|
|
only: [:id, :species_id, :color_id, :body_id, :series_name,
|
|
|
|
:adjective_name, :thumbnail_url],
|
2024-01-31 03:02:19 -08:00
|
|
|
include: {
|
|
|
|
swf_assets: {
|
2024-02-24 16:25:55 -08:00
|
|
|
only: [:id, :body_id],
|
2024-01-31 03:02:19 -08:00
|
|
|
include: [:zone],
|
2024-02-24 16:31:05 -08:00
|
|
|
methods: [:urls, :known_glitches],
|
2024-01-31 03:02:19 -08:00
|
|
|
}
|
|
|
|
},
|
2024-01-30 05:54:20 -08:00
|
|
|
methods: [:series_name, :adjective_name, :thumbnail_url],
|
2024-01-29 03:20:48 -08:00
|
|
|
)
|
|
|
|
}
|
2024-01-28 07:30:06 -08:00
|
|
|
end
|
2024-01-24 06:53:37 -08:00
|
|
|
end
|
2024-09-30 16:06:22 -07:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def find_color
|
|
|
|
if params[:color]
|
|
|
|
Color.find_by(name: params[:color])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_species
|
|
|
|
if params[:species_id]
|
|
|
|
Species.find_by(id: params[:species_id])
|
|
|
|
elsif params[:species]
|
|
|
|
Species.find_by(name: params[:species])
|
|
|
|
end
|
|
|
|
end
|
2024-01-24 06:53:37 -08:00
|
|
|
end
|