brick 1.0.17 → 1.0.18

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: 7f1a45a5262526e69cf49f16773049eb348e3971bddf09ecf05927002a265019
4
- data.tar.gz: e9566a423a19ab55d44522b44e8b4abfcc39e92335b6093fe782c6344644bbbe
3
+ metadata.gz: add7e232024e140e2fb089ef158600e2a2a955efd787dc986769b43b4b1f6d24
4
+ data.tar.gz: a45d187a7b739f90b1fede46dfc9f63a2057a3410d052e0ad57322f4741ebfee
5
5
  SHA512:
6
- metadata.gz: cb89dff96dccc7051bc854fe523b03f818255d81e4f2e2a65eb9808115e719b8bad98e38114f15ee79b32b1f035c95c364a74392948cd2e99f4030e6988e0217
7
- data.tar.gz: cd5507fde2f1f23481696ab051d14f89e5e7e7d3fc2be97af947ff287313b7ada8ca7b4e3f9e0e54dc2ab7f14e7f39a3c18f78cf7fc995c58b3d60cf68487973
6
+ metadata.gz: '0897e041c617f0e1e695d0402784184ce2f7ec575d9b0e7a7b1b59b2efbcb40a4de28bcbe2eb124f576dddb8e7371f572c67ee3b19120cd281bf3358249b4508'
7
+ data.tar.gz: fc7a4a93a7d2409f4aa82fb3dbf23710aaad45a1dca1193c8cbcefa86d5d9061a773214c8fe0dd02375660bfb6e5a9856df3a202f57a73990e79d23850918f9b
data/lib/brick/config.rb CHANGED
@@ -108,7 +108,7 @@ module Brick
108
108
  end
109
109
 
110
110
  def exclude_tables
111
- @mutex.synchronize { @exclude_tables }
111
+ @mutex.synchronize { @exclude_tables || [] }
112
112
  end
113
113
 
114
114
  def exclude_tables=(value)
@@ -454,7 +454,7 @@ class Object
454
454
 
455
455
  if model.primary_key
456
456
  code << " def show\n"
457
- code << " @#{singular_table_name} = #{model.name}.find(params[:id].split(','))\n"
457
+ code << (find_by_id = " @#{singular_table_name} = #{model.name}.find(params[:id].split(','))\n")
458
458
  code << " end\n"
459
459
  self.define_method :show do
460
460
  ::Brick.set_db_schema(params)
@@ -463,9 +463,36 @@ class Object
463
463
  end
464
464
 
465
465
  # By default, views get marked as read-only
466
- unless (relation = relations[model.table_name]).key?(:isView)
467
- code << " # (Define :new, :create, :edit, :update, and :destroy)\n"
468
- # Get column names for params from relations[model.table_name][:cols].keys
466
+ unless false # model.readonly # (relation = relations[model.table_name]).key?(:isView)
467
+ code << " # (Define :new, :create)\n"
468
+
469
+ if model.primary_key
470
+ is_need_params = true
471
+ # code << " # (Define :edit, and :destroy)\n"
472
+ code << " def update\n"
473
+ code << find_by_id
474
+ params_name = "#{singular_table_name}_params"
475
+ code << " @#{singular_table_name}.update(#{params_name})\n"
476
+ code << " end\n"
477
+ self.define_method :update do
478
+ ::Brick.set_db_schema(params)
479
+ instance_variable_set("@#{singular_table_name}".to_sym, (obj = model.find(params[:id].split(','))))
480
+ obj = obj.first if obj.is_a?(Array)
481
+ obj.send(:update, send(params_name = params_name.to_sym))
482
+ end
483
+ end
484
+
485
+ if is_need_params
486
+ code << "private\n"
487
+ code << " def params\n"
488
+ code << " params.require(:#{singular_table_name}).permit(#{model.columns_hash.keys.map { |c| c.to_sym.inspect }.join(', ')})\n"
489
+ code << " end\n"
490
+ self.define_method(params_name) do
491
+ params.require(singular_table_name.to_sym).permit(model.columns_hash.keys)
492
+ end
493
+ private params_name
494
+ # Get column names for params from relations[model.table_name][:cols].keys
495
+ end
469
496
  end
470
497
  code << "end # #{class_name}\n\n"
471
498
  end # class definition
@@ -629,14 +656,12 @@ module ActiveRecord::ConnectionHandling
629
656
  puts "\nClasses that can be built from views:"
630
657
  views.keys.each { |k| puts ActiveSupport::Inflector.singularize(k).camelize }
631
658
  end
659
+
632
660
  # Try to load the initializer pretty danged early
633
661
  if File.exist?(brick_initialiser = Rails.root.join('config/initializers/brick.rb'))
634
662
  load brick_initialiser
635
663
  ::Brick.load_additional_references
636
664
  end
637
-
638
- # relations.keys.each { |k| ActiveSupport::Inflector.singularize(k).camelize.constantize }
639
- # Layout table describes permissioned hierarchy throughout
640
665
  end
641
666
  end
642
667
 
@@ -89,7 +89,8 @@ module Brick
89
89
  end
90
90
 
91
91
  schema_options = ::Brick.db_schemas.each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }.html_safe
92
- table_options = ::Brick.relations.keys.each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }.html_safe
92
+ table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables)
93
+ .each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }.html_safe
93
94
  hms_columns = +'' # Used for 'index'
94
95
  hms_headers = hms.each_with_object([]) do |hm, s|
95
96
  next if exclude_hms.key?((hm_assoc = hm.last).name)
@@ -163,6 +164,23 @@ a.big-arrow {
163
164
  font-size: 2.5em;
164
165
  text-decoration: none;
165
166
  }
167
+ .wide-input {
168
+ display: block;
169
+ overflow: hidden;
170
+ }
171
+ .wide-input input[type=text] {
172
+ width: 100%;
173
+ }
174
+ .dimmed {
175
+ background-color: #C0C0C0;
176
+ }
177
+ input[type=submit] {
178
+ background-color: #004998;
179
+ color: #FFF;
180
+ }
181
+ .right {
182
+ text-align: right;
183
+ }
166
184
  </style>
167
185
  <% def is_bcrypt?(val)
168
186
  val.is_a?(String) && val.length == 60 && val.start_with?('$2a$')
@@ -173,8 +191,9 @@ end %>"
173
191
 
174
192
  script = "<script>
175
193
  var schemaSelect = document.getElementById(\"schema\");
194
+ var brickSchema;
176
195
  if (schemaSelect) {
177
- var brickSchema = changeout(location.href, \"_brick_schema\");
196
+ brickSchema = changeout(location.href, \"_brick_schema\");
178
197
  if (brickSchema) {
179
198
  [... document.getElementsByTagName(\"A\")].forEach(function (a) { a.href = changeout(a.href, \"_brick_schema\", brickSchema); });
180
199
  }
@@ -184,6 +203,17 @@ if (schemaSelect) {
184
203
  location.href = changeout(location.href, \"_brick_schema\", this.value);
185
204
  });
186
205
  }
206
+ [... document.getElementsByTagName(\"FORM\")].forEach(function (form) {
207
+ if (brickSchema)
208
+ form.action = changeout(form.action, \"_brick_schema\", brickSchema);
209
+ form.addEventListener('submit', function (ev) {
210
+ [... ev.target.getElementsByTagName(\"SELECT\")].forEach(function (select) {
211
+ if (select.value === \"^^^brick_NULL^^^\")
212
+ select.value = null;
213
+ });
214
+ return true;
215
+ });
216
+ });
187
217
 
188
218
  var tblSelect = document.getElementById(\"tbl\");
189
219
  if (tblSelect) {
@@ -265,14 +295,18 @@ function changeout(href, param, value) {
265
295
 
266
296
  #{"<hr><%= link_to \"New #{obj_name}\", new_#{obj_name}_path %>" unless @_brick_model.is_view?}
267
297
  #{script}"
268
- when 'show'
269
- "#{css}
270
- <p style=\"color: green\"><%= notice %></p>#{"
271
- <select id=\"schema\">#{schema_options}</select>" if ::Brick.db_schemas.length > 1}
272
- <select id=\"tbl\">#{table_options}</select>
273
- <h1>#{model_name}: <%= (obj = @#{obj_name}.first).brick_descrip %></h1>
274
- <%= link_to '(See all #{obj_name.pluralize})', #{table_name}_path %>
275
- <%= form_for obj do |f| %>
298
+ when 'show', 'update'
299
+ "#{css}
300
+ <p style=\"color: green\"><%= notice %></p>#{"
301
+ <select id=\"schema\">#{schema_options}</select>" if ::Brick.db_schemas.length > 1}
302
+ <select id=\"tbl\">#{table_options}</select>
303
+ <h1>#{model_name}: <%= (obj = @#{obj_name}&.first)&.brick_descrip || controller_name %></h1>
304
+ <%= link_to '(See all #{obj_name.pluralize})', #{table_name}_path %>
305
+ <% if obj %>
306
+ <%= # path_options = [obj.#{pk}]
307
+ # path_options << { '_brick_schema': } if
308
+ # url = send(:#{model_name.underscore}_path, obj.#{pk})
309
+ form_for(obj) do |f| %>
276
310
  <table>
277
311
  <% bts = { #{bts.each_with_object([]) { |v, s| s << "#{v.first.inspect} => [#{v.last.first.inspect}, #{v.last[1].name}, #{v.last[1].primary_key.inspect}]"}.join(', ')} }
278
312
  @#{obj_name}.first.attributes.each do |k, val| %>
@@ -281,25 +315,40 @@ function changeout(href, param, value) {
281
315
  <th class=\"show-field\">
282
316
  <% if (bt = bts[k])
283
317
  # Add a final member in this array with descriptive options to be used in <select> drop-downs
318
+ bt_name = bt[1].name
284
319
  # %%% Only do this if the user has permissions to edit this bt field
285
- bt << bt[1].order(:#{pk}).map { |obj| [obj.brick_descrip, obj.#{pk}] } if bt.length < 4 %>
286
- BT <%= \"#\{bt.first\}-\" unless bt[1].name.underscore == bt.first.to_s %><%= bt[1].name %>
320
+ if bt.length < 4
321
+ bt << (option_detail = [[\"(No #\{bt_name\} chosen)\", '^^^brick_NULL^^^']])
322
+ bt[1].order(:#{pk}).each { |obj| option_detail << [obj.brick_descrip, obj.#{pk}] }
323
+ end %>
324
+ BT <%= \"#\{bt.first\}-\" unless bt_name.underscore == bt.first.to_s %><%= bt_name %>
287
325
  <% else %>
288
326
  <%= k %>
289
327
  <% end %>
290
328
  </th>
291
329
  <td>
292
- <% if (bt = bts[k]) # bt_obj.brick_descrip %>
293
- <%= f.select k.to_sym, bt[3], {}, prompt: 'Select #{model_name}' %>
294
- <%= bt_obj = bt[1].find_by(bt[2] => val); link_to('⇛', send(\"#\{bt_obj_class = bt[1].name.underscore\}_path\".to_sym, bt_obj.send(bt[1].primary_key.to_sym)), { class: 'show-arrow' }) if bt_obj %>
295
- <% elsif is_bcrypt?(val) %>
296
- <%= hide_bcrypt(val) %>
297
- <% else %>
298
- <%= f.text_field k.to_sym %>
330
+ <% if (bt = bts[k]) # bt_obj.brick_descrip
331
+ html_options = { prompt: \"Select #\{bt_name\}\" }
332
+ html_options[:class] = 'dimmed' unless val %>
333
+ <%= f.select k.to_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options %>
334
+ <%= bt_obj = bt[1].find_by(bt[2] => val); link_to('⇛', send(\"#\{bt_obj_class = bt_name.underscore\}_path\".to_sym, bt_obj.send(bt[1].primary_key.to_sym)), { class: 'show-arrow' }) if bt_obj %>
335
+ <% else case #{model_name}.column_for_attribute(k).type
336
+ when :string, :text %>
337
+ <% if is_bcrypt?(val) # || .readonly? %>
338
+ <%= hide_bcrypt(val) %>
339
+ <% else %>
340
+ <div class=\"wide-input\"><%= f.text_field k.to_sym %></div>
341
+ <% end %>
342
+ <% when :boolean %>
343
+ <%= f.check_box k.to_sym %>
344
+ <% when :integer, :date, :datetime, :decimal %>
345
+ <%= val %>
346
+ <% end %>
299
347
  <% end %>
300
348
  </td>
301
349
  </tr>
302
- <% end %>
350
+ <% end %>
351
+ <tr><td colspan=\"2\" class=\"right\"><%= f.submit %></td></tr>
303
352
  </table>
304
353
  <% end %>
305
354
 
@@ -317,6 +366,7 @@ function changeout(href, param, value) {
317
366
  <% end %>
318
367
  <% end %>
319
368
  </table>" end.join}
369
+ <% end %>
320
370
  #{script}"
321
371
 
322
372
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 17
8
+ TINY = 18
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.17
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits