-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide CSV downloads of table contents
For now, each table has to be downloaded individually. I'm trying to figure out if there's a way to combine all the files in a zip file and allow the user to download that. Closes #304.
- Loading branch information
Showing
38 changed files
with
621 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Admin | ||
class CsvController < ApplicationController | ||
before_action :set_filename | ||
|
||
# The CSV content for each action is defined in | ||
# app/views/admin/csv/{action_name}.csv.shaper | ||
|
||
def addresses | ||
end | ||
|
||
def contacts | ||
end | ||
|
||
def holiday_schedules | ||
end | ||
|
||
def locations | ||
end | ||
|
||
def mail_addresses | ||
end | ||
|
||
def organizations | ||
end | ||
|
||
def phones | ||
end | ||
|
||
def programs | ||
end | ||
|
||
def regular_schedules | ||
end | ||
|
||
def services | ||
end | ||
|
||
private | ||
|
||
def set_filename | ||
@filename = "All #{action_name} - #{Time.zone.today.to_formatted_s}.csv" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
csv.headers :id, :location_id, :address_1, :address_2, :city, | ||
:state_province, :postal_code, :country | ||
|
||
csv.rows Address.find_each do |csv, address| | ||
csv.cells :id, :location_id, :address_1, :address_2, :city, | ||
:state_province, :postal_code, :country | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
csv.headers :id, :location_id, :organization_id, :service_id, :name, :title, | ||
:email, :department | ||
|
||
csv.rows Contact.find_each do |csv, contact| | ||
csv.cells :id, :location_id, :organization_id, :service_id, :name, :title, | ||
:email, :department | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
csv.headers :id, :location_id, :service_id, :start_date, :end_date, :closed, | ||
:opens_at, :closes_at | ||
|
||
csv.rows HolidaySchedule.find_each do |csv, hs| | ||
csv.cells :id, :location_id, :service_id, :start_date, :end_date, :closed, | ||
:opens_at, :closes_at | ||
|
||
csv.cell :start_date, hs.start_date.strftime('%B %d, %Y') | ||
csv.cell :end_date, hs.end_date.strftime('%B %d, %Y') | ||
csv.cell :opens_at, hs.opens_at.strftime('%H:%M') if hs.opens_at | ||
csv.cell :closes_at, hs.closes_at.strftime('%H:%M') if hs.closes_at | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
csv.headers :id, :organization_id, :accessibility, :admin_emails, | ||
:alternate_name, :description, :email, :languages, | ||
:latitude, :longitude, :name, :short_desc, :transportation, | ||
:website, :virtual | ||
|
||
csv.rows Location.find_each do |csv, location| | ||
csv.cells :id, :organization_id, :accessibility, :admin_emails, | ||
:alternate_name, :description, :email, :languages, | ||
:latitude, :longitude, :name, :short_desc, :transportation, | ||
:website, :virtual | ||
|
||
csv.cell :accessibility, location.accessibility.map(&:text).join(', ') | ||
csv.cell :admin_emails, location.admin_emails.join(', ') | ||
csv.cell :languages, location.languages.try(:join, ', ') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
csv.headers :id, :location_id, :attention, :address_1, :address_2, :city, | ||
:state_province, :postal_code, :country | ||
|
||
csv.rows MailAddress.find_each do |csv, mail_address| | ||
csv.cells :id, :location_id, :attention, :address_1, :address_2, :city, | ||
:state_province, :postal_code, :country | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
csv.headers :id, :accreditations, :alternate_name, :date_incorporated, | ||
:description, :email, :funding_sources, :legal_status, :licenses, | ||
:name, :tax_id, :tax_status, :website | ||
|
||
csv.rows Organization.find_each do |csv, org| | ||
csv.cells :id, :accreditations, :alternate_name, :date_incorporated, | ||
:description, :email, :funding_sources, :legal_status, :licenses, | ||
:name, :tax_id, :tax_status, :website | ||
|
||
csv.cell :accreditations, org.accreditations.try(:join, ', ') | ||
csv.cell :date_incorporated, org.date_incorporated.try(:strftime, '%B %d, %Y') | ||
csv.cell :funding_sources, org.funding_sources.try(:join, ', ') | ||
csv.cell :licenses, org.licenses.try(:join, ', ') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
csv.headers :id, :contact_id, :location_id, :organization_id, :service_id, | ||
:country_prefix, :department, :extension, :number, :number_type, | ||
:vanity_number | ||
|
||
csv.rows Phone.find_each do |csv, phone| | ||
csv.cells :id, :contact_id, :location_id, :organization_id, :service_id, | ||
:country_prefix, :department, :extension, :number, :number_type, | ||
:vanity_number | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
csv.headers :id, :organization_id, :alternate_name, :name | ||
|
||
csv.rows Program.find_each do |csv, _| | ||
csv.cells :id, :organization_id, :alternate_name, :name | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
csv.headers :id, :location_id, :service_id, :weekday, :opens_at, :closes_at | ||
|
||
csv.rows RegularSchedule.find_each do |csv, rs| | ||
csv.cells :id, :location_id, :service_id, :weekday, :opens_at, :closes_at | ||
|
||
csv.cell :opens_at, rs.opens_at.strftime('%H:%M') | ||
csv.cell :closes_at, rs.closes_at.strftime('%H:%M') | ||
csv.cell :weekday, rs.weekday == 7 ? 'Sunday' : Date::DAYNAMES[rs.weekday] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
csv.headers :id, :location_id, :program_id, :accepted_payments, | ||
:alternate_name, :application_process, :audience, :description, | ||
:eligibility, :email, :fees, :funding_sources, | ||
:interpretation_services, :keywords, :languages, :name, | ||
:required_documents, :service_areas, :status, :wait_time, :website, | ||
:taxonomy_ids | ||
|
||
csv.rows Service.find_each do |csv, service| | ||
csv.cells :id, :location_id, :program_id, :accepted_payments, | ||
:alternate_name, :application_process, :audience, :description, | ||
:eligibility, :email, :fees, :funding_sources, | ||
:interpretation_services, :keywords, :languages, :name, | ||
:required_documents, :service_areas, :status, :wait_time, :website, | ||
:category_ids | ||
|
||
csv.cell :accepted_payments, service.accepted_payments.try(:join, ', ') | ||
csv.cell :funding_sources, service.funding_sources.try(:join, ', ') | ||
csv.cell :keywords, service.keywords.try(:join, ', ') | ||
csv.cell :languages, service.languages.try(:join, ', ') | ||
csv.cell :required_documents, service.required_documents.try(:join, ', ') | ||
csv.cell :service_areas, service.service_areas.try(:join, ', ') | ||
csv.cell :taxonomy_ids, service.categories.pluck(:taxonomy_id).join(', ') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CsvShaper.configure do |config| | ||
config.header_inflector = :underscore | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
factory :org_with_extra_whitespace, class: Organization do | ||
accreditations ['BBB ', ' AAA'] | ||
alternate_name 'AKA ' | ||
date_incorporated 'April 25, 2001' | ||
description 'Organization created for testing purposes ' | ||
email '[email protected] ' | ||
funding_sources ['County ', ' State '] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
feature 'Downloading Addresses CSV' do | ||
before do | ||
@address = create(:address, location_id: 1) | ||
visit admin_csv_addresses_path(format: 'csv') | ||
end | ||
|
||
it 'contains the same headers as in the import Wiki' do | ||
expect(csv.first).to eq %w(id location_id address_1 address_2 city | ||
state_province postal_code country) | ||
end | ||
|
||
it 'populates address attribute values' do | ||
expect(csv.second).to eq [ | ||
@address.id.to_s, @address.location_id.to_s, '1800 Easton Drive', nil, | ||
'Burlingame', 'CA', '94010', 'US'] | ||
end | ||
end |
Oops, something went wrong.