Skip to content

Commit

Permalink
Add active, planned and completed session tabs
Browse files Browse the repository at this point in the history
This adds new tabs to the "School sessions" page allowing the user to
see the sessions that are active, planned in the future, and already
completed in the past.
  • Loading branch information
thomasleese committed Sep 25, 2024
1 parent e99d723 commit deec5b3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class SessionsController < ApplicationController
before_action :set_session, except: %i[index create]
before_action :set_session, except: %i[index planned completed create]

def create
skip_policy_scope
Expand All @@ -25,6 +25,18 @@ def index
render layout: "full"
end

def planned
@sessions = policy_scope(Session).active.planned

render layout: "full"
end

def completed
@sessions = policy_scope(Session).active.completed

render layout: "full"
end

def show
@patient_sessions =
@session.patient_sessions.strict_loading.includes(
Expand Down
15 changes: 15 additions & 0 deletions app/views/sessions/completed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% content_for :page_title, "#{t("sessions.index.title")} – Completed" %>
<%= h1 t("sessions.index.title"), size: "xl" %>
<%= render AppSecondaryNavigationComponent.new do |nav|
nav.with_item(href: sessions_path, text: "Active")
nav.with_item(href: planned_sessions_path, text: "Planned")
nav.with_item(href: completed_sessions_path, text: "Completed", selected: true)
end %>
<% if @sessions.empty? %>
<p>There are no sessions completed.</p>
<% else %>
<%= render AppSessionTableComponent.new(@sessions, description: "completed session", show_programmes: true) %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/sessions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<% content_for :page_title, "#{t(".title")} – Active" %>

<div class="app-heading-group">
<%= h1 t(".title"), size: "xl" %>
<%= govuk_button_to("Add a new session", sessions_path, secondary: true) %>
</div>

<%= render AppSecondaryNavigationComponent.new do |nav|
nav.with_item(href: sessions_path, text: "Active", selected: true)
nav.with_item(href: planned_sessions_path, text: "Planned")
nav.with_item(href: completed_sessions_path, text: "Completed")
end %>
<% if @sessions.empty? %>
<p>There are no sessions scheduled for today.</p>
<% else %>
Expand Down
15 changes: 15 additions & 0 deletions app/views/sessions/planned.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% content_for :page_title, "#{t("sessions.index.title")} – Planned" %>
<%= h1 t("sessions.index.title"), size: "xl" %>
<%= render AppSecondaryNavigationComponent.new do |nav|
nav.with_item(href: sessions_path, text: "Active")
nav.with_item(href: planned_sessions_path, text: "Planned", selected: true)
nav.with_item(href: completed_sessions_path, text: "Completed")
end %>
<% if @sessions.empty? %>
<p>There are no sessions planned.</p>
<% else %>
<%= render AppSessionTableComponent.new(@sessions, description: "planned session", show_programmes: true) %>
<% end %>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
end
end

collection do
get "planned"
get "completed"
end

resources :edit, controller: "sessions/edit", only: %i[show update]

constraints -> { Flipper.enabled?(:dev_tools) } do
Expand Down
13 changes: 13 additions & 0 deletions spec/features/session_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
when_i_go_to_todays_sessions_as_a_nurse
then_i_see_no_sessions

when_i_go_to_planned_sessions_as_a_nurse
then_i_see_the_new_session

when_the_parent_visits_the_consent_form
then_they_can_give_consent

Expand All @@ -38,6 +41,9 @@

when_i_go_to_todays_sessions_as_a_nurse
then_i_see_the_new_session

when_i_go_to_planned_sessions_as_a_nurse
then_i_see_no_sessions
end

def given_my_team_is_running_an_hpv_vaccination_programme
Expand All @@ -53,6 +59,13 @@ def when_i_go_to_todays_sessions_as_a_nurse
click_link "School sessions", match: :first
end

def when_i_go_to_planned_sessions_as_a_nurse
sign_in @team.users.first
visit "/dashboard"
click_link "School sessions", match: :first
click_link "Planned"
end

def then_i_see_no_sessions
expect(page).to have_content("There are no sessions")
end
Expand Down

0 comments on commit deec5b3

Please sign in to comment.