geoblacklight_admin 0.5.0 → 0.6.0

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.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -11
  3. data/Rakefile +83 -47
  4. data/app/assets/javascripts/geoblacklight_admin/chosen.js +1 -0
  5. data/app/assets/stylesheets/geoblacklight_admin/_core.scss +24 -0
  6. data/app/assets/stylesheets/geoblacklight_admin/modules/_nav.scss +0 -5
  7. data/app/assets/stylesheets/geoblacklight_admin/modules/_tables.scss +1 -1
  8. data/app/controllers/admin/admin_controller.rb +16 -0
  9. data/app/controllers/admin/advanced_search_controller.rb +7 -1
  10. data/app/controllers/admin/assets_controller.rb +47 -32
  11. data/app/controllers/admin/bookmarks_controller.rb +17 -5
  12. data/app/controllers/admin/bulk_actions_controller.rb +32 -1
  13. data/app/controllers/admin/document_accesses_controller.rb +38 -0
  14. data/app/controllers/admin/document_assets_controller.rb +47 -89
  15. data/app/controllers/admin/document_distributions_controller.rb +172 -0
  16. data/app/controllers/admin/documents_controller.rb +43 -57
  17. data/app/controllers/admin/elements_controller.rb +24 -0
  18. data/app/controllers/admin/form_elements_controller.rb +33 -0
  19. data/app/controllers/admin/ids_controller.rb +6 -0
  20. data/app/controllers/admin/import_documents_controller.rb +11 -1
  21. data/app/controllers/admin/imports_controller.rb +34 -4
  22. data/app/controllers/admin/mappings_controller.rb +15 -0
  23. data/app/controllers/admin/notifications_controller.rb +27 -0
  24. data/app/controllers/admin/reference_types_controller.rb +106 -0
  25. data/app/controllers/admin/search_controller.rb +7 -0
  26. data/app/controllers/admin/users_controller.rb +10 -0
  27. data/app/helpers/asset_helper.rb +6 -0
  28. data/app/helpers/bulk_actions_helper.rb +10 -1
  29. data/app/helpers/document_helper.rb +36 -0
  30. data/app/helpers/geoblacklight_admin_helper.rb +88 -8
  31. data/app/helpers/mappings_helper.rb +26 -0
  32. data/app/indexers/document_indexer.rb +22 -2
  33. data/app/javascript/channels/consumer.js +6 -0
  34. data/app/javascript/channels/export_channel.js +30 -0
  35. data/app/javascript/channels/index.js +3 -0
  36. data/app/javascript/controllers/results_controller.js +14 -0
  37. data/app/javascript/index.js +8 -2
  38. data/app/jobs/bulk_action_revert_document_job.rb +4 -12
  39. data/app/jobs/bulk_action_run_document_job.rb +2 -10
  40. data/app/jobs/export_job.rb +35 -8
  41. data/app/jobs/geoblacklight_admin/delete_thumbnail_job.rb +19 -0
  42. data/app/jobs/geoblacklight_admin/remove_parent_dct_references_uri_job.rb +16 -0
  43. data/app/jobs/geoblacklight_admin/set_parent_dct_references_uri_job.rb +17 -0
  44. data/app/jobs/geoblacklight_admin/store_image_job.rb +22 -0
  45. data/app/jobs/import_document_job.rb +1 -4
  46. data/app/jobs/import_run_job.rb +1 -1
  47. data/app/models/admin/bookmark.rb +1 -1
  48. data/app/models/asset.rb +20 -0
  49. data/app/models/bulk_action.rb +2 -1
  50. data/app/models/bulk_actions/change_publication_state.rb +0 -25
  51. data/app/models/bulk_actions/delete_thumbnails.rb +6 -0
  52. data/app/models/bulk_actions/draft_document.rb +6 -0
  53. data/app/models/bulk_actions/harvest_thumbnails.rb +6 -0
  54. data/app/models/bulk_actions/publish_document.rb +6 -0
  55. data/app/models/bulk_actions/unpublish_document.rb +6 -0
  56. data/app/models/document/geom_validator.rb +8 -0
  57. data/app/models/document/reference.rb +65 -65
  58. data/app/models/document.rb +129 -72
  59. data/app/models/document_distribution.rb +145 -0
  60. data/app/models/element.rb +2 -0
  61. data/app/models/geoblacklight_admin/schema.rb +10 -2
  62. data/app/models/import/csv_duplicates_validator.rb +2 -0
  63. data/app/models/import/csv_header_validator.rb +3 -1
  64. data/app/models/import_btaa_aardvark.rb +2 -2
  65. data/app/models/import_document_state_machine.rb +1 -0
  66. data/app/models/import_gblv1.rb +2 -2
  67. data/app/models/reference_type.rb +40 -0
  68. data/app/models/user.rb +4 -2
  69. data/app/services/export_csv_document_distributions_service.rb +61 -0
  70. data/app/services/geoblacklight_admin/image_service/iiif_manifest.rb +39 -43
  71. data/app/services/geoblacklight_admin/image_service/tms.rb +0 -8
  72. data/app/services/geoblacklight_admin/image_service.rb +1 -1
  73. data/app/services/geoblacklight_admin/item_viewer.rb +4 -4
  74. data/app/views/admin/bookmarks/index.html.erb +19 -14
  75. data/app/views/admin/bulk_actions/show.html.erb +1 -1
  76. data/app/views/admin/document_accesses/import.html.erb +6 -2
  77. data/app/views/admin/document_assets/_assets_table.html.erb +49 -0
  78. data/app/views/admin/document_assets/_form.html.erb +2 -3
  79. data/app/views/admin/document_assets/index.html.erb +1 -47
  80. data/app/views/admin/document_distributions/_document_distribution.html.erb +39 -0
  81. data/app/views/admin/document_distributions/_document_distribution.json.jbuilder +2 -0
  82. data/app/views/admin/document_distributions/_form.html.erb +34 -0
  83. data/app/views/admin/document_distributions/destroy_all.html.erb +82 -0
  84. data/app/views/admin/document_distributions/edit.html.erb +12 -0
  85. data/app/views/admin/document_distributions/import.html.erb +80 -0
  86. data/app/views/admin/document_distributions/index.html.erb +143 -0
  87. data/app/views/admin/document_distributions/index.json.jbuilder +1 -0
  88. data/app/views/admin/document_distributions/new.html.erb +11 -0
  89. data/app/views/admin/document_distributions/show.html.erb +10 -0
  90. data/app/views/admin/document_distributions/show.json.jbuilder +1 -0
  91. data/app/views/admin/documents/_document.html.erb +1 -3
  92. data/app/views/admin/documents/_form.html.erb +2 -4
  93. data/app/views/admin/documents/_form_control.html.erb +5 -2
  94. data/app/views/admin/documents/_form_nav.html.erb +14 -5
  95. data/app/views/admin/documents/_form_nav_kithe.html.erb +4 -1
  96. data/app/views/admin/documents/_json_aardvark.jbuilder +1 -1
  97. data/app/views/admin/documents/_json_gbl_v1.jbuilder +1 -1
  98. data/app/views/admin/documents/_result_selected_options.html.erb +5 -2
  99. data/app/views/admin/documents/admin.html.erb +5 -5
  100. data/app/views/admin/documents/features/_document_references.html.erb +23 -0
  101. data/app/views/admin/documents/features/_multiple_download_links.html.erb +29 -26
  102. data/app/views/admin/ids/fetch.json.jbuilder +0 -2
  103. data/app/views/admin/ids/index.json.jbuilder +0 -2
  104. data/app/views/admin/imports/_form.html.erb +1 -1
  105. data/app/views/admin/imports/show.html.erb +1 -1
  106. data/app/views/admin/layouts/application.html.erb +4 -2
  107. data/app/views/admin/mappings/index.html.erb +1 -1
  108. data/app/views/admin/notifications/_notification.html.haml +29 -28
  109. data/app/views/admin/reference_types/_form.html.erb +25 -0
  110. data/app/views/admin/reference_types/_reference_type.html.erb +52 -0
  111. data/app/views/admin/reference_types/_reference_type.json.jbuilder +2 -0
  112. data/app/views/admin/reference_types/edit.html.erb +12 -0
  113. data/app/views/admin/reference_types/index.html.erb +52 -0
  114. data/app/views/admin/reference_types/index.json.jbuilder +1 -0
  115. data/app/views/admin/reference_types/new.html.erb +11 -0
  116. data/app/views/admin/reference_types/show.html.erb +3 -0
  117. data/app/views/admin/reference_types/show.json.jbuilder +1 -0
  118. data/app/views/admin/shared/_footer.html.erb +5 -2
  119. data/app/views/admin/shared/_js_behaviors.html.erb +2 -3
  120. data/app/views/admin/shared/_navbar.html.erb +9 -2
  121. data/app/views/admin/users/index.html.erb +0 -1
  122. data/app/views/catalog/_show_gbl_admin.html.erb +1 -1
  123. data/config/initializers/defaults.yml +310 -0
  124. data/config/initializers/rails_config.rb +8 -0
  125. data/config/locales/documents.en.yml +14 -0
  126. data/config/routes.rb +30 -5
  127. data/db/import_references_schema_support.numbers +0 -0
  128. data/db/migrate/20230316183001_add_geoblacklight_admin_gem.rb +0 -12
  129. data/db/migrate/20241009200524_create_admin_reference_types.rb +13 -0
  130. data/db/migrate/20241010161420_create_document_references.rb +14 -0
  131. data/db/migrate/20241120238823_rename_references_to_distributions.rb +5 -0
  132. data/db/seeds.rb +5 -0
  133. data/db/seeds_elements.csv +1 -1
  134. data/db/seeds_elements.numbers +0 -0
  135. data/db/seeds_reference_types.csv +29 -0
  136. data/db/seeds_reference_types.numbers +0 -0
  137. data/db/structure.sql +1 -38
  138. data/lib/compose.yml +31 -0
  139. data/lib/generators/geoblacklight_admin/config_generator.rb +53 -12
  140. data/lib/generators/geoblacklight_admin/install_generator.rb +8 -0
  141. data/lib/generators/geoblacklight_admin/templates/btaa_sample_records.csv +5 -0
  142. data/lib/generators/geoblacklight_admin/templates/config/database.yml +1 -1
  143. data/lib/generators/geoblacklight_admin/templates/config/initializers/devise.rb +0 -2
  144. data/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb +1 -0
  145. data/lib/generators/geoblacklight_admin/templates/demo-app/Dockerfile +31 -0
  146. data/lib/generators/geoblacklight_admin/templates/demo-app/compose.yml +42 -0
  147. data/lib/generators/geoblacklight_admin/templates/demo-app/start-server.sh +21 -0
  148. data/lib/geoblacklight_admin/engine.rb +4 -0
  149. data/lib/geoblacklight_admin/rake_task.rb +2 -0
  150. data/lib/geoblacklight_admin/tasks/distributions.rake +69 -0
  151. data/lib/geoblacklight_admin/tasks/images.rake +1 -0
  152. data/lib/geoblacklight_admin/tasks/solr.rake +31 -0
  153. data/lib/geoblacklight_admin/version.rb +1 -1
  154. data/lib/geoblacklight_admin.rb +4 -0
  155. metadata +137 -53
  156. data/app/helpers/import_documents_helper.rb +0 -5
  157. data/app/javascript/entrypoints/engine.js +0 -8
  158. data/config/locales/devise_invitable.en.yml +0 -31
  159. data/lib/generators/geoblacklight_admin/templates/devise/invitations/edit.html.erb +0 -15
  160. data/lib/generators/geoblacklight_admin/templates/devise/invitations/new.html.erb +0 -15
  161. data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.html.erb +0 -11
  162. data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.text.erb +0 -11
