diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 858b66a..9d79400 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -38,7 +38,7 @@ # # get the ids of the dynamically selected guidance groups # and keep a map of them so we can extract the names later - guidance_groups_ids = @plan.plan_guidance_groups.map{|pgg| pgg.guidance_group.id} + guidance_groups_ids = @plan.guidance_groups.map{|pgg| pgg.id} guidance_groups = GuidanceGroup.includes({guidances: :themes}).find(guidance_groups_ids) # create a map from theme to array of guidances diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 140b90f..6c3e73e 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -18,7 +18,7 @@ def new @plan = Plan.new authorize @plan - @funders = Org.funders.all + @funders = Org.funders.order('name ASC') no_org = Org.new() no_org.id = -1 @@ -131,7 +131,7 @@ authorize @plan @editing = (!params[:editing].nil? && @plan.administerable_by?(current_user.id)) @all_guidance_groups = @plan.get_guidance_group_options - @selected_guidance_groups = @plan.plan_guidance_groups.pluck(:guidance_group_id) + @selected_guidance_groups = @plan.guidance_groups.pluck(:id) @based_on = @plan.base_template respond_to :html @@ -369,9 +369,9 @@ respond_to do |format| format.html - format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } - format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } - format.docx { headers["Content-Disposition"] = "attachment; filename=\"#{file_name}.docx\""} + format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } + format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } + format.docx { render docx: 'export', filename: "#{file_name}.docx" } format.pdf do @formatting = @plan.settings(:export).formatting render pdf: file_name, @@ -425,7 +425,7 @@ ghash = {} plan["guidance_groups"].map{|g| ghash[g["id"]] = g} - plan["plan_guidance_groups"].each do |pgg| + plan["plans_guidance_groups"].each do |pgg| pgg["guidance_group"] = ghash[ pgg["guidance_group_id"] ] end diff --git a/app/models/annotation.rb b/app/models/annotation.rb new file mode 100644 index 0000000..c235d0b --- /dev/null +++ b/app/models/annotation.rb @@ -0,0 +1,36 @@ +class Annotation < ActiveRecord::Base + enum type: [:example_answer, :guidance] + ## + # Associations + belongs_to :org + belongs_to :question + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :org_id, :question_id, :text, + :org, :question, :as => [:default, :admin] + + + validates :question, :org, presence: {message: _("can't be blank")} + + ## + # returns the text from the suggested_answer + # + # @return [String] the text from the suggested_answer + def to_s + "#{text}" + end + + + ## + # deep copy the given question_option and all it's associations + # + # @params [QuestionOption] question_option to be deep copied + # @return [QuestionOption] the saved, copied question_option + def self.deep_copy(annotation) + annotation_copy = annotation.dup + annotation_copy.save! + return annotation_copy + end +end \ No newline at end of file diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index 96e6dab..547d49b 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -4,6 +4,7 @@ # Associations belongs_to :org has_many :guidances + has_and_belongs_to_many :plans, join_table: :plans_guidance_groups # depricated but needed for migration "single_group_for_guidance" # has_and_belongs_to_many :guidances, join_table: "guidance_in_group" diff --git a/app/models/phase.rb b/app/models/phase.rb index 1417661..a316416 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -8,7 +8,7 @@ ## # Associations belongs_to :template - has_many :sections, dependent: :destroy + has_many :sections, -> { order(:number => :asc) }, dependent: :destroy has_many :questions, :through => :sections, dependent: :destroy ## diff --git a/app/models/plan.rb b/app/models/plan.rb index c6a9f67..50d075d 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -10,8 +10,7 @@ has_many :notes, through: :answers has_many :roles, dependent: :destroy has_many :users, through: :roles - has_many :plan_guidance_groups, dependent: :destroy - has_many :guidance_groups, through: :plan_guidance_groups + has_and_belongs_to_many :guidance_groups, join_table: :plans_guidance_groups accepts_nested_attributes_for :template has_many :exported_plans @@ -208,8 +207,7 @@ end # Get guidance by theme from any guidance groups currently selected - self.plan_guidance_groups.each do |pgg| - group = pgg.guidance_group + self.guidance_groups.each do |group| group.guidances.each do |guidance| common_themes = guidance.themes.all & question.themes.all if common_themes.length > 0 @@ -962,7 +960,7 @@ {phases: {sections: {questions: :answers}}}, {customizations: :org} ]}, - {plan_guidance_groups: {guidance_group: :guidances}} + {plans_guidance_groups: {guidance_group: :guidances}} ]).find(id) end @@ -973,7 +971,7 @@ {customizations: :org}, :org ]}, - {plan_guidance_groups: {guidance_group: {guidances: :themes}}}, + {plans_guidance_groups: {guidance_group: {guidances: :themes}}}, {questions: :themes} ]).find(id) end diff --git a/app/views/layouts/_signin_signout.html.erb b/app/views/layouts/_signin_signout.html.erb index e975dc6..6222e55 100644 --- a/app/views/layouts/_signin_signout.html.erb +++ b/app/views/layouts/_signin_signout.html.erb @@ -12,7 +12,15 @@
| <%= _('Funder') %> | -<%= plan.template.org.name %> | -
| <%= _('Funder') %> | +<%= based_on.org.name %> | +
| <%= _('Institution') %> | +<%= plan.template.org.name %> | +