diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 937d681..3dff207 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -55,8 +55,8 @@ @project = Project.new @project.organisation = current_user.organisation @funders = orgs_of_type(constant("organisation_types.funder"), true) - @templates = Dmptemplate.where(published: true) - @guidance_groups = GuidanceGroup.where(published: true) + @templates = get_available_templates + @guidance_groups = get_available_guidance @institutions = orgs_of_type(constant("organisation_types.institution")) respond_to do |format| @@ -292,4 +292,25 @@ return all_such_orgs.sort_by {|o| [o.sort_name, o.name] } end end + + # ----------------------------------------------------------- + def get_available_templates + Dmptemplate.where(published: true) + end + + # ----------------------------------------------------------- + def get_available_guidance + # Exclude Funders, Institutions, or children of Institutions + excluded_orgs = orgs_of_type(constant("organisation_types.funder")) + + orgs_of_type(constant("organisation_types.institution")) + + Organisation.orgs_with_parent_of_type(constant("organisation_types.institution")) + + # Get all guidance that does not belong to a funder or institution + guidance_groups = GuidanceGroup.guidance_groups_excluding(excluded_orgs) + + (guidance_groups + GuidanceGroup.where(optional_subset: true)).uniq + +# (GuidanceGroup.where("guidance_groups.published = ? OR guidance_groups.optional_subset = ?", true, true) + GuidanceGroup.joins(:dmptemplates).where('dmptemplates.id': @templates.collect{|t| t.id})).uniq + end + end diff --git a/app/views/projects/_dropdowns_new_project.html.erb b/app/views/projects/_dropdowns_new_project.html.erb index c79acc6..3f942ea 100644 --- a/app/views/projects/_dropdowns_new_project.html.erb +++ b/app/views/projects/_dropdowns_new_project.html.erb @@ -59,7 +59,7 @@ <%= hash_to_json_object('templates', @templates.collect{ |tmplt| {'organisation': tmplt.organisation_id, 'id': tmplt.id, 'title': tmplt.title} }) %> - <%= hash_to_json_object('guidance_groups', @guidance_groups.collect{ |grp| {'organisation': grp.organisation_id, 'id': grp.id, 'name': grp.name} }) %> + <%= hash_to_json_object('guidance_groups', @guidance_groups.collect{ |grp| {'organisation': grp.organisation_id, 'templates': grp.dmptemplates.collect{ |t| t.id }, 'id': grp.id, 'name': grp.name} }) %> <% end %>