diff --git a/app/controllers/admin/cx_collection_details_controller.rb b/app/controllers/admin/cx_collection_details_controller.rb
index 7ab54b0fe..f2d29e550 100644
--- a/app/controllers/admin/cx_collection_details_controller.rb
+++ b/app/controllers/admin/cx_collection_details_controller.rb
@@ -18,6 +18,18 @@ def show
def new
@cx_collection_detail = CxCollectionDetail.new
@cx_collection_detail.cx_collection_id = params[:collection_id]
+
+ if params[:form_id]
+ @form = Form.find_by_short_uuid(params[:form_id])
+ @cx_collection_detail.form = @form
+ @cx_collection_detail.service_stage_id = @form.service_stage_id
+ @cx_collection_detail.transaction_point = :post_interaction
+ @cx_collection_detail.survey_type = :thumbs_up_down if @form.kind == "a11_v2"
+ @cx_collection_detail.survey_title = @form.title
+ @cx_collection_detail.omb_control_number = @form.omb_approval_number
+ @cx_collection_detail.trust_question_text = @form.questions.first.text
+ @cx_collection_detail.volume_of_customers_provided_survey_opportunity = @form.survey_form_activations
+ end
end
def edit
@@ -35,6 +47,11 @@ def create
respond_to do |format|
if @cx_collection_detail.save
Event.log_event(Event.names[:cx_collection_detail_created], @cx_collection_detail.class.to_s, @cx_collection_detail.id, "CX Collection Detail #{@cx_collection_detail.id} created at #{DateTime.now}", current_user.id)
+
+ if @cx_collection_detail.form
+ CxCollectionDetailUpload.create!(user: current_user, cx_collection_detail: @cx_collection_detail)
+ end
+
format.html { redirect_to upload_admin_cx_collection_detail_url(@cx_collection_detail), notice: "CX Collection Detail was successfully created." }
format.json { render :upload, status: :created, location: @cx_collection_detail }
else
@@ -160,6 +177,22 @@ def set_cx_collections
end
def cx_collection_detail_params
- params.require(:cx_collection_detail).permit(:cx_collection_id, :transaction_point, :channel, :service_stage_id, :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)
+ params.require(:cx_collection_detail)
+ .permit(
+ :cx_collection_id,
+ :transaction_point,
+ :channel,
+ :service_stage_id,
+ :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,
+ :form_id,
+ )
end
end
diff --git a/app/controllers/admin/cx_collections_controller.rb b/app/controllers/admin/cx_collections_controller.rb
index 2c104ad1c..22f41a9c4 100644
--- a/app/controllers/admin/cx_collections_controller.rb
+++ b/app/controllers/admin/cx_collections_controller.rb
@@ -26,6 +26,8 @@ def show
def new
@cx_collection = CxCollection.new
+ @cx_collection.quarter = FiscalYear.fiscal_year_and_quarter(Date.today)[:quarter]
+ @cx_collection.fiscal_year = FiscalYear.fiscal_year_and_quarter(Date.today)[:year]
end
def edit
diff --git a/app/models/cx_collection_detail.rb b/app/models/cx_collection_detail.rb
index 06470351f..9e5541203 100644
--- a/app/models/cx_collection_detail.rb
+++ b/app/models/cx_collection_detail.rb
@@ -3,6 +3,7 @@
class CxCollectionDetail < ApplicationRecord
belongs_to :cx_collection
belongs_to :service_stage, optional: true
+ belongs_to :form, optional: true
has_many :cx_responses, dependent: :delete_all
has_many :cx_collection_detail_uploads
has_one :service_provider, through: :cx_collection
diff --git a/app/models/cx_collection_detail_upload.rb b/app/models/cx_collection_detail_upload.rb
index db825fb80..5436f2a7a 100644
--- a/app/models/cx_collection_detail_upload.rb
+++ b/app/models/cx_collection_detail_upload.rb
@@ -6,7 +6,7 @@ class CxCollectionDetailUpload < ApplicationRecord
belongs_to :cx_collection_detail
has_many :cx_responses, dependent: :delete_all
- after_create :process_csv_in_a_worker
+ after_create :process_records_in_a_worker
aasm do
state :created, initial: true
@@ -24,8 +24,15 @@ class CxCollectionDetailUpload < ApplicationRecord
end
end
- def process_csv_in_a_worker
- process_csv
+ def process_records_in_a_worker
+ if self.key?
+ process_csv
+ elsif self.cx_collection_detail.form
+ fiscal_quarter_dates = FiscalYear.fiscal_quarter_dates(self.cx_collection_detail.cx_collection.fiscal_year, self.cx_collection_detail.cx_collection.quarter)
+ start_date = fiscal_quarter_dates[:start_date]
+ end_date = fiscal_quarter_dates[:end_date]
+ upload_form_results(form_id: self.cx_collection_detail.form_id, start_date:, end_date:)
+ end
end
def process_csv
@@ -73,4 +80,39 @@ def process_csv
end
end
+ def upload_form_results(form_id:, start_date:, end_date:)
+ @form = Form.find(form_id)
+
+ job_id = SecureRandom.hex[0..9]
+ update_attribute(:job_id, job_id)
+
+ responses = @form.to_a11_v2_array(start_date:, end_date:)
+ responses.each do |response|
+ # Create the CxResponse record
+ CxResponse.create!({
+ cx_collection_detail_id: cx_collection_detail.id,
+ cx_collection_detail_upload_id: self.id,
+ job_id: job_id,
+ external_id: response[0],
+ question_1: response[:answer_01],
+ positive_effectiveness: response[:answer_02_effectiveness],
+ positive_ease: response[:answer_02_ease],
+ positive_efficiency: response[:answer_02_efficiency],
+ positive_transparency: response[:answer_02_transparency],
+ positive_humanity: response[:answer_02_humanity],
+ positive_employee: response[:answer_02_employee],
+ positive_other: response[:answer_02_other],
+ negative_effectiveness: response[:answer_03_effectiveness],
+ negative_ease: response[:answer_03_ease],
+ negative_efficiency: response[:answer_03_efficiency],
+ negative_transparency: response[:answer_03_transparency],
+ negative_humanity: response[:answer_03_humanity],
+ negative_employee: response[:answer_03_employee],
+ negative_other: response[:answer_03_other],
+ question_4: response[:answer_04],
+ })
+ end
+
+ end
+
end
diff --git a/app/models/form.rb b/app/models/form.rb
index e509630de..709881915 100644
--- a/app/models/form.rb
+++ b/app/models/form.rb
@@ -448,6 +448,39 @@ def to_a11_v2_csv(start_date: nil, end_date: nil)
end
end
+ def to_a11_v2_array(start_date: nil, end_date: nil)
+ non_flagged_submissions = submissions
+ .non_flagged
+ .where(created_at: start_date..end_date)
+ .order('created_at')
+ return nil if non_flagged_submissions.blank?
+
+ answer_02_options = self.questions.where(answer_field: "answer_02").first.question_options.collect(&:value)
+ answer_03_options = self.questions.where(answer_field: "answer_03").first.question_options.collect(&:value)
+
+ non_flagged_submissions.map do |submission|
+ {
+ id: submission.id,
+ answer_01: submission.answer_01,
+ answer_02_effectiveness: submission.answer_02 && submission.answer_02.split(",").include?("effectiveness") ? 1 :(answer_02_options.include?("effectiveness") ? 0 : 'null'),
+ answer_02_ease: submission.answer_02 && submission.answer_02.split(",").include?("ease") ? 1 : (answer_02_options.include?("ease") ? 0 : 'null'),
+ answer_02_efficiency: submission.answer_02 && submission.answer_02.split(",").include?("efficiency") ? 1 : (answer_02_options.include?("efficiency") ? 0 : 'null'),
+ answer_02_transparency: submission.answer_02 && submission.answer_02.split(",").include?("transparency") ? 1 : (answer_02_options.include?("transparency") ? 0 : 'null'),
+ answer_02_humanity: submission.answer_02 && submission.answer_02.split(",").include?("humanity") ? 1 : (answer_02_options.include?("humanity") ? 0 : 'null'),
+ answer_02_employee: submission.answer_02 && submission.answer_02.split(",").include?("employee") ? 1 : (answer_02_options.include?("employee") ? 0 : 'null'),
+ answer_02_other: submission.answer_02 && submission.answer_02.split(",").include?("other") ? 1 : (answer_02_options.include?("other") ? 0 : 'null'),
+ answer_03_effectiveness: submission.answer_03 && submission.answer_03.split(",").include?("effectiveness") ? 1 : (answer_03_options.include?("effectiveness") ? 0 : 'null'),
+ answer_03_ease: submission.answer_03 && submission.answer_03.split(",").include?("ease") ? 1 : (answer_03_options.include?("ease") ? 0 : 'null'),
+ answer_03_efficiency: submission.answer_03 && submission.answer_03.split(",").include?("efficiency") ? 1 : (answer_03_options.include?("efficiency") ? 0 : 'null'),
+ answer_03_transparency: submission.answer_03 && submission.answer_03.split(",").include?("transparency") ? 1 : (answer_03_options.include?("transparency") ? 0 : 'null'),
+ answer_03_humanity: submission.answer_03 && submission.answer_03.split(",").include?("humanity") ? 1 : (answer_03_options.include?("humanity") ? 0 : 'null'),
+ answer_03_employee: submission.answer_03 && submission.answer_03.split(",").include?("employee") ? 1 : (answer_03_options.include?("employee") ? 0 : 'null'),
+ answer_03_other: submission.answer_03 && submission.answer_03.split(",").include?("other") ? 1 : (answer_03_options.include?("other") ? 0 : 'null'),
+ answer_04: submission.answer_04,
+ }
+ end
+ end
+
def user_role?(user:)
role = user_roles.find_by_user_id(user.id)
role.present? ? role.role : nil
diff --git a/app/views/admin/cx_collection_details/_form.html.erb b/app/views/admin/cx_collection_details/_form.html.erb
index 7cd41dff1..792742210 100644
--- a/app/views/admin/cx_collection_details/_form.html.erb
+++ b/app/views/admin/cx_collection_details/_form.html.erb
@@ -132,6 +132,17 @@
+ <% if @cx_collection_detail.form %>
+ <%= form.hidden_field :form_id, value: @cx_collection_detail.form_id %>
+
+ CxResponses will be created for the form titled "<%= @cx_collection_detail.form.title %>" + for Q<%= @cx_collection_detail.cx_collection.quarter %>FY<%= @cx_collection_detail.cx_collection.fiscal_year %>. +
+@@ -140,6 +151,7 @@
<%= form.submit class: "usa-button" %> diff --git a/app/views/admin/cx_collection_details/upload.html.erb b/app/views/admin/cx_collection_details/upload.html.erb index 30eb620ae..f3c0defba 100644 --- a/app/views/admin/cx_collection_details/upload.html.erb +++ b/app/views/admin/cx_collection_details/upload.html.erb @@ -61,7 +61,7 @@ <% end %> -
User | @@ -70,9 +70,9 @@Timestamp | Uploaded record count | <%- if service_manager_permissions? %> -- | - | + | Job ID | +Process file? | +Delete? | <% end %>- <%= link_to "Uploaded file", s3_presigned_url(upload.key) %> + <%= link_to "Uploaded file", s3_presigned_url(upload.key) if upload.key %> |
<%= upload.size %>
diff --git a/app/views/admin/cx_collections/_form.html.erb b/app/views/admin/cx_collections/_form.html.erb
index 7491e10a9..ab045f5b8 100644
--- a/app/views/admin/cx_collections/_form.html.erb
+++ b/app/views/admin/cx_collections/_form.html.erb
@@ -74,7 +74,7 @@
- After creating this collection, you can add survey results in the following screen. + After creating this collection, you can add survey results on the following screen. |
---|
+