para 0.5.4 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/para/admin/async-progress.coffee +29 -0
  3. data/app/assets/javascripts/para/admin/filters-form.coffee +1 -1
  4. data/app/assets/javascripts/para/admin/importers.coffee +38 -0
  5. data/app/assets/javascripts/para/admin/table.coffee +1 -1
  6. data/app/assets/javascripts/para/admin/tabs.coffee +1 -1
  7. data/app/assets/javascripts/para/admin/theme_actions.coffee +1 -1
  8. data/app/assets/javascripts/para/admin/tree.coffee +5 -5
  9. data/app/assets/javascripts/para/admin.coffee +2 -1
  10. data/app/assets/javascripts/para/inputs/nested_many.coffee +1 -1
  11. data/app/assets/javascripts/para/lib/remote-file-forms.coffee +60 -0
  12. data/app/assets/javascripts/para/lib/turbolinks-loading.coffee +1 -1
  13. data/app/assets/javascripts/para/lib/turbolinks-reloader.coffee +19 -0
  14. data/app/assets/stylesheets/para/admin/src/datetimepicker.sass +3 -1
  15. data/app/assets/stylesheets/para/admin/src/fuelux.sass +4 -2
  16. data/app/assets/stylesheets/para/admin/src/nested_many.sass +5 -0
  17. data/app/assets/stylesheets/para/admin/src/redactor.sass +8 -5
  18. data/app/assets/stylesheets/para/admin/src/selectize.sass +7 -4
  19. data/app/assets/stylesheets/para/admin/theme/_breadcrumb.sass +20 -12
  20. data/app/assets/stylesheets/para/admin/theme/_buttons.sass +6 -2
  21. data/app/assets/stylesheets/para/admin/theme/_checkable.sass +4 -2
  22. data/app/assets/stylesheets/para/admin/theme/_commonds.sass +6 -3
  23. data/app/assets/stylesheets/para/admin/theme/_dropdown.sass +3 -1
  24. data/app/assets/stylesheets/para/admin/theme/_form.sass +4 -2
  25. data/app/assets/stylesheets/para/admin/theme/_list.sass +7 -5
  26. data/app/assets/stylesheets/para/admin/theme/_navigation.sass +12 -66
  27. data/app/assets/stylesheets/para/admin/theme/_navtabs.sass +18 -14
  28. data/app/assets/stylesheets/para/admin/theme/_orderable.sass +7 -3
  29. data/app/assets/stylesheets/para/admin/theme/_panel.sass +19 -13
  30. data/app/assets/stylesheets/para/admin/theme/_tree.sass +4 -2
  31. data/app/assets/stylesheets/para/overrides/theme.sass +14 -10
  32. data/app/controllers/para/admin/base_controller.rb +0 -5
  33. data/app/controllers/para/admin/crud_resources_controller.rb +5 -19
  34. data/app/controllers/para/admin/{singleton_resources_controller.rb → form_resources_controller.rb} +4 -4
  35. data/app/controllers/para/admin/imports_controller.rb +68 -0
  36. data/app/controllers/para/admin/resources_controller.rb +0 -1
  37. data/app/decorators/para/component/base_decorator.rb +6 -18
  38. data/app/decorators/para/component/crud_decorator.rb +3 -3
  39. data/app/decorators/para/component/{singleton_resource_decorator.rb → form_decorator.rb} +6 -6
  40. data/app/helpers/para/admin/components_helper.rb +12 -1
  41. data/app/helpers/para/admin/decorators_helper.rb +13 -0
  42. data/app/helpers/para/markup_helper.rb +4 -0
  43. data/app/helpers/para/search_helper.rb +1 -4
  44. data/app/models/para/component/base.rb +17 -14
  45. data/app/models/para/component/crud.rb +17 -0
  46. data/app/models/para/component/form.rb +36 -0
  47. data/app/models/para/component/resource.rb +9 -20
  48. data/app/models/para/component/settings.rb +1 -1
  49. data/app/models/para/library/file.rb +23 -0
  50. data/app/models/para/library.rb +5 -0
  51. data/app/views/para/admin/form_resources/show.html.haml +4 -0
  52. data/app/views/para/admin/imports/_completed.html.haml +16 -0
  53. data/app/views/para/admin/imports/_failed.html.haml +7 -0
  54. data/app/views/para/admin/imports/_progress.html.haml +5 -0
  55. data/app/views/para/admin/imports/new.html.haml +14 -0
  56. data/app/views/para/admin/imports/show.html.haml +10 -0
  57. data/app/views/para/admin/resources/_fields.html.haml +1 -4
  58. data/app/views/para/admin/resources/_imports_menu.html.haml +17 -20
  59. data/app/views/para/admin/resources/_tree.html.haml +1 -1
  60. data/app/views/para/admin/shared/_breadcrumbs.html.haml +1 -4
  61. data/app/views/para/admin/shared/_navigation.html.haml +2 -2
  62. data/app/views/para/form/_tabs.html.haml +1 -1
  63. data/config/locales/en.yml +10 -0
  64. data/config/locales/fr.yml +12 -2
  65. data/db/migrate/20160905134106_create_para_library_files.rb +9 -0
  66. data/lib/generators/para/importer/templates/base_importer.rb +8 -1
  67. data/lib/generators/para/install/install_generator.rb +1 -2
  68. data/lib/generators/para/install/templates/components.rb +9 -5
  69. data/lib/generators/para/tree_item/tree_item_generator.rb +17 -0
  70. data/lib/para/attribute_field/base.rb +12 -4
  71. data/lib/para/attribute_field/enum.rb +7 -3
  72. data/lib/para/component/importable.rb +4 -4
  73. data/lib/para/component.rb +1 -1
  74. data/lib/para/components_cleaner.rb +66 -0
  75. data/lib/para/components_configuration.rb +3 -1
  76. data/lib/para/engine.rb +36 -3
  77. data/lib/para/ext/active_job_status.rb +13 -0
  78. data/lib/para/ext/paperclip.rb +10 -0
  79. data/lib/para/ext/simple_form_extension.rb +6 -0
  80. data/lib/para/ext.rb +1 -0
  81. data/lib/para/form_builder/nested_form.rb +5 -2
  82. data/lib/para/importer/base.rb +84 -7
  83. data/lib/para/inputs/nested_many_input.rb +1 -1
  84. data/lib/para/logging/active_job_log_subscriber.rb +48 -0
  85. data/lib/para/logging.rb +8 -0
  86. data/lib/para/markup/resources_table.rb +2 -4
  87. data/lib/para/model_field_parsers/enums.rb +19 -0
  88. data/lib/para/model_field_parsers/relations.rb +1 -1
  89. data/lib/para/model_field_parsers/store.rb +1 -1
  90. data/lib/para/model_field_parsers.rb +1 -0
  91. data/lib/para/plugins/routes.rb +2 -4
  92. data/lib/para/postgres_extensions_checker.rb +30 -0
  93. data/lib/para/routes.rb +5 -4
  94. data/lib/para/routing/component_controller_constraint.rb +36 -0
  95. data/lib/para/routing.rb +7 -0
  96. data/lib/para/sti/root_model.rb +8 -2
  97. data/lib/para/version.rb +1 -1
  98. data/lib/para.rb +10 -0
  99. data/lib/rails/routing_mapper.rb +59 -27
  100. data/lib/tasks/para_tasks.rake +21 -11
  101. metadata +73 -15
  102. data/app/models/para/component/singleton_resource.rb +0 -35
  103. data/app/views/para/admin/singleton_resources/show.html.haml +0 -4
