Skip to content

Commit ce551b3

Browse files
authored
Adds Full-Text Search Indexing button to works' show page. (#2189)
* Adds Full-Text Search Indexing button to works' show page. * Add testing.
1 parent 76b9826 commit ce551b3

9 files changed

+80
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.second-row-buttons {
2+
form {padding-left: 0.5rem;}
3+
display: inline-flex;
4+
margin: 0;
5+
}

app/assets/stylesheets/curate.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@import 'search_results';
22
@import 'archivesspace_button';
3+
@import 'work_show_page';
34

45
.ui-autocomplete-loading {
56
background: #fff url("/assets/loading.gif") right center no-repeat;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class FullTextIndexingController < ApplicationController
4+
before_action :authenticate_user!
5+
6+
def full_text_index
7+
CompileFullTextJob.perform_later(work_id: params[:work_id], user_id: params[:user_id].to_i)
8+
redirect_to hyrax_curate_generic_work_path(params[:work_id]), notice: "Full-Text Indexing has been queued for this work."
9+
end
10+
end

app/views/hyrax/base/_show_actions.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
<% end %>
3636
<% if current_user.admin? %>
3737
<%= link_to t('.delete'), [main_app, presenter], class: 'btn btn-danger', data: { confirm: t('.confirm_delete', work_type: presenter.human_readable_type) }, method: :delete %>
38-
<div><%= button_to t('.regen_manifest'), "/concern/curate_generic_works/#{@presenter.id}/regen_manifest", class: 'btn btn-primary' %></div>
38+
<div class="row second-row-buttons">
39+
<%= button_to t('.regen_manifest'), "/concern/curate_generic_works/#{@presenter.id}/regen_manifest", class: 'btn btn-primary' %>
40+
<%= button_to 'Index for Full-Text Search', "/concern/curate_generic_works/#{@presenter.id}/full_text_index?user_id=#{current_user.id}", class: 'btn btn-primary' %>
41+
</div>
3942
<% end %>
4043
<% end %>
4144
</div>

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
post "/concern/file_sets/:file_set_id/clean_up", to: "derivatives#clean_up"
7070
post '/concern/file_sets/:file_set_id/re_characterize', to: 'characterization#re_characterize', as: 'file_set_re_characterization'
7171
post "/concern/curate_generic_works/:work_id/regen_manifest", to: "manifest_regeneration#regen_manifest", as: 'regen_manifest'
72+
post "/concern/curate_generic_works/:work_id/full_text_index", to: "full_text_indexing#full_text_index", as: 'full_text_index'
7273

7374
# Deprecation warning: Zizia will be removed with Curate v3.
7475
get 'csv_import_details/index'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe FullTextIndexingController, type: :controller, clean: true do
6+
let(:admin) { FactoryBot.create(:admin) }
7+
let(:work) { FactoryBot.create(:public_generic_work, user: admin) }
8+
9+
context "when signed in" do
10+
describe "POST full_text_index" do
11+
before do
12+
sign_in admin
13+
end
14+
15+
it "queues up compile full text job" do
16+
expect(CompileFullTextJob).to receive(:perform_later).with(work_id: work.id, user_id: admin.id)
17+
post :full_text_index, params: { work_id: work.id, user_id: admin.id }, xhr: true
18+
expect(response).to be_successful
19+
end
20+
end
21+
end
22+
23+
context "when not signed in" do
24+
describe "POST full_text_index" do
25+
it "returns 401" do
26+
post :full_text_index, params: { work_id: work.id, user_id: admin.id }, xhr: true
27+
expect(response.code).to eq '401'
28+
end
29+
end
30+
end
31+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe "routes for full-text indexing", type: :routing do
6+
it "routes full-text indexing requests to the full_text_indexing#full_text_index controller" do
7+
expect(post("/concern/curate_generic_works/1/full_text_index?user_id=1"))
8+
.to route_to(
9+
"controller" => "full_text_indexing",
10+
"action" => "full_text_index",
11+
"work_id" => "1",
12+
"user_id" => "1"
13+
)
14+
end
15+
end

spec/spec_helper.rb

+3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
require 'coveralls'
44
require 'active_fedora/cleaner'
55
require 'webmock/rspec'
6+
require 'webdrivers/chromedriver'
7+
68
WebMock.disable_net_connect!(allow: [
79
'127.0.0.1',
810
'chromedriver.storage.googleapis.com',
911
'id.loc.gov'
1012
],
1113
net_http_connect_on_start: true)
1214
Coveralls.wear!('rails')
15+
Webdrivers::Chromedriver.required_version = "114.0.5735.90" unless ENV['CI']
1316
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
1417
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
1518
# The generated `.rspec` file contains `--require spec_helper` which will cause

spec/system/viewing_a_work_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@
143143
expect(page).to have_selector("input[value='delete_all']", visible: false)
144144
expect(page).to have_css('button', text: 'Add to collection')
145145
end
146+
147+
it 'has a full-text search indexing button' do
148+
visit "/concern/curate_generic_works/#{user_work.id}"
149+
expect(page).to have_selector('input[value="Index for Full-Text Search"]')
150+
end
146151
end
147152

148153
context 'when logged in as a non-admin user' do
@@ -177,6 +182,11 @@
177182
expect(page).not_to have_css('button', text: 'Add to collection')
178183
end
179184

185+
it 'does not have a full-text search indexing button' do
186+
visit "/concern/curate_generic_works/#{user_work.id}"
187+
expect(page).not_to have_selector('input[value="Index for Full-Text Search"]')
188+
end
189+
180190
context 'viewer role' do
181191
let(:user) do
182192
User.create(

0 commit comments

Comments
 (0)