active_element 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +16 -31
  3. data/app/assets/javascripts/active_element/form.js +2 -1
  4. data/app/assets/javascripts/active_element/json_field.js +8 -1
  5. data/app/views/active_element/_title.html.erb +1 -0
  6. data/app/views/active_element/components/button.html.erb +6 -4
  7. data/app/views/active_element/components/form/_check_boxes.html.erb +6 -4
  8. data/app/views/active_element/components/form/_date_range_field.html.erb +14 -0
  9. data/app/views/active_element/components/form/_field.html.erb +3 -0
  10. data/app/views/active_element/components/form/_summary.html.erb +10 -0
  11. data/app/views/active_element/components/form.html.erb +12 -2
  12. data/app/views/active_element/components/table/_collection_row.html.erb +3 -3
  13. data/app/views/active_element/components/table/_field.html.erb +2 -2
  14. data/app/views/active_element/components/table/collection.html.erb +20 -11
  15. data/app/views/active_element/components/table/item.html.erb +4 -0
  16. data/app/views/active_element/default_views/forbidden.html.erb +17 -3
  17. data/app/views/active_element/default_views/index.html.erb +14 -6
  18. data/app/views/layouts/active_element.html.erb +4 -2
  19. data/config/locales/en.yml +3 -0
  20. data/example_app/.ruby-version +1 -1
  21. data/example_app/Gemfile +0 -2
  22. data/example_app/Gemfile.lock +5 -4
  23. data/lib/active_element/components/button.rb +6 -4
  24. data/lib/active_element/components/collection_table.rb +10 -3
  25. data/lib/active_element/components/form.rb +27 -2
  26. data/lib/active_element/components/item_table.rb +5 -3
  27. data/lib/active_element/components/navbar.rb +1 -1
  28. data/lib/active_element/components/util/association_mapping.rb +50 -26
  29. data/lib/active_element/components/util/default_display_value.rb +51 -0
  30. data/lib/active_element/components/util/display_value_mapping.rb +10 -0
  31. data/lib/active_element/components/util/field_mapping.rb +2 -2
  32. data/lib/active_element/components/util/form_field_mapping.rb +68 -15
  33. data/lib/active_element/components/util/record_mapping.rb +24 -3
  34. data/lib/active_element/components/util/record_path.rb +51 -20
  35. data/lib/active_element/components/util.rb +13 -0
  36. data/lib/active_element/controller_interface.rb +11 -1
  37. data/lib/active_element/controller_state.rb +4 -2
  38. data/lib/active_element/default_controller/params.rb +9 -1
  39. data/lib/active_element/default_controller/search.rb +22 -16
  40. data/lib/active_element/field_options.rb +20 -0
  41. data/lib/active_element/version.rb +1 -1
  42. data/lib/active_element.rb +1 -0
  43. data/rspec-documentation/pages/016-Default Controller.md +10 -1
  44. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4fed8a2aa02e3d31a663293eaee2485fe9a483a74c0b089638e0a4d6d6a1521
4
- data.tar.gz: edaae463c33a9e63827dbdf715b9f6cece1fdb593d17171f0f283f84f8c01689
3
+ metadata.gz: cb1aee3153ca04daa45cd99c868afb986df934e6a84e1be8675fcb01d9ed5097
4
+ data.tar.gz: 060f791791440d2d0d880384bd2bfd2c6d6724041bd2451035521f8f8ddd954a
5
5
  SHA512:
6
- metadata.gz: 8f54c3be4a35104dfa558d6842ddded264a21eb37ea210d2dd46e676d07655491d119037f4954e4225390a44f54fca827825a33d718ee5f9159133f6619fd73d
7
- data.tar.gz: 1e9e43507054e3e2a659691072249880d65136371d15d9b5fdbbad451d3822ca6def3fdb69abed646ae7993e17c7ee47ac14d8e2832e7eaee03601d8bae6c0fc
6
+ metadata.gz: c9b7a77759b27826038b895f9acc941620d4477192c22c0a13dc33ba03b64c61e292ff94520fc3ff7c2dc0abeb409483aa1f86aa3268e4e271fb3810d558e9e4
7
+ data.tar.gz: 652d599381d599a7186c654c49c87d3d7eca73c6373241b3900bd7c9c61718efa715ea83f32dfff6b9951ee7a737f79629440bf9b16c1858cedf235e94eed52e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_element (0.0.13)
4
+ active_element (0.0.15)
5
5
  bootstrap (~> 5.3.0alpha3)
6
6
  kaminari (~> 1.2)
7
7
  paintbrush (~> 0.1.2)
@@ -80,20 +80,19 @@ GEM
80
80
  addressable (2.8.4)
81
81
  public_suffix (>= 2.0.2, < 6.0)
82
82
  ast (2.4.2)
83
- autoprefixer-rails (10.4.13.0)
83
+ autoprefixer-rails (10.4.16.0)
84
84
  execjs (~> 2)
85
85
  bcrypt (3.1.18)
86
- bootstrap (5.3.0.alpha3)
86
+ bootstrap (5.3.2)
87
87
  autoprefixer-rails (>= 9.1.0)
88
- popper_js (>= 2.11.7, < 3)
89
- sassc-rails (>= 2.0.0)
88
+ popper_js (>= 2.11.8, < 3)
90
89
  brakeman (5.4.1)
91
90
  builder (3.2.4)
92
91
  concurrent-ruby (1.2.2)
93
92
  crack (0.4.5)
94
93
  rexml
95
94
  crass (1.0.6)
96
- date (3.3.3)
95
+ date (3.3.4)
97
96
  devise (4.9.2)
98
97
  bcrypt (~> 3.0)
99
98
  orm_adapter (~> 0.1)
@@ -103,7 +102,7 @@ GEM
103
102
  devpack (0.4.1)
104
103
  diff-lcs (1.5.0)
105
104
  erubi (1.12.0)
106
- execjs (2.8.1)
105
+ execjs (2.9.1)
107
106
  factory_bot (5.2.0)
108
107
  activesupport (>= 4.2.0)
109
108
  factory_bot_rails (5.2.0)
@@ -112,8 +111,8 @@ GEM
112
111
  faker (2.23.0)
113
112
  i18n (>= 1.8.11, < 2)
114
113
  ffi (1.15.5)
115
- globalid (1.1.0)
116
- activesupport (>= 5.0)
114
+ globalid (1.2.1)
115
+ activesupport (>= 6.1)
117
116
  hashdiff (1.0.1)
118
117
  htmlbeautifier (1.4.2)
119
118
  i18n (1.14.1)
@@ -148,19 +147,19 @@ GEM
148
147
  net-smtp
149
148
  marcel (1.0.2)
150
149
  method_source (1.0.0)
151
- mini_mime (1.1.2)
150
+ mini_mime (1.1.5)
152
151
  mini_portile2 (2.8.2)
153
152
  minitest (5.18.1)
154
- net-imap (0.3.6)
153
+ net-imap (0.4.8)
155
154
  date
156
155
  net-protocol
157
156
  net-pop (0.1.2)
158
157
  net-protocol
159
- net-protocol (0.2.1)
158
+ net-protocol (0.2.2)
160
159
  timeout
161
- net-smtp (0.3.3)
160
+ net-smtp (0.4.0)
162
161
  net-protocol
163
- nio4r (2.5.9)
162
+ nio4r (2.7.0)
164
163
  nokogiri (1.15.2)
165
164
  mini_portile2 (~> 2.8.2)
166
165
  racc (~> 1.4)
@@ -171,7 +170,7 @@ GEM
171
170
  parser (3.2.2.3)
172
171
  ast (~> 2.4.1)
173
172
  racc
174
- popper_js (2.11.7)
173
+ popper_js (2.11.8)
175
174
  public_suffix (5.0.1)
176
175
  racc (1.7.1)
177
176
  rack (2.2.7)
@@ -286,27 +285,13 @@ GEM
286
285
  ruby-progressbar (1.13.0)
287
286
  sassc (2.4.0)
288
287
  ffi (~> 1.9)
289
- sassc-rails (2.1.2)
290
- railties (>= 4.0.0)
291
- sassc (>= 2.0)
292
- sprockets (> 3.0)
293
- sprockets-rails
294
- tilt
295
- sprockets (4.2.0)
296
- concurrent-ruby (~> 1.0)
297
- rack (>= 2.2.4, < 4)
298
- sprockets-rails (3.4.2)
299
- actionpack (>= 5.2)
300
- activesupport (>= 5.2)
301
- sprockets (>= 3.0.0)
302
288
  sqlite3 (1.6.3)
303
289
  mini_portile2 (~> 2.8.0)
304
290
  strong_versions (0.4.5)
305
291
  i18n (>= 0.5)
306
292
  paint (~> 2.0)
307
293
  thor (1.2.2)
308
- tilt (2.2.0)
309
- timeout (0.3.2)
294
+ timeout (0.4.1)
310
295
  tzinfo (2.0.6)
311
296
  concurrent-ruby (~> 1.0)
312
297
  unicode-display_width (2.4.2)
@@ -316,7 +301,7 @@ GEM
316
301
  addressable (>= 2.8.0)
317
302
  crack (>= 0.3.2)
318
303
  hashdiff (>= 0.4.0, < 2.0.0)
319
- websocket-driver (0.7.5)
304
+ websocket-driver (0.7.6)
320
305
  websocket-extensions (>= 0.1.0)
321
306
  websocket-extensions (0.1.5)
322
307
  zeitwerk (2.6.8)
@@ -31,7 +31,8 @@
31
31
  clearFormButton.addEventListener('click', (ev) => {
32
32
  ev.preventDefault();
33
33
 
34
- form.querySelectorAll('.form-fields input, .form-fields select, .form-fields textarea')
34
+ form.querySelectorAll('.form-fields input:enabled, .form-fields select:enabled, .form-fields textarea:enabled')
35
+ .filter((formInput) => !formInput.readonly)
35
36
  .forEach((formInput) => formInput.value = '');
36
37
  });
37
38
  });
@@ -432,7 +432,14 @@ ActiveElement.JsonField = (() => {
432
432
  element.append(Option({ value: '' }));
433
433
 
434
434
  schema.options.forEach((value) => {
435
- element.append(Option({ value, selected: value === store.getValue(state) }));
435
+ let label = value;
436
+
437
+ if (isObject(value)) {
438
+ label = value.label;
439
+ value = value.value;
440
+ }
441
+
442
+ element.append(Option({ value, label, selected: value === store.getValue(state) }));
436
443
  });
437
444
 
438
445
  return element;
@@ -0,0 +1 @@
1
+ <title><%= active_element.application_name.humanize %> - <%= controller_name.humanize %></title>
@@ -1,11 +1,13 @@
1
-
2
1
  <%=
3
2
  link_to(
4
3
  path.presence || '#',
5
4
  method: path.present? && method != :get ? method : nil,
6
- data: { confirm_action: confirm },
5
+ data: { confirm_action: confirm }.merge(tooltip ? {
6
+ 'bs-trigger': 'hover',
7
+ 'bs-toggle': 'popover',
8
+ 'bs-content': title,
9
+ } : {}),
7
10
  class: "btn #{button_class} #{float_class} #{kwargs_class}",
8
- title: title,
9
11
  **kwargs
10
12
  ) do %>
11
13
  <% if block_given %>
@@ -15,7 +17,7 @@
15
17
  <% if icon.present? %>
16
18
  <i class="fa-solid fa-<%= icon %>"></i>
17
19
  <% elsif type == :show %>
18
- <i class="fa-solid fa-eye"></i>
20
+ <i class="fa-solid fa-magnifying-glass"></i>
19
21
  <% elsif type == :edit %>
20
22
  <i class="fa-solid fa-pen"></i>
21
23
  <% elsif type == :destroy %>
@@ -17,12 +17,14 @@
17
17
  <% else %>
18
18
  <div class="container w-100">
19
19
  <%= form.fields_for field do |subform| %>
20
- <% options.fetch(:options).each_slice(options.fetch(:columns, 1)) do |slice| %>
20
+ <% options.fetch(:options).in_groups(options.fetch(:columns, 1)).reduce(&:zip).each do |columns| %>
21
21
  <div class="row w-100">
22
- <% slice.each do |label, name, checked| %>
22
+ <% columns.each do |label, name, checked| %>
23
23
  <div class="col">
24
- <%= subform.check_box(name, checked: checked, class: 'me-2', tabindex: component.tabindex) %>
25
- <%= subform.label name, label %>
24
+ <% if [label, name, checked].any?(&:present?) %>
25
+ <%= subform.check_box(name, checked: checked, class: 'me-2', tabindex: component.tabindex) %>
26
+ <%= subform.label name, label %>
27
+ <% end %>
26
28
  </div>
27
29
  <br/>
28
30
  <% end %>
@@ -0,0 +1,14 @@
1
+ <div class="d-flex">
2
+ <%= form.label(nil, class: 'me-2 mt-1') { 'Between' } %>
3
+ <%= form.date_field("#{field}[from]", name: "#{field}[from]",
4
+ value: component.value_for(field, :from),
5
+ class: "form-control #{component.valid?(field) ? nil : 'is-invalid'}",
6
+ tabindex: component.tabindex,
7
+ **options) %>
8
+ <%= form.label(nil, class: 'ms-2 mt-1 me-2') { 'and' } %>
9
+ <%= form.date_field("#{field}[to]", name: "#{field}[to]",
10
+ value: component.value_for(field, :to),
11
+ class: "form-control #{component.valid?(field) ? nil : 'is-invalid'}",
12
+ tabindex: component.tabindex,
13
+ **options) %>
14
+ </div>
@@ -20,6 +20,9 @@
20
20
  <% elsif type == :datetime_range_field %>
21
21
  <%= render partial: 'active_element/components/form/datetime_range_field',
22
22
  locals: { form_id: id, form: form, field: field, type: type, options: options, component: component } %>
23
+ <% elsif type == :date_range_field %>
24
+ <%= render partial: 'active_element/components/form/date_range_field',
25
+ locals: { form_id: id, form: form, field: field, type: type, options: options, component: component } %>
23
26
  <% else %>
24
27
  <%= render partial: 'active_element/components/form/generic_field',
25
28
  locals: { form_id: id, form: form, field: field, type: type, options: options, component: component } %>
@@ -24,6 +24,16 @@
24
24
  <% elsif type == :datetime_range_field %>
25
25
  <% next unless value.present? %>
26
26
 
27
+ <% values << value %>
28
+ <div class="d-inline me-3">
29
+ <span class="text-secondary"><%= options.fetch(:label) %>:</span>
30
+ <span class="ms-1 text-primary"><%= value[:from] %></span>
31
+ <span class="text-secondary">&rarr;</span>
32
+ <span class="ms-1 text-primary"><%= value[:to] %></span>
33
+ </div>
34
+ <% elsif type == :date_range_field %>
35
+ <% next unless value.present? %>
36
+
27
37
  <% values << value %>
28
38
  <div class="d-inline me-3">
29
39
  <span class="text-secondary"><%= options.fetch(:label) %>:</span>
@@ -35,12 +35,22 @@
35
35
  <% end %>
36
36
 
37
37
  <div class="form <%= modal ? 'd-none' : 'pb-3' %>" id="form-wrapper-<%= id %>">
38
- <%= form_with local: true, action: action, method: method, id: id, class: "#{class_name} m-3", **kwargs do |form| %>
38
+ <%= form_with model: model_param,
39
+ scope: becomes_model&.model_name&.param_key,
40
+ url: record_path.path,
41
+ local: true,
42
+ action: action,
43
+ method: method,
44
+ id: id,
45
+ class: "#{class_name} m-3",
46
+ **kwargs do |form| %>
39
47
  <% if %i[top both].include?(submit_position) %>
40
48
  <div class="row mb-3 form-group sticky-top" style="top: 0.5rem;">
41
49
  <div class="col-sm-3"></div>
42
50
  <div class="col pb-3">
43
- <%= form.submit submit_label, name: '', class: "btn btn-#{method == :post ? 'success' : 'primary'} ms-2 float-end" %>
51
+ <%= form.submit submit_label,
52
+ name: '',
53
+ class: "btn btn-#{method == :post ? 'success' : 'primary'} ms-2 float-end" %>
44
54
  <%= active_element.component.button 'Clear Form', class: 'btn-secondary float-end', data: { 'form-input-type': 'clear' } %>
45
55
  </div>
46
56
  </div>
@@ -13,19 +13,19 @@
13
13
 
14
14
  <% if show %>
15
15
  <td class="<%= "#{class_name}-show" %> action-column text-end">
16
- <%= active_element.component.show_button(item, show, class: 'btn-sm') %>
16
+ <%= active_element.component.show_button(item, show, tooltip: true, class: 'btn-sm') %>
17
17
  </td>
18
18
  <% end %>
19
19
 
20
20
  <% if edit %>
21
21
  <td class="<%= "#{class_name}-edit" %> action-column text-end">
22
- <%= active_element.component.edit_button(item, show, class: 'btn-sm') %>
22
+ <%= active_element.component.edit_button(item, show, tooltip: true, class: 'btn-sm') %>
23
23
  </td>
24
24
  <% end %>
25
25
 
26
26
  <% if destroy %>
27
27
  <td class="<%= "#{class_name}-destroy" %> action-column text-end">
28
- <%= active_element.component.destroy_button(item, destroy, class: 'btn-sm') %>
28
+ <%= active_element.component.destroy_button(item, destroy, tooltip: true, class: 'btn-sm') %>
29
29
  </td>
30
30
  <% end %>
31
31
  </tr>
@@ -1,7 +1,7 @@
1
1
  <% if value.is_a?(Array) %>
2
+ <ul>
2
3
  <% value.sort.each_with_index do |each_value, index| %>
3
- <%= each_value %>
4
- <%= index < value.size - 1 ? '|' : nil %>
4
+ <li><%= each_value %></li>
5
5
  <% end %>
6
6
  <% else %>
7
7
  <%= value %>
@@ -2,6 +2,11 @@
2
2
  <%= active_element.component.new_button(component.model&.new, float: 'end', class: 'mb-3') %>
3
3
  <% end %>
4
4
 
5
+
6
+ <% if title.present? %>
7
+ <%= active_element.component.page_section_title(title) %>
8
+ <% end %>
9
+
5
10
  <% if display_pagination %>
6
11
  <%=
7
12
  render partial: 'active_element/components/table/pagination',
@@ -25,15 +30,19 @@
25
30
  i18n: i18n,
26
31
  row_class_mapper: row_class_mapper } %>
27
32
  <% else %>
28
- <%= render partial: 'active_element/components/table/ungrouped_collection',
29
- locals: { component: component,
30
- collection: collection,
31
- fields: fields,
32
- show: show,
33
- edit: edit,
34
- destroy: destroy,
35
- class_name: class_name,
36
- style: style,
37
- i18n: i18n,
38
- row_class_mapper: row_class_mapper } %>
33
+ <% if collection.try(:empty?) %>
34
+ <p><i>(No items to display).</i></p>
35
+ <% else %>
36
+ <%= render partial: 'active_element/components/table/ungrouped_collection',
37
+ locals: { component: component,
38
+ collection: collection,
39
+ fields: fields,
40
+ show: show,
41
+ edit: edit,
42
+ destroy: destroy,
43
+ class_name: class_name,
44
+ style: style,
45
+ i18n: i18n,
46
+ row_class_mapper: row_class_mapper } %>
47
+ <% end %>
39
48
  <% end %>
@@ -10,6 +10,10 @@
10
10
  <%= active_element.component.new_button(component.model, float: 'end', class: 'mb-3') %>
11
11
  <% end %>
12
12
 
13
+ <% if title.present? %>
14
+ <%= active_element.component.page_section_title(title) %>
15
+ <% end %>
16
+
13
17
  <table class="<%= class_name %> table" style="<%= style %>">
14
18
  <tbody>
15
19
  <% fields.each do |field, class_mapper, label, value_mapper, options| %>
@@ -1,7 +1,21 @@
1
- <h1>Forbidden</h1>
1
+ <% if Rails.env.development? %>
2
+ <h1>Not Configured</h1>
2
3
 
3
- <h2 class="text-danger">Access to this resource has not been configured</h2>
4
+ <p>The <code><%= type %></code> resource for <code><%= controller_name.titleize %></code> has not been configured.</p>
4
5
 
5
- <p>The <span class="text-primary font-monospace"><%= type %></span> resource for <span class="text-primary font-monospace"><%= controller_name.titleize %></span> has not been configured, please contact your administrator.</p>
6
+ <p>Configure <code><%= controller.class.name %></code> like the example below:</p>
7
+
8
+ <code><pre class="border p-3">class <%= controller.class.name %>
9
+ active_element.<%= type %>_fields :name, :email, :date_of_birth
10
+ end</pre></code>
11
+
12
+ <p>This message is visible in <code>development</code> mode only.</p>
13
+ <% else %>
14
+ <h1>Forbidden</h1>
15
+
16
+ <h2 class="text-danger">Access to this resource has not been configured</h2>
17
+
18
+ <p>The <span class="text-primary font-monospace"><%= type %></span> resource for <span class="text-primary font-monospace"><%= controller_name.titleize %></span> has not been configured, please contact your administrator.</p>
19
+ <% end %>
6
20
 
7
21
  <hr/>
@@ -7,9 +7,17 @@
7
7
  fields: active_element.state.searchable_fields %>
8
8
  <% end %>
9
9
 
10
- <%= active_element.component.table new: active_element.state.creatable?,
11
- show: active_element.state.viewable?,
12
- edit: active_element.state.editable?,
13
- destroy: active_element.state.deletable?,
14
- collection: collection,
15
- fields: active_element.state.listable_fields %>
10
+ <% if active_element.state.search_required && search_filters.compact_blank.blank? %>
11
+ <% if active_element.state.creatable? %>
12
+ <%= active_element.component.new_button(collection.model&.new, float: 'end', class: 'mb-3') %>
13
+ <% end %>
14
+ <%= active_element.component.page_section_title active_element.t('search_required.title') %>
15
+ <%= active_element.component.page_description active_element.t('search_required.description') %>
16
+ <% else %>
17
+ <%= active_element.component.table new: active_element.state.creatable?,
18
+ show: active_element.state.viewable?,
19
+ edit: active_element.state.editable?,
20
+ destroy: active_element.state.deletable?,
21
+ collection: collection,
22
+ fields: active_element.state.listable_fields %>
23
+ <% end %>
@@ -1,6 +1,8 @@
1
1
  <html>
2
2
  <head>
3
3
  <%= render_active_element_hook 'active_element/before_head' %>
4
+ <%= render_active_element_hook 'active_element/favicon' %>
5
+ <%= render_active_element_hook 'active_element/title' %>
4
6
 
5
7
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
6
8
  <link rel="stylesheet"
@@ -48,7 +50,7 @@
48
50
 
49
51
  <%= stylesheet_link_tag 'active_element/application', 'data-turbolinks-track': 'reload' %>
50
52
 
51
- <% if Rails.application.assets.find_asset('application.css').present? %>
53
+ <% if Rails.application.assets&.find_asset('application.css').present? %>
52
54
  <%= stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %>
53
55
  <% end %>
54
56
 
@@ -96,7 +98,7 @@
96
98
  <%= render_active_element_hook 'active_element/after_content' %>
97
99
 
98
100
  <%= javascript_include_tag 'active_element/application', 'data-turbolinks-track': 'reload' %>
99
- <% if Rails.application.assets.find_asset('application.js').present? %>
101
+ <% if Rails.application.assets&.find_asset('application.js').present? %>
100
102
  <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
101
103
  <% end %>
102
104
  </body>
@@ -1,3 +1,6 @@
1
1
  en:
2
2
  active_element:
3
3
  unexpected_error: 'Unexpected error'
4
+ search_required:
5
+ title: 'Apply search filters to view results'
6
+ description: 'This page requires at least one search filter to be applied before results will be displayed.'
@@ -1 +1 @@
1
- 2.7.8
1
+ 3.2.2
data/example_app/Gemfile CHANGED
@@ -2,8 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
4
 
5
- ruby "2.7.8"
6
-
7
5
  gem 'devise'
8
6
  gem 'faker'
9
7
  gem "rails", "~> 7.0.4", ">= 7.0.4.3"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_element (0.0.13)
4
+ active_element (0.0.14)
5
5
  bootstrap (~> 5.3.0alpha3)
6
6
  kaminari (~> 1.2)
7
7
  paintbrush (~> 0.1.2)
@@ -166,6 +166,8 @@ GEM
166
166
  net-smtp (0.3.3)
167
167
  net-protocol
168
168
  nio4r (2.5.9)
169
+ nokogiri (1.15.2-arm64-darwin)
170
+ racc (~> 1.4)
169
171
  nokogiri (1.15.2-x86_64-linux)
170
172
  racc (~> 1.4)
171
173
  orm_adapter (0.5.0)
@@ -234,6 +236,7 @@ GEM
234
236
  actionpack (>= 5.2)
235
237
  activesupport (>= 5.2)
236
238
  sprockets (>= 3.0.0)
239
+ sqlite3 (1.6.3-arm64-darwin)
237
240
  sqlite3 (1.6.3-x86_64-linux)
238
241
  stimulus-rails (1.2.1)
239
242
  railties (>= 6.0.0)
@@ -266,6 +269,7 @@ GEM
266
269
  zeitwerk (2.6.8)
267
270
 
268
271
  PLATFORMS
272
+ arm64-darwin-21
269
273
  x86_64-linux
270
274
 
271
275
  DEPENDENCIES
@@ -289,8 +293,5 @@ DEPENDENCIES
289
293
  web-console
290
294
  webdrivers
291
295
 
292
- RUBY VERSION
293
- ruby 2.7.8p225
294
-
295
296
  BUNDLED WITH
296
297
  2.4.13
@@ -6,7 +6,7 @@ module ActiveElement
6
6
  class Button
7
7
  # rubocop:disable Metrics/MethodLength
8
8
  def initialize(controller, record, flag_or_options, confirm: false, type: :primary, method: nil,
9
- float: nil, icon: nil, **kwargs, &block)
9
+ float: nil, icon: nil, tooltip: false, **kwargs, &block)
10
10
  @controller = controller
11
11
  @record = record.is_a?(ActiveRecord::Relation) ? record.klass.new : record
12
12
  @flag_or_options = flag_or_options
@@ -19,6 +19,7 @@ module ActiveElement
19
19
  @icon = icon
20
20
  @block_given = block_given?
21
21
  @content = block.call if block_given?
22
+ @tooltip = tooltip
22
23
  end
23
24
  # rubocop:enable Metrics/MethodLength
24
25
 
@@ -40,14 +41,15 @@ module ActiveElement
40
41
  kwargs_class: kwargs_class,
41
42
  kwargs: kwargs,
42
43
  content: content,
43
- block_given: block_given
44
+ block_given: block_given,
45
+ tooltip: tooltip
44
46
  }
45
47
  end
46
48
 
47
49
  private
48
50
 
49
51
  attr_reader :controller, :record, :flag_or_options, :float, :kwargs, :kwargs_class, :type, :method, :icon,
50
- :block_given, :content, :confirm
52
+ :block_given, :content, :confirm, :tooltip
51
53
 
52
54
  def link_method
53
55
  return method if method.present?
@@ -60,7 +62,7 @@ module ActiveElement
60
62
  when :destroy
61
63
  'btn-danger destroy-button action-button'
62
64
  when :show
63
- 'btn-primary show-button action-button'
65
+ 'btn-info show-button action-button'
64
66
  when :edit
