brick 1.0.35 → 1.0.38

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: 34a23d1057771acea1beb9ea1ea2ff3d27e5983084bcd47f4c87686af77328d5
4
- data.tar.gz: 44aea0d5fb92a361913ba4a17ebca62cf5be9aca5585fa9785b7c388c2652cee
3
+ metadata.gz: 4fcc487d2177c77f487d6d7ec910d0cb1ec61e1a9da77fdbd7e7bd413ebe7373
4
+ data.tar.gz: 618bb20e4ff8aea7a81f02191100cb9bf15905a69099a8bbaec56cea6f27e882
5
5
  SHA512:
6
- metadata.gz: e9124cbd0db47816db2dcbf59a76adcc0d4dcaea8f4ad02ea9ee99aace025c8914a7871c78a4a703f4daeced7dbaec12d52fdf56b6bc131c4c855be931d4f838
7
- data.tar.gz: 671d0333b9a89870db67cdec05306311475724d674aab494c794baa0648736c873ea2aade170bdbc51642b96e4fe76a19f568bf31e724bd513230e1a78c69521
6
+ metadata.gz: 4d71c229f3c9ae97866aeeb5f852504f593136de06dbb5b500917454d38a1f9b3afb17ab7ba0b1bfc21e9371739f37af0b4d88534d6db5332c88c4dafbccf67a
7
+ data.tar.gz: e1354cc5c4fb808aea3eb2a3b4580cdc31a37e51c799581d8461de21af520e1dab66793815e7a3ea8b3fc31b39b1e520ffb5150e7e6646279a2e3fe10933b770
@@ -1108,9 +1108,11 @@ module ActiveRecord::ConnectionHandling
1108
1108
  # Only for Postgres? (Doesn't work in sqlite3)
1109
1109
  # puts ActiveRecord::Base.execute_sql("SELECT current_setting('SEARCH_PATH')").to_a.inspect
1110
1110
 
1111
+ is_postgres = nil
1111
1112
  schema_sql = 'SELECT NULL AS table_schema;'
1112
1113
  case ActiveRecord::Base.connection.adapter_name
1113
1114
  when 'PostgreSQL'
1115
+ is_postgres = true
1114
1116
  if (is_multitenant = (multitenancy = ::Brick.config.schema_behavior[:multitenant]) &&
1115
1117
  (sta = multitenancy[:schema_to_analyse]) != 'public')
1116
1118
  ::Brick.default_schema = schema = sta
@@ -1158,7 +1160,8 @@ module ActiveRecord::ConnectionHandling
1158
1160
  # %%% Retrieve internal ActiveRecord table names like this:
1159
1161
  # ActiveRecord::Base.internal_metadata_table_name, ActiveRecord::Base.schema_migrations_table_name
1160
1162
  # For if it's not SQLite -- so this is the Postgres and MySQL version
1161
- sql ||= "SELECT t.table_schema AS schema, t.table_name AS relation_name, t.table_type,
1163
+ sql ||= "SELECT t.table_schema AS schema, t.table_name AS relation_name, t.table_type,#{"
1164
+ pg_catalog.obj_description((t.table_schema || '.' || t.table_name)::regclass, 'pg_class') AS table_description," if is_postgres}
1162
1165
  c.column_name, c.data_type,
1163
1166
  COALESCE(c.character_maximum_length, c.numeric_precision) AS max_length,
1164
1167
  tc.constraint_type AS const, kcu.constraint_name AS \"key\",
@@ -1197,6 +1200,7 @@ module ActiveRecord::ConnectionHandling
1197
1200
  relation_name = schema_name ? "#{schema_name}.#{r['relation_name']}" : r['relation_name']
1198
1201
  relation = relations[relation_name]
1199
1202
  relation[:isView] = true if r['table_type'] == 'VIEW'
1203
+ relation[:description] = r['table_description'] if r['table_description']
1200
1204
  col_name = r['column_name']
1201
1205
  key = case r['const']
1202
1206
  when 'PRIMARY KEY'
@@ -141,9 +141,14 @@ module Brick
141
141
  display: none;
142
142
  }
143
143
 
