Skip to content

Commit

Permalink
Add N:M Constellation visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorin Thwaits committed Mar 28, 2024
1 parent 787f392 commit a386fa2
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ https://user-images.githubusercontent.com/5301131/184541537-99b37fc6-ed5e-46e9-9
| Version | Documentation |
| -------------- | ----------------------------------------------------- |
| Unreleased | https://github.com/lorint/brick/blob/master/README.md |
| 1.0.211 | https://github.com/lorint/brick/blob/v1.0/README.md |
| 1.0.212 | https://github.com/lorint/brick/blob/v1.0/README.md |

One core goal behind The Brick is to adhere as closely as possible to Rails conventions. As
such, models, controllers, and views are treated independently. You can use this tool to only
Expand Down
2 changes: 1 addition & 1 deletion docs/bug_report_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
source 'https://rubygems.org'
gem 'activerecord', '5.2.6'
gem 'minitest', '5.15'
gem 'brick', '1.0.211'
gem 'brick', '1.0.212'
gem 'sqlite3'
end

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_5.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_5.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_5.2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_6.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_6.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_7.0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar_7.1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
brick (1.0.211)
brick (1.0.212)
activerecord (>= 3.1.1)
fancy_gets

Expand Down
19 changes: 18 additions & 1 deletion lib/brick/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,24 @@ def treat_as_associative
end

def treat_as_associative=(tables)
@mutex.synchronize { @treat_as_associative = tables }
@mutex.synchronize do
@treat_as_associative = if tables.is_a?(Hash)
tables.each_with_object({}) do |v, s|
# If it's :constellation, or anything else in a hash, we'll take its value
# (and hopefully in this case that would be either a string or nil)
dsl = ((v.last.is_a?(Symbol) && v.last) || v.last&.values&.last)
unless (dsl ||= '').is_a?(String) || dsl.is_a?(Symbol)
puts "Was really expecting #{v.first} / #{v.last.first&.first} / #{dsl} to be a string, " +
"so will disregard #{dsl} and just turn on simple constellation view for #{v.first}."
end
s[v.first] = v.last.is_a?(Hash) ? dsl : v.last
end
elsif tables.is_a?(String) # comma-separated list?
tables.split(',').each_with_object({}) { |v, s| s[v.trim] = nil }
else # Expecting an Array, and have no special presentation
tables&.each_with_object({}) { |v, s| s[v] = nil }
end
end
end

# Polymorphic associations
Expand Down
17 changes: 17 additions & 0 deletions lib/brick/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,23 @@ def build_controller(namespace, class_name, plural_class_name, model, relations)
# add_csp_hash
# end
# end

# Associate and unassociate in an N:M relation
self.define_method :associate do
if (base_class = (model = params['modelName']&.constantize).base_class)
args = params['args']
record = base_class.create(args[0] => args[1], args[2] => args[3])
add_csp_hash
render json: { data: record.id }
end
end
self.define_method :unassociate do
if (base_class = (model = params['modelName']&.constantize).base_class)
base_class.find_by(base_class._pk_as_array&.first => params['id']).delete
add_csp_hash
end
end

self.define_method :orphans do
instance_variable_set(:@orphans, ::Brick.find_orphans(::Brick.set_db_schema(params).first))
add_csp_hash
Expand Down
30 changes: 24 additions & 6 deletions lib/brick/frameworks/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,26 @@ def slashify(*vals)
# or
# Rails.application.reloader.to_prepare do ... end
self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
# Write out the mega-grid
#{# Determine if we should render an N:M representation or the standard "mega_grid"
taa = ::Brick.config.treat_as_associative&.fetch(res_name, nil)
options = {}
options[:prefix] = prefix unless prefix.blank?
if taa.is_a?(String) # Write out a constellation
representation = :constellation
"
brick_constellation(@#{res_name}, #{options.inspect}, bt_descrip: @_brick_bt_descrip, bts: bts)"
elsif taa.is_a?(Symbol) # Write out a bezier representation
"
brick_bezier(@#{res_name}, #{options.inspect}, bt_descrip: @_brick_bt_descrip, bts: bts)"
else # Write out the mega-grid
representation = :grid
"
brick_grid(@#{res_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
cols, bt_descrip: @_brick_bt_descrip, poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}}) %>
cols, bt_descrip: @_brick_bt_descrip,
poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}})"
end}
%>
#{"<hr><%= link_to(\"New #{new_path_name = "new_#{path_obj_name}_path"
obj_name}\", #{new_path_name}, { class: '__brick' }) if respond_to?(:#{new_path_name}) %>" unless @_brick_model.is_view?}
Expand Down Expand Up @@ -1727,10 +1744,11 @@ def slashify(*vals)
}
<%= \" showErd();\n\" if (@_brick_erd || 0) > 0
%></script>
<% end
%><script>
<% end %>
"
end
if representation == :grid
"<script>
<% # Make column headers sort when clicked
# %%% Create a smart javascript routine which can do this client-side %>
[... document.getElementsByTagName(\"TH\")].forEach(function (th) {
Expand Down
Loading

0 comments on commit a386fa2

Please sign in to comment.