Add edit form to Rainbow Pool for pet states, for support staff only

This commit is contained in:
Emi Matchu 2024-09-27 22:14:00 -07:00
parent 39e5ca59c4
commit d5a901b917
12 changed files with 130 additions and 18 deletions

View file

@ -1,3 +1,6 @@
#title:has(+ .breadcrumbs)
margin-bottom: .125em
.breadcrumbs
list-style-type: none
display: flex
@ -13,6 +16,8 @@
margin-inline: .35em
content: ""
&[data-joined-with-prev]
&::before
content: "+"
&[data-relation-to-prev=sibling]::before
content: "+"
&[data-relation-to-prev=menu]::before
content: "-"

View file

@ -1,6 +1,3 @@
#title
margin-bottom: .125em
outfit-viewer
margin: 0 auto

View file

@ -1,8 +1,5 @@
@import "../partials/clean/constants"
#title
margin-bottom: .125em
.pet-states
list-style-type: none
display: flex

View file

@ -110,5 +110,11 @@ class ApplicationController < ActionController::Base
Rails.logger.debug "Using return_to path: #{return_to.inspect}"
return_to || root_path
end
def support_staff_only
unless current_user&.support_staff?
raise AccessDenied, "Support staff only"
end
end
end

View file

@ -1,6 +1,30 @@
class PetStatesController < ApplicationController
before_action :find_pet_state
before_action :support_staff_only, except: [:show]
def show
end
def edit
end
def update
if @pet_state.update(pet_state_params)
flash[:notice] = "Pet appearance \##{@pet_state.id} successfully saved!"
redirect_to @pet_type
else
render action: :edit, status: :bad_request
end
end
protected
def find_pet_state
@pet_type = PetType.matching_name_param(params[:pet_type_name]).first!
@pet_state = @pet_type.pet_states.find(params[:id])
end
def pet_state_params
params.require(:pet_state).permit(:pose, :glitched)
end
end

View file

@ -16,7 +16,13 @@ module PetStatesHelper
when "UNCONVERTED"
"Unconverted"
else
"(Unknown)"
"Not labeled yet"
end
end
POSE_OPTIONS = %w(UNKNOWN HAPPY_FEM HAPPY_MASC SAD_FEM SAD_MASC SICK_FEM
SICK_MASC UNCONVERTED)
def pose_options
POSE_OPTIONS.map { |p| [pose_name(p), p] }
end
end

View file

@ -71,6 +71,28 @@ class PetState < ApplicationRecord
end
end
# TODO: More and more, wanting to refactor poses…
def pose=(pose)
case pose
when "UNKNOWN"
label_pose nil, nil, unconverted: nil, labeled: false
when "HAPPY_MASC"
label_pose 1, false
when "HAPPY_FEM"
label_pose 1, true
when "SAD_MASC"
label_pose 2, false
when "SAD_FEM"
label_pose 2, true
when "SICK_MASC"
label_pose 4, false
when "SICK_FEM"
label_pose 4, true
when "UNCONVERTED"
label_pose nil, nil, unconverted: true
end
end
def reassign_children_to!(main_pet_state)
self.contributions.each do |contribution|
contribution.contributed = main_pet_state
@ -175,5 +197,15 @@ class PetState < ApplicationRecord
pet_state.parent_swf_asset_relationships_to_update = relationships
pet_state
end
private
# A helper for the `pose=` method.
def label_pose(mood_id, female, unconverted: false, labeled: true)
self.labeled = labeled
self.mood_id = mood_id
self.female = female
self.unconverted = unconverted
end
end

View file

@ -0,0 +1,42 @@
- title "#{@pet_type.human_name}: #{pose_name @pet_state.pose}"
- use_responsive_design
%ol.breadcrumbs
%li
= link_to "Rainbow Pool", pet_types_path
%li
= link_to @pet_type.color.human_name,
pet_types_path(color: @pet_type.color.human_name)
%li{"data-relation-to-prev": "sibling"}
= link_to @pet_type.species.human_name,
pet_types_path(species: @pet_type.species.human_name)
%li
= link_to "Appearances", @pet_type
%li
= link_to "\##{@pet_state.id}", [@pet_type, @pet_state]
%li
Edit
= outfit_viewer pet_state: @pet_state
= form_with model: [@pet_type, @pet_state] do |f|
- if @pet_state.errors.any?
%p
Could not save:
%ul.errors
- @pet_state.errors.each do |error|
%li= error.full_message
%dl
%dt= f.label :pose
%dd= f.select :pose, pose_options
%dt= f.label :glitched, "Glitched?"
%dd= f.select :glitched, [["✅ Not marked as Glitched", false],
["👾 Yes, it's bad news bonko'd", true]]
= f.submit "Save"
- content_for :stylesheets do
= stylesheet_link_tag "application/breadcrumbs"
= stylesheet_link_tag "application/outfit-viewer"
- content_for :javascripts do
= javascript_include_tag "outfit-viewer"

View file

@ -7,13 +7,16 @@
%li
= link_to @pet_type.color.human_name,
pet_types_path(color: @pet_type.color.human_name)
%li{"data-joined-with-prev": true}
%li{"data-relation-to-prev": "sibling"}
= link_to @pet_type.species.human_name,
pet_types_path(species: @pet_type.species.human_name)
%li
= link_to "Forms", @pet_type
= link_to "Appearances", @pet_type
%li
Form ##{@pet_state.id}
\##{@pet_state.id}
- if support_staff?
%li{"data-relation-to-prev": "menu"}
= link_to "Edit", edit_pet_type_pet_state_path(@pet_type, @pet_state)
= outfit_viewer pet_state: @pet_state
@ -45,7 +48,7 @@
= stylesheet_link_tag "application/breadcrumbs"
= stylesheet_link_tag "application/hanger-spinner"
= stylesheet_link_tag "application/outfit-viewer"
= stylesheet_link_tag "pet_states/show"
= page_stylesheet_link_tag "pet_states/show"
- content_for :javascripts do
= javascript_include_tag "outfit-viewer", async: true

View file

@ -15,4 +15,4 @@
= will_paginate @pet_types
- content_for :stylesheets do
= stylesheet_link_tag "pet_types/index"
= page_stylesheet_link_tag "pet_types/index"

View file

@ -11,7 +11,7 @@
= link_to @pet_type.species.human_name,
pet_types_path(species: @pet_type.species.human_name)
%li
Forms
Appearances
%ul.pet-states
= render @pet_states[:canonical]
@ -26,7 +26,7 @@
= stylesheet_link_tag "application/breadcrumbs"
= stylesheet_link_tag "application/hanger-spinner"
= stylesheet_link_tag "application/outfit-viewer"
= stylesheet_link_tag "pet_types/show"
= page_stylesheet_link_tag "pet_types/show"
- content_for :javascripts do
= javascript_include_tag "outfit-viewer", async: true

View file

@ -39,7 +39,7 @@ OpenneoImpressItems::Application.routes.draw do
resources :swf_assets, path: 'swf-assets', only: [:show]
resources :pet_types, path: 'rainbow-pool', param: "name",
only: [:index, :show] do
resources :pet_states, only: [:show], path: "forms"
resources :pet_states, only: [:show, :edit, :update], path: "appearances"
end
# Loading and modeling pets!