common_core_js 0.3.2 → 0.3.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3c68ef2ddc0f4e98ca5b54d0c646a918b2f70d091fe89db9951a61879af34d2
4
- data.tar.gz: 5ea645a245a197d42dabf6f697a7f94e5227d6c8416da47d8dfe875fdc28cbea
3
+ metadata.gz: 5bd570ce32ada5b0551a77526d1b25e82f9b10a4ce9199e9abc60c3256a0c824
4
+ data.tar.gz: 39d7097d4e3daa434959ec9c72d93f83bee971d715f7ccde0fcb791332b8f490
5
5
  SHA512:
6
- metadata.gz: 7490de5c8f29a6a80960c50ecbb37a02122cafcc96b345c200f1cdc4cb3cf5f50f15e2fb4609f6f4a920b814c9fb123b9024a8d226a1e0f225bebe5246fe9cbb
7
- data.tar.gz: fccfc40f5851a9a0bffdc5410085073afa8798320b4abf7a770c1dd7e3070ff871e341ba613f67b7afed11ea2a69c9c685dd130b41bc301ca89386490c5dd77a
6
+ metadata.gz: 344db104a6bcca04942313947217d71f786698f6656590b5f49f03974046a557e8de438c3ba9146c1f2041996926341942f84ef3ff2b947883386e6c7ab2e9c0
7
+ data.tar.gz: 5c51d14d8d1055b3652ce5e2351582951a60b0d5cb78b1b91153cbf60aab5e141579f177c4de169dd5de3d9cc059c4795c6b45d3024c9d720dcd361ae37814b9
data/.gitignore CHANGED
@@ -11,4 +11,6 @@ test/dummy/tmp/
11
11
 
12
12
  .idea/
13
13
  *.gem
14
- .DS_Store
14
+ .DS_Store
15
+
16
+ dump.rdb
@@ -0,0 +1,79 @@
1
+ module CommonCoreHelper
2
+
3
+ def timezonize(tz)
4
+ tz = tz.to_i
5
+ (tz >= 0 ? "+" : "-") + sprintf('%02d',tz.abs) + ":00"
6
+ end
7
+
8
+
9
+ def datetime_field_localized(form_object, field_name, value, label, timezone = nil )
10
+
11
+ res = form_object.label(label,
12
+ field_name,
13
+ class: 'small form-text text-muted')
14
+
15
+ res << form_object.text_field(field_name, class: 'form-control',
16
+ type: 'datetime-local',
17
+ value: date_to_current_timezone(value, timezone))
18
+
19
+ res << timezonize(timezone)
20
+ res
21
+ end
22
+
23
+
24
+ def date_field_localized(form_object, field_name, value, label, timezone = nil )
25
+ res = form_object.label(label,
26
+ field_name,
27
+ class: 'small form-text text-muted')
28
+
29
+ res << form_object.text_field(field_name, class: 'form-control',
30
+ type: 'date',
31
+ value: value )
32
+
33
+ res
34
+ end
35
+
36
+ def time_field_localized(form_object, field_name, value, label, timezone = nil )
37
+ res = form_object.label(label,
38
+ field_name,
39
+ class: 'small form-text text-muted')
40
+
41
+ res << form_object.text_field(field_name, class: 'form-control',
42
+ type: 'time',
43
+ value: date_to_current_timezone(value, timezone))
44
+
45
+ res << timezonize(tz)
46
+ res
47
+ end
48
+
49
+ def current_timezone
50
+ if controller.try(:current_timezone)
51
+ controller.current_timezone
52
+ elsif defined?(current_user)
53
+ if current_user.try(:timezone)
54
+ Time.now.in_time_zone(current_user.timezone).strftime("%z").to_i/100
55
+ else
56
+ Time.now.strftime("%z").to_i/100
57
+ end
58
+ else
59
+ raise "no method current_user is available or it does not implement timezone; please implement/override the method current_timezone IN YOUR CONTROLLER"
60
+ end
61
+ end
62
+
63
+
64
+ def date_to_current_timezone(date, timezone = nil)
65
+
66
+ # if the timezone is nil, use the server date'
67
+ if timezone.nil?
68
+ timezone = Time.now.strftime("%z").to_i/100
69
+ end
70
+
71
+ return nil if date.nil?
72
+
73
+ begin
74
+ return date.in_time_zone(timezone).strftime("%Y-%m-%dT%H:%M")
75
+ rescue
76
+ return nil
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ module CommonCoreJs
2
+ module ControllerHelper
3
+ def modify_date_inputs_on_params(modified_params)
4
+ use_timezone = current_account.timezone || Time.now.strftime("%z")
5
+
6
+ modified_params = modified_params.tap do |params|
7
+ params.keys.each{|k|
8
+ if k.ends_with?("_at") || k.ends_with?("_date")
9
+
10
+ begin
11
+ params[k] = DateTime.strptime("#{params[k]} #{use_timezone}", '%Y-%m-%dT%H:%M %z')
12
+ rescue StandardError
13
+
14
+ end
15
+ end
16
+ }
17
+ end
18
+ modified_params
19
+ end
20
+ end
21
+ end
@@ -8,7 +8,7 @@
8
8
 
9
9
  <% if object.errors.any? %>
10
10
  $(".flash-notices").html("<%= j render 'layouts/flash_notices' %>");
11
- $("<%= (scope + " ") if controller.common_scope %> .new-<%=singular%>-form").html("<%= j render(partial: '#{controller.namespace}errors', locals: {resource: object}) %>")
11
+ $("<%= (scope + " ") if controller.common_scope %> .new-<%=singular%>-form").html('<%= j render(partial: "#{controller.namespace}errors", locals: {resource: object}) %>')
12
12
  $("<%= (scope + " ") if controller.common_scope %> .new-<%=singular%>-form").append("<%= j render(partial: "new", locals: { singular.to_sym => object}) %><i class='fa fa-times-circle fa-2x' data-name='<%=singular%>' data-role='close-button' />").slideDown();
13
13
  <% else %>
14
14
  $("<%= (scope + " ") if controller.common_scope %> .new-<%=singular%>-form").slideUp();
@@ -1,4 +1,8 @@
1
1
  %td{style: "position: relative;", colspan: controller.default_colspan}
2
+ - if object.errors.any?
3
+ = render(partial: "#{controller.namespace}errors", locals: {resource: object})
4
+
5
+
2
6
  Editing
3
7
  - if object.try(:to_label)
4
8
  = object.to_label
@@ -1,6 +1,7 @@
1
1
  <% if object.errors.any? %>
2
2
  <% pass_through_locals ||= {} %>
3
- $(".<%= singular %>-table tr[data-id=<%= object.id %>][data-edit='true']").html("<%= j render(partial: '#{controller.namespace}errors', locals: {resource: object}) %><%= j render partial: 'edit', locals: {singular.to_sym => object, url: url, colspan: controller.default_colspan}.merge(pass_through_locals || {}) %>")
3
+ $(".<%= singular %>-table tr[data-id=<%= object.id %>][data-edit='true']").html("<%= j render partial: 'edit', locals: {singular.to_sym => object, url: url, colspan: controller.default_colspan}.merge(pass_through_locals || {}) %>")
4
+
4
5
  $(".flash-notices").html("<%= j render 'layouts/flash_notices' %>");
5
6
  <% else %>
6
7
  $(".<%= singular %>-table tr[data-id=<%= object.id %>]:not([data-edit='true'])").replaceWith("<%= j render partial: 'line', locals: {singular.to_sym => object } %>").fadeIn()
@@ -6,4 +6,24 @@ require 'haml-rails'
6
6
 
7
7
  module CommonCoreJs
8
8
  # Your code goes here...
9
+ #
10
+ module ControllerHelpers
11
+ def modify_date_inputs_on_params(modified_params, authenticated_user = nil)
12
+ use_timezone = authenticated_user.timezone || Time.now.strftime("%z")
13
+
14
+ modified_params = modified_params.tap do |params|
15
+ params.keys.each{|k|
16
+ if k.ends_with?("_at") || k.ends_with?("_date")
17
+
18
+ begin
19
+ params[k] = DateTime.strptime("#{params[k]} #{use_timezone}", '%Y-%m-%dT%H:%M %z')
20
+ rescue StandardError
21
+
22
+ end
23
+ end
24
+ }
25
+ end
26
+ modified_params
27
+ end
28
+ end
9
29
  end
@@ -1,5 +1,7 @@
1
1
  module CommonCoreJs
2
2
  class Engine < ::Rails::Engine
3
3
  # isolate_namespace CommonCoreJs
4
+
5
+
4
6
  end
5
7
  end
@@ -1,3 +1,3 @@
1
1
  module CommonCoreJs
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.7'
3
3
  end
@@ -10,12 +10,11 @@ module CommonCore
10
10
 
11
11
  def initialize(*args) #:nodoc:
12
12
  super
13
-
14
- copy_file "common_core.js", "vendor/assets/javascripts/common_core.js"
15
- copy_file "common_core.scss", "vendor/assets/stylesheets/common_core.scss"
13
+ copy_file "common_core.js", "app/javascript/common_core.js"
14
+ copy_file "common_core.scss", "app/assets/stylesheets/common_core.scss"
15
+ copy_file "_flash_notices.haml", "app/views/layouts/_flash_notices.haml"
16
16
 
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
 
@@ -13,7 +13,7 @@ module CommonCore
13
13
  end
14
14
 
15
15
  ".row
16
- .form-group.col-md-4
16
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
17
17
  = f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}'
18
18
  %label.form-text
19
19
  #{col.to_s.humanize}\n"
@@ -23,7 +23,7 @@ module CommonCore
23
23
 
24
24
  def field_output(col, type = nil, width)
25
25
  ".row
26
- .form-group.col-md-4
26
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
27
27
  = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}'
28
28
  %label.form-text
29
29
  #{col.to_s.humanize}\n"
@@ -83,13 +83,17 @@ module CommonCore
83
83
  end
84
84
  end
85
85
 
86
+
87
+
86
88
  auth_assoc = @auth.gsub("current_","")
87
89
  auth_assoc_field = auth_assoc + "_id"
88
90
 
89
91
 
92
+
93
+ exclude_fields = [auth_assoc_field.to_sym, :id, :created_at, :updated_at, :encrypted_password, :reset_password_token,
94
+ :reset_password_sent_at, :remember_created_at]
90
95
  begin
91
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| field==:updated_at ||
92
- field==:created_at || field==:id || field == auth_assoc_field.to_sym }
96
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| exclude_fields.include?(field) }
93
97
  rescue StandardError => e
94
98
  puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
95
99
  exit
@@ -118,6 +122,11 @@ module CommonCore
118
122
  @auth_identifier = @auth.gsub("current_", "")
119
123
  end
120
124
 
125
+
126
+ if auth_identifier == @singular
127
+ @self_auth = true
128
+ end
129
+
121
130
  if !@nest.nil?
122
131
  @nested_args = @nest.split("/")
123
132
 
@@ -141,11 +150,16 @@ module CommonCore
141
150
 
142
151
  unless @specs_only
143
152
  template "controller.rb", File.join("app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
153
+ if @namespace
154
+ template "base_controller.rb", File.join("app/controllers#{namespace_with_dash}", "base_controller.rb")
155
+ end
144
156
  end
145
157
 
146
158
  unless @no_specs
147
159
  template "controller_spec.rb", File.join("spec/controllers#{namespace_with_dash}", "#{plural}_controller_spec.rb")
148
160
  end
161
+
162
+ template "_errors.haml", File.join("app/views#{namespace_with_dash}", "_errors.haml")
149
163
  end
150
164
 
151
165
  def list_column_headings
@@ -268,7 +282,9 @@ module CommonCore
268
282
 
269
283
  def all_objects_root
270
284
  if @auth
271
- if @nested_args.none?
285
+ if @self_auth
286
+ @singular_class + ".where(id: #{@auth}.id)"
287
+ elsif @nested_args.none?
272
288
  @auth + ".#{plural}"
273
289
  else
274
290
  "@" + @nested_args.last + ".#{plural}"
@@ -344,7 +360,7 @@ module CommonCore
344
360
 
345
361
 
346
362
  def create_merge_params
347
- if @auth
363
+ if @auth && ! @self_auth
348
364
  "#{@auth_identifier}: #{@auth}"
349
365
  else
350
366
  ""
@@ -392,45 +408,55 @@ module CommonCore
392
408
  display_column = "display_name"
393
409
  elsif assoc.active_record.column_names.include?("email")
394
410
  display_column = "email"
411
+ else
412
+ puts "Can't find a display_column on {singular_class} object"
395
413
  end
396
414
 
397
415
  ".row
398
- .form-group.col-md-4
399
- = f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} , class: 'form-control')
416
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
417
+ = f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
400
418
  %label.small.form-text.text-muted
401
419
  #{col.to_s.humanize}"
402
420
 
403
421
  else
404
422
  ".row
405
- .form-group.col-md-4
423
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
406
424
  = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number'
407
425
  %label.form-text
408
426
  #{col.to_s.humanize}\n"
409
427
  end
410
428
  when :string
411
- limit ||= 40
412
- if limit < 50
429
+ limit ||= 256
430
+ if limit <= 256
413
431
  field_output(col, nil, limit)
414
432
  else
415
433
  text_area_output(col, limit)
416
434
  end
417
435
 
418
436
  when :text
419
- limit ||= 40
420
- if limit < 50
437
+ limit ||= 256
438
+ if limit <= 256
421
439
  field_output(col, nil, limit)
422
440
  else
423
441
  text_area_output(col, limit)
424
442
  end
425
443
 
426
444
  when :datetime
427
- ".row
428
- .form-group.col-md-4
429
- = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, class: 'form-control', type: 'datetime-local'
430
- %label.form-text
431
- #{col.to_s.humanize}\n"
432
- end
433
- }.join("\n")
445
+ ".row
446
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
447
+ = datetime_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
448
+ when :date
449
+ ".row
450
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
451
+ = date_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
452
+ when :time
453
+ ".row
454
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
455
+ = time_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
456
+
457
+ end
458
+
459
+ }.join("\n")
434
460
  return res
435
461
  end
436
462
 
@@ -458,8 +484,22 @@ module CommonCore
458
484
  exit
459
485
  end
460
486
 
487
+ if assoc.active_record.column_names.include?("name")
488
+ display_column = "name"
489
+ elsif assoc.active_record.column_names.include?("to_label")
490
+ display_column = "to_label"
491
+ elsif assoc.active_record.column_names.include?("full_name")
492
+ display_column = "full_name"
493
+ elsif assoc.active_record.column_names.include?("display_name")
494
+ display_column = "display_name"
495
+ elsif assoc.active_record.column_names.include?("email")
496
+ display_column = "email"
497
+ else
498
+ puts "cant find any column to use as label for #{assoc.name.to_s}; any of name, to_labe, full_name, display_name, or email"
499
+ end
500
+
461
501
  " %td
462
- = #{singular}.#{assoc.name.to_s}.to_label"
502
+ = #{singular}.#{assoc.name.to_s}.#{display_column}"
463
503
 
464
504
  else
465
505
  " %td
@@ -474,13 +514,54 @@ module CommonCore
474
514
  = #{singular}.#{col}"
475
515
  when :datetime
476
516
  " %td
477
- = #{singular}.#{col}"
517
+ - unless #{singular}.#{col}.nil?
518
+ = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone)
519
+ - else
520
+ %span.alert-danger
521
+ MISSING
522
+ "
523
+ when :date
524
+ " %td
525
+ - unless #{singular}.#{col}.nil?
526
+ = #{singular}.#{col}
527
+ - else
528
+ %span.alert-danger
529
+ MISSING
530
+ "
531
+ when :time
532
+ " %td
533
+ - unless #{singular}.#{col}.nil?
534
+ = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone)
535
+ - else
536
+ %span.alert-danger
537
+ MISSING
538
+ "
539
+
478
540
  end
479
541
  }.join("\n")
480
542
  return res
481
543
  end
482
544
 
483
545
 
546
+ def controller_descends_from
547
+ if defined?(@namespace.titlecase + "::BaseController")
548
+ @namespace.titlecase + "::BaseController"
549
+ else
550
+ "ApplicationController"
551
+ end
552
+ end
553
+
554
+
555
+ def destroy_action
556
+ return false if @self_auth
557
+ return true
558
+ end
559
+
560
+ def create_action
561
+ return false if @self_auth
562
+ return true
563
+ end
564
+
484
565
 
485
566
  private # thor does something fancy like sending the class all of its own methods during some strange run sequence
486
567
  # does not like public methods
@@ -0,0 +1,5 @@
1
+ - if resource.errors.any?
2
+ #error_explanation
3
+ - resource.errors.full_messages.each do |message|
4
+ %div.alert.alert-danger
5
+ = message
@@ -0,0 +1,7 @@
1
+ - unless notice.nil?
2
+ %div.alert.alert-notice.alert-dismissible
3
+ = notice
4
+
5
+ - unless alert.nil?
6
+ %div.alert.alert-danger.alert-dismissible
7
+ = alert
@@ -1,3 +1,7 @@
1
1
  <%= all_line_fields %>
2
2
  %td
3
- = 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 pull-right "
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, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
5
+ <% end %>
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 "
@@ -1,9 +1,9 @@
1
1
 
2
+ <% if create_action %>
2
3
  = link_to "New <%= singular.gsub('_',' ') %>", new_<%= path_helper_singular %>(<%= nested_arity_for_path %>), disable_with: "Loading...", remote: true, class: "new-<%= singular %>-button btn btn-primary pull-right"
3
-
4
4
  .clearfix
5
5
  .new-<%= singular %>-form{style: "display: none; position: relative;"}
6
-
6
+ <% end %>
7
7
 
8
8
 
9
9
  %table.table.table-striped.<%= singular %>-table
@@ -1,4 +1,5 @@
1
1
  .container-fluid
2
2
  .row
3
3
  .col-md-12
4
- = render partial: "<%= namespace_with_trailing_dash %><%= plural %>/list", locals: {<%= plural %>: <%= all_objects_root %>.order("created_at DESC").page(1)}
4
+ .<%= singular %>-list
5
+ = render partial: "<%= namespace_with_trailing_dash %><%= plural %>/list", locals: {<%= plural %>: <%= all_objects_root %>.order("created_at DESC").page(1)}
@@ -0,0 +1,3 @@
1
+ class <%= controller_descends_from %> < ApplicationController
2
+ end
3
+
@@ -1,16 +1,31 @@
1
1
 
2
2
  require("jquery")
3
- console.log("loading common core...")
3
+ // console.log("loading common core...")
4
+
5
+ // require("jstimezonedetect/dist/jstz.min")
6
+ // var JSTZ = require('jstimezonedetect');
7
+
8
+
4
9
 
5
- $(function(){
6
- // always pass csrf tokens on ajax calls
7
- $.ajaxSetup({
8
- headers: { 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }
9
- });
10
- });
11
10
 
12
11
  $(document).on('turbolinks:load', function() {
12
+
13
13
  $(document).ready(() => {
14
+ var user_timezone = '';
15
+ try {user_timezone = JSTZ.determine().name();} catch(e){}
16
+ // always pass csrf tokens on ajax calls
17
+
18
+
19
+ // $.ajaxSetup({
20
+ // beforeSend: (xhr) => {
21
+ //
22
+ // xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
23
+ // xhr.setRequestHeader( 'X-User-Timezone', user_timezone)
24
+ //
25
+ //
26
+ // }
27
+ // })
28
+
14
29
  $("body").on("click", "[data-role='close-button']", (event) => {
15
30
  var form_name;
16
31
  form_name = $(event.currentTarget).data("name");
@@ -30,7 +45,7 @@ $(document).on('turbolinks:load', function() {
30
45
  $form.find("i").remove()
31
46
  }
32
47
  })
33
- })
48
+ });
34
49
  });
35
50
 
36
51
 
@@ -0,0 +1,5 @@
1
+ [data-role='close-button'] {
2
+ position: absolute;
3
+ top: 0;
4
+ right: 0;
5
+ }
@@ -1,4 +1,4 @@
1
- class <%= controller_class_name %> < ApplicationController
1
+ class <%= controller_class_name %> < <%= controller_descends_from %>
2
2
  <% unless @auth_identifier.nil? %>
3
3
  before_action :authenticate_<%= auth_identifier %>!
4
4
 
@@ -6,7 +6,8 @@ class <%= controller_class_name %> < ApplicationController
6
6
  <% if any_nested? %> <% @nested_args.each do |arg| %>
7
7
  before_action :load_<%= arg %><% end %> <% end %>
8
8
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
9
-
9
+ helper :common_core
10
+ include CommonCoreJs::ControllerHelpers
10
11
 
11
12
  <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each do |arg| %>
12
13
  <% if nest_chain.empty?
@@ -19,20 +20,29 @@ class <%= controller_class_name %> < ApplicationController
19
20
  @<%= arg %> = <%= this_scope %>.find(params[:<%= arg %>_id])
20
21
  end<% end %> <% end %>
21
22
 
23
+
24
+ <% if !@self_auth %>
22
25
  def load_<%= singular_name %>
23
26
  @<%= singular_name %> = <%= object_scope %>.find(params[:id])
24
27
  end
28
+ <% else %>
29
+ def load_<%= singular_name %>
30
+ @<%= singular_name %> = <%= auth_object %>
31
+ end<% end %>
25
32
 
26
33
  def index
34
+ <% if !@self_auth %>
27
35
  @<%= plural_name %> = <%= object_scope %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
28
-
36
+ <% else %>
37
+ @<%= plural_name %> = [<%= auth_object %>]
38
+ <% end %>
29
39
  respond_to do |format|
30
40
  format.js<% if @with_index %>
31
41
  format.html {render 'all.haml'}<% end %>
32
42
  end
33
43
  end
34
44
 
35
- def new
45
+ <% if create_action %> def new
36
46
  @<%= singular_name %> = <%= class_name %>.new(<%= create_merge_params %>)
37
47
  respond_to do |format|
38
48
  format.js
@@ -40,16 +50,16 @@ class <%= controller_class_name %> < ApplicationController
40
50
  end
41
51
 
42
52
  def create
43
- @<%=singular_name %> = <%=class_name %>.create(<%=singular_name %>_params<% if !create_merge_params.empty? %>.merge!(<%= create_merge_params %>)<%end%>)
53
+ modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !create_merge_params.empty? %>.merge!(<%= create_merge_params %>)<%end%> , <%= @auth ? @auth : "nil" %>)
54
+ @<%=singular_name %> = <%=class_name %>.create(modified_params)
44
55
  respond_to do |format|
45
56
  if @<%= singular_name %>.save
46
- format.js
47
57
  else
48
58
  flash[:alert] = "Oops, your <%=singular_name %> could not be saved."
49
- format.js
50
59
  end
60
+ format.js
51
61
  end
52
- end
62
+ end<% end %>
53
63
 
54
64
  def show
55
65
  respond_to do |format|
@@ -65,14 +75,14 @@ class <%= controller_class_name %> < ApplicationController
65
75
 
66
76
  def update
67
77
  respond_to do |format|
68
- if !@<%=singular_name %>.update(<%= singular %>_params)
78
+ if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%= @auth ? @auth : "nil" %> ))
69
79
  flash[:alert] = "<%=singular_name.titlecase %> could not be saved"
70
80
  end
71
81
  format.js {}
72
82
  end
73
83
  end
74
84
 
75
- def destroy
85
+ <% if destroy_action %>def destroy
76
86
  respond_to do |format|
77
87
  begin
78
88
  @<%=singular_name%>.destroy
@@ -81,7 +91,7 @@ class <%= controller_class_name %> < ApplicationController
81
91
  end
82
92
  format.js {}
83
93
  end
84
- end
94
+ end<% end %>
85
95
 
86
96
  def <%=singular_name%>_params
87
97
  params.require(:<%=singular_name%>).permit( <%= @columns %> )
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.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
@@ -142,8 +142,8 @@ files:
142
142
  - app/assets/stylesheets/common_core_js/application.css
143
143
  - app/assets/stylesheets/common_core_js/common_core.scss
144
144
  - app/controllers/common_core_js/application_controller.rb
145
- - app/helpers/common_core_js/application_helper.rb
146
- - app/helpers/common_core_js/generator_helper.rb
145
+ - app/helpers/common_core_helper.rb
146
+ - app/helpers/common_core_js/controller_helper.rb
147
147
  - app/jobs/common_core_js/application_job.rb
148
148
  - app/mailers/common_core_js/application_mailer.rb
149
149
  - app/models/common_core_js/application_record.rb
@@ -170,11 +170,14 @@ files:
170
170
  - lib/generators/common_core/install_generator.rb
171
171
  - lib/generators/common_core/scaffold_generator.rb
172
172
  - lib/generators/common_core/templates/_edit.haml
173
+ - lib/generators/common_core/templates/_errors.haml
174
+ - lib/generators/common_core/templates/_flash_notices.haml
173
175
  - lib/generators/common_core/templates/_form.haml
174
176
  - lib/generators/common_core/templates/_line.haml
175
177
  - lib/generators/common_core/templates/_list.haml
176
178
  - lib/generators/common_core/templates/_new.haml
177
179
  - lib/generators/common_core/templates/all.haml
180
+ - lib/generators/common_core/templates/base_controller.rb
178
181
  - lib/generators/common_core/templates/common_core.js
179
182
  - lib/generators/common_core/templates/common_core.scss
180
183
  - lib/generators/common_core/templates/controller.rb
@@ -1,4 +0,0 @@
1
- module CommonCoreJs
2
- module ApplicationHelper
3
- end
4
- end