common_core_js 0.3.8 → 0.3.9

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: 69b48d2b11f7087d3a842266d1c08df9da022bc7191dbc71f286431ac02112f0
4
- data.tar.gz: cdc77c41c2dff7e393837fb1954fc0bd599083c2ce305e98416c097866d6c4a8
3
+ metadata.gz: e52d23ca84e6aaeb8632f16b726dca47569602e8a30f67930a22aa1c92b85441
4
+ data.tar.gz: e203d956052682ec9e6a41049f001678ef1c6a1a4db90760e48e4f290ca7e2fe
5
5
  SHA512:
6
- metadata.gz: bceefae2fd396020f7225df73e9f74a4f6ea7d06b94250880c872e68c921b43ac1eb0b0f34805098fbab5ca877fe26d54dc152230d2990a9b58428ccf9f6e6ea
7
- data.tar.gz: d40870c3538adc2a9d687d583e7b3821544eff497425bf00f712d6426945477d7ac0bc191072ef5befbe0f38b9b0eb1b28b81298719d6eec38a427c458299509
6
+ metadata.gz: 770808dd3227c4dc7dc6c5cce6d4582f5105c59943839c5424dec7bb4d01f52ca7968a64b4615f96e968198d1f429106e0240c09909485bd9fd8b2f26d6702f0
7
+ data.tar.gz: 48dc5ad547294ab2ce9b41b5db7b2f3ea00738d27a4eb60d3c7e6abfc3c7ce0b93097d88aee4fbfecc2c7c33ff968d488ae32e5d05b307c5f63abed0cf8a3dec
@@ -1,3 +1,3 @@
1
1
  module CommonCoreJs
2
- VERSION = '0.3.8'
2
+ VERSION = '0.3.9'
3
3
  end
@@ -84,17 +84,6 @@ module CommonCore
84
84
  end
85
85
 
86
86
  auth_assoc = @auth.gsub("current_","")
87
- auth_assoc_field = auth_assoc + "_id"
88
-
89
- exclude_fields = [auth_assoc_field.to_sym, :id, :created_at, :updated_at, :encrypted_password, :reset_password_token,
90
- :reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at,
91
- :confirmation_sent_at, :unconfirmed_email]
92
- begin
93
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| exclude_fields.include?(field) }
94
- rescue StandardError => e
95
- puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
96
- exit
97
- end
98
87
 
99
88
  @no_delete = false
100
89
  @no_create = false
@@ -122,23 +111,56 @@ module CommonCore
122
111
  exit
123
112
  end
124
113
 
114
+
115
+ # only used for the before_action
125
116
  if @auth_identifier.nil? && !@auth.nil?
126
117
  @auth_identifier = @auth.gsub("current_", "")
127
118
  end
128
119
 
129
-
120
+ # when in self auth, the object is the same as the authenticated object
130
121
  if @auth && auth_identifier == @singular
131
122
  @self_auth = true
132
123
  end
133
124
 
134
125
  if !@nest.nil?
135
126
  @nested_args = @nest.split("/")
136
-
137
127
  @nested_args_plural = {}
138
128
  @nested_args.each do |a|
139
129
  @nested_args_plural[a] = a + "s"
140
130
  end
141
131
  end
132
+
133
+ # the @object_owner will always be object that will 'own' the object
134
+ # for new and create
135
+
136
+ if @auth && ! @self_auth && @nested_args.none?
137
+ @object_owner_sym = @auth.gsub("current_", "").to_sym
138
+ @object_owner_eval = @auth
139
+ else
140
+ @object_owner_sym = @nested_args.last.to_sym
141
+ @object_owner_eval = "@#{@nested_args.last}"
142
+ end
143
+
144
+
145
+
146
+ # create the columns
147
+ auth_assoc_field = auth_assoc + "_id"
148
+
149
+ ownership_field = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})").name.to_s + "_id"
150
+
151
+
152
+ exclude_fields = [auth_assoc_field.to_sym, ownership_field.to_sym, :id, :created_at, :updated_at, :encrypted_password, :reset_password_token,
153
+ :reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at,
154
+ :confirmation_sent_at, :unconfirmed_email]
155
+ begin
156
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| exclude_fields.include?(field) }
157
+ rescue StandardError => e
158
+ puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
159
+ exit
160
+ end
161
+
162
+
163
+
142
164
  end
143
165
 
