brick 1.0.253 → 1.0.254

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: 23f8352ed61f4850362135926a1a1e407297021aefeef6eca84caa3cabe4b649
4
- data.tar.gz: 5dc89b848cc8f7607d043d7ee5e7e4f2e320abfe1f0f7e046ca129f9458ba869
3
+ metadata.gz: 18c3ed9012a36ba6b8df6d62f34a41b4fd7d8fbebe8580c3b961ea1a6643ef0b
4
+ data.tar.gz: 7355cb7700fea0f61f2e44eec2e7919246d963afca8e4f1904273a72006ad3dc
5
5
  SHA512:
6
- metadata.gz: 73220fc9aed649d42514715e8be0085a1e04639f33007e7b142adbed985c2b54bb4f99a232a26b9659d53702c957a7cf704af57c951d7a761d74033df9d2a89f
7
- data.tar.gz: d794342f7836f29fdd0a1a8f79eb9f5c7cac40a252c7d3654fd712723a1a8fc3df08bb25864377d35755cc65a9b1d777eb86f1312f63a121314cf62033df8f85
6
+ metadata.gz: 16dc56a8516865c4c7f594cdf1d571fc831bc31916e9f6827edd3eff2c00ea51048500c500fc421407bcbdf0c46fec75ee1bd60f1244f449418571501eaf878a
7
+ data.tar.gz: 53b2c141cf2f7819c640db261915d01eb85153486a7b3d848b43f3fd4e735b710f55df3f3eb48792ab54446ca536112067df826d58545508109bbbbe6f2d32cf
@@ -28,6 +28,9 @@ if ActiveRecord.version < ::Gem::Version.new('6.0a') && ::Gem::Version.new(RUBY_
28
28
  end
29
29
  end
30
30
 
31
+ # Allow ActiveSupport >= 6.0 to work along with newer versions of the concurrent-ruby gem
32
+ require 'logger' if Gem.loaded_specs['concurrent-ruby']&.version >= ::Gem::Version.new('1.3.5') && Gem.loaded_specs['logger']
33
+
31
34
  # Allow ActiveRecord < 3.2 to work with Ruby 2.7 and later
32
35
  if ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('2.7')
33
36
  if ActiveRecord.version < ::Gem::Version.new('3.2')
@@ -119,7 +122,7 @@ if Object.const_defined?('ActionPack') && !ActionPack.respond_to?(:version)
119
122
  end
120
123
  end
121
124
  end
122
- if Object.const_defined?('Bundler') && Bundler.locked_gems&.dependencies&.key?('action_view')
125
+ if Gem.loaded_specs['actionview']
123
126
  require 'action_view' # Needed for Rails <= 4.0
124
127
  module ::ActionView
125
128
  if Object.const_defined?('ActionView') && !ActionView.respond_to?(:version)
@@ -183,3 +186,27 @@ if ActiveRecord.version < ::Gem::Version.new('5.0') && ::Gem::Version.new(RUBY_V
183
186
  end
184
187
  end
185
188
  end
189
+
190
+ # In ActiveSupport older than 8.1, the quirks_mode keyword argument is passed when #to_json is called. This is
191
+ # incompatible with the JSON gem v3.0 and newer.
192
+ if Object.const_defined?('ActiveSupport') && ActiveRecord.version < ::Gem::Version.new('8.1') && Gem.loaded_specs['json'].version >= ::Gem::Version.new('3.0')
193
+ module ActiveSupport::JSON
194
+ class << self
195
+ def decode(json)
196
+ data = ::JSON.parse(json)
197
+
198
+ if ActiveSupport.parse_json_times
199
+ convert_dates_from(data)
200
+ else
201
+ data
202
+ end
203
+ end
204
+ end
205
+ Encoding::JSONGemEncoder.class_exec do
206
+ private
207
+ def stringify(jsonified)
208
+ ::JSON.generate(jsonified, max_nesting: false)
209
+ end
210
+ end
211
+ end
212
+ end
@@ -1165,7 +1165,7 @@ if (window.brickFontFamily) {
1165
1165
  end
1166
1166
  %><%= if (page_num = @#{res_name}&._brick_page_num)
1167
1167
  \"<tr><td colspan=\\\"#\{td_count}\\\">Page #\{page_num}</td></tr>\".html_safe
1168
- end %></table>#{template_link}<%
1168
+ end %></table><%
1169
1169
  if description.present? %><span class=\"__brick\"><%=
1170
1170
  description %></span><br><%
1171
1171
  end
@@ -1583,8 +1583,79 @@ end}
1583
1583
  puts "Couldn't work with action #{args.first}"
1584
1584
  end
1585
1585
  end
1586
+
1587
+
1588
+ case representation
1589
+ when :grid
1590
+ inline << "<script<%= @_request.env['_brick_nonce'] %>>
1591
+ <%# Make column headers sort when clicked
1592
+ # %%% Create a smart javascript routine which can do this client-side %>
1593
+ [... document.getElementsByTagName(\"TH\")].forEach(function (th) {
1594
+ th.addEventListener(\"click\", function (e) {
1595
+ var xOrder,
1596
+ currentOrder;
1597
+ if (xOrder = this.getAttribute(\"x-order\")) {
1598
+ if ((currentOrder = changeout(location.href, \"_brick_order\")) === xOrder)
1599
+ xOrder = \"-\" + xOrder;
1600
+ location.href = changeout(location.href, \"_brick_order\", xOrder);
1601
+ }
1602
+ });
1603
+ });
1604
+ </script>"
1605
+ when :show
1606
+ inline << "<script<%= @_request.env['_brick_nonce'] %>>
1607
+ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1608
+ var origVal = getInpVal(),
1609
+ prevVal = origVal;
1610
+ var revert;
1611
+ if (inp.getAttribute(\"type\") == \"hidden\" || inp.getAttribute(\"type\") == \"submit\") return;
1612
+
1613
+ var svgTd = null;
1614
+ if ((revert = ((inp.tagName === \"SELECT\" && (svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild) ||
1615
+ ((svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild))
1616
+ ) && revert.tagName.toLowerCase() === \"svg\")
1617
+ revert.addEventListener(\"click\", function (e) {
1618
+ if (inp.type === \"checkbox\")
1619
+ inp.checked = origVal;
1620
+ else
1621
+ inp.value = origVal;
1622
+ revert.style.display = \"none\";
1623
+ if (inp._flatpickr)
1624
+ inp._flatpickr.setDate(origVal);
1625
+ else
1626
+ inp.focus();
1627
+ });
1628
+ inp.addEventListener(inp.type === \"checkbox\" ? \"change\" : \"input\", function (e) {
1629
+ if(inp.className.split(\" \").indexOf(\"check-validity\") > 0) {
1630
+ if (inp.checkValidity()) {
1631
+ prevVal = getInpVal();
1632
+ } else {
1633
+ inp.value = prevVal;
1634
+ }
1635
+ } else {
1636
+ // If this is the result of changing an hour or minute, keep the calendar open.
1637
+ // And if it was the result of selecting a date, the calendar can now close.
1638
+ if (inp._flatpickr &&
1639
+ // Test only for changes in the date portion of a date or datetime
1640
+ ((giv = getInpVal()) && (giv1 = giv.split(' ')[0])) !== (prevVal && prevVal.split(' ')[0]) &&
1641
+ giv1.indexOf(\":\") < 0 // (definitely not any part of a time thing)
1642
+ )
1643
+ inp._flatpickr.close();
1644
+ prevVal = getInpVal();
1645
+ }
1646
+ // Show or hide the revert button
1647
+ if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"block\";
1648
+ });
1649
+ function getInpVal() {
1650
+ return inp.type === \"checkbox\" ? inp.checked : inp.value;
1651
+ }
1652
+ });
1653
+ </script>"
1654
+ end
1655
+
1656
+
1586
1657
  unless is_crosstab
1587
- inline << "
1658
+ inline << "#{template_link}
1588
1659
  <% if @_date_fields_present %>
1589
1660
  <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css\">
1590
1661
  <style>
@@ -1709,73 +1780,6 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1709
1780
  %></script>
1710
1781
  <% end %>
1711
1782
  "
1712
- end
1713
- case representation
1714
- when :grid
1715
- inline << "<script<%= @_request.env['_brick_nonce'] %>>
1716
- <%# Make column headers sort when clicked
1717
- # %%% Create a smart javascript routine which can do this client-side %>
1718
- [... document.getElementsByTagName(\"TH\")].forEach(function (th) {
1719
- th.addEventListener(\"click\", function (e) {
1720
- var xOrder,
1721
- currentOrder;
1722
- if (xOrder = this.getAttribute(\"x-order\")) {
1723
- if ((currentOrder = changeout(location.href, \"_brick_order\")) === xOrder)
1724
- xOrder = \"-\" + xOrder;
1725
- location.href = changeout(location.href, \"_brick_order\", xOrder);
1726
- }
1727
- });
1728
- });
1729
- </script>"
1730
- when :show
1731
- inline << "<script<%= @_request.env['_brick_nonce'] %>>
1732
- document.querySelectorAll(\"input, select\").forEach(function (inp) {
1733
- var origVal = getInpVal(),
1734
- prevVal = origVal;
1735
- var revert;
1736
- if (inp.getAttribute(\"type\") == \"hidden\" || inp.getAttribute(\"type\") == \"submit\") return;
1737
-
1738
- var svgTd = null;
1739
- if ((revert = ((inp.tagName === \"SELECT\" && (svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild) ||
1740
- ((svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild))
1741
- ) && revert.tagName.toLowerCase() === \"svg\")
1742
- revert.addEventListener(\"click\", function (e) {
1743
- if (inp.type === \"checkbox\")
1744
- inp.checked = origVal;
1745
- else
1746
- inp.value = origVal;
1747
- revert.style.display = \"none\";
1748
- if (inp._flatpickr)
1749
- inp._flatpickr.setDate(origVal);
1750
- else
1751
- inp.focus();
1752
- });
1753
- inp.addEventListener(inp.type === \"checkbox\" ? \"change\" : \"input\", function (e) {
1754
- if(inp.className.split(\" \").indexOf(\"check-validity\") > 0) {
1755
- if (inp.checkValidity()) {
1756
- prevVal = getInpVal();
1757
- } else {
1758
- inp.value = prevVal;
1759
- }
1760
- } else {
1761
- // If this is the result of changing an hour or minute, keep the calendar open.
1762
- // And if it was the result of selecting a date, the calendar can now close.
1763
- if (inp._flatpickr &&
1764
- // Test only for changes in the date portion of a date or datetime
1765
- ((giv = getInpVal()) && (giv1 = giv.split(' ')[0])) !== (prevVal && prevVal.split(' ')[0]) &&
1766
- giv1.indexOf(\":\") < 0 // (definitely not any part of a time thing)
1767
- )
1768
- inp._flatpickr.close();
1769
- prevVal = getInpVal();
1770
- }
1771
- // Show or hide the revert button
1772
- if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"block\";
1773
- });
1774
- function getInpVal() {
1775
- return inp.type === \"checkbox\" ? inp.checked : inp.value;
1776
- }
1777
- });
1778
- </script>"
1779
1783
  end
1780
1784
  # puts "==============="
1781
1785
  # puts inline
@@ -7,7 +7,8 @@ module Brick::Rails::FormBuilder
7
7
  # @_date_fields_present - To include flatpickr date / time editor
8
8
  # @_json_fields_present - To include JSONEditor
9
9
  def brick_field(method, html_options = {}, val = nil, col = nil,
10
- bt = nil, bt_class = nil, bt_name = nil, bt_pair = nil)
10
+ bt = nil, bt_class = nil, bt_name = nil, bt_pair = nil,
11
+ is_readonly = nil)
11
12
  model = self.object.class
12
13
  col ||= model.columns_hash[method.to_s]
13
14
  out = +'<table><tr><td>'
@@ -20,8 +21,6 @@ module Brick::Rails::FormBuilder
20
21
  bt_name ||= bt[1].map { |x| x.first.name }.join('/')
21
22
  bt_pair ||= bt[1].first
22
23
 
23
- html_options[:prompt] = "Select #{bt_name}"
24
- out << self.select(method_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options)
25
24
  bt_obj = nil
26
25
  begin
27
26
  bt_obj = bt_class&.find_by(bt_pair[1] => val)
@@ -29,6 +28,10 @@ module Brick::Rails::FormBuilder
29
28
  # %%% Would be cool to indicate to the user that a subclass is missing.
30
29
  # Its name starts at: e.message.index('failed to locate the subclass: ') + 31
31
30
  end
31
+ html_options[:prompt] = "Select #{bt_name}"
32
+ out << (is_readonly ? (bt_obj&.brick_descrip || val.to_s) + '&nbsp;' :
33
+ self.select(method_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options)
34
+ )
32
35
  bt_link = if bt_obj
33
36
  bt_path = template.send(
34
37
  "#{bt_class.base_class._brick_index(:singular)}_path".to_sym,
@@ -367,13 +367,14 @@ module Brick::Rails::FormTags
367
367
  </th>
368
368
  <td>
369
369
  "
370
- if pk_pos &&
370
+ if !pk_pos || bt ||
371
371
  # Allow new records to have a text-based primary key to be entered
372
- (!obj.new_record? || [:string, :text].exclude?(col.type))
373
- out << val.to_s
374
- else
372
+ (pk_pos && obj.new_record? && [:string, :text].include?(col.type))
375
373
  has_updatable_fields = true
376
- out << f.brick_field(k, html_options = {}, val, col, bt, bt_class, bt_name, bt_pair)
374
+ out << f.brick_field(k, html_options = {}, val, col, bt, bt_class, bt_name, bt_pair,
375
+ pk_pos && !obj.new_record?) # Cause it to be read-only if it's part of a primary key
376
+ else
377
+ out << val.to_s
377
378
  end
378
379
  out << "
379
380
  </td>
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 253
8
+ TINY = 254
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -52,14 +52,14 @@ if ActiveRecord.version >= ::Gem::Version.new('4') && ActiveRecord.version < ::G
52
52
  [
53
53
  # Change 1 - Line 904
54
54
  ['build_joins(arel, joins_values.flatten) unless joins_values.empty?',
55
- "build_joins(arel, joins_values.flatten) unless joins_values.empty?
55
+ "build_joins(arel, joins_values.flatten) unless joins_values.empty?
56
56
  build_left_outer_joins(arel, left_outer_joins_values.flatten) unless left_outer_joins_values.empty?"
57
57
  ],
58
58
  # Change 2 - Line 992
59
59
  ["raise 'unknown class: %s' % join.class.name
60
60
  end
61
61
  end",
62
- "raise 'unknown class: %s' % join.class.name
62
+ "raise 'unknown class: %s' % join.class.name
63
63
  end
64
64
  end
65
65
 
@@ -927,12 +927,40 @@ if (is_postgres = (Object.const_defined?('PG::VERSION') || Gem::Specification.fi
927
927
  )
928
928
  end
929
929
 
930
+ # Allow ActiveRecord < 6.1 to work with Ruby 3.0 and later
931
+ if ActiveRecord.version < ::Gem::Version.new('6.0a') && ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('3.0')
932
+ ::Brick::Util._patch_require(
933
+ 'active_record/connection_adapters/abstract/database_statements.rb', '/activerecord',
934
+ [' def transaction(requires_new: nil, isolation: nil, joinable: true)',
935
+ " def transaction(options = {}, requires_new: nil, isolation: nil, joinable: true)
936
+ requires_new ||= options.fetch(:requires_new, nil)
937
+ isolation ||= options.fetch(:isolation, nil)"]
938
+ )
939
+ end
940
+
930
941
  require 'active_record'
931
942
  require 'active_record/relation'
932
943
  # To support adding left_outer_join
933
944
  require 'active_record/relation/query_methods' if ActiveRecord.version < ::Gem::Version.new('5')
934
945
  require 'rails/railtie' if ActiveRecord.version < ::Gem::Version.new('4.2')
935
946
 
947
+ # Allow ActiveRecord < 6.1 to work with Ruby 3.0 and later
948
+ if ActiveRecord.version < ::Gem::Version.new('6.0a') && ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('3.0')
949
+ ::ActiveRecord::Base.class_exec do
950
+ class << self
951
+ def transaction(options = {}, &block)
952
+ connection.transaction(**options, &block)
953
+ end
954
+ end
955
+ end
956
+ # ::Brick::Util._patch_require(
957
+ # 'active_record/transactions.rb', '/activerecord',
958
+ # [' connection.transaction(options, &block)',
959
+ # " connection.transaction(**options, &block)"],
960
+ # :Transactions
961
+ # )
962
+ end
963
+
936
964
  if Object.const_defined?('Rails')
937
965
  # Rake tasks
938
966
  class Railtie < ::Rails::Railtie
@@ -1295,6 +1323,18 @@ ActiveSupport.on_load(:active_record) do
1295
1323
  end
1296
1324
  end
1297
1325
 
1326
+ # Allow ActiveRecord < 6.1 to work with Ruby 3.1 and later
1327
+ if ActiveRecord.version < ::Gem::Version.new('6.1a') && ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('3.1')
1328
+ require 'active_record/connection_adapters/abstract/transaction'
1329
+ ::ActiveRecord::ConnectionAdapters::Transaction.class_exec do
1330
+ alias _original_initialize initialize
1331
+ def initialize(connection, options, kwargs = {}, run_commit_callbacks: false)
1332
+ kwargs[:run_commit_callbacks] = run_commit_callbacks unless kwargs.key?(:run_commit_callbacks)
1333
+ _original_initialize(connection, options, **kwargs)
1334
+ end
1335
+ end
1336
+ end
1337
+
1298
1338
  if ActiveRecord.version < ::Gem::Version.new('6.1.4') &&
1299
1339
  Psych.method(:load).parameters.any? { |param| param.first == :key && param.last == :aliases }
1300
1340
  Psych.class_exec do
@@ -37,12 +37,12 @@ module Brick
37
37
  # Generate a list of viable models that can be chosen
38
38
  # First start with any existing models that have been defined ...
39
39
  existing_models = ActiveRecord::Base.descendants.each_with_object({}) do |m, s|
40
- s[m.table_name] = SeedModel.new(m.table_name, m, false) if !m.abstract_class? && !m.is_view? && m.table_exists?
40
+ s[(bc = m.base_class).name] = SeedModel.new(m.table_name, bc, false) if !m.abstract_class? && !m.is_view? && m.table_exists?
41
41
  end
42
42
  models = (existing_models.values +
43
43
  # ... then add models which can be auto-built by Brick
44
44
  relations.reject do |k, v|
45
- k.is_a?(Symbol) || (v.key?(:isView) && v[:isView] == true) || existing_models.key?(k)
45
+ k.is_a?(Symbol) || (v.key?(:isView) && v[:isView] == true) || existing_models.key?(v[:class_name])
46
46
  end.map { |k, v| SeedModel.new(k, v[:class_name].constantize, true) }
47
47
  ).sort { |a, b| a.to_s <=> b.to_s }
48
48
  if models.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.253
4
+ version: 1.0.254
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits