brick 1.0.23 → 1.0.24

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: 24731ac9bd56261179224610406247cc4438c61e411aa3fe96205b2e97fc8cb8
4
- data.tar.gz: 785d12e36fcf788c05cff3a02ca2ec17fc418b0ea15b54cb6923c83c6f362d3b
3
+ metadata.gz: 96ba9e8b4ddc54e5feaaf8652c93e5d9e1ffe15345a8cad719674e051b296718
4
+ data.tar.gz: 3901467e7918ece559f55740759bd555bababe96c407488307fcb01298c14034
5
5
  SHA512:
6
- metadata.gz: '090a3c4d1b3cb4761799e05adf5caa0c83f60cf985f97ed6856beb05620014e9e7401689719209488092c6c4a7605e53781cdb71ad9e7ec204ccaddca0d92cca'
7
- data.tar.gz: 8d1f9512c948359e7d73cd7cc32302f226df7e3e744fab562e01e16170830be28d0e2e15bcd7b437f66ed79e366b0ff33b7f578e4c76ffde1dd62cdcec059069
6
+ metadata.gz: aa73995e69947be5ca83597a71751cfffb2433551d04fb00b760bc51c199bcd9890d7a05c0deb2f2c07c2c89205acf52b942d00ae78e1d7c0a26544acf70a4d0
7
+ data.tar.gz: 2328082844a0c993ada29c02eab22cf0d04efbcf3e4479c804e16f7d2a39a42d28debcd5592620fecd3bc9c404458fe3b5ff448f1f2c1b7f0d2e13557f5f9fa8
@@ -115,8 +115,8 @@ module ActiveRecord
115
115
  # If available, parse simple DSL attached to a model in order to provide a friendlier name.
116
116
  # Object property names can be referenced in square brackets like this:
117
117
  # { 'User' => '[profile.firstname] [profile.lastname]' }
118
- def brick_descrip
119
- self.class.brick_descrip(self)
118
+ def brick_descrip(data = nil, pk_alias = nil)
119
+ self.class.brick_descrip(self, data, pk_alias)
120
120
  end
121
121
 
122
122
  def self.brick_descrip(obj, data = nil, pk_alias = nil)
@@ -136,11 +136,7 @@ module ActiveRecord
136
136
  this_obj = obj
137
137
  bracket_name.split('.').each do |part|
138
138
  obj_name += ".#{part}"
139
- this_obj = if caches.key?(obj_name)
140
- caches[obj_name]
141
- else
142
- (caches[obj_name] = this_obj&.send(part.to_sym))
143
- end
139
+ this_obj = caches.fetch(obj_name) { caches[obj_name] = this_obj&.send(part.to_sym) }
144
140
  end
145
141
  this_obj&.to_s || ''
146
142
  end
@@ -160,7 +156,8 @@ module ActiveRecord
160
156
  end
161
157
  if is_brackets_have_content
162
158
  output
163
- elsif pk_alias
159
+ elsif (pk_alias ||= primary_key)
160
+ pk_alias = [pk_alias] unless pk_alias.is_a?(Array)
164
161
  id = []
165
162
  pk_alias.each do |pk_alias_part|
166
163
  if (pk_part = obj.send(pk_alias_part))
@@ -282,6 +279,23 @@ module ActiveRecord
282
279
  # , is_add_bts, is_add_hms
283
280
  )
284
281
  is_add_bts = is_add_hms = true
282
+ wheres = {}
283
+ has_hm = false
284
+ params.each do |k, v|
285
+ case (ks = k.split('.')).length
286
+ when 1
287
+ next unless klass._brick_get_fks.include?(k)
288
+ when 2
289
+ assoc_name = ks.first.to_sym
290
+ # Make sure it's a good association name and that the model has that column name
291
+ next unless (assoc = klass.reflect_on_association(assoc_name))&.klass&.columns&.map(&:name)&.include?(ks.last)
292
+
293
+ # There is some potential for duplicates when there is an HM-based where in play. De-duplicate if so.
294
+ has_hm ||= assoc.macro == :has_many
295
+ join_array[assoc_name] = nil # Store this relation name in our special collection for .joins()
296
+ end
297
+ wheres[k] = v.split(',')
298
+ end
285
299
 
286
300
  # %%% Skip the metadata columns
287
301
  if selects&.empty? # Default to all columns
@@ -274,96 +274,97 @@ function changeout(href, param, value) {
274
274
  template_link = "
275
275
  <%= link_to 'CSV', #{table_name}_path(format: :csv) %> &nbsp; <a href=\"#\" id=\"sheetsLink\">Sheets</a>
276
276
  <div id=\"dropper\" contenteditable=\"true\"></div>
277
- <input type=\"button\" id=\"btnImport\" value=\"Import\">"
278
- end
279
- "#{css}
280
- <p style=\"color: green\"><%= notice %></p>#{"
281
- <select id=\"schema\">#{schema_options}</select>" if ::Brick.db_schemas.length > 1}
282
- <select id=\"tbl\">#{table_options}</select>
283
- <h1>#{model_name.pluralize}</h1>#{template_link}
277
+ <input type=\"button\" id=\"btnImport\" value=\"Import\">
278
+
284
279
  <script>
285
- var dropperDiv = document.getElementById(\"dropper\");
286
- var btnImport = document.getElementById(\"btnImport\");
287
- var droppedTSV;
288
- if (dropperDiv) { // Other interesting events: blur keyup input
289
- dropperDiv.addEventListener(\"paste\", function (evt) {
290
- droppedTSV = evt.clipboardData.getData('text/plain');
291
- var html = evt.clipboardData.getData('text/html');
292
- var tbl = html.substring(html.indexOf(\"<tbody>\") + 7, html.lastIndexOf(\"</tbody>\"));
293
- console.log(tbl);
294
- btnImport.style.display = droppedTSV.length > 0 ? \"block\" : \"none\";
295
- });
296
- btnImport.addEventListener(\"click\", function () {
297
- fetch(changeout(<%= #{obj_name}_path(-1, format: :csv).inspect.html_safe %>, \"_brick_schema\", brickSchema), {
298
- method: 'PATCH',
299
- headers: { 'Content-Type': 'text/tab-separated-values' },
300
- body: droppedTSV
301
- }).then(function (tsvResponse) {
302
- btnImport.style.display = \"none\";
303
- console.log(\"toaster\", tsvResponse);
280
+ var dropperDiv = document.getElementById(\"dropper\");
281
+ var btnImport = document.getElementById(\"btnImport\");
282
+ var droppedTSV;
283
+ if (dropperDiv) { // Other interesting events: blur keyup input
284
+ dropperDiv.addEventListener(\"paste\", function (evt) {
285
+ droppedTSV = evt.clipboardData.getData('text/plain');
286
+ var html = evt.clipboardData.getData('text/html');
287
+ var tbl = html.substring(html.indexOf(\"<tbody>\") + 7, html.lastIndexOf(\"</tbody>\"));
288
+ console.log(tbl);
289
+ btnImport.style.display = droppedTSV.length > 0 ? \"block\" : \"none\";
304
290
  });
305
- });
306
- }
307
- var sheetUrl;
308
- var spreadsheetId;
309
- var sheetsLink = document.getElementById(\"sheetsLink\");
310
- function gapiLoaded() {
311
- // Have a click on the sheets link to bring up the sign-in window. (Must happen from some kind of user click.)
312
- sheetsLink.addEventListener(\"click\", async function (evt) {
313
- evt.preventDefault();
314
- await gapi.load(\"client\", function () {
315
- gapi.client.init({ // Load the discovery doc to initialize the API
316
- clientId: \"487319557829-fgj4u660igrpptdji7ev0r5hb6kh05dh.apps.googleusercontent.com\",
317
- scope: \"https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive.file\",
318
- discoveryDocs: [\"https://sheets.googleapis.com/$discovery/rest?version=v4\"]
319
- }).then(function () {
320
- gapi.auth2.getAuthInstance().isSignedIn.listen(updateSignInStatus);
321
- updateSignInStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
291
+ btnImport.addEventListener(\"click\", function () {
292
+ fetch(changeout(<%= #{obj_name}_path(-1, format: :csv).inspect.html_safe %>, \"_brick_schema\", brickSchema), {
293
+ method: 'PATCH',
294
+ headers: { 'Content-Type': 'text/tab-separated-values' },
295
+ body: droppedTSV
296
+ }).then(function (tsvResponse) {
297
+ btnImport.style.display = \"none\";
298
+ console.log(\"toaster\", tsvResponse);
322
299
  });
323
300
  });
324
- });
325
- }
301
+ }
302
+ var sheetUrl;
303
+ var spreadsheetId;
304
+ var sheetsLink = document.getElementById(\"sheetsLink\");
305
+ function gapiLoaded() {
306
+ // Have a click on the sheets link to bring up the sign-in window. (Must happen from some kind of user click.)
307
+ sheetsLink.addEventListener(\"click\", async function (evt) {
308
+ evt.preventDefault();
309
+ await gapi.load(\"client\", function () {
310
+ gapi.client.init({ // Load the discovery doc to initialize the API
311
+ clientId: \"487319557829-fgj4u660igrpptdji7ev0r5hb6kh05dh.apps.googleusercontent.com\",
312
+ scope: \"https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive.file\",
313
+ discoveryDocs: [\"https://sheets.googleapis.com/$discovery/rest?version=v4\"]
314
+ }).then(function () {
315
+ gapi.auth2.getAuthInstance().isSignedIn.listen(updateSignInStatus);
316
+ updateSignInStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
317
+ });
318
+ });
319
+ });
320
+ }
326
321
 
327
- async function updateSignInStatus(isSignedIn) {
328
- if (isSignedIn) {
329
- console.log(\"turds!\");
330
- await gapi.client.sheets.spreadsheets.create({
331
- properties: {
332
- title: #{table_name.inspect},
333
- },
334
- sheets: [
335
- // sheet1, sheet2, sheet3
336
- ]
337
- }).then(function (response) {
338
- sheetUrl = response.result.spreadsheetUrl;
339
- spreadsheetId = response.result.spreadsheetId;
340
- sheetsLink.setAttribute(\"href\", sheetUrl); // response.result.spreadsheetUrl
341
- console.log(\"x1\", sheetUrl);
342
-
343
- // Get JSON data
344
- fetch(changeout(<%= #{table_name}_path(format: :js).inspect.html_safe %>, \"_brick_schema\", brickSchema)).then(function (response) {
345
- response.json().then(function (data) {
346
- gapi.client.sheets.spreadsheets.values.append({
347
- spreadsheetId: spreadsheetId,
348
- range: \"Sheet1\",
349
- valueInputOption: \"RAW\",
350
- insertDataOption: \"INSERT_ROWS\"
351
- }, {
352
- range: \"Sheet1\",
353
- majorDimension: \"ROWS\",
354
- values: data,
355
- }).then(function (response2) {
356
- // console.log(\"beefcake\", response2);
322
+ async function updateSignInStatus(isSignedIn) {
323
+ if (isSignedIn) {
324
+ console.log(\"turds!\");
325
+ await gapi.client.sheets.spreadsheets.create({
326
+ properties: {
327
+ title: #{table_name.inspect},
328
+ },
329
+ sheets: [
330
+ // sheet1, sheet2, sheet3
331
+ ]
332
+ }).then(function (response) {
333
+ sheetUrl = response.result.spreadsheetUrl;
334
+ spreadsheetId = response.result.spreadsheetId;
335
+ sheetsLink.setAttribute(\"href\", sheetUrl); // response.result.spreadsheetUrl
336
+ console.log(\"x1\", sheetUrl);
337
+
338
+ // Get JSON data
339
+ fetch(changeout(<%= #{table_name}_path(format: :js).inspect.html_safe %>, \"_brick_schema\", brickSchema)).then(function (response) {
340
+ response.json().then(function (data) {
341
+ gapi.client.sheets.spreadsheets.values.append({
342
+ spreadsheetId: spreadsheetId,
343
+ range: \"Sheet1\",
344
+ valueInputOption: \"RAW\",
345
+ insertDataOption: \"INSERT_ROWS\"
346
+ }, {
347
+ range: \"Sheet1\",
348
+ majorDimension: \"ROWS\",
349
+ values: data,
350
+ }).then(function (response2) {
351
+ // console.log(\"beefcake\", response2);
352
+ });
357
353
  });
358
354
  });
359
355
  });
360
- });
361
- window.open(sheetUrl, '_blank');
356
+ window.open(sheetUrl, '_blank');
357
+ }
362
358
  }
363
- }
364
359
  </script>
365
360
  <script async defer src=\"https://apis.google.com/js/api.js\" onload=\"gapiLoaded()\"></script>
366
-
361
+ "
362
+ end
363
+ "#{css}
364
+ <p style=\"color: green\"><%= notice %></p>#{"
365
+ <select id=\"schema\">#{schema_options}</select>" if ::Brick.db_schemas.length > 1}
366
+ <select id=\"tbl\">#{table_options}</select>
367
+ <h1>#{model_name.pluralize}</h1>#{template_link}
367
368
 
368
369
  <% if @_brick_params&.present? %><h3>where <%= @_brick_params.each_with_object([]) { |v, s| s << \"#\{v.first\} = #\{v.last.inspect\}\" }.join(', ') %></h3><% end %>
369
370
  <table id=\"#{table_name}\">
@@ -400,8 +401,7 @@ async function updateSignInStatus(isSignedIn) {
400
401
  <% end %>
401
402
  </td>
402
403
  <% end %>
403
- <td>#{hms_columns.join('</td><td>')}</td>
404
- <!-- td>X</td -->
404
+ #{hms_columns.each_with_object(+'') { |hm_col, s| s << "<td>#{hm_col}</td>" }}
405
405
  </tr>
406
406
  </tbody>
407
407
  <% end %>
@@ -422,19 +422,21 @@ async function updateSignInStatus(isSignedIn) {
422
422
  # url = send(:#{model_name.underscore}_path, obj.#{pk})
423
423
  form_for(obj.becomes(#{model_name})) do |f| %>
424
424
  <table>
425
- <% @#{obj_name}.first.attributes.each do |k, val| %>
425
+ <% has_fields = false
426
+ @#{obj_name}.first.attributes.each do |k, val| %>
426
427
  <tr>
427
428
  <%# %%% Accommodate composite keys %>
428
429
  <% next if k == '#{pk}' || ::Brick.config.metadata_columns.include?(k) %>
429
430
  <th class=\"show-field\">
430
- <% if (bt = bts[k])
431
+ <% has_fields = true
432
+ if (bt = bts[k])
431
433
  # Add a final member in this array with descriptive options to be used in <select> drop-downs
432
434
  bt_name = bt[1].name
433
435
  # %%% Only do this if the user has permissions to edit this bt field
434
436
  if bt.length < 4
435
437
  bt << (option_detail = [[\"(No #\{bt_name\} chosen)\", '^^^brick_NULL^^^']])
436
438
  # %%% Accommodate composite keys for obj.pk at the end here
437
- bt[1].order(bt[1].primary_key).each { |obj| option_detail << [obj.brick_descrip, obj.send(bt[1].primary_key)] }
439
+ bt[1].order(obj_pk = bt[1].primary_key).each { |obj| option_detail << [obj.brick_descrip(nil, obj_pk), obj.send(obj_pk)] }
438
440
  end %>
439
441
  BT <%= bt[1].bt_link(bt.first) %>
440
442
  <% else %>
@@ -467,8 +469,12 @@ async function updateSignInStatus(isSignedIn) {
467
469
  <% end %>
468
470
  </td>
469
471
  </tr>
472
+ <% end
473
+ if has_fields %>
474
+ <tr><td colspan=\"2\" class=\"right\"><%= f.submit %></td></tr>
475
+ <% else %>
476
+ <tr><td colspan=\"2\">(No displayable fields)</td></tr>
470
477
  <% end %>
471
- <tr><td colspan=\"2\" class=\"right\"><%= f.submit %></td></tr>
472
478
  </table>
473
479
  <% end %>
474
480
 
@@ -482,6 +488,7 @@ async function updateSignInStatus(isSignedIn) {
482
488
  <tr><td>(none)</td></tr>
483
489
  <% else %>
484
490
  <% collection.uniq.each do |#{hm_singular_name = hm_name.singularize.underscore}| %>
491
+ <%# %%% accommodate composite primary key %>
485
492
  <tr><td><%= link_to(#{hm_singular_name}.brick_descrip, #{hm.first.klass.name.underscore}_path(#{hm_singular_name}.#{pk})) %></td></tr>
486
493
  <% end %>
487
494
  <% end %>
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 23
8
+ TINY = 24
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.23
4
+ version: 1.0.24
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-12 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord