brick 1.0.63 → 1.0.64

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: c28a4db728e9312def40be9a9a790f1f22f464c6d6ade2b6e12f255730cd4111
4
- data.tar.gz: c2e75de42686c9ad0707fd6eca3d0b0a12207e051d77622d70276845d9af0949
3
+ metadata.gz: c48ee6a2f143563e2e443f6edf0dc0e04e800e8fae6951e05b0362956129e950
4
+ data.tar.gz: f632f6e795dcf9b3aeb97e36a37c8074302c5967206b5f415a9a4b862bb4fda7
5
5
  SHA512:
6
- metadata.gz: a897f30028aac1b6e14edc967a82c268aa58236cd424ecf977409a0c893d42b9e291c11ac2b2a411f00dc35c23b80a4ed6adecde394587c96d11b9f51c173fd8
7
- data.tar.gz: 538d694b6a0717045c6e23ec536a000a552bc0ece9009f74511e33013e0dde97f8cefadbc61a45d4b7ea884dd0c1dd985f5defc58175ec51318d345a7e561c2d
6
+ metadata.gz: 0cd5e05899a2f780a0bbf378f8f49e49f604b90cf122f2cd7efe34839c434af814c9a228f36bd18b112cd8e40b6736e88742ea0f2a1a0b55ac3f8f573e614918
7
+ data.tar.gz: a34a9f47746159f6b4b39f8a3cd994055e022be9eefe8737b73c63e5d475b283ae3b99a6a11e3faf140ca6efbf67d7f400e03147a757c237c8875f11ea2c0ea4
@@ -182,8 +182,6 @@ module Brick
182
182
  h1, h3 {
183
183
  margin-bottom: 0;
184
184
  }
185
- #resourceName {
186
- }
187
185
  #imgErd {
188
186
  background-image:url(assets/brick_erd.png);
189
187
  background-size: 100% 100%;
