From 2901c7b6271761cb87524b4e9f9b9d675a74bb2a Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 28 Nov 2022 12:44:15 +0100 Subject: [PATCH] Add restore action to experiment table [SCI-7453] --- app/assets/javascripts/experiments/table.js | 14 ++++++++++++++ app/controllers/my_modules_controller.rb | 7 ++++++- app/services/experiments/table_view_service.rb | 3 ++- app/views/experiments/_table_row_actions.html.erb | 8 ++++++++ app/views/experiments/_table_toolbar.html.erb | 4 ++++ config/locales/en.yml | 2 ++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/experiments/table.js b/app/assets/javascripts/experiments/table.js index 7ea9a3280..c3f357017 100644 --- a/app/assets/javascripts/experiments/table.js +++ b/app/assets/javascripts/experiments/table.js @@ -70,6 +70,11 @@ var ExperimnetTable = { e.preventDefault(); this.archiveMyModules(e.target.href, e.target.dataset.id); }); + + $(this.table).on('click', '.restore-my-module', (e) => { + e.preventDefault(); + this.restoreMyModules(e.target.href, e.target.dataset.id); + }); }, initArchiveMyModules: function() { $('#archiveTask').on('click', (e) => { @@ -84,6 +89,14 @@ var ExperimnetTable = { HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); }); }, + initRestoreMyModules: function() { + $('#restoreTask').on('click', (e) => { + this.restoreMyModules(e.target.dataset.url, this.selectedMyModules); + }); + }, + restoreMyModules: function(url, ids) { + $.post(url, { my_modules_ids: ids, view: 'table' }); + }, initAccessModal: function() { $('#manageTaskAccess').on('click', () => { $(`.table-row[data-id="${this.selectedMyModules[0]}"] .open-access-modal`).click(); @@ -299,6 +312,7 @@ var ExperimnetTable = { this.initNewTaskModal(this); this.initMyModuleActions(); this.updateExperimentToolbar(); + this.initRestoreMyModules(); } }; diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 4924fe264..b274d7f6d 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -362,7 +362,12 @@ class MyModulesController < ApplicationController else flash[:error] = t('my_modules.restore_group.error_flash') end - redirect_to module_archive_experiment_path(experiment) + + if params[:view] == 'table' + redirect_to table_experiment_path(experiment, view_mode: :archived) + else + redirect_to module_archive_experiment_path(experiment) + end end def update_state diff --git a/app/services/experiments/table_view_service.rb b/app/services/experiments/table_view_service.rb index 5780fab6e..00727298a 100644 --- a/app/services/experiments/table_view_service.rb +++ b/app/services/experiments/table_view_service.rb @@ -70,7 +70,8 @@ module Experiments permissions: permissions_my_module_path(my_module), actions_dropdown: actions_dropdown_my_module_path(my_module), name_update: my_module_path(my_module), - access: edit_access_permissions_project_experiment_my_module_path(project, experiment, my_module) + access: edit_access_permissions_project_experiment_my_module_path(project, experiment, my_module), + restore: restore_my_modules_experiment_path(experiment) } } end diff --git a/app/views/experiments/_table_row_actions.html.erb b/app/views/experiments/_table_row_actions.html.erb index a06cd58fe..3ae2f51a9 100644 --- a/app/views/experiments/_table_row_actions.html.erb +++ b/app/views/experiments/_table_row_actions.html.erb @@ -37,3 +37,11 @@ <% end %> +<% if can_restore_my_module?(my_module) %> +
  • + + + <%= t("experiments.table.my_module_actions.restore") %> + +
  • +<% end %> diff --git a/app/views/experiments/_table_toolbar.html.erb b/app/views/experiments/_table_toolbar.html.erb index 94e73a12e..d74f460a2 100644 --- a/app/views/experiments/_table_toolbar.html.erb +++ b/app/views/experiments/_table_toolbar.html.erb @@ -32,6 +32,10 @@ <%= t("experiments.table.toolbar.archive") %> +