Skip to content

Commit

Permalink
VFEP-1232: Create two buttons for Institution export, one for Brian (…
Browse files Browse the repository at this point in the history
…subset of columns), one for developers (full set of columns) (#1070)

* Restore ability to export for Brian process

* fix archives controller and spec

* fix rubocop flagged issue

---------

Co-authored-by: nfstern02 <[email protected]>
  • Loading branch information
GcioGregg and nfstern02 authored Apr 1, 2024
1 parent d21dbc8 commit f3820ba
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/archives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index
def export
respond_to do |format|
format.csv do
send_data csv_model(params[:csv_type]).export_by_version,
send_data csv_model(params[:csv_type]).export_by_version(export_all: true),
type: 'text/csv',
filename: "#{params[:csv_type]}_version_#{params[:number]}.csv"
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def export
def export_version
respond_to do |format|
format.csv do
send_data Institution.export_by_version,
send_data Institution.export_by_version(params[:export_all]),
type: 'text/csv',
filename: "institutions_version_#{params[:number]}.csv"
end
Expand Down
20 changes: 9 additions & 11 deletions app/models/concerns/dashboard_watir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ module DashboardWatir
extend ActiveSupport::Concern

# rubocop:disable Metrics/BlockLength
# rubocop:disable Lint/ConstantDefinitionInBlock
included do
LOCAL_URL = 'http://localhost:4000/user/sign_in'
LOCAL_DASHBOARD = 'http://localhost:4000/dashboards'
LOCAL_IMPORT_PREFIX = '/uploads/new/'
LOCAL_URL ||= 'http://localhost:4000/user/sign_in'
LOCAL_DASHBOARD ||= 'http://localhost:4000/dashboards'
LOCAL_IMPORT_PREFIX ||= '/uploads/new/'

PROD_URL = 'https://www.va.gov/gids/user/sign_in'
EXPORT_PREFIX = '/gids/dashboards/export/'
PROD_URL ||= 'https://www.va.gov/gids/user/sign_in'
EXPORT_PREFIX ||= '/gids/dashboards/export/'

STAGE_URL = 'https://staging.va.gov/gids/user/sign_in'
STAGE_DASHBOARD = 'https://staging.va.gov/gids/dashboards'
STAGE_IMPORT_PREFIX = '/gids/uploads/new/'
STAGE_URL ||= 'https://staging.va.gov/gids/user/sign_in'
STAGE_DASHBOARD ||= 'https://staging.va.gov/gids/dashboards'
STAGE_IMPORT_PREFIX ||= '/gids/uploads/new/'

TIMEOUT = 180 # seconds
TIMEOUT ||= 180 # seconds

attr_accessor :headless, :bsess, :download_dir, :login_url,
:dashboard_url, :import_prefix, :user, :pass, :eilogger,
Expand Down Expand Up @@ -115,6 +114,5 @@ def log_and_puts(msg)
@eilogger.info(msg)
end
end
# rubocop:enable Lint/ConstantDefinitionInBlock
# rubocop:enable Metrics/BlockLength
end
16 changes: 10 additions & 6 deletions app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Institution < ImportableRecord

MILE_METER_CONVERSION_RATE = 1609.34

# If columns need to be added, add them at the end to preserve upload integrity to other processes.
# Do not change the order of these attributes or add columns. This is used to upload to
# another system.
CSV_CONVERTER_INFO = {
'facility_code' => { column: :facility_code, converter: FacilityCodeConverter },
'institution' => { column: :institution, converter: InstitutionConverter },
Expand Down Expand Up @@ -105,6 +106,7 @@ class Institution < ImportableRecord
'school_closing' => { column: :school_closing, converter: BooleanConverter },
'school_closing_on' => { column: :school_closing_on, converter: DateConverter },
'school_closing_message' => { column: :school_closing_message, converter: BaseConverter },
'closure109' => { column: :closure109, converter: BooleanConverter },
'complaints_facility_code' => { column: :complaints_facility_code, converter: NumberConverter },
'complaints_financial_by_fac_code' => { column: :complaints_financial_by_fac_code, converter: NumberConverter },
'complaints_quality_by_fac_code' => { column: :complaints_quality_by_fac_code, converter: NumberConverter },
Expand Down Expand Up @@ -173,11 +175,12 @@ class Institution < ImportableRecord
'school_provider' => { column: :school_provider, converter: BooleanConverter },
'in_state_tuition_information' => { column: :in_state_tuition_information, converter: BaseConverter },
'vrrap_provider' => { column: :vrrap, converter: BooleanConverter },
'ownership_name' => { column: :ownership_name, converter: BaseConverter },
'ownership_name' => { column: :ownership_name, converter: BaseConverter }
}.freeze

# The following columns were not initially included in the CSV export and have been added at the end for
# completeness. If more columns are added to the CSV export in the future, they should be added here.
# The primary user (Brian Grubb) uses the export for an import to another process and order matters.
# Used for full export of institution rows with all columns.
# rubocop:disable Layout/FirstHashElementIndentation
CSV_CONVERTER_INFO2 = CSV_CONVERTER_INFO.merge({
'version' => { column: :version, converter: NumberConverter },
'approval_status' => { column: :approval_status, converter: BaseConverter },
'stem_offered' => { column: :stem_offered, converter: BooleanConverter },
Expand Down Expand Up @@ -223,7 +226,8 @@ class Institution < ImportableRecord
'pbi' => { column: :pbi, converter: NumberConverter },
'tribal' => { column: :tribal, converter: NumberConverter },
'ungeocodable' => { column: :ungeocodable, converter: BooleanConverter }
}.freeze
}).freeze
# rubocop:enable Layout/FirstHashElementIndentation

attribute :distance

Expand Down
2 changes: 2 additions & 0 deletions app/views/dashboards/_version.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<%= link_to 'Upload', new_upload_path('Institution'),
class: "btn dashboard-btn-success btn-xs", role: "button" %>
<% end %>
<%= link_to 'Export All', dashboard_export_version_path(number: version.number, export_all:true),
class: "btn dashboard-btn-warning btn-xs", role: "button" %>
<% end %>
</td>
</tr>
22 changes: 20 additions & 2 deletions lib/common/exporter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# frozen_string_literal: true

module Common
# rubocop:disable Metrics/ModuleLength
module Exporter
def export
generate(csv_headers)
end

def export_by_version
generate_version(csv_headers)
def export_by_version(export_all)
# every other model uses csv_headers. We don't want to muck that up for them.
if export_all
generate_version(csv_headers_for_all_institution_columns)
else
generate_version(csv_headers)
end
end

# simple version that takes incoming array of arrays and creates a CSV object with it
Expand Down Expand Up @@ -77,6 +83,17 @@ def csv_headers
csv_headers
end

def csv_headers_for_all_institution_columns
csv_headers = {}

klass::CSV_CONVERTER_INFO2.each_pair do |csv_column, info|
key = info[:column]
csv_headers[key] = Common::Shared.display_csv_header(csv_column)
end

csv_headers
end

def generate(csv_headers)
CSV.generate(col_sep: defaults[:col_sep]) do |csv|
csv << csv_headers.values
Expand Down Expand Up @@ -119,4 +136,5 @@ def format_ope(col)
"=\"#{col}\""
end
end
# rubocop:enable Metrics/ModuleLength
end
2 changes: 1 addition & 1 deletion spec/controllers/archives_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
csv_type = InstitutionsArchive.name
number = 2
filename = "#{csv_type}_version_#{number}.csv"
get(:export, params: { csv_type: csv_type, number: number, format: :csv })
get(:export, params: { csv_type: csv_type, number: number, format: :csv, export_all: 'true' })
expect(response.headers['Content-Disposition']).to include("filename=\"#{filename}\"")
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,26 @@ def check_attributes_from_records(rows, header_row)
end
end

it 'creates a string representation of a csv_file' do
rows = described_class.export_by_version.split("\n")
header_row = rows.shift.split(default_options[:col_sep]).map(&:downcase)
rows = CSV.parse(rows.join("\n"), col_sep: default_options[:col_sep])
check_attributes_from_records(rows, header_row)
describe 'when default exporting' do
it 'creates a string representation of a csv_file' do
rows = described_class.export_by_version(nil).split("\n")
header_row = rows.shift.split(default_options[:col_sep]).map(&:downcase)
rows = CSV.parse(rows.join("\n"), col_sep: default_options[:col_sep])
check_attributes_from_records(rows, header_row)
expect(header_row.size).to eq 105
end
end

describe 'when exporting all columns' do
let(:mapping) { described_class::CSV_CONVERTER_INFO2 }

it 'creates a string representation of a csv_file' do
rows = described_class.export_by_version(true).split("\n")
header_row = rows.shift.split(default_options[:col_sep]).map(&:downcase)
rows = CSV.parse(rows.join("\n"), col_sep: default_options[:col_sep])
check_attributes_from_records(rows, header_row)
expect(header_row.size).to eq 149
end
end
end
end

0 comments on commit f3820ba

Please sign in to comment.