Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ div.wrapper {

#content {
flex-grow: 1;
overflow: hidden;
}

#sidebar {
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/spaces_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ def spaces_info
I18n.t('info.spaces.description')
end

def space_tag(resource)
if TeSS::Config.feature['spaces'] && resource.space && !resource.space.default? && resource.space != current_space
content_tag(:span, class: 'label label-info space-tag', style: 'position: absolute; right: -5px; top: -5px;') do
content_tag(:i, '', class: 'fa fa-share-square') + ' ' + resource.space.title
end
end
end

def space_feature_options
Space::FEATURES.select do |f|
TeSS::Config.feature[f]
Expand Down
1 change: 1 addition & 0 deletions app/views/collections/_collection.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<li class="masonry-brick media-item long">
<%= space_tag(collection) %>
<%= link_to collection, class: 'link-overlay' do %>
<h4><%= title_with_privacy(collection) %></h4>

Expand Down
1 change: 1 addition & 0 deletions app/views/collections/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="wrapper collapsing-wrapper">
<div class="collapsing-sidebar" id="sidebar">
<%= render partial: 'common/space_info', locals: { resource: @collection } %>
<%= render partial: 'collections/partials/collection_info', locals: { collection: @collection } %>
</div>

Expand Down
18 changes: 18 additions & 0 deletions app/views/common/_space_info.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% space = resource.space %>
<% if TeSS::Config.feature['spaces'] && space && !space.default? && space != current_space %>
<% theme_colour = TeSS::Config.themes[space.theme]&.dig('primary') %>
<h4 class="nav-heading"><%= Space.model_name.human %></h4>
<div class="nav-block" id="space-info">
<p>
<%= link_to(image_tag(get_image_url_for(space), class: 'medium-avatar', style: (theme_colour ? "background-color: #{theme_colour}" : nil)), space.url, target: :_blank) %>
</p>

<p>
<%= link_to space.title, space.url, class: 'h5', target: :_blank %>
</p>

<p>
<%= external_link_button t('other_space.link'), polymorphic_url(resource, host: space.host) %>
</p>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/events/_event.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<% learning_path_topic_item ||= nil %>
<% collection_item ||= learning_path_topic_item %>
<li class="masonry-brick media-item long">
<%= space_tag(event) %>
<%= link_to event, class: 'link-overlay with-left-icon' do %>
<%= item_order_badge(collection_item) if collection_item %>
<div class="with-left-icon">
Expand Down
1 change: 1 addition & 0 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<%# SIDEBAR %>
<div class="collapsing-sidebar" id="sidebar">
<%= render partial: 'common/origin_info', locals: { resource: @event } %>
<%= render partial: 'common/space_info', locals: { resource: @event } %>
<%= render partial: 'content_providers/partials/content_provider_info', locals: { content_provider: @event.content_provider } %>
<%= render partial: "nodes/partials/associated_node_info", locals: { associated_nodes: @event.associated_nodes } %>
<%= render(partial: 'users/partials/user_info', locals: { user: @event.user }) if current_user.try(:is_admin?) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<li class="masonry-brick media-item long">
<%= space_tag(learning_path_topic) %>
<%= link_to learning_path_topic, class: 'link-overlay' do %>
<div class="masonry-brick-heading">
<h4><%= learning_path_topic.title %></h4>
Expand Down
1 change: 1 addition & 0 deletions app/views/learning_path_topics/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="wrapper collapsing-wrapper">
<div class="collapsing-sidebar" id="sidebar">
<%= render partial: 'common/space_info', locals: { resource: @learning_path_topic } %>
<h4 class="nav-heading"><%= LearningPathTopic.model_name.human %></h4>
<div class="nav-block">
<h5>
Expand Down
1 change: 1 addition & 0 deletions app/views/learning_paths/_learning_path.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% cache(learning_path, expires_in: 1.hour) do %>
<li class="masonry-brick media-item large block-item learning-path-bg-<%= (learning_path.id % 4) + 1 -%>">
<%= space_tag(learning_path) %>
<%= link_to learning_path, class: 'link-overlay' do %>
<%= item_order_badge(collection_item) if defined? collection_item %>

Expand Down
1 change: 1 addition & 0 deletions app/views/learning_paths/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="wrapper collapsing-wrapper">
<div class="collapsing-sidebar" id="sidebar">
<%= render partial: 'common/space_info', locals: { resource: @learning_path } %>
<%= render partial: 'content_providers/partials/content_provider_info', locals: { content_provider: @learning_path.content_provider } %>
<%= render partial: 'nodes/partials/associated_node_info', locals: { associated_nodes: @learning_path.associated_nodes } %>
<%= render(partial: 'users/partials/user_info', locals: { user: @learning_path.user }) if current_user.try(:is_admin?) %>
Expand Down
1 change: 1 addition & 0 deletions app/views/materials/_material.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
end
%>
<li class="masonry-brick media-item long">
<%= space_tag(material) %>
<%= link_to material_path(material, **link_params), class: 'link-overlay' do %>
<%= item_order_badge(collection_item) if show_order && collection_item %>

Expand Down
1 change: 1 addition & 0 deletions app/views/materials/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
locals: { topic_link: @learning_path_topic_link,
topic_item: @learning_path_topic_item } if @learning_path_topic_link && @learning_path_topic_item %>
<%= render partial: 'common/origin_info', locals: { resource: @material } %>
<%= render partial: 'common/space_info', locals: { resource: @material } %>
<%= render partial: 'content_providers/partials/content_provider_info', locals: { content_provider: @material.content_provider } %>
<%= render partial: 'nodes/partials/associated_node_info', locals: { associated_nodes: @material.associated_nodes } %>
<%= render(partial: 'users/partials/user_info', locals: { user: @material.user }) if current_user.try(:is_admin?) %>
Expand Down
1 change: 1 addition & 0 deletions app/views/sources/_source.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="masonry-brick media-item long">
<%= space_tag(source) %>
<%= link_to source, class: 'link-overlay' do %>
<h4>
<%= source.title %>
Expand Down
1 change: 1 addition & 0 deletions app/views/sources/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<%# SIDEBAR %>
<div class="collapsing-sidebar" id="sidebar">
<%= render partial: 'common/space_info', locals: { resource: @source } %>
<%= render partial: "content_providers/partials/content_provider_info",
locals: { content_provider: @source.content_provider } %>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/workflows/_workflow.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<li class="masonry-brick media-item long">
<%= space_tag(workflow) %>
<%= link_to workflow, class: 'link-overlay' do %>
<div class="masonry-brick-heading">
<div class="masonry-icons">
Expand Down
7 changes: 7 additions & 0 deletions app/views/workflows/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<p class="muted">No description provided</p>
<% end %>
<%= render partial: 'common/extra_metadata', locals: { resource: @workflow } %>
<% space = @workflow.space %>
<% if TeSS::Config.feature['spaces'] && space && !space.default? && space != current_space %>
<p class="space no-spacing">
<strong class="text-primary"><%= Space.model_name.human %>: </strong>
<%= link_to(space.title, space) %>
</p>
<% end %>
<% if policy(@workflow).update? && @workflow.edit_suggestion %>
<%= render partial: 'common/approve_term_suggestions', locals: { suggestion: @workflow.edit_suggestion } %>
<% end %>
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,6 @@ en:
exchange:
title: Original entry
info: "This %{resource_type} originated from another TeSS registry. For complete, up-to-date information, please visit the original entry:"
link: Go to original entry
link: Go to original entry
other_space:
link: View in space
42 changes: 42 additions & 0 deletions test/controllers/materials_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1721,4 +1721,46 @@ class MaterialsControllerTest < ActionController::TestCase

assert_select '#origin-info a[href=?]', uri
end

# Space info tests
test 'should show space info when viewing a material from a different non-default space' do
plant_space_material = materials(:plant_space_material)
with_settings(feature: { spaces: true }) do
# Request comes from the default space (no specific host)
get :show, params: { id: plant_space_material }
assert_response :success
assert_select '#space-info', count: 1
assert_select '#space-info a', text: plant_space_material.space.title
end
end

test 'should not show space info when viewing a material from the current space' do
plant_space = spaces(:plants)
plant_space_material = materials(:plant_space_material)
with_settings(feature: { spaces: true }) do
with_host(plant_space.host) do
get :show, params: { id: plant_space_material }
assert_response :success
assert_select '#space-info', count: 0
end
end
end

test 'should not show space info when spaces feature is disabled' do
plant_space_material = materials(:plant_space_material)
with_settings(feature: { spaces: false }) do
get :show, params: { id: plant_space_material }
assert_response :success
assert_select '#space-info', count: 0
end
end

test 'should not show space info when material has no space' do
with_settings(feature: { spaces: true }) do
# @material has no space assigned
get :show, params: { id: @material }
assert_response :success
assert_select '#space-info', count: 0
end
end
end