Skip to content
Closed
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/controllers/student_homes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions app/views/admin/content_modules/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
</tr>
</thead>
<tbody>
<% @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 %>
</tbody>
</table>
<% else %>
Expand Down
22 changes: 22 additions & 0 deletions app/views/admin/contents/_content.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# locals: (content:, content_iteration:) %>
<% contentable = content.contentable %>
<tr>
<% case contentable %>
<% when Link %>
<td><%= link_to "#{contentable.title} ↗", safe_external_url(contentable.url), target: "_blank", rel: "noopener noreferrer", class: "link inline-flex items-center gap-1" %></td>
<td><%= contentable.link_type.humanize %></td>
<% when Game %>
<td><%= contentable.title %></td>
<td>Game</td>
<% end %>
<td>
<div class="flex gap-2">
<%= 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" %>
</div>
</td>
</tr>
14 changes: 0 additions & 14 deletions app/views/admin/contents/contentables/_game.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions app/views/admin/contents/contentables/_link.html.erb

This file was deleted.

14 changes: 14 additions & 0 deletions app/views/student_homes/_contentable.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% case contentable %>
<% when Link %>
<li>
<%= tag.a contentable.title + " ↗",
href: safe_external_url(contentable.url),
target: "_blank",
rel: "noopener noreferrer",
class: "link inline-flex items-center gap-1" %>
</li>
<% when Game %>
<li>
<%= tag.a contentable.title, href: play_game_path(contentable), class: "link inline-flex items-center gap-1" %>
</li>
<% end %>
10 changes: 1 addition & 9 deletions app/views/student_homes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@
</summary>
<div class="collapse-content">
<ul class="flex flex-col gap-2 pt-2">
<% classroom_module.content_module.links.each do |link| %>
<li>
<%= tag.a link.title + " ↗",
href: safe_external_url(link.url),
target: "_blank",
rel: "noopener noreferrer",
class: "link inline-flex items-center gap-1" %>
</li>
<% end %>
<%= render partial: "student_homes/contentable", collection: classroom_module.content_module.contents.map(&:contentable) %>
</ul>
</div>
<% end %>
Expand Down
22 changes: 19 additions & 3 deletions test/controllers/student_homes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading