Skip to content

Commit

Permalink
Add Roster report download, first pass
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 21, 2021
1 parent e6fd466 commit ec6dd41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/scheduler/people_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Scheduler::PeopleController < Scheduler::BaseController
inherit_resources
include Paginatable
respond_to :html
respond_to :html, :csv
respond_to :js, only: :index

defaults resource_class: Roster::Person
Expand Down
32 changes: 32 additions & 0 deletions app/views/scheduler/people/index.csv.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%- headers = ['Name', 'Positions', 'Num Shifts', 'Prev Shift', 'Next Shift', 'Last Login', 'Flex Schedule'] -%>
<%= CSV.generate_line headers -%>
<%- collection.each do |person|
d = prev_shift(person)
if d
prev_shift = "#{d.to_s :dow_short} (#{(Date.current-d).to_i} days ago)"
else
prev_shift = ""
end
d = next_shift(person)
if d
next_shift = d.to_s :dow_short
else
next_shift = ""
end
d = person.last_login
if d
last_login = d.to_s :dow_short
else
last_login = ""
end
positions = person.positions.select{|p|!p.hidden}.map(&:name).join ", "
-%>
<%= CSV.generate_line([person.full_name,
positions,
pluralize(num_shifts(person), 'shift'),
prev_shift,
next_shift,
last_login,
flex_schedule_for(person.id).try(:num_shifts)
]).html_safe -%>
<%- end -%>
4 changes: 3 additions & 1 deletion app/views/scheduler/people/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- model_class = Roster::Person
.page-header
%h1=t '.title', :default => model_class.model_name.human.pluralize
%h1
=t '.title', :default => model_class.model_name.human.pluralize
%span(style="font-size:60%") (#{link_to 'Download as CSV', scheduler_people_path(format: :csv, params: request.query_parameters.merge(page: 'all'))})
=form_tag scheduler_people_path, method: :get, remote: true do
=hidden_field_tag 'page', ''
%table.table.table-condensed.noprint
Expand Down

0 comments on commit ec6dd41

Please sign in to comment.