From 9f2253e7bf672159ef8102e616739325a4293e80 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 6 Dec 2023 10:41:30 -0500 Subject: [PATCH] implement writing to choices tab using options_to_xls external method --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/models/forms/export.rb | 13 +++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 7cc0915432..daf9c37035 100644 --- a/Gemfile +++ b/Gemfile @@ -178,7 +178,7 @@ group :development, :test do gem "awesome_print", "~> 1.6" gem "database_cleaner", "~> 1.7" gem "db-query-matchers", "~> 0.10" - gem "rubocop", "1.22.1" # Hound supported versions: http://help.houndci.com/en/articles/2461415-supported-linters + gem "rubocop", "1.22.3" # Hound supported versions: http://help.houndci.com/en/articles/2461415-supported-linters gem "rubocop-rails", "~> 2.8" gem "rubocop-rake", "~> 0.6.0" gem "rubocop-rspec", "~> 2.0" diff --git a/Gemfile.lock b/Gemfile.lock index 1dd7ea5f60..b7feec34ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -491,7 +491,7 @@ GEM rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) rspec-support (3.9.4) - rubocop (1.22.1) + rubocop (1.22.3) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) @@ -708,7 +708,7 @@ DEPENDENCIES rspec-collection_matchers (~> 1.1) rspec-github (~> 2.4) rspec-rails (~> 3.9) - rubocop (= 1.22.1) + rubocop (= 1.22.3) rubocop-rails (~> 2.8) rubocop-rake (~> 0.6.0) rubocop-rspec (~> 2.0) diff --git a/app/models/forms/export.rb b/app/models/forms/export.rb index 6c96a9b373..def2751263 100644 --- a/app/models/forms/export.rb +++ b/app/models/forms/export.rb @@ -133,6 +133,7 @@ def to_xls # convert question types qtype_converted = QTYPE_TO_XLS[q.qtype_name] + # TODO if there's an option set then os_name has to be replaced with level name type_to_push = "#{qtype_converted} #{os_name}" # Write the question row @@ -154,8 +155,13 @@ def to_xls # Choices # return an array to write to the spreadsheet option_matrix = options_to_xls(option_sets_used) - # Loop through matrix array and write to options spreadsheet - # options.row(...) + + # Loop through matrix array and write to "choices" tab of the XLSForm + option_matrix.each_with_index do | option_row, row_index | + option_row.each_with_index do | row_to_write, column_index | + choices.row(row_index).push(row_to_write) + end + end # note: also need to split questions with option set levels into multiple questions, one for each level, and increment the row_index accordingly # Settings @@ -262,7 +268,7 @@ def options_to_xls(option_sets) if node.children.present? # push to header row - unless header_row.contains?(node.level.name) + unless header_row.include?(node.level.name) header_row.push(node.level.name) end else @@ -282,7 +288,6 @@ def options_to_xls(option_sets) # Prepend header row os_matrix.insert(0, header_row) - Rails.logger.debug(os_matrix) end end end