Skip to content

Commit fc790a8

Browse files
committed
Add Programmes::OverviewController
This moves the logic related to the overview tab of the programmes page in to its own controller in preparation for having multiple programmes per academic year.
1 parent 28e4a15 commit fc790a8

15 files changed

Lines changed: 40 additions & 26 deletions

File tree

app/components/app_programme_navigation_component.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ def initialize(programme, active:)
1010

1111
def call
1212
render AppSecondaryNavigationComponent.new do |nav|
13-
nav.with_item(
14-
href: programme_path(programme),
15-
text: "Overview",
16-
selected: active == :overview
17-
)
18-
1913
SECTIONS.each do |section|
14+
action = section == :overview ? :show : :index
15+
2016
nav.with_item(
2117
href: public_send("programme_#{section}_path", programme),
22-
text: I18n.t("title", scope: [:programmes, section, :index]),
23-
selected: active == session
18+
text: I18n.t("title", scope: [:programmes, section, action]),
19+
selected: active == section
2420
)
2521
end
2622
end
@@ -30,5 +26,5 @@ def call
3026

3127
attr_reader :programme, :active
3228

33-
SECTIONS = %i[cohorts sessions patients vaccinations].freeze
29+
SECTIONS = %i[overview cohorts sessions patients vaccinations].freeze
3430
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::OverviewController < ApplicationController
4+
before_action :set_programme
5+
6+
layout "full"
7+
8+
def show
9+
patients = policy_scope(Patient).in_programmes([@programme])
10+
11+
@consents =
12+
policy_scope(Consent).where(patient: patients, programme: @programme)
13+
end
14+
15+
private
16+
17+
def set_programme
18+
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
19+
end
20+
end

app/controllers/programmes_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ def index
1010
policy_scope(Programme).order(:type).includes(:active_vaccines)
1111
end
1212

13-
def show
14-
patients = policy_scope(Patient).in_programmes([@programme])
15-
@consents =
16-
policy_scope(Consent).where(patient: patients, programme: @programme)
17-
end
18-
1913
def consent_form
2014
send_file(
2115
"public/consent_forms/#{@programme.type}.pdf",

app/views/programmes/cohorts/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= render AppBreadcrumbComponent.new(items: [
55
{ text: t("dashboard.index.title"), href: dashboard_path },
66
{ text: t("programmes.index.title"), href: programmes_path },
7-
{ text: @programme.name, href: programme_path(@programme) },
7+
{ text: @programme.name, href: programme_overview_path(@programme) },
88
]) %>
99
<% end %>
1010

app/views/programmes/cohorts/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<%= render AppBreadcrumbComponent.new(items: [
33
{ text: t("dashboard.index.title"), href: dashboard_path },
44
{ text: t("programmes.index.title"), href: programmes_path },
5-
{ text: @programme.name, href: programme_path(@programme) },
5+
{ text: @programme.name, href: programme_overview_path(@programme) },
66
{ text: t("programmes.cohorts.index.title"), href: programme_cohorts_path(@programme) },
77
]) %>
88
<% end %>

app/views/programmes/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<% body.with_row do |row| %>
1919
<% row.with_cell do %>
2020
<span class="nhsuk-table-responsive__heading">Programme</span>
21-
<%= link_to programme.name, programme_path(programme) %>
21+
<%= link_to programme.name, programme_overview_path(programme) %>
2222
<% end %>
2323

2424
<% row.with_cell do %>

app/views/programmes/show.html.erb renamed to app/views/programmes/overview/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% content_for :page_title, "#{@programme.name} – Overview" %>
1+
<% content_for :page_title, "#{@programme.name} – #{t(".title")}" %>
22

33
<% content_for :before_main do %>
44
<%= render AppBreadcrumbComponent.new(items: [

app/views/programmes/patients/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= render AppBreadcrumbComponent.new(items: [
55
{ text: t("dashboard.index.title"), href: dashboard_path },
66
{ text: t("programmes.index.title"), href: programmes_path },
7-
{ text: @programme.name, href: programme_path(@programme) },
7+
{ text: @programme.name, href: programme_overview_path(@programme) },
88
]) %>
99
<% end %>
1010

app/views/programmes/sessions/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= render AppBreadcrumbComponent.new(items: [
55
{ text: t("dashboard.index.title"), href: dashboard_path },
66
{ text: t("programmes.index.title"), href: programmes_path },
7-
{ text: @programme.name, href: programme_path(@programme) },
7+
{ text: @programme.name, href: programme_overview_path(@programme) },
88
]) %>
99
<% end %>
1010

app/views/programmes/vaccinations/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= render AppBreadcrumbComponent.new(items: [
55
{ text: t("dashboard.index.title"), href: dashboard_path },
66
{ text: t("programmes.index.title"), href: programmes_path },
7-
{ text: @programme.name, href: programme_path(@programme) },
7+
{ text: @programme.name, href: programme_overview_path(@programme) },
88
]) %>
99
<% end %>
1010

0 commit comments

Comments
 (0)