brick 1.0.194 → 1.0.196

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: 241617832338faa570f73caad241a98dd065fc9e1428fe54801bfbb57a26a392
4
- data.tar.gz: 86a7427f5b382bc478eec07e42c42eac1f5aeda56e29bad839e947acfec6c08f
3
+ metadata.gz: 9f5cff29063c150d35653274752bcda0ed44ce462563824f8b8a974dfacc8a81
4
+ data.tar.gz: 2d26e1e8a62b3a9e69c6a28a37e640fa5c5e0ced28a6527db4b68d2abdfc47f5
5
5
  SHA512:
6
- metadata.gz: 25392afb2c248e305decfe4c641c415f96f7836c46aeda2bad56b59016ee140c780a008dfa57a563d987ed75c7be929d786d95bfa2f15aa58128f67a043429b7
7
- data.tar.gz: afc21602ca3c3be41b686534c78b49507f1d1c06a6abe90a224c5302e8ebefaf5963bc75e181b4bd31b7b5eae9fe0970c871f33945ec192fe63bcb4e336b7baa
6
+ metadata.gz: 150e669bb088db49139311839cbca472317b371d24ab85bc096bea94221331c1f7122b8ed521a9c87691d9ded450d723954c2bd7d833b56fd07f248be5624339
7
+ data.tar.gz: cf000d92773ce9ec8db6a412e7f4fe642e6e9bc07db9412459931a69ebc7dff7fb41de9d1824d068b9c8568827cdbd1881073f3404b85eab1fc1c5670cd625ff
@@ -436,13 +436,9 @@ module ActiveRecord
436
436
  order_by = ordering&.each_with_object([]) do |ord_part, s| # %%% If a term is also used as an eqi-condition in the WHERE clause, it can be omitted from ORDER BY
437
437
  case ord_part
438
438
  when String
439
- if ord_part.index('^^^')
440
- ord_expr = ord_part.gsub('^^^', _br_quoted_name(table_name))
441
- s << Arel.sql(ord_expr)
442
- else
443
- s << Arel.sql(_br_quoted_name(ord_part))
444
- end
445
- order_by_txt&.<<("Arel.sql(#{ord_expr.inspect})")
439
+ ord_expr = _br_quoted_name(ord_part.gsub('^^^', table_name))
440
+ s << Arel.sql(ord_expr)
441
+ order_by_txt&.<<(ord_expr.index('.') ? "Arel.sql(#{ord_expr.inspect})" : ord_expr)
446
442
  else # Expecting only Symbol
447
443
  ord_part = ord_part.to_s
448
444
  if ord_part[0] == '-' # First char '-' means descending order
@@ -1860,14 +1856,14 @@ class Object
1860
1856
  end
1861
1857
  end
1862
1858
 
1863
- def default_ordering(table_name, pk)
1859
+ def default_ordering(table_name, pk, omit_table_name = nil)
1864
1860
  case (order_tbl = ::Brick.config.order[table_name]) && (order_default = order_tbl[:_brick_default])
1865
1861
  when Array
1866
1862
  order_default.map { |od_part| order_tbl[od_part] || od_part }
1867
1863
  when Symbol
1868
1864
  order_tbl[order_default] || order_default
1869
1865
  else
1870
- pk.map { |part| "#{table_name}.#{part}"} # If it's not a custom ORDER BY, just use the key
1866
+ pk.map { |part| "#{"#{table_name}." unless omit_table_name}#{part}"} # If it's not a custom ORDER BY, just use the key
1871
1867
  end
1872
1868
  end
1873
1869
 
@@ -1917,7 +1913,7 @@ class Object
1917
1913
  cspd.select! { |val| val == "'self'" }
1918
1914
  cspd << style_value
1919
1915
  else
1920
- cspd << "'sha256-Q8t+pETkz0RtyV4XprwdP+uEkVaFyMnx1mXif0wDoxw='"
1916
+ cspd << "'sha256-0Vb7j3kDGE3oNfwMpRLClTSCUo/q74bvbt3p6kG/gkM='"
1921
1917
  end
1922
1918
  cspd << 'https://cdn.jsdelivr.net'
1923
1919
  end
@@ -2035,6 +2031,7 @@ class Object
2035
2031
  end
2036
2032
 
2037
2033
  self.protect_from_forgery unless: -> { self.request.format.js? }
2034
+ plural_table_name = table_name.split('.').last.pluralize
2038
2035
  unless is_avo
2039
2036
  self.define_method :index do
2040
2037
  request_ver = request.path.split('/')[-2]
@@ -2220,7 +2217,7 @@ class Object
2220
2217
  end
2221
2218
  end
2222
2219
  ar_select = ar_relation.respond_to?(:_select!) ? ar_relation.dup._select!(*selects, *counts) : ar_relation.select(selects + counts)
2223
- instance_variable_set("@#{table_name.split('.').last}".to_sym, ar_select)
2220
+ instance_variable_set("@#{plural_table_name}".to_sym, ar_select)
2224
2221
  table_name_no_schema = singular_table_name.pluralize
2225
2222
  if namespace && (idx = lookup_context.prefixes.index(table_name_no_schema))
2226
2223
  lookup_context.prefixes[idx] = "#{namespace.name.underscore}/#{lookup_context.prefixes[idx]}"
@@ -2259,10 +2256,10 @@ class Object
2259
2256
  end
2260
2257
  end
2261
2258
 
2262
- _, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk)) if pk
2259
+ _, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk, true)) if pk
2263
2260
  code << " def index\n"
2264
- code << " @#{table_name.pluralize} = #{model.name}#{pk&.present? ? ".order(#{order_by_txt.join(', ')})" : '.all'}\n"
2265
- code << " @#{table_name.pluralize}.brick_select(params)\n"
2261
+ code << " @#{plural_table_name} = #{model.name}#{pk&.present? ? ".order(#{order_by_txt.join(', ')})" : '.all'}\n"
2262
+ code << " @#{plural_table_name}.brick_select(params)\n"
2266
2263
  code << " end\n"
2267
2264
 
2268
2265
  is_pk_string = nil
@@ -2562,12 +2559,8 @@ class Object
2562
2559
  assoc_name = assoc_parts.join('.')
2563
2560
  else
2564
2561
  class_name_parts = ::Brick.namify(hm_assoc[:inverse_table], :underscore).split('.')
2565
- last_idx = class_name_parts.length - 1
2566
- class_name_parts[last_idx] = class_name_parts[last_idx].singularize
2567
- real_name = class_name_parts.map(&:camelize).join('::')
2568
- needs_class = (real_name != hm_assoc[:inverse_table].camelize)
2562
+ needs_class = assoc_name.singularize.camelize != class_name_parts.last.singularize.camelize
2569
2563
  end
2570
- # hm_assoc[:assoc_name] = assoc_name
2571
2564
  [assoc_name, needs_class]
2572
2565
  end
2573
2566
  # Already have the HM class around?
@@ -2616,7 +2609,7 @@ end.class_exec do
2616
2609
  # https://discuss.rubyonrails.org/t/failed-write-transaction-upgrades-in-sqlite3/81480/2
2617
2610
  if ActiveRecord::Base.connection.adapter_name == 'SQLite'
2618
2611
  arca = ::ActiveRecord::ConnectionAdapters
2619
- db_statements = arca::SQLite3::DatabaseStatements
2612
+ db_statements = arca::SQLite3.const_defined?('DatabaseStatements') ? arca::SQLite3::DatabaseStatements : arca::SQLite3::SchemaStatements
2620
2613
  # Rails 7.1 and later
2621
2614
  if arca::AbstractAdapter.private_instance_methods.include?(:with_raw_connection)
2622
2615
  db_statements.define_method(:begin_db_transaction) do
@@ -3084,7 +3077,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
3084
3077
  INNER JOIN pg_class child ON pg_inherits.inhrelid = child.oid
3085
3078
  INNER JOIN pg_catalog.pg_namespace n ON n.oid = parent.relnamespace#{
3086
3079
  if schema
3087
- params = params << schema
3080
+ params << schema
3088
3081
  "
3089
3082
  WHERE n.nspname = COALESCE(?, 'public')"
3090
3083
  end}
@@ -3099,7 +3092,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
3099
3092
  FROM pg_class
3100
3093
  INNER JOIN pg_catalog.pg_namespace n ON n.oid = pg_class.relnamespace#{
3101
3094
  if schema
3102
- params = params << schema
3095
+ params << schema
3103
3096
  "
3104
3097
  WHERE n.nspname = COALESCE(?, 'public')"
3105
3098
  end}
@@ -940,7 +940,11 @@ tr th a {
940
940
  .add-hm-related {
941
941
  float: right;
942
942
  }
943
-
943
+ #tblAddCol {
944
+ position: relative;
945
+ z-index: 2;
946
+ border: 2px solid blue;
947
+ }
944
948
  tr th, tr td {
945
949
  padding: 0.2em 0.5em;
946
950
  }
