Skip to content

Commit

Permalink
implement writing to choices tab using options_to_xls external method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Dec 6, 2023
1 parent 9fb2876 commit 9f2253e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions app/models/forms/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 9f2253e

Please sign in to comment.