diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 31aebae..385493e 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -105,8 +105,8 @@ #preview a phase def admin_previewphase - @version = Version.find(params[:id]) - authorize @version.phase.dmptemplate + @template = Template.find(params[:id]) + authorize @template end @@ -138,16 +138,14 @@ @phase = Phase.find(params[:id]) authorize @phase.template @phase.description = params["phase-desc"] - respond_to do |format| - if @phase.update_attributes(params[:phase]) - format.html { redirect_to admin_phase_dmptemplate_path(@phase), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + if @phase.update_attributes(params[:phase]) + redirect_to admin_phase_template_path(@phase), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end - #delete a version, sections and questions + #delete a phase def admin_destroyphase @phase = Phase.find(params[:phase_id]) authorize @phase.template @@ -160,14 +158,13 @@ #create a section def admin_createsection @section = Section.new(params[:section]) - authorize @section.version.phase.dmptemplate + authorize @section.phase.template @section.description = params["section-desc"] - respond_to do |format| - if @section.save - format.html { redirect_to admin_phase_template_path(:id => @section.version.phase_id, :version_id => @section.version_id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + if @section.save + redirect_to admin_phase_template_path(id: @section.phase_id, + :section_id => @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" end end @@ -205,7 +202,7 @@ @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] if @question.save - redirect_to admin_phase_template_path(id: @question.section.version.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_phase_template_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') else render action: "admin_phase" end @@ -214,32 +211,26 @@ #update a question of a template def admin_updatequestion @question = Question.find(params[:id]) - authorize @question.section.version.phase.dmptemplate + authorize @question.section.phase.template @question.guidance = params["question-guidance-#{params[:id]}"] @question.default_value = params["question-default-value-#{params[:id]}"] @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @question.update_attributes(params[:question]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + @phase = @section.phase + if @question.update_attributes(params[:question]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end - #delete a version, sections and questions + #delete question def admin_destroyquestion @question = Question.find(params[:question_id]) - authorize @question.section.version.phase.dmptemplate + authorize @question.section.phase.template @section = @question.section - @version = @section.version - @phase = @version.phase + @phase = @section.phase @question.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') end @@ -247,13 +238,11 @@ #create suggested answers def admin_createsuggestedanswer @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) - authorize @suggested_answer.question.section.version.phase.dmptemplate - respond_to do |format| - if @suggested_answer.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @suggested_answer.question.section.version.phase_id, :version_id => @suggested_answer.question.section.version_id, :section_id => @suggested_answer.question.section_id, :question_id => @suggested_answer.question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + authorize @suggested_answer.question.section.phase.template + if @suggested_answer.save + redirect_to admin_phase_template_path(id: @suggested_answer.question.section.phase_id, section_id: @suggested_answer.question.section_id, question_id: @suggested_answer.question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" end end @@ -261,84 +250,26 @@ #update a suggested answer of a template def admin_updatesuggestedanswer @suggested_answer = SuggestedAnswer.find(params[:id]) - authorize @suggested_answer.question.section.version.phase.dmptemplate + authorize @suggested_answer.question.section.phase.template @question = @suggested_answer.question @section = @question.section - @version = @section.version - @phase = @version.phase - - respond_to do |format| - if @suggested_answer.update_attributes(params[:suggested_answer]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + @phase = @section.phase + if @suggested_answer.update_attributes(params[:suggested_answer]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end #delete a suggested answer def admin_destroysuggestedanswer @suggested_answer = SuggestedAnswer.find(params[:suggested_answer]) - authorize @suggested_answer.question.section.version.phase.dmptemplate + authorize @suggested_answer.question.section.phase.template @question = @suggested_answer.question @section = @question.section - @version = @section.version - @phase = @version.phase + @phase = @section.phase @suggested_answer.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') end -# GUIDANCES - - #create a guidance - def admin_createguidance - @question = Question.find(params[:question][:id]) - authorize @question.section.version.phase.dmptemplate - @guidance = Guidance.new(params[:guidance]) - @guidance.question_id = @question.id - #@question.guidance = params["new-question-guidance"] - #@question.default_value = params["new-question-default-value"] - respond_to do |format| - if @guidance.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #update a guidance of a template - def admin_updateguidance - @question = Question.find(params[:id]) - authorize @question.section.version.phase.dmptemplate - @question.guidance = params["question-guidance-#{params[:id]}"] - @question.default_value = params["question-default-value-#{params[:id]}"] - @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @question.update_attributes(params[:question]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #delete a version, sections and guidance - def admin_destroyguidance - @question = Question.find(params[:question_id]) - authorize @question.section.version.phase.dmptemplate - @section = @question.section - @version = @section.version - @phase = @version.phase - @question.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end - - end \ No newline at end of file diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index b7a2ad0..34524ab 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -5,7 +5,7 @@ belongs_to :org has_many :guidances # depricated but needed for migration "single_group_for_guidance" - has_and_belongs_to_many :guidances, join_table: "guidance_in_group" + # has_and_belongs_to_many :guidances, join_table: "guidance_in_group" ## # Possibly needed for active_admin diff --git a/app/models/question.rb b/app/models/question.rb index 8b162a9..d6ec73e 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -20,7 +20,7 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :suggested_answer, :text, :section_id,:question_format_id,:options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] + attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :suggested_answer, :text, :section_id, :question_format_id, :question_options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] @@ -92,26 +92,19 @@ # @param question [Question] the question to find guidance for # @param org_admin [Organisation] the organisation to find guidance for # @return [Hash{String => String}] - def guidance_for_question(question, org_admin) - # pulls together guidance from various sources for question - guidances = {} - theme_ids = question.theme_ids + def guidance_for_question(question, org) + # pulls together guidance from various sources for question + guidances = {} + theme_ids = question.theme_ids - GuidanceGroup.where("organisation_id = ?", org_admin.id).each do |group| - group.guidances.each do |g| - g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g - end - end + GuidanceGroup.where(org_id: org.id).each do |group| + group.guidances.each do |g| + g.themes.where("id IN (?)", theme_ids).each do |gg| + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g end - # Guidance link to directly to a question - question.guidances.each do |g_by_q| - g_by_q.guidance_groups.each do |group| - if group.organisation == org_admin - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase')] = g_by_q - end - end - end + end + end + return guidances end @@ -121,7 +114,7 @@ # @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 = suggested_answers.find_by_organisation_id(org_id) + suggested_answer = suggested_answers.find_by(org_id: org_id) return suggested_answer end diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index 3e62265..b4df355 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -8,7 +8,7 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :organisation_id, :question_id, :text, :is_example, :as => [:default, :admin] + attr_accessible :org_id, :question_id, :text, :is_example, :as => [:default, :admin] # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/user.rb b/app/models/user.rb index f7e35b3..4a915eb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -201,7 +201,7 @@ # # @return [String] the organisation type def org_type - org_type = organisation.organisation_type.name + org_type = org.organisation_type return org_type end diff --git a/app/views/templates/_add_suggested_answer.html.erb b/app/views/templates/_add_suggested_answer.html.erb index 03e11b7..8969086 100644 --- a/app/views/templates/_add_suggested_answer.html.erb +++ b/app/views/templates/_add_suggested_answer.html.erb @@ -1,25 +1,25 @@ -<%= form_for :suggested_answer, :url => {:action => "admin_createsuggestedanswer"} do |f| %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> - <%= f.hidden_field :question_id, :value => question.id %> - -
| <%= t("org_admin.questions.suggested_or_example_answer_label")%> | -
-
|
-
| <%= t("org_admin.questions.suggested_or_example_answer_label")%> | +
+
|
+
| <%= t("org_admin.questions.question_number_label")%> | -<%= f.number_field :number, :in => 1..50, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> - - | -
| <%= t("org_admin.questions.question_number_label")%> | +<%= f.number_field :number, in: 1..50, class: "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> + + | +||
| <%= t("org_admin.questions.question_text_label")%> | -<%= f.text_area :text, :rows => "5" %> - - | -||
| <%= t("org_admin.questions.question_text_label")%> | +<%= f.text_area :text, rows: "5" %> + + | +||
| <%= t("org_admin.questions.answer_format_label")%> | -
-
+
+
+
+
+
+
+
+
+
+
+
+
- <%= f.hidden_field :id,{ :class => "quest_id" } %>
- <%= f.select :question_format_id,
- options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id),
- {}, :id => "#{question.id}-select-format"%>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_format_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%>
-
+
+ <%= t("org_admin.questions.answer_format_label")%> |
+ |
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ <%= f.hidden_field :id,{ class: "quest_id" } %>
+ <%= f.select :question_format_id,
+ options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id),
+ {}, id: "#{question.id}-select-format"%>
+
+
+ <%= link_to( image_tag("help_button.png"), "#", class: "question_format_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%>
+
- |
+
| <%= t("org_admin.questions.suggested_or_example_answer_label")%> | -
- <% suggested_answer = question.suggested_answers.find_by_organisation_id(current_user.organisation.id) %>
- <% if suggested_answer.nil? then %>
- <% suggested_answer = question.suggested_answers.build %>
- <%end%>
- <%= f.fields_for :suggested_answers, suggested_answer do |s|%>
- <%= s.hidden_field :organisation_id, :value => current_user.organisation.id %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "suggested_answer_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%>
-
-
-
- |
- ||
| <%= t("org_admin.questions.guidance_label")%> | -
- <%= text_area_tag("question-guidance-#{question.id}", question.guidance , class: "tinymce") %>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_guidance_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%>
-
-
-
- |
- ||
| <%= t("org_admin.questions.themes_label")%> | -
- <%= f.collection_select(:theme_ids,
- Theme.all.order("title"),
- :id, :title, {:prompt => false, :include_blank => "None"}, {:multiple => true})%>
-
-
- <%= link_to( image_tag("help_button.png"), "#", :class => "question_themes_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%>
-
- |
-
| <%= t('org_admin.questions.suggested_or_example_answer_label')%> | -
-
|
-
| <%= t('org_admin.questions.suggested_or_example_answer_label')%> | +
+
|
+
| <%= t('org_admin.questions.question_number_label')%> | -<%= question.number%> | -
| <%= t('org_admin.questions.question_number_label')%> | +<%= question.number %> | +
| <%= t('org_admin.questions.question_text_label')%> | -<%= raw question.text %>
-
-
- <% q_format = question.question_format %>
- <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%>
-
- <% end %>
-
- |
-
| <%= t('org_admin.questions.default_value_label')%> | -<%= raw question.default_value %> | -
| <%= t('org_admin.questions.answer_format_label')%> | -<%= q_format.title %> - - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> - <% if question.option_comment_display == true then%> - <%= t("org_admin.questions.option_comment_display")%> - <%else%> - <%= t("org_admin.questions.option_comment_hide")%> - <%end%> - <%end%> - - | -
| <%= t('org_admin.questions.question_text_label')%> | +<%= raw question.text %>
+
+
+ <% q_format = question.question_format %>
+ <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %>
+
+ <% end %>
+
+ |
+
| <%= t('org_admin.questions.default_value_label')%> | +<%= raw question.default_value %> | +
| <%= t('org_admin.questions.answer_format_label')%> | +<%= q_format.title %> + + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> + <% if question.question_option_comment_display == true %> + <%= t("org_admin.questions.option_comment_display")%> + <% else %> + <%= t("org_admin.questions.option_comment_hide")%> + <% end %> + <% end %> + + | +
| - <% if suggested_answer.is_example? then %> - <%= t('org_admin.questions.example_answer_label')%> - <%else%> - <%= t('org_admin.questions.suggested_answer_label')%> - <%end%> - | -<%= raw suggested_answer.text %> | -
| <%= t('org_admin.questions.guidance_label')%> | -<%= raw question.guidance %> | -
| <%= t('org_admin.questions.themes_label')%> | -<% i = 1%> - <% themes_q.each do |t|%> - <%= t.title %> - <% if themes_q.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> - | -