mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-31 11:21:06 -04:00
- Implemented event description logic for finished jobs in EventHelper. - Created a new partial for finished job descriptions. - Updated TimelineService to include finished jobs in event queries. - Enhanced specs for event descriptions and timeline service to cover finished jobs.
153 lines
3.4 KiB
Ruby
153 lines
3.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module IconsHelper
|
|
# A Font Awesome icon: `icon 'fas', 'heart'`, optionally followed by text and
|
|
# HTML options.
|
|
def icon(style, name, text = nil, html_options = {})
|
|
text, html_options = nil, text if text.is_a?(Hash)
|
|
|
|
html_options = html_options.merge(class: ["#{style} fa-#{name}", html_options[:class]].compact.join(' '))
|
|
html_options['aria-hidden'] ||= true
|
|
|
|
html = content_tag(:i, nil, html_options)
|
|
html << ' ' << text.to_s unless text.blank?
|
|
html
|
|
end
|
|
|
|
def icon_for_model(event_model)
|
|
send("#{event_model}_icon")
|
|
end
|
|
|
|
def cute_icon
|
|
icons = %w(slug sprinkler bee ant hose grass rabbit slug-eating snail earth-worm insect watering-can
|
|
wheelbarrow cat spiderweb bug butterfly ladybird stones)
|
|
rand_num = rand(1..icons.size)
|
|
icon = icons[rand_num - 1]
|
|
image_tag("icons/#{icon}.svg", 'aria-hidden' => "true", class: 'img img-cute', alt: icon)
|
|
end
|
|
|
|
def timeline_icon
|
|
image_icon 'timeline'
|
|
end
|
|
|
|
def garden_icon
|
|
image_icon 'gardens'
|
|
end
|
|
|
|
def planting_icon
|
|
image_icon 'planting'
|
|
end
|
|
|
|
def member_icon
|
|
icon('far', 'user')
|
|
end
|
|
|
|
def harvest_icon
|
|
image_icon 'harvest'
|
|
end
|
|
|
|
def growing_icon
|
|
image_icon 'growing'
|
|
end
|
|
|
|
def seed_icon
|
|
image_icon 'seeds'
|
|
end
|
|
|
|
def comment_icon
|
|
icon('far', 'comment')
|
|
end
|
|
|
|
def finished_icon
|
|
image_icon 'finish'
|
|
end
|
|
|
|
def edit_icon
|
|
image_icon 'edit'
|
|
end
|
|
|
|
def delete_icon
|
|
image_icon 'delete'
|
|
end
|
|
|
|
def add_photo_icon
|
|
image_icon 'add-photo'
|
|
end
|
|
|
|
def photo_icon
|
|
image_icon 'photo'
|
|
end
|
|
|
|
def job_icon
|
|
icon('fas', 'note-sticky')
|
|
end
|
|
|
|
def job_finished_icon
|
|
finished_icon
|
|
end
|
|
|
|
def post_icon
|
|
image_icon 'post'
|
|
end
|
|
|
|
def perennial_icon
|
|
icon('fas', 'tree')
|
|
end
|
|
|
|
def delete_association_icon
|
|
icon('fas', 'backspace')
|
|
end
|
|
|
|
def like_icon
|
|
icon('fas', 'heart')
|
|
end
|
|
|
|
def plant_part_icon(name)
|
|
if File.exist? Rails.root.join('app', 'assets', 'images', 'icons', 'plant_parts', "#{name}.svg")
|
|
image_tag "icons/plant_parts/#{name}.svg", class: 'img img-icon', 'aria-hidden' => "true", alt: name
|
|
else
|
|
planting_icon
|
|
end
|
|
end
|
|
|
|
def crop_icon(crop)
|
|
if crop.svg_icon.present?
|
|
image_tag(crop_path(crop, format: 'svg'), class: 'crop-icon', alt: crop)
|
|
elsif crop.parent.present?
|
|
crop_icon(crop.parent)
|
|
else
|
|
planting_icon
|
|
end
|
|
end
|
|
|
|
def sunniness_icon(sunniness)
|
|
case sunniness
|
|
when 'sun'
|
|
icon 'far', 'sun'
|
|
when 'shade'
|
|
icon 'fas', 'umbrella-beach'
|
|
when 'semi-shade'
|
|
icon 'fas', 'cloud-sun'
|
|
else
|
|
icon 'fas', 'question'
|
|
end
|
|
end
|
|
|
|
def image_icon(icon)
|
|
image_tag "icons/#{icon}.svg", class: 'img img-icon', 'aria-hidden' => "true", alt: icon
|
|
end
|
|
|
|
# Line icons for the menu drawer and the action menus: the drawings are in
|
|
# app/javascript/menuIcons.json, shared with the React menus. Green by default
|
|
# (see .menu-icon); a danger item overrides it to match its text.
|
|
MENU_ICONS = JSON.parse(Rails.root.join('app/javascript/menuIcons.json').read).freeze
|
|
|
|
def menu_icon(name)
|
|
# The paths are our own, from menuIcons.json.
|
|
tag.svg(MENU_ICONS.fetch(name.to_s).html_safe, # rubocop:disable Rails/OutputSafety
|
|
class: 'menu-icon', width: 22, height: 22, viewBox: '0 0 24 24', fill: 'none',
|
|
stroke: 'currentColor', 'stroke-width': 1.8, 'stroke-linecap': 'round',
|
|
'stroke-linejoin': 'round', 'aria-hidden': 'true')
|
|
end
|
|
end
|