From e0bb2475c901b92a70961cda7723cf53c6d878ce Mon Sep 17 00:00:00 2001 From: xsrust Date: Thu, 17 Aug 2017 14:56:24 +0100 Subject: [PATCH 1/5] updated display of publish/unpublish buttons on templates index page --- app/controllers/annotations_controller.rb | 6 +++++- app/controllers/templates_controller.rb | 1 + app/views/templates/admin_index.html.erb | 14 +++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index e83366b08a..73a34fb6fa 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -16,6 +16,7 @@ def admin_create # 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 redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully created.') @@ -73,6 +74,8 @@ def admin_update @section = @question.section @phase = @section.phase + @phase.template.dirty = true + if ex_save && guid_save redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') else @@ -95,6 +98,7 @@ def admin_destroy @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: _('Information was successfully deleted.') else @@ -113,4 +117,4 @@ def init_annotation(text, question, org, type) return annotation end -end \ No newline at end of file +end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 42eb4eedc4..1752689402 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -55,6 +55,7 @@ def admin_customize random = rand 2147483647 break random unless Template.exists?(dmptemplate_id: random) end + customization.dirty = true customisation.save customisation.phases.includes(:sections, :questions).each do |phase| diff --git a/app/views/templates/admin_index.html.erb b/app/views/templates/admin_index.html.erb index 2acb25ae6a..7532bec27f 100644 --- a/app/views/templates/admin_index.html.erb +++ b/app/views/templates/admin_index.html.erb @@ -46,10 +46,10 @@ <% if hash[:live].nil? %> <%= _('Unpublished') %> - + <% elsif hash[:current].dirty? %> <%= _('Unpublished changes') %> - + <% else %> <%= _('Published') %> <% end %> @@ -58,7 +58,7 @@ <% last_temp_updated = hash[:current].updated_at %> <%= l last_temp_updated.to_date, formats: :short %> - + <%= link_to _('Edit'), admin_template_template_path(id: hash[:current].id, edit: "true"), class: "dmp_table_link" %> <%= link_to _('History'), admin_template_history_template_path(id: hash[:current].id), class: "dmp_table_link" %> @@ -119,7 +119,7 @@ <% elsif hash[:live].nil? %> <%= b_label = _('Un-published') %> - <% elsif !hash[:current].published? %> + <% elsif hash[:current].dirty? %> <%= _('You have un-published changes') %> <% else %> <%= _('Published') %> @@ -142,14 +142,14 @@ <% b_label = _('Edit customisation') %> <%= link_to b_label, admin_template_template_path(hash[:current]), class: "dmp_table_link" %> <% end %> - + <% end %> - <% if !hash[:current].customization_of.nil? %> + <% if !hash[:current].customization_of.nil? && !hash[:stale] %> <% if hash[:live].nil? || hash[:current].dirty? %> <%= link_to _('Publish'), admin_publish_template_path(hash[:current]), method: :put, class: "dmp_table_link" %> <% end %> - <% if !hash[:live].nil? %> + <% if hash[:live].present? %> <%= link_to _('Unpublish'), admin_unpublish_template_path(hash[:current]), method: :put, class: "dmp_table_link" %> <% end %> <% end %> From f4a91310bc67ac196f631041aec7ffd49199abbe Mon Sep 17 00:00:00 2001 From: xsrust Date: Thu, 17 Aug 2017 15:01:22 +0100 Subject: [PATCH 2/5] updated plan creation logic to disallow outdated customizations --- app/controllers/plans_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index f7edc1fab0..2c4d8c63d3 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -370,10 +370,10 @@ def rollup(plan, src_plan_key, super_id, obj_plan_key) 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 @@ -384,20 +384,20 @@ def template_options(org_id, funder_id) # 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 From 64db38065df2aa8260121d54b86dd36848ddc999 Mon Sep 17 00:00:00 2001 From: xsrust Date: Thu, 17 Aug 2017 15:05:22 +0100 Subject: [PATCH 3/5] updated rake task to remember which annotations should be preserved --- lib/tasks/migrate.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index 7bfa27ebc1..f0708097aa 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -258,8 +258,11 @@ namespace :migrate do task remove_duplicate_annotations: :environment do questions = Question.joins(:annotations).group("questions.id").having("count(annotations.id) > count(DISTINCT annotations.text)") questions.each do |q| + # store already de-duplicated id's so we dont remove them in later iterations + removed = [] q.annotations.each do |a| - conflicts = Annotation.where(question_id: a.question_id, text: a.text).where.not(id: a.id) + removed << a.id + conflicts = Annotation.where(question_id: a.question_id, text: a.text).where.not(id: removed) conflicts.each {|c| c.destroy } end end From 10ae97bc9fc5eff87344dd5923197675966dff7c Mon Sep 17 00:00:00 2001 From: xsrust Date: Thu, 17 Aug 2017 15:40:30 +0100 Subject: [PATCH 4/5] updated spelling mistake --- app/controllers/templates_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 1752689402..2717fefb0e 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -55,7 +55,7 @@ def admin_customize random = rand 2147483647 break random unless Template.exists?(dmptemplate_id: random) end - customization.dirty = true + customisation.dirty = true customisation.save customisation.phases.includes(:sections, :questions).each do |phase| From 7c16a2c9e48d3403ef9f6ccc0e8bc447791d8284 Mon Sep 17 00:00:00 2001 From: xsrust Date: Thu, 17 Aug 2017 15:49:13 +0100 Subject: [PATCH 5/5] updated templates_controller_test to validate new assumption that customizations are dirty --- test/functional/templates_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 0987259416..78a472417f 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -238,7 +238,7 @@ class TemplatesControllerTest < ActionDispatch::IntegrationTest assert_equal 0, customization.version assert_not customization.published? - assert_not customization.dirty? + assert customization.dirty? # Make sure the funder templates data is not modifiable! customization.phases.each do |p|