From d15038fa9c9d7017ec346a080f55526a7748b97f Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Tue, 21 Apr 2026 15:46:45 +0100 Subject: [PATCH 1/5] Expand and hide order of topic if its the only topic in the LP. Fixes #1247 --- app/assets/javascripts/learning_paths.js | 2 +- app/assets/stylesheets/learning-paths.scss | 19 ++++++++++++++++++- app/views/learning_paths/show.html.erb | 6 ++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/learning_paths.js b/app/assets/javascripts/learning_paths.js index edd866719..a31704658 100644 --- a/app/assets/javascripts/learning_paths.js +++ b/app/assets/javascripts/learning_paths.js @@ -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'); diff --git a/app/assets/stylesheets/learning-paths.scss b/app/assets/stylesheets/learning-paths.scss index f90730a63..a06da5aab 100644 --- a/app/assets/stylesheets/learning-paths.scss +++ b/app/assets/stylesheets/learning-paths.scss @@ -25,7 +25,6 @@ cursor: pointer; } - .learning-path-topic-desc { border-width: 0; padding: 1em; @@ -36,6 +35,24 @@ .learning-path-topic-contents { 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 { diff --git a/app/views/learning_paths/show.html.erb b/app/views/learning_paths/show.html.erb index 6be659567..651fd95c5 100644 --- a/app/views/learning_paths/show.html.erb +++ b/app/views/learning_paths/show.html.erb @@ -61,8 +61,10 @@
- <% @learning_path.topic_links.joins(:topic).each do |lpt| %> -
+ <% topics = @learning_path.topic_links.joins(:topic) %> + <% topic_count = topics.count %> + <% topics.each do |lpt| %> +
<%= lpt.order %>

<%= lpt.topic.title %>

From c9b5f28a6392b7f2b6156017f99a14bbaf863929 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Tue, 21 Apr 2026 15:49:00 +0100 Subject: [PATCH 2/5] Test for single topic display --- test/controllers/learning_paths_controller_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/controllers/learning_paths_controller_test.rb b/test/controllers/learning_paths_controller_test.rb index 7e1c35351..7af29a0c5 100644 --- a/test/controllers/learning_paths_controller_test.rb +++ b/test/controllers/learning_paths_controller_test.rb @@ -151,6 +151,8 @@ 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_select '.learning-path-topic.single-topic', count: 0 end test 'should show learning_path as json' do @@ -561,4 +563,12 @@ 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 end From f1f8e2ce801c4beecc2443e033253addec823a91 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Tue, 21 Apr 2026 16:00:32 +0100 Subject: [PATCH 3/5] Option to display learning paths as "unordered". Fixes #1169 --- app/assets/stylesheets/learning-paths.scss | 6 ++++++ app/controllers/learning_paths_controller.rb | 3 ++- app/views/learning_paths/_form.html.erb | 2 ++ app/views/learning_paths/show.html.erb | 7 +++++-- config/locales/en.yml | 1 + .../20260421144919_add_unordered_to_learning_paths.rb | 5 +++++ db/schema.rb | 3 ++- 7 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20260421144919_add_unordered_to_learning_paths.rb diff --git a/app/assets/stylesheets/learning-paths.scss b/app/assets/stylesheets/learning-paths.scss index a06da5aab..38f4a5375 100644 --- a/app/assets/stylesheets/learning-paths.scss +++ b/app/assets/stylesheets/learning-paths.scss @@ -36,6 +36,12 @@ display: none; } + &.unordered { + .learning-path-topic-order { + display: none; + } + } + &.single-topic { margin-left: 0; border-left: none; diff --git a/app/controllers/learning_paths_controller.rb b/app/controllers/learning_paths_controller.rb index 1e1db7411..7761faf6b 100644 --- a/app/controllers/learning_paths_controller.rb +++ b/app/controllers/learning_paths_controller.rb @@ -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 diff --git a/app/views/learning_paths/_form.html.erb b/app/views/learning_paths/_form.html.erb index 9e1cf7f33..cc62f73c5 100644 --- a/app/views/learning_paths/_form.html.erb +++ b/app/views/learning_paths/_form.html.erb @@ -130,6 +130,8 @@
+ <%= f.input :unordered, hint: t('learning_paths.hints.unordered') %> + <%= f.input :public, hint: t('learning_paths.hints.public') %> diff --git a/app/views/learning_paths/show.html.erb b/app/views/learning_paths/show.html.erb index 651fd95c5..c7a402e7a 100644 --- a/app/views/learning_paths/show.html.erb +++ b/app/views/learning_paths/show.html.erb @@ -64,7 +64,10 @@ <% 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 %>
<%= lpt.order %>

<%= lpt.topic.title %>

@@ -91,7 +94,7 @@ <% end %>
-
+ <% end %> <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index de612072f..66cc4cffb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/db/migrate/20260421144919_add_unordered_to_learning_paths.rb b/db/migrate/20260421144919_add_unordered_to_learning_paths.rb new file mode 100644 index 000000000..65e20ec49 --- /dev/null +++ b/db/migrate/20260421144919_add_unordered_to_learning_paths.rb @@ -0,0 +1,5 @@ +class AddUnorderedToLearningPaths < ActiveRecord::Migration[7.2] + def change + add_column :learning_paths, :unordered, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index c989c1696..4bfe24369 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -323,6 +323,7 @@ t.datetime "updated_at", null: false t.boolean "public", default: true t.bigint "space_id" + t.boolean "unordered" 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" From 9d9f36d05d8a2211dbc707adac5866dd9404af09 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Fri, 24 Apr 2026 12:50:08 +0100 Subject: [PATCH 4/5] Add default value to boolean --- db/migrate/20260421144919_add_unordered_to_learning_paths.rb | 2 +- db/schema.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20260421144919_add_unordered_to_learning_paths.rb b/db/migrate/20260421144919_add_unordered_to_learning_paths.rb index 65e20ec49..23dfbc981 100644 --- a/db/migrate/20260421144919_add_unordered_to_learning_paths.rb +++ b/db/migrate/20260421144919_add_unordered_to_learning_paths.rb @@ -1,5 +1,5 @@ class AddUnorderedToLearningPaths < ActiveRecord::Migration[7.2] def change - add_column :learning_paths, :unordered, :boolean + add_column :learning_paths, :unordered, :boolean, default: false, null: false end end diff --git a/db/schema.rb b/db/schema.rb index 4bfe24369..12c6de42a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -323,7 +323,7 @@ t.datetime "updated_at", null: false t.boolean "public", default: true t.bigint "space_id" - t.boolean "unordered" + 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" From 768c5de3f9b838d97d0b6bf022d1306463db2dec Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Fri, 24 Apr 2026 12:53:56 +0100 Subject: [PATCH 5/5] Test for unordered display --- test/controllers/learning_paths_controller_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/controllers/learning_paths_controller_test.rb b/test/controllers/learning_paths_controller_test.rb index 7af29a0c5..ed99fcaad 100644 --- a/test/controllers/learning_paths_controller_test.rb +++ b/test/controllers/learning_paths_controller_test.rb @@ -152,7 +152,10 @@ class LearningPathsControllerTest < ActionController::TestCase 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 @@ -571,4 +574,14 @@ class LearningPathsControllerTest < ActionController::TestCase assert_select '.learning-path-topic', count: 1 assert_select '.learning-path-topic.single-topic', count: 1 end + + 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