diff --git a/app/assets/stylesheets/items/_show.sass b/app/assets/stylesheets/items/_show.sass index a2ab33fe..685953af 100644 --- a/app/assets/stylesheets/items/_show.sass +++ b/app/assets/stylesheets/items/_show.sass @@ -40,6 +40,23 @@ body.items-show .preview-area margin: 0 auto + position: relative + + .customize-more + position: absolute + top: 1em + right: 1em + + display: flex + align-items: center + text-decoration: none + + background: #EDF2F7 + padding: .75em + border-radius: .375em + min-height: 2rem + min-width: 2rem + box-sizing: border-box outfit-viewer display: block diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e931b81a..510f1269 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -101,6 +101,12 @@ module ApplicationHelper "matchu@openneo.net" end + EDIT_ICON_SVG_SOURCE = ''.html_safe + def edit_icon(alt: "Edit") + content_tag :svg, EDIT_ICON_SVG_SOURCE, alt:, class: "icon", + viewBox: "0 0 24 24", style: "width: 1em; height: 1em" + end + # SVG icon source from Chakra UI! EXTERNAL_LINK_SVG_SOURCE = ''.html_safe def external_link_icon diff --git a/app/models/outfit.rb b/app/models/outfit.rb index 612964bd..1eafea19 100644 --- a/app/models/outfit.rb +++ b/app/models/outfit.rb @@ -1,9 +1,15 @@ class Outfit < ApplicationRecord has_many :item_outfit_relationships, :dependent => :destroy + has_many :worn_item_outfit_relationships, -> { where(is_worn: true) }, class_name: 'ItemOutfitRelationship' has_many :worn_items, through: :worn_item_outfit_relationships, source: :item + has_many :closeted_item_outfit_relationships, -> { where(is_worn: false) }, + class_name: 'ItemOutfitRelationship' + has_many :closeted_items, through: :closeted_item_outfit_relationships, + source: :item + belongs_to :alt_style, optional: true belongs_to :pet_state, optional: true # We validate presence below! belongs_to :user, optional: true @@ -231,6 +237,18 @@ class Outfit < ApplicationRecord (pet_layers + item_layers).sort_by(&:depth) end + def wardrobe_params + { + name: name, + color: color_id, + species: species_id, + pose: pose, + state: pet_state_id, + objects: worn_item_ids, + closet: closeted_item_ids, + } + end + def ensure_unique_name # If no name was provided, start with "Untitled outfit". self.name = "Untitled outfit" if name.blank? diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 86937525..acd75df9 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -19,6 +19,10 @@ = render partial: "outfit_viewer", locals: {outfit: @preview_outfit} .error-indicator 💥 We couldn't load all of this outfit. Try again? + = link_to wardrobe_path(params: @preview_outfit.wardrobe_params), + class: "customize-more", target: "_blank", + title: "Customize more", "aria-label": "Customize more" do + = edit_icon %species-color-picker = form_for item_path(@item), method: :get, data: {"is-valid": @preview_error.nil?} do |f|