diff --git a/app/assets/javascripts/my_modules/status_flow.js b/app/assets/javascripts/my_modules/status_flow.js index 4ade3086f..ca0edfdd2 100644 --- a/app/assets/javascripts/my_modules/status_flow.js +++ b/app/assets/javascripts/my_modules/status_flow.js @@ -1,18 +1,20 @@ -/* global animateSpinner */ +/* global animateSpinner $ GLOBAL_CONSTANTS */ (function() { - $('.task-sharing-and-flows').on('click', '#viewTaskFlow', function() { - $('#statusFlowModal').off('shown.bs.modal').on('shown.bs.modal', function() { - var $modalBody = $(this).find('.modal-body'); - animateSpinner($modalBody); - $.get($(this).data('status-flow-url'), function(result) { - animateSpinner($modalBody, false); - $modalBody.html(result.html); + function initStatusFlowModal() { + $('.task-sharing-and-flows').on('click', '#viewTaskFlow', function() { + $('#statusFlowModal').off('shown.bs.modal').on('shown.bs.modal', function() { + var $modalBody = $(this).find('.modal-body'); + animateSpinner($modalBody); + $.get($(this).data('status-flow-url'), function(result) { + animateSpinner($modalBody, false); + $modalBody.html(result.html); + }); }); - }); - $('#statusFlowModal').modal('show'); - }); + $('#statusFlowModal').modal('show'); + }); + } function checkStatusState() { $.getJSON($('.status-flow-dropdown').data('status-check-url'), (statusData) => { @@ -60,5 +62,25 @@ }); } - applyTaskStatusChangeCallBack(); + function checkCurrentStatus() { + $.get($('#status-container').data('current-status-url'), (statusData) => { + if ($('#status-container').data('current-status-id') !== statusData.my_module_status_id) { + $.get($('#status-container').data('status-partial-url'), (partialData) => { + $('#status-container').data('current-status-id', statusData.my_module_status_id); + $('#status-container').html(partialData.html); + initStatus(); + }); + } else { + setTimeout(() => { checkCurrentStatus(); }, GLOBAL_CONSTANTS.SLOW_STATUS_POLLING_INTERVAL); + } + }); + } + + function initStatus() { + initStatusFlowModal(); + checkCurrentStatus(); + applyTaskStatusChangeCallBack(); + } + + initStatus(); }()); diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index e8f153065..b73a8e161 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -118,6 +118,16 @@ class MyModulesController < ApplicationController current_user.save! end + def current_status + render json: { my_module_status_id: @my_module.my_module_status_id } + end + + def status_partial + render json: { + html: render_to_string(partial: 'my_modules/status_flow/task_flow_button', locals: { my_module: @my_module }) + } + end + def status_state if @my_module.last_transition_error && @my_module.last_transition_error['type'] == 'repository_snapshot' flash[:repository_snapshot_error] = @my_module.last_transition_error diff --git a/app/views/my_modules/_task_flow_and_sharing.html.erb b/app/views/my_modules/_task_flow_and_sharing.html.erb index 8ebfc60ac..89f2de039 100644 --- a/app/views/my_modules/_task_flow_and_sharing.html.erb +++ b/app/views/my_modules/_task_flow_and_sharing.html.erb @@ -1,13 +1,17 @@
- <%= render partial: 'my_modules/status_flow/task_flow_button', locals: { my_module: @my_module } if @my_module.my_module_status_flow %> - <%= javascript_include_tag("my_modules/status_flow") %> -
- + <% if @my_module.my_module_status_flow %> +
+ <%= render partial: 'my_modules/status_flow/task_flow_button', locals: { my_module: @my_module } %>
+ <% end %> + <%= javascript_include_tag("my_modules/status_flow") %> +
+ +
- <%= javascript_include_tag 'vue_share_task_container' %> + <%= javascript_include_tag 'vue_share_task_container' %>
diff --git a/app/views/my_modules/status_flow/_task_flow_button.html.erb b/app/views/my_modules/status_flow/_task_flow_button.html.erb index 4da7142bd..ea532bcb6 100644 --- a/app/views/my_modules/status_flow/_task_flow_button.html.erb +++ b/app/views/my_modules/status_flow/_task_flow_button.html.erb @@ -91,4 +91,3 @@
- diff --git a/config/locales/en.yml b/config/locales/en.yml index 2b8c20275..7c5d5c7f7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4342,7 +4342,7 @@ en: project_status_in_progress: 'Automatically update project status to "In progress" when:' project_status_done: 'Automatically update project status to "Done" when:' sub_group_element: - on_protocol_content_change: 'Protocol content is added (including step comments)' + on_protocol_content_change: 'Protocol content is added or modified (including step comments)' on_step_completion: 'At least one step is marked as completed' on_result_created_or_changed: 'Task result is added or modified (including result comments)' on_task_in_progress: 'At least one task moves from "Not started" to "In progress" or other status' diff --git a/config/routes.rb b/config/routes.rb index 22a759c13..e57b0a0ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -521,6 +521,8 @@ Rails.application.routes.draw do post :change_results_state post :favorite post :unfavorite + get :current_status + get :status_partial end resources :my_module_tags, path: '/tags', only: [:index, :create, :destroy] do collection do