Skip to content

Commit f085f9d

Browse files
authored
Merge pull request #2103 from RaspAP/feat/reconnect-dialog
Feature: Reconnect Dialog
2 parents f31a943 + d50995d commit f085f9d

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

app/js/ajax/system.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,57 @@ export function initSystem_ajax() {
1212
'csrf_token': csrfToken
1313
}, function(data) {
1414
var response = JSON.parse(data);
15+
16+
if (action === 'reboot') {
17+
const reconnectModalEl = $('#system-reconnect');
18+
const modal = new bootstrap.Modal(reconnectModalEl);
19+
modal.show();
20+
handleReconnect(reconnectModalEl);
21+
}
1522
});
1623
});
1724

25+
function handleReconnect(modal) {
26+
const secondsEl = $(modal).find('#system-reconnect-seconds');
27+
28+
let countdownInterval;
29+
const attemptSeconds = 20;
30+
31+
const attemptReconnect = async () => {
32+
console.log('attempting reconnect');
33+
$(secondsEl).text('...');
34+
35+
const startCountdown = (e) => {
36+
console.log('still rebooting - start countdown', e);
37+
clearInterval(countdownInterval);
38+
let countdownInt = attemptSeconds;
39+
countdownInterval = setInterval(() => {
40+
console.log('decrement countdownInt');
41+
if (countdownInt === 0) attemptReconnect();
42+
$(secondsEl).text(countdownInt);
43+
if (countdownInt > 0) countdownInt--;
44+
}, 1000);
45+
}
46+
47+
try {
48+
// fetch to url and get status
49+
const checkUrl = window.location.origin;
50+
const response = await fetch(checkUrl);
51+
52+
if (response.status === 200) {
53+
console.log('reconnected - reload the page');
54+
window.location.reload();
55+
} else {
56+
startCountdown();
57+
}
58+
} catch (e) {
59+
startCountdown(e);
60+
}
61+
};
62+
63+
attemptReconnect();
64+
}
65+
1866
$('#js-system-reset-confirm').on('click', function (e) {
1967
var progressText = $('#js-system-reset-confirm').attr('data-message');
2068
var successHtml = $('#system-reset-message').attr('data-message');

templates/system.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@
7878
</div>
7979
</div>
8080

81+
<!-- modal reconnecting-->
82+
<div class="modal fade" id="system-reconnect" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
83+
<div class="modal-dialog" role="document">
84+
<div class="modal-content">
85+
<div class="modal-header">
86+
<div class="modal-title" id="ModalLabel"><i class="fas fa-sync me-2"></i><?php echo _("Reconnecting"); ?></div>
87+
</div>
88+
<div class="modal-body">
89+
<div class="col-md-12 mb-3 mt-1" id="system-reconnect-message">
90+
<p><?php echo _("The system is currently rebooting."); ?></p>
91+
<p><?= _('Attempting to reconnect in'); ?>&nbsp;<span id="system-reconnect-seconds"></span></p>
92+
</div>
93+
</div>
94+
</div>
95+
</div>
96+
</div>
97+
8198
<!-- modal confirm-shutdown-->
8299
<div class="modal fade" id="system-confirm-shutdown" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
83100
<div class="modal-dialog" role="document">

0 commit comments

Comments
 (0)