diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index cebd30d..da71a93 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -5,7 +5,7 @@ def admin_index authorize Guidance @guidances = policy_scope(Guidance) - @guidance_groups = GuidanceGroup.where('org_id = ?', current_user.org_id ) + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id) respond_to do |format| format.html # index.html.erb end @@ -13,7 +13,7 @@ # GET /guidances/1 def admin_show - @guidance = Guidance.find(params[:id]) + @guidance = Guidance.includes(:guidance_group, :question, :themes).find(params[:id]) authorize @guidance respond_to do |format| format.html # show.html.erb @@ -23,29 +23,21 @@ def admin_new @guidance = Guidance.new authorize @guidance - @dmptemplates = Dmptemplate.funders_and_own_templates(current_user.org_id) + @templates = Template.funders_and_own_templates(current_user.org_id) @phases = nil - @dmptemplates.each do |template| + @templates.each do |template| if @phases.nil? then @phases = template.phases.all.order('number') else @phases = @phases + template.phases.all.order('number') end end - @versions = nil - @phases.each do |phase| - if @versions.nil? then - @versions = phase.versions.all.order('title') - else - @versions = @versions + phase.versions.all.order('title') - end - end @sections = nil - @versions.each do |version| + @phases.each do |phase| if @sections.nil? then - @sections = version.sections.all.order('number') + @sections = phase.sections.all.order('number') else - @sections = @sections + version.sections.all.order('number') + @sections = @sections + phase.sections.all.order('number') end end @questions = nil @@ -56,6 +48,8 @@ @questions = @questions + section.questions.all.order('number') end end + @themes = Theme.all.order('title') + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') respond_to do |format| format.html end @@ -65,7 +59,7 @@ def update_phases authorize Guidance # updates phases, versions, sections and questions based on template selected - dmptemplate = Dmptemplate.find(params[:dmptemplate_id]) + dmptemplate = Template.find(params[:dmptemplate_id]) # map to title and id for use in our options_for_select @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, I18n.t('helpers.select_phase')) @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) @@ -102,41 +96,10 @@ # GET /guidances/1/edit def admin_edit - @guidance = Guidance.find(params[:id]) + @guidance = Guidance.includes(:themes, :guidance_group).find(params[:id]) authorize @guidance - @dmptemplates = Dmptemplate.funders_and_own_templates(current_user.organisation_id) - @phases = nil - @dmptemplates.each do |template| - if @phases.nil? then - @phases = template.phases.all.order('number') - else - @phases = @phases + template.phases.all.order('number') - end - end - @versions = nil - @phases.each do |phase| - if @versions.nil? then - @versions = phase.versions.all.order('title') - else - @versions = @versions + phase.versions.all.order('title') - end - end - @sections = nil - @versions.each do |version| - if @sections.nil? then - @sections = version.sections.all.order('number') - else - @sections = @sections + version.sections.all.order('number') - end - end - @questions = nil - @sections.each do |section| - if @questions.nil? then - @questions = section.questions.all.order('number') - else - @questions = @questions + section.questions.all.order('number') - end - end + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + @themes = Theme.all.order('title') end # POST /guidances diff --git a/app/models/guidance.rb b/app/models/guidance.rb index c5c6566..5e33aec 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -13,6 +13,7 @@ ## # Associations belongs_to :guidance_group + belongs_to :question has_and_belongs_to_many :themes, join_table: "themes_in_guidance" # depricated, but required for migration "single_group_for_guidance" has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group" diff --git a/app/models/template.rb b/app/models/template.rb index 5a7da96..2a9752e 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -51,11 +51,11 @@ # # @return [Array] all templates from funder organisations def self.funders_templates - new_org_obejcts = OrganisationType.find_by(name: GlobalHelpers.constant("organisation_types.funder")).organisations + funder_orgs = Org.funder org_templates = Array.new - new_org_obejcts.each do |neworg| - org_templates += neworg.dmptemplates + funder_orgs.each do |neworg| + org_templates += neworg.templates end return org_templates @@ -74,7 +74,7 @@ # serching for templates for. # - A standardised behavior on querries, wether through active reccord or the # where, should maybe be thought of/decided upon - new_templates = self.where("organisation_id = ?", org_id) + new_templates = self.where("org_id = ?", org_id) return new_templates end @@ -90,7 +90,7 @@ #verify if org type is not a funder current_org = Org.find(org_id) - if current_org.organisation_type.name != GlobalHelpers.constant("organisation_types.funder") then + if !current_org.funder? then own_institutional_templates = self.own_institutional_templates(org_id) else own_institutional_templates = [] diff --git a/app/views/guidances/admin_edit.html.erb b/app/views/guidances/admin_edit.html.erb index e6a47f9..055334d 100644 --- a/app/views/guidances/admin_edit.html.erb +++ b/app/views/guidances/admin_edit.html.erb @@ -7,11 +7,11 @@
<%= link_to t("org_admin.guidance.add_guidance"), admin_new_guidance_path, - :class => 'btn btn-primary' %> + class: 'btn btn-primary' %> <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => 'btn btn-primary' %> -
+ class: 'btn btn-primary' %> +
@@ -19,8 +19,8 @@
- <%= form_for(@guidance, :url => admin_update_guidance_path(@guidance), :html => { :method => :put , :id => 'edit_guidance_form'}) do |f| %> - + <%= form_for(@guidance, url: admin_update_guidance_path(@guidance), html: { method: :put , id: 'edit_guidance_form'}) do |f| %> + @@ -28,7 +28,7 @@ <%= text_area_tag("guidance-text", @guidance.text, class: "tinymce") %>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_text_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.text_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_text_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.text_help_text_html'))%>
@@ -38,109 +38,69 @@ - + - - - - + + + + - - +
<%= t('org_admin.guidance.text_label') %>
<% if !@guidance.question_id.nil? then %> <% select_op = 2 %> - <% else%> + <% else %> <% select_op = 1%> - <%end%> - <%= hidden_field 'select_op' , :value => select_op, :id => 'edit_guid_ques_flag' %> - - <%= select_tag "g_options", options_for_select({t('org_admin.guidance.by_themes_label') => 1, + <% end %> + <%= hidden_field 'select_op', value: select_op, id: 'edit_guid_ques_flag' %> + + <%= select_tag "g_options", options_for_select({t('org_admin.guidance.by_themes_label') => 1, t('org_admin.guidance.by_question_label') => 2}, select_op) %>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_apply_to_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.apply_to_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_apply_to_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.apply_to_help_text_html'))%>
- - -
<%= t('org_admin.guidance.published') %>
- <%= f.check_box :published , :as => :check_boxes%> -
-
- -
-
<%= t('org_admin.guidance.published') %>
+ <%= f.check_box :published , as: :check_boxes%> +
+
<%= t('org_admin.guidance.guidance_group_label') %>
- <%= f.collection_select(:guidance_group_ids, - GuidanceGroup.where("organisation_id = ?", current_user.organisation_id).order('name ASC'), - :id, :name, {:prompt => false, :include_blank => 'None'}, {:multiple => false})%> +
+
+ <%= f.collection_select(:guidance_group_id, @guidance_groups, + :id, :name, {prompt: false, include_blank: 'None'}, {multiple: false})%>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_select_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_select_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_group_select_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_select_help_text_html'))%>
- +
- + - +
<%= t('helpers.submit.save')%> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn cancel' %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %>
- +
- <%= tinymce :content_css => asset_path('application.css') %> + <%= tinymce content_css: asset_path('application.css') %> <%end%>
-
+ diff --git a/app/views/guidances/admin_new.html.erb b/app/views/guidances/admin_new.html.erb index bf37fe1..43e620c 100644 --- a/app/views/guidances/admin_new.html.erb +++ b/app/views/guidances/admin_new.html.erb @@ -7,15 +7,15 @@
<%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => 'btn btn-primary' %> -
+ class: 'btn btn-primary' %> +
- <%= form_for :guidance, :url => {:action => 'admin_create'}, :html => {:id => 'new_guidance_form'} do |f| %> + <%= form_for :guidance, url: {action: 'admin_create'}, html: {id: 'new_guidance_form'} do |f| %> @@ -23,7 +23,7 @@ <%= text_area_tag("guidance-text", "", class: "tinymce") %>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_text_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.text_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_text_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.text_help_text_html'))%>
@@ -31,86 +31,82 @@ - +
<%= t('org_admin.guidance.text_label') %>
<%= t('org_admin.guidance.by_theme_or_by_question') %>
- <%= select_tag "g_options", options_for_select([[t('org_admin.guidance.by_themes_label'), 1], + <%= select_tag "g_options", options_for_select([[t('org_admin.guidance.by_themes_label'), 1], [t('org_admin.guidance.by_question_label'), 2]]) %>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_apply_to_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.apply_to_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_apply_to_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.apply_to_help_text_html'))%>
- - + +
<%= t('org_admin.guidance.published') %>
- <%= f.check_box :published , :as => :check_boxes%> + <%= f.check_box :published , as: :check_boxes%>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_subset_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_published_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_group_subset_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_published_help_text_html'))%>
<%= t('org_admin.guidance.guidance_group_label') %>
- <%= f.collection_select(:guidance_group_ids, - GuidanceGroup.where("organisation_id = ?", current_user.organisation_id).order('name ASC'), - :id, :name, {:prompt => false, :include_blank => 'None'}, {:multiple => false})%> + <%= f.collection_select(:guidance_group_id, @guidance_groups, + :id, :name, {prompt: false, include_blank: 'None'}, {multiple: false})%>
- <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_select_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_select_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_group_select_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_select_help_text_html'))%>
- +
- + - +
<%= t("helpers.submit.save")%> - - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn cancel' %> + + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %>
- +
- <%= tinymce :content_css => asset_path('application.css') %> + <%= tinymce content_css: asset_path('application.css') %> <%end%>
-
+ diff --git a/app/views/guidances/admin_show.html.erb b/app/views/guidances/admin_show.html.erb index a8f8d6e..14356f8 100644 --- a/app/views/guidances/admin_show.html.erb +++ b/app/views/guidances/admin_show.html.erb @@ -7,11 +7,11 @@
<%= link_to t("org_admin.guidance.add_guidance"), admin_new_guidance_path, - :class => "btn btn-primary" %> + class: "btn btn-primary" %> <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => "btn btn-primary" %> -
+ class: "btn btn-primary" %> +
@@ -19,7 +19,7 @@
- + @@ -30,46 +30,45 @@ - <%end%> + <% end %> <% if !@guidance.question_id.nil? %> - <%end%> + <% end %> - - + - + - +
<%= t("org_admin.guidance.text_label") %><%= t("org_admin.guidance.themes_label") %> <% @guidance.themes.each do |th|%> <%= th.title %> - <%end%> + <% end %>
<%= t("org_admin.guidance.question_label") %> <%= raw @guidance.question.text %>
<%= t("org_admin.guidance.guidance_group_label") %><% @guidance.guidance_groups.each do |p|%> - <%= p.name %> - <%end%> + + <%= @guidance.guidance_group.name %>
<%= t("org_admin.guidance.published") %> <%if @guidance.published == false || @guidance.published.nil? then%> <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> + <% else %> + <%= t("helpers.yes_label")%> + <% end %>
<%= t("org_admin.guidance.created") %><%= l @guidance.created_at.to_date, :formats => :short %><%= l @guidance.created_at.to_date, formats: :short %>
<%= t("org_admin.guidance.last_updated") %><%= l @guidance.updated_at.to_date, :formats => :short %><%= l @guidance.updated_at.to_date, formats: :short %>
- <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(@guidance.id), :class => "btn btn-primary"%> - <%= link_to t("helpers.submit.back"), :back, :class => "btn cancel" %> + <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(@guidance.id), class: "btn btn-primary"%> + <%= link_to t("helpers.submit.back"), :back, class: "btn cancel" %>

-
\ No newline at end of file + \ No newline at end of file