2010-10-10 19:18:42 -07:00
|
|
|
class OutfitsController < ApplicationController
|
2023-08-02 16:05:02 -07:00
|
|
|
before_action :find_authorized_outfit, :only => [:update, :destroy]
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
def create
|
2023-11-02 13:50:33 -07:00
|
|
|
@outfit = Outfit.new(outfit_params)
|
|
|
|
@outfit.user = current_user
|
|
|
|
|
2011-02-10 14:50:47 -08:00
|
|
|
if @outfit.save
|
2012-07-17 09:15:04 -07:00
|
|
|
render :json => @outfit
|
2010-11-10 13:59:54 -08:00
|
|
|
else
|
2011-02-10 14:50:47 -08:00
|
|
|
render_outfit_errors
|
2010-11-10 13:59:54 -08:00
|
|
|
end
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2023-08-10 18:19:03 -07:00
|
|
|
def edit
|
|
|
|
render "outfits/edit", layout: false
|
|
|
|
end
|
|
|
|
|
2011-03-23 15:23:01 -07:00
|
|
|
def index
|
|
|
|
if user_signed_in?
|
2012-08-09 15:32:33 -07:00
|
|
|
@outfits = current_user.outfits.
|
|
|
|
includes(:item_outfit_relationships, {:pet_state => :pet_type}).
|
|
|
|
wardrobe_order
|
2011-03-23 15:23:01 -07:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render }
|
|
|
|
format.json { render :json => @outfits }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
2023-08-06 15:52:05 -07:00
|
|
|
format.html { redirect_to new_auth_user_session_path(:return_to => request.fullpath) }
|
2011-03-23 15:23:01 -07:00
|
|
|
format.json { render :json => [] }
|
|
|
|
end
|
|
|
|
end
|
2010-11-11 10:43:22 -08:00
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
def destroy
|
2013-01-03 17:32:17 -08:00
|
|
|
@outfit.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
2023-08-06 17:33:57 -07:00
|
|
|
flash[:notice] = t('outfits.destroy.success',
|
2013-01-03 17:32:17 -08:00
|
|
|
:outfit_name => @outfit.name)
|
|
|
|
redirect_to current_user_outfits_path
|
|
|
|
}
|
|
|
|
format.json { render :json => true }
|
2010-11-24 17:51:01 -08:00
|
|
|
end
|
2010-11-11 10:43:22 -08:00
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-05 15:45:05 -07:00
|
|
|
def new
|
2023-10-12 22:30:16 -07:00
|
|
|
@colors = Color.funny.alphabetical
|
|
|
|
@species = Species.alphabetical
|
2012-08-01 10:34:54 -07:00
|
|
|
|
2023-11-03 16:27:39 -07:00
|
|
|
newest_items = Item.newest.
|
2024-02-20 15:36:20 -08:00
|
|
|
select(:id, :name, :updated_at, :thumbnail_url, :rarity_index, :is_manually_nc).
|
2023-08-02 12:02:19 -07:00
|
|
|
includes(:translations).limit(18)
|
|
|
|
@newest_modeled_items, @newest_unmodeled_items =
|
|
|
|
newest_items.partition(&:predicted_fully_modeled?)
|
2013-12-14 15:19:27 -08:00
|
|
|
|
2023-08-02 12:02:19 -07:00
|
|
|
@newest_unmodeled_items_predicted_missing_species_by_color = {}
|
|
|
|
@newest_unmodeled_items_predicted_modeled_ratio = {}
|
|
|
|
@newest_unmodeled_items.each do |item|
|
2024-01-23 05:23:57 -08:00
|
|
|
h = item.predicted_missing_nonstandard_body_ids_by_species_by_color
|
2023-08-02 12:02:19 -07:00
|
|
|
standard_body_ids_by_species = item.
|
2024-01-23 05:23:57 -08:00
|
|
|
predicted_missing_standard_body_ids_by_species
|
2023-08-02 12:02:19 -07:00
|
|
|
if standard_body_ids_by_species.present?
|
|
|
|
h[:standard] = standard_body_ids_by_species
|
2013-12-14 15:19:27 -08:00
|
|
|
end
|
2023-08-02 12:02:19 -07:00
|
|
|
@newest_unmodeled_items_predicted_missing_species_by_color[item] = h
|
|
|
|
@newest_unmodeled_items_predicted_modeled_ratio[item] = item.predicted_modeled_ratio
|
2012-08-09 19:35:30 -07:00
|
|
|
end
|
2023-08-02 12:02:19 -07:00
|
|
|
|
|
|
|
@species_count = Species.count
|
2012-08-09 19:35:30 -07:00
|
|
|
|
2023-08-02 12:04:09 -07:00
|
|
|
@latest_contribution = Contribution.recent.first
|
|
|
|
Contribution.preload_contributeds_and_parents([@latest_contribution].compact)
|
2014-01-17 09:12:56 -08:00
|
|
|
|
|
|
|
@neopets_usernames = user_signed_in? ? current_user.neopets_usernames : []
|
2014-09-11 16:09:00 -07:00
|
|
|
|
2024-02-18 20:29:31 -08:00
|
|
|
@campaign = Fundraising::Campaign.current rescue nil
|
2010-11-05 15:45:05 -07:00
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-12 17:58:28 -08:00
|
|
|
def show
|
2010-11-13 14:26:14 -08:00
|
|
|
@outfit = Outfit.find(params[:id])
|
2023-11-02 13:50:33 -07:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render "outfits/edit", layout: false }
|
|
|
|
format.json { render json: @outfit }
|
|
|
|
end
|
2010-11-12 17:58:28 -08:00
|
|
|
end
|
2012-06-05 09:44:11 -07:00
|
|
|
|
|
|
|
def start
|
2013-01-21 14:01:41 -08:00
|
|
|
# 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]
|
2013-01-21 12:55:48 -08:00
|
|
|
|
2012-06-05 09:44:11 -07:00
|
|
|
if @species && @color
|
|
|
|
redirect_to wardrobe_path(:species => @species.id, :color => @color.id)
|
|
|
|
else
|
|
|
|
not_found('species/color')
|
|
|
|
end
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
def update
|
2023-11-02 13:50:33 -07:00
|
|
|
if @outfit.update(outfit_params)
|
2012-07-26 20:47:22 -07:00
|
|
|
render :json => @outfit
|
2010-11-11 10:43:22 -08:00
|
|
|
else
|
2010-11-24 17:51:01 -08:00
|
|
|
render_outfit_errors
|
2010-11-11 10:43:22 -08:00
|
|
|
end
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
private
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2023-07-29 10:52:23 -07:00
|
|
|
def outfit_params
|
|
|
|
params.require(:outfit).permit(
|
2024-02-01 05:55:19 -08:00
|
|
|
:name, :starred, :alt_style_id, item_ids: {worn: [], closeted: []},
|
Oops, fix bug with saving outfits of pets loaded from Neopets.com
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!
2024-02-08 09:51:31 -08:00
|
|
|
biology: [:species_id, :color_id, :pose, :pet_state_id])
|
2023-07-29 10:52:23 -07:00
|
|
|
end
|
|
|
|
|
2010-11-13 14:26:14 -08:00
|
|
|
def find_authorized_outfit
|
2010-11-12 17:58:28 -08:00
|
|
|
raise ActiveRecord::RecordNotFound unless user_signed_in?
|
|
|
|
@outfit = current_user.outfits.find(params[:id])
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-24 17:51:01 -08:00
|
|
|
def render_outfit_errors
|
2013-01-04 18:08:41 -08:00
|
|
|
render :json => {:errors => @outfit.errors,
|
|
|
|
:full_error_messages => @outfit.errors.full_messages},
|
|
|
|
:status => :bad_request
|
2010-11-24 17:51:01 -08:00
|
|
|
end
|
2010-10-10 19:18:42 -07:00
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|