Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CX Collection updates #1307

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/admin/cx_collection_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def destroy
end
end

def export_csv
@collections = CxCollectionDetail.all
send_data @collections.to_csv, filename: "touchpoints-data-collection-details-#{Date.today}.csv"
end

# Handle a large-ish csv upload (5+ MB) to S3
def upload_csv
file = params[:file] # Assuming the file comes from a form field named 'file'
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/admin/cx_collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def publish
redirect_to admin_cx_collection_path(@cx_collection), notice: 'Collection has been published successfully.'
end

def export_csv
if performance_manager_permissions?
@collections = CxCollection.all
else
@collections = current_user.cx_collections
end
send_data @collections.to_csv, filename: "touchpoints-data-cx-collections-#{Date.today}.csv"
end

def copy
ensure_collection_owner(collection: @cx_collection)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/reporting_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def hisp_services

row << header_fields.join(',')

ServiceProviderall..all.includes(:organization).order('organizations.name', :name).each do |service_provider|
ServiceProvider.all.includes(:organization).order('organizations.name', :name).each do |service_provider|
service_provider.services.order(:name).each do |service|
service.omb_cx_reporting_collections.includes(:service, :collection).order('collections.year', 'collections.quarter', 'services.name').each do |omb_cx_reporting_collection|
row_fields = [
Expand Down
60 changes: 60 additions & 0 deletions app/models/cx_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,64 @@ class CxCollection < ApplicationRecord
transitions to: :draft
end
end

def self.to_csv
collections = CxCollection.all.order(:fiscal_year, :quarter, 'organizations.name').includes(:organization)

attributes = %i[
id
name
start_date
end_date
service_provider_id
service_provider_name
service_provider_organization_id
service_provider_organization_name
service_provider_organization_abbreviation
organization_id
organization_name
organization_abbreviation
user_email
fiscal_year
quarter
reflection
created_at
updated_at
rating
aasm_state
integrity_hash
omb_cx_reporting_collections_count
]

CSV.generate(headers: true) do |csv|
csv << attributes

collections.each do |collection|
csv << attributes = [
collection.id,
collection.name,
collection.start_date,
collection.end_date,
collection.service_provider_id,
collection.service_provider.name,
collection.service_provider.organization_id,
collection.service_provider.organization_name,
collection.service_provider.organization_abbreviation,
collection.organization_id,
collection.organization.name,
collection.organization.abbreviation,
collection.user.email,
collection.fiscal_year,
collection.quarter,
collection.reflection,
collection.created_at,
collection.updated_at,
collection.rating,
collection.aasm_state,
collection.integrity_hash,
collection.cx_collection_details.size,
]
end
end
end
end
89 changes: 86 additions & 3 deletions app/models/cx_collection_detail.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,88 @@
class CxCollectionDetail < ApplicationRecord
belongs_to :cx_collection
belongs_to :service
belongs_to :service_stage, optional: true
belongs_to :cx_collection
belongs_to :service
belongs_to :service_stage, optional: true

def self.to_csv
collection_details = CxCollectionDetail.all

attributes = %i[
id
organization_id
organization_abbreviation
organization_name
cx_collection_id
cx_collection_fiscal_year
cx_collection_quarter
cx_collection_name
cx_collection_service_provider_id
cx_collection_service_provider_name
cx_collection_service_provider_slug
service_id
service_name
transaction_point
channel
service_stage_id
service_stage_name
service_stage_position
service_stage_count
volume_of_customers
volume_of_customers_provided_survey_opportunity
volume_of_respondents
omb_control_number
federal_register_url
reflection_text
survey_type
survey_title
trust_question_text
created_at
updated_at
]

CSV.generate(headers: true) do |csv|
csv << attributes

collection_details.each do |collection_detail|
csv << attributes = [
collection_detail.id,
collection_detail.cx_collection.organization_id,
collection_detail.cx_collection.organization.abbreviation,
collection_detail.cx_collection.organization.name,

collection_detail.cx_collection_id,
collection_detail.cx_collection.fiscal_year,
collection_detail.cx_collection.quarter,
collection_detail.cx_collection.name,

collection_detail.cx_collection.service_provider_id,
collection_detail.cx_collection.service_provider.name,
collection_detail.cx_collection.service_provider.slug,

collection_detail.service_id,
collection_detail.service.name,

collection_detail.transaction_point,
collection_detail.channel,
collection_detail.service_stage_id,
collection_detail.service_stage.try(:name),
collection_detail.service_stage.try(:position),
collection_detail.service.service_stages.count,

collection_detail.volume_of_customers,
collection_detail.volume_of_customers_provided_survey_opportunity,
collection_detail.volume_of_respondents,

collection_detail.omb_control_number,
collection_detail.federal_register_url,
collection_detail.reflection_text,
collection_detail.survey_type,
collection_detail.survey_title,
collection_detail.trust_question_text,
collection_detail.created_at,
collection_detail.updated_at,
]
end
end
end

end
2 changes: 1 addition & 1 deletion app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def self.to_csv

example_service_attributes = Service.new.attributes
attributes = example_service_attributes.keys +
[:organization_name, :organization_abbreviation, :service_provider_name, :service_provider_slug] - ["channels"]
[:organization_name, :organization_abbreviation, :service_provider_id, :service_provider_name, :service_provider_slug] - ["channels"]

CSV.generate(headers: true) do |csv|
csv << attributes
Expand Down
10 changes: 7 additions & 3 deletions app/models/service_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ def organization_abbreviation
def self.to_csv
CSV.generate(headers: true) do |csv|
csv << %i[
department
department_abbreviation
service_provider_id
id
organization_id
organization_name
organization_abbreviation
service_provider_slug
name
description
year_designated
Expand All @@ -46,6 +48,8 @@ def self.to_csv
.includes(:organization)
.order('organizations.name', :name).each do |provider|
csv << [
provider.id,
provider.organization_id,
provider.organization.name,
provider.organization.abbreviation.downcase,
provider.slug,
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/collections/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<%= link_to "Download Collections as .csv", export_csv_admin_collections_path, class: "usa-button" %>
</p>
<p>
<%= link_to "Download OMB CX Data Reporting Collections as .csv", export_omb_cx_reporting_collections_csv_admin_collections_path, class: "usa-button" %>
<%= link_to "Download OMB CX Data Reporting Collections as .csv", export_csv_admin_cx_collection_details_path, class: "usa-button" %>
</p>
<% end %>

Expand Down
11 changes: 10 additions & 1 deletion app/views/admin/cx_collections/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@
</tr>
<% end %>
</tbody>
</table>
</table>

<% if performance_manager_permissions? %>
<p>
<%= link_to "Download Collections as .csv", export_csv_admin_cx_collections_path, class: "usa-button" %>
</p>
<p>
<%= link_to "Download OMB CX Data Reporting Collections as .csv", export_csv_admin_cx_collection_details_path, class: "usa-button" %>
</p>
<% end %>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,19 @@
end

resources :cx_collections do
collection do
get 'export_csv', to: 'cx_collections#export_csv', as: :export_csv
end
member do
post 'submit', to: 'cx_collections#submit', as: :submit
post 'publish', to: 'cx_collections#publish', as: :publish
end
end

resources :cx_collection_details do
collection do
get 'export_csv', to: 'cx_collection_details#export_csv', as: :export_csv
end
member do
get 'upload', to: 'cx_collection_details#upload', as: :upload
post 'upload', to: 'cx_collection_details#upload_csv', as: :post_csv
Expand Down