diff --git a/app/assets/stylesheets/application/support-form.sass b/app/assets/stylesheets/application/support-form.sass index 0db2bd0e..d0e0b994 100644 --- a/app/assets/stylesheets/application/support-form.sass +++ b/app/assets/stylesheets/application/support-form.sass @@ -19,8 +19,10 @@ input[type=url] font-size: .85em - label + > label, .field-name font-weight: bold + &:has(+ .radio-field) + align-self: start .thumbnail-field display: flex @@ -34,6 +36,11 @@ input flex: 1 0 20ch + .radio-field + display: flex + flex-direction: column + gap: .25em + .field_with_errors display: contents diff --git a/app/assets/stylesheets/partials/_item_header.sass b/app/assets/stylesheets/partials/_item_header.sass index 93901115..c56d9647 100644 --- a/app/assets/stylesheets/partials/_item_header.sass +++ b/app/assets/stylesheets/partials/_item_header.sass @@ -67,14 +67,21 @@ background: #FEEBC8 color: #7B341E + .support-form + grid-area: support + font-size: 85% + text-align: left + .user-lists-info grid-area: lists font-size: 85% text-align: left - .user-lists-form-opener - &::after - content: " ›" + display: flex + gap: 1em + + a::after + content: " ›" .user-lists-form background: $background-color diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index fe390949..9689d3d8 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,5 +1,6 @@ class ItemsController < ApplicationController before_action :set_query + before_action :support_staff_only, except: [:index, :show, :sources] rescue_from Item::Search::Error, :with => :search_error def index @@ -112,6 +113,21 @@ class ItemsController < ApplicationController end end + def edit + @item = Item.find params[:id] + render layout: "application" + end + + def update + @item = Item.find params[:id] + if @item.update(item_params) + flash[:notice] = "\"#{@item.name}\" successfully saved!" + redirect_to @item + else + render action: "edit", layout: "application" + end + end + def sources # Load all the items, then group them by source. item_ids = params[:ids].split(",") @@ -164,6 +180,14 @@ class ItemsController < ApplicationController protected + def item_params + params.require(:item).permit( + :name, :thumbnail_url, :description, :modeling_status_hint + ).tap do |p| + p[:modeling_status_hint] = nil if p[:modeling_status_hint] == "" + end + end + def assign_closeted!(items) current_user.assign_closeted_to_items!(items) if user_signed_in? end diff --git a/app/views/items/_item_header.html.haml b/app/views/items/_item_header.html.haml index 39b6de91..f9bdb1d8 100644 --- a/app/views/items/_item_header.html.haml +++ b/app/views/items/_item_header.html.haml @@ -46,6 +46,8 @@ = link_to t('items.show.closet_hangers.button'), user_closet_hangers_path(current_user), class: 'user-lists-form-opener' + - if support_staff? + = link_to "Edit", edit_item_path(item) - if user_signed_in? = form_tag update_quantities_user_item_closet_hangers_path(user_id: current_user, item_id: item), method: :put, class: 'user-lists-form', hidden: item_header_user_lists_form_state != "open" do diff --git a/app/views/items/edit.html.haml b/app/views/items/edit.html.haml new file mode 100644 index 00000000..2220876b --- /dev/null +++ b/app/views/items/edit.html.haml @@ -0,0 +1,43 @@ +- title "Editing \"#{@item.name}\"" +- use_responsive_design + +%h1#title Editing "#{@item.name}" + +:markdown + Heads up: the modeling process controls many of these fields by default! If + you change something, but it doesn't match what we're seeing on Neopets.com, + it will probably be reverted automatically when someone models it. + += form_with model: @item, class: "support-form" do |f| + - if @item.errors.any? + %p + Could not save: + %ul.errors + - @item.errors.each do |error| + %li= error.full_message + %fieldset + = f.label :name + = f.text_field :name + = f.label :thumbnail_url, "Thumbnail" + .thumbnail-field + - if @item.thumbnail_url? + = image_tag @item.thumbnail_url + = f.url_field :thumbnail_url + = f.label :description + = f.text_field :description + .field-name Modeling status + .radio-field + %label{title: "If we fit two or more species of a standard color, assume we also fit the other standard-color pets that were released at the time.\nRepeat for special colors like Baby and Maraquan."} + = f.radio_button :modeling_status_hint, "" + Automatic: Fits 2+ species → Should fit all + %label{title: "Use this when e.g. there simply is no Acara version of the item."} + = f.radio_button :modeling_status_hint, "done" + Done: Neopets.com is missing some models + %label{title: "Use this when e.g. this fits the Blue Vandagyre even though it's a Maraquan item.\nBehaves identically to Done, but helps us remember why we did this!"} + = f.radio_button :modeling_status_hint, "glitchy" + Glitchy: Neopets.com has too many models + .actions + = f.submit "Save changes" + +- content_for :stylesheets do + = page_stylesheet_link_tag "application/support-form" diff --git a/config/routes.rb b/config/routes.rb index c1a14f0b..1cbebdec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,7 @@ OpenneoImpressItems::Application.routes.draw do get '/users/current-user/outfits', to: redirect('/your-outfits') # Our customization data! Both the item pages, and JSON API endpoints. - resources :items, :only => [:index, :show] do + resources :items, only: [:index, :show, :edit, :update] do resources :trades, path: 'trades/:type', controller: 'item_trades', only: [:index], constraints: {type: /offering|seeking/}