common_core_js 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/common_core_js/controller_helper.rb +21 -0
- data/lib/common_core_js.rb +1 -1
- data/lib/common_core_js/version.rb +1 -1
- data/lib/generators/common_core/scaffold_generator.rb +33 -6
- data/lib/generators/common_core/templates/_line.haml +2 -0
- data/lib/generators/common_core/templates/_list.haml +2 -2
- data/lib/generators/common_core/templates/base_controller.rb +3 -0
- data/lib/generators/common_core/templates/controller.rb +16 -6
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bd570ce32ada5b0551a77526d1b25e82f9b10a4ce9199e9abc60c3256a0c824
|
4
|
+
data.tar.gz: 39d7097d4e3daa434959ec9c72d93f83bee971d715f7ccde0fcb791332b8f490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 344db104a6bcca04942313947217d71f786698f6656590b5f49f03974046a557e8de438c3ba9146c1f2041996926341942f84ef3ff2b947883386e6c7ab2e9c0
|
7
|
+
data.tar.gz: 5c51d14d8d1055b3652ce5e2351582951a60b0d5cb78b1b91153cbf60aab5e141579f177c4de169dd5de3d9cc059c4795c6b45d3024c9d720dcd361ae37814b9
|
@@ -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
|
data/lib/common_core_js.rb
CHANGED
@@ -8,7 +8,7 @@ module CommonCoreJs
|
|
8
8
|
# Your code goes here...
|
9
9
|
#
|
10
10
|
module ControllerHelpers
|
11
|
-
def modify_date_inputs_on_params(modified_params)
|
11
|
+
def modify_date_inputs_on_params(modified_params, authenticated_user = nil)
|
12
12
|
use_timezone = authenticated_user.timezone || Time.now.strftime("%z")
|
13
13
|
|
14
14
|
modified_params = modified_params.tap do |params|
|
@@ -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
|
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,6 +150,9 @@ 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
|
@@ -270,7 +282,9 @@ module CommonCore
|
|
270
282
|
|
271
283
|
def all_objects_root
|
272
284
|
if @auth
|
273
|
-
if @
|
285
|
+
if @self_auth
|
286
|
+
@singular_class + ".where(id: #{@auth}.id)"
|
287
|
+
elsif @nested_args.none?
|
274
288
|
@auth + ".#{plural}"
|
275
289
|
else
|
276
290
|
"@" + @nested_args.last + ".#{plural}"
|
@@ -346,7 +360,7 @@ module CommonCore
|
|
346
360
|
|
347
361
|
|
348
362
|
def create_merge_params
|
349
|
-
if @auth
|
363
|
+
if @auth && ! @self_auth
|
350
364
|
"#{@auth_identifier}: #{@auth}"
|
351
365
|
else
|
352
366
|
""
|
@@ -394,6 +408,8 @@ module CommonCore
|
|
394
408
|
display_column = "display_name"
|
395
409
|
elsif assoc.active_record.column_names.include?("email")
|
396
410
|
display_column = "email"
|
411
|
+
else
|
412
|
+
puts "Can't find a display_column on {singular_class} object"
|
397
413
|
end
|
398
414
|
|
399
415
|
".row
|
@@ -411,7 +427,7 @@ module CommonCore
|
|
411
427
|
end
|
412
428
|
when :string
|
413
429
|
limit ||= 256
|
414
|
-
if limit
|
430
|
+
if limit <= 256
|
415
431
|
field_output(col, nil, limit)
|
416
432
|
else
|
417
433
|
text_area_output(col, limit)
|
@@ -419,7 +435,7 @@ module CommonCore
|
|
419
435
|
|
420
436
|
when :text
|
421
437
|
limit ||= 256
|
422
|
-
if limit
|
438
|
+
if limit <= 256
|
423
439
|
field_output(col, nil, limit)
|
424
440
|
else
|
425
441
|
text_area_output(col, limit)
|
@@ -536,6 +552,17 @@ module CommonCore
|
|
536
552
|
end
|
537
553
|
|
538
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
|
+
|
565
|
+
|
539
566
|
private # thor does something fancy like sending the class all of its own methods during some strange run sequence
|
540
567
|
# does not like public methods
|
541
568
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
<%= all_line_fields %>
|
2
2
|
%td
|
3
|
+
<% if destroy_action %>
|
3
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 %>
|
4
6
|
|
5
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
|
@@ -7,6 +7,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
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 %> < <%= controller_descends_from %>
|
|
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
|
@@ -49,7 +59,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
49
59
|
end
|
50
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 %> < <%= controller_descends_from %>
|
|
65
75
|
|
66
76
|
def update
|
67
77
|
respond_to do |format|
|
68
|
-
if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= 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
|
-
|
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 %> < <%= controller_descends_from %>
|
|
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.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- app/assets/stylesheets/common_core_js/common_core.scss
|
144
144
|
- app/controllers/common_core_js/application_controller.rb
|
145
145
|
- app/helpers/common_core_helper.rb
|
146
|
+
- app/helpers/common_core_js/controller_helper.rb
|
146
147
|
- app/jobs/common_core_js/application_job.rb
|
147
148
|
- app/mailers/common_core_js/application_mailer.rb
|
148
149
|
- app/models/common_core_js/application_record.rb
|
@@ -176,6 +177,7 @@ files:
|
|
176
177
|
- lib/generators/common_core/templates/_list.haml
|
177
178
|
- lib/generators/common_core/templates/_new.haml
|
178
179
|
- lib/generators/common_core/templates/all.haml
|
180
|
+
- lib/generators/common_core/templates/base_controller.rb
|
179
181
|
- lib/generators/common_core/templates/common_core.js
|
180
182
|
- lib/generators/common_core/templates/common_core.scss
|
181
183
|
- lib/generators/common_core/templates/controller.rb
|