mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
Merge pull request #1112 from ZmagoD/zd_SCI_2261
propagate assigned repository items in workflow [fixes SCI-2261]
This commit is contained in:
commit
0a4deeaa35
8 changed files with 222 additions and 36 deletions
|
@ -476,19 +476,43 @@ var RepositoryDatatable = (function(global) {
|
|||
});
|
||||
};
|
||||
|
||||
global.onClickAssignRecords = function() {
|
||||
global.openAssignRecordsModal = function() {
|
||||
$.post(
|
||||
$('#assignRepositoryRecords').data('assign-url-modal'),
|
||||
{ selected_rows: rowsSelected })
|
||||
.done(
|
||||
function(data) {
|
||||
$(data.html).appendTo('body').promise().done(function() {
|
||||
$('#assignRepositoryRecordModal').modal('show');
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
global.hideAssignUnasignModal = function(id) {
|
||||
$(id).modal('hide').promise().done(
|
||||
function() {
|
||||
$(id).remove();
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
global.submitAssignRepositoryRecord = function(option) {
|
||||
animateSpinner();
|
||||
$.ajax({
|
||||
url: $('#assignRepositoryRecords').data('assign-url'),
|
||||
url: $('#assignRepositoryRecordModal').data('assign-url'),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { selected_rows: rowsSelected },
|
||||
data: { selected_rows: rowsSelected,
|
||||
downstream: (option === 'downstream') },
|
||||
success: function(data) {
|
||||
hideAssignUnasignModal('#assignRepositoryRecordModal');
|
||||
HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
onClickCancel();
|
||||
clearRowSelection();
|
||||
},
|
||||
error: function(data) {
|
||||
hideAssignUnasignModal('#assignRepositoryRecordModal');
|
||||
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
|
||||
onClickCancel();
|
||||
clearRowSelection();
|
||||
|
@ -496,19 +520,35 @@ var RepositoryDatatable = (function(global) {
|
|||
});
|
||||
}
|
||||
|
||||
global.onClickUnassignRecords = function() {
|
||||
global.openUnassignRecordsModal = function() {
|
||||
$.post(
|
||||
$('#unassignRepositoryRecords').data('unassign-url'),
|
||||
{ selected_rows: rowsSelected })
|
||||
.done(
|
||||
function(data) {
|
||||
$(data.html).appendTo('body').promise().done(function() {
|
||||
$('#unassignRepositoryRecordModal').modal('show');
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
global.submitUnassignRepositoryRecord = function(option) {
|
||||
animateSpinner();
|
||||
$.ajax({
|
||||
url: $('#unassignRepositoryRecords').data('unassign-url'),
|
||||
url: $('#unassignRepositoryRecordModal').data('unassign-url'),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {selected_rows: rowsSelected},
|
||||
data: { selected_rows: rowsSelected,
|
||||
downstream: (option === 'downstream') },
|
||||
success: function(data) {
|
||||
hideAssignUnasignModal('#unassignRepositoryRecordModal');
|
||||
HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
onClickCancel();
|
||||
clearRowSelection();
|
||||
},
|
||||
error: function(data) {
|
||||
hideAssignUnasignModal('#unassignRepositoryRecordModal');
|
||||
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
|
||||
onClickCancel();
|
||||
clearRowSelection();
|
||||
|
|
|
@ -12,10 +12,14 @@ class MyModulesController < ApplicationController
|
|||
assign_samples unassign_samples delete_samples
|
||||
toggle_task_state samples_index archive
|
||||
complete_my_module repository repository_index
|
||||
assign_repository_records unassign_repository_records)
|
||||
assign_repository_records unassign_repository_records
|
||||
unassign_repository_records_modal
|
||||
assign_repository_records_modal)
|
||||
before_action :load_vars_nested, only: %i(new create)
|
||||
before_action :load_repository, only: %i(assign_repository_records
|
||||
unassign_repository_records
|
||||
unassign_repository_records_modal
|
||||
assign_repository_records_modal
|
||||
repository_index)
|
||||
before_action :load_projects_by_teams, only: %i(protocols results activities
|
||||
samples repository archive)
|
||||
|
@ -25,10 +29,13 @@ class MyModulesController < ApplicationController
|
|||
%i(show activities activities_tab protocols results samples samples_index
|
||||
archive)
|
||||
before_action :check_complete_module_permission, only: :complete_my_module
|
||||
before_action :check_assign_repository_records_permissions, only:
|
||||
%i(assign_repository_records unassign_repository_records)
|
||||
before_action :check_assign_samples_permissions, only: %i(assign_samples
|
||||
unassign_samples)
|
||||
before_action :check_assign_repository_records_permissions,
|
||||
only: %i(unassign_repository_records_modal
|
||||
assign_repository_records_modal
|
||||
assign_repository_records
|
||||
unassign_repository_records
|
||||
assign_samples
|
||||
unassign_samples)
|
||||
|
||||
layout 'fluid'.freeze
|
||||
|
||||
|
@ -71,7 +78,7 @@ class MyModulesController < ApplicationController
|
|||
@last_activity_id = params[:from].to_i || 0
|
||||
@per_page = 10
|
||||
|
||||
@activities = @my_module.last_activities(@last_activity_id, @per_page +1 )
|
||||
@activities = @my_module.last_activities(@last_activity_id, @per_page + 1)
|
||||
@more_activities_url = ""
|
||||
|
||||
@overflown = @activities.length > @per_page
|
||||
|
@ -391,18 +398,33 @@ class MyModulesController < ApplicationController
|
|||
def assign_repository_records
|
||||
if params[:selected_rows].present? && params[:repository_id].present?
|
||||
records_names = []
|
||||
downstream = ActiveModel::Type::Boolean.new.cast(params[:downstream])
|
||||
|
||||
params[:selected_rows].each do |id|
|
||||
record = RepositoryRow.find_by_id(id)
|
||||
next if !record || @my_module.repository_rows.include?(record)
|
||||
record.last_modified_by = current_user
|
||||
record.save
|
||||
records_names << record.name
|
||||
MyModuleRepositoryRow.create!(
|
||||
my_module: @my_module,
|
||||
repository_row: record,
|
||||
assigned_by: current_user
|
||||
)
|
||||
RepositoryRow
|
||||
.where(id: params[:selected_rows],
|
||||
repository_id: params[:repository_id])
|
||||
.find_each do |record|
|
||||
unless @my_module.repository_rows.include?(record)
|
||||
record.last_modified_by = current_user
|
||||
record.save
|
||||
|
||||
MyModuleRepositoryRow.create!(
|
||||
my_module: @my_module,
|
||||
repository_row: record,
|
||||
assigned_by: current_user
|
||||
)
|
||||
records_names << record.name
|
||||
end
|
||||
|
||||
next unless downstream
|
||||
@my_module.downstream_modules.each do |my_module|
|
||||
next if my_module.repository_rows.include?(record)
|
||||
MyModuleRepositoryRow.create!(
|
||||
my_module: my_module,
|
||||
repository_row: record,
|
||||
assigned_by: current_user
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
if records_names.any?
|
||||
|
@ -439,17 +461,29 @@ class MyModulesController < ApplicationController
|
|||
|
||||
def unassign_repository_records
|
||||
if params[:selected_rows].present? && params[:repository_id].present?
|
||||
records = []
|
||||
downstream = ActiveModel::Type::Boolean.new.cast(params[:downstream])
|
||||
|
||||
params[:selected_rows].each do |id|
|
||||
record = RepositoryRow.find_by_id(id)
|
||||
next unless record && @my_module.repository_rows.include?(record)
|
||||
record.last_modified_by = current_user
|
||||
record.save
|
||||
records << record
|
||||
end
|
||||
records = RepositoryRow.assigned_on_my_module(params[:selected_rows],
|
||||
@my_module)
|
||||
|
||||
@my_module.repository_rows.destroy(records & @my_module.repository_rows)
|
||||
|
||||
if downstream
|
||||
@my_module.downstream_modules.each do |my_module|
|
||||
assigned_records = RepositoryRow.assigned_on_my_module(
|
||||
params[:selected_rows],
|
||||
my_module
|
||||
)
|
||||
my_module.repository_rows.destroy(
|
||||
assigned_records & my_module.repository_rows
|
||||
)
|
||||
assigned_records.update_all(last_modified_by_id: current_user.id)
|
||||
end
|
||||
end
|
||||
|
||||
# update last last_modified_by
|
||||
records.update_all(last_modified_by_id: current_user.id)
|
||||
|
||||
if records.any?
|
||||
Activity.create(
|
||||
type_of: :unassign_repository_record,
|
||||
|
@ -482,6 +516,28 @@ class MyModulesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def unassign_repository_records_modal
|
||||
selected_rows = params[:selected_rows]
|
||||
modal = render_to_string(
|
||||
partial: 'my_modules/modals/unassign_repository_records_modal.html.erb',
|
||||
locals: { my_module: @my_module,
|
||||
repository: @repository,
|
||||
selected_rows: selected_rows }
|
||||
)
|
||||
render json: { html: modal }, status: :ok
|
||||
end
|
||||
|
||||
def assign_repository_records_modal
|
||||
selected_rows = params[:selected_rows]
|
||||
modal = render_to_string(
|
||||
partial: 'my_modules/modals/assign_repository_records_modal.html.erb',
|
||||
locals: { my_module: @my_module,
|
||||
repository: @repository,
|
||||
selected_rows: selected_rows }
|
||||
)
|
||||
render json: { html: modal }, status: :ok
|
||||
end
|
||||
|
||||
# Complete/uncomplete task
|
||||
def toggle_task_state
|
||||
respond_to do |format|
|
||||
|
|
|
@ -21,4 +21,9 @@ class RepositoryRow < ApplicationRecord
|
|||
presence: true,
|
||||
length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
validates :created_by, presence: true
|
||||
|
||||
def self.assigned_on_my_module(ids, my_module)
|
||||
where(id: ids).joins(:my_module_repository_rows)
|
||||
.where('my_module_repository_rows.my_module' => my_module)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<div id="assignRepositoryRecordModal"
|
||||
class="modal"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
data-dismiss="modal"
|
||||
data-assign-url="<%= assign_repository_records_my_module_path(@my_module)%>">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button"
|
||||
class="close"
|
||||
data-dismiss="modal"
|
||||
aria-label="Close"
|
||||
onclick="hideAssignUnasignModal('#assignRepositoryRecordModal')"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">
|
||||
<%=t 'my_modules.modals.assign_repository_record.title',
|
||||
repository_name: repository.name,
|
||||
my_module_name: my_module.name %>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p><%=t 'my_modules.modals.assign_repository_record.message', size: selected_rows.size %></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-default" data-dismiss="modal" onclick="hideAssignUnasignModal('#assignRepositoryRecordModal')">
|
||||
<%=t 'general.cancel' %>
|
||||
</a>
|
||||
<a class="btn btn-primary" onclick="submitAssignRepositoryRecord()">
|
||||
<%=t 'Module' %>
|
||||
</a>
|
||||
<a class="btn btn-primary" onclick="submitAssignRepositoryRecord('downstream')">
|
||||
<%=t 'my_modules.modals.assign_repository_record.task_and_downstream' %>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,36 @@
|
|||
<div id="unassignRepositoryRecordModal"
|
||||
class="modal"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
data-dismiss="modal"
|
||||
data-unassign-url="<%= unassign_repository_records_my_module_path(@my_module)%>">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button"
|
||||
class="close"
|
||||
data-dismiss="modal"
|
||||
aria-label="Close"
|
||||
onclick="hideAssignUnasignModal('#unassignRepositoryRecordModal')"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">
|
||||
<%=t 'my_modules.modals.assign_repository_record.unassign_title',
|
||||
repository_name: repository.name,
|
||||
my_module_name: my_module.name %>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p><%=t 'my_modules.modals.assign_repository_record.unassign_message', size: selected_rows.size %></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-default" data-dismiss="modal" onclick="hideAssignUnasignModal('#unassignRepositoryRecordModal')">
|
||||
<%=t 'general.cancel' %>
|
||||
</a>
|
||||
<a class="btn btn-primary" onclick="submitUnassignRepositoryRecord()">
|
||||
<%=t 'Module' %>
|
||||
</a>
|
||||
<a class="btn btn-primary" onclick="submitUnassignRepositoryRecord('downstream')">
|
||||
<%=t 'my_modules.modals.assign_repository_record.task_and_downstream' %>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -19,14 +19,14 @@
|
|||
<div class="toolbarButtons" style="display:none">
|
||||
<% if module_page? && can_assign_repository_rows_to_module?(@my_module) %>
|
||||
<button type="button" class="btn btn-default"
|
||||
data-assign-url="<%= assign_repository_records_my_module_path(@my_module, @repository)%>"
|
||||
id="assignRepositoryRecords" onclick="onClickAssignRecords()" disabled>
|
||||
data-assign-url-modal="<%= assign_repository_records_modal_my_module_path(@my_module, @repository) %>"
|
||||
id="assignRepositoryRecords" onclick="openAssignRecordsModal()" disabled>
|
||||
<span class="glyphicon glyphicon-ok-circle"></span>
|
||||
<span class="hidden-xs-custom"><%= t'repositories.assign_records_to_module' %></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default"
|
||||
data-unassign-url="<%= unassign_repository_records_my_module_path(@my_module, @repository)%>"
|
||||
id="unassignRepositoryRecords" onclick="onClickUnassignRecords()" disabled>
|
||||
data-unassign-url="<%= unassign_repository_records_modal_my_module_path(@my_module, @repository)%>"
|
||||
id="unassignRepositoryRecords" onclick="openUnassignRecordsModal()" disabled>
|
||||
<span class="glyphicon glyphicon-ban-circle"></span>
|
||||
<span class="hidden-xs-custom"><%= t'repositories.unassign_records_from_module' %></span>
|
||||
</button>
|
||||
|
|
|
@ -664,7 +664,13 @@ en:
|
|||
repository:
|
||||
head_title: "%{project} | %{module} | Inventory %{repository}"
|
||||
export: 'Export'
|
||||
|
||||
modals:
|
||||
assign_repository_record:
|
||||
title: 'Assign %{repository_name} items to task %{my_module_name}'
|
||||
message: Do you want to assign %{size} items only to this task, or assign them to this task & downstream tasks in the workflow as well?
|
||||
task_and_downstream: 'Task & Downstream'
|
||||
unassign_title: "Unassign %{repository_name} items from task %{my_module_name}"
|
||||
unassign_message: "Do you want to unassign %{size} items only from this task, or unassign them from this task & downstream tasks in the workflow as well?"
|
||||
experiments:
|
||||
new:
|
||||
create: 'New Experiment'
|
||||
|
|
|
@ -329,9 +329,15 @@ Rails.application.routes.draw do
|
|||
post 'repository_index/:repository_id',
|
||||
to: 'my_modules#repository_index',
|
||||
as: :repository_index
|
||||
post 'assign_repository_records_modal/:repository_id',
|
||||
to: 'my_modules#assign_repository_records_modal',
|
||||
as: :assign_repository_records_modal
|
||||
post 'assign_repository_records/:repository_id',
|
||||
to: 'my_modules#assign_repository_records',
|
||||
as: :assign_repository_records
|
||||
post 'unassign_repository_records_modal/:repository_id',
|
||||
to: 'my_modules#unassign_repository_records_modal',
|
||||
as: :unassign_repository_records_modal
|
||||
post 'unassign_repository_records/:repository_id',
|
||||
to: 'my_modules#unassign_repository_records',
|
||||
as: :unassign_repository_records
|
||||
|
|
Loading…
Add table
Reference in a new issue