Update assign/unassign rows to task [SCI-6150] (#3604)

Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
aignatov-bio 2021-10-26 11:41:08 +02:00 committed by GitHub
parent edb09dd099
commit aa4b765407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 176 additions and 35 deletions

View file

@ -500,9 +500,9 @@ var MyModuleRepositories = (function() {
$(row).toggleClass('selected');
if (Object.keys(SELECTED_ROWS).length) {
$('#assignRepositoryRecords, #updateRepositoryRecords').attr('disabled', false);
$('.assign-button').attr('disabled', false);
} else {
$('#assignRepositoryRecords, #updateRepositoryRecords').attr('disabled', true);
$('.assign-button').attr('disabled', true);
}
refreshSelectAllCheckbox();
@ -513,8 +513,10 @@ var MyModuleRepositories = (function() {
toolbar.empty();
if (parseInt(FULL_VIEW_MODAL.data('rows-count'), 10) === 0) {
toolbar.append($('#my-module-repository-full-view-assign-button').html());
toolbar.append($('#my-module-repository-full-view-assign-downstream-button').html());
} else {
toolbar.append($('#my-module-repository-full-view-update-button').html());
toolbar.append($('#my-module-repository-full-view-update-downstream-button').html());
}
}
@ -570,9 +572,15 @@ var MyModuleRepositories = (function() {
e.stopPropagation();
}).on('click', '#assignRepositoryRecords', function() {
openAssignRecordsModal();
}).on('click', '#updateRepositoryRecords', function() {
openUpdateRecordsModal();
});
}).on('click', '#assignRepositoryRecordsDownstream', function() {
openAssignRecordsModal(true);
})
.on('click', '#updateRepositoryRecords', function() {
openUpdateRecordsModal();
})
.on('click', '#updateRepositoryRecordsDownstream', function() {
openUpdateRecordsModal(true);
});
UPDATE_REPOSITORY_MODAL.on('click', '.downstream-action', function() {
submitUpdateRepositoryRecord({ downstream: true });
@ -580,12 +588,15 @@ var MyModuleRepositories = (function() {
submitUpdateRepositoryRecord({ downstream: false });
}).on('hidden.bs.modal', function() {
FULL_VIEW_MODAL.focus();
}).on('click', '.next-step', function() {
UPDATE_REPOSITORY_MODAL.find('.next-step, .description-1, .rows-list-container').addClass('hidden');
UPDATE_REPOSITORY_MODAL.find('.description-2, .my-modules-to-assign, .hidden-my-modules, .downstream-action').removeClass('hidden');
});
}
function openUpdateRecordsModal() {
function openUpdateRecordsModal(downstream) {
var updateUrl = FULL_VIEW_MODAL.data('update-url-modal');
$.get(updateUrl, { selected_rows: SELECTED_ROWS }, function(data) {
$.get(updateUrl, { selected_rows: SELECTED_ROWS, downstream: downstream }, function(data) {
var assignList;
var assignListScrollbar;
var unassignList;
@ -602,9 +613,9 @@ var MyModuleRepositories = (function() {
});
}
function openAssignRecordsModal() {
function openAssignRecordsModal(downstream) {
var assignUrl = FULL_VIEW_MODAL.data('assign-url-modal');
$.get(assignUrl, { selected_rows: SELECTED_ROWS }, function(data) {
$.get(assignUrl, { selected_rows: SELECTED_ROWS, downstream: downstream }, function(data) {
UPDATE_REPOSITORY_MODAL.find('.modal-content').html(data.html);
UPDATE_REPOSITORY_MODAL.data('update-url', data.update_url);
UPDATE_REPOSITORY_MODAL.modal('show');

View file

@ -459,6 +459,36 @@
}
}
.my-modules-to-assign {
@include font-button;
background: $color-concrete;
border-radius: $border-radius-default;
padding: 1em;
.my-module-to-assign {
margin-bottom: .5em;
}
.current-task {
@include font-small;
background: $brand-primary-light;
border-radius: $border-radius-tag;
color: $color-white;
padding: .25em;
}
}
.hidden-my-modules {
background: $brand-warning-light;
border-radius: $border-radius-default;
margin-top: .5em;
padding: .5em;
.fas {
color: $brand-warning;
}
}
}

View file

@ -67,7 +67,8 @@ class MyModuleRepositoriesController < ApplicationController
partial: 'my_modules/modals/update_repository_records_modal_content.html.erb',
locals: { my_module: @my_module,
repository: @repository,
selected_rows: params[:selected_rows] }
selected_rows: params[:selected_rows],
downstream: params[:downstream] }
)
render json: {
html: modal,
@ -80,7 +81,8 @@ class MyModuleRepositoriesController < ApplicationController
partial: 'my_modules/modals/assign_repository_records_modal_content.html.erb',
locals: { my_module: @my_module,
repository: @repository,
selected_rows: params[:selected_rows] }
selected_rows: params[:selected_rows],
downstream: params[:downstream] }
)
render json: {
html: modal,

View file

@ -2,6 +2,7 @@
module RepositoryRows
class MyModuleAssignUnassignService
include Canaid::Helpers::PermissionsHelper
extend Service
attr_reader :repository,
@ -28,6 +29,7 @@ module RepositoryRows
ActiveRecord::Base.transaction do
if params[:downstream] == 'true'
@my_module.downstream_modules.each do |downstream_module|
next unless can_assign_my_module_repository_rows?(@user, downstream_module)
unassign_repository_rows_from_my_module(downstream_module)
assign_repository_rows_to_my_module(downstream_module)
end

View file

@ -3,23 +3,60 @@
<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) %>
<% if downstream %>
<%= t('my_modules.modals.assign_repository_record.title_downstream',
repository_name: repository.name) %>
<% else %>
<%= t('my_modules.modals.assign_repository_record.title',
repository_name: repository.name,
my_module_name: my_module.name) %>
<% end %>
</h4>
</div>
<div class="modal-body">
<p><%= t('my_modules.modals.assign_repository_record.message', size: selected_rows.values.count) %></p>
<p>
<% if downstream %>
<%= t('my_modules.modals.assign_repository_record.message_downstream', size: selected_rows.values.count) %>
<% else %>
<%= t('my_modules.modals.assign_repository_record.message', size: selected_rows.values.count) %>
<% end %>
</p>
<% if downstream %>
<div class='my-modules-to-assign'>
<% visible_modules = 0
downstream_modules = my_module.downstream_modules
downstream_modules.each do |m| %>
<% if can_assign_my_module_repository_rows?(m) %>
<div class='my-module-to-assign'>
<% if m == my_module %>
<span class="current-task"><%= t('my_modules.modals.assign_repository_record.current_task') %></span>
<% end %>
<%= m.name %>
</div>
<% visible_modules += 1 %>
<% end %>
<% end %>
</div>
<% if visible_modules != downstream_modules.size %>
<div class="hidden-my-modules">
<i class="fas fa-exclamation-triangle"></i>
<%= t('my_modules.modals.assign_repository_record.hidden_tasks', size: (downstream_modules.size - visible_modules)) %>
</div>
<% end %>
<% end %>
</div>
<div class="modal-footer">
<a class="btn btn-light" data-dismiss="modal">
<i class="fas fa-times"></i>
<%= t('general.cancel') %>
</a>
<a class="btn btn-secondary downstream-action">
<%= t('my_modules.modals.assign_repository_record.task_and_downstream') %>
</a>
<a class="btn btn-primary task-action">
<%= t('my_modules.modals.assign_repository_record.task') %>
</a>
<% if downstream %>
<a class="btn btn-primary downstream-action">
<%= t('my_modules.modals.assign_repository_record.task_and_downstream') %>
</a>
<% else %>
<a class="btn btn-primary task-action">
<%= t('my_modules.modals.assign_repository_record.task') %>
</a>
<% end %>
</div>

View file

@ -7,13 +7,23 @@
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">
<%= t('my_modules.modals.update_repository_record.title',
repository_name: repository.name,
my_module_name: my_module.name) %>
<% if downstream %>
<%= t('my_modules.modals.update_repository_record.title_downstream',
repository_name: repository.name) %>
<% else %>
<%= t('my_modules.modals.update_repository_record.title',
repository_name: repository.name,
my_module_name: my_module.name) %>
<% end %>
</h4>
</div>
<div class="modal-body">
<p><%= t('my_modules.modals.update_repository_record.message', size: selected_rows.values.count) %></p>
<% if downstream %>
<p class="description-1"><%= t('my_modules.modals.update_repository_record.message_downstream_1', size: selected_rows.values.count) %></p>
<p class="description-2 hidden"><%= t('my_modules.modals.update_repository_record.message_downstream_2') %></p>
<% else %>
<p class="description"><%= t('my_modules.modals.update_repository_record.message', size: selected_rows.values.count) %></p>
<% end %>
<div class="rows-list-container">
<% if rows_to_assign.values.any? %>
<div class="rows-to-assign">
@ -42,16 +52,45 @@
</div>
<% end %>
</div>
<% if downstream %>
<div class='my-modules-to-assign hidden'>
<% visible_modules = 0
downstream_modules = my_module.downstream_modules
downstream_modules.each do |m| %>
<% if can_assign_my_module_repository_rows?(m) %>
<div class='my-module-to-assign'>
<% if m == my_module %>
<span class="current-task"><%= t('my_modules.modals.assign_repository_record.current_task') %></span>
<% end %>
<%= m.name %>
</div>
<% visible_modules += 1 %>
<% end %>
<% end %>
</div>
<% if visible_modules != downstream_modules.size %>
<div class="hidden-my-modules hidden">
<i class="fas fa-exclamation-triangle"></i>
<%= t('my_modules.modals.assign_repository_record.hidden_tasks', size: (downstream_modules.size - visible_modules)) %>
</div>
<% end %>
<% end %>
</div>
<div class="modal-footer">
<a class="btn btn-light" data-dismiss="modal">
<i class="fas fa-times"></i>
<%= t('general.cancel') %>
</a>
<a class="btn btn-secondary downstream-action" >
<%= t('my_modules.modals.update_repository_record.task_and_downstream') %>
</a>
<a class="btn btn-primary task-action">
<%= t('my_modules.modals.update_repository_record.task') %>
</a>
<% if downstream %>
<a class="btn btn-primary next-step" >
<%= t('my_modules.modals.update_repository_record.next') %>
</a>
<a class="btn btn-primary downstream-action hidden" >
<%= t('my_modules.modals.update_repository_record.task_and_downstream') %>
</a>
<% else %>
<a class="btn btn-primary task-action">
<%= t('my_modules.modals.update_repository_record.task') %>
</a>
<% end %>
</div>

View file

@ -40,13 +40,25 @@
</div>
<template id="my-module-repository-full-view-assign-button">
<button type="button" class="btn btn-primary" id="assignRepositoryRecords" disabled>
<button type="button" class="btn btn-primary assign-button" id="assignRepositoryRecords" disabled>
<%= t('repositories.assign_records_to_module') %>
</button>
</template>
<template id="my-module-repository-full-view-assign-downstream-button">
<button type="button" class="btn btn-secondary assign-button" id="assignRepositoryRecordsDownstream" disabled>
<%= t('my_modules.modals.assign_repository_record.task_and_downstream') %>
</button>
</template>
<template id="my-module-repository-full-view-update-button">
<button type="button" class="btn btn-primary" id="updateRepositoryRecords" disabled>
<button type="button" class="btn btn-primary assign-button" id="updateRepositoryRecords" disabled>
<%= t('general.update') %>
</button>
</template>
<template id="my-module-repository-full-view-update-downstream-button">
<button type="button" class="btn btn-secondary assign-button" id="updateRepositoryRecordsDownstream" disabled>
Update task & downstream
</button>
</template>

View file

@ -997,14 +997,22 @@ en:
done: "Done"
update_repository_record:
title: "Update %{repository_name} items to %{my_module_name} task"
message: "Do you want to update %{size} items only from this task, or update them from this task & downstream tasks in the workflow also?"
title_downstream: "Update %{repository_name} items to task and downstream"
message: "Do you want to update %{size} items for this task?"
message_downstream_1: "These %{size} items will be updated on this taks and downstream tasks."
message_downstream_2: "The items will be updated in the following tasks. Ready to update them?"
next: "Next"
task: 'Update task'
task_and_downstream: 'Update task & downstream'
newly_assigned_items: "Items newly assigned"
items_will_be_removed: "Items that will be removed"
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?
title_downstream: 'Assign %{repository_name} items to task and downstream'
message: You will assign %{size} items to this task only are you ready to assign them?
message_downstream: You will assign %{size} items to the following tasks. Are you ready to assign them?
current_task: "Current task"
hidden_tasks: "No permission: There are %{size} tasks you cant assign to."
task: 'Assign to task'
task_and_downstream: 'Assign to task & downstream'
modules_list_partial: