From 76a00e505538085454c445bcfa3ae7923230d1f5 Mon Sep 17 00:00:00 2001
From: Ryan Wold
Date: Wed, 13 Dec 2023 11:24:32 -0800
Subject: [PATCH] cx collections updates
---
.../admin/cx_collection_details_controller.rb | 5 ++
.../admin/cx_collections_controller.rb | 9 ++
app/controllers/admin/reporting_controller.rb | 2 +-
app/models/cx_collection.rb | 60 +++++++++++++
app/models/cx_collection_detail.rb | 89 ++++++++++++++++++-
app/models/service.rb | 2 +-
app/models/service_provider.rb | 10 ++-
app/views/admin/collections/index.html.erb | 2 +-
app/views/admin/cx_collections/index.html.erb | 11 ++-
config/routes.rb | 6 ++
10 files changed, 186 insertions(+), 10 deletions(-)
diff --git a/app/controllers/admin/cx_collection_details_controller.rb b/app/controllers/admin/cx_collection_details_controller.rb
index db75e69c5..462bbee3a 100644
--- a/app/controllers/admin/cx_collection_details_controller.rb
+++ b/app/controllers/admin/cx_collection_details_controller.rb
@@ -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'
diff --git a/app/controllers/admin/cx_collections_controller.rb b/app/controllers/admin/cx_collections_controller.rb
index 9bb7b350b..eeadc7ca7 100644
--- a/app/controllers/admin/cx_collections_controller.rb
+++ b/app/controllers/admin/cx_collections_controller.rb
@@ -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)
diff --git a/app/controllers/admin/reporting_controller.rb b/app/controllers/admin/reporting_controller.rb
index c28c350a7..323a32114 100644
--- a/app/controllers/admin/reporting_controller.rb
+++ b/app/controllers/admin/reporting_controller.rb
@@ -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 = [
diff --git a/app/models/cx_collection.rb b/app/models/cx_collection.rb
index 858ce1782..dcc544892 100644
--- a/app/models/cx_collection.rb
+++ b/app/models/cx_collection.rb
@@ -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
diff --git a/app/models/cx_collection_detail.rb b/app/models/cx_collection_detail.rb
index ae848e76a..4fb2ed3a9 100644
--- a/app/models/cx_collection_detail.rb
+++ b/app/models/cx_collection_detail.rb
@@ -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
diff --git a/app/models/service.rb b/app/models/service.rb
index cba4cd244..c8836b97a 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -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
diff --git a/app/models/service_provider.rb b/app/models/service_provider.rb
index 63702c395..a526f3e27 100644
--- a/app/models/service_provider.rb
+++ b/app/models/service_provider.rb
@@ -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
@@ -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,
diff --git a/app/views/admin/collections/index.html.erb b/app/views/admin/collections/index.html.erb
index c648f3bf3..34b171241 100644
--- a/app/views/admin/collections/index.html.erb
+++ b/app/views/admin/collections/index.html.erb
@@ -133,7 +133,7 @@
<%= link_to "Download Collections as .csv", export_csv_admin_collections_path, class: "usa-button" %>
- <%= 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" %>
<% end %>
diff --git a/app/views/admin/cx_collections/index.html.erb b/app/views/admin/cx_collections/index.html.erb
index 79a9c6db9..05074a4f4 100644
--- a/app/views/admin/cx_collections/index.html.erb
+++ b/app/views/admin/cx_collections/index.html.erb
@@ -36,4 +36,13 @@
<% end %>
-
\ No newline at end of file
+
+
+<% if performance_manager_permissions? %>
+
+ <%= link_to "Download Collections as .csv", export_csv_admin_cx_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" %>
+
+<% end %>
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 0f9ffc498..d8924dfbe 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -136,6 +136,9 @@
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
@@ -143,6 +146,9 @@
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