@@ -453,25 +451,27 @@ window.addEventListener(\"pageshow\", function() {
453
451
 
454
452
  function changeout(href, param, value, trimAfter) {
455
453
  var hrefParts = href.split(\"?\");
456
- if (param === undefined || param === null) {
454
+ var params = hrefParts.length > 1 ? hrefParts[1].split(\"&\") : [];
455
+ if (param === undefined || param === null || param === -1) {
457
456
  hrefParts = hrefParts[0].split(\"://\");
458
457
  var pathParts = hrefParts[hrefParts.length - 1].split(\"/\");
459
458
  if (value === undefined)
460
459
  // A couple possibilities if it's namespaced, starting with two parts in the path -- and then try just one
461
460
  return [pathParts.slice(1, 3).join('/'), pathParts.slice(1, 2)[0]];
462
- else
463
- return hrefParts[0] + \"://\" + pathParts[0] + \"/\" + value;
461
+ else {
462
+ var queryString = param ? \"?\" + params.join(\"&\") : \"\";
463
+ return hrefParts[0] + \"://\" + pathParts[0] + \"/\" + value + queryString;
464
+ }
464
465
  }
465
466
  if (trimAfter) {
466
467
  var pathParts = hrefParts[0].split(\"/\");
467
468
  while (pathParts.lastIndexOf(trimAfter) !== pathParts.length - 1) pathParts.pop();
468
469
  hrefParts[0] = pathParts.join(\"/\");
469
470
  }
470
- var params = hrefParts.length > 1 ? hrefParts[1].split(\"&\") : [];
471
- params = params.reduce(function (s, v) { var parts = v.split(\"=\"); if (parts[1] !== null) s[parts[0]] = parts[1]; return s; }, {});
471
+ params = params.reduce(function (s, v) { var parts = v.split(\"=\"); if (parts[1]) s[parts[0]] = parts[1]; return s; }, {});
472
472
  if (value === undefined) return params[param];
473
473
  params[param] = value;
474
- var finalParams = Object.keys(params).reduce(function (s, v) { if (params[v] !== null) s.push(v + \"=\" + params[v]); return s; }, []).join(\"&\");
474
+ var finalParams = Object.keys(params).reduce(function (s, v) { if (params[v]) s.push(v + \"=\" + params[v]); return s; }, []).join(\"&\");
475
475
  return hrefParts[0] + (finalParams.length > 0 ? \"?\" + finalParams : \"\");
476
476
  }
477
477
 
@@ -677,25 +677,53 @@ erDiagram
677
677
  <% model_short_name = #{@_brick_model.name.split('::').last.inspect}
678
678
  callbacks = {}
679
679
  @_brick_bt_descrip.each do |bt|
680
- bt_full_name = bt[1].first.first.name
681
- callbacks[bt_name = bt_full_name.split('::').last] = bt_full_name
682
- # binding.pry
683
- %> <%= \"#\{model_short_name} #\{'||'}--#\{
684
- 'o{'} #\{bt_name} : \\\"#\{
680
+ bt_class = bt[1].first.first
681
+ callbacks[bt_name = bt_class.name.split('::').last] = bt_class
682
+ is_has_one = #{@_brick_model.name}.reflect_on_association(bt.first).inverse_of&.macro == :has_one ||
683
+ ::Brick.config.has_ones&.fetch('#{@_brick_model.name}', nil)&.key?(bt.first.to_s)
684
+ %> <%= \"#\{model_short_name} #\{is_has_one ? '||' : '}o'}--|| #\{bt_name} : \\\"#\{
685
685
  bt.first unless bt.first.to_s == bt[1].first.first.name.underscore.singularize.tr('/', '_')
686
686
  }\\\"\".html_safe %>
687
- <% end %>
688
- <% @_brick_hm_counts.each do |hm|
689
- hm_full_name = hm.last.klass.name
690
- callbacks[hm_name = hm_full_name.split('::').last] = hm_full_name
691
- %> <%= \"#\{model_short_name} #\{'}o'}--#\{
692
- '||'} #\{hm_name} : \\\"#\{
693
- hm.first unless hm.first.to_s == hm_full_name.underscore.pluralize.tr('/', '_')
694
- }\\\"\".html_safe %>
695
- <% end %>
696
- <% callbacks.keys.each do |cb|
697
- %> <%= cb %> {
698
- int id
687
+ <% end
688
+ last_through = nil
689
+ @_brick_hm_counts.each do |hm|
690
+ # Skip showing self-referencing HM links since they would have already been drawn while evaluating the BT side
691
+ next if (hm_class = hm.last.klass) == #{@_brick_model.name}
692
+
693
+ callbacks[hm_name = hm_class.name.split('::').last] = hm_class
694
+ if (through = hm.last.options[:through]&.to_s) # has_many :through (HMT)
695
+ callbacks[through.singularize.camelize] = (through_assoc = hm.last.source_reflection).active_record
696
+ if last_through == through # Same HM, so no need to build it again, and for clarity just put in a blank line
697
+ %><%= \"\n\"
698
+ %><% else
699
+ %> <%= \"#\{model_short_name} ||--o{ #\{through_assoc.active_record.name}\".html_safe %> : \"\"
700
+ <% last_through = through
701
+ end
702
+ %> <%= \"#\{through_assoc.active_record.name} }o--|| #\{hm_name}\".html_safe %> : \"\"
703
+ <%= \"#\{model_short_name} }o..o{ #\{hm_name} : \\\"#\{hm.first}\\\"\".html_safe %><%
704
+ else # has_many
705
+ %> <%= \"#\{model_short_name} ||--o{ #\{hm_name} : \\\"#\{
706
+ hm_name unless hm.first.to_s == hm_class.name.underscore.pluralize.tr('/', '_')
707
+ }\\\"\".html_safe %><%
708
+ end %>
709
+ <% end
710
+ callbacks.merge({model_short_name => #{@_brick_model.name}}).each do |cb_k, cb_class|
711
+ cb_relation = ::Brick.relations[cb_class.table_name]
712
+ pkeys = cb_relation[:pkey]&.first&.last
713
+ fkeys = cb_relation[:fks]&.values&.each_with_object([]) { |fk, s| s << fk[:fk] if fk.fetch(:is_bt, nil) }
714
+ %> <%= cb_k %> {<%
715
+ pkeys&.each do |pk| %>
716
+ <%= \"int #\{pk} \\\"PK#\{' fk' if fkeys&.include?(pk)}\\\"\".html_safe %><%
717
+ end %><%
718
+ fkeys&.each do |fk|
719
+ if fk.is_a?(Array)
720
+ fk.each do |fk_part| %>
721
+ <%= \"int #\{fk_part} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk_part) %><%
722
+ end
723
+ else %>
724
+ <%= \"int #\{fk} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk) %><%
725
+ end
726
+ end %>
699
727
  }
700
728
  <% end
701
729
  # callback < %= cb_k % > erdClick
@@ -1034,7 +1062,7 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1034
1062
  var imgErd = document.getElementById(\"imgErd\");
1035
1063
  var mermaidErd = document.getElementById(\"mermaidErd\");
1036
1064
  var mermaidCode;
1037
- var cbs = {<%= callbacks.map { |k, v| \"#\{k}: \\\"#\{v.underscore.pluralize}\\\"\" }.join(', ').html_safe %>};
1065
+ var cbs = {<%= callbacks.map { |k, v| \"#\{k}: \\\"#\{v.name.underscore.pluralize}\\\"\" }.join(', ').html_safe %>};
1038
1066
  imgErd.addEventListener(\"click\", showErd);
1039
1067
  function showErd() {
1040
1068
  imgErd.style.display = \"none\";
@@ -1049,13 +1077,14 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1049
1077
  securityLevel: \"loose\",
1050
1078
  mermaid: {callback: function(objId) {
1051
1079
  var svg = document.getElementById(objId);
1080
+ svg.removeAttribute(\"width\");
1052
1081
  var cb;
1053
1082
  for(cb in cbs) {
1054
1083
  var gErd = svg.getElementById(cb);
1055
1084
  gErd.setAttribute(\"class\", \"relatedModel\");
1056
1085
  gErd.addEventListener(\"click\",
1057
1086
  function (evt) {
1058
- location.href = changeout(changeout(location.href, null, cbs[this.id]), \"_brick_erd\", \"1\");
1087
+ location.href = changeout(changeout(location.href, -1, cbs[this.id]), \"_brick_erd\", \"1\");
1059
1088
  }
1060
1089
  );
1061
1090
  }
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 63
8
+ TINY = 64
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.63
4
+ version: 1.0.64
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-08-24 00:00:00.000000000 Z
11
+ date: 2022-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord