node: apt: spawn a window for adding repository
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
3dfb0b9a2b
commit
21860ea45c
@ -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', {
|
Ext.define('Proxmox.node.APTRepositoriesErrors', {
|
||||||
extend: 'Ext.grid.GridPanel',
|
extend: 'Ext.grid.GridPanel',
|
||||||
|
|
||||||
@ -63,10 +149,31 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: gettext('Add'),
|
text: gettext('Add'),
|
||||||
menu: {
|
id: 'addButton',
|
||||||
plain: true,
|
disabled: true,
|
||||||
itemId: "addMenu",
|
repoInfo: undefined,
|
||||||
items: [],
|
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 me = this;
|
||||||
let vm = me.getViewModel();
|
let vm = me.getViewModel();
|
||||||
|
|
||||||
let menu = me.down('#addMenu');
|
let addButton = me.down('#addButton');
|
||||||
menu.removeAll();
|
addButton.repoInfo = [];
|
||||||
|
|
||||||
for (const standardRepo of standardRepos) {
|
for (const standardRepo of standardRepos) {
|
||||||
const handle = standardRepo.handle;
|
const handle = standardRepo.handle;
|
||||||
@ -416,45 +523,11 @@ Ext.define('Proxmox.node.APTRepositories', {
|
|||||||
vm.set('noSubscriptionRepo', status);
|
vm.set('noSubscriptionRepo', status);
|
||||||
}
|
}
|
||||||
|
|
||||||
let status_text = '';
|
addButton.repoInfo.push(standardRepo);
|
||||||
if (status !== undefined && status !== null) {
|
addButton.digest = me.digest;
|
||||||
status_text = Ext.String.format(
|
|
||||||
' ({0}, {1})',
|
|
||||||
gettext('configured'),
|
|
||||||
status ? gettext('enabled') : gettext('disabled'),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.add({
|
addButton.setDisabled(false);
|
||||||
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();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
reload: function() {
|
reload: function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user