@@ -998,10 +1002,20 @@ a.big-arrow {
998
1002
  .right {
999
1003
  text-align: right;
1000
1004
  }
1005
+ .paddingBottomZero {
1006
+ padding-bottom: 0px;
1007
+ }
1008
+ .paddingTopZero {
1009
+ padding-top: 0px;
1010
+ }
1001
1011
  .orphan {
1002
1012
  color: red;
1003
1013
  white-space: nowrap;
1004
1014
  }
1015
+ .thumbImg {
1016
+ max-width: 96px;
1017
+ max-height: 96px;
1018
+ }
1005
1019
  .danger {
1006
1020
  background-color: red;
1007
1021
  color: white;
@@ -1189,18 +1203,18 @@ erDiagram
1189
1203
  # Make into a server control with a javascript snippet
1190
1204
  # Have post back go to a common "brick_schema" endpoint, this one for add_column
1191
1205
  "
1192
- <table style=\"position: relative; z-index: 2; border: 2px solid blue;\"><tr>
1206
+ <table id=\"tblAddCol\"><tr>
1193
1207
  <td rowspan=\"2\">Add<br>Column</td>
1194
- <td style=\"padding-bottom: 0px\">Type</td><td style=\"padding-bottom: 0px\">Name</td>
1208
+ <td class=\"paddingBottomZero\">Type</td><td class=\"paddingBottomZero\">Name</td>
1195
1209
  <td rowspan=\"2\"><input type=\"button\" id=\"btnAddCol\" value=\"+\"></td>
1196
- </tr><tr><td style=\"padding-top: 0px\">
1210
+ </tr><tr><td class=\"paddingTopZero\">
1197
1211
  <select id=\"ddlColType\">
1198
1212
  <option value=\"string\">String</option>
1199
1213
  <option value=\"text\">Text</option>
1200
1214
  <option value=\"integer\">Integer</option>
1201
1215
  <option value=\"bool\">Boolean</option>
1202
1216
  </select></td>
1203
- <td style=\"padding-top: 0px\"><input id=\"txtColName\"></td>
1217
+ <td class=\"paddingTopZero\"><input id=\"txtColName\"></td>
1204
1218
  </tr></table>
1205
1219
  <script>
1206
1220
  var btnAddCol = document.getElementById(\"btnAddCol\");
@@ -1376,7 +1390,7 @@ end %>#{"
1376
1390
  end
1377
1391
  \"<tr><td colspan=\\\"#\{td_count}\\\">Children: #\{child_links.join(' ')}</tr>\".html_safe
1378
1392
  end
1379
- %><%= if (page_num = @#{table_name}._brick_page_num)
1393
+ %><%= if (page_num = @#{res_name = table_name.pluralize}._brick_page_num)
1380
1394
  \"<tr><td colspan=\\\"#\{td_count}\\\">Page #\{page_num}</td></tr>\".html_safe
1381
1395
  end %></table>#{template_link}<%
1382
1396
  if description.present? %><span class=\"__brick\"><%=
@@ -1418,19 +1432,19 @@ end
1418
1432
 
1419
1433
  <%= # Consider getting the name from the association -- hm.first.name -- if a more \"friendly\" alias should be used for a screwy table name
1420
1434
  # If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
1421
- @#{table_name} ||= if (dym_list = instance_variables.reject do |entry|
1435
+ @#{res_name} ||= if (dym_list = instance_variables.reject do |entry|
1422
1436
  entry.to_s.start_with?('@_') ||
1423
1437
  ['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
1424
1438
  end).present?
1425
- msg = +\"Can't find resource \\\"#{table_name}\\\".\"
1439
+ msg = +\"Can't find resource \\\"#{res_name}\\\".\"
1426
1440
  # Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
1427
- if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{table_name}')).present?
1441
+ if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{res_name}')).present?
1428
1442
  msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
1429
1443
  msg << \" inflect.irregular '#{obj_name}', '#\{found_dym}'\"
1430
1444
  puts
1431
1445
  puts \"WARNING: #\{msg}\"
1432
1446
  puts
1433
- @#{table_name} = instance_variable_get(dym.first.to_sym)
1447
+ @#{res_name} = instance_variable_get(dym.first.to_sym)
1434
1448
  else
1435
1449
  raise ActiveRecord::RecordNotFound.new(msg)
1436
1450
  end
@@ -1450,7 +1464,7 @@ end
1450
1464
  # Rails.application.reloader.to_prepare do ... end
1451
1465
  self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
1452
1466
  # Write out the mega-grid
1453
- brick_grid(@#{table_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
1467
+ brick_grid(@#{res_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
1454
1468
  cols, bt_descrip: @_brick_bt_descrip, poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}}) %>
1455
1469
 
1456
1470
  #{"<hr><%= link_to(\"New #{new_path_name = "new_#{path_obj_name}_path"
@@ -1586,9 +1600,12 @@ end %>#{"
1586
1600
  <table id=\"resourceName\"><td><h1><%= page_title %></h1></td>
1587
1601
  <% rel = Brick.relations[#{model_name}.table_name]
1588
1602
  if (in_app = rel.fetch(:existing, nil)&.fetch(:show, nil))
1589
- in_app = send(\"#\{in_app}_path\", #{pk.is_a?(String) ? "obj.#{pk}" : '[' + pk.map { |pk_part| "obj.#{pk_part}" }.join(', ') + ']' }) if in_app.is_a?(Symbol) %>
1603
+ begin
1604
+ in_app = send(\"#\{in_app}_path\", #{pk.is_a?(String) ? "obj.#{pk}" : '[' + pk.map { |pk_part| "obj.#{pk_part}" }.join(', ') + ']' }) if in_app.is_a?(Symbol) %>
1590
1605
  <td><%= link_to(::Brick::Rails::IN_APP.html_safe, in_app) %></td>
1591
- <% end
1606
+ <% rescue ActionController::UrlGenerationError
1607
+ end
1608
+ end
1592
1609
 
1593
1610
  if Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace) %>
1594
1611
  <td><%= link_to_brick(
@@ -55,7 +55,10 @@ module Brick::Rails::FormBuilder
55
55
  is_revert = false
56
56
  out << ::Brick::Rails::FormBuilder.hide_bcrypt(val, nil, 1000)
57
57
  elsif col_type == :string
58
- if model.respond_to?(:enumerized_attributes) && (opts = (attr = model.enumerized_attributes[method])&.options).present?
58
+ if model.respond_to?(:uploaders) && model.uploaders.key?(col.name&.to_sym) &&
59
+ (url = self.object.send(col.name)&.url) # Carrierwave image?
60
+ out << "<img src=\"#{url}\" title=\"#{val}\">"
61
+ elsif model.respond_to?(:enumerized_attributes) && (opts = (attr = model.enumerized_attributes[method])&.options).present?
59
62
  enum_html_options = attr.kind_of?(Enumerize::Multiple) ? html_options.merge({ multiple: true, size: opts.length + 1 }) : html_options
60
63
  out << self.select(method.to_sym, [["(No #{method} chosen)", '^^^brick_NULL^^^']] + opts, { value: val || '^^^brick_NULL^^^' }, enum_html_options)
61
64
  else
@@ -149,9 +152,10 @@ module Brick::Rails::FormBuilder
149
152
  else
150
153
  if val.is_a?(String)
151
154
  return ::Brick::Rails.display_binary(val) unless (val_utf8 = val.dup.force_encoding('UTF-8')).valid_encoding?
155
+
152
156
  val = val_utf8.strip
153
157
  return CGI.escapeHTML(val) if is_xml
154
-
158
+
155
159
  if val.length > max_len
156
160
  if val[0] == '<' # Seems to be HTML?
157
161
  cur_len = 0
@@ -47,9 +47,12 @@ module Brick::Rails::FormTags
47
47
  "
48
48
  end
49
49
  if rel && show_in_app_button != false && (in_app = rel.fetch(:existing, nil)&.fetch(:index, nil))
50
- in_app = send("#{in_app}_path") if in_app.is_a?(Symbol)
51
- out << " <td title=\"Show in app\">#{link_to(::Brick::Rails::IN_APP.html_safe, in_app)}</td>
50
+ begin
51
+ in_app = send("#{in_app}_path") if in_app.is_a?(Symbol)
52
+ out << " <td title=\"Show in app\">#{link_to(::Brick::Rails::IN_APP.html_safe, in_app)}</td>
52
53
  "
54
+ rescue ActionController::UrlGenerationError # Avoid snags like "No route matches {:action=>"index", :controller=>"categories/products"}, missing required keys: [:category_id]"
55
+ end
53
56
  end
54
57
  if show_avo_button != false && Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace) && klass.name.exclude?('::')
55
58
  out << "
@@ -229,6 +232,9 @@ module Brick::Rails::FormTags
229
232
  # binding.pry if col.is_a?(Array)
230
233
  out << if @_brick_monetized_attributes&.include?(col_name)
231
234
  val ? Money.new(val.to_i).format : ''
235
+ elsif klass.respond_to?(:uploaders) && klass.uploaders.key?(col_name.to_sym) &&
236
+ (url = obj.send(col_name)&.url) # Carrierwave image?
237
+ "<img class=\"thumbImg\" src=\"#{url}\" title=\"#{val}\">"
232
238
  else
233
239
  lat_lng = if [:float, :decimal].include?(col.type) &&
234
240
  (
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 194
8
+ TINY = 196
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.194
4
+ version: 1.0.196
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-28 00:00:00.000000000 Z
11
+ date: 2023-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  - !ruby/object:Gem::Version
285
285
  version: 1.3.6
286
286
  requirements: []
287
- rubygems_version: 3.2.33
287
+ rubygems_version: 3.1.6
288
288
  signing_key:
289
289
  specification_version: 4
290
290
  summary: Create a Rails app from data alone