144
+ #headerTop {
145
+ position: sticky;
146
+ top: 0px;
147
+ background-color: white;
148
+ z-index: 1;
149
+ }
144
150
  table {
145
151
  border-collapse: collapse;
146
- margin: 25px 0;
147
152
  font-size: 0.9em;
148
153
  font-family: sans-serif;
149
154
  min-width: 400px;
@@ -255,6 +260,7 @@ end %>"
255
260
  var schemaSelect = document.getElementById(\"schema\");
256
261
  var tblSelect = document.getElementById(\"tbl\");
257
262
  var brickSchema;
263
+ var #{table_name}HtColumns;
258
264
 
259
265
  // This PageTransitionEvent fires when the page first loads, as well as after any other history
260
266
  // transition such as when using the browser's Back and Forward buttons.
@@ -316,6 +322,42 @@ function changeout(href, param, value, trimAfter) {
316
322
  params[param] = value;
317
323
  return hrefParts[0] + \"?\" + Object.keys(params).reduce(function (s, v) { s.push(v + \"=\" + params[v]); return s; }, []).join(\"&\");
318
324
  }
325
+
326
+ // Snag first TR for sticky header
327
+ var grid = document.getElementById(\"#{table_name}\");
328
+ #{table_name}HtColumns = grid && [grid.getElementsByTagName(\"TR\")[0]];
329
+ var headerTop = document.getElementById(\"headerTop\");
330
+ function setHeaderSizes() {
331
+ // console.log(\"start\");
332
+ // See if the headerTop is already populated
333
+ // %%% Grab the TRs from headerTop, clear it out, do this stuff, add them back
334
+ headerTop.innerHTML = \"\"; // %%% Would love to not have to clear it out like this every time! (Currently doing this to support resize events.)
335
+ var isEmpty = headerTop.childElementCount === 0;
336
+ // Set up proper sizings of sticky column header
337
+ var node;
338
+ for (var j = 0; j < #{table_name}HtColumns.length; ++j) {
339
+ var row = #{table_name}HtColumns[j];
340
+ var tr = isEmpty ? document.createElement(\"TR\") : headerTop.childNodes[j];
341
+ tr.innerHTML = row.innerHTML.trim();
342
+ // Match up widths from the original column headers
343
+ for (var i = 0; i < row.childNodes.length; ++i) {
344
+ node = row.childNodes[i];
345
+ if (node.nodeType === 1) {
346
+ var style = tr.childNodes[i].style;
347
+ style.minWidth = style.maxWidth = getComputedStyle(node).width;
348
+ }
349
+ }
350
+ if (isEmpty) headerTop.appendChild(tr);
351
+ }
352
+ grid.style.marginTop = \"-\" + getComputedStyle(headerTop).height;
353
+ // console.log(\"end\");
354
+ }
355
+ if (headerTop) {
356
+ setHeaderSizes();
357
+ window.addEventListener('resize', function(event) {
358
+ setHeaderSizes();
359
+ }, true);
360
+ }
319
361
  </script>"
320
362
  inline = case args.first
321
363
  when 'index'
@@ -419,14 +461,15 @@ function changeout(href, param, value, trimAfter) {
419
461
  <p style=\"color: green\"><%= notice %></p>#{"
420
462
  <select id=\"schema\">#{schema_options}</select>" if ::Brick.config.schema_behavior[:multitenant] && ::Brick.db_schemas.length > 1}
421
463
  <select id=\"tbl\">#{table_options}</select>
422
- <h1>#{model_plural = model_name.pluralize}</h1>#{template_link}
423
-
424
- <% if @_brick_params&.present? %>
464
+ <h1>#{model_plural = model_name.pluralize}</h1>#{template_link}<%
465
+ if (description = (relation = Brick.relations[#{model_name}.table_name])&.fetch(:description, nil)) %><%=
466
+ description %><br><%
467
+ end
468
+ if @_brick_params&.present? %>
425
469
  <% if @_brick_params.length == 1 # %%% Does not yet work with composite keys
426
470
  k, id = @_brick_params.first
427
471
  id = id.first if id.is_a?(Array) && id.length == 1
428
472
  origin = (key_parts = k.split('.')).length == 1 ? #{model_name} : #{model_name}.reflect_on_association(key_parts.first).klass
429
- # binding.pry
430
473
  if (destination_fk = Brick.relations[origin.table_name][:fks].values.find { |fk| puts fk.inspect; fk[:fk] == key_parts.last }) &&
431
474
  (obj = (destination = origin.reflect_on_association(destination_fk[:assoc_name])&.klass)&.find(id)) %>
432
475
  <h3>for <%= link_to \"#{"#\{obj.brick_descrip\} (#\{destination.name\})\""}, send(\"#\{destination.name.underscore.tr('/', '_')\}_path\".to_sym, id) %></h3><%
@@ -434,35 +477,40 @@ function changeout(href, param, value, trimAfter) {
434
477
  end %>
435
478
  (<%= link_to 'See all #{model_plural.split('::').last}', #{path_obj_name.pluralize}_path %>)
436
479
  <% end %>
480
+ <br>
481
+ <table id=\"headerTop\">
437
482
  <table id=\"#{table_name}\">
438
- <thead><tr>#{'<th></th>' if pk.present?}
439
- <% @#{table_name}.columns.map(&:name).each do |col| %>
440
- <% next if (#{(pk || []).inspect}.include?(col) && #{model_name}.column_for_attribute(col).type == :integer && !bts.key?(col)) ||
441
- ::Brick.config.metadata_columns.include?(col) || poly_cols.include?(col) %>
442
- <th>
443
- <% if (bt = bts[col]) %>
483
+ <thead><tr>#{'<th></th>' if pk.present?}<%
484
+ col_order = []
485
+ @#{table_name}.columns.each do |col|
486
+ col_name = col.name
487
+ next if (#{(pk || []).inspect}.include?(col_name) && col.type == :integer && !bts.key?(col_name)) ||
488
+ ::Brick.config.metadata_columns.include?(col_name) || poly_cols.include?(col_name)
489
+
490
+ col_order << col_name
491
+ %><th<%= \" title = \\\"#\{col.comment}\\\"\".html_safe unless col.comment.blank? %>><%
492
+ if (bt = bts[col_name]) %>
444
493
  BT <%
445
494
  bt[1].each do |bt_pair| %><%=
446
495
  bt_pair.first.bt_link(bt.first) %> <%
447
496
  end %><%
448
497
  else %><%=
449
- col %><%
450
- end %>
451
- </th>
452
- <% end %>
453
- <%# Consider getting the name from the association -- h.first.name -- if a more \"friendly\" alias should be used for a screwy table name %>
454
- #{hms_headers.map { |h| "<th>#{h[1]} <%= link_to('#{h[2]}', #{h.first.klass.name.underscore.tr('/', '_').pluralize}_path) %></th>\n" }.join}
455
- </tr></thead>
498
+ col_name %><%
499
+ end
500
+ %></th><%
501
+ end
502
+ # Consider getting the name from the association -- h.first.name -- if a more \"friendly\" alias should be used for a screwy table name
503
+ %>#{hms_headers.map { |h| "<th>#{h[1]} <%= link_to('#{h[2]}', #{h.first.klass.name.underscore.tr('/', '_').pluralize}_path) %></th>" }.join
504
+ }</tr></thead>
456
505
 
457
506
  <tbody>
458
507
  <% @#{table_name}.each do |#{obj_name}| %>
459
508
  <tr>#{"
460
509
  <td><%= link_to '⇛', #{path_obj_name}_path(#{obj_pk}), { class: 'big-arrow' } %></td>" if obj_pk}
461
- <% #{obj_name}.attributes.each do |k, val| %>
462
- <% next if (#{(obj_pk || []).inspect}.include?(k) && #{model_name}.column_for_attribute(k).type == :integer && !bts.key?(k)) ||
463
- ::Brick.config.metadata_columns.include?(k) || poly_cols.include?(k) || k.start_with?('_brfk_') || (k.start_with?('_br_') && (k.length == 63 || k.end_with?('_ct'))) %>
510
+ <% col_order.each do |col_name|
511
+ val = #{obj_name}.attributes[col_name] %>
464
512
  <td>
465
- <% if (bt = bts[k]) %>
513
+ <% if (bt = bts[col_name]) %>
466
514
  <% if bt[2] # Polymorphic?
467
515
  bt_class = #{obj_name}.send(\"#\{bt.first\}_type\")
468
516
  base_class = (::Brick.existing_stis[bt_class] || bt_class).constantize.base_class.name.underscore
@@ -496,20 +544,25 @@ function changeout(href, param, value, trimAfter) {
496
544
  <p style=\"color: green\"><%= notice %></p>#{"
497
545
  <select id=\"schema\">#{schema_options}</select>" if ::Brick.config.schema_behavior[:multitenant] && ::Brick.db_schemas.length > 1}
498
546
  <select id=\"tbl\">#{table_options}</select>
499
- <h1>#{model_name}: <%= (obj = @#{obj_name})&.brick_descrip || controller_name %></h1>
500
- <%= link_to '(See all #{obj_name.pluralize})', #{path_obj_name.pluralize}_path %>
547
+ <h1>#{model_name}: <%= (obj = @#{obj_name})&.brick_descrip || controller_name %></h1><%
548
+ if (description = (relation = Brick.relations[#{model_name}.table_name])&.fetch(:description, nil)) %><%=
549
+ description %><br><%
550
+ end
551
+ %><%= link_to '(See all #{obj_name.pluralize})', #{path_obj_name.pluralize}_path %>
501
552
  <% if obj %>
553
+ <br><br>
502
554
  <%= # path_options = [obj.#{pk}]
503
555
  # path_options << { '_brick_schema': } if
504
556
  # url = send(:#{model_name.underscore}_path, obj.#{pk})
505
557
  form_for(obj.becomes(#{model_name})) do |f| %>
506
558
  <table>
507
559
  <% has_fields = false
508
- @#{obj_name}.attributes.each do |k, val| %>
560
+ @#{obj_name}.attributes.each do |k, val|
561
+ col = #{model_name}.columns_hash[k] %>
509
562
  <tr>
510
563
  <% next if (#{(pk || []).inspect}.include?(k) && !bts.key?(k)) ||
511
564
  ::Brick.config.metadata_columns.include?(k) %>
512
- <th class=\"show-field\">
565
+ <th class=\"show-field\"<%= \" title = \\\"#\{col.comment}\\\"\".html_safe unless col.comment.blank? %>>
513
566
  <% has_fields = true
514
567
  if (bt = bts[k])
515
568
  # Add a final member in this array with descriptive options to be used in <select> drop-downs
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 35
8
+ TINY = 38
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.35
4
+ version: 1.0.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-25 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '3.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '3.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: appraisal
35
35
  requirement: !ruby/object:Gem::Requirement