Skip to content

Commit

Permalink
Add groups to xls output
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Sep 6, 2023
1 parent 17d70c0 commit 72659ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def export_xml
# XLSForm export.
def export_xls
exporter = Forms::Export.new(@form)
send_data(exporter.to_xls, filename: "test.xlsx")
send_data(exporter.to_xls, filename: "xlsform-#{@form.name.dasherize}-#{Time.zone.today}.xlsx")
# send_file ...
end

Expand Down
27 changes: 26 additions & 1 deletion app/models/forms/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,28 @@ def to_xls
choices.row(0).push("list_name", "name", "label")
settings.row(0).push("form_title", "form_id", "version", "default_language")

group_tracker = false
index_mod = 1;
@form.preordered_items.each_with_index do |q, i|
questions.row(i+1).push(q.qtype.name, q.code, q.name, q.required.to_s, "TODO")
if q.group?
questions.row(i+index_mod).push("begin group", q.code)

# Toggle group tracker so we know we are in a group
group_tracker = true
else
# did a group just end? if so, the rank will be a whole number
if group_tracker && !q.full_dotted_rank.include?(".")

# end the group and stop tracking it with the counter
questions.row(i+index_mod).push("end group")
group_tracker = false

# increment our index modifier
index_mod += 1
end

questions.row(i+index_mod).push(q.qtype_name, q.full_dotted_rank + "_" + q.code, q.name, q.required.to_s, "TODO")
end
end

# Choices TODO
Expand Down Expand Up @@ -78,5 +98,10 @@ def name(qing)
"Group"
end
end

def to_number(value)
return if value.blank?
(value.to_f % 1).positive? ? value.to_f : value.to_i
end
end
end

0 comments on commit 72659ac

Please sign in to comment.