Class: GeoblacklightAdmin::ConfigGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/geoblacklight_admin/config_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_activestorageObject



300
301
302
303
304
305
306
307
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 300

def add_activestorage
  append_to_file "app/assets/javascripts/application.js" do
    "
// Required by GBL Admin
//= require activestorage
//= require geoblacklight_admin"
  end
end

#add_api_controllerObject



309
310
311
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 309

def add_api_controller
  copy_file "api_controller.rb", "app/controllers/admin/api_controller.rb"
end

#add_assets_initialierObject



338
339
340
341
342
343
344
345
346
347
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 338

def add_assets_initialier
  append_to_file "config/initializers/assets.rb" do
    "
    # GBL ADMIN
    Rails.application.config.assets.paths << Rails.root.join('node_modules')
    Rails.application.config.assets.precompile += %w( geoblacklight_admin.js )
    Rails.application.config.assets.precompile += %w[application.js]
    Rails.application.config.assets.precompile += %w[application.css]"
  end
end

#add_import_id_facetObject



371
372
373
374
375
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 371

def add_import_id_facet
  inject_into_file "app/controllers/catalog_controller.rb", before: "# Item Relationship Facets" do
    "\nconfig.add_facet_field Settings.FIELDS.B1G_IMPORT_ID, label: 'Import ID', show: false\n"
  end
end

#add_kithe_bulk_loading_serviceObject



349
350
351
352
353
354
355
356
357
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 349

def add_kithe_bulk_loading_service
  prepend_to_file "app/controllers/catalog_controller.rb" do
    "require 'kithe/blacklight_tools/bulk_loading_search_service'\n\n"
  end

  inject_into_file "app/controllers/catalog_controller.rb", after: "include Blacklight::Catalog" do
    "\n  self.search_service_class = Kithe::BlacklightTools::BulkLoadingSearchService"
  end
end

#add_kithe_model_to_solr_documentObject



359
360
361
362
363
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 359

def add_kithe_model_to_solr_document
  inject_into_file "app/models/solr_document.rb", after: "include Geoblacklight::SolrDocument" do
    "\n\nattr_accessor :model"
  end
end

#add_package_jsonObject



330
331
332
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 330

def add_package_json
  copy_file "package.json", "package.json", force: true
end

#add_pagyObject



294
295
296
297
298
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 294

def add_pagy
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
    "  include Pagy::Backend\n" \
  end
end

#add_search_builder_publication_state_concernObject



365
366
367
368
369
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 365

def add_search_builder_publication_state_concern
  inject_into_file "app/models/search_builder.rb", after: "include Geoblacklight::SuppressedRecordsSearchBehavior" do
    "\n      include GeoblacklightAdmin::PublicationStateSearchBehavior"
  end
end

#add_show_sidebarObject



321
322
323
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 321

def add_show_sidebar
  copy_file "_show_sidebar.html.erb", "app/views/catalog/_show_sidebar.html.erb"
end

#add_test_fixture_filesObject

Add test fixture files - Necessary for import background job tests



385
386
387
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 385

def add_test_fixture_files
  copy_file "btaa_sample_records.csv", "test/fixtures/files/btaa_sample_records.csv", force: true
end


313
314
315
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 313

def add_user_util_links
  copy_file "_user_util_links.html.erb", "app/views/shared/_user_util_links.html.erb"
end

#add_vite_rails_configObject



377
378
379
380
381
382
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 377

def add_vite_rails_config
  copy_file "base.html.erb", "app/views/layouts/blacklight/base.html.erb", force: true
  copy_file "vite.config.ts", "vite.config.ts", force: true
  copy_file "config/vite.json", "config/vite.json", force: true
  copy_file "frontend/entrypoints/application.js", "app/javascript/entrypoints/application.js", force: true
end

#bundle_installObject

Run bundle with vite install



390
391
392
393
394
395
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 390

def bundle_install
  Bundler.with_clean_env do
    run "bundle install"
    run "bundle exec vite install"
  end
end

#copy_app_imagesObject



325
326
327
328
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 325

def copy_app_images
  copy_file "images/bookmark-regular.svg", "app/assets/images/bookmark-regular.svg"
  copy_file "images/bookmark-solid.svg", "app/assets/images/bookmark-solid.svg"
end

#copy_catalog_index_viewObject



317
318
319
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 317

def copy_catalog_index_view
  copy_file "views/_index_split_default.html.erb", "app/views/catalog/_index_split_default.html.erb"
end

#copy_json_schemaObject



72
73
74
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 72

def copy_json_schema
  copy_file "config/geomg_aardvark_schema.json", "config/geomg_aardvark_schema.json"
end

#copy_rake_tasksObject



334
335
336
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 334

def copy_rake_tasks
  append_to_file "Rakefile", "require \"geoblacklight_admin/rake_task\"\n"
end

#copy_solrObject



76
77
78
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 76

def copy_solr
  directory "solr", "solr", force: true
end

#create_database_ymlObject



51
52
53
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 51

def create_database_yml
  copy_file "config/database.yml", "config/database.yml", force: true
end

#create_dotenvObject



59
60
61
62
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 59

def create_dotenv
  copy_file ".env.development.example", ".env.development"
  copy_file ".env.development.example", ".env.test"
end

#create_gbl_admin_initializer_filesObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 39

def create_gbl_admin_initializer_files
  copy_file "config/initializers/geoblacklight_admin.rb", "config/initializers/geoblacklight_admin.rb", force: true
  copy_file "config/initializers/devise.rb", "config/initializers/devise.rb", force: true
  copy_file "config/initializers/kithe.rb", "config/initializers/kithe.rb", force: true
  copy_file "config/initializers/mime_types.rb", "config/initializers/mime_types.rb", force: true
  copy_file "config/initializers/pagy.rb", "config/initializers/pagy.rb", force: true
  copy_file "config/initializers/shrine.rb", "config/initializers/shrine.rb", force: true
  copy_file "config/initializers/simple_form.rb", "config/initializers/simple_form.rb", force: true
  copy_file "config/initializers/simple_form_bootstrap.rb", "config/initializers/simple_form_bootstrap.rb", force: true
  copy_file "config/initializers/statesman.rb", "config/initializers/statesman.rb", force: true
end

#create_settings_ymlObject



64
65
66
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 64

def create_settings_yml
  copy_file "config/settings.yml", "config/settings.yml", force: true
end

#create_sidekiq_ymlObject



55
56
57
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 55

def create_sidekiq_yml
  copy_file "config/sidekiq.yml", "config/sidekiq.yml", force: true
end

#create_solr_ymlObject



68
69
70
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 68

def create_solr_yml
  copy_file ".solr_wrapper.yml", ".solr_wrapper.yml", force: true
end

#set_development_mailer_hostObject



283
284
285
286
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 283

def set_development_mailer_host
  mailer_host = "\n  config.action_mailer.default_url_options = { :host => 'localhost:3000' }\n"
  inject_into_file "config/environments/development.rb", mailer_host, after: "config.action_mailer.perform_caching = false"
end

#set_routesObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 80

def set_routes
  gbl_admin_routes = "    ####################\n    # GBL\u2021ADMIN\n\n    # Bulk Actions\n    resources :bulk_actions do\n      patch :run, on: :member\n      patch :revert, on: :member\n    end\n\n    # Users\n    devise_for :users, controllers: {invitations: \"devise/invitations\"}, skip: [:registrations]\n    as :user do\n      get \"/sign_in\" => \"devise/sessions#new\" # custom path to login/sign_in\n      get \"/sign_up\" => \"devise/registrations#new\", :as => \"new_user_registration\" # custom path to sign_up/registration\n      get \"users/edit\" => \"devise/registrations#edit\", :as => \"edit_user_registration\"\n      put \"users\" => \"devise/registrations#update\", :as => \"user_registration\"\n    end\n\n    namespace :admin do\n      # Root\n      root to: \"documents#index\"\n\n      # Assets\n      # Note \"assets\" is Rails reserved word for routing, oops. So we use\n      # asset_files.\n      resources :assets, path: \"asset_files\" do\n        collection do\n          get \"display_attach_form\"\n          post \"attach_files\"\n\n          get \"destroy_all\"\n          post \"destroy_all\"\n        end\n\n        post :sort, on: :collection\n      end\n\n      # Bulk Actions\n      resources :bulk_actions do\n        patch :run, on: :member\n        patch :revert, on: :member\n      end\n\n      # Imports\n      resources :imports do\n        resources :mappings\n        resources :import_documents, only: [:show]\n        patch :run, on: :member\n      end\n\n      # Elements\n      resources :elements do\n        post :sort, on: :collection\n      end\n\n      # Form Elements\n      resources :form_elements do\n        post :sort, on: :collection\n      end\n      resources :form_header, path: :form_elements, controller: :form_elements\n      resources :form_group, path: :form_elements, controller: :form_elements\n      resources :form_control, path: :form_elements, controller: :form_elements\n      resources :form_feature, path: :form_elements, controller: :form_elements\n\n      # Notifications\n      resources :notifications do\n        put \"batch\", on: :collection\n      end\n\n      # Users\n      get \"users/index\"\n\n      # Bookmarks\n      resources :bookmarks\n      delete \"/bookmarks\", to: \"bookmarks#destroy\", as: :bookmarks_destroy_by_fkeys\n\n      # Search controller\n      get \"/search\" => \"search#index\"\n      \n      # AdvancedSearch controller\n      get '/advanced_search' => 'advanced_search#index', constraints: lambda { |req| req.format == :json }\n      get '/advanced_search/facets' => 'advanced_search#facets', constraints: lambda { |req| req.format == :json }\n      get '/advanced_search/facet/:id' => 'advanced_search#facet', constraints: lambda { |req| req.format == :json }, as: 'advanced_search_facet'\n\n      # Ids controller\n      get '/api/ids' => 'ids#index', constraints: lambda { |req| req.format == :json }\n      get '/api' => 'api#index', constraints: lambda { |req| req.format == :json }\n      get '/api/fetch' => 'api#fetch', constraints: lambda { |req| req.format == :json }\n      get '/api/facet/:id' => 'api#facet', constraints: lambda { |req| req.format == :json }\n\n      # Documents\n      resources :documents do\n        get \"admin\"\n        get \"versions\"\n\n        # DocumentAccesses\n        resources :document_accesses, path: \"access\" do\n          collection do\n            get \"import\"\n            post \"import\"\n\n            get \"destroy_all\"\n            post \"destroy_all\"\n          end\n        end\n\n        # DocumentDownloads\n        resources :document_downloads, path: \"downloads\" do\n          collection do\n            get \"import\"\n            post \"import\"\n\n            get \"destroy_all\"\n            post \"destroy_all\"\n          end\n        end\n\n        # Document Assets\n        resources :document_assets, path: \"assets\" do\n          collection do\n            get \"display_attach_form\"\n            post \"attach_files\"\n\n            get \"destroy_all\"\n            post \"destroy_all\"\n          end\n        end\n\n        collection do\n          get \"fetch\"\n        end\n      end\n\n      # Document Accesses\n      resources :document_accesses, path: \"access\" do\n        collection do\n          get \"import\"\n          post \"import\"\n\n          get \"destroy_all\"\n          post \"destroy_all\"\n        end\n      end\n\n      # Document Downloads\n      resources :document_downloads, path: \"downloads\" do\n        collection do\n          get \"import\"\n          post \"import\"\n\n          get \"destroy_all\"\n          post \"destroy_all\"\n        end\n      end\n\n      # Document Assets\n      resources :document_assets, path: \"assets\" do\n        collection do\n          get \"display_attach_form\"\n          post \"attach_files\"\n\n          get \"destroy_all\"\n          post \"destroy_all\"\n        end\n      end\n\n      # Assets\n      get \"/asset_files/ingest\", to: \"assets#display_attach_form\", as: \"assets_ingest\"\n      post \"/asset_files/ingest\", to: \"assets#attach_files\"\n      \n      # DocumentAssets\n      get \"/documents/:id/ingest\", to: \"document_assets#display_attach_form\", as: \"asset_ingest\"\n      post \"/documents/:id/ingest\", to: \"document_assets#attach_files\"\n      \n      # Asset Direct Upload\n      mount Kithe::AssetUploader.upload_endpoint(:cache) => \"/direct_upload\", :as => :direct_app_upload\n\n      resources :collections, except: [:show]\n\n      # Note \"assets\" is Rails reserved word for routing, oops. So we use\n      # asset_files.\n      resources :assets, path: \"asset_files\", except: [:new, :create] do\n        member do\n          put \"convert_to_child_work\"\n        end\n      end\n\n      # @TODO\n      # mount Qa::Engine => \"/authorities\"\n      mount ActionCable.server => \"/cable\"\n\n      # @TODO\n      # authenticate :user, ->(user) { user } do\n        # mount Blazer::Engine, at: \"blazer\"\n      # end\n    end\n  ROUTES\n\n  inject_into_file \"config/routes.rb\", gbl_admin_routes, before: /^end/\nend\n"

#set_seedsObject



288
289
290
291
292
# File 'lib/generators/geoblacklight_admin/config_generator.rb', line 288

def set_seeds
  append_to_file "db/seeds.rb" do
    "GeoblacklightAdmin::Engine.load_seed"
  end
end