From 9f44fd47e4d3ca5a13aaf4ddbe58d780eb16b805 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 3 Sep 2024 17:27:43 -0700 Subject: [PATCH] Add "No data yet" to species face tooltip when needed, in item previews --- app/helpers/items_helper.rb | 23 +++++++++++++++-------- app/models/item.rb | 2 +- app/views/items/show.html.haml | 8 +++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 186c6554..7e8c0ea2 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -33,7 +33,9 @@ module ItemsHelper def standard_species_search_links all_species = Species.alphabetical.map(&:id) PetType.random_basic_per_species(all_species).map do |pet_type| - image = pet_type_image(pet_type, :happy, :zoom) + human_name = pet_type.species.human_name + image = pet_type_image pet_type, :happy, :zoom, + alt: human_name, title: human_name query = "species:#{pet_type.species.name}" link_to(image, items_path(:q => query)) end.join.html_safe @@ -222,8 +224,16 @@ module ItemsHelper cookies["DTIOutfitViewerIsPlaying"] == "true" end - def item_fits?(pet_type, all_appearances) - all_appearances.any? { |a| a.fits? pet_type } + def item_fits?(item, pet_type) + item.appearances.any? { |a| a.fits? pet_type } + end + + def species_face_tooltip(pet_type, item) + if item_fits?(item, pet_type) + "#{pet_type.species.human_name}" + else + "#{pet_type.species.human_name}: No data yet" + end end def item_zone_partial_fit?(appearances_in_zone, all_appearances) @@ -234,12 +244,9 @@ module ItemsHelper appearances_in_zone.map(&:species).uniq.map(&:human_name).sort.join(", ") end - private - - def pet_type_image(pet_type, emotion, size) + def pet_type_image(pet_type, emotion, size, **options) src = pet_type_image_url(pet_type, emotion:, size:) - human_name = pet_type.species.name.humanize - image_tag(src, :alt => human_name, :title => human_name) + image_tag(src, **options) end def item_header_user_lists_form_state diff --git a/app/models/item.rb b/app/models/item.rb index 21232069..100f4bc3 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -502,7 +502,7 @@ class Item < ApplicationRecord Appearance = Struct.new(:item, :body, :swf_assets) do include ActiveModel::Serializers::JSON delegate :present?, :empty?, to: :swf_assets - delegate :species, :fits?, to: :body + delegate :species, :fits?, :fits_all?, to: :body def attributes {item:, body:, swf_assets:} diff --git a/app/views/items/show.html.haml b/app/views/items/show.html.haml index 0c80a79c..2326289b 100644 --- a/app/views/items/show.html.haml +++ b/app/views/items/show.html.haml @@ -42,12 +42,14 @@ "aria-hidden": true, # waits for JS to remove } - @preview_pet_type_options.each do |pet_type| - %label + %label{ + title: species_face_tooltip(pet_type, @item), + } = radio_button_tag "species_face_id", pet_type.species_id, checked: pet_type == @preview_outfit.pet_type, - disabled: !item_fits?(pet_type, @all_appearances) + disabled: !item_fits?(@item, pet_type) = pet_type_image pet_type, - item_fits?(pet_type, @all_appearances) ? :happy : :sad, + item_fits?(@item, pet_type) ? :happy : :sad, :face .item-zones-info