@@ -1,17 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::DocumentsController
4
+ # This controller handles the management of documents within the admin interface.
5
+ # It provides actions to list, create, update, and delete documents, as well as
6
+ # export them in various formats.
4
7
  module Admin
5
8
  class DocumentsController < Admin::AdminController
9
+ # Allow all parameters (not recommended for production use)
6
10
  ActionController::Parameters.permit_all_parameters = true
7
- before_action :set_document,
8
- only: %i[show edit update destroy admin versions]
11
+
12
+ # Set the document before certain actions
13
+ before_action :set_document, only: %i[show edit update destroy admin versions]
9
14
 
10
15
  # GET /documents
11
16
  # GET /documents.json
17
+ # Lists all documents with support for various export formats.
12
18
  def index
19
+ # Construct the request URL
13
20
  @request = "#{request.protocol}#{request.host}:#{request.port}"
14
21
 
22
+ # Define query parameters for the document search
15
23
  query_params = {
16
24
  q: params["q"],
17
25
  f: params["f"],
@@ -22,56 +30,47 @@ module Admin
22
30
  }
23
31
  @documents = BlacklightApi.new(@request, **query_params)
24
32
 
33
+ # Respond to different formats
25
34
  respond_to do |format|
26
35
  format.html { render :index }
27
36
  format.json { render json: @documents.results.to_json }
28
-
29
- # JSON - BTAA Aardvark
30
37
  format.json_btaa_aardvark do
31
- ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_btaa_aardvark"}),
32
- ExportJsonService)
38
+ ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_btaa_aardvark"}), ExportJsonService)
33
39
  head :no_content
34
40
  end
35
-
36
- # JSON - GBL Aardvark
37
41
  format.json_aardvark do
38
42
  ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_aardvark"}), ExportJsonService)
39
43
  head :no_content
40
44
  end
41
-
42
- # JSON - GBL v1
43
45
  format.json_gbl_v1 do
44
46
  ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_gbl_v1"}), ExportJsonService)
45
47
  head :no_content
46
48
  end
47
-
48
- # JSON - FILE
49
49
  format.json_file do
50
50
  ExportJsonBulkJob.perform_later(@request, current_user, query_params.merge!({format: "json_file"}), ExportJsonService)
51
51
  head :no_content
52
52
  end
53
-
54
- # CSV - B1G
55
53
  format.csv do
56
54
  ExportJob.perform_later(@request, current_user, query_params, ExportCsvService)
57
55
  head :no_content
58
56
  end
59
-
60
- # CSV Document Downloads - B1G
61
57
  format.csv_document_downloads do
62
58
  ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentDownloadsService)
63
59
  head :no_content
64
60
  end
65
-
66
- # CSV Document Access Links - B1G
67
61
  format.csv_document_access_links do
68
62
  ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentAccessLinksService)
69
63
  head :no_content
70
64
  end
65
+ format.csv_document_distributions do
66
+ ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentDistributionsService)
67
+ head :no_content
68
+ end
71
69
  end
72
70
  end
73
71
 
74
- # Fetch documents from array of friendlier_ids
72
+ # Fetch documents from an array of friendlier_ids
73
+ # This action retrieves documents based on their friendlier IDs.
75
74
  def fetch
76
75
  @request = "#{request.protocol}#{request.host}:#{request.port}"
77
76
  @documents = Document.where(friendlier_id: params["ids"])
@@ -79,71 +78,62 @@ module Admin
79
78
  respond_to do |format|
80
79
  format.html { render :index }
81
80
  format.json { render json: @documents.to_json }
82
-
83
- # JSON - BTAA Aardvark
84
81
  format.json_btaa_aardvark do
85
- ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_btaa_aardvark"},
86
- ExportJsonService)
82
+ ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_btaa_aardvark"}, ExportJsonService)
87
83
  head :no_content
88
84
  end
89
-
90
- # JSON - GBL Aardvark
91
85
  format.json_aardvark do
92
- ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_aardvark"},
93
- ExportJsonService)
86
+ ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_aardvark"}, ExportJsonService)
94
87
  head :no_content
95
88
  end
96
-
97
- # JSON - GBL v1
98
89
  format.json_gbl_v1 do
99
- ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_gbl_v1"},
100
- ExportJsonService)
90
+ ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_gbl_v1"}, ExportJsonService)
101
91
  head :no_content
102
92
  end
103
-
104
- # CSV - B1G
105
93
  format.csv do
106
- ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv"},
107
- ExportCsvService)
94
+ ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv"}, ExportCsvService)
108
95
  head :no_content
109
96
  end
110
-
111
- # CSV Document Downloads - B1G
112
97
  format.csv_document_downloads do
113
- ExportJob.perform_later(@request, current_user,
114
- {ids: @documents.pluck(:friendlier_id), format: "csv_document_downloads"}, ExportCsvDocumentDownloadsService)
98
+ ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_downloads"}, ExportCsvDocumentDownloadsService)
115
99
  head :no_content
116
100
  end
117
-
118
- # CSV Document Downloads - B1G
119
101
  format.csv_document_access_links do
120
- ExportJob.perform_later(@request, current_user,
121
- {ids: @documents.pluck(:friendlier_id), format: "csv_document_access_links"}, ExportCsvDocumentAccessLinksService)
102
+ ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_access_links"}, ExportCsvDocumentAccessLinksService)
103
+ head :no_content
104
+ end
105
+ format.csv_document_distributions do
106
+ ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_distributions"}, ExportCsvDocumentDistributionsService)
122
107
  head :no_content
123
108
  end
124
109
  end
125
110
  end
126
111
 
127
112
  # GET /documents/new
113
+ # Renders a form for creating a new document.
128
114
  def new
129
115
  @document = Document.new
130
116
  render :edit
131
117
  end
132
118
 
133
119
  # GET /documents/1/edit
120
+ # Renders a form for editing an existing document.
134
121
  def edit
135
122
  end
136
123
 
137
124
  # GET /documents/1/admin
125
+ # Admin view for a specific document.
138
126
  def admin
139
127
  end
140
128
 
141
129
  # GET /documents/1/versions
130
+ # Displays the version history of a document.
142
131
  def versions
143
132
  end
144
133
 
145
134
  # POST /documents
146
135
  # POST /documents.json
136
+ # Creates a new document with the provided parameters.
147
137
  def create
148
138
  @document = Document.new(document_params)
149
139
  @document.friendlier_id = @document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:id])
@@ -152,7 +142,7 @@ module Admin
152
142
  format.html { redirect_to edit_admin_document_path(@document), notice: "Document was successfully created." }
153
143
  format.json { render :show, status: :created, location: @document }
154
144
  else
155
- format.html { render :edit }
145
+ format.html { render :edit, status: :unprocessable_entity }
156
146
  format.json { render json: @document.errors, status: :unprocessable_entity }
157
147
  end
158
148
  end
@@ -160,13 +150,14 @@ module Admin
160
150
 
161
151
  # PATCH/PUT /documents/1
162
152
  # PATCH/PUT /documents/1.json
153
+ # Updates an existing document with the provided parameters.
163
154
  def update
164
155
  respond_to do |format|
165
156
  if @document.update(document_params)
166
157
  format.html { redirect_to edit_admin_document_path(@document), notice: "Document was successfully updated." }
167
158
  format.json { render :show, status: :ok, location: @document }
168
159
  else
169
- format.html { render :edit }
160
+ format.html { render :edit, status: :unprocessable_entity }
170
161
  format.json { render json: @document.errors, status: :unprocessable_entity }
171
162
  end
172
163
  end
@@ -174,6 +165,7 @@ module Admin
174
165
 
175
166
  # DELETE /documents/1
176
167
  # DELETE /documents/1.json
168
+ # Deletes a document.
177
169
  def destroy
178
170
  @document.destroy
179
171
  respond_to do |format|
@@ -184,6 +176,8 @@ module Admin
184
176
  end
185
177
  end
186
178
 
179
+ # GET /documents/1
180
+ # Shows a document in various formats.
187
181
  def show
188
182
  respond_to do |format|
189
183
  format.html { redirect_to edit_admin_document_url(@document) }
@@ -191,37 +185,29 @@ module Admin
191
185
  format.json_aardvark
192
186
  format.json_btaa_aardvark
193
187
  format.json_gbl_v1
194
- # B1G CSV
195
188
  format.csv { send_data collect_csv([@document]), filename: "documents-#{Time.zone.today}.csv" }
196
-
197
- # @TODO:
198
- # geoblacklight_version: 1.0 (strict)
199
- # geoblacklight_version: 1.0 + B1G customizations
200
- # geoblacklight_version: 2.0 (strict)
201
- # geoblacklight_version: 2.0 + B1G customizations
202
189
  end
203
190
  end
204
191
 
205
192
  private
206
193
 
207
194
  # Use callbacks to share common setup or constraints between actions.
195
+ # Finds and sets the document based on the friendlier_id.
208
196
  def set_document
209
197
  @document = Document.includes(:leaf_representative).find_by!(friendlier_id: params[:id] || params[:document_id])
210
198
  end
211
199
 
212
- # only allow whitelisted params through (TODO, we're allowing all document params!)
213
- # Plus sanitization or any other mutation.
214
- #
215
- # This could be done in a form object or otherwise abstracted, but this is good
216
- # enough for now.
200
+ # Defines the list of permitted parameters for document creation and updates.
217
201
  def permittable_params
218
202
  %i[title publication_state layer_geom_type_s dct_references_s q f page sort rows daterange]
219
203
  end
220
204
 
205
+ # Strong parameters for document creation and updates.
221
206
  def document_params
222
207
  Kithe::Parameters.new(params).require(:document).permit_attr_json(Document).permit(permittable_params)
223
208
  end
224
209
 
210
+ # Collects documents into a CSV format.
225
211
  def collect_csv(documents)
226
212
  CSV.generate(headers: true) do |csv|
227
213
  csv << GeoblacklightAdmin::Schema.instance.exportable_fields.map { |k, _v| k.to_s }
@@ -1,29 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::ElementsController
4
+ # This controller manages the CRUD operations for elements within the admin namespace.
5
+ # It includes actions for listing, showing, creating, updating, and deleting elements.
6
+ # Additionally, it provides a custom action for sorting elements.
4
7
  module Admin
5
8
  class ElementsController < Admin::AdminController
6
9
  before_action :set_element, only: %i[show edit update destroy]
7
10
 
8
11
  # GET /elements or /elements.json
12
+ # Lists all elements, ordered by position in ascending order.
13
+ # Uses pagination to limit the number of elements displayed per page.
9
14
  def index
10
15
  @pagy, @elements = pagy(Element.all.order(position: :asc), items: 100)
11
16
  end
12
17
 
13
18
  # GET /elements/1 or /elements/1.json
19
+ # Displays a specific element.
14
20
  def show
15
21
  end
16
22
 
17
23
  # GET /elements/new
24
+ # Initializes a new element object.
18
25
  def new
19
26
  @element = Element.new
20
27
  end
21
28
 
22
29
  # GET /elements/1/edit
30
+ # Prepares an element for editing.
23
31
  def edit
24
32
  end
25
33
 
26
34
  # POST /elements or /elements.json
35
+ # Creates a new element with the provided parameters.
36
+ # If successful, redirects to the element's show page with a success notice.
37
+ # If unsuccessful, re-renders the new element form with error messages.
27
38
  def create
28
39
  @element = Element.new(element_params)
29
40
 
@@ -39,6 +50,9 @@ module Admin
39
50
  end
40
51
 
41
52
  # PATCH/PUT /elements/1 or /elements/1.json
53
+ # Updates an existing element with the provided parameters.
54
+ # If successful, redirects to the element's show page with a success notice.
55
+ # If unsuccessful, re-renders the edit form with error messages.
42
56
  def update
43
57
  respond_to do |format|
44
58
  if @element.update(element_params)
@@ -52,6 +66,8 @@ module Admin
52
66
  end
53
67
 
54
68
  # DELETE /elements/1 or /elements/1.json
69
+ # Deletes a specific element.
70
+ # Redirects to the elements index page with a success notice.
55
71
  def destroy
56
72
  @element.destroy
57
73
 
@@ -61,6 +77,9 @@ module Admin
61
77
  end
62
78
  end
63
79
 
80
+ # POST /elements/sort
81
+ # Sorts elements based on the provided list of IDs.
82
+ # Renders an empty response body.
64
83
  def sort
65
84
  Element.sort_elements(params[:id_list])
66
85
  render body: nil
@@ -69,11 +88,16 @@ module Admin
69
88
  private
70
89
 
71
90
  # Use callbacks to share common setup or constraints between actions.
91
+ # Finds an element by ID and sets it as an instance variable.
92
+ # Redirects to the elements index page with an alert if the element is not found.
72
93
  def set_element
73
94
  @element = Element.find(params[:id])
95
+ rescue ActiveRecord::RecordNotFound
96
+ redirect_to admin_elements_url, alert: "Element not found."
74
97
  end
75
98
 
76
99
  # Only allow a list of trusted parameters through.
100
+ # Permits specific parameters for element creation and updates.
77
101
  def element_params
78
102
  params.require(:element).permit(:label, :solr_field, :field_definition, :field_type, :required, :repeatable,
79
103
  :formable, :placeholder_text, :data_entry_hint, :test_fixture_example, :controlled_vocabulary, :js_behaviors, :html_attributes, :display_only_on_persisted, :importable, :import_deliminated, :import_transformation_method, :exportable, :export_transformation_method, :indexable, :index_transformation_method, :validation_method, :position)
@@ -1,29 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::FormElementsController
4
+ #
5
+ # This controller manages the CRUD operations for form elements within the admin namespace.
6
+ # It provides actions to list, show, create, update, and delete form elements.
7
+ #
8
+ # Actions:
9
+ # - index: Lists all form elements.
10
+ # - show: Displays a specific form element.
11
+ # - new: Renders a form for creating a new form element.
12
+ # - edit: Renders a form for editing an existing form element.
13
+ # - create: Creates a new form element.
14
+ # - update: Updates an existing form element.
15
+ # - destroy: Deletes a form element.
16
+ # - sort: Sorts form elements based on a provided list of IDs.
17
+ #
18
+ # Before Actions:
19
+ # - set_form_element: Sets the form element for show, edit, update, and destroy actions.
20
+ #
21
+ # Private Methods:
22
+ # - set_form_element: Finds and sets the form element by ID, redirects if not found.
23
+ # - form_element_params: Permits only trusted parameters for form elements.
4
24
  module Admin
5
25
  class FormElementsController < Admin::AdminController
6
26
  before_action :set_form_element, only: %i[show edit update destroy]
7
27
 
8
28
  # GET /form_elements or /form_elements.json
29
+ # Lists all form elements.
9
30
  def index
10
31
  @form_elements = FormElement.all
11
32
  end
12
33
 
13
34
  # GET /form_elements/1 or /form_elements/1.json
35
+ # Displays a specific form element.
14
36
  def show
15
37
  end
16
38
 
17
39
  # GET /form_elements/new
40
+ # Renders a form for creating a new form element.
18
41
  def new
19
42
  @form_element = FormElement.new
20
43
  end
21
44
 
22
45
  # GET /form_elements/1/edit
46
+ # Renders a form for editing an existing form element.
23
47
  def edit
24
48
  end
25
49
 
26
50
  # POST /form_elements or /form_elements.json
51
+ # Creates a new form element.
27
52
  def create
28
53
  @form_element = FormElement.new(form_element_params)
29
54
 
@@ -39,6 +64,7 @@ module Admin
39
64
  end
40
65
 
41
66
  # PATCH/PUT /form_elements/1 or /form_elements/1.json
67
+ # Updates an existing form element.
42
68
  def update
43
69
  respond_to do |format|
44
70
  if @form_element.update(form_element_params)
@@ -52,6 +78,7 @@ module Admin
52
78
  end
53
79
 
54
80
  # DELETE /form_elements/1 or /form_elements/1.json
81
+ # Deletes a form element.
55
82
  def destroy
56
83
  @form_element.destroy
57
84
 
@@ -61,6 +88,8 @@ module Admin
61
88
  end
62
89
  end
63
90
 
91
+ # POST /form_elements/sort
92
+ # Sorts form elements based on a provided list of IDs.
64
93
  def sort
65
94
  FormElement.sort_elements(params[:id_list])
66
95
  render body: nil
@@ -69,11 +98,15 @@ module Admin
69
98
  private
70
99
 
71
100
  # Use callbacks to share common setup or constraints between actions.
101
+ # Finds and sets the form element by ID, redirects if not found.
72
102
  def set_form_element
73
103
  @form_element = FormElement.find(params[:id])
104
+ rescue ActiveRecord::RecordNotFound
105
+ redirect_to admin_form_elements_url, alert: "Form element not found."
74
106
  end
75
107
 
76
108
  # Only allow a list of trusted parameters through.
109
+ # Permits only trusted parameters for form elements.
77
110
  def form_element_params
78
111
  params.require(:form_element).permit(:type, :label, :element_solr_field)
79
112
  end
@@ -397,5 +397,11 @@ module Admin
397
397
  end
398
398
  end
399
399
  end
400
+
401
+ private
402
+
403
+ def ids_params
404
+ params.permit(:id)
405
+ end
400
406
  end
401
407
  end
@@ -1,16 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::ImportDocumentsController
4
+ #
5
+ # This controller handles the import documents within the admin namespace.
6
+ # It inherits from Admin::AdminController and provides actions related to
7
+ # import documents.
4
8
  module Admin
5
9
  class ImportDocumentsController < Admin::AdminController
10
+ # Before action callback to set the import document for the show action.
6
11
  before_action :set_import_document, only: %i[show]
7
12
 
13
+ # GET /admin/import_documents/:id
14
+ #
15
+ # Displays a specific import document.
8
16
  def show
9
17
  end
10
18
 
11
19
  private
12
20
 
13
- # Use callbacks to share common setup or constraints between actions.
21
+ # Sets the import document based on the ID provided in the parameters.
22
+ #
23
+ # @return [ImportDocument] the import document found by ID
14
24
  def set_import_document
15
25
  @import_document = ImportDocument.find(params[:id])
16
26
  end
@@ -1,34 +1,60 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::ImportsController
4
+ #
5
+ # This controller handles the CRUD operations for Import objects within the admin namespace.
6
+ # It provides actions to list, show, create, update, and delete imports, as well as run an import.
7
+ #
8
+ # Before Actions:
9
+ # - set_import: Sets the @import instance variable for actions that require an import ID.
10
+ #
11
+ # Actions:
12
+ # - index: Lists all imports with pagination.
13
+ # - show: Displays a specific import and its associated documents, with pagination for success and failed states.
14
+ # - new: Initializes a new Import object.
15
+ # - edit: Prepares an existing Import object for editing.
16
+ # - create: Creates a new Import object and redirects to import mappings if successful.
17
+ # - update: Updates an existing Import object and redirects to the import if successful.
18
+ # - destroy: Deletes an Import object and redirects to the imports list.
19
+ # - run: Executes the import process and redirects to the import show page.
20
+ #
21
+ # Private Methods:
22
+ # - set_import: Finds and sets the import based on the provided ID.
23
+ # - permittable_params: Returns an array of permitted parameters for import.
24
+ # - import_params: Permits parameters for creating or updating an import, including nested attributes.
4
25
  module Admin
5
26
  class ImportsController < Admin::AdminController
6
27
  before_action :set_import, only: %i[show edit update destroy run]
7
28
 
8
29
  # GET /imports
9
30
  # GET /imports.json
31
+ # Lists all imports with pagination.
10
32
  def index
11
33
  @pagy, @imports = pagy(Import.all.order("created_at DESC"), items: 20)
12
34
  end
13
35
 
14
36
  # GET /imports/1
15
37
  # GET /imports/1.json
38
+ # Displays a specific import and its associated documents, with pagination for success and failed states.
16
39
  def show
17
40
  @pagy_failed, @import_failed_documents = pagy(@import.import_documents.not_in_state(:success), items: 50, page_param: :failed_page)
18
41
  @pagy_success, @import_success_documents = pagy(@import.import_documents.in_state(:success), items: 50, page_param: :success_page)
19
42
  end
20
43
 
21
44
  # GET /imports/new
45
+ # Initializes a new Import object.
22
46
  def new
23
47
  @import = Import.new
24
48
  end
25
49
 
26
50
  # GET /imports/1/edit
51
+ # Prepares an existing Import object for editing.
27
52
  def edit
28
53
  end
29
54
 
30
55
  # POST /imports
31
56
  # POST /imports.json
57
+ # Creates a new Import object and redirects to import mappings if successful.
32
58
  def create
33
59
  @import = Import.new(import_params)
34
60
 
@@ -40,7 +66,7 @@ module Admin
40
66
  end
41
67
  format.json { render :show, status: :created, location: @import }
42
68
  else
43
- format.html { render :new }
69
+ format.html { render :new, status: :unprocessable_entity }
44
70
  format.json { render json: @import.errors, status: :unprocessable_entity }
45
71
  end
46
72
  end
@@ -48,13 +74,14 @@ module Admin
48
74
 
49
75
  # PATCH/PUT /imports/1
50
76
  # PATCH/PUT /imports/1.json
77
+ # Updates an existing Import object and redirects to the import if successful.
51
78
  def update
52
79
  respond_to do |format|
53
80
  if @import.update(import_params)
54
81
  format.html { redirect_to admin_import_path(@import), notice: "Import was successfully updated." }
55
82
  format.json { render :show, status: :ok, location: @import }
56
83
  else
57
- format.html { render :edit }
84
+ format.html { render :edit, status: :unprocessable_entity }
58
85
  format.json { render json: @import.errors, status: :unprocessable_entity }
59
86
  end
60
87
  end
@@ -62,6 +89,7 @@ module Admin
62
89
 
63
90
  # DELETE /imports/1
64
91
  # DELETE /imports/1.json
92
+ # Deletes an Import object and redirects to the imports list.
65
93
  def destroy
66
94
  @import.destroy
67
95
  respond_to do |format|
@@ -70,6 +98,7 @@ module Admin
70
98
  end
71
99
  end
72
100
 
101
+ # Runs the import process and redirects to the import show page.
73
102
  def run
74
103
  @import.run!
75
104
  redirect_to admin_import_url(@import), notice: "Import is running. Check back soon for results."
@@ -78,17 +107,18 @@ module Admin
78
107
  private
79
108
 
80
109
  # Use callbacks to share common setup or constraints between actions.
110
+ # Finds and sets the import based on the provided ID.
81
111
  def set_import
82
112
  @import = Import.find(params[:id])
83
113
  end
84
114
 
85
- # Never trust parameters from the scary internet, only allow the white list through.
86
-
115
+ # Returns an array of permitted parameters for import.
87
116
  def permittable_params
88
117
  %i[type name filename source description row_count encoding content_type extension validity validation_result
89
118
  csv_file run]
90
119
  end
91
120
 
121
+ # Permits parameters for creating or updating an import, including nested attributes.
92
122
  def import_params
93
123
  # Handle STI key
94
124
  key = (params.keys & %w[import import_btaa import_btaa_aardvark import_gblv1])[0]
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::MappingsController
4
+ # This controller manages the CRUD operations for Mappings within an Import context.
5
+ # It provides actions to list, show, create, update, and destroy mappings.
4
6
  module Admin
5
7
  class MappingsController < Admin::AdminController
6
8
  before_action :set_import
@@ -8,6 +10,7 @@ module Admin
8
10
 
9
11
  # GET /import/:id/mappings
10
12
  # GET /import/:id/mappings.json
13
+ # Lists all mappings for a specific import. If no mappings exist, it initializes a new one.
11
14
  def index
12
15
  @mappings = Mapping.where(import_id: @import)
13
16
 
@@ -17,21 +20,26 @@ module Admin
17
20
 
18
21
  # GET /mappings/1
19
22
  # GET /mappings/1.json
23
+ # Shows a specific mapping.
20
24
  def show
21
25
  @import = Import.find(params[:import_id])
22
26
  end
23
27
 
24
28
  # GET /mappings/new
29
+ # Initializes a new mapping object.
25
30
  def new
26
31
  @mapping = Mapping.new
27
32
  end
28
33
 
29
34
  # GET /mappings/1/edit
35
+ # Prepares a mapping for editing.
30
36
  def edit
31
37
  end
32
38
 
33
39
  # POST /mappings
34
40
  # POST /mappings.json
41
+ # Creates a new mapping. If successful, redirects to the mapping's show page.
42
+ # Otherwise, re-renders the new form.
35
43
  def create
36
44
  @mapping = Mapping.new(mapping_params)
37
45
 
@@ -50,6 +58,8 @@ module Admin
50
58
 
51
59
  # PATCH/PUT /mappings/1
52
60
  # PATCH/PUT /mappings/1.json
61
+ # Updates an existing mapping. If successful, redirects to the mappings index.
62
+ # Otherwise, re-renders the edit form.
53
63
  def update
54
64
  respond_to do |format|
55
65
  if @mapping.update(mapping_params)
@@ -64,6 +74,7 @@ module Admin
64
74
 
65
75
  # DELETE /mappings/1
66
76
  # DELETE /mappings/1.json
77
+ # Deletes a mapping and redirects to the mappings index.
67
78
  def destroy
68
79
  @mapping.destroy
69
80
  respond_to do |format|
@@ -75,15 +86,19 @@ module Admin
75
86
  private
76
87
 
77
88
  # Use callbacks to share common setup or constraints between actions.
89
+
90
+ # Sets the import based on the import_id parameter.
78
91
  def set_import
79
92
  @import = Import.find(params[:import_id])
80
93
  end
81
94
 
95
+ # Sets the mapping based on the id parameter.
82
96
  def set_mapping
83
97
  @mapping = Mapping.find(params[:id])
84
98
  end
85
99
 
86
100
  # Only allow a list of trusted parameters through.
101
+ # Permits the parameters required for creating or updating a mapping.
87
102
  def mapping_params
88
103
  params.require(:mapping).permit(
89
104
  :source_header,