forked from OpenNeo/impress
[WIP] Add species/color picker for simplified item page preview
Still a lot missing here, like choosing the right default for Baby etc items, and saving the user's preferences. But it's a start!
This commit is contained in:
parent
ea17e76c39
commit
1b000189c4
3 changed files with 63 additions and 4 deletions
|
@ -57,3 +57,14 @@ body.items-show
|
||||||
img
|
img
|
||||||
width: 100%
|
width: 100%
|
||||||
height: 100%
|
height: 100%
|
||||||
|
|
||||||
|
.species-color-picker
|
||||||
|
.error-icon
|
||||||
|
cursor: help
|
||||||
|
margin-right: .25em
|
||||||
|
|
||||||
|
&[data-is-valid="false"]
|
||||||
|
select
|
||||||
|
border-color: $error-border-color
|
||||||
|
color: $error-color
|
||||||
|
|
||||||
|
|
|
@ -83,15 +83,16 @@ class ItemsController < ApplicationController
|
||||||
@current_user_quantities = current_user.item_quantities_for(@item)
|
@current_user_quantities = current_user.item_quantities_for(@item)
|
||||||
end
|
end
|
||||||
|
|
||||||
@preview_pet_type = PetType.find_by_color_id_and_species_id(
|
@selected_preview_pet_type = load_selected_preview_pet_type
|
||||||
Color.find_by_name("Blue"),
|
@preview_pet_type = load_preview_pet_type
|
||||||
Species.find_by_name("Acara"),
|
|
||||||
)
|
|
||||||
@item_layers = @item.appearance_for(
|
@item_layers = @item.appearance_for(
|
||||||
@preview_pet_type, swf_asset_includes: [:zone]
|
@preview_pet_type, swf_asset_includes: [:zone]
|
||||||
).swf_assets
|
).swf_assets
|
||||||
@pet_layers = @preview_pet_type.canonical_pet_state.swf_assets.
|
@pet_layers = @preview_pet_type.canonical_pet_state.swf_assets.
|
||||||
includes(:zone)
|
includes(:zone)
|
||||||
|
|
||||||
|
@preview_error = validate_preview
|
||||||
end
|
end
|
||||||
|
|
||||||
format.gif do
|
format.gif do
|
||||||
|
@ -199,6 +200,38 @@ class ItemsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_selected_preview_pet_type
|
||||||
|
color_id = params.dig(:preview, :color_id)
|
||||||
|
species_id = params.dig(:preview, :species_id)
|
||||||
|
|
||||||
|
return load_default_preview_pet_type if color_id.nil? || species_id.nil?
|
||||||
|
|
||||||
|
PetType.find_or_initialize_by(color_id:, species_id:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_preview_pet_type
|
||||||
|
if @selected_preview_pet_type.persisted?
|
||||||
|
@selected_preview_pet_type
|
||||||
|
else
|
||||||
|
load_default_preview_pet_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_default_preview_pet_type
|
||||||
|
PetType.find_by_color_id_and_species_id(
|
||||||
|
Color.find_by_name("Blue"),
|
||||||
|
Species.find_by_name("Acara"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_preview
|
||||||
|
if @selected_preview_pet_type.new_record?
|
||||||
|
:pet_type_does_not_exist
|
||||||
|
elsif @item_layers.empty?
|
||||||
|
:no_item_data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def search_error(e)
|
def search_error(e)
|
||||||
@items = []
|
@items = []
|
||||||
@query = params[:q]
|
@query = params[:q]
|
||||||
|
|
|
@ -19,6 +19,21 @@
|
||||||
%outfit-item-appearance
|
%outfit-item-appearance
|
||||||
= outfit_viewer_layers @item_layers
|
= outfit_viewer_layers @item_layers
|
||||||
|
|
||||||
|
= form_for item_path(@item), method: :get, class: "species-color-picker",
|
||||||
|
data: {"is-valid": @preview_error.nil?} do |f|
|
||||||
|
- if @preview_error == :pet_type_does_not_exist
|
||||||
|
%span.error-icon{title: "We haven't seen this kind of pet before."} ⚠️
|
||||||
|
- elsif @preview_error == :no_item_data
|
||||||
|
%span.error-icon{title: "We haven't seen this item on this pet before."} ⚠️
|
||||||
|
|
||||||
|
= select_tag "preview[color_id]",
|
||||||
|
options_from_collection_for_select(Color.funny.alphabetical,
|
||||||
|
"id", "human_name", @selected_preview_pet_type.color_id)
|
||||||
|
= select_tag "preview[species_id]",
|
||||||
|
options_from_collection_for_select(Species.alphabetical,
|
||||||
|
"id", "human_name", @selected_preview_pet_type.species_id)
|
||||||
|
= submit_tag "Go", name: nil
|
||||||
|
|
||||||
- unless @contributors_with_counts.empty?
|
- unless @contributors_with_counts.empty?
|
||||||
#item-contributors
|
#item-contributors
|
||||||
%header #{t '.contributors.header'}:
|
%header #{t '.contributors.header'}:
|
||||||
|
|
Loading…
Reference in a new issue