144
166
  def formats
@@ -239,6 +261,14 @@ module CommonCore
239
261
  end
240
262
 
241
263
 
264
+ def path_helper_full
265
+ "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
266
+ end
267
+
268
+ def path_helper_args
269
+ [(@nested_args if @nested_args.any?).collect{|a| "@#{a}"} , singular].join(",")
270
+ end
271
+
242
272
  def path_helper_singular
243
273
  "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
244
274
  end
@@ -268,7 +298,7 @@ module CommonCore
268
298
  end
269
299
 
270
300
  def nested_arity_for_path
271
- @nested_args.join(", ") #metaprgramming into arity for the Rails path helper
301
+ [@nested_args[0..-1].collect{|a| "@#{a}"}].join(", ") #metaprgramming into arity for the Rails path helper
272
302
  end
273
303
 
274
304
  def object_scope
@@ -366,15 +396,6 @@ module CommonCore
366
396
  :erb
367
397
  end
368
398
 
369
-
370
- def create_merge_params
371
- if @auth && ! @self_auth
372
- "#{@auth_identifier}: #{@auth}"
373
- else
374
- ""
375
- end
376
- end
377
-
378
399
  def model_has_strings?
379
400
  false
380
401
  end
@@ -405,6 +426,7 @@ module CommonCore
405
426
  puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
406
427
  exit
407
428
  end
429
+ assoc_class_name = eval("#{singular_class}.reflect_on_association(:#{assoc_name})").class_name
408
430
 
409
431
  if assoc.active_record.column_names.include?("name")
410
432
  display_column = "name"
@@ -420,9 +442,10 @@ module CommonCore
420
442
  puts "Can't find a display_column on {singular_class} object"
421
443
  end
422
444
 
445
+
423
446
  ".row
424
447
  %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
425
- = f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
448
+ = f.collection_select(:#{col.to_s}, #{assoc_class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
426
449
  %label.small.form-text.text-muted
427
450
  #{col.to_s.humanize}"
428
451
 
@@ -1,7 +1,7 @@
1
1
  <%= all_line_fields %>
2
2
  %td
3
3
  <% if destroy_action %>
4
- = link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_singular %>(<%= singular %>), remote: true, method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
4
+ = link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_full %>(<%= path_helper_args %>), remote: true, method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
5
5
  <% end %>
6
6
  &nbsp;
7
- = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_singular %>(<%= singular %>), remote: true , disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
7
+ = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>), remote: true , disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
@@ -1,5 +1,5 @@
1
1
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
- <% unless @auth_identifier.nil? %>
2
+ <% unless @auth_identifier == '' %>
3
3
  before_action :authenticate_<%= auth_identifier %>!
4
4
 
5
5
  <% end %>
@@ -43,14 +43,14 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
43
43
  end
44
44
 
45
45
  <% if create_action %> def new
46
- @<%= singular_name %> = <%= class_name %>.new(<%= create_merge_params %>)
46
+ @<%= singular_name %> = <%= class_name %>.new(<%= @object_owner_sym %>: <%= @object_owner_eval %>)
47
47
  respond_to do |format|
48
48
  format.js
49
49
  end
50
50
  end
51
51
 
52
52
  def create
53
- modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !create_merge_params.empty? %>.merge!(<%= create_merge_params %>)<% end %> <%= @auth ? ",#{@auth}" : "" %>)
53
+ modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !@object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %>, <%= @auth %>)
54
54
  @<%=singular_name %> = <%=class_name %>.create(modified_params)
55
55
  respond_to do |format|
56
56
  if @<%= singular_name %>.save
@@ -75,7 +75,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
75
75
 
76
76
  def update
77
77
  respond_to do |format|
78
- if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%= @auth ? @auth : "nil" %> ))
78
+ if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%= @auth %> ))
79
79
  flash[:alert] = "<%=singular_name.titlecase %> could not be saved"
80
80
  end
81
81
  format.js {}
@@ -1 +1 @@
1
- <%%= render partial: 'common/common_create', locals: {object: @<%= singular %>, singular: "<%= singular %>", plural: "<%= plural %>"} %>
1
+ <%%= render partial: 'common/common_create', locals: {object: @<%= singular %>, singular: "<%= singular %>", plural: "<%= plural %>"<%= ", " + nested_assignments if nested_assignments %>} %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: common_core_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt