From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B4CF771745; Fri, 11 Jun 2021 13:44:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AE00410C6E; Fri, 11 Jun 2021 13:44:39 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0C2DD108D6; Fri, 11 Jun 2021 13:44:27 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D9D1B43EA8; Fri, 11 Jun 2021 13:44:26 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Fri, 11 Jun 2021 13:44:01 +0200 Message-Id: <20210611114418.28772-13-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210611114418.28772-1-f.ebner@proxmox.com> References: <20210611114418.28772-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.835 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [values.name] Subject: [pve-devel] [PATCH v6 proxmox-widget-toolkit 1/3] add UI for APT repositories X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Jun 2021 11:44:44 -0000 Signed-off-by: Fabian Ebner --- No changes from v5. src/Makefile | 1 + src/node/APTRepositories.js | 268 ++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 src/node/APTRepositories.js diff --git a/src/Makefile b/src/Makefile index 9e3ad4e..9c00b98 100644 --- a/src/Makefile +++ b/src/Makefile @@ -67,6 +67,7 @@ JSSRC= \ window/ACMEDomains.js \ window/FileBrowser.js \ node/APT.js \ + node/APTRepositories.js \ node/NetworkEdit.js \ node/NetworkView.js \ node/DNSEdit.js \ diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js new file mode 100644 index 0000000..71b141c --- /dev/null +++ b/src/node/APTRepositories.js @@ -0,0 +1,268 @@ +Ext.define('apt-repolist', { + extend: 'Ext.data.Model', + fields: [ + 'Path', + 'Number', + 'FileType', + 'Enabled', + 'Comment', + 'Types', + 'URIs', + 'Suites', + 'Components', + 'Options', + ], +}); + +Ext.define('Proxmox.node.APTRepositoriesErrors', { + extend: 'Ext.grid.GridPanel', + + xtype: 'proxmoxNodeAPTRepositoriesErrors', + + title: gettext('Errors'), + + store: {}, + + viewConfig: { + stripeRows: false, + getRowClass: () => 'proxmox-invalid-row', + }, + + columns: [ + { + header: gettext('File'), + dataIndex: 'path', + renderer: function(value, cell, record) { + return "" + value; + }, + width: 350, + }, + { + header: gettext('Error'), + dataIndex: 'error', + flex: 1, + }, + ], +}); + +Ext.define('Proxmox.node.APTRepositoriesGrid', { + extend: 'Ext.grid.GridPanel', + + xtype: 'proxmoxNodeAPTRepositoriesGrid', + + title: gettext('APT Repositories'), + + sortableColumns: false, + + columns: [ + { + header: gettext('Enabled'), + dataIndex: 'Enabled', + renderer: Proxmox.Utils.format_enabled_toggle, + width: 90, + }, + { + header: gettext('Types'), + dataIndex: 'Types', + renderer: function(types, cell, record) { + return types.join(' '); + }, + width: 100, + }, + { + header: gettext('URIs'), + dataIndex: 'URIs', + renderer: function(uris, cell, record) { + return uris.join(' '); + }, + width: 350, + }, + { + header: gettext('Suites'), + dataIndex: 'Suites', + renderer: function(suites, cell, record) { + return suites.join(' '); + }, + width: 130, + }, + { + header: gettext('Components'), + dataIndex: 'Components', + renderer: function(components, cell, record) { + return components.join(' '); + }, + width: 170, + }, + { + header: gettext('Options'), + dataIndex: 'Options', + renderer: function(options, cell, record) { + if (!options) { + return ''; + } + + let filetype = record.data.FileType; + let text = ''; + + options.forEach(function(option) { + let key = option.Key; + if (filetype === 'list') { + let values = option.Values.join(','); + text += `${key}=${values} `; + } else if (filetype === 'sources') { + let values = option.Values.join(' '); + text += `${key}: ${values}
`; + } else { + throw "unkown file type"; + } + }); + return text; + }, + flex: 1, + }, + { + header: gettext('Comment'), + dataIndex: 'Comment', + flex: 2, + }, + ], + + initComponent: function() { + let me = this; + + let store = Ext.create('Ext.data.Store', { + model: 'apt-repolist', + groupField: 'Path', + sorters: [ + { + property: 'Number', + direction: 'ASC', + }, + ], + }); + + let groupingFeature = Ext.create('Ext.grid.feature.Grouping', { + groupHeaderTpl: '{[ "File: " + values.name ]} ({rows.length} ' + + 'repositor{[values.rows.length > 1 ? "ies" : "y"]})', + enableGroupingMenu: false, + }); + + let sm = Ext.create('Ext.selection.RowModel', {}); + + Ext.apply(me, { + store: store, + selModel: sm, + features: [groupingFeature], + }); + + me.callParent(); + }, +}); + +Ext.define('Proxmox.node.APTRepositories', { + extend: 'Ext.panel.Panel', + + xtype: 'proxmoxNodeAPTRepositories', + + digest: undefined, + + viewModel: { + data: { + errorCount: 0, + }, + formulas: { + noErrors: (get) => get('errorCount') === 0, + }, + }, + + items: [ + { + xtype: 'proxmoxNodeAPTRepositoriesErrors', + name: 'repositoriesErrors', + hidden: true, + bind: { + hidden: '{noErrors}', + }, + }, + { + xtype: 'proxmoxNodeAPTRepositoriesGrid', + name: 'repositoriesGrid', + }, + ], + + tbar: [ + { + xtype: 'proxmoxButton', + text: gettext('Reload'), + handler: function() { + let me = this; + me.up('proxmoxNodeAPTRepositories').reload(); + }, + }, + ], + + reload: function() { + let me = this; + let vm = me.getViewModel(); + let repoGrid = me.down('proxmoxNodeAPTRepositoriesGrid'); + let errorGrid = me.down('proxmoxNodeAPTRepositoriesErrors'); + + me.store.load(function(records, operation, success) { + let gridData = []; + let errors = []; + let digest; + + if (success && records.length > 0) { + let data = records[0].data; + let files = data.files; + errors = data.errors; + digest = data.digest; + + files.forEach(function(file) { + for (let n = 0; n < file.repositories.length; n++) { + let repo = file.repositories[n]; + repo.Path = file.path; + repo.Number = n + 1; + gridData.push(repo); + } + }); + } + + me.digest = digest; + + repoGrid.store.loadData(gridData); + + vm.set('errorCount', errors.length); + errorGrid.store.loadData(errors); + }); + }, + + listeners: { + activate: function() { + let me = this; + me.reload(); + }, + }, + + initComponent: function() { + let me = this; + + if (!me.nodename) { + throw "no node name specified"; + } + + let store = Ext.create('Ext.data.Store', { + proxy: { + type: 'proxmox', + url: `/api2/json/nodes/${me.nodename}/apt/repositories`, + }, + }); + + Ext.apply(me, { store: store }); + + Proxmox.Utils.monStoreErrors(me, me.store, true); + + me.callParent(); + }, +}); -- 2.20.1