Skip to content

Commit

Permalink
Add responders history date search, csv
Browse files Browse the repository at this point in the history
Issue #301: Built-in report pages, to replace dependency on external query
            dashboards.
  • Loading branch information
Frank Duncan committed Feb 24, 2021
1 parent 2dc1deb commit 7c01324
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
22 changes: 19 additions & 3 deletions app/controllers/incidents/responses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
class Incidents::ResponsesController < Incidents::BaseController

#respond_to :html, :csv

has_scope :with_person_in_shift_territories, as: :shift_territory_id, default: ->controller{controller.current_user.primary_shift_territory_id}
has_scope :response_in_last, default: 180 do |controller, scope, val|
date = Date.current - val.to_i
scope.left_outer_joins(:incident).where(incidents_incidents: { date: date..DateTime::Infinity.new })
has_scope :date_after, :allow_blank => true, :default => FiscalYear.current.start_date.to_s do |controller, scope, val|
if not controller.params[:date_before].blank?
scope.left_outer_joins(:incident).where(incidents_incidents: { date: val..controller.params[:date_before] })
elsif not val.blank?
scope.left_outer_joins(:incident).where("incidents_incidents.date > ?", val)
else
scope
end
end
has_scope :date_before do |controller, scope, val|
# This is a hack, I guess, but I don't know how to do it otherwise
# If there date_after is present, we have to let that scope handle everything
if not controller.params[:date_after].blank?
scope
else
scope.left_outer_joins(:incident).where("incidents_incidents.date < ?", val)
end
end

expose(:responders) {
Expand Down
12 changes: 12 additions & 0 deletions app/views/incidents/responses/responders.csv.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%- headers = ['Name', 'Last Contacted', 'Responses', 'Not Available'] -%>
<%= CSV.generate_line headers -%>
<%- responders.each do |responder, assignments|
recent = assignments.first
-%>
<%= CSV.generate_line([
responder.full_name,
recent && recent.incident.date.to_s(:mdy),
assignments.select(&:was_available).count,
assignments.reject{|r| r.was_available || r.was_flex }.count
]).html_safe -%>
<%- end -%>
9 changes: 7 additions & 2 deletions app/views/incidents/responses/responders.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
=form_tag '', method: :get, class: 'form-inline' do
Show Shift Territory:
=select_tag :shift_territory_id, options_from_collection_for_select(current_region.shift_territories.enabled, :id, :name, current_scopes[:shift_territory_id]), class: "form-control"
Responses Between:
=date_field_tag "date_after", (current_scopes[:date_after] or FiscalYear.current.start_date.to_s), class: 'form-control', placeholder: 'After YYYY-MM-DD'
and:
=date_field_tag "date_before", current_scopes[:date_before], class: 'form-control', placeholder: 'Before YYYY-MM-DD'
=submit_tag 'Show', class: 'btn btn-primary'

= link_to 'Download as CSV', incidents_region_responders_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "people.csv"
.legend
%span.text-success
%i.fa.fa-check-square
Expand All @@ -18,10 +23,10 @@
%tr
%th Name
%th Last Contacted
%th Available
%th Responses
%th Not Available
%th(colspan=max_responses)
Responses
Last 10 Responses (within Date Range)

%tbody
- responders.each do |responder, assignments|
Expand Down

0 comments on commit 7c01324

Please sign in to comment.