Class: Crm::FloorPlanDisplayPresenter
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.
2
3
4
5
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 2
def initialize(floor_plan_display, view_context)
@floor_plan_display = floor_plan_display
@view_context = view_context
end
|
Instance Method Details
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 20
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
115
116
117
118
119
120
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 115
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
51
52
53
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 51
def created_date_display
@floor_plan_display.created_at.strftime('%m/%d/%Y')
end
|
#description_preview ⇒ Object
59
60
61
62
63
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 59
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
73
74
75
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 73
def filter_value_display
@floor_plan_display.filter_value.presence || 'Not set'
end
|
#image_count_badge ⇒ Object
33
34
35
36
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 33
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
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 89
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
109
110
111
112
113
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 109
def main_image_thumbnail_url
return nil unless @floor_plan_display.main_image.present?
@floor_plan_display.main_image.attachment.url
end
|
#main_image_url ⇒ Object
103
104
105
106
107
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 103
def main_image_url
return nil unless @floor_plan_display.main_image.present?
@floor_plan_display.main_image.attachment.url
end
|
#operating_cost_display ⇒ Object
43
44
45
46
47
48
49
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 43
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
77
78
79
80
81
82
83
84
85
86
87
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 77
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
38
39
40
41
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 38
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
69
70
71
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 69
def seo_description_display
@floor_plan_display.seo_description.presence || 'Not set'
end
|
#seo_title_display ⇒ Object
65
66
67
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 65
def seo_title_display
@floor_plan_display.seo_title.presence || 'Not set'
end
|
#state_badge ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 7
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
122
123
124
125
126
127
128
129
130
131
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 122
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
55
56
57
|
# File 'app/presenters/crm/floor_plan_display_presenter.rb', line 55
def updated_date_display
@floor_plan_display.updated_at.strftime('%m/%d/%Y')
end
|