From b637cf67502735d6ab9ee8a6deb1d1f323a2b15b Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 7 Oct 2019 10:51:28 +0200 Subject: [PATCH] luci-mod-system: port reboot view to client side js Signed-off-by: Jo-Philipp Wich --- .../resources/view/system/reboot.js | 59 ++++++++++++++++++ .../luasrc/controller/admin/system.lua | 7 +-- .../luasrc/view/admin_system/reboot.htm | 62 ------------------- 3 files changed, 60 insertions(+), 68 deletions(-) create mode 100644 modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js delete mode 100644 modules/luci-mod-system/luasrc/view/admin_system/reboot.htm diff --git a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js new file mode 100644 index 000000000..0a1446555 --- /dev/null +++ b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js @@ -0,0 +1,59 @@ +'use strict'; +'require fs'; +'require ui'; +'require uci'; +'require rpc'; + +var callReboot = rpc.declare({ + object: 'luci', + method: 'setReboot', + expect: { result: false } +}); + +return L.view.extend({ + load: function() { + return uci.changes(); + }, + + render: function(changes) { + var body = E([ + E('h2', _('Reboot')), + E('p', {}, _('Reboots the operating system of your device')) + ]); + + for (var config in (changes || {})) { + body.appendChild(E('p', { 'class': 'alert-message warning' }, + _('Warning: There are unsaved changes that will get lost on reboot!'))); + break; + } + + body.appendChild(E('hr')); + body.appendChild(E('button', { + 'class': 'cbi-button cbi-button-action important', + 'click': ui.createHandlerFn(this, 'handleReboot') + }, _('Perform reboot'))); + + return body; + }, + + handleReboot: function(ev) { + return callReboot().then(function() { + L.ui.showModal(_('Rebooting…'), [ + E('p', { 'class': 'spinning' }, _('Waiting for device...')) + ]); + + window.setTimeout(function() { + L.ui.showModal(_('Rebooting…'), [ + E('p', { 'class': 'spinning alert-message warning' }, + _('Device unreachable! Still waiting for device...')) + ]); + }, 150000); + + L.ui.awaitReconnect(); + }); + }, + + handleSaveApply: null, + handleSave: null, + handleReset: null +}); diff --git a/modules/luci-mod-system/luasrc/controller/admin/system.lua b/modules/luci-mod-system/luasrc/controller/admin/system.lua index c7d8ac532..2913a23ef 100644 --- a/modules/luci-mod-system/luasrc/controller/admin/system.lua +++ b/modules/luci-mod-system/luasrc/controller/admin/system.lua @@ -31,10 +31,5 @@ function index() entry({"admin", "system", "flash"}, view("system/flash"), _("Backup / Flash Firmware"), 70) - entry({"admin", "system", "reboot"}, template("admin_system/reboot"), _("Reboot"), 90) - entry({"admin", "system", "reboot", "call"}, post("action_reboot")) -end - -function action_reboot() - luci.sys.reboot() + entry({"admin", "system", "reboot"}, view("system/reboot"), _("Reboot"), 90) end diff --git a/modules/luci-mod-system/luasrc/view/admin_system/reboot.htm b/modules/luci-mod-system/luasrc/view/admin_system/reboot.htm deleted file mode 100644 index d23664ada..000000000 --- a/modules/luci-mod-system/luasrc/view/admin_system/reboot.htm +++ /dev/null @@ -1,62 +0,0 @@ -<%# - Copyright 2008 Steven Barth - Copyright 2008-2015 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -<%+header%> - -

<%:Reboot%>

- -

<%:Reboots the operating system of your device%>

- -<%- local c = require("luci.model.uci").cursor():changes(); if c and next(c) then -%> -

<%:Warning: There are unsaved changes that will get lost on reboot!%>

-<%- end -%> - -
- - - - - - - -<%+footer%> -- 2.25.1