archangel 0.0.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.jshintrc +1 -1
  3. data/.reek.yml +42 -0
  4. data/.rubocop.yml +1 -12
  5. data/.rubocop_exclude.yml +12 -0
  6. data/.rubocop_todo.yml +0 -4
  7. data/.travis.yml +5 -7
  8. data/Gemfile +12 -14
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +1 -1
  11. data/app/controllers/archangel/application_controller.rb +0 -2
  12. data/app/controllers/archangel/auth/registrations_controller.rb +12 -0
  13. data/app/controllers/archangel/backend/assets_controller.rb +10 -259
  14. data/app/controllers/archangel/backend/collections_controller.rb +5 -214
  15. data/app/controllers/archangel/backend/entries_controller.rb +25 -239
  16. data/app/controllers/archangel/backend/pages_controller.rb +11 -261
  17. data/app/controllers/archangel/backend/profiles_controller.rb +19 -12
  18. data/app/controllers/archangel/backend/sites_controller.rb +17 -16
  19. data/app/controllers/archangel/backend/templates_controller.rb +5 -232
  20. data/app/controllers/archangel/backend/users_controller.rb +10 -260
  21. data/app/controllers/archangel/backend/widgets_controller.rb +5 -226
  22. data/app/controllers/archangel/frontend/pages_controller.rb +6 -7
  23. data/app/controllers/concerns/archangel/actionable_concern.rb +9 -0
  24. data/app/controllers/concerns/archangel/controllers/backend/resourceful_concern.rb +28 -0
  25. data/app/controllers/concerns/archangel/controllers/resourceful_concern.rb +258 -0
  26. data/app/controllers/concerns/archangel/paginatable_concern.rb +2 -0
  27. data/app/controllers/concerns/archangel/seoable_concern.rb +9 -8
  28. data/app/models/archangel/metatag.rb +12 -0
  29. data/app/models/archangel/page.rb +7 -1
  30. data/app/models/archangel/site.rb +6 -1
  31. data/app/models/archangel/user.rb +7 -0
  32. data/app/views/archangel/backend/pages/_form.html.erb +12 -2
  33. data/app/views/archangel/backend/pages/_metatag_fields.html.erb +6 -0
  34. data/app/views/archangel/backend/pages/show.html.erb +0 -10
  35. data/app/views/archangel/backend/profiles/_form.html.erb +2 -0
  36. data/app/views/archangel/backend/sites/_form.html.erb +11 -2
  37. data/app/views/archangel/backend/sites/_metatag_fields.html.erb +6 -0
  38. data/app/views/archangel/backend/sites/show.html.erb +0 -10
  39. data/app/views/archangel/frontend/pages/show.json.jbuilder +1 -2
  40. data/archangel.gemspec +18 -11
  41. data/bin/archangel +6 -4
  42. data/config/locales/active_record.en.yml +3 -4
  43. data/config/locales/en.yml +6 -0
  44. data/db/migrate/20190101220919_add_preferences_to_archangel_users.rb +5 -0
  45. data/db/migrate/20190113130750_create_archangel_metatags.rb +14 -0
  46. data/db/migrate/20190113130751_remove_meta_keywords_and_meta_description_from_archangel_pages.rb +6 -0
  47. data/db/migrate/20190113130752_remove_meta_keywords_and_meta_description_from_archangel_sites.rb +6 -0
  48. data/docs/Developers.md +2 -2
  49. data/docs/Extension/Developers.md +1 -1
  50. data/docs/Extension/Uploaders.md +53 -1
  51. data/docs/Theme/Developers.md +8 -2
  52. data/lib/archangel.rb +2 -2
  53. data/lib/archangel/commands/base_command.rb +35 -0
  54. data/lib/archangel/commands/extension_command.rb +128 -0
  55. data/lib/archangel/{command/templates/extension → commands/templates/common}/.editorconfig +0 -0
  56. data/lib/archangel/{command/templates/extension → commands/templates/common}/.gitignore +0 -0
  57. data/lib/archangel/{command/templates/extension → commands/templates/common}/.rspec +0 -0
  58. data/lib/archangel/{command/templates/extension → commands/templates/common}/.rubocop.yml +0 -0
  59. data/lib/archangel/{command/templates/extension → commands/templates/common}/MIT-LICENSE +0 -0
  60. data/lib/archangel/{command/templates/extension → commands/templates/common}/spec/rails_helper.rb.tt +0 -3
  61. data/lib/archangel/{command/templates/extension → commands/templates/common}/spec/spec_helper.rb +0 -0
  62. data/lib/archangel/{command/templates/extension → commands/templates/common}/spec/support/.keep +0 -0
  63. data/lib/archangel/{command → commands}/templates/extension/Gemfile +9 -10
  64. data/lib/archangel/{command → commands}/templates/extension/README.md +0 -0
  65. data/lib/archangel/{command → commands}/templates/extension/Rakefile +0 -0
  66. data/lib/archangel/{command → commands}/templates/extension/app/assets/javascripts/archangel/auth/%extension_name%.js.tt +0 -0
  67. data/lib/archangel/{command → commands}/templates/extension/app/assets/javascripts/archangel/backend/%extension_name%.js.tt +0 -0
  68. data/lib/archangel/{command → commands}/templates/extension/app/assets/javascripts/archangel/frontend/%extension_name%.js.tt +0 -0
  69. data/lib/archangel/{command → commands}/templates/extension/app/assets/stylesheets/archangel/auth/%extension_name%.css.tt +0 -0
  70. data/lib/archangel/{command → commands}/templates/extension/app/assets/stylesheets/archangel/backend/%extension_name%.css.tt +0 -0
  71. data/lib/archangel/{command → commands}/templates/extension/app/assets/stylesheets/archangel/frontend/%extension_name%.css.tt +0 -0
  72. data/lib/archangel/{command → commands}/templates/extension/bin/rails.tt +0 -0
  73. data/lib/archangel/{command → commands}/templates/extension/config/locales/en.yml.tt +0 -0
  74. data/lib/archangel/{command → commands}/templates/extension/config/routes.rb +0 -0
  75. data/lib/archangel/{command/templates/extension/extension.gemspec → commands/templates/extension/extension.gemspec.tt} +0 -0
  76. data/lib/archangel/{command → commands}/templates/extension/lib/%extension_name%.rb.tt +0 -0
  77. data/lib/archangel/{command → commands}/templates/extension/lib/%extension_name%/engine.rb.tt +0 -0
  78. data/lib/archangel/{command → commands}/templates/extension/lib/%extension_name%/factories.rb.tt +0 -0
  79. data/lib/archangel/{command → commands}/templates/extension/lib/%extension_name%/version.rb.tt +0 -0
  80. data/lib/archangel/{command → commands}/templates/extension/lib/generators/%extension_name%/install/install_generator.rb.tt +0 -0
  81. data/lib/archangel/commands/templates/theme/Gemfile +27 -0
  82. data/lib/archangel/commands/templates/theme/README.md +44 -0
  83. data/lib/archangel/commands/templates/theme/Rakefile +29 -0
  84. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/assets/javascripts/%theme_base_name%/auth.js +2 -0
  85. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/assets/javascripts/%theme_base_name%/backend.js +2 -0
  86. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/assets/javascripts/%theme_base_name%/frontend.js +2 -0
  87. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/assets/stylesheets/%theme_base_name%/auth.css +4 -0
  88. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/assets/stylesheets/%theme_base_name%/backend.css +4 -0
  89. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/assets/stylesheets/%theme_base_name%/frontend.css +4 -0
  90. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/config/locales/en.yml.tt +4 -0
  91. data/lib/archangel/commands/templates/theme/app/themes/%theme_base_name%/views/layouts/frontend.liquid +18 -0
  92. data/lib/archangel/commands/templates/theme/bin/rails.tt +11 -0
  93. data/lib/archangel/commands/templates/theme/lib/%theme_name%.rb.tt +9 -0
  94. data/lib/archangel/commands/templates/theme/lib/%theme_name%/engine.rb.tt +29 -0
  95. data/lib/archangel/commands/templates/theme/lib/%theme_name%/version.rb.tt +5 -0
  96. data/lib/archangel/commands/templates/theme/theme.gemspec.tt +25 -0
  97. data/lib/archangel/commands/theme_command.rb +129 -0
  98. data/lib/archangel/config.rb +11 -2
  99. data/lib/archangel/liquid/drop.rb +26 -0
  100. data/lib/archangel/liquid/drops/page_drop.rb +1 -1
  101. data/lib/archangel/liquid/drops/site_drop.rb +1 -1
  102. data/lib/archangel/liquid/filters/link_to_filter.rb +1 -0
  103. data/lib/archangel/liquid/tags/application_tag.rb +18 -5
  104. data/lib/archangel/liquid/tags/collection_tag.rb +1 -1
  105. data/lib/archangel/liquid/tags/csrf_meta_tags_tag.rb +1 -0
  106. data/lib/archangel/liquid/tags/locale_tag.rb +1 -0
  107. data/lib/archangel/liquid/tags/meta_tags_tag.rb +1 -0
  108. data/lib/archangel/liquid/tags/noembed_tag.rb +140 -0
  109. data/lib/archangel/liquid/tags/text_direction_tag.rb +1 -0
  110. data/lib/archangel/liquid/tags/theme_javascript_tag.rb +1 -0
  111. data/lib/archangel/liquid/tags/theme_stylesheet_tag.rb +1 -0
  112. data/lib/archangel/testing_support/factories/archangel_assets.rb +2 -2
  113. data/lib/archangel/testing_support/factories/archangel_collections.rb +1 -1
  114. data/lib/archangel/testing_support/factories/archangel_entries.rb +1 -1
  115. data/lib/archangel/testing_support/factories/archangel_fields.rb +4 -4
  116. data/lib/archangel/testing_support/factories/archangel_metatags.rb +21 -0
  117. data/lib/archangel/testing_support/factories/archangel_pages.rb +5 -7
  118. data/lib/archangel/testing_support/factories/archangel_sites.rb +1 -3
  119. data/lib/archangel/testing_support/factories/archangel_templates.rb +7 -7
  120. data/lib/archangel/testing_support/factories/archangel_users.rb +10 -10
  121. data/lib/archangel/testing_support/factories/archangel_widgets.rb +2 -2
  122. data/lib/archangel/testing_support/matchers/have_meta.rb +18 -0
  123. data/lib/archangel/testing_support/matchers/have_title.rb +18 -0
  124. data/lib/archangel/testing_support/rake/dummy_rake.rb +0 -2
  125. data/lib/archangel/version.rb +1 -1
  126. data/lib/generators/archangel/install/templates/config/archangel.yml +52 -37
  127. data/spec/controllers/archangel/backend/entries_controller_spec.rb +3 -3
  128. data/spec/controllers/archangel/backend/pages_controller_spec.rb +17 -1
  129. data/spec/controllers/archangel/backend/profiles_controller_spec.rb +1 -1
  130. data/spec/controllers/archangel/backend/sites_controller_spec.rb +6 -6
  131. data/spec/controllers/archangel/backend/users_controller_spec.rb +2 -2
  132. data/spec/controllers/archangel/frontend/pages_controller_spec.rb +2 -6
  133. data/spec/controllers/concerns/archangel/controllers/backend/resourceful_concern_spec.rb +90 -0
  134. data/spec/features/auth/registration_spec.rb +18 -0
  135. data/spec/features/frontend/liquid_drop_variables_spec.rb +51 -57
  136. data/spec/features/frontend/pages/homepage_redirect_spec.rb +2 -2
  137. data/spec/features/frontend/pages/metatags_spec.rb +73 -0
  138. data/spec/helpers/archangel/flash_helper_spec.rb +14 -0
  139. data/spec/lib/archangel/{command/extension_spec.rb → commands/extension_command_spec.rb} +3 -3
  140. data/spec/lib/archangel/commands/theme_command_spec.rb +100 -0
  141. data/spec/lib/archangel/liquid/drops/page_drop_spec.rb +1 -9
  142. data/spec/lib/archangel/liquid/drops/site_drop_spec.rb +2 -12
  143. data/spec/lib/archangel/liquid/tags/noembed_tag_spec.rb +76 -0
  144. data/spec/mailers/archangel/{application_job_spec.rb → application_mailer_spec.rb} +0 -0
  145. data/spec/models/archangel/metatag_spec.rb +22 -0
  146. data/spec/models/archangel/page_spec.rb +5 -2
  147. data/spec/models/archangel/site_spec.rb +2 -0
  148. data/spec/rails_helper.rb +1 -0
  149. data/spec/uploaders/archangel/application_uploader_spec.rb +1 -1
  150. data/spec/uploaders/archangel/asset_uploader_spec.rb +1 -1
  151. metadata +108 -93
  152. data/.reek +0 -44
  153. data/lib/archangel/command/extension.rb +0 -97
@@ -9,190 +9,7 @@ module Archangel
9
9
  # Backend collections controller
10
10
  #
11
11
  class CollectionsController < BackendController
12
- before_action :set_resources, only: %i[index]
13
- before_action :set_resource, only: %i[destroy edit show update]
14
- before_action :set_new_resource, only: %i[create new]
15
-
16
- ##
17
- # Backend collections
18
- #
19
- # Formats
20
- # HTML, JSON
21
- #
22
- # Request
23
- # GET /backend/collections
24
- # GET /backend/collections.json
25
- #
26
- # Response
27
- # [
28
- # {
29
- # "id": 123,
30
- # "site_id": 123,
31
- # "name": "Collection Name",
32
- # "slug": "collection_slug",
33
- # "deleted_at": null,
34
- # "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
35
- # "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
36
- # },
37
- # ...
38
- # ]
39
- #
40
- def index
41
- respond_with @collections
42
- end
43
-
44
- ##
45
- # Backend collection
46
- #
47
- # Formats
48
- # HTML, JSON
49
- #
50
- # Params
51
- # [String] slug - the collection slug
52
- #
53
- # Request
54
- # GET /backend/collections/:slug
55
- # GET /backend/collections/:slug.json
56
- #
57
- # Response
58
- # {
59
- # "id": 123,
60
- # "site_id": 123,
61
- # "name": "Collection Name",
62
- # "slug": "collection_slug",
63
- # "deleted_at": null,
64
- # "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
65
- # "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
66
- # }
67
- #
68
- def show
69
- respond_with @collection
70
- end
71
-
72
- ##
73
- # New backend collection
74
- #
75
- # Formats
76
- # HTML, JSON
77
- #
78
- # Request
79
- # GET /backend/collections/new
80
- # GET /backend/collections/new.json
81
- #
82
- # Response
83
- # {
84
- # "id": null,
85
- # "site_id": 123,
86
- # "name": null,
87
- # "slug": null,
88
- # "deleted_at": null,
89
- # "created_at": null,
90
- # "updated_at": null
91
- # }
92
- #
93
- def new
94
- respond_with @collection
95
- end
96
-
97
- ##
98
- # Create backend collection
99
- #
100
- # Formats
101
- # HTML, JSON
102
- #
103
- # Request
104
- # POST /backend/collections
105
- # POST /backend/collections.json
106
- #
107
- # Paramaters
108
- # {
109
- # "collection": {
110
- # "name": "Collection Name",
111
- # "slug": "collection_slug"
112
- # }
113
- # }
114
- #
115
- def create
116
- @collection.save
117
-
118
- respond_with @collection, location: -> { location_after_create }
119
- end
120
-
121
- ##
122
- # Edit backend collection
123
- #
124
- # Formats
125
- # HTML, JSON
126
- #
127
- # Params
128
- # [String] slug - the collection slug
129
- #
130
- # Request
131
- # GET /backend/collections/:slug/edit
132
- # GET /backend/collections/:slug/edit.json
133
- #
134
- # Response
135
- # {
136
- # "id": 123,
137
- # "site_id": 123,
138
- # "name": "Collection Name",
139
- # "slug": "collection_slug",
140
- # "deleted_at": null,
141
- # "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
142
- # "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
143
- # }
144
- #
145
- def edit
146
- respond_with @collection
147
- end
148
-
149
- ##
150
- # Update backend collection
151
- #
152
- # Formats
153
- # HTML, JSON
154
- #
155
- # Params
156
- # [String] slug - the collection slug
157
- #
158
- # Request
159
- # PATCH /backend/collections/:slug
160
- # PATCH /backend/collections/:slug.json
161
- # PUT /backend/collections/:slug
162
- # PUT /backend/collections/:slug.json
163
- #
164
- # Response
165
- # {
166
- # "collection": {
167
- # "name": "Collection Name",
168
- # "slug": "collection_slug"
169
- # }
170
- # }
171
- #
172
- def update
173
- @collection.update(resource_params)
174
-
175
- respond_with @collection, location: -> { location_after_update }
176
- end
177
-
178
- ##
179
- # Destroy backend collection
180
- #
181
- # Formats
182
- # HTML, JSON
183
- #
184
- # Params
185
- # [String] slug - the collection slug
186
- #
187
- # Request
188
- # DELETE /backend/collections/:slug
189
- # DELETE /backend/collections/:slug.json
190
- #
191
- def destroy
192
- @collection.destroy
193
-
194
- respond_with @collection, location: -> { location_after_destroy }
195
- end
12
+ include Archangel::Controllers::Backend::ResourcefulConcern
196
13
 
