Skip to content

Commit aa10463

Browse files
authored
Merge pull request #1288 from ElixirTeSS/learning-path-display-options
Learning path display options
2 parents f522414 + 768c5de commit aa10463

9 files changed

Lines changed: 68 additions & 7 deletions

File tree

app/assets/javascripts/learning_paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var LearningPaths = {
22
init: function () {
3-
$('.learning-path-topic-title').click(function () {
3+
$('.learning-path-topic:not(.single-topic) .learning-path-topic-title').click(function () {
44
const container = $(this).closest('.learning-path-topic');
55
const contents = container.find('.learning-path-topic-contents');
66
$(this).find('.expand-icon, .collapse-icon').toggleClass('collapse-icon').toggleClass('expand-icon');

app/assets/stylesheets/learning-paths.scss

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
cursor: pointer;
2626
}
2727

28-
2928
.learning-path-topic-desc {
3029
border-width: 0;
3130
padding: 1em;
@@ -36,6 +35,30 @@
3635
.learning-path-topic-contents {
3736
display: none;
3837
}
38+
39+
&.unordered {
40+
.learning-path-topic-order {
41+
display: none;
42+
}
43+
}
44+
45+
&.single-topic {
46+
margin-left: 0;
47+
border-left: none;
48+
padding: 1em;
49+
50+
.learning-path-topic-title {
51+
cursor: unset;
52+
}
53+
54+
.expand-icon, .learning-path-topic-order {
55+
display: none;
56+
}
57+
58+
.learning-path-topic-contents {
59+
display: block;
60+
}
61+
}
3962
}
4063

4164
.block-item {

app/controllers/learning_paths_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def learning_path_params
109109
{ node_ids: [] }, { node_names: [] },
110110
{ topic_links_attributes: [:id, :topic_id, :order, :_destroy] }, :public,
111111
{ authors: [:name, :orcid] }, { contributors: [:name, :orcid] }, # Structured
112-
{ authors: [] }, { contributors: [] } # as strings
112+
{ authors: [] }, { contributors: [] }, # as strings
113+
:unordered
113114
)
114115
end
115116

app/views/learning_paths/_form.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130

131131
<hr>
132132

133+
<%= f.input :unordered, hint: t('learning_paths.hints.unordered') %>
134+
133135
<%= f.input :public, hint: t('learning_paths.hints.public') %>
134136

135137
<!-- Form Buttons -->

app/views/learning_paths/show.html.erb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@
6161
</div>
6262

6363
<div class="learning-path-topics">
64-
<% @learning_path.topic_links.joins(:topic).each do |lpt| %>
65-
<div class="learning-path-topic" id="topic-<%= lpt.id -%>">
64+
<% topics = @learning_path.topic_links.joins(:topic) %>
65+
<% topic_count = topics.count %>
66+
<% topics.each do |lpt| %>
67+
<% classes = ['learning-path-topic'] %>
68+
<% classes << 'single-topic' if topic_count == 1 %>
69+
<% classes << 'unordered' if @learning_path.unordered? %>
70+
<%= content_tag(:div, id: "topic-#{lpt.id}", class: classes) do %>
6671
<div class="learning-path-topic-order"><%= lpt.order %></div>
6772
<div class="learning-path-topic-title">
6873
<h4><%= lpt.topic.title %> <i class="icon icon-md expand-icon"></i></h4>
@@ -89,7 +94,7 @@
8994
<% end %>
9095
</ul>
9196
</div>
92-
</div>
97+
<% end %>
9398
<% end %>
9499
</div>
95100
</div>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ en:
735735
url: 'Preferred URL to direct people to your learning path landing page.'
736736
version: 'Indicate the current version of the learning path.'
737737
public: Un-ticking this box will hide this learning path from anyone who isn't the creator or a collaborator.
738+
unordered: Ticking this box will hide the order numbering of topics when viewing the learning path.
738739
next_topic: Next topic
739740
next_item: Next
740741
end_of: End of learning path
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddUnorderedToLearningPaths < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :learning_paths, :unordered, :boolean, default: false, null: false
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2026_04_17_000001) do
13+
ActiveRecord::Schema[7.2].define(version: 2026_04_21_144919) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -323,6 +323,7 @@
323323
t.datetime "updated_at", null: false
324324
t.boolean "public", default: true
325325
t.bigint "space_id"
326+
t.boolean "unordered", default: false, null: false
326327
t.index ["content_provider_id"], name: "index_learning_paths_on_content_provider_id"
327328
t.index ["slug"], name: "index_learning_paths_on_slug", unique: true
328329
t.index ["space_id"], name: "index_learning_paths_on_space_id"

test/controllers/learning_paths_controller_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ class LearningPathsControllerTest < ActionController::TestCase
151151
get :show, params: { id: @learning_path }
152152
assert_response :success
153153
assert assigns(:learning_path)
154+
assert_select '.learning-path-topic', count: 2
155+
assert_operator assigns(:learning_path).topics.length, :>, 1
156+
assert_select '.learning-path-topic.single-topic', count: 0
157+
refute assigns(:learning_path).unordered?
158+
assert_select '.learning-path-topic.unordered', count: 0
154159
end
155160

156161
test 'should show learning_path as json' do
@@ -561,4 +566,22 @@ class LearningPathsControllerTest < ActionController::TestCase
561566
assert_equal 'Joe', lp.authors.first[:name]
562567
assert_nil lp.authors.first[:orcid]
563568
end
569+
570+
test 'displays single-topic view if only one topic in the learning path' do
571+
get :show, params: { id: learning_paths(:two) }
572+
assert_response :success
573+
assert assigns(:learning_path)
574+
assert_select '.learning-path-topic', count: 1
575+
assert_select '.learning-path-topic.single-topic', count: 1
576+
end
577+
578+
test 'displays unordered view when learning path is unordered' do
579+
learning_path = learning_paths(:one)
580+
learning_path.update!(unordered: true)
581+
get :show, params: { id: learning_path }
582+
assert_response :success
583+
assert assigns(:learning_path)
584+
assert assigns(:learning_path).unordered?
585+
assert_select '.learning-path-topic.unordered', minimum: 1
586+
end
564587
end

0 commit comments

Comments
 (0)