@@ -1,5 +1,10 @@
1
1
  @import "variables"
2
2
 
3
+ @import "compass/css3/box-shadow"
4
+ @import "compass/css3/transition"
5
+ @import "compass/css3/text-shadow"
6
+ @import "compass/css3/border-radius"
7
+
3
8
  .page-sidebar
4
9
  position: fixed
5
10
  height: 100%
@@ -9,7 +14,7 @@
9
14
  width: $left-menu-width-open
10
15
  float: left
11
16
  z-index: 3
12
- box-shadow: 2px 0 5px #fafafa
17
+ +box-shadow(2px 0 5px #fafafa)
13
18
  &.navbar-collapse
14
19
  padding: 0
15
20
 
@@ -56,7 +61,7 @@
56
61
  display: block
57
62
  z-index: 3
58
63
  background-color: $navbar-default-bg
59
- box-shadow: 0 2px 5px #fafafa
64
+ +box-shadow(0 2px 5px #fafafa)
60
65
  .ul-navbar li
61
66
  float: left
62
67
  display: block
@@ -131,7 +136,7 @@
131
136
  border-bottom: 0
132
137
  line-height: 19px
133
138
  color: $navbar-default-link-color
134
- text-shadow: none
139
+ +text-shadow(none)
135
140
  display: block
136
141
 
137
142
  &:hover
@@ -156,8 +161,8 @@
156
161
  width: $left-menu-width-open
157
162
  position: absolute
158
163
  overflow: visible
159
- border-radius: 3px
160
- box-shadow: 0 2px 1px 0 rgba(0, 0, 0, 0.1)
164
+ +border-radius(3px)
165
+ +box-shadow(0 2px 1px 0 rgba(0, 0, 0, 0.1))
161
166
  z-index: 3
162
167
  li
163
168
  width: 100%
@@ -188,7 +193,7 @@
188
193
  img
189
194
  width: 36px
190
195
  border: 2px solid #FFF
191
- border-radius: 50%
196
+ +border-radius(50%)
192
197
  .informer
193
198
  font-size: 11px
194
199
  position: absolute
@@ -199,7 +204,7 @@
199
204
  right: 10px
200
205
  top: 15px
201
206
  color: #FFF
202
- border-radius: 3px
207
+ +border-radius(3px)
203
208
  &.pulsate
204
209
  animation: pulsate 1s ease-out
205
210
  animation-iteration-count: infinite
@@ -222,62 +227,3 @@
222
227
  top: 5px
223
228
 
224
229
 
225
- /*
226
- * Profile
227
-
228
- .profile
229
- width: 100%
230
- float: left
231
- padding: 15px 10px
232
- position: relative
233
- background: #2d3945
234
- .profile-image
235
- float: left
236
- width: 100%
237
- margin: 0 0 10px
238
- text-align: center
239
- img
240
- width: 100px
241
- border: 3px solid #FFF
242
- border-radius: 50%
243
- .profile-data
244
- width: 100%
245
- float: left
246
- text-align: center
247
- .profile-data-name
248
- width: 100%
249
- float: left
250
- font-size: 14px
251
- font-weight: 500
252
- color: #FFF
253
- .profile-data-title
254
- width: 100%
255
- float: left
256
- font-size: 11px
257
- font-weight: 400
258
- color: $gray-dark
259
- .profile-controls a
260
- width: 30px
261
- height: 30px
262
- font-size: 14px
263
- color: #DDD
264
- border: 2px solid #DDD
265
- line-height: 25px
266
- position: absolute
267
- border-radius: 50%
268
- padding: 0
269
- transition: all 200ms ease
270
- &.profile-control-left
271
- left: 15px
272
- top: 53px
273
- text-align: center
274
- &.profile-control-right
275
- right: 15px
276
- top: 53px
277
- text-align: center
278
- .fa, .glyphicon
279
- width: auto
280
- margin-right: auto
281
- &:hover
282
- border-color: #FFF
283
- color: #FFF
@@ -1,5 +1,9 @@
1
1
  @import 'variables'
2
2
 
3
+ @import "compass/css3/box-shadow"
4
+ @import "compass/css3/transition"
5
+ @import "compass/css3/border-radius"
6
+
3
7
  .tabs
4
8
  float: left
5
9
  width: 100%
@@ -29,13 +33,13 @@
29
33
  border: 0
30
34
  font-size: 14px
31
35
  border-top: 2px solid transparent
32
- border-radius: 0
36
+ +border-radius(0)
33
37
  color: #333
34
- transition: all 200ms ease
38
+ +single-transition(all 200ms ease)
35
39
  background: $btn-default-bg
36
40
  padding: 9px 15px
37
41
  &:first-child > a
38
- border-radius: 5px 0 0
42
+ +border-radius(5px 0 0)
39
43
  > a:hover
40
44
  border-color: transparent
41
45
  background: #FFF
@@ -43,24 +47,24 @@
43
47
  border: 0
44
48
  border-top: 2px solid $brand-primary
45
49
  background: #FFF
46
- border-radius: 3px 3px 0 0
50
+ +border-radius( 3px 3px 0 0)
47
51
  li.active > a
48
52
  border: 0
49
53
  border-top: 2px solid $brand-primary
50
54
  background: #FFF
51
- border-radius: 3px 3px 0 0
55
+ +border-radius( 3px 3px 0 0)
52
56
  &:focus, &:hover
53
57
  border: 0
54
58
  border-top: 2px solid $brand-primary
55
59
  background: #FFF
56
- border-radius: 3px 3px 0 0
60
+ +border-radius( 3px 3px 0 0)
57
61
  &.nav-justified >
58
62
  li > a
59
63
  border: 0
60
64
  border-top: 2px solid transparent
61
- border-radius: 0
65
+ +border-radius( 0)
62
66
  color: #333
63
- transition: all 200ms ease
67
+ +single-transition(all 200ms ease)
64
68
  &:hover
65
69
  border-color: $brand-primary
66
70
  background: 0 0
@@ -68,12 +72,12 @@
68
72
  border: 0
69
73
  border-top: 2px solid $brand-primary
70
74
  background: #FFF
71
- border-radius: 3px 3px 0 0
75
+ +border-radius( 3px 3px 0 0)
72
76
  &:focus, &:hover
73
77
  border: 0
74
78
  border-top: 2px solid $brand-primary
75
79
  background: #FFF
76
- border-radius: 3px 3px 0 0
80
+ +border-radius( 3px 3px 0 0)
77
81
  a
78
82
  .caret, &:hover .caret
79
83
  color: $brand-primary
@@ -94,7 +98,7 @@
94
98
  width: 100%
95
99
  > a
96
100
  width: 100%
97
- border-radius: 0
101
+ +border-radius( 0)
98
102
  border-top: 0
99
103
  border-left: 2px solid transparent
100
104
  background: #FFF
@@ -115,9 +119,9 @@
115
119
  border-left: 2px solid $brand-primary
116
120
  background: $btn-default-bg
117
121
  &:first-child > a
118
- border-top-left-radius: 3px
122
+ +border-top-left-radius(3px)
119
123
  &:last-child > a
120
- border-bottom-left-radius: 3px
124
+ +border-bottom-left-radius(3px)
121
125
  .tab-content
122
126
  width: auto
123
127
  margin-left: 150px
@@ -127,7 +131,7 @@
127
131
  .form-tabs
128
132
  .navbar
129
133
  margin-bottom: 0
130
- border-radius: 0
134
+ +border-radius( 0)
131
135
  .nav li
132
136
  border-top: none
133
137
  &.active
@@ -1,12 +1,16 @@
1
1
  @import "variables"
2
2
 
3
+ @import "compass/css3/transition"
4
+ @import "compass/css3/transform"
5
+ @import "compass/css3/inline-block"
6
+
3
7
  .order-anchor
4
8
  float: left
5
9
  margin-right: 10px
6
10
  color: $gray-darker
7
11
  cursor: move
8
12
  outline: 0
9
- transition: all, .2s, ease-out
13
+ +single-transition(all, .2s, ease-out)
10
14
  &:hover
11
15
  color: $gray-darker
12
16
  &:focus,
@@ -19,13 +23,13 @@
19
23
  .btn-group
20
24
  display: none
21
25
  .order-anchor
22
- display: inline-block
26
+ +inline-block
23
27
  position: relative
24
28
 
25
29
  .panel
26
30
  .collapsed
27
31
  .caret
28
- transform: rotate(270deg)
32
+ +rotate(270deg)
29
33
 
30
34
  .nested-many-field
31
35
  &.orderable
@@ -1,14 +1,20 @@
1
1
  @import "variables"
2
2
 
3
+ @import "compass/css3/border-radius"
4
+ @import "compass/css3/box-shadow"
5
+ @import "compass/css3/inline-block"
6
+ @import "compass/css3/transition"
7
+ @import "compass/css3/transform"
8
+
3
9
  .panel
4
10
  float: left
5
11
  width: 100%
6
- border-radius: $panel-border-radius
12
+ +border-radius($panel-border-radius)
7
13
  border: 0
8
14
  border-top: 2px solid $panel-default-border
9
15
  margin-bottom: 20px
10
16
  position: relative
11
- box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.2)
17
+ +box-shadow(0 1px 1px 0 rgba(0, 0, 0, 0.2))
12
18
  &.panel-default
13
19
  border-top-color: $panel-default-border
14
20
  border-top-width: 1px
@@ -28,7 +34,7 @@
28
34
  float: left
29
35
  width: 30px
30
36
  border: 2px solid $gray-lighter
31
- border-radius: 50%
37
+ +border-radius(50%)
32
38
  margin-right: 5px
33
39
  .panel-title
34
40
  margin-left: 7px
@@ -81,7 +87,7 @@
81
87
  margin-bottom: 10px
82
88
  position: relative
83
89
  img
84
- border-radius: 5px 5px 0 0
90
+ +border-radius(5px 5px 0 0)
85
91
  width: 100%
86
92
  .panel-body-inform
87
93
  width: 30px
@@ -91,13 +97,13 @@
91
97
  left: 50%
92
98
  background: $brand-info
93
99
  color: #FFF
94
- border-radius: 5px
100
+ +border-radius(5px)
95
101
  margin-left: -15px
96
102
  text-align: center
97
103
  line-height: 30px
98
104
  padding-left: 1px
99
105
  padding-top: 1px
100
- transform: rotate(45deg)
106
+ +rotate(45deg)
101
107
  &.inform-primary
102
108
  background: $brand-primary
103
109
  &.inform-success
@@ -109,11 +115,11 @@
109
115
  .fa
110
116
  font-size: 16px
111
117
  color: #FFF
112
- transform: rotate(-45deg)
118
+ +rotate(-45deg)
113
119
  &.list-group
114
120
  padding: 0
115
121
  &.profile
116
- border-radius: 5px 5px 0 0
122
+ +border-radius(5px 5px 0 0)
117
123
  &.panel-body-search
118
124
  padding: 5px
119
125
  &.panel-body-half .panel-body
@@ -181,9 +187,9 @@ ul.panel-controls
181
187
  line-height: 28px
182
188
  color: $breadcrumb-active-color
183
189
  border: 1px solid #BBB
184
- border-radius: 50%
190
+ +border-radius(50%)
185
191
  margin-left: 3px
186
- transition: all 200ms ease
192
+ +single-transition(all, 200ms, ease)
187
193
  &.control-primary
188
194
  color: $brand-primary
189
195
  border-color: $brand-primary
@@ -204,7 +210,7 @@ ul.panel-controls
204
210
  color: $title-color
205
211
 
206
212
  .label-form
207
- display: inline-block
213
+ +inline-block
208
214
  font-size: 11px
209
215
  padding: 5px 10px
210
216
  line-height: 12px
@@ -215,8 +221,8 @@ ul.panel-controls
215
221
  padding: 4px 10px
216
222
  margin: 3px 0 3px 5px
217
223
  font-size: 12px
218
- display: inline-block
219
- border-radius: 3px
224
+ +inline-block
225
+ +border-radius(3px)
220
226
  &.pulsate
221
227
  animation: pulsate 1s ease-out
222
228
  animation-iteration-count: infinite
@@ -1,5 +1,7 @@
1
1
  @import "variables"
2
2
 
3
+ @import "compass/css3/inline-block"
4
+
3
5
  .root-tree
4
6
  padding-left: 0
5
7
  > .node
@@ -27,7 +29,7 @@
27
29
  padding: 5px
28
30
  text-align: center
29
31
  width: 32px
30
- display: inline-block
32
+ +inline-block
31
33
  margin-top: 3px
32
34
  &:focus,
33
35
  &:active,
@@ -36,7 +38,7 @@
36
38
 
37
39
  .node-name
38
40
  margin-top: 3px
39
- display: inline-block
41
+ +inline-block
40
42
 
41
43
  .placeholder
42
44
  height: 30px
@@ -1,5 +1,9 @@
1
1
  @import "para/admin/theme/variables"
2
2
 
3
+ @import "compass/css3/box-shadow"
4
+ @import "compass/css3/transition"
5
+
6
+
3
7
  .animated
4
8
  animation-duration: 100ms
5
9
 
@@ -11,11 +15,11 @@
11
15
 
12
16
  @mixin button-hover-focus-active($color-border, $color-bg)
13
17
  position: relative
14
- box-shadow: 0px 2px darken($color-border, 10%)
15
- transition: none
18
+ +box-shadow(0px 2px darken($color-border, 10%))
19
+ +single-transition(none)
16
20
  &:hover
17
21
  top: 1px
18
- box-shadow: 0px 1px darken($color-border, 10%)
22
+ +box-shadow(0px 1px darken($color-border, 10%))
19
23
  background-color: $color-bg
20
24
  border-color: $color-border
21
25
  &:focus,
@@ -24,7 +28,7 @@
24
28
  .open &.dropdown-toggle
25
29
  background-color: darken($color-bg, 7%)
26
30
  top: 2px
27
- box-shadow: 0px 0 darken($color-border, 10%)
31
+ +box-shadow(0px 0 darken($color-border, 10%))
28
32
  border-color: $color-border
29
33
  &:hover
30
34
  background-color: darken($color-bg, 7%)
@@ -32,8 +36,8 @@
32
36
  @mixin button-variant-inverse($color-border, $color-bg)
33
37
  color: $color-border
34
38
  background-color: transparent
35
- box-shadow: none
36
- transition: all, .2s, linear
39
+ +box-shadow(none)
40
+ +single-transition(all, .2s, linear)
37
41
  &:hover
38
42
  box-shadow: none
39
43
  top: 0
@@ -45,7 +49,7 @@
45
49
  &:active,
46
50
  &.active,
47
51
  .open &.dropdown-toggle
48
- box-shadow: none
52
+ +box-shadow(none)
49
53
  top: 0
50
54
  color: #fff
51
55
  background-color: darken($color-bg, 7%)
@@ -57,7 +61,7 @@ input,
57
61
  textarea,
58
62
  select,
59
63
  button
60
- transition: all, .1s, linear
64
+ +single-transition(all, .1s, linear)
61
65
  &,
62
66
  &:active,
63
67
  &.active
@@ -132,7 +136,7 @@ button
132
136
  height: 50px
133
137
 
134
138
  .pull-right.btn-group
135
- min-width: 145px
139
+ min-width: 146px
136
140
  text-align: right
137
141
  > .btn
138
142
  float: none
@@ -144,7 +148,7 @@ button
144
148
  .btn:focus,
145
149
  .btn:active,
146
150
  top: 0
147
- box-shadow: none
151
+ +box-shadow(none)
148
152
 
149
153
  .form-group-separated
150
154
  &:after
@@ -8,7 +8,6 @@ module Para
8
8
  end
9
9
 
10
10
  before_action :authorize_admin_access
11
- before_action :load_component_sections
12
11
 
13
12
  layout 'para/admin'
14
13
 
@@ -32,10 +31,6 @@ module Para
32
31
  authorize! :access, :admin
33
32
  end
34
33
 
35
- def load_component_sections
36
- @component_sections = Para::ComponentSection.ordered.includes(:components)
37
- end
38
-
39
34
  def self.load_and_authorize_component(options = {})
40
35
  before_action do
41
36
  load_and_authorize_component(options)
@@ -6,11 +6,11 @@ module Para
6
6
  include Para::Admin::ResourceControllerConcerns
7
7
  include Para::SearchHelper
8
8
 
9
- before_filter :load_and_authorize_crud_resource
10
- before_filter :add_breadcrumbs, only: [:show, :index, :edit, :new]
9
+ before_action :load_and_authorize_crud_resource
10
+ before_action :add_breadcrumbs, only: [:show, :index, :edit, :new]
11
11
 
12
- after_filter :attach_resource_to_component, only: [:create]
13
- after_filter :remove_resource_from_component, only: [:destroy]
12
+ after_action :attach_resource_to_component, only: [:create]
13
+ after_action :remove_resource_from_component, only: [:destroy]
14
14
 
15
15
  def index
16
16
  @q = @component.resources.search(params[:q])
@@ -41,7 +41,7 @@ module Para
41
41
  end
42
42
 
43
43
  flash_message(:success, new_resource)
44
- redirect_to after_form_submit_path
44
+ redirect_to @component.relation_path(new_resource, action: :edit)
45
45
  else
46
46
  flash_message(:error, new_resource)
47
47
  render after_form_submit_path
@@ -62,20 +62,6 @@ module Para
62
62
  end
63
63
  end
64
64
 
65
- def import
66
- if @component.importable?
67
- file = params[:file]
68
- if file
69
- importer = params[:importer].constantize.new(file.tempfile)
70
- importer.run
71
- flash_message(:success)
72
- else
73
- flash_message(:error)
74
- end
75
- end
76
- redirect_to @component.path
77
- end
78
-
79
65
  private
80
66
 
81
67
  def resource_model
@@ -2,11 +2,11 @@ require_dependency "para/application_controller"
2
2
 
3
3
  module Para
4
4
  module Admin
5
- class SingletonResourcesController < Para::Admin::ResourcesController
5
+ class FormResourcesController < Para::Admin::ResourcesController
6
6
  include Para::Admin::ResourceControllerConcerns
7
7
 
8
- before_filter :load_and_authorize_singleton_resource
9
- after_filter :attach_resource_to_component, only: [:create]
8
+ before_action :load_and_authorize_form
9
+ after_action :attach_resource_to_component, only: [:create]
10
10
 
11
11
  private
12
12
 
@@ -16,7 +16,7 @@ module Para
16
16
  @component.save
17
17
  end
18
18
 
19
- def load_and_authorize_singleton_resource
19
+ def load_and_authorize_form
20
20
  loader = self.class.cancan_resource_class.new(
21
21
  self, :resource, parent: false, class: resource_model.name,
22
22
  singleton: true, through: :component
@@ -0,0 +1,68 @@
1
+ module Para
2
+ module Admin
3
+ class ImportsController < Para::Admin::ComponentController
4
+ include Para::Admin::ResourceControllerConcerns
5
+
6
+ layout false
7
+
8
+ before_action :load_importer
9
+
10
+ def show
11
+ @status = ActiveJob::Status.get(params[:id])
12
+
13
+ respond_to do |format|
14
+ format.json do
15
+ if @status.failed?
16
+ render json: { status: @status.status }, status: 422
17
+ else
18
+ render json: { status: @status.status, progress: @status.progress * 100 }
19
+ end
20
+ end
21
+
22
+ format.html
23
+ end
24
+ end
25
+
26
+ def new
27
+ @file = Para::Library::File.new
28
+ @model = resource_model
29
+ end
30
+
31
+ def create
32
+ @file = Para::Library::File.new(file_params)
33
+
34
+ if @file.save
35
+ job = @importer.perform_later(@file)
36
+ @status = ActiveJob::Status.get(job)
37
+
38
+ render 'show'
39
+ else
40
+ render 'new'
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def load_importer
47
+ importer_name = params[:importer]&.camelize
48
+
49
+ @importer = @component.importers.find do |importer|
50
+ importer.name == importer_name
51
+ end
52
+
53
+ unless @importer
54
+ raise "Requested importer (#{ importer_name }) not found for " +
55
+ ":#{ @component.identifier } component."
56
+ end
57
+ end
58
+
59
+ def file_params
60
+ @file_params ||= if params[:file]
61
+ params.require(:file).permit(:attachment)
62
+ else
63
+ {}
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -122,7 +122,6 @@ module Para
122
122
  def self.resource(name, options = {})
123
123
  default_options = {
124
124
  class: name.to_s.camelize,
125
- through: :component,
126
125
  parent: false
127
126
  }
128
127
 
@@ -27,27 +27,15 @@ module Para
27
27
  # The only problem is if we have engines that declare the same routes
28
28
  #
29
29
  def find_path(path, options)
30
- polymorphic_path(path, options)
31
- rescue NoMethodError, NameError => original_error
32
- mounted_proxy_methods.each do |proxy_method|
33
- begin
34
- proxy = send(proxy_method)
35
- return polymorphic_path(([proxy] + path), options)
36
- rescue NoMethodError, NameError => e
37
- next
38
- end
30
+ safe_polymorphic_path(path, options).tap do |result|
31
+ raise result.class, result.message if Exception === result
39
32
  end
40
-
41
- raise original_error
42
33
  end
43
34
 
44
- def mounted_proxy_methods
45
- @mounted_proxy_methods ||= begin
46
- routes = Rails.application.routes
47
- routes.mounted_helpers.instance_methods.select do |name|
48
- /^[^_]/ =~ name
49
- end
50
- end
35
+ def safe_polymorphic_path(path, options)
36
+ polymorphic_path(path, options)
37
+ rescue => exception
38
+ exception
51
39
  end
52
40
  end
53
41
  end
@@ -3,9 +3,9 @@ module Para
3
3
  module CrudDecorator
4
4
  include Para::Component::BaseDecorator
5
5
 
6
- def path(options = {})
6
+ def path(namespace: :resources, **options)
7
7
  options[:model] ||= model_singular_route_key
8
- find_path([:admin, self, :resources], options)
8
+ find_path([:admin, self, namespace], options)
9
9
  end
10
10
 
11
11
  def relation_path(controller_or_resource, *nested_resources, **options)
@@ -25,7 +25,7 @@ module Para
25
25
 
26
26
  options[:action] = action_option_for(options, nested: nested)
27
27
 
28
- polymorphic_path(data, options)
28
+ find_path(data, options)
29
29
  end
30
30
 
31
31
  private