-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
126 additions
and
8 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
app/controllers/admin/eligibility_assignment_collections_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,23 @@ | ||
class Admin::EligibilityAssignmentCollectionsController < Admin::BaseController | ||
def create | ||
@form = EligibilityAssignmentCollection.new(create_params) | ||
authorize @form, :create? | ||
|
||
@form.subject = current_subject | ||
|
||
if @form.save | ||
redirect_to admin_form_answers_path(year: params[:year], search_id: params[:search_id]), notice: @form.notice_message | ||
else | ||
# Ensure form_answer_ids is an array | ||
@form.form_answer_ids = @form.form_answer_ids.split(",") if @form.form_answer_ids.is_a?(String) | ||
render "admin/form_answers/bulk_assign_eligibility" | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_params | ||
params.require(:eligibility_assignment_collection) | ||
.permit(:form_answer_ids, :state) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class EligibilityAssignmentCollection < AssignmentCollection | ||
VALID_STATES = %w[submitted admin_pending_eligibility].freeze | ||
|
||
|
||
attribute :state, String | ||
|
||
validates :state, presence: true, inclusion: { in: FormAnswerStateMachine::ELIGIBILITY_STATES.map(&:to_s) } | ||
|
||
validate :form_answers_state_validation | ||
|
||
def save | ||
return unless valid? | ||
form_answers.update_all(state: state) | ||
end | ||
|
||
def notice_message | ||
if ids.length > 1 | ||
"Groups have" | ||
else | ||
"Group has" | ||
end.concat " been assigned the #{state} status." | ||
end | ||
|
||
private | ||
|
||
def form_answers_state_validation | ||
unless form_answers.all? { |form_answer| VALID_STATES.include?(form_answer.state) } | ||
errors.add(:form_answer_ids, "To assign the eligibility status, you must only select groups that currently have ‘Nomination submitted’ or ‘Eligibility pending’ status.") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class EligibilityAssignmentCollectionPolicy < ApplicationPolicy | ||
def create? | ||
admin? | ||
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
24 changes: 24 additions & 0 deletions
24
app/views/admin/form_answers/bulk_assign_eligibility.html.slim
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,24 @@ | ||
|
||
h3.govuk-heading-m | ||
| Assign eligibility status to selected groups | ||
|
||
= simple_form_for [namespace_name, @form] do |f| | ||
.govuk-form-group.primary-subgroup-group | ||
= f.input :state, | ||
as: :radio_buttons, | ||
collection: FormAnswerStateMachine::ELIGIBILITY_STATES.map { |s| [t(s, scope: "form_answers.state"), s] }, | ||
input_html: { class: "admin-eligibility-option" }, | ||
label: "Select the eligibility status", | ||
label_html: { class: "govuk-!-font-size-19 govuk-!-margin-bottom-0" } | ||
- if @form.errors[:sub_group].any? | ||
.govuk-error-message | ||
| Please select a national assessor sub-group | ||
|
||
= f.hidden_field :search_id, value: params[:search_id], name: :search_id | ||
= f.hidden_field :year, value: params[:year], name: :year | ||
|
||
= f.hidden_field :form_answer_ids, value: @form.form_answer_ids.join(",") | ||
|
||
.govuk-button-group | ||
= f.submit "Bulk assign eligibility status", class: "govuk-button" | ||
= link_to "Cancel", [namespace_name, :form_answers, year: params[:year], search_id: params[:search_id]], class: "govuk-link" |
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