diff --git a/app/controllers/pet_states_controller.rb b/app/controllers/pet_states_controller.rb index 090640ac1..bc9aed56d 100644 --- a/app/controllers/pet_states_controller.rb +++ b/app/controllers/pet_states_controller.rb @@ -8,7 +8,7 @@ class PetStatesController < ApplicationController def update if @pet_state.update(pet_state_params) flash[:notice] = "Pet appearance \##{@pet_state.id} successfully saved!" - redirect_to @pet_type + redirect_to destination_after_save else render action: :edit, status: :bad_request end @@ -24,4 +24,29 @@ class PetStatesController < ApplicationController def pet_state_params params.require(:pet_state).permit(:pose, :glitched) end + + def destination_after_save + if params[:next] == "unlabeled-appearance" + next_unlabeled_appearance_path + else + @pet_type + end + end + + def next_unlabeled_appearance_path + # Rather than just getting the newest unlabeled pet state, prioritize the + # newest *pet type*. This better matches the user's perception of what the + # newest state is, because the Rainbow Pool UI is grouped by pet type! + unlabeled_appearance = PetState.unlabeled.newest_pet_type.newest.first + + if unlabeled_appearance + edit_pet_type_pet_state_path( + unlabeled_appearance.pet_type, + unlabeled_appearance, + next: "unlabeled-appearance" + ) + else + @pet_type + end + end end diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index f3e33f9f0..2a5ce1dfd 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -17,6 +17,10 @@ class PetState < ApplicationRecord alias_method :swf_asset_ids_from_association, :swf_asset_ids + scope :newest, -> { order(created_at: :desc) } + scope :newest_pet_type, -> { joins(:pet_type).merge(PetType.newest) } + scope :unlabeled, -> { with_pose("UNKNOWN") } + # A simple ordering that tries to bring reliable pet states to the front. scope :emotion_order, -> { order(Arel.sql( diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 29a5611c6..3c6dda412 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -15,6 +15,7 @@ class PetType < ApplicationRecord species = Species.find_by_name!(species_name) where(color_id: color.id, species_id: species.id) } + scope :newest, -> { order(created_at: :desc) } scope :preferring_species, ->(species_id) { joins(:species).order([Arel.sql("species_id = ? DESC"), species_id]) } diff --git a/app/views/pet_states/edit.html.haml b/app/views/pet_states/edit.html.haml index 9bc61b3f3..9a407baed 100644 --- a/app/views/pet_states/edit.html.haml +++ b/app/views/pet_states/edit.html.haml @@ -34,6 +34,9 @@ = f.actions do = f.submit "Save changes" + = f.go_to_next_field title: "If checked, takes you to the first unlabeled appearance in the database, if any. Useful for labeling in bulk!" do + = f.go_to_next_check_box "unlabeled-appearance" + Then: Go to unlabeled appearance - content_for :stylesheets do = stylesheet_link_tag "application/breadcrumbs"