From aa4b765407a0724299a8d32fd68c41af35e7b09f Mon Sep 17 00:00:00 2001 From: aignatov-bio <47317017+aignatov-bio@users.noreply.github.com> Date: Tue, 26 Oct 2021 11:41:08 +0200 Subject: [PATCH] Update assign/unassign rows to task [SCI-6150] (#3604) Co-authored-by: Anton --- .../javascripts/my_modules/repositories.js | 29 ++++++--- .../stylesheets/my_modules/repositories.scss | 30 ++++++++++ .../my_module_repositories_controller.rb | 6 +- .../my_module_assign_unassign_service.rb | 2 + ..._repository_records_modal_content.html.erb | 57 ++++++++++++++---- ..._repository_records_modal_content.html.erb | 59 +++++++++++++++---- .../repositories/_full_view_modal.html.erb | 16 ++++- config/locales/en.yml | 12 +++- 8 files changed, 176 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/my_modules/repositories.js b/app/assets/javascripts/my_modules/repositories.js index e6e8571da..9064429a7 100644 --- a/app/assets/javascripts/my_modules/repositories.js +++ b/app/assets/javascripts/my_modules/repositories.js @@ -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'); diff --git a/app/assets/stylesheets/my_modules/repositories.scss b/app/assets/stylesheets/my_modules/repositories.scss index 2da93a946..1d6dedd5a 100644 --- a/app/assets/stylesheets/my_modules/repositories.scss +++ b/app/assets/stylesheets/my_modules/repositories.scss @@ -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; + } + } } diff --git a/app/controllers/my_module_repositories_controller.rb b/app/controllers/my_module_repositories_controller.rb index c5d0bdc08..abd40cf73 100644 --- a/app/controllers/my_module_repositories_controller.rb +++ b/app/controllers/my_module_repositories_controller.rb @@ -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, diff --git a/app/services/repository_rows/my_module_assign_unassign_service.rb b/app/services/repository_rows/my_module_assign_unassign_service.rb index cf1e210e3..f4dc8eb37 100644 --- a/app/services/repository_rows/my_module_assign_unassign_service.rb +++ b/app/services/repository_rows/my_module_assign_unassign_service.rb @@ -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 diff --git a/app/views/my_modules/modals/_assign_repository_records_modal_content.html.erb b/app/views/my_modules/modals/_assign_repository_records_modal_content.html.erb index 6596c9d06..091d824f4 100644 --- a/app/views/my_modules/modals/_assign_repository_records_modal_content.html.erb +++ b/app/views/my_modules/modals/_assign_repository_records_modal_content.html.erb @@ -3,23 +3,60 @@ diff --git a/app/views/my_modules/modals/_update_repository_records_modal_content.html.erb b/app/views/my_modules/modals/_update_repository_records_modal_content.html.erb index f7782db8d..8764cf698 100644 --- a/app/views/my_modules/modals/_update_repository_records_modal_content.html.erb +++ b/app/views/my_modules/modals/_update_repository_records_modal_content.html.erb @@ -7,13 +7,23 @@ diff --git a/app/views/my_modules/repositories/_full_view_modal.html.erb b/app/views/my_modules/repositories/_full_view_modal.html.erb index fb21aa9e6..99992a192 100644 --- a/app/views/my_modules/repositories/_full_view_modal.html.erb +++ b/app/views/my_modules/repositories/_full_view_modal.html.erb @@ -40,13 +40,25 @@ + + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index ab594afe3..d846fbbf9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 can’t assign to." task: 'Assign to task' task_and_downstream: 'Assign to task & downstream' modules_list_partial: