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_navbar_nav_item(key, path, &block) ⇒ Object
Navbar.
-
#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
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/lato/components_helper.rb', line 74 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
206 207 208 |
# File 'app/helpers/lato/components_helper.rb', line 206 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
210 211 212 213 214 215 216 217 |
# File 'app/helpers/lato/components_helper.rb', line 210 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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/helpers/lato/components_helper.rb', line 100 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('labels.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
151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/lato/components_helper.rb', line 151 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
180 181 182 183 184 |
# File 'app/helpers/lato/components_helper.rb', line 180 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
186 187 188 189 190 |
# File 'app/helpers/lato/components_helper.rb', line 186 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
139 140 141 142 143 |
# File 'app/helpers/lato/components_helper.rb', line 139 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
168 169 170 171 172 |
# File 'app/helpers/lato/components_helper.rb', line 168 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
133 134 135 136 137 |
# File 'app/helpers/lato/components_helper.rb', line 133 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
145 146 147 148 149 |
# File 'app/helpers/lato/components_helper.rb', line 145 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
162 163 164 165 166 |
# File 'app/helpers/lato/components_helper.rb', line 162 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
127 128 129 130 131 |
# File 'app/helpers/lato/components_helper.rb', line 127 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
174 175 176 177 178 |
# File 'app/helpers/lato/components_helper.rb', line 174 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
120 121 122 123 124 125 |
# File 'app/helpers/lato/components_helper.rb', line 120 def lato_form_item_label(form, key, label = nil, = {}) [:class] ||= [] [:class].push('form-label') form.label key, label, end |
#lato_form_notices(options = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/lato/components_helper.rb', line 87 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
192 193 194 195 196 197 198 199 200 201 |
# File 'app/helpers/lato/components_helper.rb', line 192 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/lato/components_helper.rb', line 39 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_underscore = [:model_name] || collection.model.name.gsub('/', '_').underscore render( 'lato/components/index', key: key, collection: collection, columns: columns, sortable_columns: sortable_columns, searchable_columns: searchable_columns, model_name_underscore: model_name_underscore, custom_actions: [:custom_actions] || {} ) 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_operation(operation) ⇒ Object
Operation
64 65 66 67 68 69 |
# File 'app/helpers/lato/components_helper.rb', line 64 def lato_operation(operation) render( 'lato/components/operation', operation: operation ) end |
#lato_page_head(title, breadcrumbs = [], &block) ⇒ Object
Page head
30 31 32 33 34 |
# File 'app/helpers/lato/components_helper.rb', line 30 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
18 19 20 21 22 23 24 25 |
# File 'app/helpers/lato/components_helper.rb', line 18 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 |