Add edit form to Rainbow Pool for pet states, for support staff only
This commit is contained in:
parent
39e5ca59c4
commit
d5a901b917
12 changed files with 130 additions and 18 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
#title:has(+ .breadcrumbs)
|
||||||
|
margin-bottom: .125em
|
||||||
|
|
||||||
.breadcrumbs
|
.breadcrumbs
|
||||||
list-style-type: none
|
list-style-type: none
|
||||||
display: flex
|
display: flex
|
||||||
|
@ -13,6 +16,8 @@
|
||||||
margin-inline: .35em
|
margin-inline: .35em
|
||||||
content: "→"
|
content: "→"
|
||||||
|
|
||||||
&[data-joined-with-prev]
|
&[data-relation-to-prev=sibling]::before
|
||||||
&::before
|
content: "+"
|
||||||
content: "+"
|
|
||||||
|
&[data-relation-to-prev=menu]::before
|
||||||
|
content: "-"
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#title
|
|
||||||
margin-bottom: .125em
|
|
||||||
|
|
||||||
outfit-viewer
|
outfit-viewer
|
||||||
margin: 0 auto
|
margin: 0 auto
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
@import "../partials/clean/constants"
|
@import "../partials/clean/constants"
|
||||||
|
|
||||||
#title
|
|
||||||
margin-bottom: .125em
|
|
||||||
|
|
||||||
.pet-states
|
.pet-states
|
||||||
list-style-type: none
|
list-style-type: none
|
||||||
display: flex
|
display: flex
|
||||||
|
|
|
@ -110,5 +110,11 @@ class ApplicationController < ActionController::Base
|
||||||
Rails.logger.debug "Using return_to path: #{return_to.inspect}"
|
Rails.logger.debug "Using return_to path: #{return_to.inspect}"
|
||||||
return_to || root_path
|
return_to || root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def support_staff_only
|
||||||
|
unless current_user&.support_staff?
|
||||||
|
raise AccessDenied, "Support staff only"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,30 @@
|
||||||
class PetStatesController < ApplicationController
|
class PetStatesController < ApplicationController
|
||||||
|
before_action :find_pet_state
|
||||||
|
before_action :support_staff_only, except: [:show]
|
||||||
|
|
||||||
def 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_type = PetType.matching_name_param(params[:pet_type_name]).first!
|
||||||
@pet_state = @pet_type.pet_states.find(params[:id])
|
@pet_state = @pet_type.pet_states.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pet_state_params
|
||||||
|
params.require(:pet_state).permit(:pose, :glitched)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,13 @@ module PetStatesHelper
|
||||||
when "UNCONVERTED"
|
when "UNCONVERTED"
|
||||||
"Unconverted"
|
"Unconverted"
|
||||||
else
|
else
|
||||||
"(Unknown)"
|
"Not labeled yet"
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -71,6 +71,28 @@ class PetState < ApplicationRecord
|
||||||
end
|
end
|
||||||
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)
|
def reassign_children_to!(main_pet_state)
|
||||||
self.contributions.each do |contribution|
|
self.contributions.each do |contribution|
|
||||||
contribution.contributed = main_pet_state
|
contribution.contributed = main_pet_state
|
||||||
|
@ -175,5 +197,15 @@ class PetState < ApplicationRecord
|
||||||
pet_state.parent_swf_asset_relationships_to_update = relationships
|
pet_state.parent_swf_asset_relationships_to_update = relationships
|
||||||
pet_state
|
pet_state
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
42
app/views/pet_states/edit.html.haml
Normal file
42
app/views/pet_states/edit.html.haml
Normal 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"
|
|
@ -7,13 +7,16 @@
|
||||||
%li
|
%li
|
||||||
= link_to @pet_type.color.human_name,
|
= link_to @pet_type.color.human_name,
|
||||||
pet_types_path(color: @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,
|
= link_to @pet_type.species.human_name,
|
||||||
pet_types_path(species: @pet_type.species.human_name)
|
pet_types_path(species: @pet_type.species.human_name)
|
||||||
%li
|
%li
|
||||||
= link_to "Forms", @pet_type
|
= link_to "Appearances", @pet_type
|
||||||
%li
|
%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
|
= outfit_viewer pet_state: @pet_state
|
||||||
|
|
||||||
|
@ -45,7 +48,7 @@
|
||||||
= stylesheet_link_tag "application/breadcrumbs"
|
= stylesheet_link_tag "application/breadcrumbs"
|
||||||
= stylesheet_link_tag "application/hanger-spinner"
|
= stylesheet_link_tag "application/hanger-spinner"
|
||||||
= stylesheet_link_tag "application/outfit-viewer"
|
= stylesheet_link_tag "application/outfit-viewer"
|
||||||
= stylesheet_link_tag "pet_states/show"
|
= page_stylesheet_link_tag "pet_states/show"
|
||||||
|
|
||||||
- content_for :javascripts do
|
- content_for :javascripts do
|
||||||
= javascript_include_tag "outfit-viewer", async: true
|
= javascript_include_tag "outfit-viewer", async: true
|
||||||
|
|
|
@ -15,4 +15,4 @@
|
||||||
= will_paginate @pet_types
|
= will_paginate @pet_types
|
||||||
|
|
||||||
- content_for :stylesheets do
|
- content_for :stylesheets do
|
||||||
= stylesheet_link_tag "pet_types/index"
|
= page_stylesheet_link_tag "pet_types/index"
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
= link_to @pet_type.species.human_name,
|
= link_to @pet_type.species.human_name,
|
||||||
pet_types_path(species: @pet_type.species.human_name)
|
pet_types_path(species: @pet_type.species.human_name)
|
||||||
%li
|
%li
|
||||||
Forms
|
Appearances
|
||||||
|
|
||||||
%ul.pet-states
|
%ul.pet-states
|
||||||
= render @pet_states[:canonical]
|
= render @pet_states[:canonical]
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
= stylesheet_link_tag "application/breadcrumbs"
|
= stylesheet_link_tag "application/breadcrumbs"
|
||||||
= stylesheet_link_tag "application/hanger-spinner"
|
= stylesheet_link_tag "application/hanger-spinner"
|
||||||
= stylesheet_link_tag "application/outfit-viewer"
|
= stylesheet_link_tag "application/outfit-viewer"
|
||||||
= stylesheet_link_tag "pet_types/show"
|
= page_stylesheet_link_tag "pet_types/show"
|
||||||
|
|
||||||
- content_for :javascripts do
|
- content_for :javascripts do
|
||||||
= javascript_include_tag "outfit-viewer", async: true
|
= javascript_include_tag "outfit-viewer", async: true
|
||||||
|
|
|
@ -39,7 +39,7 @@ OpenneoImpressItems::Application.routes.draw do
|
||||||
resources :swf_assets, path: 'swf-assets', only: [:show]
|
resources :swf_assets, path: 'swf-assets', only: [:show]
|
||||||
resources :pet_types, path: 'rainbow-pool', param: "name",
|
resources :pet_types, path: 'rainbow-pool', param: "name",
|
||||||
only: [:index, :show] do
|
only: [:index, :show] do
|
||||||
resources :pet_states, only: [:show], path: "forms"
|
resources :pet_states, only: [:show, :edit, :update], path: "appearances"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Loading and modeling pets!
|
# Loading and modeling pets!
|
||||||
|
|
Loading…
Reference in a new issue