Module: SpreeCmCommissioner::Admin::HomepageSegmentHelper

Defined in:
app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb

Constant Summary collapse

SEGMENT_BADGE_COLORS =

Bootstrap has only eight badge colors, so later segments share one; the label tells them apart.

{
  general: 'primary',
  ticket: 'secondary',
  tour: 'info',
  accommodation: 'warning',
  things_to_do: 'success',
  football: 'dark',
  show: 'danger',
  bus: 'light',
  intercity_taxi: 'warning',
  rails: 'secondary',
  ferry: 'info'
}.freeze

Instance Method Summary collapse

Instance Method Details

#badge_class_for_mini_app(_mini_app_name) ⇒ Object



24
25
26
# File 'app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb', line 24

def badge_class_for_mini_app(_mini_app_name)
  'badge badge-info text-uppercase'
end

#badge_class_for_segment(segment_name) ⇒ Object



19
20
21
22
# File 'app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb', line 19

def badge_class_for_segment(segment_name)
  color = SEGMENT_BADGE_COLORS[segment_name.to_sym]
  color ? "badge badge-#{color} text-uppercase" : 'badge'
end

#calculate_mini_app_value(params) ⇒ Object



42
43
44
# File 'app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb', line 42

def calculate_mini_app_value(params)
  calculate_bitwise_value(params, SpreeCmCommissioner::HomepageSectionBitwise::BIT_MINI_APP)
end

#calculate_segment_value(params) ⇒ Object



38
39
40
# File 'app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb', line 38

def calculate_segment_value(params)
  calculate_bitwise_value(params, SpreeCmCommissioner::HomepageSectionBitwise::BIT_SEGMENT)
end

#mini_app_filter_options ⇒ Object

none is any value outside BIT_MINI_APP, which filter_by_mini_app reads as untagged.



33
34
35
36
# File 'app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb', line 33

def mini_app_filter_options
  [['No mini app', 'none']] +
    SpreeCmCommissioner::HomepageSectionBitwise::BIT_MINI_APP.keys.map { |name| [mini_app_label(name), name] }
end

#mini_app_label(mini_app_name) ⇒ Object



28
29
30
# File 'app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb', line 28

def mini_app_label(mini_app_name)
  mini_app_name.to_s.titleize
end