From 70280fadabf9a585c07a1c4a1e24136918dff98f Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Wed, 21 Dec 2016 13:53:51 -0800 Subject: [PATCH] Display an icon for imported fields in metadata. --- app/assets/javascripts/pom_boot.es6 | 5 +++ app/assets/stylesheets/application.scss | 4 +++ .../_metadata_field.html.erb | 19 ++++++++++ .../_metadata_field.html.erb_spec.rb | 35 +++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 app/views/spotlight/metadata_configurations/_metadata_field.html.erb create mode 100644 spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb diff --git a/app/assets/javascripts/pom_boot.es6 b/app/assets/javascripts/pom_boot.es6 index 538349d7..76ead7c8 100644 --- a/app/assets/javascripts/pom_boot.es6 +++ b/app/assets/javascripts/pom_boot.es6 @@ -3,9 +3,14 @@ export default class Initializer { constructor() { this.initialize_blacklight_oembed() this.universal_viewer = new UniversalViewer + this.initialize_tooltips() } initialize_blacklight_oembed() { $("[data-embed-url]").oEmbed() } + + initialize_tooltips() { + $('[data-toggle="tooltip"]').tooltip() + } } diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index a7992f43..f0227f00 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -53,3 +53,7 @@ li[dir=rtl] { margin-top: -1px; } } + +.import-tooltip { + margin-left: 10px; +} diff --git a/app/views/spotlight/metadata_configurations/_metadata_field.html.erb b/app/views/spotlight/metadata_configurations/_metadata_field.html.erb new file mode 100644 index 00000000..706251b5 --- /dev/null +++ b/app/views/spotlight/metadata_configurations/_metadata_field.html.erb @@ -0,0 +1,19 @@ + + <%= f.fields_for key do |field| %> + + <%= field.hidden_field :weight, 'data-property' => 'weight' %> +
+
<%= t :drag %>
+ <%= index_field_label(nil, key) %> + <%- if @exhibit.custom_fields.vocab.map(&:field).include?(key) %> + + <% end %> + <%= field.hidden_field :label, value: index_field_label(nil, key), class: 'form-control input-sm', data: {:"edit-field-target" => 'true'} %> +
+ + <%= field.check_box :show, inline: true, checked: config.show, label: "" %> + <% available_view_fields.keys.each do |type| %> + <%= field.check_box type, inline: true, checked: config.send(type), label: "" %> + <% end %> + <% end %> + diff --git a/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb b/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb new file mode 100644 index 00000000..ca8c14c2 --- /dev/null +++ b/spec/views/spotlight/metadata_configurations/_metadata_field.html.erb_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe 'spotlight/metadata_configurations/_metadata_field', type: :view do + let(:exhibit) { FactoryGirl.create(:exhibit) } + let(:p) { 'spotlight/metadata_configurations/metadata_field.html.erb' } + before do + assign(:exhibit, exhibit) + assign(:blacklight_configuration, exhibit.blacklight_configuration) + allow(view).to receive_messages( + current_exhibit: exhibit, + blacklight_config: exhibit.blacklight_configuration, + available_view_fields: { some_view_type: 1, another_view_type: 2 }, + select_deselect_button: nil + ) + end + + let(:facet_field) { Blacklight::Configuration::FacetField.new } + let(:builder) { ActionView::Helpers::FormBuilder.new 'z', nil, view, {} } + + it 'renders a tooltip for imported fields' do + Spotlight::CustomField.create!(exhibit: exhibit, slug: "two", field: "two", label: "two", field_type: "vocab", readonly_field: true) + 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 '.import-tooltip' + end + + it "doesn't render a tooltip for writeable fields" 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 '.import-tooltip' + end +end