Class: Crm::FloorPlanDisplayPresenter
Overview
Presenter: floor plan display presenter.
Instance Attribute Summary
#current_account, #options, #url_helper
Instance Method Summary
collapse
#can?, #capture, #concat, #content_tag, #fa_icon, #h, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u
Constructor Details
Returns a new instance of FloorPlanDisplayPresenter.
4
5
6
7
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 4
def initialize(floor_plan_display, view_context)
@floor_plan_display = floor_plan_display
@view_context = view_context
end
|
Instance Method Details
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 22
def action_buttons
@view_context.content_tag :div, class: 'btn-group', role: 'group' do
concat @view_context.link_to('View', @view_context.floor_plan_display_path(@floor_plan_display),
class: 'btn btn-sm btn-outline-primary')
concat @view_context.link_to('Edit', @view_context.edit_floor_plan_display_path(@floor_plan_display),
class: 'btn btn-sm btn-outline-secondary')
concat @view_context.link_to('Images', @view_context.edit_images_floor_plan_display_path(@floor_plan_display),
class: 'btn btn-sm btn-outline-info')
concat @view_context.link_to('Preview', @view_context.preview_floor_plan_display_path(@floor_plan_display),
class: 'btn btn-sm btn-outline-success', target: '_blank', rel: 'noopener')
end
end
|
#breadcrumb_items ⇒ Object
117
118
119
120
121
122
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 117
def breadcrumb_items
[
{ name: 'Floor Plan Displays', url: @view_context.floor_plan_displays_path },
{ name: @floor_plan_display.name, url: @view_context.floor_plan_display_path(@floor_plan_display) }
]
end
|
#created_date_display ⇒ Object
53
54
55
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 53
def created_date_display
@floor_plan_display.created_at.strftime('%m/%d/%Y')
end
|
#description_preview ⇒ Object
61
62
63
64
65
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 61
def description_preview
return 'No description' if @floor_plan_display.description.blank?
@view_context.truncate(@view_context.strip_tags(@floor_plan_display.description), length: 100)
end
|
#filter_value_display ⇒ Object
75
76
77
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 75
def filter_value_display
@floor_plan_display.filter_value.presence || 'Not set'
end
|
#image_count_badge ⇒ Object
35
36
37
38
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 35
def image_count_badge
count = @floor_plan_display.images.count
@view_context.content_tag :span, count, class: 'badge bg-info'
end
|
#images_table_data ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 91
def images_table_data
@floor_plan_display.images.order(:position).map do |image|
{
id: image.id,
title: image.title,
size: image.attachment_size,
size_display: @view_context.number_to_human_size(image.attachment_size),
reference_number: image.reference_number,
from_room_config: image.tags&.include?('room-configuration'),
position: image.position
}
end
end
|
#main_image_thumbnail_url ⇒ Object
111
112
113
114
115
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 111
def main_image_thumbnail_url
return nil if @floor_plan_display.main_image.blank?
@floor_plan_display.main_image.attachment.url
end
|
#main_image_url ⇒ Object
105
106
107
108
109
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 105
def main_image_url
return nil if @floor_plan_display.main_image.blank?
@floor_plan_display.main_image.attachment.url
end
|
#operating_cost_display ⇒ Object
45
46
47
48
49
50
51
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 45
def operating_cost_display
return 'N/A' if @floor_plan_display.total_cost_to_operate.zero?
@view_context.content_tag :span,
"$#{@view_context.number_with_precision(@floor_plan_display.total_cost_to_operate, precision: 2)}",
class: 'text-success fw-bold'
end
|
#room_configurations_table_data ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 79
def room_configurations_table_data
@floor_plan_display.floor_plan_display_room_configurations.includes(:room_configuration).map do |fpdr|
{
room_name: fpdr.room_name,
room_description: fpdr.room_description,
cost_to_operate: fpdr.cost_to_operate,
reference_number: fpdr.room_configuration.reference_number,
operating_cost_display: "$#{@view_context.number_with_precision(fpdr.cost_to_operate, precision: 2)}"
}
end
end
|
#room_count_badge ⇒ Object
40
41
42
43
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 40
def room_count_badge
count = @floor_plan_display.room_configurations.count
@view_context.content_tag :span, count, class: 'badge bg-primary'
end
|
#seo_description_display ⇒ Object
71
72
73
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 71
def seo_description_display
@floor_plan_display.seo_description.presence || 'Not set'
end
|
#seo_title_display ⇒ Object
67
68
69
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 67
def seo_title_display
@floor_plan_display.seo_title.presence || 'Not set'
end
|
#state_badge ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 9
def state_badge
case @floor_plan_display.state
when 'published'
@view_context.content_tag :span, 'Published', class: 'badge bg-success'
when 'draft'
@view_context.content_tag :span, 'Draft', class: 'badge bg-warning'
when 'archived'
@view_context.content_tag :span, 'Archived', class: 'badge bg-secondary'
else
@view_context.content_tag :span, @floor_plan_display.state.humanize, class: 'badge bg-secondary'
end
end
|
#status_summary ⇒ Object
124
125
126
127
128
129
130
131
132
133
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 124
def status_summary
{
state: @floor_plan_display.state,
room_count: @floor_plan_display.room_configurations.count,
image_count: @floor_plan_display.images.count,
operating_cost: @floor_plan_display.total_cost_to_operate,
created_at: @floor_plan_display.created_at,
updated_at: @floor_plan_display.updated_at
}
end
|
#updated_date_display ⇒ Object
57
58
59
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 57
def updated_date_display
@floor_plan_display.updated_at.strftime('%m/%d/%Y')
end
|