Add automatic my module status refresh [SCI-12316]

This commit is contained in:
Anton 2025-09-11 14:29:27 +02:00
parent 90d746679b
commit e654c61fc3
6 changed files with 60 additions and 23 deletions

View file

@ -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();
}());

View file

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

View file

@ -1,13 +1,17 @@
<div class="task-sharing-and-flows flex items-center gap-2 pl-3">
<%= 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") %>
<div id="share-task-container" data-behaviour="vue">
<share-task-container
shareable-link-url="<%= my_module_shareable_link_path(@my_module) %>"
:enabled="<%= current_team.shareable_links_enabled? %>"
:shared="<%= @my_module.shared? %>"
:can-share="<%= can_share_my_module?(@my_module) %>" />
<% if @my_module.my_module_status_flow %>
<div id="status-container" class="flex items-center gap-2" data-current-status-id="<%= @my_module.my_module_status_id %>" data-current-status-url="<%= current_status_my_module_path(@my_module) %>" data-status-partial-url="<%= status_partial_my_module_path(@my_module) %>">
<%= render partial: 'my_modules/status_flow/task_flow_button', locals: { my_module: @my_module } %>
</div>
<% end %>
<%= javascript_include_tag("my_modules/status_flow") %>
<div id="share-task-container" data-behaviour="vue">
<share-task-container
shareable-link-url="<%= my_module_shareable_link_path(@my_module) %>"
:enabled="<%= current_team.shareable_links_enabled? %>"
:shared="<%= @my_module.shared? %>"
:can-share="<%= can_share_my_module?(@my_module) %>" />
</div>
<%= javascript_include_tag 'vue_share_task_container' %>
<%= javascript_include_tag 'vue_share_task_container' %>
</div>

View file

@ -91,4 +91,3 @@
</ul>
</div>
</div>

View file

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

View file

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