diff --git a/app/models/answer.rb b/app/models/answer.rb index a2a625f..4e8a3e5 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -87,6 +87,18 @@ return notes.select{ |n| n.archived.blank? }.sort!{ |x,y| y.updated_at <=> x.updated_at } end + ## + # Returns True if answer text is blank, false otherwise + # specificly we want to remove empty hml tags and check + # + # @return [Boolean] is the answer's text blank + def is_blank? + if self.text.present? + return self.text.gsub(/<\/?p>/, '').gsub(//, '').chomp.blank? + end + # no text so blank + return true + end ## # Returns the parsed JSON hash for the current answer object diff --git a/app/models/concerns/exportable_plan.rb b/app/models/concerns/exportable_plan.rb index b9254b8..020d4fb 100644 --- a/app/models/concerns/exportable_plan.rb +++ b/app/models/concerns/exportable_plan.rb @@ -56,15 +56,7 @@ phase.sections.each do |section| sctn = { title: section.title, number: section.number, questions: [] } section.questions.each do |question| - txt = [] - if question.question_format.option_based? - opts = QuestionOption.where(question_id: question.id) - opts.each do |opt| - txt << opt.text - end - else - txt << question.text - end + txt = question.text sctn[:questions] << { id: question.id, text: txt, format: question.question_format } end phs[:sections] << sctn diff --git a/app/views/shared/export/_plan.erb b/app/views/shared/export/_plan.erb index e3e5772..d6db153 100644 --- a/app/views/shared/export/_plan.erb +++ b/app/views/shared/export/_plan.erb @@ -19,7 +19,7 @@ <%= @plan.title %> - <%= render partial: '/shared/export/plan_styling', + <%= render partial: '/shared/export/plan_styling', locals: { font_face: font_face, font_size: "#{font_size}pt", @@ -44,25 +44,17 @@ <% section[:questions].each do |question| %>
<% if @show_sections_questions && !@public_plan %> - <%# text in this case is an array to accomodate for option_based %> - <% if question[:text].length > 1 %> - - <% else %> -

<%= raw question[:text][0].gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") if question[:text].present? && question[:text][0].present? %>

- <% end %> +

<%= raw question[:text].gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") if question[:text].present?%>


<% end %> - <% answer = @plan.answer(question[:id], false) %> - <% blank = (answer.present? && answer.is_valid?) ? answer.text.gsub(/<\/?p>/, '').gsub(//, '').chomp.blank? : true %> + <% blank = answer.present? ? answer.is_blank? : true %> <% options = answer.present? ? answer.question_options : [] %> - <% if blank && @show_unanswered && options.blank? %> + <%# case where question has not been answered sufficiently to display%> + <% if @show_unanswered && (answer.blank? || (options.blank? && blank))%>

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

- <% elsif !blank %> + <% else %> + <%# case where Question has options %> <% if options.present?%>
    <% options.each do |opt| %> @@ -70,7 +62,8 @@ <% end %>
<% end %> - <% if question[:format].rda_metadata? %> + <%# case for RDA answer display %> + <% if question[:format].rda_metadata? && !blank %> <% ah = answer.answer_hash %> <% if ah['standards'].present? %>
    @@ -80,8 +73,9 @@
<% end %>

<%= raw ah['text'] %>

- <% else %> -

<%= raw answer.text.chomp.strip %>

+ <%# case for displaying comments OR text %> + <% elsif !blank %> +

<%= raw answer.text %>

<% end %> <% end %>