add restart logic

This commit is contained in:
jr-k 2024-02-27 15:16:34 +01:00
parent 709e065ed4
commit cc4bf88335
6 changed files with 43 additions and 4 deletions

18
data/www/js/sysinfo.js Normal file
View File

@ -0,0 +1,18 @@
jQuery(document).ready(function ($) {
$(document).on('click', '.sysinfo-restart', function () {
if (confirm(l.js_sysinfo_restart_confirmation)) {
$('body').html(l.js_sysinfo_restart_loading).css({margin:200});
$.ajax({
url: '/sysinfo/restart',
headers: {'Content-Type': 'application/json'},
data: '',
method: 'POST',
}).catch(function () {
setTimeout(function() {
document.location.reload();
}, 3000);
});
}
});
});

View File

@ -63,8 +63,11 @@
"settings_variable_help_fleet_enabled": "Enable fleet screen management view (restart needed)",
"sysinfo_page_title": "System infos",
"sysinfo_panel_button_restart": "Restart",
"sysinfo_panel_title": "Infos",
"sysinfo_panel_th_attribute": "Attribute",
"sysinfo_panel_th_value": "Value",
"sysinfo_panel_td_ipaddr": "IP Address"
"sysinfo_panel_td_ipaddr": "IP Address",
"js_sysinfo_restart_confirmation": "Are you sure?",
"js_sysinfo_restart_loading": "Restarting, please wait..."
}

View File

@ -63,8 +63,11 @@
"settings_variable_help_fleet_enabled": "Activer la gestion de flotte des écrans (redémarrage nécessaire)",
"sysinfo_page_title": "Système",
"sysinfo_panel_button_restart": "Redémarrer",
"sysinfo_panel_title": "Informations",
"sysinfo_panel_th_attribute": "Attribut",
"sysinfo_panel_th_value": "Valeur",
"sysinfo_panel_td_ipaddr": "Adresse IP"
"sysinfo_panel_td_ipaddr": "Adresse IP",
"js_sysinfo_restart_confirmation": "Êtes-vous sûr ?",
"js_sysinfo_restart_loading": "Redémarrage en cours, veuillez patienter..."
}

View File

@ -1,4 +1,7 @@
from flask import Flask, render_template
import os
import sys
from flask import Flask, render_template, jsonify
from src.utils import get_ip_address
@ -11,6 +14,7 @@ class SysinfoController:
def register(self):
self._app.add_url_rule('/sysinfo', 'sysinfo_attribute_list', self.sysinfo, methods=['GET'])
self._app.add_url_rule('/sysinfo/restart', 'sysinfo_restart', self.sysinfo_restart, methods=['POST'])
def sysinfo(self):
return render_template(
@ -18,3 +22,9 @@ class SysinfoController:
ipaddr=get_ip_address(),
l=self._lang_dict,
)
def sysinfo_restart(self):
python = sys.executable
os.execl(python, python, *sys.argv)
return jsonify({'status': 'ok'})

View File

@ -66,6 +66,8 @@
<script>
var l = {'js_slideshow_slide_delete_confirmation': '{{ l.slideshow_slide_delete_confirmation }}'};
var l = {'js_fleet_screen_delete_confirmation': '{{ l.js_fleet_screen_delete_confirmation }}'};
var l = {'js_sysinfo_restart_confirmation': '{{ l.js_sysinfo_restart_confirmation }}'};
var l = {'js_sysinfo_restart_loading': '{{ l.js_sysinfo_restart_loading }}'};
</script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
{% block add_js %}{% endblock %}

View File

@ -6,12 +6,15 @@
{% endblock %}
{% block add_js %}
<script src="{{ STATIC_PREFIX }}js/sysinfo.js"></script>
{% endblock %}
{% block page %}
<div class="toolbar">
<h2>{{ l.sysinfo_page_title }}</h2>
<div class="toolbar-actions">
<button class="purple sysinfo-restart"><i class="fa fa-refresh icon-left"></i>{{ l.sysinfo_panel_button_restart }}</button>
</div>
</div>
<div class="panel">
<div class="panel-body">