active_element 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb1aee3153ca04daa45cd99c868afb986df934e6a84e1be8675fcb01d9ed5097
4
- data.tar.gz: 060f791791440d2d0d880384bd2bfd2c6d6724041bd2451035521f8f8ddd954a
3
+ metadata.gz: 400b6c6c72f4bf41706eb1266704d9c7ae5a9807969ceb069dce935387db8012
4
+ data.tar.gz: 716241936a61a2bab52158b538d50ea48880af24f38b0d292f2a2c581a180361
5
5
  SHA512:
6
- metadata.gz: c9b7a77759b27826038b895f9acc941620d4477192c22c0a13dc33ba03b64c61e292ff94520fc3ff7c2dc0abeb409483aa1f86aa3268e4e271fb3810d558e9e4
7
- data.tar.gz: 652d599381d599a7186c654c49c87d3d7eca73c6373241b3900bd7c9c61718efa715ea83f32dfff6b9951ee7a737f79629440bf9b16c1858cedf235e94eed52e
6
+ metadata.gz: 1cc434c86434948327d8b1c768883a8a806a3440ddc866087627abcd576a777bdc0bab24cd91330336819bf8e12937c144da29d479b8dc1419bb28e6f7ee3dcc
7
+ data.tar.gz: 0fc355d84b115702c99a162b2f2df2d8728948b192fe643a99db6bbd0abb58d085ede47af66f087f714bdd24731d8a82637b9bb6998e12be2d7c14a643703d4a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_element (0.0.15)
4
+ active_element (0.0.16)
5
5
  bootstrap (~> 5.3.0alpha3)
6
6
  kaminari (~> 1.2)
7
7
  paintbrush (~> 0.1.2)
@@ -150,14 +150,14 @@ 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.8)
153
+ net-imap (0.4.9.1)
154
154
  date
155
155
  net-protocol
156
156
  net-pop (0.1.2)
157
157
  net-protocol
158
158
  net-protocol (0.2.2)
159
159
  timeout
160
- net-smtp (0.4.0)
160
+ net-smtp (0.4.0.1)
161
161
  net-protocol
162
162
  nio4r (2.7.0)
163
163
  nokogiri (1.15.2)
@@ -1,2 +1,2 @@
1
- //= link active_element/application.js
2
- //= link active_element/application.css
1
+ //= link active_element/active_element.js
2
+ //= link active_element/active_element.css
@@ -1,4 +1,3 @@
1
- //= require rails-ujs
2
1
  //= require bootstrap
3
2
  //= require active_element/setup
4
3
  //= require active_element/theme
@@ -1,7 +1,7 @@
1
1
  (() => {
2
2
  const cloneElement = (id) => ActiveElement.cloneElement('form', id);
3
3
 
4
- window.addEventListener('DOMContentLoaded', () => {
4
+ window.addEventListener(ActiveElement.reloadEvent, () => {
5
5
  const confirmLinks = document.querySelectorAll('[data-confirm-action="true"]');
6
6
 
7
7
  confirmLinks.forEach((element) => {
@@ -39,7 +39,7 @@
39
39
  });
40
40
  };
41
41
 
42
- window.addEventListener('DOMContentLoaded', () => {
42
+ window.addEventListener(ActiveElement.reloadEvent, () => {
43
43
  initModalButtons();
44
44
  initClearFormButtons();
45
45
  });
@@ -602,7 +602,7 @@ ActiveElement.JsonField = (() => {
602
602
  })();
603
603
 
604
604
  (() => {
605
- window.addEventListener('DOMContentLoaded', () => {
605
+ window.addEventListener(ActiveElement.reloadEvent, () => {
606
606
  document.querySelectorAll('.json-field').forEach((element) => {
607
607
  ActiveElement.JsonField(element);
608
608
  });
@@ -1,5 +1,5 @@
1
1
  (() => {
2
- window.addEventListener('DOMContentLoaded', () => {
2
+ window.addEventListener(ActiveElement.reloadEvent, () => {
3
3
  const paginationSelect = document.querySelector('#collection-table-page-size-selector');
4
4
 
5
5
  if (paginationSelect) {
@@ -1,5 +1,5 @@
1
1
  (() => {
2
- window.addEventListener('DOMContentLoaded', () => {
2
+ window.addEventListener(ActiveElement.reloadEvent, () => {
3
3
  const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
4
4
  const popoverList = popoverTriggerList.map(function (element) {
5
5
  return new bootstrap.Popover(element)
@@ -1,7 +1,7 @@
1
1
  (() => {
2
2
  const cloneElement = (id) => ActiveElement.cloneElement('secret', id);
3
3
 
4
- window.addEventListener('DOMContentLoaded', () => {
4
+ window.addEventListener(ActiveElement.reloadEvent, () => {
5
5
  document.querySelectorAll('span[data-field-type="secret"]').forEach((element) => {
6
6
  const secret = element.dataset.secret;
7
7
  const showButton = cloneElement('show-button');
@@ -33,6 +33,7 @@
33
33
 
34
34
  const ActiveElement = {
35
35
  debug: false,
36
+ reloadEvent: window.ActiveElement.turbo ? 'turbo:load' : 'DOMContentLoaded',
36
37
  log: {
37
38
  debug: (message) => { ActiveElement.debug && console.log(`[ActiveElement:debug]`, message); },
38
39
  info: (message) => { console.log(`[ActiveElement:info] ${message}`); },
@@ -47,7 +48,7 @@
47
48
  controller_path: document.querySelector('meta[name="active_element_controller_path"]').content
48
49
  };
49
50
 
50
- window.ActiveElement = ActiveElement;
51
+ window.ActiveElement = { ...(window.ActiveElement || {}), ...ActiveElement };
51
52
  })();
52
53
 
53
54
  ActiveElement.log.info('Initialized');
@@ -58,7 +58,7 @@
58
58
  }
59
59
  };
60
60
 
61
- window.addEventListener('DOMContentLoaded', () => {
61
+ window.addEventListener(ActiveElement.reloadEvent, () => {
62
62
  document.querySelectorAll('[data-field-type="text-search"]').forEach((element) => {
63
63
  const id = element.id;
64
64
  const hiddenId = `${id}-hidden-value`;
@@ -1,7 +1,7 @@
1
1
  (() => {
2
2
  const cloneElement = (id) => ActiveElement.cloneElement('theme', id);
3
3
 
4
- window.addEventListener('DOMContentLoaded', () => {
4
+ window.addEventListener(ActiveElement.reloadEvent, () => {
5
5
  const themeSelect = document.querySelector('#theme-select');
6
6
 
7
7
  const setTheme = (theme) => {
@@ -1,5 +1,5 @@
1
1
  (() => {
2
- window.addEventListener('DOMContentLoaded', () => {
2
+ window.addEventListener(ActiveElement.reloadEvent, () => {
3
3
  const timezoneOffset = new Date().getTimezoneOffset();
4
4
  document.cookie = `timezone_offset=${timezoneOffset};`;
5
5
  });
@@ -1,9 +1,24 @@
1
1
  <html>
2
2
  <head>
3
+ <script>
4
+ window.ActiveElement = window.ActiveElement || {};
5
+ </script>
6
+
3
7
  <%= render_active_element_hook 'active_element/before_head' %>
4
8
  <%= render_active_element_hook 'active_element/favicon' %>
5
9
  <%= render_active_element_hook 'active_element/title' %>
6
10
 
11
+ <% if respond_to?(:javascript_importmap_tags) %>
12
+ <%= javascript_importmap_tags %>
13
+ <script>
14
+ window.ActiveElement.turbo = true;
15
+ </script>
16
+ <% else %>
17
+ <script>
18
+ window.ActiveElement.turbo = false;
19
+ </script>
20
+ <% end %>
21
+
7
22
  <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" />
8
23
  <link rel="stylesheet"
9
24
  href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
@@ -48,16 +63,16 @@
48
63
  window.ActiveElement = window.ActiveElement || {};
49
64
  </script>
50
65
 
51
- <%= stylesheet_link_tag 'active_element/application', 'data-turbolinks-track': 'reload' %>
66
+ <%= csrf_meta_tag %>
67
+ <meta name="active_element_controller_path" content="<%= controller_path %>">
68
+
69
+ <%= stylesheet_link_tag 'active_element/active_element' %>
70
+ <%= javascript_include_tag 'active_element/active_element' %>
52
71
 
53
72
  <% if Rails.application.assets&.find_asset('application.css').present? %>
54
- <%= stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %>
73
+ <%= stylesheet_link_tag 'application' %>
55
74
  <% end %>
56
75
 
57
- <%= csrf_meta_tag %>
58
-
59
- <meta name="active_element_controller_path" content="<%= controller_path %>">
60
-
61
76
  <%= render_active_element_hook 'active_element/after_head' %>
62
77
  </head>
63
78
 
@@ -97,9 +112,10 @@
97
112
 
98
113
  <%= render_active_element_hook 'active_element/after_content' %>
99
114
 
100
- <%= javascript_include_tag 'active_element/application', 'data-turbolinks-track': 'reload' %>
101
- <% if Rails.application.assets&.find_asset('application.js').present? %>
102
- <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
115
+ <% if !respond_to?(:javascript_importmap_tags) && Rails.application.assets&.find_asset('application.js').present? %>
116
+ <%= javascript_include_tag 'active_element/active_element', 'data-turbo-track': 'reload', 'data-turbolinks-track': 'reload' %>
117
+ <%= javascript_include_tag 'application', 'data-turbo-track': 'reload', 'data-turbolinks-track': 'reload' %>
103
118
  <% end %>
119
+
104
120
  </body>
105
121
  </html>
@@ -144,8 +144,6 @@ module ActiveElement
144
144
  end
145
145
 
146
146
  nil
147
- rescue
148
- byebug
149
147
  end
150
148
 
151
149
  def link_to(value)
@@ -90,6 +90,7 @@ module ActiveElement
90
90
  end
91
91
 
92
92
  def default_record_path
93
+ return record.controller_name.constantize.controller_path.underscore.singularize.tr('/', '_') + '_path' if record.try(:controller_name).present?
93
94
  "#{record_path_prefix}#{namespace_prefix}#{record_name}_path"
94
95
  end
95
96
 
@@ -52,6 +52,10 @@ module ActiveElement
52
52
  state.deletable = true
53
53
  end
54
54
 
55
+ def model=(model)
56
+ state.model = model.constantize
57
+ end
58
+
55
59
  def application_name
56
60
  RailsComponent.new(::Rails).application_name
57
61
  end
@@ -8,7 +8,7 @@ module ActiveElement
8
8
  attr_reader :permissions, :listable_fields, :viewable_fields, :editable_fields, :searchable_fields,
9
9
  :field_options
10
10
  attr_accessor :sign_in_path, :sign_in, :sign_in_method, :sign_out_path, :sign_out_method,
11
- :deletable, :authorizor, :authenticator, :list_order, :search_required
11
+ :deletable, :authorizor, :authenticator, :list_order, :search_required, :model
12
12
 
13
13
  def initialize(controller:)
14
14
  @controller = controller
@@ -21,6 +21,7 @@ module ActiveElement
21
21
  @editable_fields = []
22
22
  @searchable_fields = []
23
23
  @field_options = {}
24
+ @model = nil
24
25
  end
25
26
 
26
27
  def deletable?
@@ -116,7 +116,7 @@ module ActiveElement
116
116
  end
117
117
 
118
118
  def model
119
- controller.controller_name.classify.constantize
119
+ state.model || controller.controller_name.classify.constantize
120
120
  end
121
121
 
122
122
  def record
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveElement
4
- VERSION = '0.0.15'
4
+ VERSION = '0.0.17'
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.15
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-14 00:00:00.000000000 Z
11
+ date: 2024-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap
@@ -113,7 +113,7 @@ files:
113
113
  - Rakefile
114
114
  - active_element.gemspec
115
115
  - app/assets/config/active_element/manifest.js
116
- - app/assets/javascripts/active_element/application.js
116
+ - app/assets/javascripts/active_element/active_element.js
117
117
  - app/assets/javascripts/active_element/confirm.js
118
118
  - app/assets/javascripts/active_element/form.js
119
119
  - app/assets/javascripts/active_element/highlight.js
@@ -128,7 +128,7 @@ files:
128
128
  - app/assets/javascripts/active_element/toast.js
129
129
  - app/assets/stylesheets/active_element/_dark.scss
130
130
  - app/assets/stylesheets/active_element/_variables.scss
131
- - app/assets/stylesheets/active_element/application.scss
131
+ - app/assets/stylesheets/active_element/active_element.scss
132
132
  - app/controllers/active_element/application_controller.rb
133
133
  - app/controllers/concerns/active_element/default_controller_actions.rb
134
134
  - app/views/active_element/_title.html.erb