From 12f141b82ed72a4b0279afb69e52552dfa9cabce Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 1 Dec 2022 09:34:29 +0100 Subject: [PATCH] Experiment table connect task action in dropdown [SCI-7525] --- app/assets/javascripts/experiments/table.js | 101 +++++++++++------- app/assets/stylesheets/experiment/table.scss | 5 + app/controllers/experiments_controller.rb | 2 +- .../experiments/_table_display_modal.html.erb | 5 +- .../experiments/_table_row_actions.html.erb | 6 +- 5 files changed, 77 insertions(+), 42 deletions(-) diff --git a/app/assets/javascripts/experiments/table.js b/app/assets/javascripts/experiments/table.js index b4a90f495..3b553514d 100644 --- a/app/assets/javascripts/experiments/table.js +++ b/app/assets/javascripts/experiments/table.js @@ -76,14 +76,34 @@ var ExperimnetTable = { e.preventDefault(); this.archiveMyModules(e.target.href, e.target.dataset.id); }); + + $(this.table).on('click', '.duplicate-my-module', (e) => { + e.preventDefault(); + this.duplicateMyModules($('#duplicateTasks').data('url'), e.target.dataset.id); + }); + + $(this.table).on('click', '.move-my-module', (e) => { + e.preventDefault(); + this.openMoveModulesModal([e.target.dataset.id]); + }); + + $(this.table).on('click', '.edit-my-module', (e) => { + e.preventDefault(); + $('#modal-edit-module').modal('show'); + $('#modal-edit-module').data('id', e.target.dataset.id); + $('#edit-module-name-input').val($(`#taskName${$('#modal-edit-module').data('id')}`).data('full-name')); + }); }, initDuplicateMyModules: function() { $('#duplicateTasks').on('click', (e) => { - $.post(e.target.dataset.url, { my_module_ids: this.selectedMyModules }, () => { - this.loadTable(); - }).error((data) => { - HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); - }); + this.duplicateMyModules(e.target.dataset.url, this.selectedMyModules); + }); + }, + duplicateMyModules: function(url, ids) { + $.post(url, { my_module_ids: ids }, () => { + this.loadTable(); + }).error((data) => { + HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); }); }, initArchiveMyModules: function() { @@ -107,23 +127,25 @@ var ExperimnetTable = { initRenameModal: function() { $('#editTask').on('click', () => { $('#modal-edit-module').modal('show'); - $('#edit-module-name-input').val($(`#taskName${this.selectedMyModules[0]}`).data('full-name')); + $('#modal-edit-module').data('id', this.selectedMyModules[0]); + $('#edit-module-name-input').val($(`#taskName${$('#modal-edit-module').data('id')}`).data('full-name')); }); $('#modal-edit-module').on('click', 'button[data-action="confirm"]', () => { + let id = $('#modal-edit-module').data('id'); let newValue = $('#edit-module-name-input').val(); - if (newValue === $(`#taskName${this.selectedMyModules[0]}`).data('full-name')) { + if (newValue === $(`#taskName${id}`).data('full-name')) { $('#modal-edit-module').modal('hide'); return false; } $.ajax({ - url: this.getUrls(this.selectedMyModules[0]).name_update, + url: this.getUrls(id).name_update, type: 'PATCH', dataType: 'json', data: { my_module: { name: $('#edit-module-name-input').val() } }, success: () => { - $(`#taskName${this.selectedMyModules[0]}`).text(newValue); - $(`#taskName${this.selectedMyModules[0]}`).data('full-name', newValue); + $(`#taskName${id}`).text(newValue); + $(`#taskName${id}`).data('full-name', newValue); $('#edit-module-name-input').closest('.sci-input-container').removeClass('error'); $('#modal-edit-module').modal('hide'); }, @@ -216,33 +238,36 @@ var ExperimnetTable = { } }); }, - initMoveModulesModal: function () { - let table = $(this.table); + initMoveModulesModal: function() { $('#moveTask').on('click', () => { - $.get(table.data('move-modules-modal-url'), (modalData) => { - if ($('#modal-move-modules').length > 0) { - $('#modal-move-modules').replaceWith(modalData.html); - } else { - $('#experimentTable').append(modalData.html); - } - $('#modal-move-modules').on('shown.bs.modal', function () { - $(this).find('.selectpicker').selectpicker().focus(); - }); - $('#modal-move-modules').on('click', 'button[data-action="confirm"]', () => { - let moveParams = { - to_experiment_id: $('#modal-move-modules').find('.selectpicker').val(), - my_module_ids: this.selectedMyModules - }; - $.post(table.data('move-modules-url'), moveParams, (data) => { - HelperModule.flashAlertMsg(data.message, 'success'); - this.loadTable(); - }).error((data) => { - HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); - }); - $('#modal-move-modules').modal('hide'); - }); - $('#modal-move-modules').modal('show'); + this.openMoveModulesModal(this.selectedMyModules); + }); + }, + openMoveModulesModal: function(ids) { + let table = $(this.table); + $.get(table.data('move-modules-modal-url'), (modalData) => { + if ($('#modal-move-modules').length > 0) { + $('#modal-move-modules').replaceWith(modalData.html); + } else { + $('#experimentTable').append(modalData.html); + } + $('#modal-move-modules').on('shown.bs.modal', function() { + $(this).find('.selectpicker').selectpicker().focus(); }); + $('#modal-move-modules').on('click', 'button[data-action="confirm"]', () => { + let moveParams = { + to_experiment_id: $('#modal-move-modules').find('.selectpicker').val(), + my_module_ids: ids + }; + $.post(table.data('move-modules-url'), moveParams, (data) => { + HelperModule.flashAlertMsg(data.message, 'success'); + this.loadTable(); + }).error((data) => { + HelperModule.flashAlertMsg(data.responseJSON.message, 'danger'); + }); + $('#modal-move-modules').modal('hide'); + }); + $('#modal-move-modules').modal('show'); }); }, checkActionPermission: function(permission) { @@ -326,7 +351,8 @@ var ExperimnetTable = { $.each($('.table-display-modal .fa-eye-slash'), (_i, column) => { $(column).parent().removeClass('visible'); }); - $('.experiment-table')[0].style.setProperty('--columns-count', $('.table-display-modal .fa-eye').length + 1); + $('.experiment-table')[0].style + .setProperty('--columns-count', $('.table-display-modal .fa-eye:not(.disabled)').length + 1); $('.table-display-modal').on('click', '.column-container .fas', (e) => { let icon = $(e.target); @@ -343,7 +369,8 @@ var ExperimnetTable = { let visibleColumns = $('.table-display-modal .fa-eye').map((_i, col) => col.dataset.column).toArray(); // Update columns on backend - $.post('', { columns: visibleColumns }, () => {}); - $('.experiment-table')[0].style.setProperty('--columns-count', $('.table-display-modal .fa-eye').length + 1); + $('.experiment-table')[0].style + .setProperty('--columns-count', $('.table-display-modal .fa-eye:not(.disabled)').length + 1); }); }, initNewTaskModal: function(table) { diff --git a/app/assets/stylesheets/experiment/table.scss b/app/assets/stylesheets/experiment/table.scss index b0f118302..cddb4d39d 100644 --- a/app/assets/stylesheets/experiment/table.scss +++ b/app/assets/stylesheets/experiment/table.scss @@ -434,6 +434,11 @@ .fas { cursor: pointer; margin-right: 1em; + + &.disabled { + color: $color-alto; + pointer-events: none; + } } &.task_name { diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index d3e1cb57f..45fc7f78a 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -95,7 +95,7 @@ class ExperimentsController < ApplicationController end def load_table - my_modules = @experiment.my_modules + my_modules = @experiment.my_modules.readable_by_user(current_user) my_modules = params[:view_mode] == 'archived' ? my_modules.archived : my_modules.active render json: Experiments::TableViewService.new(my_modules, current_user, params).call end diff --git a/app/views/experiments/_table_display_modal.html.erb b/app/views/experiments/_table_display_modal.html.erb index c3f382ba1..29a7b49c2 100644 --- a/app/views/experiments/_table_display_modal.html.erb +++ b/app/views/experiments/_table_display_modal.html.erb @@ -11,11 +11,14 @@

<%= t("experiments.table.column_display_modal.description") %>

<% Experiments::TableViewService::COLUMNS.each do |col| %>
- <% unless col == :task_name %> + <% if col == :archived && params[:view_mode] != 'archived' %> + + <% elsif col != :task_name %> <% end %> <%= t("experiments.table.column_display_modal.#{col}") %>
+ <% end %> diff --git a/app/views/experiments/_table_row_actions.html.erb b/app/views/experiments/_table_row_actions.html.erb index a06cd58fe..3fe0aca39 100644 --- a/app/views/experiments/_table_row_actions.html.erb +++ b/app/views/experiments/_table_row_actions.html.erb @@ -1,7 +1,7 @@
  • <%= t("experiments.table.my_module_actions.title") %>
  • <% if can_manage_my_module?(my_module) %>
  • - + <%= t("experiments.table.my_module_actions.edit") %> @@ -9,7 +9,7 @@ <% end %> <% if can_manage_experiment?(my_module.experiment) && my_module.active? %>
  • - + <%= t("experiments.table.my_module_actions.duplicate") %> @@ -17,7 +17,7 @@ <% end %> <% if can_move_my_module?(my_module) %>
  • - + <%= t("experiments.table.my_module_actions.move") %>