diff --git a/app/controllers/student_homes_controller.rb b/app/controllers/student_homes_controller.rb index 30386a7..25b94f6 100644 --- a/app/controllers/student_homes_controller.rb +++ b/app/controllers/student_homes_controller.rb @@ -9,7 +9,7 @@ def index .order("programs.name") @active_program = @classroom_programs.find { |cp| cp.id.to_s == params[:classroom_program_id] } || @classroom_programs.first @published_modules = if @active_program - @active_program.classroom_modules.published.includes(content_module: :links) + @active_program.classroom_modules.published.includes(content_module: { contents: :contentable }) else [] end diff --git a/app/views/admin/content_modules/edit.html.erb b/app/views/admin/content_modules/edit.html.erb index 1f67ca9..db9e96f 100644 --- a/app/views/admin/content_modules/edit.html.erb +++ b/app/views/admin/content_modules/edit.html.erb @@ -42,10 +42,7 @@ - <% @contents.each_with_index do |content, index| %> - <%= render "admin/contents/contentables/#{content.contentable_name}", content: content, - first: index.zero?, last: index == @contents.size - 1 %> - <% end %> + <%= render partial: "admin/contents/content", collection: @contents %> <% else %> diff --git a/app/views/admin/contents/_content.html.erb b/app/views/admin/contents/_content.html.erb new file mode 100644 index 0000000..6cc6c43 --- /dev/null +++ b/app/views/admin/contents/_content.html.erb @@ -0,0 +1,22 @@ +<%# locals: (content:, content_iteration:) %> +<% contentable = content.contentable %> + + <% case contentable %> + <% when Link %> + <%= link_to "#{contentable.title} ↗", safe_external_url(contentable.url), target: "_blank", rel: "noopener noreferrer", class: "link inline-flex items-center gap-1" %> + <%= contentable.link_type.humanize %> + <% when Game %> + <%= contentable.title %> + Game + <% end %> + +
+ <%= render "admin/shared/move_buttons", url: admin_content_position_path(content), title: contentable.title, + first: content_iteration.first?, last: content_iteration.last? %> + <%= link_to "Edit", edit_polymorphic_path([:admin, contentable]), class: "btn btn-xs btn-primary" %> + <%= button_to "Remove", admin_content_path(content), method: :delete, + data: { "turbo-confirm": "Remove this item from the module?" }, + class: "btn btn-xs btn-error" %> +
+ + diff --git a/app/views/admin/contents/contentables/_game.html.erb b/app/views/admin/contents/contentables/_game.html.erb deleted file mode 100644 index 3da5573..0000000 --- a/app/views/admin/contents/contentables/_game.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% game = content.contentable %> - - <%= game.title %> - Game - -
- <%= render "admin/shared/move_buttons", url: admin_content_position_path(content), title: game.title, first: first, last: last %> - <%= link_to "Edit", edit_admin_game_path(game), class: "btn btn-xs btn-primary" %> - <%= button_to "Remove", admin_content_path(content), method: :delete, - data: { "turbo-confirm": "Remove this game from the module?" }, - class: "btn btn-xs btn-error" %> -
- - diff --git a/app/views/admin/contents/contentables/_link.html.erb b/app/views/admin/contents/contentables/_link.html.erb deleted file mode 100644 index 3d6349a..0000000 --- a/app/views/admin/contents/contentables/_link.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% link = content.contentable %> - - <%= link_to "#{link.title} ↗", safe_external_url(link.url), target: "_blank", rel: "noopener noreferrer", class: "link inline-flex items-center gap-1" %> - <%= link.link_type.humanize %> - -
- <%= render "admin/shared/move_buttons", url: admin_content_position_path(content), title: link.title, first: first, last: last %> - <%= link_to "Edit", edit_admin_link_path(link), class: "btn btn-xs btn-primary" %> - <%= button_to "Delete", admin_content_path(content), method: :delete, - data: { "turbo-confirm": "Delete this link?" }, - class: "btn btn-xs btn-error" %> -
- - diff --git a/app/views/student_homes/_contentable.html.erb b/app/views/student_homes/_contentable.html.erb new file mode 100644 index 0000000..06aa00e --- /dev/null +++ b/app/views/student_homes/_contentable.html.erb @@ -0,0 +1,14 @@ +<% case contentable %> +<% when Link %> +
  • + <%= tag.a contentable.title + " ↗", + href: safe_external_url(contentable.url), + target: "_blank", + rel: "noopener noreferrer", + class: "link inline-flex items-center gap-1" %> +
  • +<% when Game %> +
  • + <%= tag.a contentable.title, href: play_game_path(contentable), class: "link inline-flex items-center gap-1" %> +
  • +<% end %> diff --git a/app/views/student_homes/index.html.erb b/app/views/student_homes/index.html.erb index db4cd85..7c94709 100644 --- a/app/views/student_homes/index.html.erb +++ b/app/views/student_homes/index.html.erb @@ -30,15 +30,7 @@
    <% end %> diff --git a/test/controllers/student_homes_controller_test.rb b/test/controllers/student_homes_controller_test.rb index d7567a2..aa50aef 100644 --- a/test/controllers/student_homes_controller_test.rb +++ b/test/controllers/student_homes_controller_test.rb @@ -18,11 +18,21 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest assert_select "summary", text: /Introduction to Health/ end - test "shows links inside published modules" do + test "shows links and games inside published modules" do get student_homes_url assert_response :success - link = content_modules(:one).links.first - assert_select "a[target='_blank']", text: /#{link.title}/ if link + assert_select "li a[target='_blank'][href='#{links(:one).url}']", text: /#{links(:one).title}/ + assert_select "li a[href='#{play_game_path(games(:one))}']:not([target])", text: games(:one).title + end + + test "shows contents in position order" do + get student_homes_url + assert_equal [ games(:one).title, links(:one).title ], listed_titles + + contents(:one).move_down + + get student_homes_url + assert_equal [ links(:one).title, games(:one).title ], listed_titles end test "most recently published module has the open attribute" do @@ -79,4 +89,10 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest get student_homes_url(classroom_program_id: enrollment.id) assert_select "a[role='tab'][aria-selected='true'][href*='classroom_program_id=#{enrollment.id}']" end + + private + + def listed_titles + css_select("details li a").map { |a| a.text.delete_suffix(" ↗") } + end end