brick 1.0.99 → 1.0.100
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 +4 -4
- data/lib/brick/extensions.rb +6 -27
- data/lib/brick/frameworks/rails/engine.rb +3 -19
- data/lib/brick/frameworks/rails/form_tags.rb +3 -47
- data/lib/brick/version_number.rb +1 -1
- 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: ba0de7f332d1d98502a4e66bc4fda9b44d4f97fe6d6a259ac7527a856c726000
|
4
|
+
data.tar.gz: 45898a638f4c944cf33e98ff73a41da97686819bbdfcc8534257c013a6b28582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28079c58b020d395845c681710c88db3e7a32ae312fbdf607ab496854aab37d29f3a9dfed78a2495a011b3817aed8259260a1d0d5ecd409803d89b4eda70b87f
|
7
|
+
data.tar.gz: 834499603e05412ee19c2f5db90f55df1f927eff85a41488e4f57381065580aeb4477700596988e4cc630282268f40045d1831822bde2c80b659a23e257f692a
|
data/lib/brick/extensions.rb
CHANGED
@@ -404,21 +404,9 @@ module ActiveRecord
|
|
404
404
|
def brick_select(params, selects = [], order_by = nil, translations = {}, join_array = ::Brick::JoinArray.new)
|
405
405
|
is_add_bts = is_add_hms = true
|
406
406
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
model._brick_calculate_bts_hms(translations, join_array) if is_add_bts || is_add_hms
|
411
|
-
else
|
412
|
-
is_api = true
|
413
|
-
# If there are any provided selects, treat them as API columns and build them as cust_cols since they
|
414
|
-
# can be built using DSL.
|
415
|
-
# false = not polymorphic, and true = yes -- please emit_dsl
|
416
|
-
selects.each do |api_col|
|
417
|
-
pieces, my_dsl = brick_parse_dsl(join_array, [], translations, false, "[#{api_col}]", true)
|
418
|
-
_br_cust_cols[api_col.tr('.', '_')] = [pieces, my_dsl]
|
419
|
-
end
|
420
|
-
selects.clear # Now these have become custom columns
|
421
|
-
end
|
407
|
+
# Build out cust_cols, bt_descrip and hm_counts now so that they are available on the
|
408
|
+
# model early in case the user wants to do an ORDER BY based on any of that.
|
409
|
+
model._brick_calculate_bts_hms(translations, join_array) if is_add_bts || is_add_hms
|
422
410
|
|
423
411
|
is_postgres = ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
424
412
|
is_mysql = ActiveRecord::Base.connection.adapter_name == 'Mysql2'
|
@@ -426,7 +414,7 @@ module ActiveRecord
|
|
426
414
|
is_distinct = nil
|
427
415
|
wheres = {}
|
428
416
|
params.each do |k, v|
|
429
|
-
next if ['_brick_schema', '_brick_order', '
|
417
|
+
next if ['_brick_schema', '_brick_order', 'controller', 'action'].include?(k)
|
430
418
|
|
431
419
|
if (where_col = (ks = k.split('.')).last)[-1] == '!'
|
432
420
|
where_col = where_col[0..-2]
|
@@ -454,8 +442,6 @@ module ActiveRecord
|
|
454
442
|
# ActiveRecord::StatementInvalid (TinyTds::Error: DBPROCESS is dead or not enabled)
|
455
443
|
# Relevant info here: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/402
|
456
444
|
columns.each do |col|
|
457
|
-
next if is_api && id_parts.exclude?(col.name) # Only keep the ID columns if this is an API request
|
458
|
-
|
459
445
|
col_alias = " AS #{col.name}_" if (col_name = col.name) == 'class'
|
460
446
|
selects << if is_mysql
|
461
447
|
"`#{tbl_no_schema}`.`#{col_name}`#{col_alias}"
|
@@ -505,6 +491,7 @@ module ActiveRecord
|
|
505
491
|
# binding.pry
|
506
492
|
next
|
507
493
|
end
|
494
|
+
|
508
495
|
key_klass = nil
|
509
496
|
key_tbl_name = nil
|
510
497
|
dest_pk = nil
|
@@ -984,7 +971,7 @@ Module.class_exec do
|
|
984
971
|
::Brick.is_oracle ? class_name.upcase : class_name,
|
985
972
|
(plural_class_name = class_name.pluralize)].find { |s| Brick.db_schemas&.include?(s) }&.camelize ||
|
986
973
|
(::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}::") && class_name) ||
|
987
|
-
(::Brick.config.table_name_prefixes
|
974
|
+
(::Brick.config.table_name_prefixes.values.include?(class_name) && class_name))
|
988
975
|
return self.const_get(schema_name) if self.const_defined?(schema_name)
|
989
976
|
|
990
977
|
# Build out a module for the schema if it's namespaced
|
@@ -1590,13 +1577,6 @@ class Object
|
|
1590
1577
|
|
1591
1578
|
ar_relation = ActiveRecord.version < Gem::Version.new('4') ? model.preload : model.all
|
1592
1579
|
|
1593
|
-
if (cc = params['_brick_api']&.split(','))
|
1594
|
-
is_api = true
|
1595
|
-
selects = cc
|
1596
|
-
counts = [] # No need for any extra HM count columns
|
1597
|
-
model._br_cust_cols.clear
|
1598
|
-
end
|
1599
|
-
|
1600
1580
|
@_brick_params = ar_relation.brick_select(params, (selects ||= []), order_by,
|
1601
1581
|
translations = {},
|
1602
1582
|
join_array = ::Brick::JoinArray.new)
|
@@ -1611,7 +1591,6 @@ class Object
|
|
1611
1591
|
"b_r_#{v.first}.c_t_ AS \"b_r_#{v.first}_ct\""
|
1612
1592
|
end
|
1613
1593
|
end
|
1614
|
-
|
1615
1594
|
ar_select = ar_relation.respond_to?(:_select!) ? ar_relation.dup._select!(*selects, *counts) : ar_relation.select(selects + counts)
|
1616
1595
|
instance_variable_set("@#{table_name.pluralize}".to_sym, ar_select)
|
1617
1596
|
if namespace && (idx = lookup_context.prefixes.index(table_name))
|
@@ -54,7 +54,7 @@ module Brick
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# When table names have specific prefixes, automatically place them in their own module with a table_name_prefix.
|
57
|
-
::Brick.table_name_prefixes = app.config.brick.fetch(:table_name_prefixes,
|
57
|
+
::Brick.table_name_prefixes = app.config.brick.fetch(:table_name_prefixes, {})
|
58
58
|
|
59
59
|
# Columns to treat as being metadata for purposes of identifying associative tables for has_many :through
|
60
60
|
::Brick.metadata_columns = app.config.brick.fetch(:metadata_columns, ['created_at', 'updated_at', 'deleted_at'])
|
@@ -424,14 +424,6 @@ h1, h3 {
|
|
424
424
|
cursor: pointer;
|
425
425
|
}
|
426
426
|
|
427
|
-
#apiToggle {
|
428
|
-
border: 2px solid purple;
|
429
|
-
}
|
430
|
-
|
431
|
-
#apiToggle, .apiColName {
|
432
|
-
cursor: pointer;
|
433
|
-
}
|
434
|
-
|
435
427
|
#dropper {
|
436
428
|
background-color: #eee;
|
437
429
|
}
|
@@ -1012,9 +1004,6 @@ erDiagram
|
|
1012
1004
|
<p style=\"color: green\"><%= notice %></p>#{"
|
1013
1005
|
#{schema_options}" if schema_options}
|
1014
1006
|
<select id=\"tbl\">#{table_options}</select>
|
1015
|
-
|
1016
|
-
<%= pick_api(#{model_name}).html_safe %>
|
1017
|
-
|
1018
1007
|
<table id=\"resourceName\"><tr>
|
1019
1008
|
<td><h1>#{model_name}</h1></td>
|
1020
1009
|
<td id=\"imgErd\" title=\"Show ERD\"></td>
|
@@ -1088,13 +1077,8 @@ erDiagram
|
|
1088
1077
|
end
|
1089
1078
|
|
1090
1079
|
# Write out the mega-grid
|
1091
|
-
|
1092
|
-
|
1093
|
-
cols, poly_cols, {}, [], {})
|
1094
|
-
else
|
1095
|
-
brick_grid(@#{table_name}, @_brick_bt_descrip, @_brick_sequence, @_brick_incl, @_brick_excl,
|
1096
|
-
cols, poly_cols, bts, #{hms_keys.inspect}, {#{hms_columns.join(', ')}})
|
1097
|
-
end %>
|
1080
|
+
brick_grid(@#{table_name}, @_brick_bt_descrip, @_brick_sequence, @_brick_incl, @_brick_excl,
|
1081
|
+
cols, poly_cols, bts, #{hms_keys.inspect}, {#{hms_columns.join(', ')}}) %>
|
1098
1082
|
|
1099
1083
|
#{"<hr><%= link_to \"New #{obj_name}\", new_#{path_obj_name}_path %>" unless @_brick_model.is_view?}
|
1100
1084
|
#{script}
|
@@ -137,51 +137,6 @@ module Brick::Rails::FormTags
|
|
137
137
|
out.html_safe
|
138
138
|
end # brick_grid
|
139
139
|
|
140
|
-
# Recursively render UL and LI to choose columns to include
|
141
|
-
def pick_api(model, is_last = nil, visited = [])
|
142
|
-
out = +''
|
143
|
-
if visited.empty?
|
144
|
-
out << '<span id="apiToggle">API buffet</span><div id="apiBuffet" style="display: none;">'
|
145
|
-
out << '<textarea id="apiCode" cols="100"></textarea>'
|
146
|
-
out << '<input type="button" id="apiRender" value="Render">'
|
147
|
-
end
|
148
|
-
out << "\n#{indent = ' ' * visited.length}<ul>"
|
149
|
-
model.column_names.each { |col_name| out << "\n#{indent} <li class=\"apiColName\" x-nm=\"#{visited.map { |v| "#{v.last}." }.join}#{col_name}\">#{col_name}</li>" }
|
150
|
-
unless is_last || visited.length == 2
|
151
|
-
model.reflect_on_all_associations.each_with_object({}) do |v, s|
|
152
|
-
next if v.macro == :has_many || v.polymorphic?
|
153
|
-
|
154
|
-
out << "\n#{indent} <li><b>#{v.name}</b>#{pick_api(v.klass, visited.map(&:first).include?(v.klass),
|
155
|
-
visited.dup << [v.klass, v.name]
|
156
|
-
)}"
|
157
|
-
out << "\n#{indent} </li>"
|
158
|
-
s[v.name] = nil
|
159
|
-
end
|
160
|
-
end
|
161
|
-
out << "\n#{indent}</ul>"
|
162
|
-
if visited.empty?
|
163
|
-
out << '</div><script>[... document.getElementsByClassName("apiColName")].forEach(function (li) {li.addEventListener("click", apiColClick);});'
|
164
|
-
out << "
|
165
|
-
var colList = [];
|
166
|
-
var apiBuffet = document.getElementById(\"apiBuffet\");
|
167
|
-
var apiCode = document.getElementById(\"apiCode\");
|
168
|
-
function apiColClick(evt) {
|
169
|
-
apiCode.innerHTML += this.getAttribute(\"x-nm\") + \",\\n\";
|
170
|
-
}
|
171
|
-
document.getElementById(\"apiToggle\").addEventListener(\"click\", function () {
|
172
|
-
apiBuffet.style.display = (apiBuffet.style.display === \"block\" ? \"none\" : \"block\");
|
173
|
-
});
|
174
|
-
// Cheap and cheerful way to render a list of columns just for the demo
|
175
|
-
document.getElementById(\"apiRender\").addEventListener(\"click\", function () {
|
176
|
-
var changecolList = apiCode.innerHTML.substring(0, apiCode.innerHTML.length - 2);
|
177
|
-
location.href = changeout(location.href, \"_brick_api\", changecolList);
|
178
|
-
});
|
179
|
-
</script>
|
180
|
-
"
|
181
|
-
end
|
182
|
-
out
|
183
|
-
end
|
184
|
-
|
185
140
|
def link_to_brick(*args, **kwargs)
|
186
141
|
return unless ::Brick.config.mode == :on
|
187
142
|
|
@@ -231,13 +186,14 @@ document.getElementById(\"apiRender\").addEventListener(\"click\", function () {
|
|
231
186
|
end
|
232
187
|
end
|
233
188
|
filter = "?#{filter_parts.join('&')}" if filter_parts.present?
|
189
|
+
app_routes = Rails.application.routes # In case we're operating in another engine, reference the application since Brick routes are placed there.
|
234
190
|
if (klass_or_obj&.is_a?(Class) && klass_or_obj < ActiveRecord::Base) ||
|
235
191
|
(klass_or_obj&.is_a?(ActiveRecord::Base) && klass_or_obj.new_record? && (klass_or_obj = klass_or_obj.class))
|
236
|
-
path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj) : "#{
|
192
|
+
path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index, action: :index)}#{filter}"
|
237
193
|
lt_args = [text || "Index for #{klass_or_obj.name.pluralize}", path]
|
238
194
|
else
|
239
195
|
# If there are multiple incoming parameters then last one is probably the actual ID, and first few might be some nested tree of stuff leading up to it
|
240
|
-
path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj) : "#{
|
196
|
+
path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj) : "#{app_routes.path_for(controller: klass_or_obj.class.base_class._brick_index, action: :show, id: klass_or_obj)}#{filter}"
|
241
197
|
lt_args = [text || "Show this #{klass_or_obj.class.name}", path]
|
242
198
|
end
|
243
199
|
link_to(*lt_args, **kwargs)
|
data/lib/brick/version_number.rb
CHANGED
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.100
|
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-12-
|
11
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|