Skip to content

Commit

Permalink
Merge pull request #729 from bitzesty/main
Browse files Browse the repository at this point in the history
Staging < main
  • Loading branch information
TheDancingClown authored Sep 30, 2024
2 parents 1c723bd + bafd8a8 commit 78c7b37
Show file tree
Hide file tree
Showing 39 changed files with 1,316 additions and 248 deletions.
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);
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ $todo-black: #333;
}

.govuk-notification-banner__heading {
max-width: 700px
max-width: 100%
}
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
49 changes: 47 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,47 @@ 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 = if params[:bulk_action]
params[:bulk_action][:ids]
elsif params[:eligibility_assignment_collection]
# get form_answer_ids after validation error
params[:eligibility_assignment_collection][:form_answer_ids]
end
@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 +320,10 @@ def eligibility_params
)
end

def bulk_assign_params
params.require(:bulk_action).permit(ids: []).merge(params.permit(:bulk_assign_lieutenants, :bulk_assign_assessors, :bulk_assign_eligibility))
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
45 changes: 41 additions & 4 deletions app/controllers/concerns/form_answer_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,56 @@ 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)

unless @processor.valid?
flash[:bulk_error] = @processor.base_error_messages
redirect_to admin_form_answers_path(year: params[:year], search_id: @processor.search_id, anchor: "bulk_error") and return
end

redirect_url = @processor.redirect_url

if redirect_url
redirect_to redirect_url and return
end
end

# If search is present, save it and clean up the params.
# Do not pass params[:year] to the redirect as this does not work with the non-js search
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]]
end
year = JSON.parse(search.serialized_query)[:year]
redirect_to [namespace_name, :form_answers, search_id: search.id, year: year] and return

if params[:search_id]
elsif params[:search_id]
search = NominationSearch.find_by_id(params[:search_id])

if search.present?
payload = JSON.parse(search.serialized_query)
search_params[:search_filter] = payload["search_filter"]
search_params[:query] = payload["query"]
search_params[:sort] = payload["sort"]
search_params[:year] = payload["year"]

# Update the year parameter if it is different
if params[:year] && search_params[:year] != params[:year]
search_params[:year] = params[:year]
search.update_attribute(:serialized_query, search_params.to_json)

# Redirect to include the year parameter if it is not present
elsif !params[:year] && namespace_name == :admin
redirect_to [namespace_name, :form_answers, search_id: search.id, year: search_params[:year]] and return
end
end
end

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
Loading

0 comments on commit 78c7b37

Please sign in to comment.