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..38f4a5375 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,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 { 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 6be659567..c7a402e7a 100644 --- a/app/views/learning_paths/show.html.erb +++ b/app/views/learning_paths/show.html.erb @@ -61,8 +61,13 @@
- <% @learning_path.topic_links.joins(:topic).each do |lpt| %> -
+ <% 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 %>

@@ -89,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..23dfbc981 --- /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, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index c989c1696..12c6de42a 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", 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" diff --git a/test/controllers/learning_paths_controller_test.rb b/test/controllers/learning_paths_controller_test.rb index 7e1c35351..ed99fcaad 100644 --- a/test/controllers/learning_paths_controller_test.rb +++ b/test/controllers/learning_paths_controller_test.rb @@ -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 @@ -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 + + 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