From: Jonas Theisen <j.theisen@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH widget-toolkit 06/16] partially fix #3809: node: time: show and edit NTP servers if supported
Date: Thu, 26 Nov 2026 14:40:03 +0100 [thread overview]
Message-ID: <20261126134128.316681-7-j.theisen@proxmox.com> (raw)
In-Reply-To: <20261126134128.316681-1-j.theisen@proxmox.com>
Add rows for the active NTP service and its custom sources to the time
view, and a table to the edit window, where sources can be added and
removed, each with a type selector for server or pool. They are only
shown if the API reports a supported time synchronization service, as
the components are shared with products whose time API does not
provide NTP settings.
The view shows the custom servers and pools together in one row, with
pools marked as such. The API returns neither if the service uses its
default sources, so the row gets an empty default value, which is
shown as "Default". It needs a separate filter to stay hidden without
a supported service, and an explicit sorter to keep the row order, as
rows with a default value are added before the first load.
The table is submitted as the separate server and pool parameters of
the API. The type selector is hidden if the API reports that the
service does not support pools, like systemd-timesyncd. Removing all
sources resets the service to its default sources. As the edit window
is no longer only about the time zone, change its title to "Time
settings".
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/node/TimeEdit.js | 285 ++++++++++++++++++++++++++++++++++++++++---
src/node/TimeView.js | 64 ++++++++--
2 files changed, 322 insertions(+), 27 deletions(-)
diff --git a/src/node/TimeEdit.js b/src/node/TimeEdit.js
index 2238a41..9624973 100644
--- a/src/node/TimeEdit.js
+++ b/src/node/TimeEdit.js
@@ -1,28 +1,281 @@
+// Edits the custom NTP servers and pools as one list, submitted as the 'ntp-servers' and
+// 'ntp-pools' parameters. An empty list resets the service to its default sources.
+Ext.define('Proxmox.form.NTPSourceList', {
+ extend: 'Ext.form.FieldContainer',
+ alias: 'widget.proxmoxNTPSourceList',
+
+ mixins: ['Ext.form.field.Field'],
+
+ isFormField: true,
+
+ // list of { type: 'server' | 'pool', address }
+ setValue: function (list) {
+ let me = this;
+
+ // copy, as the store uses the objects as record data and adds an id to them, which would
+ // modify the original value used for the dirty tracking
+ me.lookup('grid')
+ .getStore()
+ .setData((list ?? []).map(({ type, address }) => ({ type, address })));
+ me.checkChange();
+ return me;
+ },
+
+ getValue: function () {
+ let me = this;
+
+ let list = [];
+ me.lookup('grid')
+ .getStore()
+ .each((rec) => {
+ list.push({ type: rec.data.type, address: rec.data.address });
+ });
+ return list;
+ },
+
+ // the default compares the string representation, which is the same for all lists of objects
+ // with the same length
+ isEqual: function (value1, value2) {
+ return JSON.stringify(value1) === JSON.stringify(value2);
+ },
+
+ getErrors: function () {
+ let me = this;
+
+ let errors = [];
+ me.lookup('grid')
+ .getStore()
+ .each((rec) => {
+ let address = rec.data.address ?? '';
+ if (address === '' || !Ext.form.field.VTypes.DnsOrIp(address)) {
+ errors.push(Ext.form.field.VTypes.DnsOrIpText);
+ return false;
+ }
+ return true;
+ });
+ return errors;
+ },
+
+ getSubmitData: function () {
+ let me = this;
+
+ if (me.disabled || !me.submitValue) {
+ return null;
+ }
+
+ let addresses = { 'ntp-servers': [], 'ntp-pools': [] };
+ for (const { type, address } of me.getValue()) {
+ addresses[type === 'pool' ? 'ntp-pools' : 'ntp-servers'].push(address);
+ }
+
+ let data = {};
+ let deletes = [];
+ for (const [param, list] of Object.entries(addresses)) {
+ if (list.length) {
+ data[param] = list.join(',');
+ } else {
+ deletes.push(param);
+ }
+ }
+ if (deletes.length) {
+ data.delete = deletes;
+ }
+ return data;
+ },
+
+ // without pool support, all sources are servers, so there is nothing to choose
+ setPoolsSupported: function (supported) {
+ let me = this;
+ me.lookup('typeColumn').setHidden(!supported);
+ },
+
+ controller: {
+ xclass: 'Ext.app.ViewController',
+
+ addSource: function () {
+ let me = this;
+ me.lookup('grid').getStore().add({ type: 'server', address: '' });
+ me.getView().checkChange();
+ me.getView().validate();
+ },
+
+ removeSource: function (button) {
+ let me = this;
+ let record = button.getWidgetRecord();
+ if (record === undefined) {
+ // this is sometimes called before a record/column is initialized
+ return;
+ }
+ me.lookup('grid').getStore().remove(record);
+ me.getView().checkChange();
+ me.getView().validate();
+ },
+
+ itemChange: function (field, newValue) {
+ let me = this;
+ let record = field.getWidgetRecord();
+ if (!record) {
+ return;
+ }
+ record.set(field.getWidgetColumn().dataIndex, newValue);
+ me.getView().checkChange();
+ me.getView().validate();
+ },
+
+ control: {
+ 'grid button': {
+ click: 'removeSource',
+ },
+ },
+ },
+
+ initComponent: function () {
+ let me = this;
+
+ Ext.apply(me, {
+ items: [
+ {
+ xtype: 'grid',
+ reference: 'grid',
+ height: 150,
+ scrollable: 'vertical',
+ margin: '0 0 5 0',
+ viewConfig: {
+ deferEmptyText: false,
+ emptyText: gettext('Default sources of the service'),
+ },
+ store: {
+ fields: ['type', 'address'],
+ listeners: {
+ update: function () {
+ this.commitChanges();
+ },
+ },
+ },
+ columns: [
+ {
+ header: gettext('Type'),
+ reference: 'typeColumn',
+ dataIndex: 'type',
+ xtype: 'widgetcolumn',
+ width: 110,
+ widget: {
+ xtype: 'proxmoxKVComboBox',
+ isFormField: false,
+ comboItems: [
+ ['server', gettext('Server')],
+ ['pool', gettext('Pool')],
+ ],
+ listeners: {
+ change: 'itemChange',
+ },
+ },
+ },
+ {
+ header: gettext('Address'),
+ dataIndex: 'address',
+ xtype: 'widgetcolumn',
+ flex: 1,
+ widget: {
+ xtype: 'textfield',
+ isFormField: false,
+ allowBlank: false,
+ vtype: 'DnsOrIp', // matches the 'address' format of the API
+ emptyText: gettext('Host name or IP address'),
+ listeners: {
+ change: 'itemChange',
+ },
+ },
+ onWidgetAttach: function (_col, widget) {
+ widget.isValid();
+ },
+ },
+ {
+ xtype: 'widgetcolumn',
+ width: 40,
+ widget: {
+ xtype: 'button',
+ iconCls: 'fa fa-trash-o',
+ },
+ },
+ ],
+ },
+ {
+ xtype: 'button',
+ text: gettext('Add'),
+ iconCls: 'fa fa-plus-circle',
+ handler: 'addSource',
+ },
+ ],
+ });
+
+ me.callParent();
+ me.initField();
+ },
+});
+
Ext.define('Proxmox.node.TimeEdit', {
extend: 'Proxmox.window.Edit',
alias: ['widget.proxmoxNodeTimeEdit'],
- subject: gettext('Time zone'),
+ subject: gettext('Time settings'),
- width: 400,
+ width: 550,
autoLoad: true,
fieldDefaults: {
- labelWidth: 70,
- },
-
- items: {
- xtype: 'combo',
- fieldLabel: gettext('Time zone'),
- name: 'timezone',
- queryMode: 'local',
- store: Ext.create('Proxmox.data.TimezoneStore'),
- displayField: 'zone',
- editable: true,
- anyMatch: true,
- forceSelection: true,
- allowBlank: false,
+ labelWidth: 90,
+ },
+
+ items: [
+ {
+ xtype: 'combo',
+ fieldLabel: gettext('Time zone'),
+ name: 'timezone',
+ queryMode: 'local',
+ store: Ext.create('Proxmox.data.TimezoneStore'),
+ displayField: 'zone',
+ editable: true,
+ anyMatch: true,
+ forceSelection: true,
+ allowBlank: false,
+ },
+ {
+ // shown once the loaded data says configuring NTP sources is supported
+ xtype: 'proxmoxNTPSourceList',
+ fieldLabel: gettext('NTP sources'),
+ name: 'ntp-sources',
+ hidden: true,
+ disabled: true,
+ },
+ ],
+
+ setValues: function (values) {
+ let me = this;
+
+ let supported = !!values['ntp-service'];
+ let sourceList = me.down('proxmoxNTPSourceList');
+ sourceList.setVisible(supported);
+ sourceList.setDisabled(!supported);
+ sourceList.setPoolsSupported(!!values['ntp-pools-supported']);
+
+ // set through the parent, so that the loaded list becomes the original value for the dirty
+ // tracking and resetting of the form
+ let toList = (value, type) =>
+ (value ?? '')
+ .split(',')
+ .filter((address) => address !== '')
+ .map((address) => ({ type, address }));
+ values = {
+ ...values,
+ 'ntp-sources': [
+ ...toList(values['ntp-servers'], 'server'),
+ ...toList(values['ntp-pools'], 'pool'),
+ ],
+ };
+
+ me.callParent([values]);
},
initComponent: function () {
diff --git a/src/node/TimeView.js b/src/node/TimeView.js
index 20214eb..35ac72f 100644
--- a/src/node/TimeView.js
+++ b/src/node/TimeView.js
@@ -14,6 +14,7 @@ Ext.define('Proxmox.node.TimeView', {
let servertime = new Date(value * 1000 + tzOffset);
return Ext.Date.format(servertime, 'Y-m-d H:i:s');
};
+ let splitList = (value) => (value ?? '').split(',').filter((item) => item !== '');
let run_editor = () => {
let win = Ext.create('Proxmox.node.TimeEdit', {
@@ -23,6 +24,8 @@ Ext.define('Proxmox.node.TimeView', {
win.on('destroy', me.reload, me);
};
+ let get_ntp_service = () => me.rstore.getById('ntp-service')?.data.value;
+
// the server time is read-only, so its row has no action
let run_row_action = () => {
let key = me.getSelectionModel().getSelection()[0]?.data.key;
@@ -31,22 +34,55 @@ Ext.define('Proxmox.node.TimeView', {
}
};
+ let rows = {
+ timezone: {
+ header: gettext('Time zone'),
+ required: true,
+ },
+ localtime: {
+ header: gettext('Server time'),
+ required: true,
+ renderer: renderLocaltime,
+ },
+ // only returned if configuring NTP servers is supported
+ 'ntp-service': {
+ header: gettext('NTP service'),
+ renderer: Ext.htmlEncode,
+ },
+ // Shows the custom servers and pools together. It is keyed on the servers, as their row
+ // always exists through the empty default value, while neither is returned if the
+ // service uses its default sources. The filter below hides it if there is no NTP
+ // service.
+ 'ntp-servers': {
+ header: gettext('NTP sources'),
+ defaultValue: '',
+ renderer: function (servers) {
+ let pools = me.rstore.getById('ntp-pools')?.data.value;
+ let sources = [
+ ...splitList(servers),
+ ...splitList(pools).map((pool) => `${pool} (${gettext('Pool')})`),
+ ];
+ if (!sources.length) {
+ return Proxmox.Utils.defaultText;
+ }
+ return Ext.htmlEncode(sources.join(', '));
+ },
+ },
+ // the reader drops keys without a row, keep it in the store for the renderer above
+ 'ntp-pools': {
+ visible: false,
+ },
+ };
+ let rowOrder = Object.keys(rows);
+
Ext.apply(me, {
url: `/api2/json/nodes/${me.nodename}/time`,
cwidth1: 150,
interval: 1000,
run_editor: run_row_action,
- rows: {
- timezone: {
- header: gettext('Time zone'),
- required: true,
- },
- localtime: {
- header: gettext('Server time'),
- required: true,
- renderer: renderLocaltime,
- },
- },
+ rows: rows,
+ // rows with a default value are added before the first load, keep the defined order
+ sorterFn: (a, b) => rowOrder.indexOf(a.data.key) - rowOrder.indexOf(b.data.key),
tbar: [
{
text: gettext('Edit'),
@@ -60,6 +96,12 @@ Ext.define('Proxmox.node.TimeView', {
me.callParent();
+ me.store.filters.add(
+ Ext.create('Ext.util.Filter', {
+ filterFn: (item) => item.data.key !== 'ntp-servers' || !!get_ntp_service(),
+ }),
+ );
+
me.on('activate', me.rstore.startUpdate);
me.on('deactivate', me.rstore.stopUpdate);
me.on('destroy', me.rstore.stopUpdate);
--
2.47.3
next prev parent reply other threads:[~2026-11-26 13:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 13:39 [PATCH common/manager/widget-toolkit 00/16] partially fix #3809: configure and monitor NTP in the node time panel Jonas Theisen
2026-11-26 13:39 ` [PATCH common 01/16] systemd: add helpers to get and set NTP servers Jonas Theisen
2026-11-26 13:39 ` [PATCH common 02/16] systemd: add helper to query clock synchronization status Jonas Theisen
2026-11-26 13:40 ` [PATCH common 03/16] systemd: add helpers to synchronize the clock immediately Jonas Theisen
2026-11-26 13:40 ` [PATCH common 04/16] systemd: add helper to list the current NTP sources Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 05/16] node: time: do not open the editor for the server time row Jonas Theisen
2026-11-26 13:40 ` Jonas Theisen [this message]
2026-11-26 13:40 ` [PATCH widget-toolkit 07/16] node: time: show clock synchronization status Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 08/16] window: add reusable service log window Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 09/16] node: time: add button to open the NTP service log Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 10/16] node: time: add button to synchronize the clock immediately Jonas Theisen
2026-11-26 13:40 ` [PATCH widget-toolkit 11/16] node: time: add window listing the current NTP sources Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 12/16] partially fix #3809: api: nodes: time: allow configuring NTP servers Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 13/16] api: nodes: time: report clock synchronization status Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 14/16] ui: node: time: use journal for the NTP service log Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 15/16] api: nodes: time: add endpoint to synchronize the clock immediately Jonas Theisen
2026-11-26 13:40 ` [PATCH manager 16/16] api: nodes: time: add endpoint to list the current NTP sources Jonas Theisen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126134128.316681-7-j.theisen@proxmox.com \
--to=j.theisen@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.