active_scaffold 4.4.1 → 4.4.4

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: 62f92c20382d4b5a33b53bb1525e677d81259a2d89a51996caefcb68ab314ed2
4
- data.tar.gz: 2b8b5f59b6bdf856af6bdb4cfd5697caca0095960c41278bdb16ea5d51e0d03b
3
+ metadata.gz: b212c764ce6307b7968f811cd89c2042b8cb5d1f79b448ddd838360efc8375ab
4
+ data.tar.gz: 4f44ea2e0e00189d67f4027e95decea8b3589e5f3d372d1c53cd289ca70188c7
5
5
  SHA512:
6
- metadata.gz: cffce904d4531775442f630fe004153a6ff602fdf7d1d416601712038324d0ad27b75c0e075dca01cefe0cc05d103769de538c2295ae5ab0d670a85944bf59c7
7
- data.tar.gz: d7b32cbea9ac2da0d506de89ccd6dd5fbfefd7f3565780e4c93d97308bf2e1808d3a4bf396e63d7f7aeaedef7b72efaa2dd03c1d9f63fb7f49390a23382e8bdf
6
+ metadata.gz: 264149ca1905e0bae13b93a71a3720d9e09d3b2bae57b15a702474dfb40d2d8fad33ea04a8708991d6c983ef6c45159a5fd7133ad143cf95e3d5c74f5b830a34
7
+ data.tar.gz: b8bf1c62d6fc8e9063ccb46df88709630a0ce6d1eb9edebcb3058df8e43535f7e0420a4781614bd479197f00f5cdcce423bf1298b15ddd264515701fa7c83b03
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,14 @@
1
+ = 4.4.4
2
+ - Fix the inconsistent behaviour for constraints containing an array with only one value
3
+ - Wait for dynamically loaded plugins and bridges to finish registering their ready and setup callbacks before initial setup, fixing initialization on directly rendered forms
4
+ - Show all association records in select and multi-select search UIs instead of applying form association conditions
5
+
6
+ = 4.4.3 (yanked)
7
+ - Yanked because it accidentally included unreleased 4.5 functionality
8
+
9
+ = 4.4.2 (yanked)
10
+ - Yanked because it accidentally included unreleased 4.5 functionality
11
+
1
12
  = 4.4.1
2
13
  - Avoid unnecessary DISTINCT in searches without joins or with only belongs_to joins, fixing PostgreSQL searches on models with json columns
3
14
  - Update install generator for the supported rails versions and asset pipelines
@@ -1695,8 +1695,10 @@
1695
1695
 
1696
1696
  // call setup on document.ready if Turbolinks not enabled
1697
1697
  if ((typeof(Turbolinks) == 'undefined' || !Turbolinks.supported) && typeof(Turbo) == 'undefined') {
1698
- ActiveScaffold.setup_history_state();
1699
- ActiveScaffold.setup(document);
1698
+ if (!ActiveScaffold.config.deferInitialSetup) {
1699
+ ActiveScaffold.setup_history_state();
1700
+ ActiveScaffold.setup(document);
1701
+ }
1700
1702
  }
1701
1703
  if (ActiveScaffold.config.warn_changes) ActiveScaffold.setup_warn_changes();
1702
1704
  jQuery(document).on('as:element_updated as:element_created', function(e, action_link) {
@@ -1732,7 +1734,7 @@
1732
1734
  });
1733
1735
 
1734
1736
  jQuery(document).on('turbolinks:load turbo:load', function($) {
1735
- ActiveScaffold.setup(document);
1737
+ if (!ActiveScaffold.config.deferInitialSetup) ActiveScaffold.setup(document);
1736
1738
  });
1737
1739
  jQuery(window).on('scroll resize', ActiveScaffold.update_floating_form_footer);
1738
1740
  };
@@ -1,6 +1,10 @@
1
1
  // ActiveScaffold main entry point
2
2
  (function() {
3
3
  const config = window.ActiveScaffold?.config || {};
4
+ config.deferInitialSetup = true;
5
+ const scriptLoads = new Map();
6
+ const readyHeld = typeof window.jQuery?.holdReady === 'function';
7
+ if (readyHeld) window.jQuery.holdReady(true);
4
8
 
5
9
  // Load dependencies based on configuration
6
10
  const loadDependencies = async () => {
@@ -17,23 +21,14 @@
17
21
  await loadScript(RAILS_ASSET_URL('/active_scaffold/active_scaffold.js'));
18
22
  await loadScript(RAILS_ASSET_URL('/active_scaffold/jquery.editinplace.js'));
19
23
 
20
- // Load plugins
21
- if (config.plugins) {
22
- for (const plugin of config.plugins) {
23
- await loadScript(plugin);
24
- }
25
- }
26
-
27
- // Load bridges
28
- if (config.bridges) {
29
- for (const bridge of config.bridges) {
30
- await loadScript(bridge);
31
- }
32
- }
24
+ // Load plugins and bridges in order. Some of them depend on scripts loaded
25
+ // before them and register callbacks while they are being evaluated.
26
+ await loadScripts(config.plugins);
27
+ await loadScripts(config.bridges);
33
28
 
34
29
  // ALL DEPENDENCIES ARE LOADED NOW
35
30
  // Initialize everything
36
- initializeActiveScaffold();
31
+ await initializeActiveScaffold();
37
32
  };
38
33
 
39
34
  const loadJQueryUI = async () => {
@@ -57,8 +52,16 @@
57
52
  initializeJQueryUI();
58
53
  };
59
54
 
55
+ const loadScripts = async (paths = []) => {
56
+ for (const path of paths || []) {
57
+ await loadScript(path);
58
+ }
59
+ };
60
+
60
61
  const loadScript = (path) => {
61
- return new Promise((resolve, reject) => {
62
+ if (scriptLoads.has(path)) return scriptLoads.get(path);
63
+
64
+ const promise = new Promise((resolve, reject) => {
62
65
  // Check if already loaded
63
66
  if (document.querySelector(`script[src*="${path}"]`)) {
64
67
  resolve();
@@ -72,6 +75,9 @@
72
75
  script.onerror = reject;
73
76
  document.head.appendChild(script);
74
77
  });
78
+
79
+ scriptLoads.set(path, promise);
80
+ return promise;
75
81
  };
76
82
 
77
83
  const initializeJQueryUI = function() {
@@ -100,13 +106,26 @@
100
106
  }
101
107
  };
102
108
 
103
- // NEW: Initialize everything after all scripts are loaded
104
- const initializeActiveScaffold = () => {
105
- // Run any post-load initialization
106
- if (window.jQuery) {
107
- jQuery(document).trigger('active-scaffold:loaded');
109
+ // Initialize only after plugins and bridges are available. This is especially
110
+ // important when this file is loaded as a regular script after DOM ready.
111
+ const initializeActiveScaffold = () => new Promise((resolve) => {
112
+ if (!window.jQuery || !window.ActiveScaffold) {
113
+ resolve();
114
+ return;
108
115
  }
109
- };
116
+
117
+ jQuery(function() {
118
+ config.deferInitialSetup = false;
119
+ if ((typeof(Turbolinks) == 'undefined' || !Turbolinks.supported) && typeof(Turbo) == 'undefined') {
120
+ ActiveScaffold.setup_history_state();
121
+ }
122
+ ActiveScaffold.setup(document);
123
+ jQuery(document).trigger('active-scaffold:loaded');
124
+ resolve();
125
+ });
126
+
127
+ if (readyHeld) window.jQuery.holdReady(false);
128
+ });
110
129
 
111
130
  // Start loading when DOM is ready
112
131
  if (document.readyState === 'loading') {
@@ -114,4 +133,4 @@
114
133
  } else {
115
134
  loadDependencies();
116
135
  }
117
- })();
136
+ })();
@@ -163,8 +163,9 @@ module ActiveScaffold
163
163
  elsif association.polymorphic?
164
164
  apply_constraint_on_polymorphic_association(record, association, value)
165
165
  elsif !association.source_reflection&.through? && # regular singular association, or one-level through association
166
- !value.is_a?(Array)
167
- record.send(:"#{association.name}=", association.klass.find(value))
166
+ (!value.is_a?(Array) || value.size == 1)
167
+ constraint_value = value.is_a?(Array) ? value.first : value
168
+ record.send(:"#{association.name}=", association.klass.find(constraint_value))
168
169
 
169
170
  # setting the belongs_to side of a has_one isn't safe. if the has_one was already
170
171
  # specified, rails won't automatically clear out the previous associated record.
@@ -93,7 +93,7 @@ module ActiveScaffold
93
93
  associated.collect!(&:to_i)
94
94
  method = ui_options[:label_method] || :to_label
95
95
  helper_method = association_helper_method(column.association, :sorted_association_options_find)
96
- select_options = send(helper_method, column.association, nil, record).collect do |r|
96
+ select_options = send(helper_method, column.association, {}, record).collect do |r|
97
97
  [r.send(method), r.id]
98
98
  end
99
99
  else
@@ -119,7 +119,7 @@ module ActiveScaffold
119
119
  associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
120
120
  method = column.association.belongs_to? ? column.association.foreign_key : column.name
121
121
  helper_method = association_helper_method(column.association, :sorted_association_options_find)
122
- select_options = send(helper_method, column.association, false, record)
122
+ select_options = send(helper_method, column.association, {}, record)
123
123
  else
124
124
  method = column.name
125
125
  select_options = active_scaffold_translated_enum_options(column, record, ui_options: ui_options)
@@ -4,7 +4,7 @@ module ActiveScaffold
4
4
  module Version
5
5
  MAJOR = 4
6
6
  MINOR = 4
7
- PATCH = 1
7
+ PATCH = 4
8
8
  FIX = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, FIX].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README