197
14
  protected
198
15
 
@@ -203,7 +20,7 @@ module Archangel
203
20
  ]
204
21
  end
205
22
 
206
- def set_resources
23
+ def resources_content
207
24
  @collections = current_site.collections
208
25
  .order(name: :asc)
209
26
  .page(page_num).per(per_page)
@@ -211,7 +28,7 @@ module Archangel
211
28
  authorize @collections
212
29
  end
213
30
 
214
- def set_resource
31
+ def resource_content
215
32
  resource_id = params.fetch(:id)
216
33
 
217
34
  @collection = current_site.collections.find_by!(slug: resource_id)
@@ -219,39 +36,13 @@ module Archangel
219
36
  authorize @collection
220
37
  end
221
38
 
222
- def set_new_resource
223
- new_params = action_name.to_sym == :create ? resource_params : nil
224
-
225
- @collection = current_site.collections.new(new_params)
39
+ def resource_new_content
40
+ @collection = current_site.collections.new(resource_new_params)
226
41
 
227
42
  @collection.fields.build unless @collection.fields.present?
228
43
 
229
44
  authorize @collection
230
45
  end
231
-
232
- def resource_params
233
- params.require(resource_namespace).permit(permitted_attributes)
234
- end
235
-
236
- def resource_namespace
237
- controller_name.singularize.to_sym
238
- end
239
-
240
- def location_after_create
241
- location_after_save
242
- end
243
-
244
- def location_after_update
245
- location_after_save
246
- end
247
-
248
- def location_after_destroy
249
- location_after_save
250
- end
251
-
252
- def location_after_save
253
- backend_collections_path
254
- end
255
46
  end
256
47
  end
257
48
  end
@@ -9,215 +9,7 @@ module Archangel
9
9
  # Backend collection entries controller
10
10
  #
11
11
  class EntriesController < BackendController
12
- before_action :set_parent_resource
13
- before_action :set_resources, only: %i[index]
14
- before_action :set_resource, only: %i[destroy edit show update]
15
- before_action :set_new_resource, only: %i[create new]
16
-
17
- ##
18
- # Backend collection entries
19
- #
20
- # Formats
21
- # HTML, JSON
22
- #
23
- # Request
24
- # GET /backend/collections/:slug/entries/:id
25
- # GET /backend/collections/:slug/entries/:id.json
26
- #
27
- # Response
28
- # [
29
- # {
30
- # "id": 123,
31
- # "collection_id": 123,
32
- # "value": {
33
- # "field_key_1": "Field 1 Value",
34
- # "field_key_2": "Field 2 Value"
35
- # },
36
- # "position": 0,
37
- # "available_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
38
- # "deleted_at": null,
39
- # "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
40
- # "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
41
- # },
42
- # ...
43
- # ]
44
- #
45
- def index
46
- respond_with @entries
47
- end
48
-
49
- ##
50
- # Backend collection entry
51
- #
52
- # Formats
53
- # HTML, JSON
54
- #
55
- # Params
56
- # [String] slug - the collection slug
57
- # [Integer] id - the entry id
58
- #
59
- # Request
60
- # GET /backend/collections/:slug/entries/:id
61
- # GET /backend/collections/:slug/entries/:id.json
62
- #
63
- # Response
64
- # {
65
- # "id": 123,
66
- # "collection_id": 123,
67
- # "value": {
68
- # "field_key_1": "Field 1 Value",
69
- # "field_key_2": "Field 2 Value"
70
- # },
71
- # "position": 0,
72
- # "available_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
73
- # "deleted_at": null,
74
- # "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
75
- # "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
76
- # }
77
- #
78
- def show
79
- respond_with @entry
80
- end
81
-
82
- ##
83
- # New backend collection entry
84
- #
85
- # Formats
86
- # HTML, JSON
87
- #
88
- # Request
89
- # GET /backend/collections/:slug/entries/new
90
- # GET /backend/collections/:slug/entries/new.json
91
- #
92
- # Response
93
- # {
94
- # "id": null,
95
- # "collection_id": null,
96
- # "value": null,
97
- # "position": null,
98
- # "available_at": null,
99
- # "deleted_at": null,
100
- # "created_at": null,
101
- # "updated_at": null
102
- # }
103
- #
104
- def new
105
- respond_with @entry
106
- end
107
-
108
- ##
109
- # Create backend collection entry
110
- #
111
- # Formats
112
- # HTML, JSON
113
- #
114
- # Params
115
- # [String] slug - the collection slug
116
- #
117
- # Request
118
- # POST /backend/collections/:slug/entries
119
- # POST /backend/collections/:slug/entries.json
120
- #
121
- # Paramaters
122
- # {
123
- # "collection_entry": {
124
- # "value": {
125
- # "field_key_1": "Field 1 Value",
126
- # "field_key_2": "Field 2 Value"
127
- # },
128
- # "available_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
129
- # }
130
- # }
131
- #
132
- def create
133
- @entry.save
134
-
135
- respond_with @entry, location: -> { location_after_create }
136
- end
137
-
138
- ##
139
- # Edit backend collection entry
140
- #
141
- # Formats
142
- # HTML, JSON
143
- #
144
- # Params
145
- # [String] slug - the collection slug
146
- # [Integer] id - the entry id
147
- #
148
- # Request
149
- # GET /backend/collections/:slug/entries/:id/edit
150
- # GET /backend/collections/:slug/entries/:id/edit.json
151
- #
152
- # Response
153
- # {
154
- # "id": 123,
155
- # "site_id": 123,
156
- # "name": "Widget Name",
157
- # slug": "widget_slug",
158
- # "content": "</p>Content of the Widget</p>",
159
- # "template_id": 123,
160
- # "deleted_at": null,
161
- # "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
162
- # "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
163
- # }
164
- #
165
- def edit
166
- respond_with @entry
167
- end
168
-
169
- ##
170
- # Update backend collection entry
171
- #
172
- # Formats
173
- # HTML, JSON
174
- #
175
- # Params
176
- # [String] slug - the collection slug
177
- # [Integer] id - the entry id
178
- #
179
- # Request
180
- # PATCH /backend/collections/:slug/entries/:id
181
- # PATCH /backend/collections/:slug/entries/:id.json
182
- # PUT /backend/collections/:slug/entries/:id
183
- # PUT /backend/collections/:slug/entries/:id.json
184
- #
185
- # Paramaters
186
- # {
187
- # "collection_entry": {
188
- # "value": {
189
- # "field_key_1": "Field 1 Value",
190
- # "field_key_2": "Field 2 Value"
191
- # },
192
- # "available_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
193
- # }
194
- # }
195
- #
196
- def update
197
- @entry.update(resource_params)
198
-
199
- respond_with @entry, location: -> { location_after_update }
200
- end
201
-
202
- ##
203
- # Destroy backend collection entry
204
- #
205
- # Formats
206
- # HTML, JSON
207
- #
208
- # Params
209
- # [String] slug - the collection slug
210
- # [Integer] id - the entry id
211
- #
212
- # Request
213
- # DELETE /backend/collections/:slug/entries/:id
214
- # DELETE /backend/collections/:slug/entries/:id.json
215
- #
216
- def destroy
217
- @entry.destroy
218
-
219
- respond_with @entry, location: -> { location_after_destroy }
220
- end
12
+ include Archangel::Controllers::Backend::ResourcefulConcern
221
13
 
222
14
  ##
223
15
  # Update collection entry sort order
@@ -240,6 +32,8 @@ module Archangel
240
32
  # }
241
33
  #
242
34
  def sort
35
+ parent_resource_content
36
+
243
37
  sort_order = sort_resource_params.fetch(:sort)
244
38
 
245
39
  ApplicationRecord.transaction do
@@ -274,14 +68,28 @@ module Archangel
274
68
  ]
275
69
  end
276
70
 
277
- def set_parent_resource
71
+ def resource_params
72
+ params.require(resource_namespace)
73
+ .permit(permitted_attributes)
74
+ .merge(collection_id: @collection.id)
75
+ end
76
+
77
+ def sort_resource_params
78
+ params.clone
79
+ .require(resource_namespace)
80
+ .permit(permitted_sort_attributes)
81
+ end
82
+
83
+ def parent_resource_content
278
84
  collection_id = params.fetch(:collection_id)
279
85
 
280
86
  @collection = current_site.collections
281
87
  .find_by!(slug: collection_id)
282
88
  end
283
89
 
284
- def set_resources
90
+ def resources_content
91
+ parent_resource_content
92
+
285
93
  @entries = current_site.entries
286
94
  .where(collection: @collection)
287
95
  .page(page_num)
@@ -290,7 +98,9 @@ module Archangel
290
98
  authorize @entries
291
99
  end
292
100
 
293
- def set_resource
101
+ def resource_content
102
+ parent_resource_content
103
+
294
104
  resource_id = params.fetch(:id)
295
105
 
296
106
  @entry = current_site.entries
@@ -300,42 +110,18 @@ module Archangel
300
110
  authorize @entry
301
111
  end
302
112
 
303
- def set_new_resource
304
- new_params = action_name.to_sym == :create ? resource_params : nil
113
+ def resource_new_content
114
+ parent_resource_content
305
115
 
306
- @entry = current_site.entries.new(new_params)
116
+ @entry = current_site.entries.new(resource_new_params)
307
117
 
308
118
  authorize @entry
309
119
  end
310
120
 
311
- def resource_params
312
- params.require(resource_namespace)
313
- .permit(permitted_attributes)
314
- .merge(collection_id: @collection.id)
315
- end
316
-
317
- def sort_resource_params
318
- params.clone
319
- .require(resource_namespace)
320
- .permit(permitted_sort_attributes)
321
- end
322
-
323
121
  def resource_namespace
324
122
  :collection_entry
325
123
  end
326
124
 
327
- def location_after_create
328
- location_after_save
329
- end
330
-
331
- def location_after_update
332
- location_after_save
333
- end
334
-
335
- def location_after_destroy
336
- location_after_save
337
- end
338
-
339
125
  def location_after_save
340
126
  backend_collection_entries_path(@collection)
341
127
  end