diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index dd87dbc..0558760 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -16,6 +16,7 @@ # if they dont exist, no requirement for them to be saved ex_save = example_answer.present? ? example_answer.save : true guid_save = guidance.present? ? guidance.save : true + @question.section.phase.template.dirty = true if ex_save && guid_save typ = (example_answer.present? && guidance.present? ? 'example answer and guidance' : (guidance.present? ? 'guidance' : 'example answer')) @@ -74,6 +75,8 @@ @section = @question.section @phase = @section.phase + @phase.template.dirty = true + if ex_save && guid_save typ = (example_answer.present? && guidance.present? ? 'example answer and guidance' : (guidance.present? ? 'guidance' : 'example answer')) redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: success_message(typ, _('saved')) @@ -97,6 +100,7 @@ @question = @example_answer.question @section = @question.section @phase = @section.phase + @phase.template.dirty = true if @example_answer.destroy redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: success_message(_('information'), _('deleted')) else @@ -115,4 +119,4 @@ return annotation end -end \ No newline at end of file +end diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 668742e..6275b15 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -29,17 +29,19 @@ # where guidance is a hash with the text and the org name theme_guidance = {} - guidance_groups.each do |guidance_group| - guidance_group.guidances.where(published: true).each do |guidance| - guidance.themes.each do |theme| - title = theme.title - if !theme_guidance.has_key?(title) - theme_guidance[title] = Array.new + guidance_groups.includes(guidances:[:themes]).each do |guidance_group| + guidance_group.guidances.each do |guidance| + if guidance.published + guidance.themes.each do |theme| + title = theme.title + if !theme_guidance.has_key?(title) + theme_guidance[title] = Array.new + end + theme_guidance[title] << { + text: guidance.text, + org: guidance_group.name + ':' + } end - theme_guidance[title] << { - text: guidance.text, - org: guidance_group.name + ':' - } end end end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 5a8687c..93b9508 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -423,10 +423,10 @@ def template_options(org_id, funder_id) @templates = [] - if !org_id.blank? || !funder_id.blank? + if org_id.present? || funder_id.present? if funder_id.blank? # Load the org's template(s) - unless org_id.nil? + if org_id.present? org = Org.find(org_id) @templates = Template.valid.where(published: true, org: org, customization_of: nil).to_a @msg = _("We found multiple DMP templates corresponding to the research organisation.") if @templates.count > 1 @@ -437,20 +437,20 @@ # Load the funder's template(s) @templates = Template.valid.where(published: true, org: funder).to_a - unless org_id.blank? + if org_id.present? org = Org.find(org_id) # Swap out any organisational cusotmizations of a funder template @templates.each do |tmplt| customization = Template.valid.find_by(published: true, org: org, customization_of: tmplt.dmptemplate_id) - unless customization.nil? + if customization.present? && tmplt.updated_at < customization.created_at @templates.delete(tmplt) @templates << customization end end end - msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1 + @msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1 end end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 4001bbe..696a8de 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -11,7 +11,7 @@ def admin_index authorize Template - funder_templates, org_templates, customizations = [], [], [] + funder_templates, org_templates = [], [] # Get all of the unique template family ids (dmptemplate_id) for each funder and the current org funder_ids = Org.funders.includes(:templates).collect{|f| f.templates.where(published: true).valid.collect{|ft| ft.dmptemplate_id } }.flatten.uniq @@ -55,6 +55,7 @@ random = rand 2147483647 break random unless Template.exists?(dmptemplate_id: random) end + customisation.dirty = true customisation.save customisation.phases.includes(:sections, :questions).each do |phase| @@ -131,7 +132,7 @@ # find corresponding question in new template customization_question = customization_section.questions.where(number: question.number).first # apply annotations - question.annotations.each do |annotation| + question.annotations.where(org_id: current_user.org_id).each do |annotation| annotation_copy = Annotation.deep_copy(annotation) annotation_copy.question_id = customization_question.id annotation_copy.save! @@ -213,7 +214,7 @@ new_version.save @template = new_version # @current = Template.current(@template.dmptemplate_id) - end + end else flash[:notice] = _('You are viewing a historical version of this template. You will not be able to make changes.') end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1915dc5..1aa751c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -44,7 +44,7 @@ else if perms.include? perm @user.perms << perm - if perm.name == Perm.use_api.id + if perm.id == Perm.use_api.id @user.keep_or_generate_token! end end diff --git a/app/dashboards/exported_plan_dashboard.rb b/app/dashboards/exported_plan_dashboard.rb index 47b352e..ec618cf 100644 --- a/app/dashboards/exported_plan_dashboard.rb +++ b/app/dashboards/exported_plan_dashboard.rb @@ -15,6 +15,7 @@ format: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, + phase_id: Field::Number, }.freeze # COLLECTION_ATTRIBUTES @@ -39,6 +40,7 @@ :format, :created_at, :updated_at, + :phase_id, ].freeze # FORM_ATTRIBUTES @@ -49,6 +51,7 @@ :user, :setting_objects, :format, + :phase_id, ].freeze # Overwrite this method to customize how exported plans are displayed diff --git a/app/dashboards/guidance_dashboard.rb b/app/dashboards/guidance_dashboard.rb index 8e6427f..c76c41b 100644 --- a/app/dashboards/guidance_dashboard.rb +++ b/app/dashboards/guidance_dashboard.rb @@ -10,7 +10,6 @@ ATTRIBUTE_TYPES = { guidance_group: Field::BelongsTo, themes: Field::HasMany, - guidance_groups: Field::HasMany, id: Field::Number, text: Field::Text, created_at: Field::DateTime, @@ -27,8 +26,8 @@ COLLECTION_ATTRIBUTES = [ :guidance_group, :themes, - :guidance_groups, :id, + :text, ].freeze # SHOW_PAGE_ATTRIBUTES @@ -36,7 +35,6 @@ SHOW_PAGE_ATTRIBUTES = [ :guidance_group, :themes, - :guidance_groups, :id, :text, :created_at, @@ -51,7 +49,6 @@ FORM_ATTRIBUTES = [ :guidance_group, :themes, - :guidance_groups, :text, :question_id, :published, diff --git a/app/dashboards/guidance_group_dashboard.rb b/app/dashboards/guidance_group_dashboard.rb index a8a83cc..76e2f09 100644 --- a/app/dashboards/guidance_group_dashboard.rb +++ b/app/dashboards/guidance_group_dashboard.rb @@ -10,6 +10,7 @@ ATTRIBUTE_TYPES = { org: Field::BelongsTo, guidances: Field::HasMany, + plans: Field::HasMany, id: Field::Number, name: Field::String, created_at: Field::DateTime, @@ -24,10 +25,11 @@ # By default, it's limited to four items to reduce clutter on index pages. # Feel free to add, remove, or rearrange items. COLLECTION_ATTRIBUTES = [ + :name, :org, :guidances, +# :plans, :id, - :name, ].freeze # SHOW_PAGE_ATTRIBUTES @@ -35,6 +37,7 @@ SHOW_PAGE_ATTRIBUTES = [ :org, :guidances, +# :plans, :id, :name, :created_at, @@ -49,6 +52,7 @@ FORM_ATTRIBUTES = [ :org, :guidances, +# :plans, :name, :optional_subset, :published, @@ -60,7 +64,6 @@ # def display_resource(guidance_group) # "GuidanceGroup ##{guidance_group.id}" # end - def display_resource(guidance_group) guidance_group.name end diff --git a/app/dashboards/org_dashboard.rb b/app/dashboards/org_dashboard.rb index c00db7b..72f8962 100644 --- a/app/dashboards/org_dashboard.rb +++ b/app/dashboards/org_dashboard.rb @@ -43,7 +43,7 @@ :abbreviation, :language, :guidance_groups, - :templates, +# :templates, :contact_email, :org_type, ].freeze @@ -55,7 +55,7 @@ :abbreviation, :language, :guidance_groups, - :templates, +# :templates, :contact_email, :org_type, :users, diff --git a/app/dashboards/plan_dashboard.rb b/app/dashboards/plan_dashboard.rb index cb3b724..e22c30f 100644 --- a/app/dashboards/plan_dashboard.rb +++ b/app/dashboards/plan_dashboard.rb @@ -17,12 +17,10 @@ notes: Field::HasMany, roles: Field::HasMany, users: Field::HasMany, - plans_guidance_groups: Field::HasMany, guidance_groups: Field::HasMany, exported_plans: Field::HasMany, setting_objects: Field::HasMany.with_options(class_name: "Settings::Template"), id: Field::Number, - project_id: Field::Number, title: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, @@ -61,12 +59,10 @@ :notes, :roles, :users, - :plans_guidance_groups, :guidance_groups, :exported_plans, :setting_objects, :id, - :project_id, :title, :created_at, :updated_at, @@ -94,11 +90,9 @@ :notes, :roles, :users, - :plans_guidance_groups, :guidance_groups, :exported_plans, :setting_objects, - :project_id, :title, :slug, :grant_number, diff --git a/app/dashboards/question_dashboard.rb b/app/dashboards/question_dashboard.rb index af3d8bb..cda2c4c 100644 --- a/app/dashboards/question_dashboard.rb +++ b/app/dashboards/question_dashboard.rb @@ -17,7 +17,6 @@ id: Field::Number, text: Field::Text, default_value: Field::Text, - guidance: Field::Text, number: Field::Number, created_at: Field::DateTime, updated_at: Field::DateTime, @@ -49,7 +48,6 @@ :id, :text, :default_value, - :guidance, :number, :created_at, :updated_at, @@ -69,7 +67,6 @@ :question_format, :text, :default_value, - :guidance, :number, :option_comment_display, :modifiable, diff --git a/app/dashboards/template_dashboard.rb b/app/dashboards/template_dashboard.rb index cfaa8e0..7a5a313 100644 --- a/app/dashboards/template_dashboard.rb +++ b/app/dashboards/template_dashboard.rb @@ -28,6 +28,8 @@ visibility: Field::Number, customization_of: Field::Number, dmptemplate_id: Field::Number, + migrated: Field::Boolean, + dirty: Field::Boolean, }.freeze # COLLECTION_ATTRIBUTES @@ -67,6 +69,8 @@ :visibility, :customization_of, :dmptemplate_id, + :migrated, + :dirty, ].freeze # FORM_ATTRIBUTES @@ -90,6 +94,8 @@ :visibility, :customization_of, :dmptemplate_id, + :migrated, + :dirty, ].freeze # Overwrite this method to customize how templates are displayed diff --git a/app/dashboards/theme_dashboard.rb b/app/dashboards/theme_dashboard.rb index 40f8b3d..2be7c8d 100644 --- a/app/dashboards/theme_dashboard.rb +++ b/app/dashboards/theme_dashboard.rb @@ -60,4 +60,7 @@ # def display_resource(theme) # "Theme ##{theme.id}" # end + def display_resource(theme) + "Theme: #{theme.title} (##{theme.id})" + end end diff --git a/app/models/plan.rb b/app/models/plan.rb index fd828e4..84f2a76 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -160,7 +160,7 @@ # find all the themes in this plan # and get the guidance groups they belong to ggroups = [] - self.template.phases.each do |phase| + Template.includes(phases: [sections: [questions: [themes: [guidances: [guidance_group: :org]]]]]).find(self.template_id).phases.each do |phase| phase.sections.each do |section| section.questions.each do |question| question.themes.each do |theme| diff --git a/app/models/user.rb b/app/models/user.rb index 94918ec..d4e0543 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -46,7 +46,7 @@ ## # Scopes - default_scope { includes(:org, :perms, :plans) } + default_scope { includes(:org, :perms) } diff --git a/app/views/devise/registrations/_external_identifier_shibboleth.html.erb b/app/views/devise/registrations/_external_identifier_shibboleth.html.erb index 1a33004..65ca8fb 100644 --- a/app/views/devise/registrations/_external_identifier_shibboleth.html.erb +++ b/app/views/devise/registrations/_external_identifier_shibboleth.html.erb @@ -16,7 +16,6 @@ <% title = _("Unlink your account from #{scheme.description}. You can link again at any time.") %> <%= link_to ''.html_safe, destroy_user_identifier_path(id), method: :delete, title: title, 'aria-label': title, - 'data-toggle': "modal", 'dialog-width': "450px", data: {confirm: _("Are you sure you want to unlink #{scheme.description} ID?")} %> <% end %> \ No newline at end of file diff --git a/app/views/devise/registrations/_personal_details.html.erb b/app/views/devise/registrations/_personal_details.html.erb index 692c43c..5ed5eb3 100644 --- a/app/views/devise/registrations/_personal_details.html.erb +++ b/app/views/devise/registrations/_personal_details.html.erb @@ -119,10 +119,3 @@ <% end %> - - -
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index d9242fa..cbf6238 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -4,13 +4,12 @@ <% unless session["devise.shibboleth_data"].nil? %>
- <%= (_("%{application_name} doesn't recognise your institutional credentials - either you haven't created an account with us or you haven't linked these details to your existing account.
* If you do not have an account with %{application_name}, please complete the form below.
* If you have an account with %{application_name}, please Sign in so we can link your account to your institutional credentials.
Once you have created and/or linked your account, you'll be able to sign in with your institutional credentials directly.") % { :application_name => Rails.configuration.branding[:application][:name] }).html_safe %>
+ <%= (_("%{application_name} doesn't recognise your institutional credentials - either you haven't created an account with us or you haven't linked these details to your existing account.
* If you do not have an account with %{application_name}, please complete the form below.
* If you have an account with %{application_name}, please so we can link your account to your institutional credentials.
Once you have created and/or linked your account, you'll be able to sign in with your institutional credentials directly.") % { :application_name => Rails.configuration.branding[:application][:name] }).html_safe %>
| <%= _('Text') %> | -
-
- <%= text_area_tag("guidance-text", "", class: "tinymce") %>
-
-
-
-
-
-
- |
-
| <%= _('Should this guidance apply:') %> | -- - | -
| <%= _('Published') %> | -
-
- <%= f.check_box :published , as: :check_boxes %>
-
- |
-
| <%= _('Guidance group') %> | -
-
- <%= f.collection_select(:guidance_group_ids,
- GuidanceGroup.where(org_id: current_user.org_id).order("name ASC"),
- :id, :name, {prompt: false, include_blank: _('None')}, {multiple: false})%>
-
-
-
-
-
-
- |
-