brick 1.0.21 → 1.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +97 -66
- data/lib/brick/frameworks/rails/engine.rb +68 -48
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +1 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82ebef3561b9cd7b8abcbbd8a30b7687485543ddf1a0900a9935dfb99299f13f
|
4
|
+
data.tar.gz: ba071d53409fd8d4833693907364c745585aeb0bb18e885fcf7cbf1bd23b9940
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ad3ae158a8e478864db65dc808152d4b1b16bdc8779b1a651f59f199167daf00d2aa10018c5f65d5e619bbca4c09e99bc319ca736eed57023d61e6067ea365
|
7
|
+
data.tar.gz: 18ca63e176e12ea50a5168e835a2eddfa66c8f522943d42e6d895d2f3e05d0cf6d396ab28d79f98898c91670b618cc27dbad5fa0bc9129a3edcfc3f74f5db029
|
data/lib/brick/extensions.rb
CHANGED
@@ -166,8 +166,8 @@ module ActiveRecord
|
|
166
166
|
if is_brackets_have_content
|
167
167
|
output
|
168
168
|
elsif pk_alias
|
169
|
-
if (id = obj.send(
|
170
|
-
"#{klass.name} ##{id}"
|
169
|
+
if (id = pk_alias.map { |pk_alias_part| obj.send(pk_alias_part) })
|
170
|
+
"#{klass.name} ##{id.join(', ')}"
|
171
171
|
end
|
172
172
|
# elsif klass.primary_key
|
173
173
|
# "#{klass.name} ##{obj.send(klass.primary_key)}"
|
@@ -176,6 +176,14 @@ module ActiveRecord
|
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
+
def self.bt_link(assoc_name)
|
180
|
+
model_underscore = name.underscore
|
181
|
+
assoc_name = CGI.escapeHTML(assoc_name.to_s)
|
182
|
+
model_path = Rails.application.routes.url_helpers.send("#{model_underscore.pluralize}_path".to_sym)
|
183
|
+
link = Class.new.extend(ActionView::Helpers::UrlHelper).link_to(name, model_path)
|
184
|
+
model_underscore == assoc_name ? link : "#{assoc_name}-#{link}".html_safe
|
185
|
+
end
|
186
|
+
|
179
187
|
private
|
180
188
|
|
181
189
|
def self._brick_get_fks
|
@@ -267,27 +275,6 @@ module ActiveRecord
|
|
267
275
|
# , is_add_bts, is_add_hms
|
268
276
|
)
|
269
277
|
is_add_bts = is_add_hms = true
|
270
|
-
wheres = {}
|
271
|
-
has_hm = false
|
272
|
-
params.each do |k, v|
|
273
|
-
case (ks = k.split('.')).length
|
274
|
-
when 1
|
275
|
-
next unless klass._brick_get_fks.include?(k)
|
276
|
-
when 2
|
277
|
-
assoc_name = ks.first.to_sym
|
278
|
-
# Make sure it's a good association name and that the model has that column name
|
279
|
-
next unless (assoc = klass.reflect_on_association(assoc_name))&.klass&.columns&.map(&:name)&.include?(ks.last)
|
280
|
-
|
281
|
-
# So that we can map an association name to any special alias name used in an AREL query
|
282
|
-
ans = (assoc.klass._assoc_names[assoc_name] ||= [])
|
283
|
-
ans << assoc.klass unless ans.include?(assoc.klass)
|
284
|
-
# There is some potential for duplicates when there is an HM-based where in play. De-duplicate if so.
|
285
|
-
has_hm ||= assoc.macro == :has_many
|
286
|
-
join_array[assoc_name] = nil # Store this relation name in our special collection for .joins()
|
287
|
-
end
|
288
|
-
wheres[k] = v.split(',')
|
289
|
-
end
|
290
|
-
# distinct! if has_hm
|
291
278
|
|
292
279
|
# %%% Skip the metadata columns
|
293
280
|
if selects&.empty? # Default to all columns
|
@@ -301,59 +288,101 @@ module ActiveRecord
|
|
301
288
|
if is_add_bts || is_add_hms
|
302
289
|
bts, hms, associatives = ::Brick.get_bts_and_hms(klass)
|
303
290
|
bts.each do |_k, bt|
|
304
|
-
# join_array
|
291
|
+
# join_array will receive this relation name when calling #brick_parse_dsl
|
305
292
|
bt_descrip[bt.first] = [bt.last, bt.last.brick_parse_dsl(join_array, bt.first, translations)]
|
306
293
|
end
|
307
294
|
skip_klass_hms = ::Brick.config.skip_index_hms[klass.name] || {}
|
308
295
|
hms.each do |k, hm|
|
309
296
|
next if skip_klass_hms.key?(k)
|
310
297
|
|
311
|
-
|
312
|
-
hm_counts[k] = nil # Placeholder that will be filled in once we know the proper table alias
|
298
|
+
hm_counts[k] = hm
|
313
299
|
end
|
314
300
|
end
|
315
|
-
|
301
|
+
|
302
|
+
wheres = {}
|
303
|
+
params.each do |k, v|
|
304
|
+
case (ks = k.split('.')).length
|
305
|
+
when 1
|
306
|
+
next unless klass._brick_get_fks.include?(k)
|
307
|
+
when 2
|
308
|
+
assoc_name = ks.first.to_sym
|
309
|
+
# Make sure it's a good association name and that the model has that column name
|
310
|
+
next unless klass.reflect_on_association(assoc_name)&.klass&.columns&.any? { |col| col.name == ks.last }
|
311
|
+
|
312
|
+
join_array[assoc_name] = nil # Store this relation name in our special collection for .joins()
|
313
|
+
end
|
314
|
+
wheres[k] = v.split(',')
|
315
|
+
end
|
316
|
+
|
316
317
|
if join_array.present?
|
317
318
|
left_outer_joins!(join_array) # joins!(join_array)
|
318
319
|
# Without working from a duplicate, touching the AREL ast tree sets the @arel instance variable, which causes the relation to be immutable.
|
319
320
|
(rel_dupe = dup)._arel_alias_names
|
320
321
|
core_selects = selects.dup
|
321
|
-
groups = []
|
322
322
|
chains = rel_dupe._brick_chains
|
323
|
-
id_for_tables = {}
|
323
|
+
id_for_tables = Hash.new { |h, k| h[k] = [] }
|
324
|
+
field_tbl_names = Hash.new { |h, k| h[k] = {} }
|
324
325
|
bt_columns = bt_descrip.each_with_object([]) do |v, s|
|
325
|
-
tbl_name =
|
326
|
-
if (id_col = v.last.first.primary_key) && !id_for_tables.key?(tbl_name
|
327
|
-
|
328
|
-
|
329
|
-
|
326
|
+
tbl_name = field_tbl_names[v.first][v.last.first] ||= shift_or_first(chains[v.last.first])
|
327
|
+
if (id_col = v.last.first.primary_key) && !id_for_tables.key?(v.first) # was tbl_name
|
328
|
+
# Accommodate composite primary key by allowing id_col to come in as an array
|
329
|
+
(id_col.is_a?(Array) ? id_col : [id_col]).each do |id_part|
|
330
|
+
selects << "#{"#{tbl_name}.#{id_part}"} AS \"#{(id_alias = "_brfk_#{v.first}__#{id_part}")}\""
|
331
|
+
id_for_tables[v.first] << id_alias
|
332
|
+
end
|
333
|
+
v.last << id_for_tables[v.first]
|
330
334
|
end
|
331
335
|
if (col_name = v.last[1].last&.last)
|
336
|
+
field_tbl_name = nil
|
332
337
|
v.last[1].map { |x| [translations[x[0..-2].map(&:to_s).join('.')], x.last] }.each_with_index do |sel_col, idx|
|
333
|
-
|
338
|
+
field_tbl_name ||= field_tbl_names[v.first][sel_col.first] ||= shift_or_first(chains[sel_col.first])
|
334
339
|
# col_name is weak when there are multiple, using sel_col.last instead
|
335
|
-
|
336
|
-
selects << "#{unaliased} AS \"#{(col_alias = "_brfk_#{tbl_name2}__#{sel_col.last}")}\""
|
340
|
+
selects << "#{"#{field_tbl_name}.#{sel_col.last}"} AS \"#{(col_alias = "_brfk_#{v.first}__#{sel_col.last}")}\""
|
337
341
|
v.last[1][idx] << col_alias
|
338
342
|
end
|
339
343
|
end
|
340
344
|
end
|
341
|
-
group!(core_selects + groups) if hm_counts.any? # + bt_columns
|
342
345
|
join_array.each do |assoc_name|
|
343
346
|
# %%% Need to support {user: :profile}
|
344
347
|
next unless assoc_name.is_a?(Symbol)
|
345
348
|
|
346
|
-
klass = reflect_on_association(assoc_name)&.klass
|
347
|
-
table_alias = chains[klass].length > 1 ? chains[klass].shift : chains[klass].first
|
349
|
+
table_alias = shift_or_first(chains[klass = reflect_on_association(assoc_name)&.klass])
|
348
350
|
_assoc_names[assoc_name] = [table_alias, klass]
|
349
351
|
end
|
350
|
-
|
351
|
-
|
352
|
-
|
352
|
+
end
|
353
|
+
# Add derived table JOIN for the has_many counts
|
354
|
+
hm_counts.each do |k, hm|
|
355
|
+
associative = nil
|
356
|
+
count_column = if hm.options[:through]
|
357
|
+
fk_col = (associative = associatives[hm.name]).foreign_key
|
358
|
+
hm.foreign_key
|
359
|
+
else
|
360
|
+
fk_col = hm.foreign_key
|
361
|
+
hm.klass.primary_key || '*'
|
362
|
+
end
|
363
|
+
tbl_alias = "_br_#{hm.name}"
|
364
|
+
pri_tbl = hm.active_record
|
365
|
+
if fk_col.is_a?(Array) # Composite key?
|
366
|
+
on_clause = []
|
367
|
+
fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl.table_name}.#{pri_tbl.primary_key[idx]}" }
|
368
|
+
joins!("LEFT OUTER
|
369
|
+
JOIN (SELECT #{fk_col.join(', ')}, COUNT(#{count_column}) AS _ct_ FROM #{associative&.name || hm.klass.table_name} GROUP BY #{(1..fk_col.length).to_a.join(', ')}) AS #{tbl_alias}
|
370
|
+
ON #{on_clause.join(' AND ')}")
|
371
|
+
else
|
372
|
+
joins!("LEFT OUTER
|
373
|
+
JOIN (SELECT #{fk_col}, COUNT(#{count_column}) AS _ct_ FROM #{associative&.name || hm.klass.table_name} GROUP BY 1) AS #{tbl_alias}
|
374
|
+
ON #{tbl_alias}.#{fk_col} = #{pri_tbl.table_name}.#{pri_tbl.primary_key}")
|
353
375
|
end
|
354
376
|
end
|
377
|
+
where!(wheres) unless wheres.empty?
|
355
378
|
wheres unless wheres.empty? # Return the specific parameters that we did use
|
356
379
|
end
|
380
|
+
|
381
|
+
private
|
382
|
+
|
383
|
+
def shift_or_first(ary)
|
384
|
+
ary.length > 1 ? ary.shift : ary.first
|
385
|
+
end
|
357
386
|
end
|
358
387
|
|
359
388
|
module Inheritance
|
@@ -552,27 +581,30 @@ class Object
|
|
552
581
|
# Do the bulk of the has_many / belongs_to processing, and store details about HMT so they can be done at the very last
|
553
582
|
hmts = fks.each_with_object(Hash.new { |h, k| h[k] = [] }) do |fk, hmts|
|
554
583
|
# The key in each hash entry (fk.first) is the constraint name
|
555
|
-
|
556
|
-
inverse_assoc_name = assoc[:inverse]&.fetch(:assoc_name, nil)
|
584
|
+
inverse_assoc_name = (assoc = fk.last)[:inverse]&.fetch(:assoc_name, nil)
|
557
585
|
options = {}
|
558
586
|
singular_table_name = ActiveSupport::Inflector.singularize(assoc[:inverse_table])
|
559
587
|
macro = if assoc[:is_bt]
|
560
588
|
# Try to take care of screwy names if this is a belongs_to going to an STI subclass
|
561
|
-
if (primary_class = assoc.fetch(:primary_class, nil)) &&
|
562
|
-
|
563
|
-
|
564
|
-
|
589
|
+
assoc_name = if (primary_class = assoc.fetch(:primary_class, nil)) &&
|
590
|
+
sti_inverse_assoc = primary_class.reflect_on_all_associations.find do |a|
|
591
|
+
a.macro == :has_many && a.options[:class_name] == self.name && assoc[:fk] = a.foreign_key
|
592
|
+
end
|
593
|
+
sti_inverse_assoc.options[:inverse_of]&.to_s || assoc_name
|
594
|
+
else
|
595
|
+
assoc[:assoc_name]
|
596
|
+
end
|
565
597
|
need_class_name = singular_table_name.underscore != assoc_name
|
566
598
|
need_fk = "#{assoc_name}_id" != assoc[:fk]
|
567
599
|
if (inverse = assoc[:inverse])
|
568
600
|
inverse_assoc_name, _x = _brick_get_hm_assoc_name(relations[assoc[:inverse_table]], inverse)
|
569
601
|
if (has_ones = ::Brick.config.has_ones&.fetch(inverse[:alternate_name].camelize, nil))&.key?(singular_inv_assoc_name = ActiveSupport::Inflector.singularize(inverse_assoc_name))
|
570
602
|
inverse_assoc_name = if has_ones[singular_inv_assoc_name]
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
603
|
+
need_inverse_of = true
|
604
|
+
has_ones[singular_inv_assoc_name]
|
605
|
+
else
|
606
|
+
singular_inv_assoc_name
|
607
|
+
end
|
576
608
|
end
|
577
609
|
end
|
578
610
|
:belongs_to
|
@@ -583,12 +615,12 @@ class Object
|
|
583
615
|
need_fk = "#{ActiveSupport::Inflector.singularize(assoc[:inverse][:inverse_table])}_id" != assoc[:fk]
|
584
616
|
# fks[table_name].find { |other_assoc| other_assoc.object_id != assoc.object_id && other_assoc[:assoc_name] == assoc[assoc_name] }
|
585
617
|
if (has_ones = ::Brick.config.has_ones&.fetch(model_name, nil))&.key?(singular_assoc_name = ActiveSupport::Inflector.singularize(assoc_name))
|
586
|
-
assoc_name = if has_ones[singular_assoc_name]
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
618
|
+
assoc_name = if (custom_assoc_name = has_ones[singular_assoc_name])
|
619
|
+
need_class_name = custom_assoc_name != singular_assoc_name
|
620
|
+
custom_assoc_name
|
621
|
+
else
|
622
|
+
singular_assoc_name
|
623
|
+
end
|
592
624
|
:has_one
|
593
625
|
else
|
594
626
|
:has_many
|
@@ -674,7 +706,7 @@ class Object
|
|
674
706
|
@_brick_params = ar_relation.brick_select(params, (selects = []), (bt_descrip = {}), (hm_counts = {}), (join_array = ::Brick::JoinArray.new))
|
675
707
|
# %%% Add custom HM count columns
|
676
708
|
# %%% What happens when the PK is composite?
|
677
|
-
counts = hm_counts.each_with_object([]) { |v, s| s << "
|
709
|
+
counts = hm_counts.each_with_object([]) { |v, s| s << "_br_#{v.first}._ct_ AS _br_#{v.first}_ct" }
|
678
710
|
# *selects,
|
679
711
|
instance_variable_set("@#{table_name}".to_sym, ar_relation.dup._select!(*selects, *counts))
|
680
712
|
# binding.pry
|
@@ -732,7 +764,8 @@ class Object
|
|
732
764
|
|
733
765
|
def _brick_get_hm_assoc_name(relation, hm_assoc)
|
734
766
|
if relation[:hm_counts][hm_assoc[:assoc_name]]&.> 1
|
735
|
-
|
767
|
+
plural = ActiveSupport::Inflector.pluralize(hm_assoc[:alternate_name])
|
768
|
+
[hm_assoc[:alternate_name] == name.underscore ? "#{hm_assoc[:assoc_name].singularize}_#{plural}" : plural, true]
|
736
769
|
else
|
737
770
|
[ActiveSupport::Inflector.pluralize(hm_assoc[:inverse_table]), nil]
|
738
771
|
end
|
@@ -989,18 +1022,16 @@ module Brick
|
|
989
1022
|
|
990
1023
|
return if is_class || ::Brick.config.exclude_hms&.any? { |exclusion| fk[0] == exclusion[0] && fk[1] == exclusion[1] && primary_table == exclusion[2] }
|
991
1024
|
|
992
|
-
|
993
|
-
if (assoc_hm = hms.fetch(cnstr_name, nil))
|
1025
|
+
if (assoc_hm = hms.fetch((hm_cnstr_name = "hm_#{cnstr_name}"), nil))
|
994
1026
|
assoc_hm[:fk] = assoc_hm[:fk].is_a?(String) ? [assoc_hm[:fk], fk[1]] : assoc_hm[:fk].concat(fk[1])
|
995
1027
|
assoc_hm[:alternate_name] = "#{assoc_hm[:alternate_name]}_#{bt_assoc_name}" unless assoc_hm[:alternate_name] == bt_assoc_name
|
996
1028
|
assoc_hm[:inverse] = assoc_bt
|
997
1029
|
else
|
998
|
-
assoc_hm = hms[
|
1030
|
+
assoc_hm = hms[hm_cnstr_name] = { is_bt: false, fk: fk[1], assoc_name: fk[0], alternate_name: bt_assoc_name, inverse_table: fk[0], inverse: assoc_bt }
|
999
1031
|
hm_counts = relation.fetch(:hm_counts) { relation[:hm_counts] = {} }
|
1000
1032
|
hm_counts[fk[0]] = hm_counts.fetch(fk[0]) { 0 } + 1
|
1001
1033
|
end
|
1002
1034
|
assoc_bt[:inverse] = assoc_hm
|
1003
|
-
# hms[cnstr_name] << { is_bt: false, fk: fk[1], assoc_name: fk[0], alternate_name: bt_assoc_name, inverse_table: fk[0] }
|
1004
1035
|
end
|
1005
1036
|
end
|
1006
1037
|
end
|
@@ -64,6 +64,14 @@ module Brick
|
|
64
64
|
is_template_exists
|
65
65
|
end
|
66
66
|
|
67
|
+
def path_keys(fk_name, obj_name, pk)
|
68
|
+
if fk_name.is_a?(Array) && pk.is_a?(Array) # Composite keys?
|
69
|
+
fk_name.zip(pk.map { |pk_part| "#{obj_name}.#{pk_part}" })
|
70
|
+
else
|
71
|
+
[[fk_name, "#{obj_name}.#{pk}"]]
|
72
|
+
end.map { |x| "#{x.first}: #{x.last}"}.join(', ')
|
73
|
+
end
|
74
|
+
|
67
75
|
alias :_brick_find_template :find_template
|
68
76
|
def find_template(*args, **options)
|
69
77
|
return _brick_find_template(*args, **options) unless @_brick_model
|
@@ -73,35 +81,32 @@ module Brick
|
|
73
81
|
obj_name = model_name.underscore
|
74
82
|
table_name = model_name.pluralize.underscore
|
75
83
|
bts, hms, associatives = ::Brick.get_bts_and_hms(@_brick_model) # This gets BT and HM and also has_many :through (HMT)
|
76
|
-
hms_columns =
|
84
|
+
hms_columns = [] # Used for 'index'
|
77
85
|
skip_klass_hms = ::Brick.config.skip_index_hms[model_name] || {}
|
78
86
|
hms_headers = hms.each_with_object([]) do |hm, s|
|
79
|
-
hm_assoc = hm.last
|
80
|
-
if
|
81
|
-
|
82
|
-
|
83
|
-
"'#{associative.name}.#{associative.foreign_key}'"
|
84
|
-
else
|
85
|
-
hm_assoc.foreign_key
|
86
|
-
end
|
87
|
-
hms_columns << if hm_assoc.macro == :has_many
|
88
|
-
set_ct = if skip_klass_hms.key?((assoc_name = hm.first).to_sym)
|
89
|
-
'nil'
|
87
|
+
hm_stuff = [(hm_assoc = hm.last), "H#{hm_assoc.macro == :has_one ? 'O' : 'M'}#{'T' if hm_assoc.options[:through]}", (assoc_name = hm.first)]
|
88
|
+
hm_fk_name = if hm_assoc.options[:through]
|
89
|
+
associative = associatives[hm_assoc.name]
|
90
|
+
"'#{associative.name}.#{associative.foreign_key}'"
|
90
91
|
else
|
91
|
-
|
92
|
+
hm_assoc.foreign_key
|
92
93
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
if args.first == 'index'
|
95
|
+
hms_columns << if hm_assoc.macro == :has_many
|
96
|
+
set_ct = if skip_klass_hms.key?(assoc_name.to_sym)
|
97
|
+
'nil'
|
98
|
+
else
|
99
|
+
"#{obj_name}._br_#{assoc_name}_ct || 0"
|
100
|
+
end
|
101
|
+
"<%= ct = #{set_ct}
|
102
|
+
link_to \"#\{ct || 'View'\} #{assoc_name}\", #{hm_assoc.klass.name.underscore.pluralize}_path({ #{path_keys(hm_fk_name, obj_name, pk)} }) unless ct&.zero? %>\n"
|
98
103
|
else # has_one
|
99
|
-
"
|
100
|
-
<%= obj = #{obj_name}.#{hm.first}; link_to(obj.brick_descrip, obj) if obj %>
|
101
|
-
</td>\n"
|
104
|
+
"<%= obj = #{obj_name}.#{hm.first}; link_to(obj.brick_descrip, obj) if obj %>\n"
|
102
105
|
end
|
106
|
+
elsif args.first == 'show'
|
107
|
+
hm_stuff << "<%= link_to '#{assoc_name}', #{hm_assoc.klass.name.underscore.pluralize}_path({ #{path_keys(hm_fk_name, "@#{obj_name}&.first&", pk)} }) %>\n"
|
103
108
|
end
|
104
|
-
s <<
|
109
|
+
s << hm_stuff
|
105
110
|
end
|
106
111
|
|
107
112
|
schema_options = ::Brick.db_schemas.each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }.html_safe
|
@@ -121,9 +126,12 @@ table {
|
|
121
126
|
|
122
127
|
table thead tr th, table tr th {
|
123
128
|
background-color: #009879;
|
124
|
-
color: #
|
129
|
+
color: #fff;
|
125
130
|
text-align: left;
|
126
131
|
}
|
132
|
+
table thead tr th a, table tr th a {
|
133
|
+
color: #80FFB8;
|
134
|
+
}
|
127
135
|
|
128
136
|
table th, table td {
|
129
137
|
padding: 0.2em 0.5em;
|
@@ -132,6 +140,9 @@ table th, table td {
|
|
132
140
|
.show-field {
|
133
141
|
background-color: #004998;
|
134
142
|
}
|
143
|
+
.show-field a {
|
144
|
+
color: #80B8D2;
|
145
|
+
}
|
135
146
|
|
136
147
|
table tbody tr {
|
137
148
|
border-bottom: thin solid #dddddd;
|
@@ -244,6 +255,11 @@ function changeout(href, param, value) {
|
|
244
255
|
</script>"
|
245
256
|
inline = case args.first
|
246
257
|
when 'index'
|
258
|
+
obj_pk = if pk&.is_a?(Array) # Composite primary key?
|
259
|
+
"[#{pk.map { |pk_part| "#{obj_name}.#{pk_part}" }.join(', ')}]"
|
260
|
+
elsif pk
|
261
|
+
"#{obj_name}.#{pk}"
|
262
|
+
end
|
247
263
|
"#{css}
|
248
264
|
<p style=\"color: green\"><%= notice %></p>#{"
|
249
265
|
<select id=\"schema\">#{schema_options}</select>" if ::Brick.db_schemas.length > 1}
|
@@ -256,26 +272,27 @@ function changeout(href, param, value) {
|
|
256
272
|
<% next if col == '#{pk}' || ::Brick.config.metadata_columns.include?(col) %>
|
257
273
|
<th>
|
258
274
|
<% if (bt = bts[col]) %>
|
259
|
-
BT <%=
|
275
|
+
BT <%= bt[1].bt_link(bt.first) %>
|
260
276
|
<% else %>
|
261
277
|
<%= col %>
|
262
278
|
<% end %>
|
263
279
|
</th>
|
264
280
|
<% end %>
|
265
|
-
|
281
|
+
<%# Consider getting the name from the association -- h.first.name -- if a more \"friendly\" alias should be used for a screwy table name %>
|
282
|
+
#{hms_headers.map { |h| "<th>#{h[1]} <%= link_to('#{h[2]}', #{h.first.klass.name.underscore.pluralize}_path) %></th>\n" }.join}
|
266
283
|
</tr></thead>
|
267
284
|
|
268
285
|
<tbody>
|
269
286
|
<% @#{table_name}.each do |#{obj_name}| %>
|
270
287
|
<tr>#{"
|
271
|
-
<td><%= link_to '⇛', #{obj_name}_path(#{
|
288
|
+
<td><%= link_to '⇛', #{obj_name}_path(#{obj_pk}), { class: 'big-arrow' } %></td>" if pk}
|
272
289
|
<% #{obj_name}.attributes.each do |k, val| %>
|
273
290
|
<% next if k == '#{pk}' || ::Brick.config.metadata_columns.include?(k) || k.start_with?('_brfk_') || (k.start_with?('_br_') && k.end_with?('_ct')) %>
|
274
291
|
<td>
|
275
292
|
<% if (bt = bts[k]) %>
|
276
|
-
<%# binding.pry
|
277
|
-
<% bt_txt = bt[1].brick_descrip(#{obj_name}, @_brick_bt_descrip[bt.first][1].map { |z| #{obj_name}.send(z.last) }, @_brick_bt_descrip[bt.first][2]) %>
|
278
|
-
<% bt_id_col = @_brick_bt_descrip[bt.first][2]; bt_id = #{obj_name}.send(bt_id_col) if bt_id_col %>
|
293
|
+
<%# binding.pry # Postgres column names are limited to 63 characters!!! %>
|
294
|
+
<% bt_txt = bt[1].brick_descrip(#{obj_name}, @_brick_bt_descrip[bt.first][1].map { |z| #{obj_name}.send(z.last[0..62]) }, @_brick_bt_descrip[bt.first][2]) %>
|
295
|
+
<% bt_id_col = @_brick_bt_descrip[bt.first][2]; bt_id = #{obj_name}.send(*bt_id_col) if bt_id_col&.present? %>
|
279
296
|
<%= bt_id ? link_to(bt_txt, send(\"#\{bt_obj_path_base = bt[1].name.underscore\}_path\".to_sym, bt_id)) : bt_txt %>
|
280
297
|
<%#= Previously was: bt_obj = bt[1].find_by(bt[2] => val); link_to(bt_obj.brick_descrip, send(\"#\{bt_obj_path_base = bt[1].name.underscore\}_path\".to_sym, bt_obj.send(bt[1].primary_key.to_sym))) if bt_obj %>
|
281
298
|
<% else %>
|
@@ -283,7 +300,7 @@ function changeout(href, param, value) {
|
|
283
300
|
<% end %>
|
284
301
|
</td>
|
285
302
|
<% end %>
|
286
|
-
|
303
|
+
<td>#{hms_columns.join('</td><td>')}</td>
|
287
304
|
<!-- td>X</td -->
|
288
305
|
</tr>
|
289
306
|
</tbody>
|
@@ -301,9 +318,9 @@ function changeout(href, param, value) {
|
|
301
318
|
<%= link_to '(See all #{obj_name.pluralize})', #{table_name}_path %>
|
302
319
|
<% if obj %>
|
303
320
|
<%= # path_options = [obj.#{pk}]
|
304
|
-
# path_options << { '_brick_schema': } if
|
321
|
+
# path_options << { '_brick_schema': } if
|
305
322
|
# url = send(:#{model_name.underscore}_path, obj.#{pk})
|
306
|
-
form_for(obj) do |f| %>
|
323
|
+
form_for(obj.becomes(#{model_name})) do |f| %>
|
307
324
|
<table>
|
308
325
|
<% @#{obj_name}.first.attributes.each do |k, val| %>
|
309
326
|
<tr>
|
@@ -317,7 +334,7 @@ function changeout(href, param, value) {
|
|
317
334
|
bt << (option_detail = [[\"(No #\{bt_name\} chosen)\", '^^^brick_NULL^^^']])
|
318
335
|
bt[1].order(:#{pk}).each { |obj| option_detail << [obj.brick_descrip, obj.#{pk}] }
|
319
336
|
end %>
|
320
|
-
BT <%=
|
337
|
+
BT <%= bt[1].bt_link(bt.first) %>
|
321
338
|
<% else %>
|
322
339
|
<%= k %>
|
323
340
|
<% end %>
|
@@ -353,21 +370,24 @@ function changeout(href, param, value) {
|
|
353
370
|
</table>
|
354
371
|
<% end %>
|
355
372
|
|
356
|
-
#{hms_headers.
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
373
|
+
#{hms_headers.each_with_object(+'') do |hm, s|
|
374
|
+
if (pk = hm.first.klass.primary_key)
|
375
|
+
s << "<table id=\"#{hm_name = hm.first.name.to_s}\">
|
376
|
+
<tr><th>#{hm[3]}</th></tr>
|
377
|
+
<% collection = @#{obj_name}.first.#{hm_name}
|
378
|
+
collection = collection.is_a?(ActiveRecord::Associations::CollectionProxy) ? collection.order(#{pk.inspect}) : [collection]
|
379
|
+
if collection.empty? %>
|
380
|
+
<tr><td>(none)</td></tr>
|
381
|
+
<% else %>
|
382
|
+
<% collection.uniq.each do |#{hm_singular_name = hm_name.singularize.underscore}| %>
|
383
|
+
<tr><td><%= link_to(#{hm_singular_name}.brick_descrip, #{hm.first.klass.name.underscore}_path(#{hm_singular_name}.#{pk})) %></td></tr>
|
384
|
+
<% end %>
|
385
|
+
<% end %>
|
386
|
+
</table>"
|
387
|
+
else
|
388
|
+
s
|
389
|
+
end
|
390
|
+
end}
|
371
391
|
<% end %>
|
372
392
|
#{script}"
|
373
393
|
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -105,9 +105,6 @@ module Brick
|
|
105
105
|
bts, hms = model.reflect_on_all_associations.each_with_object([{}, {}]) do |a, s|
|
106
106
|
next if !const_defined?(a.name.to_s.singularize.camelize) && ::Brick.config.exclude_tables.include?(a.plural_name)
|
107
107
|
|
108
|
-
# So that we can map an association name to any special alias name used in an AREL query
|
109
|
-
ans = (model._assoc_names[a.name] ||= [])
|
110
|
-
ans << a.klass unless ans.include?(a.klass)
|
111
108
|
case a.macro
|
112
109
|
when :belongs_to
|
113
110
|
s.first[a.foreign_key] = [a.name, a.klass]
|
@@ -427,9 +424,7 @@ ActiveSupport.on_load(:active_record) do
|
|
427
424
|
end
|
428
425
|
|
429
426
|
result = result.map do |attributes|
|
430
|
-
|
431
|
-
|
432
|
-
columns.zip(values).map do |column, value|
|
427
|
+
columns.zip(klass.initialize_attributes(attributes).values).map do |column, value|
|
433
428
|
column.type_cast(value)
|
434
429
|
end
|
435
430
|
end
|
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.
|
4
|
+
version: 1.0.22
|
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-05-
|
11
|
+
date: 2022-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|