mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 03:46:39 +08:00
"Move" feature for multiple selected tasks and experiments (bulk action)
This commit is contained in:
parent
0343188c9d
commit
cc8a10edb0
5 changed files with 43 additions and 38 deletions
|
@ -10,17 +10,17 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
before_action :load_project, only: %i(new create archive_group restore_group)
|
before_action :load_project, only: %i(new create archive_group restore_group)
|
||||||
before_action :load_experiment, except: %i(new create archive_group restore_group
|
before_action :load_experiment, except: %i(new create archive_group restore_group
|
||||||
inventory_assigning_experiment_filter actions_toolbar)
|
inventory_assigning_experiment_filter actions_toolbar move_modal move)
|
||||||
|
before_action :load_experiments, only: %i(move_modal move)
|
||||||
before_action :check_read_permissions, except: %i(edit archive clone move new
|
before_action :check_read_permissions, except: %i(edit archive clone move new
|
||||||
create archive_group restore_group
|
create archive_group restore_group
|
||||||
inventory_assigning_experiment_filter actions_toolbar)
|
inventory_assigning_experiment_filter actions_toolbar move_modal)
|
||||||
before_action :check_canvas_read_permissions, only: %i(canvas)
|
before_action :check_canvas_read_permissions, only: %i(canvas)
|
||||||
before_action :check_create_permissions, only: %i(new create)
|
before_action :check_create_permissions, only: %i(new create)
|
||||||
before_action :check_manage_permissions, only: %i(edit batch_clone_my_modules)
|
before_action :check_manage_permissions, only: %i(edit batch_clone_my_modules)
|
||||||
before_action :check_update_permissions, only: %i(update)
|
before_action :check_update_permissions, only: %i(update)
|
||||||
before_action :check_archive_permissions, only: :archive
|
before_action :check_archive_permissions, only: :archive
|
||||||
before_action :check_clone_permissions, only: %i(clone_modal clone)
|
before_action :check_clone_permissions, only: %i(clone_modal clone)
|
||||||
before_action :check_move_permissions, only: %i(move_modal move)
|
|
||||||
before_action :set_inline_name_editing, only: %i(canvas table module_archive)
|
before_action :set_inline_name_editing, only: %i(canvas table module_archive)
|
||||||
before_action :set_breadcrumbs_items, only: %i(canvas table module_archive)
|
before_action :set_breadcrumbs_items, only: %i(canvas table module_archive)
|
||||||
before_action :set_navigator, only: %i(canvas module_archive table)
|
before_action :set_navigator, only: %i(canvas module_archive table)
|
||||||
|
@ -274,7 +274,7 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
# GET: move_modal_experiment_path(id)
|
# GET: move_modal_experiment_path(id)
|
||||||
def move_modal
|
def move_modal
|
||||||
@projects = @experiment.movable_projects(current_user)
|
@projects = @experiments.first.movable_projects(current_user)
|
||||||
render json: {
|
render json: {
|
||||||
html: render_to_string(partial: 'move_modal', formats: :html)
|
html: render_to_string(partial: 'move_modal', formats: :html)
|
||||||
}
|
}
|
||||||
|
@ -297,15 +297,18 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
# POST: move_experiment(id)
|
# POST: move_experiment(id)
|
||||||
def move
|
def move
|
||||||
|
move_responses = []
|
||||||
|
|
||||||
|
@experiments.each do |experiment|
|
||||||
|
@experiment = experiment
|
||||||
service = Experiments::MoveToProjectService
|
service = Experiments::MoveToProjectService
|
||||||
.call(experiment_id: @experiment.id,
|
.call(experiment_id: experiment.id,
|
||||||
project_id: move_experiment_param,
|
project_id: params[:project_id],
|
||||||
user_id: current_user.id)
|
user_id: current_user.id)
|
||||||
if service.succeed?
|
if service.succeed?
|
||||||
flash[:success] = t('experiments.move.success_flash',
|
flash[:success] = t('experiments.move.success_flash', experiment: experiment.name)
|
||||||
experiment: @experiment.name)
|
|
||||||
status = :ok
|
status = :ok
|
||||||
view_state = @experiment.current_view_state(current_user)
|
view_state = experiment.current_view_state(current_user)
|
||||||
view_type = view_state.state['my_modules']['view_type'] || 'canvas'
|
view_type = view_state.state['my_modules']['view_type'] || 'canvas'
|
||||||
path = view_mode_redirect_url(view_type)
|
path = view_mode_redirect_url(view_type)
|
||||||
else
|
else
|
||||||
|
@ -313,7 +316,9 @@ class ExperimentsController < ApplicationController
|
||||||
status = :unprocessable_entity
|
status = :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: { message: message, path: path }, status: status
|
move_responses << {message: message, path: path, status: status }
|
||||||
|
end
|
||||||
|
render json: move_responses
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_modules_modal
|
def move_modules_modal
|
||||||
|
@ -531,6 +536,11 @@ class ExperimentsController < ApplicationController
|
||||||
render_404 unless @experiment
|
render_404 unless @experiment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_experiments
|
||||||
|
@experiments = Experiment.preload(user_assignments: %i(user user_role)).where(id: params[:ids])
|
||||||
|
render_404 unless @experiments
|
||||||
|
end
|
||||||
|
|
||||||
def load_project
|
def load_project
|
||||||
@project = Project.find_by(id: params[:project_id])
|
@project = Project.find_by(id: params[:project_id])
|
||||||
render_404 unless @project
|
render_404 unless @project
|
||||||
|
|
|
@ -87,18 +87,14 @@ module Toolbars
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_action
|
def move_action
|
||||||
return unless @single
|
return unless @experiments.all? { |experiment| can_move_experiment?(experiment) }
|
||||||
|
|
||||||
experiment = @experiments.first
|
|
||||||
|
|
||||||
return unless can_move_experiment?(experiment)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'move',
|
name: 'move',
|
||||||
label: I18n.t('experiments.toolbar.move_button'),
|
label: I18n.t('experiments.toolbar.move_button'),
|
||||||
icon: 'sn-icon sn-icon-move',
|
icon: 'sn-icon sn-icon-move',
|
||||||
button_class: 'move-experiments-btn',
|
button_class: 'move-experiments-btn',
|
||||||
path: move_modal_experiments_path(id: experiment.id),
|
path: move_modal_experiments_path(ids: @experiments.map(&:id)),
|
||||||
type: 'remote-modal'
|
type: 'remote-modal'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,11 +88,7 @@ module Toolbars
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_action
|
def move_action
|
||||||
return unless @single
|
return unless @my_modules.all? { |my_module| can_move_my_module?(my_module) }
|
||||||
|
|
||||||
my_module = @my_modules.first
|
|
||||||
|
|
||||||
return unless can_move_my_module?(my_module)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'move',
|
name: 'move',
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<div class="modal move-experiment-modal"
|
<div class="modal move-experiment-modal"
|
||||||
id="move-experiment-modal-<%= @experiment.id %>"
|
id="move-experiment-modal-<%= @experiments.map(&:id) %>"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
role="dialog"
|
role="dialog"
|
||||||
aria-labelledby="move-experiment-modal-label">
|
aria-labelledby="move-experiment-modal-label">
|
||||||
<%= form_with model: @experiment,
|
<%= form_with model: @experiment,
|
||||||
url: move_experiment_path(@experiment),
|
url: move_experiment_path(id: @experiments.map(&:id)),
|
||||||
method: :post,
|
method: :post,
|
||||||
data: { remote: true },
|
data: { remote: true },
|
||||||
html: { class: 'experiment-action-form' } do |f| %>
|
html: { class: 'experiment-action-form' } do |f| %>
|
||||||
|
@ -12,11 +12,11 @@
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
||||||
<h4 class="modal-title" id="move-experiment-modal-label"><%= t("experiments.move.modal_title", experiment: @experiment.name ) %></h5>
|
<h4 class="modal-title" id="move-experiment-modal-label"><%= t("experiments.move.modal_title") %></h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p><small><%= t("experiments.move.notice") %></small></p>
|
<p><small><%= t("experiments.move.notice") %></small></p>
|
||||||
<% if @projects.any? && can_manage_all_experiment_my_modules?(@experiment) %>
|
<% if @projects.any? && @experiments.all? { |experiment| can_manage_all_experiment_my_modules?(experiment) } %>
|
||||||
<%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] }),
|
<%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] }),
|
||||||
{ label: t("experiments.move.target_project") }, { class: "form-control selectpicker", "data-role" => "clear" } %>
|
{ label: t("experiments.move.target_project") }, { class: "form-control selectpicker", "data-role" => "clear" } %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
@ -24,15 +24,18 @@
|
||||||
<i class="fas fa-exclamation-triangle"></i>
|
<i class="fas fa-exclamation-triangle"></i>
|
||||||
<% if @projects.blank? %>
|
<% if @projects.blank? %>
|
||||||
<%= t("experiments.move.no_projects") %>
|
<%= t("experiments.move.no_projects") %>
|
||||||
<% elsif !can_manage_all_experiment_my_modules?(@experiment) %>
|
<% elsif !@experiments.all? { |experiment| can_manage_all_experiment_my_modules?(experiment) } %>
|
||||||
<%= t("experiments.move.task_permission") %>
|
<%= t("experiments.move.task_permission") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<% @experiments.each do |experiment| %>
|
||||||
|
<%= f.hidden_field :ids, multiple: true, value: experiment.id %>
|
||||||
|
<% end %>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal"><%=t "general.cancel" %></button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal"><%=t "general.cancel" %></button>
|
||||||
<% if @projects.any? && can_manage_all_experiment_my_modules?(@experiment) %>
|
<% if @projects.any? && @experiments.all? { |experiment| can_manage_all_experiment_my_modules?(experiment) } %>
|
||||||
<%= f.submit t("experiments.move.modal_submit"), class: "btn btn-primary" %>
|
<%= f.submit t("experiments.move.modal_submit"), class: "btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1515,7 +1515,7 @@ en:
|
||||||
success: 'Successfully duplicated %{count} task(s) as template.'
|
success: 'Successfully duplicated %{count} task(s) as template.'
|
||||||
duplicating: 'Duplicating contents...'
|
duplicating: 'Duplicating contents...'
|
||||||
move:
|
move:
|
||||||
modal_title: 'Move experiment %{experiment}'
|
modal_title: 'Move experiment(s)'
|
||||||
notice: 'Moving is possible to projects, where you have permissions to create experiments and tasks.'
|
notice: 'Moving is possible to projects, where you have permissions to create experiments and tasks.'
|
||||||
target_project: 'Target project'
|
target_project: 'Target project'
|
||||||
label_title: 'Move'
|
label_title: 'Move'
|
||||||
|
|
Loading…
Add table
Reference in a new issue