Skip to content

Commit f58261e

Browse files
committed
#1250 Make ontology terms clickable
1 parent aa02d1a commit f58261e

7 files changed

Lines changed: 58 additions & 26 deletions

File tree

app/assets/stylesheets/application.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,3 +1111,7 @@ td.day .calendar-text {
11111111
display: flex;
11121112
justify-content: center;
11131113
}
1114+
1115+
.tag-topic, .tag-operation {
1116+
text-decoration: none;
1117+
}

app/assets/stylesheets/masonry.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
border-radius: 8px;
106106
padding: $item-padding-base;
107107
display: block;
108+
position: relative;
108109
transition: $transition-time;
109110

110111
&:hover, &:focus {
@@ -163,6 +164,20 @@
163164
}
164165
}
165166

167+
.link-overlay-main-link {
168+
position: absolute;
169+
top: 0;
170+
left: 0;
171+
bottom: 0;
172+
right: 0;
173+
z-index: 0;
174+
}
175+
176+
.link-overlay-link {
177+
position: relative;
178+
z-index: 1;
179+
}
180+
166181
li.media-item {
167182
list-style-type: none;
168183
}

app/helpers/materials_helper.rb

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,15 @@ def display_attribute(resource, attribute, show_label: true, title: nil, markdow
7171
].any?
7272

7373
value = resource.send(attribute)
74-
if markdown
75-
value = render_markdown(value)
76-
end
74+
value = render_markdown(value) if markdown
7775
if value.present?
78-
if list
79-
value = value.map do |v|
80-
html_escape(block_given? ? yield(v) : v)
81-
end
82-
else
83-
value = html_escape(block_given? ? yield(value) : value)
84-
end
76+
value = if list
77+
value.map do |v|
78+
html_escape(block_given? ? yield(v) : v)
79+
end
80+
else
81+
html_escape(block_given? ? yield(value) : value)
82+
end
8583
end
8684
string = "<p class=\"#{attribute}#{show_label ? ' no-spacing' : ''}\">"
8785
unless value.blank? || value.try(:strip) == 'License Not Specified'
@@ -119,18 +117,26 @@ def embed_youtube(material)
119117
def keywords_and_topics(resource, limit: nil)
120118
tags = []
121119

122-
%i[scientific_topic_names operation_names keywords].each do |field|
123-
tags |= resource.send(field) if resource.respond_to?(field)
120+
if resource.respond_to?(:scientific_topics)
121+
tags += resource.scientific_topics.map do |term|
122+
link_to(term.preferred_label, term.uri, class: 'label label-info tag-topic link-overlay-link', target: '_blank')
123+
end
124124
end
125125

126-
limit_exceeded = limit && (tags.length > limit)
127-
tags = tags.first(limit) if limit
126+
if resource.respond_to?(:operations)
127+
tags += resource.operations.map do |term|
128+
link_to(term.preferred_label, term.uri, class: 'label label-info tag-operation link-overlay-link', target: '_blank')
129+
end
130+
end
128131

129-
elements = tags.map do |tag|
130-
content_tag(:span, tag, class: 'label label-info')
132+
if resource.respond_to?(:keywords)
133+
tags += resource.keywords.map do |tag|
134+
content_tag(:span, tag, class: 'label label-info tag-keyword')
135+
end
131136
end
132-
elements << '&hellip;' if limit_exceeded
133137

134-
elements.join(' ').html_safe
138+
tags = tags.first(limit) if limit
139+
tags << '&hellip;' if limit && (tags.length > limit)
140+
safe_join(tags, ' ')
135141
end
136142
end

app/views/common/_extra_metadata.html.erb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
<%= display_attribute(resource, :contributors) { |values| values.join(', ') } if resource.respond_to?(:contributors) %>
6464
<%= display_attribute(resource, :remote_created_date) if resource.respond_to?(:remote_created_date) %>
6565
<%= display_attribute(resource, :remote_updated_date) if resource.respond_to?(:remote_updated_date) %>
66-
<%= display_attribute(resource, :scientific_topics) { |values| values.map { |x| x.preferred_label }.join(', ') } %>
66+
<%= display_attribute(resource, :scientific_topics) {
67+
|values| safe_join(values.map { |x| link_to(x.preferred_label, x.uri, target: '_blank') }, ', ')
68+
} %>
6769

6870
<% if resource.is_a?(LearningPath) %>
6971
<%= display_attribute(resource, :status) { |value| material_status_title_for_label(value) } %>
@@ -73,5 +75,7 @@
7375
<% end %>
7476

7577
<% if resource.respond_to?(:operations) -%>
76-
<%= display_attribute(resource, :operations) { |values| values.map { |x| x.preferred_label }.join(', ') } %>
78+
<%= display_attribute(resource, :operations) {
79+
|values| safe_join(values.map { |x| link_to(x.preferred_label, x.uri, target: '_blank') }, ', ')
80+
} %>
7781
<% end %>

app/views/events/_event.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<% learning_path_topic_item ||= nil %>
22
<% collection_item ||= learning_path_topic_item %>
33
<li class="masonry-brick media-item long">
4-
<%= link_to event, class: 'link-overlay with-left-icon' do %>
4+
<div class="link-overlay with-left-icon">
5+
<%= link_to '', event, class: 'link-overlay-main-link' %>
56
<%= item_order_badge(collection_item) if collection_item %>
67
<div class="with-left-icon">
78
<div class="icon-container hidden-xs">
@@ -55,5 +56,5 @@
5556
</div>
5657

5758
<%= item_comment(collection_item) if collection_item %>
58-
<% end %>
59+
</div>
5960
</li>

app/views/learning_paths/_learning_path.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<li class="masonry-brick media-item large block-item learning-path-bg-<%= (learning_path.id % 4) + 1 -%>">
2-
<%= link_to learning_path, class: 'link-overlay' do %>
2+
<div class="link-overlay">
3+
<%= link_to '', learning_path, class: 'link-overlay-main-link' %>
34
<%= item_order_badge(collection_item) if defined? collection_item %>
45

56
<div class="masonry-brick-heading">
@@ -34,5 +35,5 @@
3435
</div>
3536

3637
<%= item_comment(collection_item) if defined? collection_item %>
37-
<% end %>
38+
</div>
3839
</li>

app/views/materials/_material.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
end
88
%>
99
<li class="masonry-brick media-item long">
10-
<%= link_to material_path(material, **link_params), class: 'link-overlay' do %>
10+
<div class="link-overlay">
11+
<%= link_to '', material_path(material, **link_params), class: 'link-overlay-main-link' %>
1112
<%= item_order_badge(collection_item) if show_order && collection_item %>
1213

1314
<div class="masonry-brick-heading">
@@ -40,5 +41,5 @@
4041
</div>
4142

4243
<%= item_comment(collection_item) if collection_item %>
43-
<% end %>
44+
</div>
4445
</li>

0 commit comments

Comments
 (0)