brick 1.0.41 → 1.0.42

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: 4455ebfde80fe8a4bd51f19438171abae2614e0740adba98ab39184952843a01
4
- data.tar.gz: d5157748c37564156fc2f823cc3c4753b536491aa2cf81175683c8241fb2a2b9
3
+ metadata.gz: a385c606282392cbefea1eaa045dc6a023bd05f56044013bc3835ef06a630b87
4
+ data.tar.gz: 261e21a2eb02ac1b199c831e1bba5eeec3add7b5faf0b2567fbb94a3252d817f
5
5
  SHA512:
6
- metadata.gz: 2a649c78c3e597004b36d6c33f1cd812a712fcfd561dfe94994de28e489de81508f9fea30b0896b4447c4ce0ffd0877fb8c5d7e20a34011212fd797a3cbd02ca
7
- data.tar.gz: 58ecdc4acb12abb77169a8fda8cb8146fceaedeacdf77f1cec992008f98b05412e3a9e2f5b6a9721880caa710ba94792a187d3587248eea4d9946d309c91be56
6
+ metadata.gz: 686a6ad73671511c36c6871e86fd6d02f7b8b48b2e1bacb033ec5348a85cedfc1c6848c92293e4144c0ca95ab79888c5993dcdbb7f440d93265a6c65b5c74a6b
7
+ data.tar.gz: 04e0cb25404beb9fead5d07ff3c76066bc23d097fb2a01c53b689737e1a5d70cfef94b432b89f45f61497074171bb171fae0064aef970c2c025f3ce05de23557
@@ -905,10 +905,8 @@ class Object
905
905
  if plural_class_name == 'BrickGem'
906
906
  self.define_method :orphans do
907
907
  instance_variable_set(:@orphans, ::Brick.find_orphans(::Brick.set_db_schema(params)))
908
- puts "BrickGemController #{action_name} #{params.inspect}"
909
- # render inline: 'Brick gem!'
910
908
  end
911
- return [new_controller_class, code + ' # BrickGem controller!']
909
+ return [new_controller_class, code + ' # BrickGem controller']
912
910
  end
913
911
 
914
912
  unless (is_swagger = plural_class_name == 'BrickSwagger') # && request.format == :json)
@@ -1061,10 +1059,11 @@ class Object
1061
1059
  if is_need_params
1062
1060
  code << "private\n"
1063
1061
  code << " def #{params_name}\n"
