Module: MyProjectsHelper
- Defined in:
- app/helpers/my_projects_helper.rb
Overview
View helper: my projects.
Instance Method Summary collapse
- #class_for_zip(country_iso3) ⇒ Object
- #project_filter_links ⇒ Object
- #project_link_helper ⇒ Object
- #room_cart_helper(room) ⇒ Object
- #setup_project(project) ⇒ Object
- #shorten_name(name, max = 40) ⇒ Object
Instance Method Details
#class_for_zip(country_iso3) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/helpers/my_projects_helper.rb', line 37 def class_for_zip(country_iso3) case country_iso3 when 'USA' 'zip_code' else 'canadian_postal_code' end end |
#project_filter_links ⇒ Object
52 53 54 55 56 57 |
# File 'app/helpers/my_projects_helper.rb', line 52 def project_filter_links content_tag(:p, link_to("Active (#{@all_projects.open_opportunities.size})", my_account_projects_path(view: 'active'), class: ('link-underline' if (params[:view] == 'active') || params[:view].nil?).to_s)) + content_tag(:p, link_to("Purchased (#{@all_projects.won.size})", my_account_projects_path(view: 'purchased'), class: ('link-underline' if params[:view] == 'purchased').to_s)) + content_tag(:p, link_to("Archived (#{@all_projects.lost_or_abandoned.size})", my_account_projects_path(view: 'archived'), class: ('link-underline' if params[:view] == 'archived').to_s)) + content_tag(:p, link_to("View All (#{@all_projects.not_cancelled.size})", my_account_projects_path(view: 'all'), class: ('link-underline' if params[:view] == 'all').to_s)) end |
#project_link_helper ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/helpers/my_projects_helper.rb', line 11 def project_link_helper links = [] links << link_to("Edit Project info", edit_my_project_path(@project), { class: "secondary_button" }) if @project.ok_to_customer_cancel? links << link_to("Cancel Project", cancel_my_project_path(@project, authenticity_token: form_authenticity_token), { data: { turbo_method: :put, turbo_confirm: "Are you sure you want to cancel this project?" }, class: "secondary_button" }) end raw links.join(' ') end |
#room_cart_helper(room) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/my_projects_helper.rb', line 20 def room_cart_helper(room) if room.orders.non_carts.present? raw(%( You purchased this heating system as part of order # #{room.orders.non_carts.map { |o| link_to o.reference_number, my_account_order_path(o) }.join(' ')} )) elsif @context_user.cart.room_configuration_ids.include? room.id raw(%( #{link_to 'Remove Heated Space from cart', remove_from_cart_my_room_path(room), class: 'default_button'} )) elsif room.line_items.present? raw(%( #{link_to '+ Add Heated Space to Cart', add_to_cart_my_room_path(room), class: 'default_button'} )) end end |
#setup_project(project) ⇒ Object
4 5 6 7 8 9 |
# File 'app/helpers/my_projects_helper.rb', line 4 def setup_project(project) project.tap do |p| p.room_configurations.build if p.room_configurations.empty? p.name ||= "Project ##{@context_user.opportunities.length + 1}" end end |
#shorten_name(name, max = 40) ⇒ Object
46 47 48 49 50 |
# File 'app/helpers/my_projects_helper.rb', line 46 def shorten_name(name, max = 40) res = name.to_s res = "#{res[0..(max - 4)]}..." if res.length > max res end |