Skip to content

Commit

Permalink
feat(e&o): add school picker to case creation
Browse files Browse the repository at this point in the history
Jira: PWNN-1659
  • Loading branch information
EdwinKruglov committed Oct 16, 2023
1 parent 2cf512d commit 4a9f710
Show file tree
Hide file tree
Showing 50 changed files with 844 additions and 1,619 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Engagement
module CaseRequests
class SchoolPickersController < ApplicationController
before_action :case_request, only: %i[edit update]

def edit
@back_url = params[:source] == "change_link" ? engagement_case_request_path(@case_request) : edit_engagement_case_request_path(@case_request)
@school_picker = @case_request.school_picker
@group = @case_request.organisation
@all_schools = @group.organisations.order(:name)
@filters = @all_schools.filtering(form_params[:filters] || {})
@filtered_schools = @filters.results.map { |s| Support::OrganisationPresenter.new(s) }
end

def update
@school_picker = @case_request.school_picker(school_urns: form_params[:school_urns].compact_blank.excluding("all"))
@school_picker.save!
redirect_to engagement_case_request_path(@case_request)
end

private

def case_request
@case_request = CaseRequest.find_by(id: params[:id])
end

def form_params
params.fetch(:case_request, {}).permit(filters: params.key?(:clear) ? nil : { local_authorities: [], phases: [] }, school_urns: [])
end
end
end
end
43 changes: 23 additions & 20 deletions app/controllers/engagement/case_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
module Engagement
class CaseRequestsController < ApplicationController
before_action -> { @back_url = engagement_cases_path }, only: %i[new create]

def new
@case_request = CaseRequest.new
@upload_reference = SecureRandom.hex
end
before_action :case_request, only: %i[show edit update submit]

def create
@case_request = CaseRequest.new(form_params.except(:upload_reference))
@case_request.created_by = current_agent
@case_request = CaseRequest.new(source: :engagement_and_outreach_cms, creation_source: :engagement_and_outreach_team, created_by: current_agent)
@case_request.save!(validate: false)
redirect_to edit_engagement_case_request_path(@case_request)
end

if @case_request.valid?
@case_request.save!
# kase = @case_request.create_case
def show; end

# CaseFiles::SubmitCaseUpload.new.call(upload_reference: form_params[:upload_reference], support_case_id: kase.id)
def edit
@back_url = @case_request.completed? ? engagement_case_request_path(@case_request) : engagement_cases_path
end

# create_interaction(kase.id, "create_case", "Case created", @case_request.attributes.slice(:source, :category))
def update
@back_url = @case_request.completed? ? engagement_case_request_path(@case_request) : engagement_cases_path
@case_request.assign_attributes(form_params)

redirect_to @case_request.eligible_for_school_picker? ? edit_support_case_request_school_picker_path(@case_request) : engagement_case_request_path(@case_request)
if @case_request.valid?
@case_request.save!
redirect_to(@case_request.eligible_for_school_picker? && @case_request.school_urns.empty? ? edit_engagement_case_request_school_picker_path(@case_request) : engagement_case_request_path(@case_request))
else
render :new
render :edit
end
end

def submit
@case_request.create_case
redirect_to engagement_cases_path
end

private

def case_request
@case_request = CaseRequest.find_by(id: params[:id])
end

def form_params
params.require(:case_request).permit(
:organisation_id,
Expand All @@ -47,11 +54,7 @@ def form_params
:other_category,
:other_query,
:procurement_amount,
:upload_reference,
).merge({
source: :engagement_and_outreach_cms.to_s,
creation_source: :engagement_and_outreach_team.to_s,
})
)
end
end
end
25 changes: 0 additions & 25 deletions app/controllers/engagement/cases/previews_controller.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/controllers/engagement/cases/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def upload
if file_is_safe?
upload = EngagementCaseUpload.pending.create!(
file: params[:file],
upload_reference: params[:upload_reference],
case_request_id: params[:upload_reference],
filename: params[:file].original_filename,
filesize: File.size(params[:file].tempfile.path),
)
render status: :ok, json: { file_id: upload.id }.to_json
else
Rollbar.error("Infected file uploaded", upload_reference: params[:upload_reference])
Rollbar.error("Infected file uploaded", case_request_id: params[:upload_reference])

params[:file].tempfile.delete

Expand All @@ -29,7 +29,7 @@ def remove

def list
reference = params[:upload_reference]
files = EngagementCaseUpload.where(upload_reference: reference)
files = EngagementCaseUpload.where(case_request_id: reference)
result = files.map do |f|
{
file_id: f.id,
Expand Down
58 changes: 0 additions & 58 deletions app/controllers/engagement/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ def index
end
end

def new
@form = Support::CreateCaseForm.new
@back_url = engagement_cases_path
end

def create
@form = Support::CreateCaseForm.from_validation(validation)
@form.creator = current_agent

if validation.success? && params[:button] == "create"
kase = @form.create_case

CaseFiles::SubmitCaseUpload.new.call(upload_reference: @form.upload_reference, support_case_id: kase.id)

create_interaction(kase.id, "create_case", "Case created", @form.to_h.slice(:source, :category))

redirect_to engagement_cases_path
else
render :new
end
end

def show
session[:back_link] = url_from(back_link_param) unless back_link_param.nil?
@back_url = url_from(back_link_param) || session[:back_link] || engagement_cases_path
Expand All @@ -56,41 +34,5 @@ def current_case
def filter_forms
@all_cases_filter_form = Support::Case.created_by_e_and_o.filtering(filter_params_for(:filter_all_cases_form))
end

def validation
Support::CreateCaseFormSchema.new.call(**form_params)
end

def form_params
params.require(:create_case_form).permit(
:organisation_id,
:organisation_name,
:organisation_type,
:organisation_urn,
:first_name,
:last_name,
:email,
:phone_number,
:extension_number,
:discovery_method,
:discovery_method_other_text,
:category_id,
:query_id,
:other_category,
:other_query,
:estimated_procurement_completion_date,
:estimated_savings,
:progress_notes,
:request_type,
:request_text,
:procurement_amount,
:upload_reference,
:blob_attachments,
file_attachments: [],
).merge({
source: :engagement_and_outreach_cms.to_s,
creation_source: :engagement_and_outreach_team.to_s,
})
end
end
end
32 changes: 21 additions & 11 deletions app/controllers/support/case_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
module Support
class CaseRequestsController < ApplicationController
before_action -> { @back_url = support_cases_path }, only: %i[new create]
before_action :case_request, only: %i[show edit update submit]

def new
@case_request = CaseRequest.new
def create
@case_request = CaseRequest.new(created_by: current_agent)
@case_request.save!(validate: false)
redirect_to edit_support_case_request_path(@case_request)
end

def create
@case_request = CaseRequest.new(form_params.except(:upload_reference))
@case_request.created_by = current_agent
def show; end

if @case_request.valid?
@case_request.save!
# kase = @case_request.create_case
def edit
@back_url = @case_request.completed? ? support_case_request_path(@case_request) : support_cases_path
end

# create_interaction(kase.id, "create_case", "Case created", @case_request.attributes.slice(:source, :category))
def update
@back_url = @case_request.completed? ? support_case_request_path(@case_request) : support_cases_path
@case_request.assign_attributes(form_params)

if @case_request.valid?
@case_request.save!
redirect_to support_case_request_path(@case_request)
else
render :new
render :edit
end
end

def submit
kase = @case_request.create_case
redirect_to support_case_path(kase)
end

private

def case_request
@case_request = CaseRequest.find_by(id: params[:id])
end

def form_params
params.require(:case_request).permit(
:organisation_id,
Expand Down
47 changes: 0 additions & 47 deletions app/controllers/support/cases/previews_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Support
module Cases
module RequestDetails
class ParticipatingSchoolsController < Cases::ApplicationController
def show
@back_url = support_case_request_details_path
@participating_schools = @current_case.request.selected_schools.map { |s| Support::OrganisationPresenter.new(s) }
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Support
module Cases
class RequestsController < Cases::ApplicationController
class RequestDetailsController < Cases::ApplicationController
def show
@request = FrameworkRequestPresenter.new(@current_case.framework_request)
@request = FrameworkRequestPresenter.new(@current_case.request)
end

private
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def edit
end

def update
@case_school_picker = current_case.school_picker(school_urns: form_params[:school_urns].compact_blank)
@case_school_picker = current_case.school_picker(school_urns: form_params[:school_urns].compact_blank.excluding("all"))
@case_school_picker.save!
redirect_to support_case_school_details_participating_schools_path
end
Expand Down
Loading

0 comments on commit 4a9f710

Please sign in to comment.