diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 9108ba9..205b96c 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -52,7 +52,7 @@ # GET /dmptemplates/1 def admin_template @template = Template.includes(:org, phases: [sections: [questions: [:question_options, :question_format, - :suggested_answers]]]).find(params[:id]) + :annotations]]]).find(params[:id]) # check to see if this is a funder template needing customized authorize @template @@ -75,7 +75,7 @@ end end end - customizations = Template.includes(:org, phases: [sections: [questions: :suggested_answers ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) + customizations = Template.includes(:org, phases: [sections: [questions: :annotations ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) if customizations.present? # existing customization to port over max_version = customizations.first @@ -105,7 +105,7 @@ section_copy.save! else # not a customized section, iterate over questions - customization_phase = new_customization.phases.includes(sections: [questions: :suggested_answers]).where(number: phase.number).first + customization_phase = new_customization.phases.includes(sections: [questions: :annotations]).where(number: phase.number).first customization_section = customization_phase.sections.where(number: section.number).first section.questions.each do |question| # find corresponding question in new template diff --git a/app/models/annotation.rb b/app/models/annotation.rb index c6c79b7..66b58e6 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -1,5 +1,5 @@ class Annotation < ActiveRecord::Base - enum type: [ :guidance, :example_answer,] + enum type: [ :guidance, :example_answer] ## # Associations belongs_to :org diff --git a/app/models/question.rb b/app/models/question.rb index f5eabfc..93ae151 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -103,13 +103,24 @@ end ## - # get suggested answer belonging to the currents user for this question + # get example answer belonging to the currents user for this question # # @param org_id [Integer] the id for the organisation - # @return [String] the suggested_answer for this question for the specified organisation - def get_suggested_answer(org_id) - suggested_answer = Annotaion.find_by(org_id: org_id).where("type <> ?", Annotation.types[:example_answer]) - return suggested_answer + # @return [String] the example answer for this question for the specified org + def get_example_answer(org_id) + example_answer = Annotation.where(org_id: org_id).where("type <> ?", Annotation.types[:example_answer]) + return example_answer.first end + ## + # get guidance belonging to the current user's org for this question(need org + # to distinguish customizations) + # + # @param org_id [Integer] the id for the organisation + # @return [String] the annotation guidance for this question for the specified org + def get_guidance_annotation(org_id) + guidance = Annotation.where(org_id: org_id).where("type <> ?", Annotation.types[:guidance]) + return guidance.first + end + end diff --git a/app/models/template.rb b/app/models/template.rb index de44b10..0a78b22 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -72,10 +72,10 @@ section.questions.each do |question| phases[phase.number][:sections][section.number][:questions][question.number] = {} phases[phase.number][:sections][section.number][:questions][question.number][:data] = question - phases[phase.number][:sections][section.number][:questions][question.number][:suggested_answers] = {} - question.suggested_answers.each do |suggested_answer| - phases[phase.number][:sections][section.number][:questions][question.number][:suggested_answers][suggested_answer.id] = {} - phases[phase.number][:sections][section.number][:questions][question.number][:suggested_answers][suggested_answer.id][:data] = suggested_answer + phases[phase.number][:sections][section.number][:questions][question.number][:annotations] = {} + question.annotations.each do |annotation| + phases[phase.number][:sections][section.number][:questions][question.number][:annotations][annotation.id] = {} + phases[phase.number][:sections][section.number][:questions][question.number][:annotations][annotation.id][:data] = annotation end phases[phase.number][:sections][section.number][:questions][question.number][:question_options] = {} question.question_options.each do |question_option| diff --git a/app/views/questions/_add_question.html.erb b/app/views/questions/_add_question.html.erb index cbd0207..4dac18c 100644 --- a/app/views/questions/_add_question.html.erb +++ b/app/views/questions/_add_question.html.erb @@ -114,20 +114,20 @@