65
67
  'btn-primary edit-button action-button'
66
68
  when :new
@@ -15,7 +15,7 @@ module ActiveElement
15
15
  # rubocop:disable Metrics/MethodLength
16
16
  def initialize(controller, class_name:, collection:, fields:, params:, model_name: nil, style: nil,
17
17
  show: false, new: false, edit: false, destroy: false, paginate: true, group: nil,
18
- group_title: false, row_class: nil, **_kwargs)
18
+ group_title: false, row_class: nil, title: nil, **_kwargs)
19
19
  @controller = controller
20
20
  @class_name = class_name
21
21
  @model_name = model_name
@@ -31,6 +31,7 @@ module ActiveElement
31
31
  @group = group
32
32
  @group_title = group_title
33
33
  @row_class = row_class
34
+ @title = title
34
35
  verify_paginate_and_group
35
36
  end
36
37
  # rubocop:enable Metrics/MethodLength
@@ -43,6 +44,7 @@ module ActiveElement
43
44
  {
44
45
  component: self,
45
46
  class_name: class_name,
47
+ title: title,
46
48
  collection: group ? collection : paginated_collection,
47
49
  fields: Util::FieldMapping.new(self, fields, class_name).mapped_fields,
48
50
  style: style,
@@ -76,10 +78,10 @@ module ActiveElement
76
78
 
77
79
  attr_reader :class_name, :collection, :fields, :style, :row_class,
78
80
  :new, :show, :edit, :destroy,
79
- :paginate, :params, :group, :group_title
81
+ :paginate, :params, :group, :group_title, :title
80
82
 
81
83
  def paginated_collection
82
- return collection unless paginate && collection.respond_to?(:page)
84
+ return collection unless paginate && collection.respond_to?(:page) && !limit?
83
85
  return collection.page(page_number).per(page_size) if supports_pagination_but_not_yet_paginated?
84
86
 
85
87
  @paginated_collection ||= collection.page(page_number).per(page_size)
@@ -99,6 +101,7 @@ module ActiveElement
99
101
 
100
102
  def display_pagination?
101
103
  return false if group.present?
104
+ return false if limit?
102
105
  return false unless paginate && paginated_collection.respond_to?(:total_count)
103
106
 
104
107
  paginated_collection.total_count > (params[:page_size].presence&.to_i || DEFAULT_PAGE_SIZE)
@@ -120,6 +123,10 @@ module ActiveElement
120
123
 
121
124
  collection.includes(fields.select { |field| collection.model.reflect_on_association(field).present? })
122
125
  end
126
+
127
+ def limit?
128
+ !collection.try(:limit_value).nil?
129
+ end
123
130
  end
124
131
  end
125
132
  end