Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/assets/javascripts/learning_paths.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var LearningPaths = {
init: function () {
$('.learning-path-topic-title').click(function () {
$('.learning-path-topic:not(.single-topic) .learning-path-topic-title').click(function () {
const container = $(this).closest('.learning-path-topic');
const contents = container.find('.learning-path-topic-contents');
$(this).find('.expand-icon, .collapse-icon').toggleClass('collapse-icon').toggleClass('expand-icon');
Expand Down
25 changes: 24 additions & 1 deletion app/assets/stylesheets/learning-paths.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
cursor: pointer;
}


.learning-path-topic-desc {
border-width: 0;
padding: 1em;
Expand All @@ -36,6 +35,30 @@
.learning-path-topic-contents {
display: none;
}

&.unordered {
.learning-path-topic-order {
display: none;
}
}

&.single-topic {
margin-left: 0;
border-left: none;
padding: 1em;

.learning-path-topic-title {
cursor: unset;
}

.expand-icon, .learning-path-topic-order {
display: none;
}

.learning-path-topic-contents {
display: block;
}
}
}

.block-item {
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/learning_paths_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def learning_path_params
{ node_ids: [] }, { node_names: [] },
{ topic_links_attributes: [:id, :topic_id, :order, :_destroy] }, :public,
{ authors: [:name, :orcid] }, { contributors: [:name, :orcid] }, # Structured
{ authors: [] }, { contributors: [] } # as strings
{ authors: [] }, { contributors: [] }, # as strings
:unordered
)
end

Expand Down
2 changes: 2 additions & 0 deletions app/views/learning_paths/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@

<hr>

<%= f.input :unordered, hint: t('learning_paths.hints.unordered') %>

<%= f.input :public, hint: t('learning_paths.hints.public') %>

<!-- Form Buttons -->
Expand Down
11 changes: 8 additions & 3 deletions app/views/learning_paths/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@
</div>

<div class="learning-path-topics">
<% @learning_path.topic_links.joins(:topic).each do |lpt| %>
<div class="learning-path-topic" id="topic-<%= lpt.id -%>">
<% topics = @learning_path.topic_links.joins(:topic) %>
<% topic_count = topics.count %>
<% topics.each do |lpt| %>
<% classes = ['learning-path-topic'] %>
<% classes << 'single-topic' if topic_count == 1 %>
<% classes << 'unordered' if @learning_path.unordered? %>
<%= content_tag(:div, id: "topic-#{lpt.id}", class: classes) do %>
<div class="learning-path-topic-order"><%= lpt.order %></div>
<div class="learning-path-topic-title">
<h4><%= lpt.topic.title %> <i class="icon icon-md expand-icon"></i></h4>
Expand All @@ -89,7 +94,7 @@
<% end %>
</ul>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ en:
url: 'Preferred URL to direct people to your learning path landing page.'
version: 'Indicate the current version of the learning path.'
public: Un-ticking this box will hide this learning path from anyone who isn't the creator or a collaborator.
unordered: Ticking this box will hide the order numbering of topics when viewing the learning path.
next_topic: Next topic
next_item: Next
end_of: End of learning path
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20260421144919_add_unordered_to_learning_paths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUnorderedToLearningPaths < ActiveRecord::Migration[7.2]
def change
add_column :learning_paths, :unordered, :boolean, default: false, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

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

Expand Down Expand Up @@ -323,6 +323,7 @@
t.datetime "updated_at", null: false
t.boolean "public", default: true
t.bigint "space_id"
t.boolean "unordered", default: false, null: false
t.index ["content_provider_id"], name: "index_learning_paths_on_content_provider_id"
t.index ["slug"], name: "index_learning_paths_on_slug", unique: true
t.index ["space_id"], name: "index_learning_paths_on_space_id"
Expand Down
23 changes: 23 additions & 0 deletions test/controllers/learning_paths_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ class LearningPathsControllerTest < ActionController::TestCase
get :show, params: { id: @learning_path }
assert_response :success
assert assigns(:learning_path)
assert_select '.learning-path-topic', count: 2
assert_operator assigns(:learning_path).topics.length, :>, 1
assert_select '.learning-path-topic.single-topic', count: 0
refute assigns(:learning_path).unordered?
assert_select '.learning-path-topic.unordered', count: 0
end

test 'should show learning_path as json' do
Expand Down Expand Up @@ -561,4 +566,22 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_equal 'Joe', lp.authors.first[:name]
assert_nil lp.authors.first[:orcid]
end

test 'displays single-topic view if only one topic in the learning path' do
get :show, params: { id: learning_paths(:two) }
assert_response :success
assert assigns(:learning_path)
assert_select '.learning-path-topic', count: 1
assert_select '.learning-path-topic.single-topic', count: 1
end
Comment thread
fbacall marked this conversation as resolved.

test 'displays unordered view when learning path is unordered' do
learning_path = learning_paths(:one)
learning_path.update!(unordered: true)
get :show, params: { id: learning_path }
assert_response :success
assert assigns(:learning_path)
assert assigns(:learning_path).unordered?
assert_select '.learning-path-topic.unordered', minimum: 1
end
end
Loading