Skip to content

Commit 005d4f7

Browse files
committed
wip
1 parent 70d04c4 commit 005d4f7

7 files changed

Lines changed: 37 additions & 11 deletions

File tree

app/controllers/draft_sessions_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class DraftSessionsController < ApplicationController
2121
skip_after_action :verify_policy_scoped
2222

2323
def show
24-
authorize @session, :edit?
24+
authorize @session, @session.new_record? ? :new? : :edit?
2525

2626
render_wizard
2727
end
2828

2929
def update
30-
authorize @session, :update?
30+
authorize @session, @session.new_record? ? :create? : :update?
3131

3232
jump_to("confirm") if @draft_session.editing? && current_step != :confirm
3333

@@ -52,7 +52,7 @@ def set_draft_session
5252
end
5353

5454
def set_session
55-
@session = @draft_session.session
55+
@session = @draft_session.session || Session.new
5656
end
5757

5858
def set_steps

app/controllers/sessions_controller.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ class SessionsController < ApplicationController
44
include SessionSearchFormConcern
55

66
before_action :set_session_search_form, only: :index
7-
before_action :set_session, except: :index
7+
before_action :set_session, except: %i[index new]
8+
9+
skip_after_action :verify_policy_scoped, only: :new
810

911
def index
1012
@programmes = current_user.selected_team.programmes
@@ -20,6 +22,17 @@ def index
2022
render layout: "full"
2123
end
2224

25+
def new
26+
@draft_session = DraftSession.new(request_session: session, current_user:)
27+
28+
@draft_session.clear_attributes
29+
@draft_session.assign_attributes(create_params)
30+
31+
@draft_session.save!
32+
33+
redirect_to draft_session_path(Wicked::FIRST_STEP)
34+
end
35+
2336
def show
2437
respond_to do |format|
2538
format.html { render layout: "full" }
@@ -93,4 +106,12 @@ def patient_counts_for_sessions(sessions)
93106
.group("sessions.id")
94107
.count("DISTINCT patients.id")
95108
end
109+
110+
def create_params
111+
{
112+
academic_year: AcademicYear.pending,
113+
session_dates: [DraftSessionDate.new],
114+
team_id: current_team.id
115+
}
116+
end
96117
end

app/models/draft_session.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def wizard_steps
4040

4141
steps << :location_type unless editing?
4242

43-
steps << :dates
44-
steps << :dates_check if school?
45-
4643
steps << :programmes
4744
steps << :programmes_check if school?
4845

46+
steps << :dates
47+
steps << :dates_check if school?
48+
4949
if include_notification_steps?
5050
steps += %i[consent_requests consent_reminders] if school?
5151
steps << :invitations if generic_clinic?
@@ -250,8 +250,8 @@ def writable_attribute_names
250250
end
251251

252252
def include_notification_steps?
253-
dates.present? && session.consent_notifications.empty? &&
254-
session.session_notifications.empty?
253+
dates.present? && session&.consent_notifications&.empty? &&
254+
session&.session_notifications&.empty?
255255
end
256256

257257
def new_programme_types

app/models/draft_session_date.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def self.load(arr)
3030
end
3131

3232
def self.dump(values)
33+
return if values.nil?
3334
values.map { |value| value.is_a?(Hash) ? value : value.attributes }
3435
end
3536
end

app/views/draft_sessions/dates.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<% @draft_session.session_dates.each_with_index do |session_date, index| %>
1313
<%= f.fields_for "session_date_#{index}", session_date do |ff| %>
1414
<li class="app-add-another__list-item">
15-
<% if @draft_session.session.has_been_attended?(date: session_date.value) %>
15+
<% if @draft_session.session&.has_been_attended?(date: session_date.value) %>
1616
<h2 class="nhsuk-heading-m">
1717
<%= session_date.value.to_fs(:long) %>
1818
</h2>

app/views/sessions/index.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
<%= h1 t(".title"), size: "xl" %>
44

5+
<% if Flipper.enabled?(:schools_and_sessions) %>
6+
<%= govuk_button_link_to "Add a new session", new_session_path, secondary: true %>
7+
<% end %>
8+
59
<div class="nhsuk-grid-row">
610
<div class="app-grid-column-filters">
711
<%= render AppSessionSearchFormComponent.new(

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
get "sessions"
250250
end
251251

252-
resources :sessions, only: %i[index show edit], param: :slug do
252+
resources :sessions, only: %i[index new show edit], param: :slug do
253253
resource :patients, only: :show, controller: "sessions/patients"
254254
resource :consent, only: :show, controller: "sessions/consent"
255255
resource :triage, only: :show, controller: "sessions/triage"

0 commit comments

Comments
 (0)