From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC proxmox-widget-toolkit 1/1] node: apt: spawn a window for adding repository
Date: Wed, 30 Jun 2021 17:07:54 +0200 [thread overview]
Message-ID: <20210630150754.9921-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210630150754.9921-1-f.ebner@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
I couldn't get the validation to work properly and adding a repo
gives an "Unknown Error" (but does add the repo).
src/node/APTRepositories.js | 161 ++++++++++++++++++++++++++----------
1 file changed, 117 insertions(+), 44 deletions(-)
diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js
index 6812d46..43297c9 100644
--- a/src/node/APTRepositories.js
+++ b/src/node/APTRepositories.js
@@ -15,6 +15,92 @@ Ext.define('apt-repolist', {
],
});
+Ext.define('Proxmox.window.APTRepositoryAdd', {
+ extend: 'Proxmox.window.Edit',
+ alias: 'widget.pmxAPTRepositoryAdd',
+
+ isCreate: true,
+ isAdd: true,
+
+ subject: gettext('Repository'),
+
+ initComponent: function() {
+ let me = this;
+
+ if (!me.repoInfo || me.repoInfo.length === 0) {
+ throw "repository information not initialized";
+ }
+
+ let description = Ext.create('Ext.form.field.Display', {
+ fieldLabel: gettext('Description'),
+ name: 'description',
+ });
+
+ let status = Ext.create('Ext.form.field.Display', {
+ fieldLabel: gettext('Status'),
+ name: 'status',
+ renderer: function(value) {
+ let statusText = gettext('Not yet configured');
+ if (value !== '') {
+ statusText = Ext.String.format(
+ '{0}: {1}',
+ gettext('Configured'),
+ value ? gettext('enabled') : gettext('disabled'),
+ );
+ }
+
+ return statusText;
+ },
+ });
+
+ let repoSelector = Ext.create('Proxmox.form.KVComboBox', {
+ fieldLabel: gettext('Repository'),
+ xtype: 'proxmoxKVComboBox',
+ name: 'handle',
+ allowBlank: false,
+ comboItems: me.repoInfo.map(info => [info.handle, info.name]),
+ isValid: function() {
+ const handle = this.value;
+
+ if (!handle) {
+ return false;
+ }
+
+ const info = me.repoInfo.find(elem => elem.handle === handle);
+
+ if (!info) {
+ return false;
+ }
+
+ // not yet configured
+ return info.status === undefined || info.status === null;
+ },
+ listeners: {
+ change: function(f, value) {
+ const info = me.repoInfo.find(elem => elem.handle === value);
+ description.setValue(info.description);
+ status.setValue(info.status);
+ },
+ },
+ });
+
+ repoSelector.setValue(me.repoInfo[0].handle);
+
+ let items = [
+ repoSelector,
+ description,
+ status,
+ ];
+
+ Ext.apply(me, {
+ items: items,
+ repoSelector: repoSelector,
+ });
+
+ me.callParent();
+ },
+});
+
Ext.define('Proxmox.node.APTRepositoriesErrors', {
extend: 'Ext.grid.GridPanel',
@@ -63,10 +149,31 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
},
{
text: gettext('Add'),
- menu: {
- plain: true,
- itemId: "addMenu",
- items: [],
+ id: 'addButton',
+ disabled: true,
+ repoInfo: undefined,
+ handler: function(button, event, record) {
+ Proxmox.Utils.checked_command(() => {
+ let me = this;
+ let panel = me.up('proxmoxNodeAPTRepositories');
+
+ let extraParams = {};
+ if (panel.digest !== undefined) {
+ extraParams.digest = panel.digest;
+ }
+
+ Ext.create('Proxmox.window.APTRepositoryAdd', {
+ repoInfo: me.repoInfo,
+ url: `/api2/json/nodes/${panel.nodename}/apt/repositories`,
+ method: 'PUT',
+ extraRequestParams: extraParams,
+ listeners: {
+ destroy: function() {
+ panel.reload();
+ },
+ },
+ }).show();
+ });
},
},
'-',
@@ -403,8 +510,8 @@ Ext.define('Proxmox.node.APTRepositories', {
let me = this;
let vm = me.getViewModel();
- let menu = me.down('#addMenu');
- menu.removeAll();
+ let addButton = me.down('#addButton');
+ addButton.repoInfo = [];
for (const standardRepo of standardRepos) {
const handle = standardRepo.handle;
@@ -416,45 +523,11 @@ Ext.define('Proxmox.node.APTRepositories', {
vm.set('noSubscriptionRepo', status);
}
- let status_text = '';
- if (status !== undefined && status !== null) {
- status_text = Ext.String.format(
- ' ({0}, {1})',
- gettext('configured'),
- status ? gettext('enabled') : gettext('disabled'),
- );
- }
-
- menu.add({
- text: standardRepo.name + status_text,
- disabled: status !== undefined && status !== null,
- repoHandle: handle,
- handler: function(menuItem) {
- Proxmox.Utils.checked_command(() => {
- let params = {
- handle: menuItem.repoHandle,
- };
-
- if (me.digest !== undefined) {
- params.digest = me.digest;
- }
-
- Proxmox.Utils.API2Request({
- url: `/nodes/${me.nodename}/apt/repositories`,
- method: 'PUT',
- params: params,
- failure: function(response, opts) {
- Ext.Msg.alert(gettext('Error'), response.htmlStatus);
- me.reload();
- },
- success: function(response, opts) {
- me.reload();
- },
- });
- });
- },
- });
+ addButton.repoInfo.push(standardRepo);
+ addButton.digest = me.digest;
}
+
+ addButton.setDisabled(false);
},
reload: function() {
--
2.30.2
next prev parent reply other threads:[~2021-06-30 15:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-30 15:07 [pve-devel] [PATCH-SERIES proxmox-apt/proxmox-widget-toolkit] Spawn a window when adding a repository Fabian Ebner
2021-06-30 15:07 ` [pve-devel] [PATCH proxmox-apt 1/1] standard repos: allow conversion from handle and improve information Fabian Ebner
2021-06-30 18:46 ` [pve-devel] applied: " Thomas Lamprecht
2021-06-30 15:07 ` Fabian Ebner [this message]
2021-06-30 19:31 ` [pve-devel] applied: [RFC proxmox-widget-toolkit 1/1] node: apt: spawn a window for adding repository Thomas Lamprecht
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=20210630150754.9921-3-f.ebner@proxmox.com \
--to=f.ebner@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal