diff --git a/Gemfile b/Gemfile index c95209d..53d9493 100644 --- a/Gemfile +++ b/Gemfile @@ -73,8 +73,6 @@ gem 'wicked_pdf' gem 'htmltoword' gem 'feedjira' -gem 'caracal' # WORD DOC EXPORTING -gem 'caracal-rails' gem 'yaml_db', :git => 'https://github.com/vyruss/yaml_db.git' # ------------------------------------------------ diff --git a/Gemfile.lock b/Gemfile.lock index 38f77ae..37b6745 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,13 +86,6 @@ rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) - caracal (1.0.8) - nokogiri (~> 1.6) - rubyzip (~> 1.1) - tilt (>= 1.4) - caracal-rails (1.0.1) - caracal (~> 1.0) - rails (>= 3.2) coderay (1.1.1) commonjs (0.2.7) concurrent-ruby (1.0.2) @@ -367,8 +360,6 @@ better_errors binding_of_caller byebug - caracal - caracal-rails contact_us (>= 1.2.0) devise devise_invitable diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index f4e6090..f8e3fe8 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -338,6 +338,8 @@ render 'show_export' end + + def export @plan = Plan.find(params[:id]) authorize @plan @@ -347,6 +349,7 @@ @exported_plan = ExportedPlan.new.tap do |ep| ep.plan = @plan + ep.phase_id = params[:phase_id] ep.user = current_user ep.format = params[:format].to_sym plan_settings = @plan.settings(:export) @@ -358,7 +361,7 @@ begin @exported_plan.save! - file_name = @exported_plan.project_name + file_name = @plan.title.gsub(/ /, "_") respond_to do |format| format.html diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 0ce6426..15cbcdc 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -79,22 +79,13 @@ end end -# TODO: This looks like it will always return an empty array as questions is undefined - # sections taken from fields settings def sections - # TODO: How do we know which phase to use here!? - sections = self.plan.template.phases.first.sections - - return [] if questions.empty? - - section_ids = questions.pluck(:section_id).uniq - sections = sections.select {|section| section_ids.member?(section.id) } - + sections = Phase.find(self.phase_id).sections sections.sort_by(&:number) end def questions_for_section(section_id) - questions.where(section_id: section_id) + questions.where(section_id: section_id).sort_by(&:number) end def admin_details diff --git a/app/views/plans/export.docx.erb b/app/views/plans/export.docx.erb new file mode 100644 index 0000000..db005f6 --- /dev/null +++ b/app/views/plans/export.docx.erb @@ -0,0 +1,44 @@ +
+ <%= admin_field_t(field.to_s) %>: + <%= value.present? ? value : _('-') %> +
+ <% end %> +<% end %> + + + +<% @exported_plan.sections.each do |section| %> +<%= raw question.text %>
+ + <% answer = @plan.answer(question.id, false) %> + <% if answer.nil? then %> +<%= _('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') %> +