generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cms): ability to update participating schools
Jira: PWNN-1638
- Loading branch information
1 parent
42ee86c
commit f4fcc88
Showing
35 changed files
with
499 additions
and
175 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
app/controllers/support/cases/confirm_organisation_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Support | ||
module Cases | ||
class ConfirmOrganisationController < Cases::ApplicationController | ||
def show | ||
@back_url = edit_support_case_organisation_path(current_case) | ||
@new_organisation = get_organisation | ||
end | ||
|
||
def update | ||
organisation = get_organisation | ||
CaseManagement::AssignOrganisationToCase.new.call( | ||
support_case_id: current_case.id, | ||
agent_id: current_agent.id, | ||
organisation_id: organisation.id, | ||
organisation_type: organisation.class.name, | ||
) | ||
redirect_to support_case_path(current_case, anchor: "school-details"), notice: I18n.t("support.case_organisation.flash.updated") | ||
end | ||
|
||
private | ||
|
||
def get_organisation | ||
type = params[:type] == Support::EstablishmentGroup.name ? Support::EstablishmentGroup : Support::Organisation | ||
type.find(params[:id]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/controllers/support/cases/school_details/participating_schools_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Support | ||
module Cases | ||
module SchoolDetails | ||
class ParticipatingSchoolsController < Cases::ApplicationController | ||
def show | ||
@back_url = support_case_school_details_path | ||
@participating_schools = @current_case.participating_schools.map { |s| Support::OrganisationPresenter.new(s) } | ||
end | ||
|
||
def edit | ||
@back_url = support_case_school_details_participating_schools_path | ||
@case_school_picker = current_case.school_picker | ||
@group = current_case.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 | ||
@case_school_picker = current_case.school_picker(school_urns: form_params[:school_urns].compact_blank) | ||
@case_school_picker.save! | ||
redirect_to support_case_school_details_participating_schools_path | ||
end | ||
|
||
private | ||
|
||
def form_params | ||
params.fetch(:participating_schools, {}).permit(filters: params.key?(:clear) ? nil : { local_authorities: [], phases: [] }, school_urns: []) | ||
end | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/controllers/support/cases/school_details_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Support | ||
module Cases | ||
class SchoolDetailsController < Cases::ApplicationController | ||
private | ||
|
||
def current_case | ||
@current_case ||= CasePresenter.new(super) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Support::Case::SchoolPickable | ||
extend ActiveSupport::Concern | ||
|
||
def school_picker(school_urns: participating_schools.map(&:urn)) | ||
Support::Case::SchoolPicker.new(support_case: self, school_urns:) | ||
end | ||
|
||
def pick_schools(school_urns) | ||
schools = Support::Organisation.where(urn: school_urns) | ||
self.participating_schools = schools | ||
save! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Support::Case::SchoolPicker | ||
include ActiveModel::Model | ||
|
||
attr_accessor( | ||
:support_case, | ||
:school_urns, | ||
) | ||
|
||
def save! | ||
support_case.pick_schools(school_urns) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/views/components/school_picker/_school_picker.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-one-third"> | ||
<%= render "components/school_picker/school_picker_filters", model: filters_model, url: filters_url, scope: %> | ||
</div> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: results_model, scope:, url: update_url, method: do |form| %> | ||
<%= form.govuk_error_summary %> | ||
|
||
<%= render "components/school_picker/school_picker_results", form: form, scope: %> | ||
|
||
<%= form.submit I18n.t("generic.button.save"), class: "govuk-button", role: "button" %> | ||
<% end %> | ||
</div> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
app/views/components/school_picker/_school_picker_filters.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="filters-panel"> | ||
<%= form_with model:, scope:, method: :get, url:, html: { "data-controller" => "school-picker-filters", "data-school-picker-filters-school-picker-outlet" => ".school-picker", "data-school-picker-filters-scope-value" => scope } do |form| %> | ||
<%= form.submit I18n.t("components.school_picker.filters.clear"), class: "govuk-button govuk-button--secondary", name: :clear, data: { action: "school-picker-filters#setSchoolUrns" } %> | ||
|
||
<%= form.fields :filters, model: do |f| %> | ||
<%= f.govuk_collection_check_boxes :phases, school_picker_phase_filter_options(@all_schools), :id, :title, small: true, legend: { text: I18n.t("components.school_picker.filters.phase"), size: "s" } if show_school_picker_phase_filters?(@all_schools) %> | ||
<%= f.govuk_collection_check_boxes :local_authorities, school_picker_la_filter_options(@all_schools), :id, :title, small: true, legend: { text: I18n.t("components.school_picker.filters.local_authority"), size: "s" } if show_school_picker_la_filters?(@all_schools) %> | ||
<% end %> | ||
<% end %> | ||
</div> |
32 changes: 32 additions & 0 deletions
32
app/views/components/school_picker/_school_picker_results.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<div class="school-picker" data-controller="school-picker" data-school-picker-scope-value=<%= scope %>> | ||
<p class="govuk-body"> | ||
<b data-school-picker-target="selectedCount"></b> | ||
<%= I18n.t("components.school_picker.table.selected", total: @all_schools.count, group_name: @group.name).html_safe %> | ||
</p> | ||
<%= form.govuk_check_boxes_fieldset :school_urns, legend: nil do %> | ||
<table class="govuk-table" aria-label="Available schools"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header"> | ||
<%= form.govuk_check_box :school_urns, :all, label: { text: I18n.t("components.school_picker.table.school_name").html_safe }, "data-school-picker-target": "selectAll", "data-action": "school-picker#toggleSelectAll" %> | ||
</th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("components.school_picker.table.address") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("components.school_picker.table.phase") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("components.school_picker.table.local_authority") %></th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body" data-school-picker-target="schoolTableBody"> | ||
<% @filtered_schools.each do |school| %> | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell"> | ||
<%= form.govuk_check_box :school_urns, school.urn, label: { text: school.name }, "data-action": "school-picker#toggleSelection" %> | ||
</td> | ||
<td class="govuk-table__cell"><%= school.formatted_address %></td> | ||
<td class="govuk-table__cell"><%= school.phase %></td> | ||
<td class="govuk-table__cell"><%= school.local_authority %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,4 @@ | ||
<%= render "framework_requests/common_form_fields", form: form %> | ||
<%= form.hidden_field :source %> | ||
|
||
<div class="school-picker" data-controller="school-picker"> | ||
<p class="govuk-body"> | ||
<b data-school-picker-target="selectedCount"></b> | ||
<%= I18n.t("faf.school_picker.table.selected", total: @all_schools.count, group_name: @group.name).html_safe %> | ||
</p> | ||
<%= form.govuk_check_boxes_fieldset :school_urns, legend: nil do %> | ||
<table class="govuk-table" aria-label="Available schools"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header"> | ||
<%= form.govuk_check_box :school_urns, :all, label: { text: I18n.t("faf.school_picker.table.school_name").html_safe }, "data-school-picker-target": "selectAll", "data-action": "school-picker#toggleSelectAll" %> | ||
</th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("faf.school_picker.table.address") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("faf.school_picker.table.phase") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("faf.school_picker.table.local_authority") %></th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body" data-school-picker-target="schoolTableBody"> | ||
<% @filtered_schools.each do |school| %> | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell"> | ||
<%= form.govuk_check_box :school_urns, school.urn, label: { text: school.name }, "data-action": "school-picker#toggleSelection" %> | ||
</td> | ||
<td class="govuk-table__cell"><%= school.formatted_address %></td> | ||
<td class="govuk-table__cell"><%= school.phase %></td> | ||
<td class="govuk-table__cell"><%= school.local_authority %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> | ||
</div> | ||
<%= render "components/school_picker/school_picker_results", form: form, scope: :framework_support_form %> |
Oops, something went wrong.