Merge pull request #4642 from okriuchykhin/ok_SCI_7381

Add task moving action to experiment table view [SCI-7381]
This commit is contained in:
Alex Kriuchykhin 2022-12-01 13:34:16 +01:00 committed by GitHub
commit a84d228e0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 111 additions and 3 deletions

View file

@ -201,6 +201,35 @@ var ExperimnetTable = {
}
});
},
initMoveModulesModal: function () {
let table = $(this.table);
$('#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');
});
});
},
checkActionPermission: function(permission) {
let allMyModules;
@ -371,6 +400,7 @@ var ExperimnetTable = {
this.loadTable();
this.initRenameModal();
this.initAccessModal();
this.initMoveModulesModal();
this.initArchiveMyModules();
this.initManageColumnsModal();
this.initNewTaskModal(this);

View file

@ -280,6 +280,43 @@ class ExperimentsController < ApplicationController
render json: { message: message, path: path }, status: status
end
def move_modules_modal
@experiments = @experiment.project.experiments.active.where.not(id: @experiment)
.managable_by_user(current_user).order(name: :asc)
render json: {
html: render_to_string(
partial: 'move_modules_modal.html.erb'
)
}
end
def move_modules
modules_to_move = {}
dst_experiment = @experiment.project.experiments.find(params[:to_experiment_id])
return render_403 unless can_manage_experiment?(dst_experiment)
@experiment.with_lock do
params[:my_module_ids].each do |id|
my_module = @experiment.my_modules.find(id)
return render_403 unless can_move_my_module?(my_module)
modules_to_move[id] = dst_experiment.id
end
@experiment.move_modules(modules_to_move, current_user)
render json: { message: t('experiments.table.modal_move_modules.success_flash',
experiment: sanitize_input(dst_experiment.name)) }
rescue StandardError => e
Rails.logger.error(e.message)
Rails.logger.error(e.backtrace.join("\n"))
render json: {
message: t('experiments.table.modal_move_modules.error_flash', experiment: sanitize_input(dst_experiment.name))
}, status: :unprocessable_entity
raise ActiveRecord::Rollback
end
rescue ActiveRecord::RecordNotFound
render_404
end
def module_archive
@project = @experiment.project
@my_modules = @experiment.archived_branch? ? @experiment.my_modules : @experiment.my_modules.archived

View file

@ -228,8 +228,6 @@ class Experiment < ApplicationRecord
project
end
private
# Archive all modules. Receives an array of module integer IDs
# and current user.
def archive_modules(module_ids, current_user)
@ -520,6 +518,8 @@ class Experiment < ApplicationRecord
true
end
private
def log_activity(type_of, current_user, my_module)
Activities::CreateActivityService
.call(activity_type: type_of,

View file

@ -0,0 +1,31 @@
<div class="modal fade" id="modal-move-modules" tabindex="-1" role="dialog" aria-labelledby="modal-move-modules-label">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="modal-move-modules-label"><%= t('experiments.table.modal_move_modules.title') %></h4>
</div>
<div class="modal-body">
<% if @experiments.present? %>
<%= bootstrap_form_tag do |f| %>
<%= f.select :experiment_id, @experiments.collect { |e| [ e.name, e.id ] }, {}, class: "form-control selectpicker", 'data-role': 'clear' %>
<% end %>
<% else %>
<div>
<em>
<%= t('experiments.table.modal_move_modules.no_experiments') %>
</em>
</div>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><%= t('general.cancel') %></button>
<% if @experiments.present? %>
<button type="button" class="btn btn-primary" data-action="confirm">
<%= t('experiments.table.modal_move_modules.confirm') %>
</button>
<% end %>
</div>
</div>
</div>
</div>

View file

@ -13,7 +13,9 @@
<div class="experiment-table-container">
<div class="experiment-table"
style="--columns-count: <%= Experiments::TableViewService::COLUMNS.length%>"
data-my-modules-url= <%= load_table_experiment_path(@experiment, view_mode: params[:view_mode]) %>
data-my-modules-url="<%= load_table_experiment_path(@experiment, view_mode: params[:view_mode]) %>"
data-move-modules-modal-url="<%= move_modules_modal_experiment_path(@experiment) %>"
data-move-modules-url="<%= move_modules_experiment_path(@experiment) %>"
>
<div class="table-header">
<div class="table-header-cell select-all-checkboxes">

View file

@ -1305,6 +1305,12 @@ en:
assigned_html: 'Assigned to'
tags_html: 'Tags'
comments_html: '<i class="fas fa-comment"></i>'
modal_move_modules:
title: "Move task(s) to experiment"
confirm: "Move"
no_experiments: "No experiments to move this task to."
success_flash: "Successfully moved task(s) to experiment %{experiment}."
error_flash: "Failed to move task(s) to experiment %{experiment}."
column_display_modal:
title: 'Task data display'
description: 'Click the eye buttons to hide or show columns in the table'

View file

@ -357,6 +357,8 @@ Rails.application.routes.draw do
get 'actions_dropdown'
get :table
get :load_table
get :move_modules_modal
post :move_modules
get 'canvas' # Overview/structure for single experiment
# AJAX-loaded canvas edit mode (from canvas)
get 'canvas/edit', to: 'canvas#edit'