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 @@ +

<%= @exported_plan.title %>

+

<%= @plan.template.title %>

+ +<% details = @exported_plan.admin_details %> +<% if details.present? %> +

<%= _('Admin Details') %>

+ <% details.each do |field| %> + <% value = @exported_plan.send(field) %> +

+ <%= admin_field_t(field.to_s) %>: + <%= value.present? ? value : _('-') %> +

+ <% end %> +<% end %> + + + +<% @exported_plan.sections.each do |section| %> +

<%= section.title %>

+ <% questions = @exported_plan.questions_for_section(section.id) %> + <% questions.each do |question| %> +

<%= 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') %> + + <% if question.option_comment_display %> + <%= raw answer.text %> + <% end %> + <%else%> + <%= raw answer.text %> + <%end%> + <% end %> + <% end %> +<% end %> diff --git a/app/views/shared/_export_links.html.erb b/app/views/shared/_export_links.html.erb index 6898a04..6ce39cd 100644 --- a/app/views/shared/_export_links.html.erb +++ b/app/views/shared/_export_links.html.erb @@ -1,5 +1,6 @@ <% javascript("export_configure") %>
+ <%= label_tag(:format, _('format')) %> <%= select_tag(:format, options_for_select(ExportedPlan::VALID_FORMATS, :pdf), class: 'export-format-selection') %> diff --git a/db/migrate/20170412143945_add_phase_id_to_exported_plan.rb b/db/migrate/20170412143945_add_phase_id_to_exported_plan.rb new file mode 100644 index 0000000..01df115 --- /dev/null +++ b/db/migrate/20170412143945_add_phase_id_to_exported_plan.rb @@ -0,0 +1,9 @@ +class AddPhaseIdToExportedPlan < ActiveRecord::Migration + def up + add_column :exported_plans, :phase_id, :integer + end + + def down + remove_column :exported_plans, :phase_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 7161ae7..cbe7b61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170303220255) do +ActiveRecord::Schema.define(version: 20170412143945) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -40,6 +40,7 @@ t.string "format" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "phase_id" end create_table "file_types", force: :cascade do |t|