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 @@
  • <%= link_to _('Super admin area'), "/admin", class: "signIn_dropdown_link" %>
  • <% end %> <% if current_user.can_org_admin? && !current_user.org_id.nil? %> -
  • <%= link_to _("Admin area"), admin_index_template_path(current_user.org_id), class: "signIn_dropdown_link" %>
  • + <% if current_user.can_modify_templates? %> +
  • <%= link_to _("Admin area"), admin_index_template_path(current_user.org_id), class: "signIn_dropdown_link" %>
  • + <% elsif current_user.can_modify_guidance? %> +
  • <%= link_to _("Admin area"), admin_index_guidance_path(current_user.org_id), class: "signIn_dropdown_link" %>
  • + <% elsif current_user.can_modify_org_details? %> +
  • <%= link_to _("Admin area"), admin_show_org_path(current_user.org_id), class: "signIn_dropdown_link" %>
  • + <% elsif current_user.can_grant_permissions? %> +
  • <%= link_to _("Admin area"), admin_index_user_path, class: "signIn_dropdown_link" %>
  • + <% end %> <% end %>
  • <%= link_to _('Sign out'), destroy_user_session_path, method: :delete, class: "signIn_dropdown_link" %>
  • diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index b277af4..2817e20 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -199,17 +199,20 @@

    <%= _('This plan is based on:')%>

    - - <%if plan.template.org.name.present? %> - - - - - <%end%> - - <%if based_on.present? %> - <%= " (#{_('Customised from')} " + based_on.org.name + ")" %> - <%end%> + + <%if based_on.present? %> + + + + + <%end%> + <%if plan.template.org.name.present? %> + + + + + <%end%> +
    <%= _('Funder') %><%= plan.template.org.name %>
    <%= _('Funder') %><%= based_on.org.name %>
    <%= _('Institution') %><%= plan.template.org.name %>
    diff --git a/db/migrate/20170130105546_create_plan_guidance_groups.rb b/db/migrate/20170130105546_create_plan_guidance_groups.rb deleted file mode 100644 index b3d330e..0000000 --- a/db/migrate/20170130105546_create_plan_guidance_groups.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreatePlanGuidanceGroups < ActiveRecord::Migration - def change - create_table :plan_guidance_groups do |t| - t.references :plan, index: true, foreign_key: true - t.references :guidance_group, index: true, foreign_key: true - - t.timestamps null: false - end - end -end diff --git a/db/migrate/20170130111947_add_selected_to_plan_guidance_groups.rb b/db/migrate/20170130111947_add_selected_to_plan_guidance_groups.rb deleted file mode 100644 index d9548ba..0000000 --- a/db/migrate/20170130111947_add_selected_to_plan_guidance_groups.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddSelectedToPlanGuidanceGroups < ActiveRecord::Migration - def change - add_column :plan_guidance_groups, :selected, :boolean - end -end diff --git a/db/schema.rb b/db/schema.rb index 62d2ca1..6147894 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -212,6 +212,11 @@ add_index "plans", ["template_id"], name: "fk_rails_3424ca281f" + create_table "plans_guidance_groups", force: :cascade do |t| + t.integer "guidance_group_id" + t.integer "plan_id" + end + create_table "question_formats", force: :cascade do |t| t.string "title" t.text "description" @@ -413,7 +418,44 @@ t.integer "perm_id" end - add_index "users_perms", ["perm_id"], name: "fk_rails_457217c31c" - add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id" + add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree + add_foreign_key "answers", "plans" + add_foreign_key "answers", "questions" + add_foreign_key "answers", "users" + add_foreign_key "answers_question_options", "answers" + add_foreign_key "answers_question_options", "question_options" + add_foreign_key "guidance_groups", "orgs" + add_foreign_key "guidances", "guidance_groups" + add_foreign_key "notes", "answers" + add_foreign_key "notes", "users" + add_foreign_key "org_token_permissions", "orgs" + add_foreign_key "org_token_permissions", "token_permission_types" + add_foreign_key "orgs", "languages" + add_foreign_key "orgs", "regions" + add_foreign_key "phases", "templates" + add_foreign_key "plan_guidance_groups", "guidance_groups" + add_foreign_key "plan_guidance_groups", "plans" + add_foreign_key "plans", "templates" + add_foreign_key "plans_guidance_groups", "guidance_groups" + add_foreign_key "plans_guidance_groups", "plans" + add_foreign_key "question_options", "questions" + add_foreign_key "questions", "question_formats" + add_foreign_key "questions", "sections" + add_foreign_key "questions_themes", "questions" + add_foreign_key "questions_themes", "themes" + add_foreign_key "roles", "plans" + add_foreign_key "roles", "users" + add_foreign_key "sections", "phases" + add_foreign_key "suggested_answers", "orgs" + add_foreign_key "suggested_answers", "questions" + add_foreign_key "templates", "orgs" + add_foreign_key "themes_in_guidance", "guidances" + add_foreign_key "themes_in_guidance", "themes" + add_foreign_key "user_identifiers", "identifier_schemes" + add_foreign_key "user_identifiers", "users" + add_foreign_key "users", "languages" + add_foreign_key "users", "orgs" + add_foreign_key "users_perms", "perms" + add_foreign_key "users_perms", "users" end