Skip to content

Commit

Permalink
feat: start moving bulk assing out of js modules
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamfall committed Aug 19, 2024
1 parent 484b968 commit 8533caa
Show file tree
Hide file tree
Showing 16 changed files with 4,501 additions and 3,688 deletions.
4 changes: 1 addition & 3 deletions app/assets/stylesheets/admin/page-applications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,6 @@
}

.bulk-assignment-container {
display: none;

&.show-container {
display: flex;
align-items: center;
Expand All @@ -487,7 +485,7 @@
}
}

.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;
}
Expand Down
51 changes: 50 additions & 1 deletion app/controllers/admin/form_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ def index
.page(params[:page])

respond_to do |format|
format.html
format.html do
raise params[:bulk_action].to_yaml if params[:bulk_action].present?

@processor = NominationsBulkActionForm.new(params)

redirect_url = @processor.redirect_url

if redirect_url
redirect_to redirect_url
return
end
end

format.csv do
timestamp = Time.zone.now.strftime("%d-%m-%Y")
Expand Down Expand Up @@ -253,6 +264,44 @@ def awarded_trade_applications
)
end

# batch actions

def bulk_assign_lieutenants
authorize :lieutenant_assignment_collection, :create?

@form = LieutenantAssignmentCollection.new
@form.form_answer_ids = []
end

def bulk_assign_lieutenants_confirm
authorize :lieutenant_assignment_collection, :create?

# ConfirmationForm.new(kind: "bulk_assign_lieutenants")
end

def bulk_assign_assessors
authorize :assessor_assignment_collection, :create?

@form = AssessorAssignmentCollection.new
@form.form_answer_ids = []
end

def bulk_assign_assessors_confirm
authorize :assessor_assignment_collection, :create?

# ConfirmationForm.new(kind: "bulk_assign_assessors")
end

def bulk_assign_eligibility
authorize :eligibility_assignment_collection, :create?
end

def bulk_assign_eligibility_confirm
authorize :eligibility_assignment_collection, :create?
end

# / batch actions

private

helper_method :resource
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
- if show_bulk_lieutenants_assignment?

.if-no-js-hide
p.govuk-body.bulk-assignment-help
| Select groups from the list below to bulk assign to Lord Lieutenancy office or national assessor sub-groups.
.bulk-assignment-container
p.govuk-body.nominations-checked-total
button.govuk-button.bulk-assign-lieutenants-link type="button" Bulk assign to Lord Lieutenancy office

button.govuk-button.bulk-assign-assessors-link type="button" Bulk assign to national assessor sub-group
.bulk-assignment-container
p.govuk-body.nominations-checked-total aria-live='polite'
= f.submit "Bulk assign to Lord Lieutenancy office", class: "govuk-button bulk-assign-lieutenants-link", name: "bulk_assign_lieutenants"
= f.submit "Bulk assign to national assessor sub-group", class: "govuk-button bulk-assign-assessors-link", name: "bulk_assign_assessors"
= f.submit "Bulk assign eligibility status", class: "govuk-button bulk-assign-eligibility-link", name: "bulk_assign_eligibility"
54 changes: 0 additions & 54 deletions app/views/admin/form_answers/_bulk_assignment_modal.html.slim

This file was deleted.

17 changes: 17 additions & 0 deletions app/views/admin/form_answers/bulk_assign_assessors.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
h3.govuk-heading-m
| Bulk assign groups to national assessor sub-group

= form_for [namespace_name, @form] do |f|
= flash[:error]
.govuk-form-group.primary-subgroup-group
= f.label :sub_group, "Select national assessor sub-group", class: "govuk-label"
= f.select :sub_group,
Assessor.sub_group.options,
{ include_blank: true },
class: "govuk-select custom-select"

= f.text_field :form_answer_ids, class: "if-js-hide visuallyhidden"

.govuk-button-group
= f.submit "Bulk assign groups to national assessor sub-group", class: "govuk-button"
= link_to "Cancel", [namespace_name, :form_answers], class: "govuk-link"
17 changes: 17 additions & 0 deletions app/views/admin/form_answers/bulk_assign_lieutenants.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
h3.govuk-heading-m
| Bulk assign groups to Lord Lieutenancy office

= form_for [namespace_name, @form] do |f|
= flash[:error]
.govuk-form-group.primary-lieutenant-group
= f.label :ceremonial_county_id, "Select Lord Lieutenancy office", class: "govuk-label"
= f.select :ceremonial_county_id,
CeremonialCounty.ordered.pluck(:name, :id),
{ include_blank: true },
class: "govuk-select custom-select"

= f.text_field :form_answer_ids, class: "if-js-hide visuallyhidden"

.govuk-button-group
= f.submit "Bulk assign groups to Lord Lieutenancy office", class: "govuk-button"
= link_to "Cancel", [namespace_name, :form_answers], class: "govuk-link"
3 changes: 1 addition & 2 deletions app/views/admin/form_answers/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ h1.govuk-heading-xl
hr.govuk-section-break.govuk-section-break--l.govuk-section-break--visible
- if policy(:form_answer).can_download_csv_reports?
= render("admin/form_answers/csv_reports_links")
= render("admin/form_answers/bulk_assignment_button_top")
= render("admin/form_answers/bulk_assignment_button_top", f: f)

= render("admin/form_answers/list_components/table", f: f)
= render("admin/form_answers/bulk_assignment_button_bottom")

= paginate @form_answers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- obj = form_answer.decorate
tr.govuk-table__row
- if show_bulk_lieutenants_assignment?
td.govuk-table__cell = check_box_tag "check_#{obj.id}", obj.id, false, class: "form-answer-check", aria: { label: "Select nomination #{obj.id} for bulk action" }
td.govuk-table__cell = check_box_tag "bulk_action[ids][]", obj.id, false, class: "form-answer-check", aria: { label: "Select nomination #{obj.id} for bulk action" }
td.td-title.govuk-table__cell
- if obj.company_or_nominee_name.present?
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year], page: params[:page]), aria: { label: "View submitted nomination for #{obj.company_or_nominee_name}" }, class: 'govuk-link', target: :_blank do
Expand Down
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@
collection do
post :index
get :awarded_trade_applications

%w[bulk_assign_lieutenants bulk_assign_assessors bulk_assign_eligibility].each do |action|
get action
post action
get "#{action}_confirm"
post "#{action}_confirm"
end
end

member do
Expand Down
Loading

0 comments on commit 8533caa

Please sign in to comment.