public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v5 proxmox-widget-toolkit 07/23] add UI for APT repositories
Date: Fri, 28 May 2021 16:29:46 +0200	[thread overview]
Message-ID: <20210528143002.16190-8-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210528143002.16190-1-f.ebner@proxmox.com>

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v4:
    * move code from activation listener into a reload() helper to be re-useable
    * add a reload button

 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 "<i class='pve-grid-fa fa fa-fw " +
+		    "fa-exclamation-triangle'></i>" + 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}<br>`;
+		    } 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





  parent reply	other threads:[~2021-05-28 14:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 14:29 [pve-devel] [PATCH-SERIES v5] APT repositories API/UI Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-apt 01/23] initial commit Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-apt 02/23] add files for Debian packaging Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-apt 03/23] add functions to check for Proxmox repositories Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-apt 04/23] add check_repositories function Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-apt 05/23] add common_digest helper Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-apt 06/23] add replace_suite function and constants for the current/next stable suites Fabian Ebner
2021-05-31 13:06   ` [pve-devel] [pbs-devel] " Fabian Ebner
2021-05-28 14:29 ` Fabian Ebner [this message]
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-widget-toolkit 08/23] APT repositories: add warnings Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-widget-toolkit 09/23] add upgrade button Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-backup 10/23] depend on new proxmox-apt crate Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-backup 11/23] api: apt: add repositories call Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-backup 12/23] ui: add APT repositories Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [PATCH v5 proxmox-backup 13/23] add check_repositories_call Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [RFC v5 proxmox-backup 14/23] RFC: add upgrade_repositories call Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [RFC v5 pve-rs 15/23] add cargo config Fabian Ebner
2021-05-31 12:53   ` [pve-devel] [pbs-devel] " Wolfgang Bumiller
2021-05-31 13:12     ` Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [RFC v5 pve-rs 16/23] add perlmod crate with initial APT module Fabian Ebner
2021-05-31 12:55   ` [pve-devel] [pbs-devel] " Wolfgang Bumiller
2021-05-31 13:17     ` Fabian Ebner
2021-05-31 13:07   ` Wolfgang Bumiller
2021-05-28 14:29 ` [pve-devel] [RFC v5 pve-rs 17/23] add files for Debian packaging Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [RFC v5 pve-rs 18/23] update .gitignore Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [RFC v5 pve-rs 19/23] RFC: add upgrade_repositories wrapper Fabian Ebner
2021-05-28 14:29 ` [pve-devel] [RFC v5 pve-manager 20/23] api: apt: add call to list repositories Fabian Ebner
2021-05-28 14:30 ` [pve-devel] [RFC v5 pve-manager 21/23] ui: add panel for listing APT repositories Fabian Ebner
2021-05-28 14:30 ` [pve-devel] [RFC v5 pve-manager 22/23] api: apt: add call for repository check Fabian Ebner
2021-05-28 14:30 ` [pve-devel] [RFC v5 pve-manager 23/23] api: apt: add upgrade repos call Fabian Ebner

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=20210528143002.16190-8-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pbs-devel@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal