Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start moving bulk assing out of js modules #709

Merged
merged 14 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions app/assets/javascripts/admin/form_answers.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,6 @@ ready = ->
else
area.addClass("if-js-hide")

$(document).on "submit", "#new_assessor_assignment_collection", (e) ->
form = $(this)
ids = ""
$(".form-answer-check:checked").each ->
ids += ($(@).val() + ",")
$("#assessor_assignment_collection_form_answer_ids").val(ids)

$(document).on "submit", "#new_lieutenant_assignment_collection", (e) ->
form = $(this)
ids = ""
$(".form-answer-check:checked").each ->
ids += ($(@).val() + ",")
$("#lieutenant_assignment_collection_form_answer_ids").val(ids)

changeRagStatus = ->
$(document).on "click", ".btn-rag .dropdown-menu a", (e) ->
e.preventDefault()
Expand Down
21 changes: 10 additions & 11 deletions app/assets/stylesheets/admin/page-applications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -474,28 +474,22 @@
}

.bulk-assignment-container {
display: none;
background-color: $grey-lightest;
padding: 20px 25px;

&.show-container {
.bulk-assignment-buttons-container {
display: flex;
align-items: center;
}

.show-bulk-assign & {
.js & {
display: none;
}
}

.bulk-assign-lieutenants-link, .bulk-assign-assessors-link {
.bulk-assign-lieutenants-link, .bulk-assign-assessors-link, .bulk-assign-eligibility-link {
margin-bottom: 20px;
margin-right: 20px;
}
}

.nominations-checked-total {
display: inline;
margin-right: 20px;
margin-bottom: 15px;
}

.bulk-assign-assessors-form, .bulk-assign-lieutenants-form {
Expand Down Expand Up @@ -599,3 +593,8 @@
.js-remove-audit-certificate-link span {
margin-top: 0;
}

.govuk-bulk-error-message {
margin-top: 20px;
color: rgb(212, 53, 28);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
class Admin::AssessorAssignmentCollectionsController < Admin::BaseController
def create
@assessor_assignment_collection = AssessorAssignmentCollection.new(create_params)
authorize @assessor_assignment_collection, :create?
@form = AssessorAssignmentCollection.new(create_params)
authorize @form, :create?

@assessor_assignment_collection.subject = current_subject
@form.subject = current_subject

@assessor_assignment_collection.save

respond_to do |format|
format.html do
flash[:notice] = @assessor_assignment_collection.notice_message
flash[:error] = @assessor_assignment_collection.errors.full_messages.to_sentence
redirect_back(fallback_location: root_path)
end
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_assessors"
end
end

Expand Down
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
45 changes: 43 additions & 2 deletions app/controllers/admin/form_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Admin::FormAnswersController < Admin::BaseController
expose(:target_scope) do
if params[:year].to_s == "all_years"
FormAnswer.all
elsif params[:year]
elsif params[:year].present?
(year = AwardYear.find_by(year: params[:year])) ? year.form_answers : FormAnswer.none
else
@award_year.form_answers
Expand Down Expand Up @@ -59,14 +59,14 @@ class Admin::FormAnswersController < Admin::BaseController
def index
authorize :form_answer, :index?
search_params = save_or_load_search!
return if search_params.nil? # Redirected from save_or_load_search!

@search = FormAnswerSearch.new(target_scope, current_admin).search(search_params)
@search.ordered_by = "company_or_nominee_name" unless @search.ordered_by
@form_answers = @search.results
.with_comments_counters
.group("form_answers.id")
.page(params[:page])

respond_to do |format|
format.html

Expand Down Expand Up @@ -253,6 +253,42 @@ def awarded_trade_applications
)
end

# batch actions

def bulk_assign_lieutenants
authorize :lieutenant_assignment_collection, :create?
form_answer_ids = if params[:bulk_action]
params[:bulk_action][:ids]
elsif params[:lieutenant_assignment_collection]
# get form_answer_ids after validation error
params[:lieutenant_assignment_collection][:form_answer_ids]
end

@form = LieutenantAssignmentCollection.new(form_answer_ids: form_answer_ids, params: bulk_assign_params)
end

def bulk_assign_assessors
authorize :assessor_assignment_collection, :create?

form_answer_ids = params[:bulk_action][:ids]
@form = AssessorAssignmentCollection.new(form_answer_ids: form_answer_ids)
end

def bulk_assign_eligibility
authorize :eligibility_assignment_collection, :create?

form_answer_ids = if params[:bulk_action]
params[:bulk_action][:ids]
elsif params[:lieutenant_assignment_collection]
# get form_answer_ids after validation error
params[:lieutenant_assignment_collection][:form_answer_ids]
end

@form = EligibilityAssignmentCollection.new(form_answer_ids: form_answer_ids)
end

# / batch actions

private

helper_method :resource
Expand All @@ -279,6 +315,11 @@ def eligibility_params
)
end

def bulk_assign_params
# params.require(:bulk_action).permit(ids: []).merge(params.permit(:bulk_assign_lieutenants))
params.permit!
dreamfall marked this conversation as resolved.
Show resolved Hide resolved
end

def resolve_layout
case action_name
when "edit", "update", "save"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
class Admin::LieutenantAssignmentCollectionsController < Admin::BaseController
def create
@lieutenant_assignment_collection = LieutenantAssignmentCollection.new(create_params)
authorize @lieutenant_assignment_collection, :create?
@form = LieutenantAssignmentCollection.new(create_params)
authorize @form, :create?

@lieutenant_assignment_collection.subject = current_subject
@form.subject = current_subject

@lieutenant_assignment_collection.save

respond_to do |format|
format.html do
flash[:notice] = @lieutenant_assignment_collection.notice_message
flash[:error] = @lieutenant_assignment_collection.errors.full_messages.to_sentence
redirect_back(fallback_location: root_path)
end
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_lieutenants"
end
end

private

def create_params
params
.require(:lieutenant_assignment_collection)
.permit(:form_answer_ids,
:ceremonial_county_id)
params.require(:lieutenant_assignment_collection)
.permit(:form_answer_ids, :ceremonial_county_id)
end
end
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def require_to_be_account_admin!
end

def load_award_year_and_settings
if params[:year] && AwardYear::AVAILABLE_YEARS.include?(params[:year].to_i)
if params[:year].present? && AwardYear::AVAILABLE_YEARS.include?(params[:year].to_i)
@award_year = AwardYear.for_year(params[:year].to_i).first_or_create
else
@award_year = AwardYear.current
Expand Down
1 change: 1 addition & 0 deletions app/controllers/assessor/form_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Assessor::FormAnswersController < Assessor::BaseController
def index
authorize :form_answer, :index?
search_params = save_or_load_search!
return if search_params.nil? # Redirected from save_or_load_search!

scope = current_assessor.applications_scope(
params[:year].to_s == "all_years" ? nil : @award_year
Expand Down
29 changes: 28 additions & 1 deletion app/controllers/concerns/form_answer_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,36 @@ def financial_data_ops
def save_or_load_search!
search_params = params[:search] || default_filters

if params[:bulk_assign_lieutenants] || params[:bulk_assign_assessors] || params[:bulk_assign_eligibility]

bulk_params = params.permit(
:year,
:bulk_assign_lieutenants,
:bulk_assign_assessors,
:bulk_assign_eligibility,
search: {},
bulk_action: { ids: [] }
)

@processor = NominationsBulkActionForm.new(bulk_params)
# Debugging: Inspect the parameters and validation errors
dreamfall marked this conversation as resolved.
Show resolved Hide resolved

unless @processor.valid?
# raise "Invalid bulk action parameters: #{params.to_yaml}\nErrors: #{@processor.errors.full_messages.to_yaml}"
dreamfall marked this conversation as resolved.
Show resolved Hide resolved
flash[:bulk_error] = @processor.base_error_messages
redirect_to admin_form_answers_path(year: params[:year], search_id: @processor.search_id) and return
end

redirect_url = @processor.redirect_url

if redirect_url
redirect_to redirect_url and return
end
end

if params[:search] && params[:search][:search_filter] != FormAnswerSearch.default_search[:search_filter]
search = NominationSearch.create(serialized_query: params[:search].to_json)
redirect_to [namespace_name, :form_answers, search_id: search.id, year: params[:year]]
redirect_to [namespace_name, :form_answers, search_id: search.id, year: params[:year]] and return
end

if params[:search_id]
Expand Down
1 change: 1 addition & 0 deletions app/controllers/lieutenant/form_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def index
authorize :form_answer, :index?

search_params = save_or_load_search!
return if search_params.nil? # Redirected from save_or_load_search!

scope = current_lieutenant.nominations_scope(
params[:year].to_s == "all_years" ? nil : @award_year
Expand Down
42 changes: 1 addition & 41 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,17 @@ SessionTimeout();

frontend.initAll()

$('.bulk-assign-lieutenants-link').on('click', function(e) {
e.preventDefault();
e.stopPropagation();

MicroModal.show('modal-bulk-assign-lieutenants');
$("html").addClass('modal-open');
})

$('.bulk-assign-assessors-link').on('click', function(e) {
e.preventDefault();
e.stopPropagation();

MicroModal.show('modal-bulk-assign-assessors');
$("html").addClass('modal-open');
})

$(document).on('click', 'button[data-micromodal-close]', function(e) {
e.preventDefault();
e.stopPropagation()
$("html").removeClass('modal-open');
})

if ($('.bulk-assignment-container').length > 0) {
$("#check_all").on("change", function() {
$("#check_all").on("click", function() {
var select_all_value = $(this).prop("checked");
$(this).closest("table").find(".form-answer-check").prop("checked", select_all_value)
});

$(".form-answer-check, #check_all").on("change", function() {
var show_button = false;

$(".form-answer-check").each(function() {
if ($(this).prop("checked")) {
show_button = true
}
})

if (show_button) {
$(".bulk-assignment-container").addClass("show-container")
$(".bulk-assignment-help").addClass("govuk-!-display-none")
var selected_count = $('input[type=checkbox].form-answer-check:checked').length
if (selected_count > 1) {
$('.nominations-checked-total').text(selected_count +' groups selected')
} else {
$('.nominations-checked-total').text(selected_count +' group selected')
}
} else {
$(".bulk-assignment-container").removeClass("show-container")
$(".bulk-assignment-help").removeClass("govuk-!-display-none")
}
})
}

var dropdowns = $('select[multiple]');
Expand Down
13 changes: 12 additions & 1 deletion app/javascript/styles/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@

.dropdown.open .dropdown-menu {
display: block;
}
}

#select-award-year {
padding-top: 9px !important;
}

#select-award-year__options {
font-family: "GDS Transport", sans-serif;
color: #444;
padding: 0.3em 1em 0.25em 0.5em;
margin-top: -1px;
}
2 changes: 2 additions & 0 deletions app/models/assessor_assignment_collection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class AssessorAssignmentCollection < AssignmentCollection
NOT_ASSIGNED = "not assigned"

validates :sub_group, presence: true

attribute :sub_group, String


Expand Down
Loading
Loading