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 @@