[fix] Indicate to users server is rebooting/shutting down

This commit is contained in:
ljf 2017-10-04 18:09:00 +02:00
parent d4e86accce
commit 802b189faa
3 changed files with 106 additions and 68 deletions

View file

@ -172,8 +172,34 @@
y18n.t('confirm_reboot_action_' + action),
function(){
c.api('/'+action+'?force', function(data) {
// This code is not executed due to 502 response (reboot or shutdown)
c.redirect('#/logout');
}, 'PUT');
}, 'PUT', {}, false, function (xhr) {
c.flash('success', y18n.t('tools_' + action + '_done'))
// Disconnect from the webadmin
store.clear('url');
store.clear('connected');
store.set('path', '#/');
// Rename the page to allow refresh without ask for rebooting
window.location.href = window.location.href.split('#')[0] + '#/';
// Display reboot or shutdown info
// We can't use template because now the webserver is off
if (action == 'reboot') {
$('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-refresh"></i> ' + y18n.t('tools_rebooting') + '</div></div>');
}
else {
$('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-power-off"></i> ' + y18n.t('tools_shuttingdown') + '</div></div>');
}
// Remove loader if any
$('div.loader').remove();
// Force scrollTop on page load
$('html, body').scrollTop(0);
store.clear('slide');
});
},
function(){
store.clear('slide');
@ -187,6 +213,11 @@
c.redirect('#/tools/reboot');
}
});
app.get('#/tools/reboot/:action/done', function (c) {
var action = c.params['action'].toLowerCase();
if (action == 'reboot' || action == 'shutdown') {
}
});
// Diagnosis
app.get('#/tools/diagnosis(/:private)?', function (c) {

View file

@ -62,10 +62,10 @@
},
// API call
api: function(uri, callback, method, data, websocket) {
api: function(uri, callback, method, data, websocket, callbackOnFailure) {
c = this;
call = function(uri, callback, method, data) {
call = function(uri, callback, method, data, callbackOnFailure) {
method = typeof method !== 'undefined' ? method : 'GET';
data = typeof data !== 'undefined' ? data : {};
if (window.navigator && window.navigator.language && (typeof data.locale === 'undefined')) {
@ -84,22 +84,8 @@
if ($('div.loader').length === 0) {
$('#main').append('<div class="loader loader-content"></div>');
}
jQuery.ajax({
url: 'https://' + store.get('url') + uri,
type: method,
crossdomain: true,
data: data,
traditional: true,
dataType: 'json'
})
.always(function(xhr, ts, error) {
})
.done(function(data) {
data = data || {};
callback(data);
})
.fail(function(xhr) {
if (typeof callbackOnFailure !== 'function') {
callbackOnFailure = function(xhr) {
// Postinstall is a custom case, we have to wait that
// operation is done before doing anything
if (uri === '/postinstall') {
@ -161,7 +147,24 @@
$('html, body').scrollTop(0);
store.clear('slide');
}
});
};
}
jQuery.ajax({
url: 'https://' + store.get('url') + uri,
type: method,
crossdomain: true,
data: data,
traditional: true,
dataType: 'json'
})
.always(function(xhr, ts, error) {
})
.done(function(data) {
data = data || {};
callback(data);
})
.fail(callbackOnFailure);
};
websocket = typeof websocket !== 'undefined' ? websocket : true;
@ -181,9 +184,9 @@
ws.onclose = function() {};
ws.onopen = call(uri, callback, method, data);
ws.onopen = call(uri, callback, method, data, callbackOnFailure);
} else {
call(uri, callback, method, data);
call(uri, callback, method, data, callbackOnFailure);
}
},

View file

@ -273,8 +273,12 @@
"tools_security_feed_view_items": "View all security notifications",
"tools_reboot": "Reboot your server",
"tools_reboot_btn": "Reboot",
"tools_reboot_done": "Rebooting...",
"tools_rebooting": "Your server is rebooting. To return on the web administration interface you need to wait your server to be up. You can check that by refreshing regularly this page (F5).",
"tools_shutdown": "Shutdown your server",
"tools_shutdown_btn": "Shutdown",
"tools_shutdown_done": "Shutting down...",
"tools_shuttingdown": "Your server is powerring off. As long as your server is off, you won't be able to use the web administration.",
"tools_shutdown_reboot": "Shutdown/Reboot",
"total": "Total",
"transmission": "Transmission",