Skip to content

Commit

Permalink
Add Link to Search Configuration
Browse files Browse the repository at this point in the history
Closes #598
  • Loading branch information
tpendragon committed Sep 25, 2019
1 parent 9da1da5 commit 28df356
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Rails/OutputSafety:
- 'app/processors/custom_field_rendering.rb'
- 'app/presenters/rtl_index_presenter.rb'
- 'app/presenters/rtl_show_presenter.rb'
- 'spec/presenters/rtl_show_presenter_spec.rb'

Rails/DynamicFindBy:
Exclude:
Expand All @@ -135,6 +136,7 @@ RSpec/ExampleLength:
- 'spec/requests/catalog_spec.rb'
- 'spec/features/catalog_show_spec.rb'
- 'spec/features/**/*.rb'
- 'spec/views/**/*.rb'

RSpec/ExampleWording:
CustomTransform:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def exhibit_configuration_index_params
views = @blacklight_configuration.default_blacklight_config.view.keys | [:show]

@blacklight_configuration.blacklight_config.index_fields.keys.each_with_object({}) do |element, result|
result[element] = (%i[enabled label weight text_area] | views)
result[element] = (%i[enabled label weight text_area link_to_search] | views)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/rtl_show_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class RTLShowPresenter < ::Blacklight::ShowPresenter
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::SanitizeHelper
include ActionView::Context

def field_value_separator
Expand All @@ -18,7 +19,7 @@ def field_value_separator
def field_value(field, options = {})
tags = super.split(field_value_separator).collect do |value|
value = collection_value(value) if field.to_s.include?("readonly_collections_ssim")
content_tag(:li, value.html_safe, dir: value.dir)
content_tag(:li, value.html_safe, dir: strip_tags(value).dir)
end

content_tag(:ul) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<% available_view_fields.keys.each do |type| %>
<td class="checkbox-cell text-center"><%= field.check_box type, inline: true, checked: config.send(type), label: "" %></td>
<% end %>
<td class="checkbox-cell text-center"><%= field.check_box :link_to_search, {inline: true, checked: config.link_to_search.present?, label: ""}, config.field, false%></td>
<% end %>
</tr>
4 changes: 4 additions & 0 deletions app/views/spotlight/metadata_configurations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<%= select_deselect_button %>
</th>
<% end %>
<th class="text-center">
<div>Link to Search</div>
<%= select_deselect_button %>
</th>
</tr>
</thead>
<tbody class="metadata_fields dd dd-list" data-behavior="nestable" data-max-depth="1" data-list-node-name="tbody" data-item-node-name="tr" data-expand-btn-HTML=" " data-collapse-btn-HTML=" ">
Expand Down
20 changes: 20 additions & 0 deletions spec/presenters/rtl_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@
)
end

describe "link_to_search" do
let(:view_context) { double(blacklight_config: blacklight_config, search_state: double(reset: double(add_facet_params: true)), search_action_path: "/exhibit/catalog") }
let(:blacklight_config) do
double(
show_fields: { field:
double(highlight: false, accessor: nil, default: nil, field: :field, text_area: false, helper_method: nil, link_to_search: "field", itemprop: nil, separator_options: nil, :separator_options= => nil) },
view_config: double(title_field: :title, html_title_field: nil),
facet_fields: { "exhibit_tags" => double(field: "tags_ssim") }
)
end

before do
allow(view_context).to receive(:link_to).with("بي", "/exhibit/catalog").and_return("<a link>بي</a link>".html_safe)
end

it "links each individual property" do
expect(presenter.field_value(:field)).to eq "<ul><li dir=\"rtl\"><a link>بي</a link></li></ul>"
end
end

describe "#field_value" do
context "when given a RTL string" do
it "renders it as a RTL list item" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@

expect(rendered).to have_selector '.import-tooltip'
end

it "renders a field to set link_to_search" do
Spotlight::CustomField.create!(exhibit: exhibit, slug: "two", field: "two", label: "two", field_type: "vocab", readonly_field: false)
allow(view).to receive(:index_field_label).with(nil, 'two').and_return 'Some label'
render partial: p, locals: { key: 'two', config: facet_field, f: builder }

expect(rendered).to have_selector "input[type=checkbox][name='z[two][link_to_search]']"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
expect(rendered).to have_content "one"
expect(rendered).not_to have_content "two"
expect(rendered).to have_selector "th", text: "Text Area"
expect(rendered).to have_selector "th", text: "Link to Search"
end
end
end

0 comments on commit 28df356

Please sign in to comment.