diff --git a/app/controllers/results_controller.rb b/app/controllers/results_controller.rb index ff0ce393f..6c15331f1 100644 --- a/app/controllers/results_controller.rb +++ b/app/controllers/results_controller.rb @@ -41,7 +41,12 @@ class ResultsController < ApplicationController end def list - @results = @my_module.results.active + if params[:with_linked_step_id].present? + step = @my_module.protocol.steps.find_by(id: params[:with_linked_step_id]) + @results = @my_module.results.where(archived: false).or(@my_module.results.where(id: step.results.select(:id))) + else + @results = @my_module.results.active + end update_and_apply_user_sort_preference! end diff --git a/app/javascript/vue/protocol/modals/link_results.vue b/app/javascript/vue/protocol/modals/link_results.vue index 55de5e4a8..3d5fccdf9 100644 --- a/app/javascript/vue/protocol/modals/link_results.vue +++ b/app/javascript/vue/protocol/modals/link_results.vue @@ -94,7 +94,7 @@ export default { }, computed: { resultsListUrl() { - return list_my_module_results_path({ my_module_id: this.step.attributes.my_module_id }); + return list_my_module_results_path({ my_module_id: this.step.attributes.my_module_id, with_linked_step_id: this.step.id }); }, resultsPageUrl() { return my_module_results_path({ my_module_id: this.step.attributes.my_module_id }); diff --git a/app/models/result.rb b/app/models/result.rb index b23b63e49..9b51088f5 100644 --- a/app/models/result.rb +++ b/app/models/result.rb @@ -39,6 +39,7 @@ class Result < ApplicationRecord accepts_nested_attributes_for :tables before_save :ensure_default_name + after_discard :delete_step_results after_discard do CleanupUserSettingsJob.perform_later('result_states', id) end @@ -187,4 +188,8 @@ class Result < ApplicationRecord def ensure_default_name self.name = name.presence || I18n.t('my_modules.results.default_name') end + + def delete_step_results + step_results.destroy_all + end end