From d5a901b917f58659aa95c82b8c16b319b5b0f8a4 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 27 Sep 2024 22:14:00 -0700 Subject: [PATCH] Add edit form to Rainbow Pool for pet states, for support staff only --- .../stylesheets/application/breadcrumbs.sass | 11 +++-- app/assets/stylesheets/pet_states/show.sass | 3 -- app/assets/stylesheets/pet_types/show.sass | 3 -- app/controllers/application_controller.rb | 6 +++ app/controllers/pet_states_controller.rb | 24 +++++++++++ app/helpers/pet_states_helper.rb | 8 +++- app/models/pet_state.rb | 32 ++++++++++++++ app/views/pet_states/edit.html.haml | 42 +++++++++++++++++++ app/views/pet_states/show.html.haml | 11 +++-- app/views/pet_types/index.html.haml | 2 +- app/views/pet_types/show.html.haml | 4 +- config/routes.rb | 2 +- 12 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 app/views/pet_states/edit.html.haml diff --git a/app/assets/stylesheets/application/breadcrumbs.sass b/app/assets/stylesheets/application/breadcrumbs.sass index 92af0781..611d0db0 100644 --- a/app/assets/stylesheets/application/breadcrumbs.sass +++ b/app/assets/stylesheets/application/breadcrumbs.sass @@ -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: "-" diff --git a/app/assets/stylesheets/pet_states/show.sass b/app/assets/stylesheets/pet_states/show.sass index 9e0d56a0..8e19d73c 100644 --- a/app/assets/stylesheets/pet_states/show.sass +++ b/app/assets/stylesheets/pet_states/show.sass @@ -1,6 +1,3 @@ -#title - margin-bottom: .125em - outfit-viewer margin: 0 auto diff --git a/app/assets/stylesheets/pet_types/show.sass b/app/assets/stylesheets/pet_types/show.sass index 8782fd3a..60a72514 100644 --- a/app/assets/stylesheets/pet_types/show.sass +++ b/app/assets/stylesheets/pet_types/show.sass @@ -1,8 +1,5 @@ @import "../partials/clean/constants" -#title - margin-bottom: .125em - .pet-states list-style-type: none display: flex diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 15a8cc99..82a2429e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/pet_states_controller.rb b/app/controllers/pet_states_controller.rb index 410de3c3..32bead88 100644 --- a/app/controllers/pet_states_controller.rb +++ b/app/controllers/pet_states_controller.rb @@ -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 diff --git a/app/helpers/pet_states_helper.rb b/app/helpers/pet_states_helper.rb index c06be602..67ea71b6 100644 --- a/app/helpers/pet_states_helper.rb +++ b/app/helpers/pet_states_helper.rb @@ -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 diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index 392270d9..8e86b50d 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -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 diff --git a/app/views/pet_states/edit.html.haml b/app/views/pet_states/edit.html.haml new file mode 100644 index 00000000..17226f11 --- /dev/null +++ b/app/views/pet_states/edit.html.haml @@ -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" diff --git a/app/views/pet_states/show.html.haml b/app/views/pet_states/show.html.haml index a073c0ff..8958e3ee 100644 --- a/app/views/pet_states/show.html.haml +++ b/app/views/pet_states/show.html.haml @@ -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 diff --git a/app/views/pet_types/index.html.haml b/app/views/pet_types/index.html.haml index 8d4e1c8f..623fdb60 100644 --- a/app/views/pet_types/index.html.haml +++ b/app/views/pet_types/index.html.haml @@ -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" diff --git a/app/views/pet_types/show.html.haml b/app/views/pet_types/show.html.haml index 18516ce4..f0b523bf 100644 --- a/app/views/pet_types/show.html.haml +++ b/app/views/pet_types/show.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index fbabef2d..9c6e8c3a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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!