Module: Lato::ComponentsHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/lato/components_helper.rb
Instance Method Summary collapse
-
#_lato_form_input_options(form, key, options, action_change_event, classes = '') ⇒ Object
Forms.
-
#lato_data_badge(label, color = 'primary') ⇒ Object
Data.
- #lato_data_user(label, image_url = nil) ⇒ Object
- #lato_form_errors(instance, options = {}) ⇒ Object
- #lato_form_item_input_check(form, key, label, options = {}) ⇒ Object
- #lato_form_item_input_date(form, key, options = {}) ⇒ Object
- #lato_form_item_input_datetime(form, key, options = {}) ⇒ Object
- #lato_form_item_input_email(form, key, options = {}) ⇒ Object
- #lato_form_item_input_file(form, key, options = {}) ⇒ Object
- #lato_form_item_input_number(form, key, options = {}) ⇒ Object
- #lato_form_item_input_password(form, key, options = {}) ⇒ Object
- #lato_form_item_input_select(form, key, select_options = [], options = {}) ⇒ Object
- #lato_form_item_input_text(form, key, options = {}) ⇒ Object
- #lato_form_item_input_textarea(form, key, options = {}) ⇒ Object
- #lato_form_item_label(form, key, label = nil, options = {}) ⇒ Object
- #lato_form_notices(options = {}) ⇒ Object
- #lato_form_submit(form, label, options = {}) ⇒ Object
-
#lato_index(collection, options = {}) ⇒ Object
Index.
- #lato_index_dynamic_label(params = {}) ⇒ Object
- #lato_index_dynamic_value(params = {}) ⇒ Object
-
#lato_navbar_nav_item(key, path, &block) ⇒ Object
Navbar.
- #lato_navbar_nav_locales_item(options = {}) ⇒ Object
-
#lato_operation(operation) ⇒ Object
Operation.
-
#lato_page_head(title, breadcrumbs = [], &block) ⇒ Object
Page head.
-
#lato_sidebar_nav_item(key, path, &block) ⇒ Object
Sidebar.
Instance Method Details
#_lato_form_input_options(form, key, options, action_change_event, classes = '') ⇒ Object
Forms
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/lato/components_helper.rb', line 90 def (form, key, , action_change_event, classes = '') # setup classes [:class] ||= [] [:class].push(classes) [:class].push('is-invalid') if form.object && form.object.errors[key] && form.object.errors[key].any? # setup stimulus [:data] ||= {} [:data][:action] ||= '' [:data][:action] += " #{action_change_event}->lato-form#onInputChange" [:data][:lato_form_target] = 'input' end |
#lato_data_badge(label, color = 'primary') ⇒ Object
Data
222 223 224 |
# File 'app/helpers/lato/components_helper.rb', line 222 def lato_data_badge(label, color = 'primary') content_tag :span, label, class: "badge rounded-pill bg-#{color}" end |
#lato_data_user(label, image_url = nil) ⇒ Object
226 227 228 229 230 231 232 233 |
# File 'app/helpers/lato/components_helper.rb', line 226 def lato_data_user(label, image_url = nil) image_url ||= image_path('lato/user-150x150') content_tag :div, class: 'd-flex align-items-center' do concat content_tag :div, '', class: 'border border-2 rounded-circle me-2', style: "background-position: center; background-size: cover; background-repeat: no-repeat; background-image: url(#{image_url}); width: 30px; height: 30px;" concat content_tag :small, label, class: 'text-black' end end |
#lato_form_errors(instance, options = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/lato/components_helper.rb', line 116 def lato_form_errors(instance, = {}) return unless instance.errors.any? [:class] ||= [] [:class] += %w[alert alert-danger] [:class] += %w[alert-dismissible fade show] unless [:fixed] errors_list = content_tag(:ul, class: %w[mb-0 ps-3]) do instance.errors.collect do |error| content_tag :li, error. end.join.html_safe end content_tag :div, do concat content_tag(:span, "#{I18n.t('lato.there_are_some_errors')}:") concat errors_list concat ('', type: 'button', class: 'btn-close', data: { bs_dismiss: 'alert' }) unless [:fixed] end end |
#lato_form_item_input_check(form, key, label, options = {}) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/lato/components_helper.rb', line 167 def lato_form_item_input_check(form, key, label, = {}) (form, key, , :change, 'form-check-input') # TO-DO: Trovare il modo di calcolare l'id dato da rails a check_input_tag e metterlo nell'attributo :for di check_label_tag content_tag :div, class: 'form-check' do concat form.check_box(key, ) concat label_tag(key, raw(label), class: 'form-check-label') end end |
#lato_form_item_input_date(form, key, options = {}) ⇒ Object
196 197 198 199 200 |
# File 'app/helpers/lato/components_helper.rb', line 196 def lato_form_item_input_date(form, key, = {}) (form, key, , :change, 'form-control') form.date_field key, end |
#lato_form_item_input_datetime(form, key, options = {}) ⇒ Object
202 203 204 205 206 |
# File 'app/helpers/lato/components_helper.rb', line 202 def lato_form_item_input_datetime(form, key, = {}) (form, key, , :change, 'form-control') form.datetime_field key, end |
#lato_form_item_input_email(form, key, options = {}) ⇒ Object
155 156 157 158 159 |
# File 'app/helpers/lato/components_helper.rb', line 155 def lato_form_item_input_email(form, key, = {}) (form, key, , :keyup, 'form-control') form.email_field key, end |
#lato_form_item_input_file(form, key, options = {}) ⇒ Object
184 185 186 187 188 |
# File 'app/helpers/lato/components_helper.rb', line 184 def lato_form_item_input_file(form, key, = {}) (form, key, , :change, 'form-control') form.file_field key, end |
#lato_form_item_input_number(form, key, options = {}) ⇒ Object
149 150 151 152 153 |
# File 'app/helpers/lato/components_helper.rb', line 149 def lato_form_item_input_number(form, key, = {}) (form, key, , :keyup, 'form-control') form.number_field key, end |
#lato_form_item_input_password(form, key, options = {}) ⇒ Object
161 162 163 164 165 |
# File 'app/helpers/lato/components_helper.rb', line 161 def lato_form_item_input_password(form, key, = {}) (form, key, , :keyup, 'form-control') form.password_field key, end |
#lato_form_item_input_select(form, key, select_options = [], options = {}) ⇒ Object
178 179 180 181 182 |
# File 'app/helpers/lato/components_helper.rb', line 178 def lato_form_item_input_select(form, key, = [], = {}) (form, key, , :change, 'form-control') form.select key, , {}, end |
#lato_form_item_input_text(form, key, options = {}) ⇒ Object
143 144 145 146 147 |
# File 'app/helpers/lato/components_helper.rb', line 143 def lato_form_item_input_text(form, key, = {}) (form, key, , :keyup, 'form-control') form.text_field key, end |
#lato_form_item_input_textarea(form, key, options = {}) ⇒ Object
190 191 192 193 194 |
# File 'app/helpers/lato/components_helper.rb', line 190 def lato_form_item_input_textarea(form, key, = {}) (form, key, , :keyup, 'form-control') form.text_area key, end |
#lato_form_item_label(form, key, label = nil, options = {}) ⇒ Object
136 137 138 139 140 141 |
# File 'app/helpers/lato/components_helper.rb', line 136 def lato_form_item_label(form, key, label = nil, = {}) [:class] ||= [] [:class].push('form-label') form.label key, label, end |
#lato_form_notices(options = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/lato/components_helper.rb', line 103 def lato_form_notices( = {}) return unless notice [:class] ||= [] [:class] += %w[alert alert-success] [:class] += %w[alert-dismissible fade show] unless [:fixed] content_tag :div, do concat notice concat ('', type: 'button', class: 'btn-close', data: { bs_dismiss: 'alert' }) unless [:fixed] end end |
#lato_form_submit(form, label, options = {}) ⇒ Object
208 209 210 211 212 213 214 215 216 217 |
# File 'app/helpers/lato/components_helper.rb', line 208 def lato_form_submit(form, label, = {}) [:class] ||= [] [:class].push('btn') [:class].push('btn-primary') [:data] ||= {} [:data][:lato_form_target] = 'submit' form.submit label, end |
#lato_index(collection, options = {}) ⇒ Object
Index
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/lato/components_helper.rb', line 45 def lato_index(collection, = {}) key = [:key] || 'default' @_lato_index ||= {} @_lato_index[key] ||= {} columns = [:columns] || @_lato_index[key][:columns] || collection.column_names || [] sortable_columns = @_lato_index[key][:sortable_columns] || [] searchable_columns = @_lato_index[key][:searchable_columns] || [] model_name = [:model_name] || collection.model.name model_name_underscore = [:model_name] || model_name.underscore.gsub('/', '_') render( 'lato/components/index', key: key, collection: collection, columns: columns, sortable_columns: sortable_columns, searchable_columns: searchable_columns, model_name: model_name, model_name_underscore: model_name_underscore, custom_actions: [:custom_actions] || {} ) end |
#lato_index_dynamic_label(params = {}) ⇒ Object
69 70 71 |
# File 'app/helpers/lato/components_helper.rb', line 69 def lato_index_dynamic_label(params = {}) 'Please override the method lato_index_dynamic_label in your application_helper.rb' end |
#lato_index_dynamic_value(params = {}) ⇒ Object
73 74 75 |
# File 'app/helpers/lato/components_helper.rb', line 73 def lato_index_dynamic_value(params = {}) 'Please override the method lato_index_dynamic_value in your application_helper.rb' end |
#lato_navbar_nav_item(key, path, &block) ⇒ Object
Navbar
6 7 8 9 10 11 12 13 |
# File 'app/helpers/lato/components_helper.rb', line 6 def (key, path, &block) active = request.path == path active = @navbar_key == key if @navbar_key render 'lato/components/navbar_nav_item', active: active, path: path do yield if block end end |
#lato_navbar_nav_locales_item(options = {}) ⇒ Object
15 16 17 18 19 |
# File 'app/helpers/lato/components_helper.rb', line 15 def ( = {}) flag = [:flag] || false render 'lato/components/navbar_nav_locales_item', flag: flag end |
#lato_operation(operation) ⇒ Object
Operation
80 81 82 83 84 85 |
# File 'app/helpers/lato/components_helper.rb', line 80 def lato_operation(operation) render( 'lato/components/operation', operation: operation ) end |
#lato_page_head(title, breadcrumbs = [], &block) ⇒ Object
Page head
36 37 38 39 40 |
# File 'app/helpers/lato/components_helper.rb', line 36 def lato_page_head(title, = [], &block) render 'lato/components/page_head', title: title, breadcrumbs: do yield if block end end |
#lato_sidebar_nav_item(key, path, &block) ⇒ Object
Sidebar
24 25 26 27 28 29 30 31 |
# File 'app/helpers/lato/components_helper.rb', line 24 def (key, path, &block) active = request.path == path active = @sidebar_key == key if @sidebar_key render 'lato/components/sidebar_nav_item', active: active, path: path do yield if block end end |