Merge pull request #4676 from aignatov-bio/ai-sci-7525-experiment-table-connect-actions-to-context-menu

Experiment table connect task action in dropdown [SCI-7525]
This commit is contained in:
aignatov-bio 2022-12-02 13:36:01 +01:00 committed by GitHub
commit cd0af24a24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 42 deletions

View file

@ -114,14 +114,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() {
@ -145,23 +165,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');
},
@ -254,33 +276,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) {
@ -364,7 +389,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);
@ -381,7 +407,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) {

View file

@ -487,6 +487,11 @@
.fas {
cursor: pointer;
margin-right: 1em;
&.disabled {
color: $color-alto;
pointer-events: none;
}
}
&.task_name {

View file

@ -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

View file

@ -11,11 +11,14 @@
<p><%= t("experiments.table.column_display_modal.description") %></p>
<% Experiments::TableViewService::COLUMNS.each do |col| %>
<div class="column-container <%= col %> visible">
<% unless col == :task_name %>
<% if col == :archived && params[:view_mode] != 'archived' %>
<i class="fas fa-eye disabled" data-column="<%= col %>"></i>
<% elsif col != :task_name %>
<i class="fas fa-eye" data-column="<%= col %>"></i>
<% end %>
<%= t("experiments.table.column_display_modal.#{col}") %>
</div>
<% end %>
</div>
</div>

View file

@ -1,7 +1,7 @@
<li class="divider-label"><%= t("experiments.table.my_module_actions.title") %></li>
<% if can_manage_my_module?(my_module) %>
<li>
<a href="" class="edit-my-module">
<a href="" class="edit-my-module" data-id="<%= my_module.id %>">
<i class="fas fa-pen"></i>
<%= t("experiments.table.my_module_actions.edit") %>
</a>
@ -9,7 +9,7 @@
<% end %>
<% if can_manage_experiment?(my_module.experiment) && my_module.active? %>
<li>
<a href="" class="duplicate-my-module">
<a href="" class="duplicate-my-module" data-id="<%= my_module.id %>">
<i class="fas fa-copy"></i>
<%= t("experiments.table.my_module_actions.duplicate") %>
</a>
@ -17,7 +17,7 @@
<% end %>
<% if can_move_my_module?(my_module) %>
<li>
<a href="" class="move-my-module">
<a href="" class="move-my-module" data-id="<%= my_module.id %>">
<i class="fas fa-arrow-right"></i>
<%= t("experiments.table.my_module_actions.move") %>
</a>