Module: Crm::FloorPlanDisplaysHelper

Defined in:
app/helpers/crm/floor_plan_displays_helper.rb

Overview

View helpers for the CRM floor plan display screens: state badges, action
button groups, and image / room / operating-cost summary chips.

Instance Method Summary collapse

Instance Method Details

#floor_plan_display_actions(floor_plan_display) ⇒ ActiveSupport::SafeBuffer

Renders the View / Edit / Images / Preview button group for a display.

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer)

    the button group HTML



31
32
33
34
35
36
37
38
# File 'app/helpers/crm/floor_plan_displays_helper.rb', line 31

def floor_plan_display_actions(floor_plan_display)
   :div, class: 'btn-group', role: 'group' do
    concat link_to('View', floor_plan_display_path(floor_plan_display), class: 'btn btn-sm btn-outline-primary')
    concat link_to('Edit', edit_floor_plan_display_path(floor_plan_display), class: 'btn btn-sm btn-outline-secondary')
    concat link_to('Images', edit_images_floor_plan_display_path(floor_plan_display), class: 'btn btn-sm btn-outline-info')
    concat link_to('Preview', preview_floor_plan_display_path(floor_plan_display), class: 'btn btn-sm btn-outline-success', target: '_blank', rel: 'noopener')
  end
end

#floor_plan_display_image_count(floor_plan_display) ⇒ ActiveSupport::SafeBuffer

Renders a badge with the number of images attached to a display.

Parameters:

  • floor_plan_display (FloorPlanDisplay)

    the display whose images are counted

Returns:

  • (ActiveSupport::SafeBuffer)

    the badge HTML



44
45
46
47
# File 'app/helpers/crm/floor_plan_displays_helper.rb', line 44

def floor_plan_display_image_count(floor_plan_display)
  count = floor_plan_display.images.count
   :span, count, class: 'badge bg-info'
end

#floor_plan_display_operating_cost(floor_plan_display) ⇒ ActiveSupport::SafeBuffer, String

Renders the display's total operating cost as a dollar amount.

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer, String)

    formatted cost HTML, or
    the string 'N/A' when the cost is zero



63
64
65
66
67
68
# File 'app/helpers/crm/floor_plan_displays_helper.rb', line 63

def floor_plan_display_operating_cost(floor_plan_display)
  return 'N/A' if floor_plan_display.total_cost_to_operate.zero?

   :span, "$#{number_with_precision(floor_plan_display.total_cost_to_operate, precision: 2)}",
              class: 'text-success fw-bold'
end

#floor_plan_display_room_count(floor_plan_display) ⇒ ActiveSupport::SafeBuffer

Renders a badge with the number of room configurations on a display.

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer)

    the badge HTML



53
54
55
56
# File 'app/helpers/crm/floor_plan_displays_helper.rb', line 53

def floor_plan_display_room_count(floor_plan_display)
  count = floor_plan_display.room_configurations.count
   :span, count, class: 'badge bg-primary'
end

#floor_plan_display_state_badge(state) ⇒ ActiveSupport::SafeBuffer

Renders a Bootstrap badge colored by the display's lifecycle state.

Parameters:

  • state (String)

    the floor plan display state
    (published, draft, archived)

Returns:

  • (ActiveSupport::SafeBuffer)

    the badge HTML; unknown states fall
    back to a bg-secondary badge



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/crm/floor_plan_displays_helper.rb', line 14

def floor_plan_display_state_badge(state)
  case state
  when 'published'
     :span, state.humanize, class: 'badge bg-success'
  when 'draft'
     :span, state.humanize, class: 'badge bg-warning'
  when 'archived'
     :span, state.humanize, class: 'badge bg-secondary'
  else
     :span, state.humanize, class: 'badge bg-secondary'
  end
end