Skip to content

Commit 539eb30

Browse files
committed
Display origin info for resources with an origin_uri
1 parent 252fd7a commit 539eb30

10 files changed

Lines changed: 63 additions & 2 deletions

File tree

app/assets/stylesheets/application.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ sup {
690690
margin-left: 5px;
691691
}
692692

693+
.exchange-icon {
694+
color: $brand-primary;
695+
margin-left: 5px;
696+
}
697+
693698
.days_ago_text {
694699
color: grey;
695700
font-style: italic;

app/helpers/application_helper.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module ApplicationHelper
2929
private: { icon: 'fa-eye-slash', message: 'This resource is private' },
3030
missing: { icon: 'fa-chain-broken', message: 'This resource has been offline for over three days' },
3131
check: { icon: 'fa-check', message: 'This resource is enabled' },
32-
cross: { icon: 'fa-times', message: 'This resource has been disabled' }
32+
cross: { icon: 'fa-times', message: 'This resource has been disabled' },
33+
exchanged: { icon: 'fa-exchange', message: 'This resource originated from another TeSS registry' },
3334
}.freeze
3435

3536
# Countries that have priority in the country selection menu. Using ISO 3166-1 Alpha2 code.
@@ -93,6 +94,11 @@ def event_status_icon(event, size = nil)
9394
end
9495
end
9596

97+
def exchange_icon(resource, size = nil)
98+
return unless resource.origin_uri
99+
"<span class='exchange-icon pull-right'>#{icon_for(:exchanged, size)}</span>".html_safe
100+
end
101+
96102
def icon_for(type, size = nil, options = {})
97103
options[:class] ||= "info-icon#{'-' + size.to_s if size}"
98104
"<i class=\"fa #{ICONS[type][:icon]} has-tooltip #{options[:class]}\"

app/views/common/_origin_info.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<% unless resource.origin_uri.blank? %>
2+
<h4 class="nav-heading"><%= t('exchange.title') %></h4>
3+
<div class="nav-block" id="origin-info">
4+
<p>
5+
<%= t('exchange.info', resource_type: resource.model_name.human) %>
6+
</p>
7+
8+
<p>
9+
<%= external_link_button t('exchange.link'), resource.origin_uri %>
10+
</p>
11+
</div>
12+
<% end %>

app/views/events/_event.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<% end %>
2020

2121
<%= event_status_icon(event) %>
22+
<%= exchange_icon(event) %>
2223
</div>
2324
<% if event.event_types.any? %>
2425
<% event.event_types.each do |t| %>

app/views/events/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="wrapper collapsing-wrapper">
22
<%# SIDEBAR %>
33
<div class="collapsing-sidebar" id="sidebar">
4+
<%= render partial: 'common/origin_info', locals: { resource: @event } %>
45
<%= render partial: 'content_providers/partials/content_provider_info', locals: { content_provider: @event.content_provider } %>
56
<%= render partial: "nodes/partials/associated_node_info", locals: { associated_nodes: @event.associated_nodes } %>
67
<%= render(partial: 'users/partials/user_info', locals: { user: @event.user }) if current_user.try(:is_admin?) %>

app/views/materials/_material.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<%= scrape_status_icon(material) %>
1818
<%= suggestion_icon(material) %>
1919
<% end %>
20+
<%= exchange_icon(material) %>
2021
</div>
2122
<div class="sub-heading">
2223
<%= display_attribute_no_label(material, :resource_type) { |values| values.join(', ') } %>

app/views/materials/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<%= render partial: 'learning_paths/partials/navigation',
44
locals: { topic_link: @learning_path_topic_link,
55
topic_item: @learning_path_topic_item } if @learning_path_topic_link && @learning_path_topic_item %>
6+
<%= render partial: 'common/origin_info', locals: { resource: @material } %>
67
<%= render partial: 'content_providers/partials/content_provider_info', locals: { content_provider: @material.content_provider } %>
78
<%= render partial: 'nodes/partials/associated_node_info', locals: { associated_nodes: @material.associated_nodes } %>
89
<%= render(partial: 'users/partials/user_info', locals: { user: @material.user }) if current_user.try(:is_admin?) %>

config/locales/en.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,4 +1188,8 @@ en:
11881188
any: Any time
11891189
week: Within the last week
11901190
month: Within the last month
1191-
year: Within the last year
1191+
year: Within the last year
1192+
exchange:
1193+
title: Original entry
1194+
info: "This %{resource_type} originated from another TeSS registry. For complete, up-to-date information, please visit the original entry:"
1195+
link: Go to original entry

test/controllers/events_controller_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,4 +1704,19 @@ class EventsControllerTest < ActionController::TestCase
17041704
end
17051705
end
17061706
end
1707+
1708+
test 'should link back to original entry if origin URI set' do
1709+
get :show, params: { id: @event }
1710+
assert_response :success
1711+
1712+
assert_select '#origin-info', count: 0
1713+
1714+
uri = 'https://some-tess-instance.org/events/123'
1715+
@event.update(origin_uri: uri)
1716+
1717+
get :show, params: { id: @event }
1718+
assert_response :success
1719+
1720+
assert_select '#origin-info a[href=?]', uri
1721+
end
17071722
end

test/controllers/materials_controller_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,4 +1706,19 @@ class MaterialsControllerTest < ActionController::TestCase
17061706
assert_select 'p.scientific_topics a[href="http://edamontology.org/topic_0622"]', text: 'Genomics'
17071707
assert_select 'p.operations a[href="http://edamontology.org/operation_0292"]', text: 'Sequence alignment'
17081708
end
1709+
1710+
test 'should link back to original entry if origin URI set' do
1711+
get :show, params: { id: @material }
1712+
assert_response :success
1713+
1714+
assert_select '#origin-info', count: 0
1715+
1716+
uri = 'https://some-tess-instance.org/materials/123'
1717+
@material.update(origin_uri: uri)
1718+
1719+
get :show, params: { id: @material }
1720+
assert_response :success
1721+
1722+
assert_select '#origin-info a[href=?]', uri
1723+
end
17091724
end

0 commit comments

Comments
 (0)