Module: Avo::ApplicationHelper
- Includes:
- ResourcesHelper, Pagy::Frontend
- Included in:
- ActionsComponent, AlertComponent, BacktraceAlertComponent, BaseApplicationController, Fields::Common::Files::ControlsComponent, Fields::Common::KeyValueComponent, Fields::HasOneField::ShowComponent, FiltersComponent, FlashAlertsComponent, Index::ResourceControlsComponent, Index::ResourceTableComponent, Items::PanelComponent, MediaLibrary::ItemDetailsComponent, MediaLibrary::ListComponent, PanelComponent, PanelHeaderComponent, TabSwitcherComponent, Views::ResourceEditComponent, Views::ResourceIndexComponent, Views::ResourceShowComponent
- Defined in:
- app/helpers/avo/application_helper.rb
Instance Method Summary
collapse
-
#a_button(**args, &block) ⇒ Object
-
#a_link(path = nil, **args, &block) ⇒ Object
-
#button_classes(extra_classes = nil, color: nil, variant: nil, size: :md, active: false) ⇒ Object
-
#card_classes ⇒ Object
-
#chart_color(index) ⇒ Object
-
#container_classes ⇒ Object
-
#container_is_full_width? ⇒ Boolean
-
#d(value) ⇒ Object
-
#decode_filter_params(encoded_params) ⇒ Object
-
#e(value) ⇒ Object
-
#empty_state(**args) ⇒ Object
-
#encode_filter_params(filter_params) ⇒ Object
-
#frame_id(resource) ⇒ Object
-
#get_model_class(model) ⇒ Object
-
#input_classes(extra_classes = "", has_error: false) ⇒ Object
-
#mount_path ⇒ Object
-
#number_to_social(number, start_at: 10_000) ⇒ Object
-
#pagy_major_version ⇒ Object
-
#possibly_rails_authentication? ⇒ Boolean
-
#render_license_warning(title: "", message: "", icon: "exclamation") ⇒ Object
-
#root_path_without_url ⇒ Object
-
#white_panel_classes ⇒ Object
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Instance Method Details
18
19
20
21
22
|
# File 'app/helpers/avo/application_helper.rb', line 18
def a_button(**args, &block)
render Avo::ButtonComponent.new(is_link: false, **args) do
capture(&block) if block.present?
end
end
|
#a_link(path = nil, **args, &block) ⇒ Object
24
25
26
27
28
|
# File 'app/helpers/avo/application_helper.rb', line 24
def a_link(path = nil, **args, &block)
render Avo::ButtonComponent.new(path, is_link: true, **args) do
capture(&block) if block.present?
end
end
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/helpers/avo/application_helper.rb', line 30
def button_classes( = nil, color: nil, variant: nil, size: :md, active: false)
classes = "inline-flex flex-grow-0 items-center text-sm font-semibold leading-6 fill-current whitespace-nowrap transition duration-100 rounded transform transition duration-100 active:translate-x-px active:translate-y-px cursor-pointer disabled:cursor-not-allowed #{}"
if color.present?
if variant.present? && (variant.to_sym == :outlined)
classes += " bg-white border"
classes += " hover:border-#{color}-700 border-#{color}-500 text-#{color}-600 hover:text-#{color}-700 disabled:border-gray-300 disabled:text-gray-600"
else
classes += " text-white bg-#{color}-500 hover:bg-#{color}-600 disabled:bg-#{color}-300"
end
else
classes += " text-gray-700 bg-white hover:bg-gray-100 disabled:bg-gray-300"
end
size = size.present? ? size.to_sym : :md
classes += case size
when :xs
" p-2 py-1"
when :sm
" py-1 px-4"
when :md
" py-2 px-4"
when :xl
" py-3 px-4"
else
" p-4"
end
classes
end
|
#card_classes ⇒ Object
80
81
82
|
# File 'app/helpers/avo/application_helper.rb', line 80
def card_classes
"bg-white rounded shadow-panel"
end
|
#chart_color(index) ⇒ Object
129
130
131
|
# File 'app/helpers/avo/application_helper.rb', line 129
def chart_color(index)
Avo.configuration.branding.chart_colors[index % Avo.configuration.branding.chart_colors.length]
end
|
#container_classes ⇒ Object
158
159
160
|
# File 'app/helpers/avo/application_helper.rb', line 158
def container_classes
container_is_full_width? ? "" : "2xl:container 2xl:mx-auto"
end
|
#container_is_full_width? ⇒ Boolean
146
147
148
149
150
151
152
153
154
155
156
|
# File 'app/helpers/avo/application_helper.rb', line 146
def container_is_full_width?
if @container_full_width.present?
@container_full_width
elsif Avo.configuration.full_width_container
true
elsif Avo.configuration.full_width_index_view && action_name.to_sym == :index && controller.class.superclass.to_s == "Avo::ResourcesController"
true
else
false
end
end
|
#d(value) ⇒ Object
169
170
171
172
173
174
|
# File 'app/helpers/avo/application_helper.rb', line 169
def d(value)
decoded = Base64.urlsafe_decode64(value.to_s)
Avo::Services::EncryptionService.decrypt(message: decoded, purpose: :return_to, serializer: Marshal)
rescue
nil
end
|
#decode_filter_params(encoded_params) ⇒ Object
#e(value) ⇒ Object
163
164
165
166
|
# File 'app/helpers/avo/application_helper.rb', line 163
def e(value)
encrypted = Avo::Services::EncryptionService.encrypt(message: value, purpose: :return_to, serializer: Marshal)
Base64.urlsafe_encode64(encrypted, padding: false)
end
|
#empty_state(**args) ⇒ Object
14
15
16
|
# File 'app/helpers/avo/application_helper.rb', line 14
def empty_state(**args)
render Avo::EmptyStateComponent.new(**args)
end
|
#encode_filter_params(filter_params) ⇒ Object
#frame_id(resource) ⇒ Object
125
126
127
|
# File 'app/helpers/avo/application_helper.rb', line 125
def frame_id(resource)
["frame", resource.model_name.singular, resource.record_param].compact.join("-")
end
|
#get_model_class(model) ⇒ Object
84
85
86
87
88
89
90
|
# File 'app/helpers/avo/application_helper.rb', line 84
def get_model_class(model)
if model.instance_of?(Class)
model
else
model.class
end
end
|
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/helpers/avo/application_helper.rb', line 62
def input_classes( = "", has_error: false)
classes = "appearance-none inline-flex bg-gray-25 disabled:cursor-not-allowed text-gray-600 disabled:opacity-50 rounded py-2 px-3 leading-tight border focus:border-gray-600 focus-visible:ring-0 focus:text-gray-700 placeholder:text-gray-300"
classes += if has_error
" border-red-600"
else
" border-gray-200"
end
classes += " #{}"
classes
end
|
#mount_path ⇒ Object
98
99
100
|
# File 'app/helpers/avo/application_helper.rb', line 98
def mount_path
Avo::Engine.routes.find_script_name(params.permit!.to_h.symbolize_keys)
end
|
#number_to_social(number, start_at: 10_000) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/helpers/avo/application_helper.rb', line 110
def number_to_social(number, start_at: 10_000)
return number_with_delimiter(number) if number < start_at
number_to_human(number,
precision: 1,
significant: false,
round_mode: :down,
format: "%n%u",
units: {
thousand: "K",
million: "M",
billion: "B"
})
end
|
#pagy_major_version ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'app/helpers/avo/application_helper.rb', line 137
def pagy_major_version
return nil unless defined?(Pagy::VERSION)
version = Pagy::VERSION&.split(".")&.first&.to_i
return "8-or-more" if version >= 8
version
end
|
#possibly_rails_authentication? ⇒ Boolean
133
134
135
|
# File 'app/helpers/avo/application_helper.rb', line 133
def possibly_rails_authentication?
defined?(Authentication) && Authentication.private_instance_methods.include?(:require_authentication) && Authentication.private_instance_methods.include?(:authenticated?)
end
|
#render_license_warning(title: "", message: "", icon: "exclamation") ⇒ Object
6
7
8
9
10
11
12
|
# File 'app/helpers/avo/application_helper.rb', line 6
def render_license_warning(title: "", message: "", icon: "exclamation")
render partial: "avo/sidebar/license_warning", locals: {
title: title,
message: message,
icon: icon
}
end
|
#root_path_without_url ⇒ Object
92
93
94
95
96
|
# File 'app/helpers/avo/application_helper.rb', line 92
def root_path_without_url
"#{Avo.configuration.prefix_path}#{mount_path}"
rescue
Avo.configuration.root_path
end
|
#white_panel_classes ⇒ Object
76
77
78
|
# File 'app/helpers/avo/application_helper.rb', line 76
def white_panel_classes
"bg-white rounded shadow-md"
end
|