diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 368f077..e4c03ea 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -107,13 +107,19 @@ self.questions_for_section(section).each do |question| answer = self.plan.answer(question.id) q_format = question.question_format - if q_format.title == _('Check box') || q_format.title == _('Multi select box') || - q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') - options_string = answer.options.collect {|o| o.text}.join('; ') + if q_format.option_based? + options_string = answer.question_options.collect {|o| o.text}.join('; ') else options_string = '' end - csv << [section.title, sanitize_text(question.text), sanitize_text(answer.text), options_string, user.name, answer.updated_at] + csv << [ + section.title, + sanitize_text(question.text), + question.option_comment_display ? sanitize_text(answer.text) : '', + options_string, + user.name, + answer.updated_at + ] end end end @@ -145,9 +151,8 @@ output += _('Question not answered.')+ "\n" else q_format = question.question_format - if q_format.title == _('Check box') || q_format.title == _('Multi select box') || - q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') - output += answer.options.collect {|o| o.text}.join("\n") + if q_format.option_based? + output += answer.question_options.collect {|o| o.text}.join("\n") if question.option_comment_display output += "\n#{sanitize_text(answer.text)}\n" end diff --git a/app/views/plans/export.docx.caracal b/app/views/plans/export.docx.caracal deleted file mode 100644 index 778eb3c..0000000 --- a/app/views/plans/export.docx.caracal +++ /dev/null @@ -1,256 +0,0 @@ -#----------------------------------------------------- -# page settings -#----------------------------------------------------- - -docx.page_numbers true do - align :center -end - -docx.font do - name 'Arial' -end - -docx.p do - size 32 -end - - -#--------------------------------------------- -# Structure for docx format -#--------------------------------------------- - -docx.h1 @exported_plan.plan.title.upcase, font: 'Arial', color: '000000' -docx.h2 @plan.template.title.upcase, font: 'Arial', color: '000000' - -#---- PLAN ADMIN DETAILS ----- -if @exported_plan.admin_details.present? - docx.p - docx.h3 _('Admin Details').upcase , italic: false, font: 'Arial', color: '000000' - @exported_plan.admin_details.each do |field| - value = @exported_plan.send(field) - if value.present? - docx.p do |p| - p.text admin_field_t(field.to_s), bold: true, color: '000000' - p.text ': ', bold: true, color: '000000' - p.text value - end - end - end -end - - -#---- PLAN SECTIONS, QUESTIONS AND ANSWERS ----- -@exported_plan.sections.each do |section| - docx.p - docx.h3 section.title.upcase, italic: false, font: 'Arial', color: '000000' - - @exported_plan.questions_for_section(section.id).each do |question| - docx.p strip_tags(question.text.gsub(/
  • /, ' * ')), bold: true - - answer = @exported_plan.plan.answer(question.id, false) - if answer.nil? - docx.p _('Question not answered'), italic: true - else - q_format = question.question_format - if q_format.title == _('Check box') || q_format.title == _('Multi select box') || - q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') then - answer.options.each do |option| - docx.ul do - if !option.text.nil? - li option.text - end - end - end - end - - if q_format.title == _('Date') || - q_format.title == _('Text field') || - q_format.title == _('Text area') - docx.p strip_tags(answer.text) - end - - if !answer.text.nil? && question.option_comment_display == true then - search_answer = Nokogiri::HTML::DocumentFragment.parse "
    " - search_answer.at(".//div").inner_html = answer.text - - if search_answer.css('table').present? then - table_content = search_answer.css('table').css('tbody') - - if table_content.size > 0 then - table_array = Array.new - - table_content.css('tr').each do |tr| - row_th_array = Array.new - row_td_array = Array.new - - if tr.search('th') then - tr.search('th').each do |cell| - row_th_array << cell.text.to_s - end - end - - if tr.search('td') then - tr.search('td').each do |td_cell| - if !td_cell.text.to_s.blank? then - new_val = Nokogiri::HTML::DocumentFragment.parse "

    " - new_val.at(".//p").inner_html = td_cell - td_tags = new_val.at_css('td').children.map {|x| x.name.strip} - td_text = new_val.at_css('td').children.map {|x| x.text.strip} - - start_c = 0 - end_c = td_tags.size - - c1 = Caracal::Core::Models::TableCellModel.new do - while start_c < end_c do - p do - #-- TEXT - if td_tags[start_c] == 'text' then - text td_text[start_c] - else - #-- LINK - if td_tags[start_c] == 'a' then - l_address = "" - l_text = td_text[start_c] - #-- GET HREF - td_cell.search('a').each do |link| - if link.content == td_text[start_c] then - l_address = link["href"] - end - end - link td_text[start_c], l_address - #-- BOLD TEXT - else - if td_tags[start_c] == 'strong' && td_text[start_c] != "" then - text td_text[start_c], bold: true - text ' ' - #-- ITALIC TEXT - else - if td_tags[start_c] == 'em' && td_text[start_c] != "" then - text td_text[start_c], italic: true - text ' ' - end - end - end - end - end - start_c += 1 - end - end - row_td_array << c1 - else - row_td_array << td_cell.text.to_s - end - end - end - - #--- check if all cells are empty - if row_td_array.size > 0 then - if row_td_array.all?(&:blank?) then - row_td_array = [] - end - end - - if !row_th_array.empty? then - table_array << row_th_array - end - if !row_td_array.empty? then - table_array << row_td_array - end - - end - - #--- build the table layout - docx.table table_array, border_size: 4 do - cell_style rows[0], bold: true, background: 'fbb400' - cell_style cells, size: 18, margins: { top: 100, bottom: 0, left: 100, right: 100 } - end - - end - - else - higher_level = search_answer.search('div.container').children.map {|x| x.name.strip} - all_text = search_answer.search('div.container').children.map {|x| x.inner_html.strip} - high_count = 0 - high_end_count = higher_level.size - - while high_count < high_end_count do - - if higher_level[high_count] == 'p' then - inner_txt_with_tags = Nokogiri::HTML::DocumentFragment.parse "

    " - inner_txt_with_tags.at(".//p").inner_html = all_text[high_count] - tags_type = inner_txt_with_tags.at_css('p').children.map {|x| x.name.strip} - inner_txt = inner_txt_with_tags.at_css('p').children.map {|x| x.text.strip} - - start_count = 0 - end_counter = tags_type.size - - docx.p do - while start_count < end_counter do - text_val = inner_txt[start_count].to_s - #-- TEXT - if tags_type[start_count] == 'text' && text_val != "" then - text text_val - text ' ' - #-- LINK - else - if tags_type[start_count] == 'a' && text_val != "" then - l_text = text_val - l_address = "" - # all links - search_answer.search('a').each do |link| - if link.content == text_val then - l_address = link["href"] - end - end - link text_val, l_address - #-- BOLD TEXT - else - if tags_type[start_count] == 'strong' && text_val != "" then - text text_val, bold: true - text ' ' - #-- ITALIC TEXT - else - if tags_type[start_count] == 'em' && text_val != "" then - text text_val, italic: true - text ' ' - end - end - end - end - start_count +=1 - end - end - #-- END OF P - else - if higher_level[high_count] == 'ul' then - ul_text = search_answer.search('ul').children.map {|x| x.text.strip} - docx.ul do - ul_text.each do |txt| - if !txt.blank? - li txt - end - end - end - else - if higher_level[high_count] == 'ol' then - ol_text = search_answer.search('ol').children.map {|x| x.text.strip} - docx.ol do - ol_text.each do |txt| - if !txt.blank? - li txt - end - end - end - end - end - end - - high_count += 1 - end - end - end - end - #-- add a new line - docx.p - end -end diff --git a/app/views/plans/export.docx.erb b/app/views/plans/export.docx.erb index 12d289f..0ea56f4 100644 --- a/app/views/plans/export.docx.erb +++ b/app/views/plans/export.docx.erb @@ -28,8 +28,7 @@

    <%= _('Question not answered') %>

    <% else %> <% q_format = question.question_format %> - <% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || - q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') %> + <% if q_format.option_based? %>