luci-mod-system: describe NTP server candidates
[project/luci.git] / modules / luci-mod-system / htdocs / luci-static / resources / view / system / system.js
index 6563bf4638f0a58cd6957ac82282ff90e19d1fb1..f7c13467831370b559f6e969879daacbdcb9b8c1 100644 (file)
@@ -1,14 +1,18 @@
 'use strict';
+'require view';
+'require poll';
+'require ui';
 'require uci';
 'require rpc';
 'require form';
+'require tools.widgets as widgets';
 
-var callInitList, callInitAction, callTimezone,
+var callRcList, callRcInit, callTimezone,
     callGetLocaltime, callSetLocaltime, CBILocalTime;
 
-callInitList = rpc.declare({
-       object: 'luci',
-       method: 'getInitList',
+callRcList = rpc.declare({
+       object: 'rc',
+       method: 'list',
        params: [ 'name' ],
        expect: { '': {} },
        filter: function(res) {
@@ -18,17 +22,17 @@ callInitList = rpc.declare({
        }
 });
 
-callInitAction = rpc.declare({
-       object: 'luci',
-       method: 'setInitAction',
+callRcInit = rpc.declare({
+       object: 'rc',
+       method: 'init',
        params: [ 'name', 'action' ],
        expect: { result: false }
 });
 
 callGetLocaltime = rpc.declare({
-       object: 'luci',
-       method: 'getLocaltime',
-       expect: { result: 0 }
+       object: 'system',
+       method: 'info',
+       expect: { localtime: 0 }
 });
 
 callSetLocaltime = rpc.declare({
@@ -44,39 +48,54 @@ callTimezone = rpc.declare({
        expect: { '': {} }
 });
 
+function formatTime(epoch) {
+       var date = new Date(epoch * 1000);
+
+       return '%04d-%02d-%02d %02d:%02d:%02d'.format(
+               date.getUTCFullYear(),
+               date.getUTCMonth() + 1,
+               date.getUTCDate(),
+               date.getUTCHours(),
+               date.getUTCMinutes(),
+               date.getUTCSeconds()
+       );
+}
+
 CBILocalTime = form.DummyValue.extend({
        renderWidget: function(section_id, option_id, cfgvalue) {
                return E([], [
-                       E('span', {}, [
-                               E('input', {
-                                       'id': 'localtime',
-                                       'type': 'text',
-                                       'readonly': true,
-                                       'value': new Date(cfgvalue * 1000).toLocaleString()
-                               })
-                       ]),
-                       ' ',
-                       E('button', {
-                               'class': 'cbi-button cbi-button-apply',
-                               'click': L.ui.createHandlerFn(this, function() {
-                                       return callSetLocaltime(Math.floor(Date.now() / 1000));
-                               })
-                       }, _('Sync with browser')),
-                       ' ',
-                       this.ntpd_support ? E('button', {
-                               'class': 'cbi-button cbi-button-apply',
-                               'click': L.ui.createHandlerFn(this, function() {
-                                       return callInitAction('sysntpd', 'restart');
-                               })
-                       }, _('Sync with NTP-Server')) : ''
+                       E('input', {
+                               'id': 'localtime',
+                               'type': 'text',
+                               'readonly': true,
+                               'value': formatTime(cfgvalue)
+                       }),
+                       E('br'),
+                       E('span', { 'class': 'control-group' }, [
+                               E('button', {
+                                       'class': 'cbi-button cbi-button-apply',
+                                       'click': ui.createHandlerFn(this, function() {
+                                               return callSetLocaltime(Math.floor(Date.now() / 1000));
+                                       }),
+                                       'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
+                               }, _('Sync with browser')),
+                               ' ',
+                               this.ntpd_support ? E('button', {
+                                       'class': 'cbi-button cbi-button-apply',
+                                       'click': ui.createHandlerFn(this, function() {
+                                               return callRcInit('sysntpd', 'restart');
+                                       }),
+                                       'disabled': (this.readonly != null) ? this.readonly : this.map.readonly
+                               }, _('Sync with NTP-Server')) : ''
+                       ])
                ]);
        },
 });
 
-return L.view.extend({
+return view.extend({
        load: function() {
                return Promise.all([
-                       callInitList('sysntpd'),
+                       callRcList('sysntpd'),
                        callTimezone(),
                        callGetLocaltime(),
                        uci.load('luci'),
@@ -116,6 +135,13 @@ return L.view.extend({
                o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
                o.datatype = 'hostname';
 
+               /* could be used also as a default for LLDP, SNMP "system description" in the future */
+               o = s.taboption('general', form.Value, 'description', _('Description'), _('An optional, short description for this device'));
+               o.optional = true;
+
+               o = s.taboption('general', form.TextValue, 'notes', _('Notes'), _('Optional, free-form notes about this device'));
+               o.optional = true;
+
                o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
                o.value('UTC');
 
@@ -141,7 +167,7 @@ return L.view.extend({
                o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
                o.optional    = true
                o.placeholder = '0.0.0.0'
-               o.datatype    = 'ip4addr'
+               o.datatype    = 'host'
 
                o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
                o.optional    = true
@@ -186,15 +212,10 @@ return L.view.extend({
 
                        o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
                        o.optional    = true;
-                       o.placeholder = 'lzo';
+                       o.default     = 'lzo';
                        o.value('lzo', 'lzo');
                        o.value('lz4', 'lz4');
-                       o.value('deflate', 'deflate');
-
-                       o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
-                       o.optional    = true;
-                       o.placeholder = 1;
-                       o.datatype    = 'uinteger';
+                       o.value('zstd', 'zstd');
                }
 
                /*
@@ -207,10 +228,11 @@ return L.view.extend({
                o.ucioption = 'lang';
                o.value('auto');
 
-               var k = Object.keys(uci.get('luci', 'languages') || {}).sort();
+               var l = Object.assign({ en: 'English' }, uci.get('luci', 'languages')),
+                   k = Object.keys(l).sort();
                for (var i = 0; i < k.length; i++)
                        if (k[i].charAt(0) != '.')
-                               o.value(k[i], uci.get('luci', 'languages', k[i]));
+                               o.value(k[i], l[k[i]]);
 
                o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
                o.uciconfig = 'luci';
@@ -249,7 +271,7 @@ return L.view.extend({
                                else
                                        uci.unset('system', 'ntp', 'enabled');
 
-                               return callInitAction('sysntpd', 'enable');
+                               return callRcInit('sysntpd', 'enable');
                        };
                        o.load = function(section_id) {
                                return (ntpd_enabled == 1 &&
@@ -261,12 +283,22 @@ return L.view.extend({
                        o.ucisection = 'ntp';
                        o.depends('enabled', '1');
 
+                       o = s.taboption('timesync', widgets.NetworkSelect, 'interface',
+                               _('Bind NTP server'),
+                               _('Provide the NTP server to the selected interface or, if unspecified, to all interfaces'));
+                       o.ucisection = 'ntp';
+                       o.depends('enable_server', '1');
+                       o.multiple = false;
+                       o.nocreate = true;
+                       o.optional = true;
+
                        o = s.taboption('timesync', form.Flag, 'use_dhcp', _('Use DHCP advertised servers'));
                        o.ucisection = 'ntp';
                        o.default = o.enabled;
                        o.depends('enabled', '1');
 
-                       o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'));
+                       o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'),
+                               _('List of upstream NTP server candidates with which to synchronize.'));
                        o.datatype = 'host(0)';
                        o.ucisection = 'ntp';
                        o.depends('enabled', '1');
@@ -276,9 +308,9 @@ return L.view.extend({
                }
 
                return m.render().then(function(mapEl) {
-                       L.Poll.add(function() {
+                       poll.add(function() {
                                return callGetLocaltime().then(function(t) {
-                                       mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();
+                                       mapEl.querySelector('#localtime').value = formatTime(t);
                                });
                        });