forked from OpenNeo/impress
Emi Matchu
dc44b4dbb3
Okay right, the wardrobe-2020 app treats `state` as a bit of an override thing, and `pose` is the main canonical field for how a pet looks. We were missing a few pieces here: 1. After loading a pet, we weren't including the `pose` field in the initial query string for the wardrobe URL, but we _were_ including the `state` field, so the outfit would get set up with a conflicting pet state ID vs pose. 2. When saving an outfit, we weren't taking the `state` field into account at all. This could cause the saved outfit to not quite match how it actually looked in-app, because the default pet state for that species/color/pose trio could be different; and regardless, the outfit state would come back with `appearanceId` set to `null`, which wouldn't match the local outfit state, which would trigger an infinite loop. Here, we complete the round-trip of the `state` field, from pet loading to outfit saving to the outfit data that comes back after saving!
133 lines
3.7 KiB
Ruby
133 lines
3.7 KiB
Ruby
class OutfitsController < ApplicationController
|
|
before_action :find_authorized_outfit, :only => [:update, :destroy]
|
|
|
|
def create
|
|
@outfit = Outfit.new(outfit_params)
|
|
@outfit.user = current_user
|
|
|
|
if @outfit.save
|
|
render :json => @outfit
|
|
else
|
|
render_outfit_errors
|
|
end
|
|
end
|
|
|
|
def edit
|
|
render "outfits/edit", layout: false
|
|
end
|
|
|
|
def index
|
|
if user_signed_in?
|
|
@outfits = current_user.outfits.
|
|
includes(:item_outfit_relationships, {:pet_state => :pet_type}).
|
|
wardrobe_order
|
|
respond_to do |format|
|
|
format.html { render }
|
|
format.json { render :json => @outfits }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
format.html { redirect_to new_auth_user_session_path(:return_to => request.fullpath) }
|
|
format.json { render :json => [] }
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@outfit.destroy
|
|
|
|
respond_to do |format|
|
|
format.html {
|
|
flash[:notice] = t('outfits.destroy.success',
|
|
:outfit_name => @outfit.name)
|
|
redirect_to current_user_outfits_path
|
|
}
|
|
format.json { render :json => true }
|
|
end
|
|
end
|
|
|
|
def new
|
|
@colors = Color.funny.alphabetical
|
|
@species = Species.alphabetical
|
|
|
|
newest_items = Item.newest.
|
|
select(:id, :updated_at, :thumbnail_url, :rarity_index, :is_manually_nc).
|
|
includes(:translations).limit(18)
|
|
@newest_modeled_items, @newest_unmodeled_items =
|
|
newest_items.partition(&:predicted_fully_modeled?)
|
|
|
|
@newest_unmodeled_items_predicted_missing_species_by_color = {}
|
|
@newest_unmodeled_items_predicted_modeled_ratio = {}
|
|
@newest_unmodeled_items.each do |item|
|
|
h = item.predicted_missing_nonstandard_body_ids_by_species_by_color
|
|
standard_body_ids_by_species = item.
|
|
predicted_missing_standard_body_ids_by_species
|
|
if standard_body_ids_by_species.present?
|
|
h[:standard] = standard_body_ids_by_species
|
|
end
|
|
@newest_unmodeled_items_predicted_missing_species_by_color[item] = h
|
|
@newest_unmodeled_items_predicted_modeled_ratio[item] = item.predicted_modeled_ratio
|
|
end
|
|
|
|
@species_count = Species.count
|
|
|
|
@latest_contribution = Contribution.recent.first
|
|
Contribution.preload_contributeds_and_parents([@latest_contribution].compact)
|
|
|
|
@neopets_usernames = user_signed_in? ? current_user.neopets_usernames : []
|
|
|
|
@campaign = Campaign.current rescue nil
|
|
end
|
|
|
|
def show
|
|
@outfit = Outfit.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html { render "outfits/edit", layout: false }
|
|
format.json { render json: @outfit }
|
|
end
|
|
end
|
|
|
|
def start
|
|
# Start URLs are always in English, so let's make sure we search in
|
|
# English.
|
|
I18n.locale = I18n.default_locale
|
|
|
|
@species = Species.find_by_name params[:species_name]
|
|
@color = Color.find_by_name params[:color_name]
|
|
|
|
if @species && @color
|
|
redirect_to wardrobe_path(:species => @species.id, :color => @color.id)
|
|
else
|
|
not_found('species/color')
|
|
end
|
|
end
|
|
|
|
def update
|
|
if @outfit.update(outfit_params)
|
|
render :json => @outfit
|
|
else
|
|
render_outfit_errors
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def outfit_params
|
|
params.require(:outfit).permit(
|
|
:name, :starred, :alt_style_id, item_ids: {worn: [], closeted: []},
|
|
biology: [:species_id, :color_id, :pose, :pet_state_id])
|
|
end
|
|
|
|
def find_authorized_outfit
|
|
raise ActiveRecord::RecordNotFound unless user_signed_in?
|
|
@outfit = current_user.outfits.find(params[:id])
|
|
end
|
|
|
|
def render_outfit_errors
|
|
render :json => {:errors => @outfit.errors,
|
|
:full_error_messages => @outfit.errors.full_messages},
|
|
:status => :bad_request
|
|
end
|
|
end
|
|
|