luci-base,luci-mod-system: split ubus localtime into get and set call
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
abee9138de
commit
acbc031a6d
3 changed files with 30 additions and 10 deletions
|
@ -37,14 +37,26 @@ local methods = {
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
localtime = {
|
getLocaltime = {
|
||||||
call = function(args)
|
call = function(args)
|
||||||
return { localtime = os.time() }
|
return { localtime = os.time() }
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setLocaltime = {
|
||||||
|
args = { localtime = 0 },
|
||||||
|
call = function(args)
|
||||||
|
local sys = require "luci.sys"
|
||||||
|
local date = os.date("*t", args.localtime)
|
||||||
|
if date then
|
||||||
|
sys.call("date -s '%04d-%02d-%02d %02d:%02d:%02d' >/dev/null" %{ date.year, date.month, date.day, date.hour, date.min, date.sec })
|
||||||
|
sys.call("/etc/init.d/sysfixtime restart >/dev/null")
|
||||||
|
end
|
||||||
|
return { localtime = args.localtime }
|
||||||
|
end
|
||||||
|
},
|
||||||
|
|
||||||
timezone = {
|
timezone = {
|
||||||
args = { zonename = "UTC" },
|
|
||||||
call = function(args)
|
call = function(args)
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local zones = require "luci.sys.zoneinfo"
|
local zones = require "luci.sys.zoneinfo"
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
"read": {
|
"read": {
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"iwinfo": [ "info" ],
|
"iwinfo": [ "info" ],
|
||||||
"luci": [ "boardjson", "duid_hints", "host_hints", "ifaddrs", "initList", "leases", "leds", "netdevs", "offload_support", "usb" ],
|
"luci": [ "boardjson", "duid_hints", "host_hints", "ifaddrs", "initList", "getLocaltime", "leases", "leds", "netdevs", "offload_support", "usb" ],
|
||||||
"network.device": [ "status" ],
|
"network.device": [ "status" ],
|
||||||
"network.interface": [ "dump" ],
|
"network.interface": [ "dump" ],
|
||||||
"network.wireless": [ "status" ],
|
"network.wireless": [ "status" ],
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
},
|
},
|
||||||
"write": {
|
"write": {
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"luci": [ "initCall", "localtime", "timezone" ],
|
"luci": [ "initCall", "setLocaltime", "timezone" ],
|
||||||
"uci": [ "add", "apply", "confirm", "delete", "order", "set" ]
|
"uci": [ "add", "apply", "confirm", "delete", "order", "set" ]
|
||||||
},
|
},
|
||||||
"uci": [ "*" ]
|
"uci": [ "*" ]
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
'require rpc';
|
'require rpc';
|
||||||
'require form';
|
'require form';
|
||||||
|
|
||||||
var callInitList, callInitAction, callLocaltime, callTimezone, CBILocalTime;
|
var callInitList, callInitAction, callTimezone,
|
||||||
|
callGetLocaltime, callSetLocaltime, CBILocalTime;
|
||||||
|
|
||||||
callInitList = rpc.declare({
|
callInitList = rpc.declare({
|
||||||
object: 'luci',
|
object: 'luci',
|
||||||
|
@ -24,9 +25,16 @@ callInitAction = rpc.declare({
|
||||||
expect: { result: false }
|
expect: { result: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
callLocaltime = rpc.declare({
|
callGetLocaltime = rpc.declare({
|
||||||
object: 'luci',
|
object: 'luci',
|
||||||
method: 'localtime',
|
method: 'getLocaltime',
|
||||||
|
expect: { localtime: 0 }
|
||||||
|
});
|
||||||
|
|
||||||
|
callSetLocaltime = rpc.declare({
|
||||||
|
object: 'luci',
|
||||||
|
method: 'setLocaltime',
|
||||||
|
params: [ 'localtime' ],
|
||||||
expect: { localtime: 0 }
|
expect: { localtime: 0 }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,7 +56,7 @@ CBILocalTime = form.DummyValue.extend({
|
||||||
this.blur();
|
this.blur();
|
||||||
this.classList.add('spinning');
|
this.classList.add('spinning');
|
||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
callLocaltime(Math.floor(Date.now() / 1000)).then(L.bind(function() {
|
callSetLocaltime(Math.floor(Date.now() / 1000)).then(L.bind(function() {
|
||||||
this.classList.remove('spinning');
|
this.classList.remove('spinning');
|
||||||
this.disabled = false;
|
this.disabled = false;
|
||||||
}, this));
|
}, this));
|
||||||
|
@ -77,7 +85,7 @@ return L.view.extend({
|
||||||
callInitList('sysntpd'),
|
callInitList('sysntpd'),
|
||||||
callInitList('zram'),
|
callInitList('zram'),
|
||||||
callTimezone(),
|
callTimezone(),
|
||||||
callLocaltime(),
|
callGetLocaltime(),
|
||||||
uci.load('luci'),
|
uci.load('luci'),
|
||||||
uci.load('system')
|
uci.load('system')
|
||||||
]);
|
]);
|
||||||
|
@ -276,7 +284,7 @@ return L.view.extend({
|
||||||
|
|
||||||
return m.render().then(function(mapEl) {
|
return m.render().then(function(mapEl) {
|
||||||
L.Poll.add(function() {
|
L.Poll.add(function() {
|
||||||
return callLocaltime().then(function(t) {
|
return callGetLocaltime().then(function(t) {
|
||||||
mapEl.querySelector('#localtime').innerHTML = new Date(t * 1000).toLocaleString();
|
mapEl.querySelector('#localtime').innerHTML = new Date(t * 1000).toLocaleString();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue