geoblacklight_admin 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -9
  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 +1 -1
  10. data/app/controllers/admin/assets_controller.rb +41 -5
  11. data/app/controllers/admin/bookmarks_controller.rb +14 -2
  12. data/app/controllers/admin/bulk_actions_controller.rb +31 -0
  13. data/app/controllers/admin/document_accesses_controller.rb +38 -0
  14. data/app/controllers/admin/document_assets_controller.rb +46 -9
  15. data/app/controllers/admin/document_distributions_controller.rb +172 -0
  16. data/app/controllers/admin/documents_controller.rb +41 -55
  17. data/app/controllers/admin/elements_controller.rb +22 -0
  18. data/app/controllers/admin/form_elements_controller.rb +31 -0
  19. data/app/controllers/admin/import_documents_controller.rb +11 -1
  20. data/app/controllers/admin/imports_controller.rb +32 -2
  21. data/app/controllers/admin/mappings_controller.rb +15 -0
  22. data/app/controllers/admin/notifications_controller.rb +27 -0
  23. data/app/controllers/admin/reference_types_controller.rb +106 -0
  24. data/app/controllers/admin/search_controller.rb +7 -0
  25. data/app/controllers/admin/users_controller.rb +10 -0
  26. data/app/helpers/asset_helper.rb +6 -0
  27. data/app/helpers/bulk_actions_helper.rb +9 -0
  28. data/app/helpers/document_helper.rb +36 -0
  29. data/app/helpers/geoblacklight_admin_helper.rb +88 -8
  30. data/app/helpers/mappings_helper.rb +26 -0
  31. data/app/indexers/document_indexer.rb +22 -2
  32. data/app/javascript/channels/consumer.js +6 -0
  33. data/app/javascript/channels/export_channel.js +30 -0
  34. data/app/javascript/channels/index.js +3 -0
  35. data/app/javascript/controllers/results_controller.js +14 -0
  36. data/app/javascript/index.js +8 -2
  37. data/app/jobs/export_job.rb +35 -8
  38. data/app/jobs/geoblacklight_admin/delete_thumbnail_job.rb +19 -0
  39. data/app/jobs/geoblacklight_admin/remove_parent_dct_references_uri_job.rb +16 -0
  40. data/app/jobs/geoblacklight_admin/set_parent_dct_references_uri_job.rb +17 -0
  41. data/app/jobs/geoblacklight_admin/store_image_job.rb +22 -0
  42. data/app/models/asset.rb +20 -0
  43. data/app/models/bulk_action.rb +2 -1
  44. data/app/models/document/geom_validator.rb +8 -0
  45. data/app/models/document/reference.rb +65 -65
  46. data/app/models/document.rb +128 -71
  47. data/app/models/document_distribution.rb +145 -0
  48. data/app/models/element.rb +2 -0
  49. data/app/models/geoblacklight_admin/schema.rb +10 -2
  50. data/app/models/import_document_state_machine.rb +1 -0
  51. data/app/models/reference_type.rb +40 -0
  52. data/app/models/user.rb +4 -2
  53. data/app/services/export_csv_document_distributions_service.rb +61 -0
  54. data/app/services/geoblacklight_admin/image_service/tms.rb +0 -4
  55. data/app/services/geoblacklight_admin/image_service.rb +1 -1
  56. data/app/services/geoblacklight_admin/item_viewer.rb +4 -4
  57. data/app/views/admin/bulk_actions/show.html.erb +1 -1
  58. data/app/views/admin/document_accesses/import.html.erb +6 -2
  59. data/app/views/admin/document_assets/_assets_table.html.erb +49 -0
  60. data/app/views/admin/document_assets/_form.html.erb +2 -3
  61. data/app/views/admin/document_assets/index.html.erb +1 -47
  62. data/app/views/admin/document_distributions/_document_distribution.html.erb +39 -0
  63. data/app/views/admin/document_distributions/_document_distribution.json.jbuilder +2 -0
  64. data/app/views/admin/document_distributions/_form.html.erb +34 -0
  65. data/app/views/admin/document_distributions/destroy_all.html.erb +82 -0
  66. data/app/views/admin/document_distributions/edit.html.erb +12 -0
  67. data/app/views/admin/document_distributions/import.html.erb +80 -0
  68. data/app/views/admin/document_distributions/index.html.erb +143 -0
  69. data/app/views/admin/document_distributions/index.json.jbuilder +1 -0
  70. data/app/views/admin/document_distributions/new.html.erb +11 -0
  71. data/app/views/admin/document_distributions/show.html.erb +10 -0
  72. data/app/views/admin/document_distributions/show.json.jbuilder +1 -0
  73. data/app/views/admin/documents/_document.html.erb +1 -3
  74. data/app/views/admin/documents/_form.html.erb +2 -4
  75. data/app/views/admin/documents/_form_control.html.erb +5 -2
  76. data/app/views/admin/documents/_form_nav.html.erb +14 -5
  77. data/app/views/admin/documents/_form_nav_kithe.html.erb +4 -1
  78. data/app/views/admin/documents/_json_aardvark.jbuilder +1 -1
  79. data/app/views/admin/documents/_json_gbl_v1.jbuilder +1 -1
  80. data/app/views/admin/documents/_result_selected_options.html.erb +5 -2
  81. data/app/views/admin/documents/admin.html.erb +5 -5
  82. data/app/views/admin/documents/features/_document_references.html.erb +23 -0
  83. data/app/views/admin/documents/features/_multiple_download_links.html.erb +29 -26
  84. data/app/views/admin/ids/fetch.json.jbuilder +0 -2
  85. data/app/views/admin/ids/index.json.jbuilder +0 -2
  86. data/app/views/admin/imports/_form.html.erb +1 -1
  87. data/app/views/admin/imports/show.html.erb +1 -1
  88. data/app/views/admin/layouts/application.html.erb +4 -2
  89. data/app/views/admin/reference_types/_form.html.erb +25 -0
  90. data/app/views/admin/reference_types/_reference_type.html.erb +52 -0
  91. data/app/views/admin/reference_types/_reference_type.json.jbuilder +2 -0
  92. data/app/views/admin/reference_types/edit.html.erb +12 -0
  93. data/app/views/admin/reference_types/index.html.erb +52 -0
  94. data/app/views/admin/reference_types/index.json.jbuilder +1 -0
  95. data/app/views/admin/reference_types/new.html.erb +11 -0
  96. data/app/views/admin/reference_types/show.html.erb +3 -0
  97. data/app/views/admin/reference_types/show.json.jbuilder +1 -0
  98. data/app/views/admin/shared/_footer.html.erb +5 -2
  99. data/app/views/admin/shared/_js_behaviors.html.erb +2 -3
  100. data/app/views/admin/shared/_navbar.html.erb +9 -2
  101. data/app/views/admin/users/index.html.erb +0 -1
  102. data/app/views/catalog/_show_gbl_admin.html.erb +1 -1
  103. data/config/initializers/defaults.yml +310 -0
  104. data/config/initializers/rails_config.rb +8 -0
  105. data/config/locales/documents.en.yml +14 -0
  106. data/config/routes.rb +30 -5
  107. data/db/import_references_schema_support.numbers +0 -0
  108. data/db/migrate/20230316183001_add_geoblacklight_admin_gem.rb +0 -12
  109. data/db/migrate/20241009200524_create_admin_reference_types.rb +13 -0
  110. data/db/migrate/20241010161420_create_document_references.rb +14 -0
  111. data/db/migrate/20241120238823_rename_references_to_distributions.rb +5 -0
  112. data/db/seeds.rb +5 -0
  113. data/db/seeds_elements.csv +1 -1
  114. data/db/seeds_elements.numbers +0 -0
  115. data/db/seeds_reference_types.csv +29 -0
  116. data/db/seeds_reference_types.numbers +0 -0
  117. data/db/structure.sql +1 -38
  118. data/lib/compose.yml +31 -0
  119. data/lib/generators/geoblacklight_admin/config_generator.rb +48 -12
  120. data/lib/generators/geoblacklight_admin/install_generator.rb +8 -0
  121. data/lib/generators/geoblacklight_admin/templates/config/database.yml +1 -1
  122. data/lib/generators/geoblacklight_admin/templates/config/initializers/devise.rb +0 -2
  123. data/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb +1 -0
  124. data/lib/generators/geoblacklight_admin/templates/demo-app/Dockerfile +31 -0
  125. data/lib/generators/geoblacklight_admin/templates/demo-app/compose.yml +42 -0
  126. data/lib/generators/geoblacklight_admin/templates/demo-app/start-server.sh +21 -0
  127. data/lib/geoblacklight_admin/engine.rb +4 -0
  128. data/lib/geoblacklight_admin/tasks/distributions.rake +69 -0
  129. data/lib/geoblacklight_admin/tasks/images.rake +1 -0
  130. data/lib/geoblacklight_admin/tasks/solr.rake +31 -0
  131. data/lib/geoblacklight_admin/version.rb +1 -1
  132. data/lib/geoblacklight_admin.rb +4 -0
  133. metadata +78 -41
  134. data/app/javascript/entrypoints/engine.js +0 -8
  135. data/config/locales/devise_invitable.en.yml +0 -31
  136. data/lib/generators/geoblacklight_admin/templates/devise/invitations/edit.html.erb +0 -15
  137. data/lib/generators/geoblacklight_admin/templates/devise/invitations/new.html.erb +0 -15
  138. data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.html.erb +0 -11
  139. data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.text.erb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c69db073de82cb4873945d0ae70de901c08b517852e98f4ad5ee44812eb70b0
4
- data.tar.gz: ae8eeeada318da7edac96eae733f67d5e93dccabc4dcc309cf4fb1b58f22f84d
3
+ metadata.gz: fb7dfdea7cb8626ae4e65999624310642a89c81cea03a8d0e58a5649c080091b
4
+ data.tar.gz: e08e45d57f47e372d574e7cce41e1babd93697741a1261a22dcf816e07a0b74b
5
5
  SHA512:
6
- metadata.gz: 2c21ed4eec52af1dcee587aa7b0e6894e121ccbd8f728198b6dd445c59c259f33fe90ea826b58007395e4770f2a0890ca4001935030e5f147739f68f648e6c72
7
- data.tar.gz: 463306e5810b82d77f6059205993ed233d803dc83892b66f0cd5bacb245bb6269ba6c5c621825b28c3698de713b2c170243026383d7d0967c5b804bce13dca34
6
+ metadata.gz: b7e2504e7f0fb46e55e0ba3359577a4d6e90842afa5c6be608e79a52d2b278ec39fe24812b68d8ca6d950ff2ef7842905550bb2a1354ba012f82f8b6349da154
7
+ data.tar.gz: d913fe08b848b6b9a2f2cd730570cecbb1f0e98157540b967306fc903ee7433bdae04a422b7d0b06c20678103bd30440bfaa939b04369c9b9f100bdd55611a65
data/README.md CHANGED
@@ -28,12 +28,19 @@ You need a PostgreSQL database to use this project.
28
28
 
29
29
  ### Install Template
30
30
 
31
- Use Ruby v3.3 and Rails v7.0.8.1 to bootstrap a new GeoBlacklight + GBL Admin application using the template script:
31
+ #### 1. Create your geoblacklight_admin_development PostgreSQL database
32
32
 
33
33
  ```bash
34
- rails _7.0.8.1_ new gbl_admin -m https://raw.githubusercontent.com/geobtaa/geoblacklight_admin/develop/template.rb
34
+ psql postgres
35
+ CREATE DATABASE geoblacklight_admin_development;
36
+ ```
37
+
38
+ #### 2. Bootstrap a new GeoBlacklight + GBL Admin application using the template script:
39
+
40
+ ```bash
41
+ rails _7.2.2_ new gbl_admin -m https://raw.githubusercontent.com/geobtaa/geoblacklight_admin/develop/template.rb
35
42
  cd gbl_admin
36
- bundle exec rake gbl_admin:server
43
+ bundle exec rake geoblacklight:server
37
44
  ```
38
45
 
39
46
  You have now generated the .internal_test_app and populated the Elements / FormElements tables for OMG Aardvark support.
@@ -44,7 +51,7 @@ You have now generated the .internal_test_app and populated the Elements / FormE
44
51
  2. Click on the "Sign in" link
45
52
  3. Enter email: admin@geoblacklight.org and password: 123456
46
53
  4. Click on the "GBL Admin" link
47
- 5. Import some CSV (test/fixtures/files/btaa_sample_records.csv)
54
+ 5. Import some CSV data (test/fixtures/files/btaa_sample_records.csv)
48
55
 
49
56
  -----
50
57
 
@@ -58,10 +65,12 @@ The gem is available as open source under the terms of the [Apache 2.0 License](
58
65
  ## TODOs / Roadmap
59
66
  * ~~Send GBLADMIN JavaScript pack to NPM like Blacklight~~
60
67
  * ~~Improve test coverage~~
61
- * Fix CI test runner
62
- * Debug Rails 7.2 support
63
- * Separate dct_references_s support into a separate model
64
- * Import/Export dct_references_s outside of the main document model
65
- * Migrate our GBL api controllers to just RSolr-based models
68
+ * ~~Fix CI test runner~~
69
+ * ~~Debug Rails 7.2 support (remove devise_invitable, see [#915](https://github.com/scambra/devise_invitable/issues/915))~~
70
+ * ~~Separate dct_references_s support into a separate model~~
71
+ * ~~Import/Export dct_references_s outside of the main document model~~
72
+ * Migrate our GBL API controllers to just RSolr-based models
66
73
  * DRY up Gem dependencies and Engine routing
74
+ * Gazetteer: Add GeoNames support
75
+ * Gazetteer: Add Who's On First support
67
76
  * Remove any remaining GEOMG references
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "rubygems"
4
4
  require "rails"
5
+ require "database_cleaner/active_record"
5
6
 
6
7
  require "bundler/setup"
7
8
 
@@ -13,15 +14,12 @@ load "rails/tasks/statistics.rake"
13
14
 
14
15
  require "bundler/gem_tasks"
15
16
 
16
- require "solr_wrapper"
17
-
18
17
  require "rspec/core/rake_task"
19
18
  RSpec::Core::RakeTask.new(:spec)
20
19
 
21
20
  require "rubocop/rake_task"
22
21
  RuboCop::RakeTask.new(:rubocop)
23
22
 
24
- require "solr_wrapper/rake_task"
25
23
  require "engine_cart/rake_task"
26
24
  require "geoblacklight_admin/version"
27
25
  require "rake/testtask"
@@ -40,66 +38,104 @@ end
40
38
  task default: :test
41
39
 
42
40
  desc "Run test suite"
43
- task ci: ["geoblacklight:generate"] do
44
- within_test_app do
45
- require "simple_form"
46
- system "RAILS_ENV=test bin/rails db:migrate"
47
- system "RAILS_ENV=test rake db:seed"
48
- system "RAILS_ENV=test rails webpacker:compile"
41
+ task :ci do
42
+ # Reset the database if the test app exists
43
+ if File.exist? EngineCart.destination
44
+ within_test_app do
45
+ system "bundle exec rake db:reset"
46
+ end
49
47
  end
50
48
 
51
- # Run RSpec tests with Coverage
52
- Rake::Task["geoblacklight:coverage"].invoke
53
- end
49
+ # Start docker
50
+ Rake::Task["geoblacklight:admin:docker:start"].invoke
54
51
 
55
- namespace :geoblacklight do
56
- desc "Run tests with coverage"
57
- task :coverage do
58
- ENV["COVERAGE"] = "true"
59
- # Rake::Task["spec"].invoke
60
- Rake::Task["test"].invoke
61
- end
52
+ # Create the test rails app
53
+ Rake::Task["geoblacklight:admin:generate"].invoke
62
54
 
63
- desc "Create the test rails app"
64
- task generate: ["engine_cart:generate"] do
65
- # Intentionally Empty Block
66
- end
55
+ # Run Minitest tests with Coverage
56
+ Rake::Task["geoblacklight:admin:coverage"].invoke
67
57
 
68
- namespace :internal do
69
- task seed: ["engine_cart:generate"] do
70
- within_test_app do
71
- system "bundle exec rake db:seed"
72
- system "bundle exec rake geoblacklight:downloads:mkdir"
73
- end
74
- end
75
- end
58
+ # Stop docker
59
+ Rake::Task["geoblacklight:admin:docker:stop"].invoke
60
+ end
76
61
 
77
- desc "Run Solr and seed with sample data"
78
- task :solr do
79
- if File.exist? EngineCart.destination
80
- within_test_app do
81
- system "bundle update"
62
+ namespace :geoblacklight do
63
+ namespace :admin do
64
+ desc "Run GeoBlacklight Admin and Solr with seed data for interactive development"
65
+ task :server, [:rails_server_args] do |_t, args|
66
+ if File.exist? EngineCart.destination
67
+ within_test_app do
68
+ system "bundle update"
69
+ end
70
+ else
71
+ Rake::Task["engine_cart:generate"].invoke
82
72
  end
83
- else
84
- Rake::Task["engine_cart:generate"].invoke
85
- end
86
73
 
87
- SolrWrapper.wrap(port: "8983") do |solr|
88
- solr.with_collection(name: "blacklight-core",
89
- dir: File.join(File.expand_path(".", File.dirname(__FILE__)),
90
- "solr", "conf")) do
91
- Rake::Task["geoblacklight:internal:seed"].invoke
74
+ system "docker compose up -d"
75
+ Rake::Task["geoblacklight:admin:internal:seed"].invoke
92
76
 
77
+ begin
93
78
  within_test_app do
94
- puts "\nSolr server running: http://localhost:#{solr.port}/solr/#/blacklight-core"
95
- puts "\n^C to stop"
79
+ puts "\nSolr server running: http://localhost:8983/solr/#/blacklight-core"
80
+ puts "\nPostgreSQL server running: http://localhost:5555"
96
81
  puts " "
97
82
  begin
98
- sleep
83
+ system "bundle exec rails s #{args[:rails_server_args]}"
99
84
  rescue Interrupt
100
85
  puts "Shutting down..."
101
86
  end
102
87
  end
88
+ ensure
89
+ system "docker compose down"
90
+ end
91
+ end
92
+
93
+ desc "Run tests with coverage"
94
+ task :coverage do
95
+ ENV["COVERAGE"] = "true"
96
+ Rake::Task["test"].invoke
97
+ end
98
+
99
+ desc "Create the test rails app"
100
+ task generate: ["engine_cart:generate"] do
101
+ # system "bundle exec rake db:reset"
102
+ end
103
+
104
+ namespace :internal do
105
+ task seed: ["engine_cart:generate"] do
106
+ within_test_app do
107
+ system "Settings.reload!"
108
+ system "bundle exec rake db:reset"
109
+ system "bundle exec rake db:seed"
110
+ system "bundle exec rake geoblacklight:downloads:mkdir"
111
+ end
112
+ end
113
+ end
114
+
115
+ desc "Run Solr and seed with sample data"
116
+ task :solr do
117
+ if File.exist? EngineCart.destination
118
+ within_test_app do
119
+ system "bundle update"
120
+ end
121
+ else
122
+ Rake::Task["engine_cart:generate"].invoke
123
+ end
124
+ end
125
+
126
+ namespace :docker do
127
+ desc "Start docker and seed with sample data"
128
+ task :start do
129
+ system "docker compose up -d"
130
+ Rake::Task["geoblacklight:admin:internal:seed"].invoke
131
+ puts "\nSolr server running: http://localhost:8983/solr/#/blacklight-core"
132
+ puts "\nPostgreSQL server running: http://localhost:5555"
133
+ puts " "
134
+ end
135
+
136
+ desc "Stop docker"
137
+ task :stop do
138
+ system "docker compose down"
103
139
  end
104
140
  end
105
141
  end
@@ -1,4 +1,5 @@
1
1
  // VanillaJS Ready
2
+ // @TODO: Replace with Tom Select
2
3
  document.addEventListener('DOMContentLoaded', function() {
3
4
  var elements = document.querySelectorAll('.chosen-select');
4
5
  Array.prototype.forEach.call(elements, function(el, i){
@@ -45,10 +45,34 @@ footer.gbl-admin {
45
45
  box-shadow: inset 0 0 0 50vw rgba(0, 0, 0, 0.8);
46
46
  }
47
47
 
48
+ main#gbl-admin {
49
+ min-height: 75vh;
50
+ margin-top: 0rem;
51
+ }
52
+
48
53
  main.container-fluid {
49
54
  margin-top: 5rem;
50
55
  }
51
56
 
52
57
  .navbar-brand.gbl-admin {
53
58
  background: none;
59
+ }
60
+
61
+ kbd {
62
+ background-color:aliceblue;
63
+ }
64
+
65
+ a.btn.btn-gbl-admin {
66
+ color: black;
67
+ border-color: #ffc107;
68
+ margin: 1rem 0;
69
+
70
+ &:visited {
71
+ color: black;
72
+ background-color: #ffc107;
73
+ }
74
+ }
75
+
76
+ div.dropdown-menu.show {
77
+ z-index: 2000;
54
78
  }
@@ -1,8 +1,3 @@
1
- // Keep Document Cancel and Update buttons visible
2
- .admin-header {
3
- top:4rem;
4
- }
5
-
6
1
  // Keep View in Geoportal visible
7
2
  .make-me-sticky {
8
3
  top:8rem;
@@ -1,4 +1,4 @@
1
1
  th.header{
2
2
  position: sticky;
3
- top: 55px;
3
+ top: 0.25rem;
4
4
  }
@@ -1,18 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The Admin module contains controllers for the admin section of the application.
3
4
  module Admin
5
+ # AdminController is the base controller for all admin-related controllers.
6
+ # It includes necessary modules and provides authentication for admin users.
4
7
  class AdminController < ApplicationController
8
+ # Includes Devise helpers for authentication.
5
9
  include Devise::Controllers::Helpers
10
+ # Includes Pagy for pagination.
6
11
  include ::Pagy::Backend
12
+ # Sets the layout for the admin section.
7
13
  layout "admin/layouts/application"
8
14
 
15
+ # Before any action, ensure the user is authenticated as an admin.
9
16
  before_action :authenticate_admin!
17
+ before_action :set_action_cable_identifier
10
18
 
11
19
  protected
12
20
 
21
+ # Authenticates the user and checks if they are an admin.
22
+ # Redirects to a specified location with a forbidden status if the user is not an admin.
13
23
  def authenticate_admin!
14
24
  authenticate_user!
15
25
  redirect_to :somewhere, status: :forbidden unless current_user.admin?
16
26
  end
27
+
28
+ private
29
+
30
+ def set_action_cable_identifier
31
+ cookies.encrypted[:user_id] = current_user&.id
32
+ end
17
33
  end
18
34
  end
@@ -76,7 +76,7 @@ module Admin
76
76
  # config.index.record_display_type = 'format'
77
77
 
78
78
  config.index.title_field = Settings.FIELDS.TITLE
79
- config.index.document_presenter_class = Geoblacklight::DocumentPresenter
79
+ config.index.document_presenter_class = ::Geoblacklight::DocumentPresenter
80
80
 
81
81
  # solr field configuration for document/show views
82
82
 
@@ -1,11 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::AssetsController
4
+ #
5
+ # This controller handles the management of assets within the admin namespace.
6
+ # It provides actions to list, show, edit, update, and destroy assets.
7
+ # Additionally, it supports attaching files to assets.
8
+ #
9
+ # Actions:
10
+ # - index: Lists all assets with optional search functionality.
11
+ # - show: Displays a specific asset.
12
+ # - edit: Provides a form to edit an asset.
13
+ # - update: Updates an asset with new data.
14
+ # - destroy: Deletes an asset.
15
+ # - display_attach_form: Displays a form to attach files to an asset.
16
+ # - attach_files: Attaches files to an asset based on provided JSON data.
17
+ #
18
+ # Private Methods:
19
+ # - parent_id_via_friendly_id: Finds a document's ID using its friendlier_id.
20
+ # - set_asset: Finds and sets an asset based on the provided ID.
21
+ # - asset_params: Permits only trusted parameters for asset updates.
22
+ # - date_check?: Checks if a value can be converted to a date.
4
23
  module Admin
5
24
  class AssetsController < Admin::AdminController
6
25
  before_action :set_asset, only: %i[show edit update destroy]
7
26
 
8
27
  # GET /admin/asset_files
28
+ #
29
+ # Lists all assets. Supports searching by ID, friendlier_id, title, or parent_id.
30
+ # If a date is provided as a search query, it filters assets created on that date.
9
31
  def index
10
32
  scope = Asset
11
33
  search_query = params[:q].strip if params[:q].present?
@@ -29,14 +51,21 @@ module Admin
29
51
  end
30
52
 
31
53
  # GET /assets/1 or /assets/1.json
54
+ #
55
+ # Displays a specific asset.
32
56
  def show
33
57
  end
34
58
 
35
59
  # GET /assets/1/edit
60
+ #
61
+ # Provides a form to edit an asset.
36
62
  def edit
37
63
  end
38
64
 
39
65
  # PATCH/PUT /assets/1 or /assets/1.json
66
+ #
67
+ # Updates an asset with new data. If successful, redirects to the asset's page.
68
+ # Otherwise, re-renders the edit form with errors.
40
69
  def update
41
70
  respond_to do |format|
42
71
  if @asset.update(asset_params.merge!(parent_id: parent_id_via_friendly_id(asset_params[:parent_id])))
@@ -50,6 +79,8 @@ module Admin
50
79
  end
51
80
 
52
81
  # DELETE /assets/1 or /assets/1.json
82
+ #
83
+ # Deletes an asset and redirects to the assets list with a success notice.
53
84
  def destroy
54
85
  @asset.destroy
55
86
 
@@ -60,14 +91,16 @@ module Admin
60
91
  end
61
92
 
62
93
  # /assets/display_attach_form
94
+ #
95
+ # Displays a form to attach files to an asset.
63
96
  def display_attach_form
64
97
  end
65
98
 
66
- # Receives json hashes for direct uploaded files in params[:files],
67
- # and id in params[:id] (friendlier_id)
68
- # creates filesets for them and attach.
69
- #
70
99
  # POST /assets/ingest
100
+ #
101
+ # Receives JSON hashes for direct uploaded files in params[:files],
102
+ # and id in params[:id] (friendlier_id). Creates filesets for them and attaches.
103
+ # Redirects to the assets list with a success notice.
71
104
  def attach_files
72
105
  # @parent = Document.find_by_friendlier_id!(params[:id])
73
106
 
@@ -98,20 +131,23 @@ module Admin
98
131
 
99
132
  private
100
133
 
134
+ # Finds a document's ID using its friendlier_id.
101
135
  def parent_id_via_friendly_id(friendlier_id)
102
136
  Document.find_by_friendlier_id(friendlier_id)&.id
103
137
  end
104
138
 
105
139
  # Use callbacks to share common setup or constraints between actions.
140
+ # Finds and sets an asset based on the provided ID.
106
141
  def set_asset
107
142
  @asset = Asset.find(params[:id])
108
143
  end
109
144
 
110
145
  # Only allow a list of trusted parameters through.
111
146
  def asset_params
112
- params.require(:asset).permit(:parent_id)
147
+ params.require(:asset).permit(:parent_id, :thumbnail)
113
148
  end
114
149
 
150
+ # Checks if a value can be converted to a date.
115
151
  def date_check?(val)
116
152
  val.to_date
117
153
  rescue Date::Error
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::BookmarksController
4
+ # This controller handles the management of bookmarks for the admin interface.
5
+ # It allows for listing, creating, and destroying bookmarks associated with the current user.
4
6
  module Admin
5
7
  class BookmarksController < Admin::AdminController
6
- before_action :set_document,
7
- only: %i[create destroy]
8
+ before_action :set_document, only: %i[create destroy]
8
9
 
9
10
  # GET /bookmarks
10
11
  # GET /bookmarks.json
12
+ # Lists all bookmarks for the current user, filtered by document type "Kithe::Model".
13
+ # Responds with HTML or CSV format.
11
14
  def index
12
15
  @pagy, @bookmarks = pagy(current_user.bookmarks.where(document_type: "Kithe::Model"))
13
16
 
@@ -20,6 +23,9 @@ module Admin
20
23
 
21
24
  # POST /bookmarks
22
25
  # POST /bookmarks.json
26
+ # Creates a new bookmark for the current user and the specified document.
27
+ # If successful, redirects to the bookmarks index with a success notice.
28
+ # Otherwise, renders the index with an error status.
23
29
  def create
24
30
  @bookmark = Admin::Bookmark.find_or_create_by(user: current_user, document: @document)
25
31
 
@@ -36,6 +42,8 @@ module Admin
36
42
 
37
43
  # DELETE /bookmarks/1
38
44
  # DELETE /bookmarks/1.json
45
+ # Destroys the bookmark for the current user and the specified document.
46
+ # Redirects to the bookmarks index with a success notice.
39
47
  def destroy
40
48
  Admin::Bookmark.destroy_by(user: current_user, document: @document)
41
49
 
@@ -47,6 +55,7 @@ module Admin
47
55
 
48
56
  private
49
57
 
58
+ # Sets the document based on the friendlier_id parameter.
50
59
  def set_document
51
60
  @document = Document.find_by(friendlier_id: params["document"])
52
61
  end
@@ -56,6 +65,9 @@ module Admin
56
65
  params.fetch(:bookmark, {})
57
66
  end
58
67
 
68
+ # Collects bookmarks into a CSV format.
69
+ # @param bookmarks [Array<Bookmark>] the bookmarks to be converted to CSV
70
+ # @return [String] the generated CSV data
59
71
  def collect_csv(bookmarks)
60
72
  CSV.generate(headers: true) do |csv|
61
73
  csv << GeoblacklightAdmin::Schema.instance.importable_fields.map { |k, _v| k.to_s }
@@ -1,34 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Admin::BulkActionsController
4
+ #
5
+ # This controller manages bulk actions within the admin interface.
6
+ # It provides actions to list, show, create, update, destroy, run, and revert bulk actions.
4
7
  module Admin
5
8
  class BulkActionsController < Admin::AdminController
6
9
  before_action :set_bulk_action, only: %i[show edit update destroy run revert]
7
10
 
8
11
  # GET /bulk_actions
9
12
  # GET /bulk_actions.json
13
+ #
14
+ # Lists all bulk actions, paginated.
15
+ # @return [Array<BulkAction>] List of bulk actions
10
16
  def index
11
17
  @pagy, @bulk_actions = pagy(BulkAction.all.order(created_at: :desc), items: 20)
12
18
  end
13
19
 
14
20
  # GET /bulk_actions/1
15
21
  # GET /bulk_actions/1.json
22
+ #
23
+ # Shows a specific bulk action and its associated documents.
24
+ # @return [BulkAction] The requested bulk action
16
25
  def show
17
26
  @pagy, @documents = pagy(@bulk_action.documents, items: 30)
18
27
  @bulk_action.check_run_state
19
28
  end
20
29
 
21
30
  # GET /bulk_actions/new
31
+ #
32
+ # Initializes a new bulk action with a given scope.
33
+ # @return [BulkAction] A new bulk action instance
22
34
  def new
23
35
  @bulk_action = BulkAction.new(scope: params[:scope])
24
36
  end
25
37
 
26
38
  # GET /bulk_actions/1/edit
39
+ #
40
+ # Prepares a bulk action for editing.
41
+ # @return [BulkAction] The bulk action to be edited
27
42
  def edit
28
43
  end
29
44
 
30
45
  # POST /bulk_actions
31
46
  # POST /bulk_actions.json
47
+ #
48
+ # Creates a new bulk action.
49
+ # @return [BulkAction] The created bulk action
32
50
  def create
33
51
  @bulk_action = BulkAction.new(bulk_action_params)
34
52
 
@@ -47,6 +65,9 @@ module Admin
47
65
 
48
66
  # PATCH/PUT /bulk_actions/1
49
67
  # PATCH/PUT /bulk_actions/1.json
68
+ #
69
+ # Updates an existing bulk action.
70
+ # @return [BulkAction] The updated bulk action
50
71
  def update
51
72
  respond_to do |format|
52
73
  if @bulk_action.update(bulk_action_params)
@@ -63,6 +84,9 @@ module Admin
63
84
 
64
85
  # DELETE /bulk_actions/1
65
86
  # DELETE /bulk_actions/1.json
87
+ #
88
+ # Deletes a bulk action.
89
+ # @return [void]
66
90
  def destroy
67
91
  @bulk_action.destroy
68
92
  respond_to do |format|
@@ -71,12 +95,16 @@ module Admin
71
95
  end
72
96
  end
73
97
 
98
+ # Runs a bulk action.
99
+ # @return [void]
74
100
  def run
75
101
  @bulk_action.run!
76
102
  # @bulk_action.state_machine.transition_to!(:queued)
77
103
  redirect_to admin_bulk_action_url(@bulk_action), notice: "Bulk action is running. Check back soon for results."
78
104
  end
79
105
 
106
+ # Reverts a bulk action.
107
+ # @return [void]
80
108
  def revert
81
109
  @bulk_action.revert!
82
110
  @bulk_action.state_machine.transition_to!(:queued)
@@ -87,11 +115,14 @@ module Admin
87
115
  private
88
116
 
89
117
  # Use callbacks to share common setup or constraints between actions.
118
+ # Finds and sets the bulk action based on the provided ID.
119
+ # @return [BulkAction] The found bulk action
90
120
  def set_bulk_action
91
121
  @bulk_action = BulkAction.find(params[:id])
92
122
  end
93
123
 
94
124
  # Only allow a list of trusted parameters through.
125
+ # @return [ActionController::Parameters] The permitted parameters
95
126
  def bulk_action_params
96
127
  params.require(:bulk_action).permit(:name, :scope, :request, :field_name, :field_value)
97
128
  end