MSIN-4328 — Implement countdown for next auto sync in ChronoTrack API. Enhance UI to display countdown timer for upcoming cron jobs and update push panel messages for clarity on sync operations. Introduce new functions for managing auto sync metadata and improve overall user feedback during synchronization processes.
This commit is contained in:
@ -335,7 +335,8 @@ function fxChronotrackApiAdminRenderPushPanel($intEveId, $blnClosed = false, $ar
|
||||
. 'Lancer le script cron</button>';
|
||||
echo '</div>';
|
||||
echo '<p class="small text-muted mb-2">Envoi manuel : nouveaux / modifiés depuis le dernier push. '
|
||||
. 'Page : refresh statut MS1 chaque minute.</p>';
|
||||
. 'Refresh écran (~60 s) = statut MS1 seulement, <strong>aucun envoi</strong> vers ChronoTrack. '
|
||||
. 'L’envoi auto = cron <code>auto_chronotrack_sync.php</code>.</p>';
|
||||
echo '<div id="ct_api_push_result" class="small mb-3"></div>';
|
||||
echo '<div id="ct_api_logs_wrap" class="mb-3 d-none"></div>';
|
||||
|
||||
@ -453,11 +454,71 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed
|
||||
var intCtLiveCount = null;
|
||||
var blnPushRunning = false;
|
||||
var intStatusRefreshTimer = null;
|
||||
var intAutoCountdownTimer = null;
|
||||
// MSIN-4328 — countdown prochain passage cron auto (pas le refresh écran)
|
||||
var objAutoCd = {
|
||||
enabled: false,
|
||||
nextDueTs: 0,
|
||||
serverNowTs: 0,
|
||||
receivedAtMs: 0
|
||||
};
|
||||
|
||||
function escHtml(str) {
|
||||
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
|
||||
function formatCountdownMmSs(intSec) {
|
||||
intSec = Math.max(0, parseInt(intSec, 10) || 0);
|
||||
var intM = Math.floor(intSec / 60);
|
||||
var intS = intSec % 60;
|
||||
return intM + ':' + (intS < 10 ? '0' : '') + intS;
|
||||
}
|
||||
|
||||
function paintAutoCountdown() {
|
||||
var $status = $('#ct_api_push_status');
|
||||
if (!$status.length) {
|
||||
return;
|
||||
}
|
||||
var $el = $('#ct_api_next_auto');
|
||||
if (!objAutoCd.enabled) {
|
||||
$el.remove();
|
||||
return;
|
||||
}
|
||||
if (!$el.length) {
|
||||
$status.append('<p id="ct_api_next_auto" class="small text-muted mb-0 mt-1"></p>');
|
||||
$el = $('#ct_api_next_auto');
|
||||
}
|
||||
var intElapsed = Math.floor((Date.now() - objAutoCd.receivedAtMs) / 1000);
|
||||
var intServerNow = objAutoCd.serverNowTs + intElapsed;
|
||||
var intLeft = objAutoCd.nextDueTs - intServerNow;
|
||||
if (intLeft <= 0) {
|
||||
$el.html('Prochain envoi auto : <strong>dû</strong> (dès le prochain cron, ~chaque minute)');
|
||||
} else {
|
||||
$el.html('Prochain envoi auto dans <strong>' + formatCountdownMmSs(intLeft) + '</strong>');
|
||||
}
|
||||
}
|
||||
|
||||
function syncAutoCountdownFromPreview(res) {
|
||||
var a = (res && res.auto_sync) ? res.auto_sync : null;
|
||||
if (!a || !a.enabled || !a.next_due_ts) {
|
||||
objAutoCd.enabled = false;
|
||||
if (intAutoCountdownTimer) {
|
||||
clearInterval(intAutoCountdownTimer);
|
||||
intAutoCountdownTimer = null;
|
||||
}
|
||||
$('#ct_api_next_auto').remove();
|
||||
return;
|
||||
}
|
||||
objAutoCd.enabled = true;
|
||||
objAutoCd.nextDueTs = parseInt(a.next_due_ts, 10) || 0;
|
||||
objAutoCd.serverNowTs = parseInt(a.server_now_ts, 10) || Math.floor(Date.now() / 1000);
|
||||
objAutoCd.receivedAtMs = Date.now();
|
||||
paintAutoCountdown();
|
||||
if (!intAutoCountdownTimer) {
|
||||
intAutoCountdownTimer = setInterval(paintAutoCountdown, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
if (window.Ms1Loader) {
|
||||
Ms1Loader.init({
|
||||
src: <?php echo json_encode($vDomaine . '/images/ms1-runner-loader.gif?v=' . _VERSION_CODE); ?>
|
||||
@ -945,6 +1006,7 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed
|
||||
}
|
||||
$('#ct_api_push_blocked_wrap').addClass('d-none').empty();
|
||||
$btn.prop('disabled', true);
|
||||
syncAutoCountdownFromPreview(null);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -982,6 +1044,8 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed
|
||||
+ intEligible + ' éligibles · rien à envoyer pour le moment.</p>'
|
||||
);
|
||||
}
|
||||
// MSIN-4328 — mini countdown prochain envoi cron (écran = lecture seule)
|
||||
syncAutoCountdownFromPreview(res);
|
||||
}
|
||||
|
||||
// Détails (sous les boutons, zone repliable)
|
||||
@ -1194,11 +1258,13 @@ function fxChronotrackApiAdminRenderPageScript($intEveId, $arrConfig, $blnClosed
|
||||
$msg.addClass('text-success').text(res.message || 'Enregistré');
|
||||
if (res.auto_sync) {
|
||||
if (res.auto_sync.enabled && res.auto_sync.until) {
|
||||
$hint.text('Config OK — cron toutes les minutes lit cette config (auto_chronotrack_sync.php). Arrêt : '
|
||||
$hint.text('Config OK — le cron envoie les changements (pas le refresh écran). Arrêt : '
|
||||
+ res.auto_sync.until + '.');
|
||||
} else {
|
||||
$hint.text('Sync auto désactivée.');
|
||||
$('#ct_api_next_auto').remove();
|
||||
}
|
||||
loadPushPreview(true);
|
||||
}
|
||||
}, 'json').fail(function () {
|
||||
$msg.addClass('text-danger').text('Erreur réseau');
|
||||
|
||||
Reference in New Issue
Block a user