Skip to content

Commit

Permalink
Add download capability for CSV downloads
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 25, 2021
1 parent 06797de commit ae91a97
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/models/incidents/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(person)

dispatch_console(region_admin) if is_admin or person.has_capability 'dispatch_console'
create_incident if person.has_capability 'create_incident'
download if person.has_capability 'download'
submit_incident_report if is_admin or person.has_capability 'submit_incident_report'
cas_admin if is_admin or person.has_capability 'cas_admin'
incident_details if is_admin or person.has_capability 'incident_details'
Expand Down Expand Up @@ -87,6 +88,10 @@ def incidents_admin(region_admin)
can :manage, Incidents::InitialIncidentReport, incident: {region_id: @region_scope}
end

def download
can :download, Incidents::Incident, region_id: @region_scope
end

def incident_details
can [:read_dat_details, :index], Incidents::Incident
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/scheduler/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def initialize(person)
dat_admin_shift_territories = person.scope_for_capability('shift_territory_dat_admin')
shift_territory_dat_admin dat_admin_shift_territories if dat_admin_shift_territories.present? # is dat shift_territory admin

download if person.has_capability 'region_admin' or person.has_capability 'download'

read_only if ENV['READ_ONLY']
end

Expand Down Expand Up @@ -71,4 +73,9 @@ def shift_territory_dat_admin ids
def read_only
cannot [:update, :create, :destroy], :all
end

def download
can :download, Scheduler::Shift
can :download, Roster::Person
end
end
5 changes: 3 additions & 2 deletions app/views/incidents/incidents_list/_index_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.text-center= paginate collection, :theme => 'twitter-bootstrap-3', remote: true

%h1(style="font-size:150%;text-align:center;margin-top:0px")
= link_to 'Download as CSV', incidents_region_incidents_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "incidents.csv"
- if can? :download, Incidents::Incident
%h1(style="font-size:150%;text-align:center;margin-top:0px")
= link_to 'Download as CSV', incidents_region_incidents_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "incidents.csv"

%table.table.table-condensed
%tr
Expand Down
3 changes: 2 additions & 1 deletion app/views/incidents/responses/responders.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
=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"
- if can? :download, Incidents::Incident
= 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 Down
5 changes: 3 additions & 2 deletions app/views/scheduler/people/_index_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.text-center= paginate collection, :theme => 'twitter-bootstrap-3', remote: true
%h1(style="font-size:150%;text-align:center;margin-top:0px")
= link_to 'Download as CSV', scheduler_people_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "people.csv"
- if can? :download, Roster::Person
%h1(style="font-size:150%;text-align:center;margin-top:0px")
= link_to 'Download as CSV', scheduler_people_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "people.csv"

%table.table.table-striped.table-condensed
%thead
Expand Down
5 changes: 3 additions & 2 deletions app/views/scheduler/shift_report/_index_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.text-center= paginate collection, :theme => 'twitter-bootstrap-3', remote: true
%h1(style="font-size:150%;text-align:center;margin-top:0px")
= link_to 'Download as CSV', scheduler_shift_report_index_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "shifts.csv"
- if can? :download, Scheduler::Shift
%h1(style="font-size:150%;text-align:center;margin-top:0px")
= link_to 'Download as CSV', scheduler_shift_report_index_path(format: :csv, params: request.query_parameters.merge(page: 'all')), download: "shifts.csv"

%table.table.table-striped.table-condensed
%thead
Expand Down

0 comments on commit ae91a97

Please sign in to comment.