Skip to content

Commit 90f3b7b

Browse files
committed
feat: Use interactive table on bus list passengers
1 parent 7364223 commit 90f3b7b

File tree

4 files changed

+52
-54
lines changed

4 files changed

+52
-54
lines changed

app/assets/javascripts/manage/lib/datatables.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ $.fn.autoDatatable = function() {
3434

3535
var config = convertDataAttrsToConfig(this);
3636
if (config.order) {
37-
var parts = config.order.split(' ');
38-
var index = parseInt(parts[0], 10);
39-
var direction = parts.length > 1 ? parts[1] : 'asc';
40-
config.order = [index, direction];
37+
var sequence = config.order.split(',').map(function(piece) {
38+
return piece.trim();
39+
});
40+
config.order = sequence.map(function(piece) {
41+
var parts = piece.split(' ');
42+
var index = parseInt(parts[0], 10);
43+
var direction = parts.length > 1 ? parts[1] : 'asc';
44+
return [index, direction];
45+
});
4146
} else {
4247
config.order = [1, 'asc'];
4348
}

app/datatables/questionnaire_datatable.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class QuestionnaireDatatable < ApplicationDatatable
2-
def_delegators :@view, :link_to, :manage_questionnaire_path, :manage_school_path, :current_user, :acc_status_class, :display_datetime, :bold
2+
def_delegators :@view, :link_to, :manage_questionnaire_path, :manage_school_path, :toggle_bus_captain_manage_bus_list_path, :current_user, :acc_status_class, :display_datetime, :bold
33

44
def view_columns
55
@view_columns ||= {
@@ -14,6 +14,7 @@ def view_columns
1414
acc_status: { source: "Questionnaire.acc_status", searchable: true },
1515
checked_in: { source: "Questionnaire.checked_in_at", searchable: false },
1616
boarded_bus: { source: "Questionnaire.boarded_bus_at", searchable: false },
17+
bus_captain: { source: "Questionnaire.is_bus_captain", searchable: false },
1718
school: { source: "School.name" },
1819
created_at: { source: "Questionnaire.created_at", searchable: false },
1920
dietary_restrictions: { source: "Questionnaire.dietary_restrictions", searchable: true },
@@ -32,6 +33,17 @@ def note(record)
3233
output.html_safe
3334
end
3435

36+
def bus_captain(record)
37+
return "No" unless record.bus_list_id?
38+
return record.is_bus_captain? ? '<span class="badge badge-success">Yes</span>' : "No" unless current_user.admin?
39+
40+
if record.is_bus_captain?
41+
link_to("Remove", toggle_bus_captain_manage_bus_list_path(record.bus_list, questionnaire_id: record.id, bus_captain: "0"), method: "post", class: "text-danger")
42+
else
43+
link_to("Promote", toggle_bus_captain_manage_bus_list_path(record.bus_list, questionnaire_id: record.id, bus_captain: "1"), method: "post", data: { confirm: "Are you sure you want to make #{record.full_name} a bus captain? They will receive a confirmation email." })
44+
end
45+
end
46+
3547
def data
3648
records.map do |record|
3749
{
@@ -48,6 +60,7 @@ def data
4860
acc_status: "<span class=\"text-#{acc_status_class(record.acc_status)}\">#{record.acc_status.titleize}</span>".html_safe,
4961
checked_in: record.checked_in? ? '<span class="badge badge-success">Yes</span>'.html_safe : "No",
5062
boarded_bus: record.boarded_bus? ? '<span class="badge badge-success">Yes</span>'.html_safe : "No",
63+
bus_captain: bus_captain(record),
5164
school: link_to(record.school.name, manage_school_path(record.school)),
5265
created_at: record.created_at.present? ? display_datetime(record.created_at) : "",
5366
dietary_restrictions: record.dietary_restrictions,
@@ -57,6 +70,16 @@ def data
5770
end
5871

5972
def get_raw_records
60-
Questionnaire.includes(:user, :school).references(:user, :school)
73+
records = Questionnaire.includes(:user, :school).references(:user, :school)
74+
if @params[:school_id].present?
75+
records = records.where(school_id: @params[:school_id])
76+
end
77+
if @params[:bus_list_id].present?
78+
records = records.where(bus_list_id: @params[:bus_list_id])
79+
end
80+
if @params[:acc_status].present?
81+
records = records.where(acc_status: @params[:acc_status])
82+
end
83+
records
6184
end
6285
end

app/views/manage/application/_questionnaire_datatable.html.haml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
columns ||= %w(link note first_name last_name email acc_status checked_in school created_at)
99
visible = -> (column, columns) { columns.include?(column) ? 'true' : 'false' }
1010

11+
order ||= "15 desc"
12+
bulk_actions = true unless defined?(bulk_actions)
13+
1114
# Use default page length if not defined
1215
page_length ||= nil
1316

1417
%div
15-
%table.datatable.table.table-striped.table-hover{ data: { "auto-datatable": true, source: data_source, "table-order": "14 desc", 'page-length': page_length } }
18+
%table.datatable.table.table-striped.table-hover{ data: { "auto-datatable": true, source: data_source, "table-order": order, 'page-length': page_length } }
1619
%thead
1720
%tr
18-
%th{'data-table': { orderable: 'false', data: 'bulk' }}
21+
%th{'data-table': { orderable: 'false', data: 'bulk', visible: bulk_actions ? 'true' : 'false' }}
1922
- if current_user.admin?
2023
%input{ type: "checkbox", name: "select_allc", value: "1", data: { bulk_row_select: "" } }
2124
%th{'data-table': { orderable: 'false', data: 'link', visible: visible.call('link', columns) }}
@@ -30,6 +33,7 @@
3033
%th{'data-table': { orderable: 'true', data: 'acc_status', visible: visible.call('acc_status', columns) }} Status
3134
%th{'data-table': { orderable: 'true', data: 'checked_in', visible: visible.call('checked_in', columns) }} Checked in
3235
%th{'data-table': { orderable: 'true', data: 'boarded_bus', visible: visible.call('boarded_bus', columns) }} Boarded bus
36+
%th{'data-table': { orderable: 'true', data: 'bus_captain', visible: visible.call('bus_captain', columns) }} Bus captain
3337
%th{'data-table': { orderable: 'true', data: 'school', visible: visible.call('school', columns) }} School
3438
%th{'data-table': { orderable: 'true', data: 'created_at', visible: visible.call('created_at', columns) }} Applied on
3539
%th{'data-table': { orderable: 'true', data: 'dietary_restrictions', visible: visible.call('dietary_restrictions', columns) }} Dietary restrictions
@@ -60,6 +64,7 @@
6064
%option{value: key}= value
6165
%th
6266
%th
67+
%th
6368
%th
6469
%input.form-control.form-control-sm{autocomplete: 'off', placeholder: 'School'}
6570
%th
@@ -69,12 +74,13 @@
6974
%input.form-control.form-control-sm{autocomplete: 'off', placeholder: 'Special needs'}
7075
7176
72-
.row
73-
.col-sm-7.col-lg-6
74-
%br
75-
.card
76-
.card-body
77-
%h5.card-title Bulk Action
78-
= bs_vertical_simple_form Questionnaire.new, url: bulk_apply_manage_questionnaires_path, html: { data: { bulk_row_edit: true } } do |f|
79-
= f.input :acc_status, as: :select, collection: Questionnaire::POSSIBLE_ACC_STATUS.invert, include_blank: false, label: "Acceptance Status:", input_html: { data: { bulk_row_edit: true } }, hint: "Updating this status may trigger an automatic email to each applicant - see below for details."
80-
= f.button :submit, value: "Update Status", data: { bulk_row_edit: true }, class: 'btn-primary'
77+
- if bulk_actions
78+
.row
79+
.col-sm-7.col-lg-6
80+
%br
81+
.card
82+
.card-body
83+
%h5.card-title Bulk Action
84+
= bs_vertical_simple_form Questionnaire.new, url: bulk_apply_manage_questionnaires_path, html: { data: { bulk_row_edit: true } } do |f|
85+
= f.input :acc_status, as: :select, collection: Questionnaire::POSSIBLE_ACC_STATUS.invert, include_blank: false, label: "Acceptance Status:", input_html: { data: { bulk_row_edit: true } }, hint: "Updating this status may trigger an automatic email to each applicant - see below for details."
86+
= f.button :submit, value: "Update Status", data: { bulk_row_edit: true }, class: 'btn-primary'

app/views/manage/bus_lists/show.html.haml

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,7 @@
4747
Passengers
4848
%small.text-muted (#{@bus_list.passengers.count} total, #{@bus_list.boarded_passengers.count} boarded, #{@bus_list.checked_in_passengers.count} checked in)
4949

50-
%table.table
51-
%thead
52-
%tr
53-
%th
54-
%th First Name
55-
%th Last Name
56-
%th Email
57-
%th Phone Number
58-
%th School
59-
%th Boarded bus?
60-
%th Checked in?
61-
%th Bus Captain
62-
%tbody
63-
- was_bus_captain = false
64-
- @bus_list.passengers.reorder('is_bus_captain DESC, last_name ASC').each do |p|
65-
- # Visual separator between captains and passengers
66-
- if was_bus_captain && !p.is_bus_captain
67-
%tr
68-
%td{colspan: 9}
69-
- was_bus_captain = p.is_bus_captain
70-
%tr
71-
%td= link_to '<i class="fa fa-search"></i>'.html_safe, manage_questionnaire_path(p)
72-
%td= p.first_name
73-
%td= p.last_name
74-
%td= p.email
75-
%td= phone_link_to p.phone
76-
%td= link_to p.school.name, manage_school_path(p.school)
77-
%td= p.boarded_bus? ? '<span class="text-success">Yes</span>'.html_safe : 'No'
78-
%td= p.checked_in? ? '<span class="text-success">Yes</span>'.html_safe : 'No'
79-
- if current_user.admin?
80-
%td
81-
- if p.is_bus_captain?
82-
= link_to "Remove", toggle_bus_captain_manage_bus_list_path(@bus_list, questionnaire_id: p.id, bus_captain: '0'), method: 'post', class: 'text-danger'
83-
- else
84-
= link_to "Promote", toggle_bus_captain_manage_bus_list_path(@bus_list, questionnaire_id: p.id, bus_captain: '1'), method: 'post', data: { confirm: "Are you sure you want to make #{p.full_name} a bus captain? They will receive a confirmation email." }
85-
- else
86-
%td= p.is_bus_captain? ? "Yes" : "No"
50+
= render "questionnaire_datatable", scope_params: { bus_list_id: @bus_list.id, acc_status: 'rsvp_confirmed' }, columns: %w(link first_name last_name email phone checked_in boarded_bus bus_captain school), order: '13 desc, 15 desc', bulk_actions: false
8751

8852
- if @bus_list.needs_bus_captain
8953
%h4.mt-4.pb-2 Possible Bus Captains

0 commit comments

Comments
 (0)