Skip to content

Commit

Permalink
Merge pull request #510 from geoblacklight/modify-routes
Browse files Browse the repository at this point in the history
Modify routes to use exportable, and use rails rendering engine
  • Loading branch information
sgbalogh committed Oct 26, 2016
2 parents 8c10ed2 + 54f5f29 commit fe5e43b
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 63 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/geoblacklight/modules/relations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Blacklight.onLoad(function () {
$.ajax({
url: relation_url,
type: 'GET',
dataType: 'html',
success: function (data) {
$elem.append($(data).hide().fadeIn(200));
}
Expand Down
13 changes: 3 additions & 10 deletions app/controllers/relation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@ class RelationController < ApplicationController
include Blacklight::SearchHelper
copy_blacklight_config_from(CatalogController)

def relations
@relation_response = Geoblacklight::Relation::RelationResponse.new(params[:id], repository)
respond_to do |format|
format.json do
render json: @relation_response.relations
end
format.html do
render 'catalog/relations', layout: false
end
end
def index
@relations = Geoblacklight::Relation::RelationResponse.new(params[:id], repository)
render layout: !request.xhr?
end
end
39 changes: 0 additions & 39 deletions app/views/catalog/relations.html.erb

This file was deleted.

8 changes: 8 additions & 0 deletions app/views/relation/_ancestors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<b><%= t('geoblacklight.relations.ancestor') %></b>
<% @relations.ancestors['docs'].each do |ancestor| %>
<li>
<%= link_to solr_document_path(ancestor['layer_slug_s']) do %>
<span class='geoblacklight geoblacklight-relations-ancestor'></span> <%= ancestor['dc_title_s'] %>
<% end %>
</li>
<% end %>
15 changes: 15 additions & 0 deletions app/views/relation/_descendants.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<b><%= t('geoblacklight.relations.descendant', count: @relations.descendants['numFound']) %></b>
<% @relations.descendants['docs'][0..2].each do |descendant| %>
<li>
<%= link_to solr_document_path(descendant['layer_slug_s']) do %>
<span class='geoblacklight geoblacklight-relations-descendant'></span> <%= descendant['dc_title_s'] %>
<% end %>
</li>
<% end %>
<% unless (@relations.descendants['numFound'].to_i <= 3) %>
<li>
<%= link_to search_catalog_path({f: {"#{Settings.FIELDS.SOURCE}" => [@relations.search_id]}}) do %>
<%= t('geoblacklight.relations.browse_all', count: @relations.descendants['numFound']) %>
<% end %>
</li>
<% end %>
13 changes: 13 additions & 0 deletions app/views/relation/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% unless @relations.empty? %>
<div class="panel panel-default show-tools">
<div class="panel-heading">
<%= t('geoblacklight.relations.title') %>
</div>
<div class="panel-body">
<ul class="nav">
<%= render 'ancestors' unless @relations.ancestors['numFound'].to_i == 0 %>
<%= render 'descendants' unless @relations.descendants['numFound'].to_i == 0 %>
</ul>
</div>
</div>
<% end %>
3 changes: 3 additions & 0 deletions app/views/relation/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
json.ancestors@relations.ancestors
json.descendants @relations.descendants
json.current_doc @relations.search_id
4 changes: 3 additions & 1 deletion config/locales/geoblacklight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ en:
data_dictionary: 'Documentation'
relations:
ancestor: 'Source Datasets'
descendant: 'Derived Datasets'
descendant: 'Derived Datasets (%{count})'
browse_all: "Browse all %{count} records..."
title: 'Data Relations'
2 changes: 0 additions & 2 deletions lib/generators/geoblacklight/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def inject_geoblacklight_routes
concerns :gbl_downloadable
end
resources :download, only: [:show]
get '/catalog/:id/relations' => 'relation#relations', as: :relations
EOF
end

Expand Down
17 changes: 10 additions & 7 deletions lib/geoblacklight/relation/relation_response.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
module Geoblacklight
module Relation
class RelationResponse
attr_reader :relations
attr_reader :search_id
def initialize(id, repository)
@search_id = id
@repository = repository
@relations = {
ancestors: Geoblacklight::Relation::Ancestors.new(@search_id, @repository).results,
descendants: Geoblacklight::Relation::Descendants.new(@search_id, @repository).results,
current_doc: id
}
end

def ancestors
@ancestors ||= Geoblacklight::Relation::Ancestors.new(@search_id, @repository).results
end

def descendants
@descendants ||= Geoblacklight::Relation::Descendants.new(@search_id, @repository).results
end

def empty?
!(@relations[:ancestors]['numFound'] > 0 || @relations[:descendants]['numFound'] > 0)
!(ancestors['numFound'] > 0 || descendants['numFound'] > 0)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/geoblacklight/routes/exportable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def call(mapper, _options = {})
mapper.member do
mapper.get 'web_services'
mapper.get 'metadata'
mapper.get 'relations' => 'relation#index'
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
}
end
scenario 'Record with dc_source_sm value(s) should have parent(s)' do
visit relations_path('nyu_2451_34502')
visit relations_solr_document_path('nyu_2451_34502')
expect(page).to have_css('ul b', text: 'Source Datasets')
end

scenario 'Record that is pointed to by others should have children' do
visit relations_path('nyu_2451_34635')
visit relations_solr_document_path('nyu_2451_34635')
expect(page).to have_css('ul b', text: 'Derived Datasets')
end

scenario 'Relations should respond to json' do
visit relations_path('nyu_2451_34635', format: 'json')
visit relations_solr_document_path('nyu_2451_34635', format: 'json')
expect(page.body).to eq(expected_json_resp.to_json)
end

Expand Down

0 comments on commit fe5e43b

Please sign in to comment.