1064
- code << " params.require(:#{singular_table_name}).permit(#{model.columns_hash.keys.map { |c| c.to_sym.inspect }.join(', ')})\n"
1062
+ code << " params.require(:#{require_name = model.name.underscore.tr('/', '_')
1063
+ }).permit(#{model.columns_hash.keys.map { |c| c.to_sym.inspect }.join(', ')})\n"
1065
1064
  code << " end\n"
1066
1065
  self.define_method(params_name) do
1067
- params.require(singular_table_name.to_sym).permit(model.columns_hash.keys)
1066
+ params.require(require_name.to_sym).permit(model.columns_hash.keys)
1068
1067
  end
1069
1068
  private params_name
1070
1069
  # Get column names for params from relations[model.table_name][:cols].keys
@@ -112,7 +112,8 @@ module Brick
112
112
  else
113
113
  hm_assoc.foreign_key
114
114
  end
115
- if args.first == 'index'
115
+ case args.first
116
+ when 'index'
116
117
  hms_columns << if hm_assoc.macro == :has_many
117
118
  set_ct = if skip_klass_hms.key?(assoc_name.to_sym)
118
119
  'nil'
@@ -124,16 +125,16 @@ module Brick
124
125
  if hm_fk_name
125
126
  "<%= ct = #{set_ct}
126
127
  link_to \"#\{ct || 'View'\} #{assoc_name}\", #{hm_assoc.klass.name.underscore.tr('/', '_').pluralize}_path({ #{path_keys(hm_assoc, hm_fk_name, obj_name, pk)} }) unless ct&.zero? %>\n"
127
- else
128
+ else # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
128
129
  "#{assoc_name}\n"
129
130
  end
130
131
  else # has_one
131
132
  "<%= obj = #{obj_name}.#{hm.first}; link_to(obj.brick_descrip, obj) if obj %>\n"
132
133
  end
133
- elsif args.first == 'show'
134
+ when 'show', 'update'
134
135
  hm_stuff << if hm_fk_name
135
136
  "<%= link_to '#{assoc_name}', #{hm_assoc.klass.name.underscore.tr('/', '_').pluralize}_path({ #{path_keys(hm_assoc, hm_fk_name, "@#{obj_name}", pk)} }) %>\n"
136
- else
137
+ else # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
137
138
  assoc_name
138
139
  end
139
140
  end
@@ -213,6 +214,9 @@ table tbody tr.active-row {
213
214
  color: #009879;
214
215
  }
215
216
 
217
+ td.val {
218
+ display: block;
219
+ }
216
220
  a.show-arrow {
217
221
  font-size: 1.5em;
218
222
  text-decoration: none;
@@ -226,11 +230,27 @@ a.big-arrow {
226
230
  overflow: hidden;
227
231
  }
228
232
  .wide-input input[type=text] {
229
- width: 100%;
233
+ display: inline-block;
234
+ width: 90%;
230
235
  }
231
236
  .dimmed {
232
237
  background-color: #C0C0C0;
233
238
  }
239
+
240
+ #revertTemplate {
241
+ display: none;
242
+ }
243
+ svg.revert {
244
+ display: none;
245
+ margin-left: 0.25em;
246
+ }
247
+ .wide-input > svg.revert {
248
+ float: right;
249
+ }
250
+ input+svg.revert {
251
+ top: 0.5em;
252
+ }
253
+
234
254
  input[type=submit] {
235
255
  background-color: #004998;
236
256
  color: #FFF;
@@ -239,7 +259,10 @@ input[type=submit] {
239
259
  text-align: right;
240
260
  }
241
261
  </style>
242
- <% def is_bcrypt?(val)
262
+ <%
263
+ is_includes_dates = nil
264
+
265
+ def is_bcrypt?(val)
243
266
  val.is_a?(String) && val.length == 60 && val.start_with?('$2a$')
244
267
  end
245
268
  def hide_bcrypt(val, max_len = 200)
@@ -328,7 +351,7 @@ function changeout(href, param, value, trimAfter) {
328
351
  var pathParts = hrefParts[hrefParts.length - 1].split(\"/\");
329
352
  if (value === undefined)
330
353
  // A couple possibilities if it's namespaced, starting with two parts in the path -- and then try just one
331
- return [pathParts.slice(1, 3).join('/'), pathParts.slice(1, 2)];
354
+ return [pathParts.slice(1, 3).join('/'), pathParts.slice(1, 2)[0]];
332
355
  else
333
356
  return hrefParts[0] + \"://\" + pathParts[0] + \"/\" + value;
334
357
  }
@@ -478,7 +501,7 @@ if (headerTop) {
478
501
  end
479
502
  # %%% Instead of our current "for Janet Leverling (Employee)" kind of link we previously had this code that did a "where x = 123" thing:
480
503
  # (where <%= @_brick_params.each_with_object([]) { |v, s| s << \"#\{v.first\} = #\{v.last.inspect\}\" }.join(', ') %>)
481
- "#{css}
504
+ +"#{css}
482
505
  <p style=\"color: green\"><%= notice %></p>#{"
483
506
  <select id=\"schema\">#{schema_options}</select>" if ::Brick.config.schema_behavior[:multitenant] && ::Brick.db_schemas.length > 1}
484
507
  <select id=\"tbl\">#{table_options}</select>
@@ -504,8 +527,7 @@ if (headerTop) {
504
527
  <thead><tr>#{'<th></th>' if pk.present?}<%
505
528
  col_order = []
506
529
  @#{table_name}.columns.each do |col|
507
- col_name = col.name
508
- next if (#{(pk || []).inspect}.include?(col_name) && col.type == :integer && !bts.key?(col_name)) ||
530
+ next if (#{(pk || []).inspect}.include?(col_name = col.name) && col.type == :integer && !bts.key?(col_name)) ||
509
531
  ::Brick.config.metadata_columns.include?(col_name) || poly_cols.include?(col_name)
510
532
 
511
533
  col_order << col_name
@@ -518,12 +540,12 @@ if (headerTop) {
518
540
  else %><%=
519
541
  col_name %><%
520
542
  end
521
- %></th><%
543
+ %></th><%
522
544
  end
523
545
  # Consider getting the name from the association -- h.first.name -- if a more \"friendly\" alias should be used for a screwy table name
524
546
  %>#{hms_headers.map do |h|
525
547
  if h.first.options[:through] && !h.first.through_reflection
526
- "<th>#{h[1]} #{h[2]} %></th>"
548
+ "<th>#{h[1]} #{h[2]} %></th>" # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
527
549
  else
528
550
  "<th>#{h[1]} <%= link_to('#{h[2]}', #{h.first.klass.name.underscore.tr('/', '_').pluralize}_path) %></th>"
529
551
  end
@@ -569,7 +591,7 @@ if (headerTop) {
569
591
  #{script}"
570
592
  when 'orphans'
571
593
  if is_orphans
572
- "#{css}
594
+ +"#{css}
573
595
  <p style=\"color: green\"><%= notice %></p>#{"
574
596
  <select id=\"schema\">#{schema_options}</select>" if ::Brick.config.schema_behavior[:multitenant] && ::Brick.db_schemas.length > 1}
575
597
  <select id=\"tbl\">#{table_options}</select>
@@ -584,7 +606,14 @@ if (headerTop) {
584
606
  end
585
607
 
586
608
  when 'show', 'update'
587
- "#{css}
609
+ +"#{css}
610
+
611
+ <svg id=\"revertTemplate\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"
612
+ width=\"32px\" height=\"32px\" viewBox=\"0 0 512 512\" xml:space=\"preserve\">
613
+ <path id=\"revertPath\" fill=\"#2020A0\" d=\"M271.844,119.641c-78.531,0-148.031,37.875-191.813,96.188l-80.172-80.188v256h256l-87.094-87.094
614
+ c23.141-70.188,89.141-120.906,167.063-120.906c97.25,0,176,78.813,176,176C511.828,227.078,404.391,119.641,271.844,119.641z\" />
615
+ </svg>
616
+
588
617
  <p style=\"color: green\"><%= notice %></p>#{"
589
618
  <select id=\"schema\">#{schema_options}</select>" if ::Brick.config.schema_behavior[:multitenant] && ::Brick.db_schemas.length > 1}
590
619
  <select id=\"tbl\">#{table_options}</select>
@@ -642,31 +671,39 @@ end
642
671
  <%= k %>
643
672
  <% end %>
644
673
  </th>
645
- <td>
646
- <% if bt
674
+ <td class=\"val\">
675
+ <% dt_pickers = { datetime: 'datetimepicker', timestamp: 'datetimepicker', time: 'timepicker', date: 'datepicker' }
676
+ if bt
647
677
  html_options = { prompt: \"Select #\{bt_name\}\" }
648
678
  html_options[:class] = 'dimmed' unless val %>
649
679
  <%= f.select k.to_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options %>
650
680
  <%= if (bt_obj = bt_class&.find_by(bt_pair[1] => val))
651
681
  link_to('⇛', send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_obj.send(bt_class.primary_key.to_sym)), { class: 'show-arrow' })
652
682
  elsif val
653
- \"Orphaned ID: #\{val}\"
654
- end %>
655
- <% else case #{model_name}.column_for_attribute(k).type
683
+ \"<span>Orphaned ID: #\{val}</span>\".html_safe
684
+ end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
685
+ <% else case (col_type = #{model_name}.column_for_attribute(k).type)
656
686
  when :string, :text %>
657
687
  <% if is_bcrypt?(val) # || .readonly? %>
658
688
  <%= hide_bcrypt(val, 1000) %>
659
689
  <% else %>
660
- <div class=\"wide-input\"><%= f.text_field k.to_sym %></div>
690
+ <div class=\"wide-input\"><%= f.text_field k.to_sym %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg></div>
661
691
  <% end %>
662
692
  <% when :boolean %>
663
- <%= f.check_box k.to_sym %>
664
- <% when :integer, :decimal, :float, :date, :datetime, :time, :timestamp
693
+ <%= f.check_box k.to_sym %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
694
+ <% when :integer, :decimal, :float
665
695
  # What happens when keys are UUID?
666
696
  # Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
667
697
  # If it's not yet enabled then: enable_extension 'uuid-ossp'
668
698
  # ActiveUUID gem created a new :uuid type %>
669
- <%= val %>
699
+ <%= if col_type == :integer
700
+ f.text_field k.to_sym, { pattern: '\\d*', class: 'check-validity' }
701
+ else
702
+ f.number_field k.to_sym
703
+ end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
704
+ <% when *dt_pickers.keys
705
+ is_includes_dates = true %>
706
+ <%= f.text_field k.to_sym, { class: dt_pickers[col_type] } %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
670
707
  <% when :binary, :primary_key %>
671
708
  <% end %>
672
709
  <% end %>
@@ -682,6 +719,7 @@ end
682
719
  <% end %>
683
720
 
684
721
  #{hms_headers.each_with_object(+'') do |hm, s|
722
+ # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
685
723
  next if hm.first.options[:through] && !hm.first.through_reflection
686
724
 
687
725
  if (pk = hm.first.klass.primary_key)
@@ -707,6 +745,61 @@ end
707
745
  #{script}"
708
746
 
709
747
  end
748
+ inline << "
749
+ <% if is_includes_dates %>
750
+ <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css\">
751
+ <style>
752
+ .flatpickr-calendar {
753
+ background: #A0FFA0;
754
+ }
755
+ </style>
756
+ <script src=\"https://cdn.jsdelivr.net/npm/flatpickr\"></script>
757
+ <script>
758
+ flatpickr(\".datepicker\");
759
+ flatpickr(\".datetimepicker\", {enableTime: true});
760
+ </script>
761
+ <% end %>
762
+ <script>
763
+ document.querySelectorAll(\"input, select\").forEach(function (inp) {
764
+ var origVal = getInpVal(),
765
+ prevVal = origVal;
766
+ var revert;
767
+ if ((revert = ((inp.tagName === \"SELECT\" && inp.nextElementSibling.nextElementSibling) ||
768
+ inp.nextElementSibling ||
769
+ inp.parentElement.nextElementSibling)) && revert.tagName.toLowerCase() === \"svg\")
770
+ revert.addEventListener(\"click\", function (e) {
771
+ if (inp.type === \"checkbox\")
772
+ inp.checked = origVal;
773
+ else
774
+ inp.value = origVal;
775
+ revert.style.display = \"none\";
776
+ if (!inp._flatpickr) inp.focus();
777
+ });
778
+ inp.addEventListener(inp.type === \"checkbox\" ? \"change\" : \"input\", function (e) {
779
+ if(inp.className.split(\" \").indexOf(\"check-validity\") > 0) {
780
+ if (inp.checkValidity()) {
781
+ prevVal = getInpVal();
782
+ } else {
783
+ inp.value = prevVal;
784
+ }
785
+ } else {
786
+ // If this is the result of changing an hour or minute, keep the calendar open.
787
+ // And if it was the result of selecting a date, the calendar can now close.
788
+ if (inp._flatpickr &&
789
+ // Test only for changes in the date portion of a date or datetime
790
+ ((giv = getInpVal()) && giv.split(' ')[0]) !== (prevVal && prevVal.split(' ')[0])
791
+ )
792
+ inp._flatpickr.close();
793
+ prevVal = getInpVal();
794
+ }
795
+ // Show or hide the revert button
796
+ if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"inline-block\";
797
+ });
798
+ function getInpVal() {
799
+ return inp.type === \"checkbox\" ? inp.checked : inp.value;
800
+ }
801
+ });
802
+ </script>"
710
803
  # As if it were an inline template (see #determine_template in actionview-5.2.6.2/lib/action_view/renderer/template_renderer.rb)
711
804
  keys = options.has_key?(:locals) ? options[:locals].keys : []
712
805
  handler = ActionView::Template.handler_for_extension(options[:type] || 'erb')
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 41
8
+ TINY = 42
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.41
4
+ version: 1.0.42
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-07-04 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord