common_core_js 0.3.0 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/LICENSE +2 -2
- data/app/helpers/common_core_helper.rb +79 -0
- data/app/views/common/_common_create.js.erb +1 -1
- data/app/views/common/_common_edit_form.haml +4 -0
- data/app/views/common/_common_update.js.erb +2 -1
- data/common_core_js.gemspec +1 -0
- data/lib/common_core_js.rb +20 -0
- data/lib/common_core_js/engine.rb +2 -0
- data/lib/common_core_js/version.rb +1 -1
- data/lib/generators/common_core/USAGE +2 -4
- data/lib/generators/common_core/install_generator.rb +22 -0
- data/lib/generators/common_core/scaffold_generator.rb +143 -36
- data/lib/generators/common_core/templates/_errors.haml +5 -0
- data/lib/generators/common_core/templates/_flash_notices.haml +7 -0
- data/lib/generators/common_core/templates/_line.haml +3 -1
- data/lib/generators/common_core/templates/all.haml +2 -1
- data/{app/javascript/common_core/xyz.js → lib/generators/common_core/templates/common_core.js} +24 -9
- data/lib/generators/common_core/templates/common_core.scss +5 -0
- data/lib/generators/common_core/templates/controller.rb +5 -4
- data/lib/generators/common_core/templates/controller_spec.rb +1 -1
- data/lib/tasks/common_core_js_tasks.rake +7 -4
- metadata +21 -4
- data/app/helpers/common_core_js/application_helper.rb +0 -4
- data/vendor/assets/stylesheets/common_core_js.scss +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b5a9a869b6a0f94746461670598d9cb5bedb33990863601ef3ecdf220fbdc9
|
4
|
+
data.tar.gz: 32503cb59ddee608eeae10c6ff8f75c044550c400d28bec85b0b0bb97170eea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e02dc262dc51c695434596729c6fb3521ceb6399446a1ddfb0c3e331c5a34c0f91e533c9e27ce2135e1ccb5da5101ed981873ef26beb97f9b56e88545de8e1
|
7
|
+
data.tar.gz: 21be6527906de8b37ce77b497a10e3c2edbdd1fb5f94aab9ba250820ef58735a4933ae119c2f46aab956ed49724573e84c51c51e9d83e4f3e4434e238796b4db
|
data/.gitignore
CHANGED
data/LICENSE
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Permission is hereby granted to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
2
2
|
|
3
|
-
Any users of this software agree to work to dismantle systemic racism
|
3
|
+
Any users of this software agree to work to dismantle systemic racism, seek justice for black, brown, transgender people, women, and LTBQIAA+ representation and inclusion.
|
4
4
|
|
5
|
-
Organizations using this software agree to center the narratives of black, brown, and
|
5
|
+
Organizations using this software agree to center the narratives of black, brown, and transgender people people.
|
6
6
|
|
7
7
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
8
|
|
@@ -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
|
@@ -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(
|
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,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
|
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()
|
data/common_core_js.gemspec
CHANGED
@@ -47,6 +47,7 @@ Gem::Specification.new do |spec|
|
|
47
47
|
spec.add_runtime_dependency 'bootsnap'
|
48
48
|
spec.add_runtime_dependency 'bootstrap'
|
49
49
|
spec.add_runtime_dependency 'font-awesome-rails'
|
50
|
+
spec.add_dependency 'ffaker'
|
50
51
|
|
51
52
|
spec.post_install_message = <<~MSG
|
52
53
|
---------------------------------------------
|
data/lib/common_core_js.rb
CHANGED
@@ -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)
|
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
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/erb/scaffold/scaffold_generator'
|
2
|
+
require 'ffaker'
|
3
|
+
|
4
|
+
module CommonCore
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
hook_for :form_builder, :as => :scaffold
|
7
|
+
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(*args) #:nodoc:
|
12
|
+
super
|
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
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -1,6 +1,36 @@
|
|
1
1
|
require 'rails/generators/erb/scaffold/scaffold_generator'
|
2
|
+
require 'ffaker'
|
3
|
+
|
4
|
+
|
2
5
|
|
3
6
|
module CommonCore
|
7
|
+
|
8
|
+
module GeneratorHelper
|
9
|
+
def text_area_output(col, field_length)
|
10
|
+
lines = field_length % 40
|
11
|
+
if lines > 5
|
12
|
+
lines = 5
|
13
|
+
end
|
14
|
+
|
15
|
+
".row
|
16
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
17
|
+
= f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}'
|
18
|
+
%label.form-text
|
19
|
+
#{col.to_s.humanize}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
def field_output(col, type = nil, width)
|
25
|
+
".row
|
26
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
27
|
+
= f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}'
|
28
|
+
%label.form-text
|
29
|
+
#{col.to_s.humanize}\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
4
34
|
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
5
35
|
hook_for :form_builder, :as => :scaffold
|
6
36
|
|
@@ -8,6 +38,9 @@ module CommonCore
|
|
8
38
|
attr_accessor :path, :singular, :plural, :singular_class, :nest_with
|
9
39
|
|
10
40
|
|
41
|
+
include GeneratorHelper
|
42
|
+
|
43
|
+
|
11
44
|
def initialize(*meta_args) #:nodoc:
|
12
45
|
super
|
13
46
|
|
@@ -18,12 +51,7 @@ module CommonCore
|
|
18
51
|
exit
|
19
52
|
end
|
20
53
|
|
21
|
-
|
22
|
-
@columns = object.columns.map(&:name).map(&:to_sym).reject{|x| x==:updated_at || x==:created_at || x==:id}
|
23
|
-
rescue StandardError => e
|
24
|
-
puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
|
25
|
-
exit
|
26
|
-
end
|
54
|
+
|
27
55
|
|
28
56
|
args = meta_args[0]
|
29
57
|
@singular = args[0].tableize.singularize # should be in form hello_world
|
@@ -55,6 +83,18 @@ module CommonCore
|
|
55
83
|
end
|
56
84
|
end
|
57
85
|
|
86
|
+
auth_assoc = @auth.gsub("current_","")
|
87
|
+
auth_assoc_field = auth_assoc + "_id"
|
88
|
+
|
89
|
+
|
90
|
+
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 }
|
93
|
+
rescue StandardError => e
|
94
|
+
puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
|
95
|
+
exit
|
96
|
+
end
|
97
|
+
|
58
98
|
flags = meta_args[1]
|
59
99
|
flags.each do |f|
|
60
100
|
case (f)
|
@@ -106,6 +146,8 @@ module CommonCore
|
|
106
146
|
unless @no_specs
|
107
147
|
template "controller_spec.rb", File.join("spec/controllers#{namespace_with_dash}", "#{plural}_controller_spec.rb")
|
108
148
|
end
|
149
|
+
|
150
|
+
template "_errors.haml", File.join("app/views#{namespace_with_dash}", "_errors.haml")
|
109
151
|
end
|
110
152
|
|
111
153
|
def list_column_headings
|
@@ -322,9 +364,7 @@ module CommonCore
|
|
322
364
|
|
323
365
|
def all_form_fields
|
324
366
|
res = @columns.map { |col|
|
325
|
-
|
326
|
-
# byebug
|
327
|
-
# end
|
367
|
+
|
328
368
|
|
329
369
|
type = eval("#{singular_class}.columns_hash['#{col}']").type
|
330
370
|
limit = eval("#{singular_class}.columns_hash['#{col}']").limit
|
@@ -334,47 +374,77 @@ module CommonCore
|
|
334
374
|
when :integer
|
335
375
|
# look for a belongs_to on this object
|
336
376
|
if col.to_s.ends_with?("_id")
|
377
|
+
# guess the association name label
|
378
|
+
|
337
379
|
|
338
380
|
assoc_name = col.to_s.gsub("_id","")
|
339
|
-
assoc = eval("#{singular_class}.reflect_on_association(
|
381
|
+
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
382
|
+
if assoc.nil?
|
383
|
+
puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
384
|
+
exit
|
385
|
+
end
|
386
|
+
|
387
|
+
if assoc.active_record.column_names.include?("name")
|
388
|
+
display_column = "name"
|
389
|
+
elsif assoc.active_record.column_names.include?("to_label")
|
390
|
+
display_column = "to_label"
|
391
|
+
elsif assoc.active_record.column_names.include?("full_name")
|
392
|
+
display_column = "full_name"
|
393
|
+
elsif assoc.active_record.column_names.include?("display_name")
|
394
|
+
display_column = "display_name"
|
395
|
+
elsif assoc.active_record.column_names.include?("email")
|
396
|
+
display_column = "email"
|
397
|
+
end
|
398
|
+
|
340
399
|
".row
|
341
|
-
|
342
|
-
= f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id,
|
400
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
|
401
|
+
= f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
|
343
402
|
%label.small.form-text.text-muted
|
344
403
|
#{col.to_s.humanize}"
|
345
404
|
|
346
405
|
else
|
347
406
|
".row
|
348
|
-
|
349
|
-
= f.text_field :#{col.to_s}, class: 'form-control', size: 4, type: 'number'
|
407
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
408
|
+
= f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number'
|
350
409
|
%label.form-text
|
351
410
|
#{col.to_s.humanize}\n"
|
352
411
|
end
|
353
412
|
when :string
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
413
|
+
limit ||= 40
|
414
|
+
if limit < 50
|
415
|
+
field_output(col, nil, limit)
|
416
|
+
else
|
417
|
+
text_area_output(col, limit)
|
418
|
+
end
|
419
|
+
|
360
420
|
when :text
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
#{col.humanize}\n"
|
367
|
-
when :datetime
|
368
|
-
".row
|
369
|
-
.form-group.col-md-4
|
370
|
-
= f.text_field :#{col.to_s}, class: 'form-control', type: 'datetime-local'
|
371
|
-
%label.form-text
|
372
|
-
#{col.to_s.humanize}\n"
|
421
|
+
limit ||= 40
|
422
|
+
if limit < 50
|
423
|
+
field_output(col, nil, limit)
|
424
|
+
else
|
425
|
+
text_area_output(col, limit)
|
373
426
|
end
|
374
|
-
|
427
|
+
|
428
|
+
when :datetime
|
429
|
+
".row
|
430
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
431
|
+
= datetime_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth}.timezone)"
|
432
|
+
when :date
|
433
|
+
".row
|
434
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
435
|
+
= date_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth}.timezone)"
|
436
|
+
when :time
|
437
|
+
".row
|
438
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
439
|
+
= time_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth}.timezone)"
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
}.join("\n")
|
375
444
|
return res
|
376
445
|
end
|
377
446
|
|
447
|
+
|
378
448
|
def all_line_fields
|
379
449
|
res = "%tr{'data-id': #{singular}.id, 'data-edit': 'false'}\n"
|
380
450
|
|
@@ -394,11 +464,26 @@ module CommonCore
|
|
394
464
|
assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
|
395
465
|
|
396
466
|
if assoc.nil?
|
397
|
-
|
467
|
+
puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
468
|
+
exit
|
469
|
+
end
|
470
|
+
|
471
|
+
if assoc.active_record.column_names.include?("name")
|
472
|
+
display_column = "name"
|
473
|
+
elsif assoc.active_record.column_names.include?("to_label")
|
474
|
+
display_column = "to_label"
|
475
|
+
elsif assoc.active_record.column_names.include?("full_name")
|
476
|
+
display_column = "full_name"
|
477
|
+
elsif assoc.active_record.column_names.include?("display_name")
|
478
|
+
display_column = "display_name"
|
479
|
+
elsif assoc.active_record.column_names.include?("email")
|
480
|
+
display_column = "email"
|
481
|
+
else
|
482
|
+
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"
|
398
483
|
end
|
399
484
|
|
400
485
|
" %td
|
401
|
-
= #{singular}.#{assoc.name.to_s}
|
486
|
+
= #{singular}.#{assoc.name.to_s}.#{display_column}"
|
402
487
|
|
403
488
|
else
|
404
489
|
" %td
|
@@ -413,7 +498,29 @@ module CommonCore
|
|
413
498
|
= #{singular}.#{col}"
|
414
499
|
when :datetime
|
415
500
|
" %td
|
416
|
-
|
501
|
+
- unless #{singular}.#{col}.nil?
|
502
|
+
= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + human_timezone(Time.now, current_timezone)
|
503
|
+
- else
|
504
|
+
%span.alert-danger
|
505
|
+
MISSING
|
506
|
+
"
|
507
|
+
when :date
|
508
|
+
" %td
|
509
|
+
- unless #{singular}.#{col}.nil?
|
510
|
+
= #{singular}.#{col}
|
511
|
+
- else
|
512
|
+
%span.alert-danger
|
513
|
+
MISSING
|
514
|
+
"
|
515
|
+
when :time
|
516
|
+
" %td
|
517
|
+
- unless #{singular}.#{col}.nil?
|
518
|
+
= #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + human_timezone(Time.now, current_timezone)
|
519
|
+
- else
|
520
|
+
%span.alert-danger
|
521
|
+
MISSING
|
522
|
+
"
|
523
|
+
|
417
524
|
end
|
418
525
|
}.join("\n")
|
419
526
|
return res
|
@@ -1,3 +1,5 @@
|
|
1
1
|
<%= all_line_fields %>
|
2
2
|
%td
|
3
|
-
= link_to "
|
3
|
+
= 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 "
|
4
|
+
|
5
|
+
= 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,4 +1,5 @@
|
|
1
1
|
.container-fluid
|
2
2
|
.row
|
3
3
|
.col-md-12
|
4
|
-
|
4
|
+
.<%= singular %>-list
|
5
|
+
= render partial: "<%= namespace_with_trailing_dash %><%= plural %>/list", locals: {<%= plural %>: <%= all_objects_root %>.order("created_at DESC").page(1)}
|
data/{app/javascript/common_core/xyz.js → lib/generators/common_core/templates/common_core.js}
RENAMED
@@ -1,16 +1,31 @@
|
|
1
1
|
|
2
2
|
require("jquery")
|
3
|
-
console.log("loading common core...")
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
});
|
3
|
+
// console.log("loading common core...")
|
4
|
+
|
5
|
+
// require("jstimezonedetect/dist/jstz.min")
|
6
|
+
// var JSTZ = require('jstimezonedetect');
|
7
|
+
|
8
|
+
|
9
|
+
|
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
|
|
@@ -22,6 +22,7 @@ class <%= controller_class_name %> < ApplicationController
|
|
22
22
|
def load_<%= singular_name %>
|
23
23
|
@<%= singular_name %> = <%= object_scope %>.find(params[:id])
|
24
24
|
end
|
25
|
+
include CommonCoreJs::ControllerHelpers
|
25
26
|
|
26
27
|
def index
|
27
28
|
@<%= plural_name %> = <%= object_scope %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
|
@@ -40,14 +41,14 @@ class <%= controller_class_name %> < ApplicationController
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def create
|
43
|
-
|
44
|
+
modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !create_merge_params.empty? %>.merge!(<%= create_merge_params %><%end%> ), <%=@auth%>)
|
45
|
+
@<%=singular_name %> = <%=class_name %>.create(modified_params)
|
44
46
|
respond_to do |format|
|
45
47
|
if @<%= singular_name %>.save
|
46
|
-
format.js
|
47
48
|
else
|
48
49
|
flash[:alert] = "Oops, your <%=singular_name %> could not be saved."
|
49
|
-
format.js
|
50
50
|
end
|
51
|
+
format.js
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -65,7 +66,7 @@ class <%= controller_class_name %> < ApplicationController
|
|
65
66
|
|
66
67
|
def update
|
67
68
|
respond_to do |format|
|
68
|
-
if !@<%=singular_name %>.update(<%= singular %>_params)
|
69
|
+
if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%=@auth%> ))
|
69
70
|
flash[:alert] = "<%=singular_name.titlecase %> could not be saved"
|
70
71
|
end
|
71
72
|
format.js {}
|
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe <%= controller_class_name %> do
|
4
4
|
render_views
|
5
|
-
let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}
|
5
|
+
<% unless @auth.nil? %> let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
|
6
6
|
let(:<%= singular %>) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
|
7
7
|
|
8
8
|
<%= objest_nest_factory_setup %>
|
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.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ffaker
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Simple, plug & play Rails scaffolding with really simple Javascript
|
112
126
|
email: jason.fb@datatravels.com
|
113
127
|
executables: []
|
@@ -128,8 +142,7 @@ files:
|
|
128
142
|
- app/assets/stylesheets/common_core_js/application.css
|
129
143
|
- app/assets/stylesheets/common_core_js/common_core.scss
|
130
144
|
- app/controllers/common_core_js/application_controller.rb
|
131
|
-
- app/helpers/
|
132
|
-
- app/javascript/common_core/xyz.js
|
145
|
+
- app/helpers/common_core_helper.rb
|
133
146
|
- app/jobs/common_core_js/application_job.rb
|
134
147
|
- app/mailers/common_core_js/application_mailer.rb
|
135
148
|
- app/models/common_core_js/application_record.rb
|
@@ -153,13 +166,18 @@ files:
|
|
153
166
|
- lib/generators/.DS_Store
|
154
167
|
- lib/generators/common_core/USAGE
|
155
168
|
- lib/generators/common_core/erb/scaffold/common_core_scaffold_generator.rb
|
169
|
+
- lib/generators/common_core/install_generator.rb
|
156
170
|
- lib/generators/common_core/scaffold_generator.rb
|
157
171
|
- lib/generators/common_core/templates/_edit.haml
|
172
|
+
- lib/generators/common_core/templates/_errors.haml
|
173
|
+
- lib/generators/common_core/templates/_flash_notices.haml
|
158
174
|
- lib/generators/common_core/templates/_form.haml
|
159
175
|
- lib/generators/common_core/templates/_line.haml
|
160
176
|
- lib/generators/common_core/templates/_list.haml
|
161
177
|
- lib/generators/common_core/templates/_new.haml
|
162
178
|
- lib/generators/common_core/templates/all.haml
|
179
|
+
- lib/generators/common_core/templates/common_core.js
|
180
|
+
- lib/generators/common_core/templates/common_core.scss
|
163
181
|
- lib/generators/common_core/templates/controller.rb
|
164
182
|
- lib/generators/common_core/templates/controller_spec.rb
|
165
183
|
- lib/generators/common_core/templates/create.js.erb
|
@@ -169,7 +187,6 @@ files:
|
|
169
187
|
- lib/generators/common_core/templates/new.js.erb
|
170
188
|
- lib/generators/common_core/templates/update.js.erb
|
171
189
|
- lib/tasks/common_core_js_tasks.rake
|
172
|
-
- vendor/assets/stylesheets/common_core_js.scss
|
173
190
|
homepage: https://blog.jasonfleetwoodboldt.com/common-core-js/
|
174
191
|
licenses:
|
175
192
|
- MIT
|
File without changes
|