Skip to content

Commit

Permalink
Merge pull request #890 from sul-dlss/metadata-show-partial
Browse files Browse the repository at this point in the history
Metadata show partial + basic default mods rendering
  • Loading branch information
aeschylus authored Nov 15, 2017
2 parents 1d5f594 + 8394518 commit 157df09
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ gem 'bibtex-ruby'
gem 'citeproc-ruby'
gem 'csl-styles'
gem 'acts-as-taggable-on'
gem 'mods_display'
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ GEM
bibtex-ruby (4.4.4)
latex-decode (~> 0.0)
bindex (0.5.0)
blacklight (6.11.2)
blacklight (6.12.0)
bootstrap-sass (~> 3.2)
deprecation
globalid
Expand Down Expand Up @@ -139,7 +139,7 @@ GEM
bundler (~> 1.2)
thor (~> 0.18)
byebug (9.1.0)
cancancan (2.1.0)
cancancan (2.1.1)
capistrano (3.10.0)
airbrussh (>= 1.0.0)
i18n
Expand Down Expand Up @@ -208,7 +208,7 @@ GEM
tins (~> 1.6)
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.2)
crass (1.0.3)
csl (1.4.5)
namae (~> 0.7)
csl-styles (1.0.1.8)
Expand Down Expand Up @@ -383,6 +383,9 @@ GEM
iso-639
nokogiri
nom-xml (~> 0.6.0)
mods_display (0.4.1)
i18n
stanford-mods (~> 2.1)
multi_json (1.12.2)
multi_xml (0.6.0)
multipart-post (2.0.0)
Expand Down Expand Up @@ -655,7 +658,7 @@ GEM
hashdiff
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
websocket-extensions (0.1.3)
whenever (0.9.7)
chronic (>= 0.6.3)
xml-simple (1.1.5)
Expand Down Expand Up @@ -706,6 +709,7 @@ DEPENDENCIES
jsonpath
listen (>= 3.0.5, < 3.2)
mirador_rails
mods_display
mysql2 (~> 0.4.4)
net-http-persistent (< 3)
newrelic_rpm
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
@import "spotlight";
@import "sul_theme";
@import "viewers";
@import "modules/view_metadata";
16 changes: 16 additions & 0 deletions app/assets/stylesheets/modules/view_metadata.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// .view-in-modal is a helper class used to show content in the modal view only
// useful for modal close buttons and other stuff

.view-metadata {
.view-in-modal {
display: none;
}
}

#ajax-modal {
.view-metadata {
.view-in-modal {
display: block;
}
}
}
16 changes: 16 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class CatalogController < ApplicationController
include BlacklightAdvancedSearch::Controller
helper Openseadragon::OpenseadragonHelper
include ModsDisplay::ControllerExtension

include Blacklight::Catalog

Expand Down Expand Up @@ -65,6 +66,7 @@ class CatalogController < ApplicationController
config.show.tile_source_field = :content_metadata_image_iiif_info_ssm

config.show.partials.insert(1, :viewer)
config.show.partials << :metadata_button
config.show.partials.unshift :bibliography_buttons
config.show.partials << :bibliography
config.show.partials << :cited_documents
Expand Down Expand Up @@ -331,6 +333,20 @@ class CatalogController < ApplicationController
config.add_sort_field 'title_sort asc, pub_year_isi desc', label: 'title'
end

##
# A simplification of Blacklight's `Blacklight::CatalogController#show` and
# `Blacklight:DefaultComponentConfiguration#add_show_tools_partial` method for
# our `metadata` which is not defined as a "Blacklight show tool".
# https://github.com/projectblacklight/blacklight/blob/v6.12.0/app/controllers/concerns/blacklight/default_component_configuration.rb#L42-L73
def metadata
@response, @document = fetch params[:id]
respond_to do |format|
format.html do
return render layout: false if request.xhr?
end
end
end

# JSON API queries should not trigger new search histories
def start_new_search_session?
super && params[:format] != 'json'
Expand Down
5 changes: 5 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SolrDocument
include ManifestConcern

include CanvasConcern
include ModsDisplay::ModelExtension

# self.unique_key = 'id'

Expand All @@ -34,4 +35,8 @@ class SolrDocument
use_extension(ModsDocument) do |document|
document[:modsxml]
end

mods_xml_source do |model|
model.fetch(:modsxml)
end
end
1 change: 1 addition & 0 deletions app/views/catalog/_metadata.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render_mods_display(@document).to_html.html_safe %>
12 changes: 12 additions & 0 deletions app/views/catalog/_metadata_button_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class='container'>
<div class='row'>
<% # Using the Bootstrap container/row/col structure here to easily get this on its own line %>
<div class='col-md-12'>
<%= link_to 'View all metadata »',
metadata_exhibit_solr_document_path(current_exhibit, document),
data: { ajax_modal: 'trigger' },
class: 'btn btn-default'
%>
</div>
</div>
</div>
12 changes: 12 additions & 0 deletions app/views/catalog/metadata.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class='view-metadata'>
<div class='modal-header'>
<button type='button' class='ajax-modal-close close' data-dismiss='modal' aria-hidden='true'>×</button>
<h3 class='modal-title'>Metadata: <%= presenter(@document).heading %></h3>
</div>
<div class='modal-body'>
<%= render partial: 'metadata' %>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default view-in-modal pull-right' data-dismiss='modal'>Close</button>
</div>
</div>
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@
resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog'

mount Spotlight::Engine, at: '/'
concern :exportable, Blacklight::Routes::Exportable.new

resources :exhibits, path: '/', only: [] do
resource :dor_harvester, controller: :"dor_harvester", only: [:create, :update]
resource :bibliography_resources, only: [:create, :update]
resource :viewers, only: [:create, :edit, :update]

resources :solr_documents, only: [], path: '/catalog', controller: 'catalog' do
concerns :exportable

member do
get 'metadata'
end
end
end

mount MiradorRails::Engine, at: MiradorRails::Engine.locales_mount_path
Expand Down
26 changes: 26 additions & 0 deletions spec/features/metadata_display_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.feature 'Metadata display' do
let(:exhibit) { create(:exhibit, slug: 'default-exhibit') }

before do
visit spotlight.exhibit_solr_document_path(exhibit_id: exhibit.slug, id: 'gk885tn1705')
end

it 'view metadata link links through to page' do
click_link 'View all metadata »'
expect(page).to have_css 'h3', text: 'Metadata: Afrique Physique.'
expect(page).to have_css 'dt', text: 'Title'
expect(page).to have_css 'dd', text: 'Afrique Physique.'
end
it 'opens view metadata in modal', js: true do
click_link 'View all metadata »'
within '#ajax-modal' do
expect(page).to have_css 'h3', text: 'Metadata: Afrique Physique.'
expect(page).to have_css 'dt', text: 'Title'
expect(page).to have_css 'dd', text: 'Afrique Physique.'
end
end
end

0 comments on commit 157df09

Please sign in to comment.