active_element 0.0.22 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9d94959c19253efbd6ed4d945304d6397d4d1ad1a9aa0d8bd23ef5329559980
4
- data.tar.gz: b3a0d8f7bc1d514c6cca342e7e8fadc37a818497c87ebf5e894c757186ae6b21
3
+ metadata.gz: d4f5dd5354dc376a1a2179ab3f2d95d64ad1bcdbb12811c3f42419311ae9667a
4
+ data.tar.gz: 9e27dcd69d2117ff43a10c4319cdfb8567f49b3a746a8d66960b9071b1481b94
5
5
  SHA512:
6
- metadata.gz: 7a019e911c0d376c2a12f44e5d37ef697cf00a9a11d889c016784a2a3b41df9b0deb17f93c545ee0e2563d5f8a132a9f2c49cb0f900ed4bd926fa361cf67f81b
7
- data.tar.gz: f7e4b9a719611918516bb1d2601eb66eb77f87dc648dffe93cbdf1b5c7c96f829bf76098145e698b27b943fa8331128409ccb8fc089d32c0e8f4b91851afe514
6
+ metadata.gz: d7c47f04a28e066443c39c559c99be9d5ef90da0d130096ab1e1dd6a100ca5eb10c39d72af509ad6f6843526bdfb2613801578738d4f30d5ee267dbe61f2c2b8
7
+ data.tar.gz: ec1c2359b328cdc16de9123282106b851a5e9deac0f11764e6d7fd0356c6fbb898e5be653f5432c89f2bc620c10560b8ba7c670b526b3ab073d9a5cd1394fd68
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_element (0.0.22)
4
+ active_element (0.0.24)
5
5
  bootstrap (~> 5.3.0alpha3)
6
6
  kaminari (~> 1.2)
7
7
  paintbrush (~> 0.1.2)
@@ -150,7 +150,7 @@ GEM
150
150
  mini_mime (1.1.5)
151
151
  mini_portile2 (2.8.2)
152
152
  minitest (5.18.1)
153
- net-imap (0.4.11)
153
+ net-imap (0.4.12)
154
154
  date
155
155
  net-protocol
156
156
  net-pop (0.1.2)
@@ -1,6 +1,8 @@
1
1
  (() => {
2
2
  const cloneElement = (id) => ActiveElement.cloneElement('form', id);
3
3
 
4
+ if (window._active_element_form_loaded) return;
5
+
4
6
  const initModalButtons = () => {
5
7
  document.querySelectorAll('[data-field-type="form-modal"]').forEach((element) => {
6
8
  const formId = element.dataset.formId;
@@ -17,9 +19,10 @@
17
19
 
18
20
  document.body.append(modal);
19
21
 
20
- element.addEventListener('click', () => {
22
+ element.addEventListener('click', (ev) => {
21
23
  wrapper.classList.remove('d-none');
22
24
  bootstrapModal.toggle();
25
+ ev.stopPropagation();
23
26
  return false;
24
27
  });
25
28
  });
@@ -43,4 +46,6 @@
43
46
  initModalButtons();
44
47
  initClearFormButtons();
45
48
  });
49
+
50
+ window._active_element_secrets_loaded = true;
46
51
  })();
@@ -84,7 +84,8 @@
84
84
  field: field,
85
85
  options: options,
86
86
  component: component,
87
- record: record }
87
+ record: record
88
+ }
88
89
  %>
89
90
  <% if type != :hidden_field %></div><% end %>
90
91
  <% end %>
@@ -51,3 +51,10 @@
51
51
  row_class_mapper: row_class_mapper } %>
52
52
  <% end %>
53
53
  <% end %>
54
+
55
+ <% if footer_pagination %>
56
+ <%=
57
+ render partial: 'active_element/components/table/pagination',
58
+ locals: { collection: collection, params: params, page_size: page_size, page_sizes: page_sizes }
59
+ %>
60
+ <% end %>
@@ -122,6 +122,7 @@
122
122
  <%= render_active_element_hook 'active_element/after_content' %>
123
123
 
124
124
  <% if !respond_to?(:javascript_importmap_tags) && Rails.application.assets&.find_asset('application.js').present? %>
125
+ <%= javascript_include_tag 'active_element/active_element', 'data-turbo-track': 'reload', 'data-turbolinks-track': 'reload' %>
125
126
  <%= javascript_include_tag 'application', 'data-turbo-track': 'reload', 'data-turbolinks-track': 'reload' %>
126
127
  <% end %>
127
128
  </body>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_element (0.0.21)
4
+ active_element (0.0.20)
5
5
  bootstrap (~> 5.3.0alpha3)
6
6
  kaminari (~> 1.2)
7
7
  paintbrush (~> 0.1.2)
@@ -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, nested_for: nil, row_class: nil, title: nil, **_kwargs)
18
+ group_title: false, nested_for: nil, row_class: nil, title: nil, footer_pagination: nil, **_kwargs)
19
19
  @controller = controller
20
20
  @class_name = class_name
21
21
  @model_name = model_name
@@ -34,6 +34,7 @@ module ActiveElement
34
34
  @title = title
35
35
  @nested_for = nested_for
36
36
  verify_paginate_and_group
37
+ @footer_pagination = footer_pagination
37
38
  end
38
39
  # rubocop:enable Metrics/MethodLength
39
40
 
@@ -60,7 +61,8 @@ module ActiveElement
60
61
  page_sizes: [5, 10, 25, 50, 75, 100, 200],
61
62
  page_size: page_size,
62
63
  i18n: i18n,
63
- row_class_mapper: row_class_mapper
64
+ row_class_mapper: row_class_mapper,
65
+ footer_pagination: @footer_pagination && display_pagination?
64
66
  }
65
67
  end
66
68
 
@@ -7,7 +7,7 @@ module ActiveElement
7
7
  class Form # rubocop:disable Metrics/ClassLength
8
8
  include Translations
9
9
 
10
- attr_reader :controller
10
+ attr_reader :controller, :search
11
11
 
12
12
  # rubocop:disable Metrics/MethodLength
13
13
  def initialize(controller, fields:, submit:, item:, title: nil, destroy: false, search: false,
@@ -142,7 +142,7 @@ module ActiveElement
142
142
  private
143
143
 
144
144
  attr_reader :fields, :submit, :title, :kwargs, :item, :method, :action,
145
- :destroy, :modal, :columns, :search
145
+ :destroy, :modal, :columns
146
146
 
147
147
  def form_field_mapping
148
148
  @form_field_mapping ||= Util::FormFieldMapping.new(
@@ -231,9 +231,9 @@ module ActiveElement
231
231
 
232
232
  def options_with_inferred_translations(field, options)
233
233
  options.reverse_merge({
234
- label: i18n.label(field),
235
- description: i18n.description(field),
236
- placeholder: i18n.placeholder(field)
234
+ label: i18n.label(field, record: record),
235
+ description: i18n.description(field, record: record),
236
+ placeholder: i18n.placeholder(field, record: record)
237
237
  })
238
238
  end
239
239
 
@@ -267,6 +267,7 @@ module ActiveElement
267
267
  end
268
268
 
269
269
  def required?(field)
270
+ return false if search
270
271
  return false if record.blank?
271
272
  return false unless record.class.respond_to?(:validators)
272
273
 
@@ -15,31 +15,31 @@ module ActiveElement
15
15
  @component = component
16
16
  end
17
17
 
18
- def label(field)
19
- return titleize(field) unless model?
18
+ def label(field, record: nil)
19
+ return titleize(field) unless model?(record)
20
20
 
21
- key = "admin.models.#{model_key}.fields.#{field}.label"
21
+ key = "admin.models.#{model_key(record)}.fields.#{field}.label"
22
22
  ::I18n.t(key, default: titleize(field))
23
23
  end
24
24
 
25
- def description(field)
26
- return nil unless model?
25
+ def description(field, record: nil)
26
+ return nil unless model?(record)
27
27
 
28
- key = "admin.models.#{model_key}.fields.#{field}.description"
28
+ key = "admin.models.#{model_key(record)}.fields.#{field}.description"
29
29
  ::I18n.t(key, default: nil)
30
30
  end
31
31
 
32
- def placeholder(field)
33
- return nil unless model?
32
+ def placeholder(field, record: nil)
33
+ return nil unless model?(record)
34
34
 
35
- key = "admin.models.#{model_key}.fields.#{field}.placeholder"
35
+ key = "admin.models.#{model_key(record)}.fields.#{field}.placeholder"
36
36
  ::I18n.t(key, default: nil)
37
37
  end
38
38
 
39
- def format(field)
40
- return nil unless model?
39
+ def format(field, record: nil)
40
+ return nil unless model?(record)
41
41
 
42
- key = "admin.models.#{model_key}.fields.#{field}.format"
42
+ key = "admin.models.#{model_key(record)}.fields.#{field}.format"
43
43
  ::I18n.t(key, default: nil)
44
44
  end
45
45
 
@@ -47,14 +47,14 @@ module ActiveElement
47
47
 
48
48
  attr_reader :component
49
49
 
50
- def model_key
51
- @model_key ||= component.model.name.underscore.pluralize
50
+ def model_key(record = nil)
51
+ @model_key ||= (record&.class || component.model).name.underscore.pluralize
52
52
  end
53
53
 
54
- def model?
55
- return false if component.model.nil?
54
+ def model?(record = nil)
55
+ return false if record.nil? && component.model.nil?
56
56
 
57
- component.model.is_a?(ActiveModel::Naming)
57
+ (record&.class || component.model).is_a?(ActiveModel::Naming)
58
58
  end
59
59
 
60
60
  def titleize(field)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveElement
4
- VERSION = '0.0.22'
4
+ VERSION = '0.0.24'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_element
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-29 00:00:00.000000000 Z
11
+ date: 2024-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap