[pve-devel] [PATCH manager v2 06/11] ui: ceph/ServiceList: refactor controller out
Dominik Csapak
d.csapak at proxmox.com
Mon Oct 25 16:01:33 CEST 2021
we want to reuse that controller type by overriding some functionality
in the future, so factor it out.
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
www/manager6/ceph/ServiceList.js | 302 ++++++++++++++++---------------
1 file changed, 153 insertions(+), 149 deletions(-)
diff --git a/www/manager6/ceph/ServiceList.js b/www/manager6/ceph/ServiceList.js
index 86cdcc8f..d5ba2efa 100644
--- a/www/manager6/ceph/ServiceList.js
+++ b/www/manager6/ceph/ServiceList.js
@@ -44,172 +44,176 @@ Ext.define('PVE.CephCreateService', {
},
});
-Ext.define('PVE.node.CephServiceList', {
- extend: 'Ext.grid.GridPanel',
- xtype: 'pveNodeCephServiceList',
-
- onlineHelp: 'chapter_pveceph',
- emptyText: gettext('No such service configured.'),
-
- stateful: true,
+Ext.define('PVE.node.CephServiceController', {
+ extend: 'Ext.app.ViewController',
+ alias: 'controller.CephServiceList',
- // will be called when the store loads
- storeLoadCallback: Ext.emptyFn,
- // if set to true, does shows the ceph install mask if needed
- showCephInstallMask: false,
+ render_version: function(value, metadata, rec) {
+ if (value === undefined) {
+ return '';
+ }
+ let view = this.getView();
+ let host = rec.data.host, nodev = [0];
+ if (view.nodeversions[host] !== undefined) {
+ nodev = view.nodeversions[host].version.parts;
+ }
- controller: {
- xclass: 'Ext.app.ViewController',
+ let icon = '';
+ if (PVE.Utils.compare_ceph_versions(view.maxversion, nodev) > 0) {
+ icon = PVE.Utils.get_ceph_icon_html('HEALTH_UPGRADE');
+ } else if (PVE.Utils.compare_ceph_versions(nodev, value) > 0) {
+ icon = PVE.Utils.get_ceph_icon_html('HEALTH_OLD');
+ } else if (view.mixedversions) {
+ icon = PVE.Utils.get_ceph_icon_html('HEALTH_OK');
+ }
+ return icon + value;
+ },
- render_version: function(value, metadata, rec) {
- if (value === undefined) {
- return '';
+ getMaxVersions: function(store, records, success) {
+ if (!success || records.length < 1) {
+ return;
+ }
+ let me = this;
+ let view = me.getView();
+
+ view.nodeversions = records[0].data.node;
+ view.maxversion = [];
+ view.mixedversions = false;
+ for (const [_nodename, data] of Object.entries(view.nodeversions)) {
+ let res = PVE.Utils.compare_ceph_versions(data.version.parts, view.maxversion);
+ if (res !== 0 && view.maxversion.length > 0) {
+ view.mixedversions = true;
}
- let view = this.getView();
- let host = rec.data.host, nodev = [0];
- if (view.nodeversions[host] !== undefined) {
- nodev = view.nodeversions[host].version.parts;
+ if (res > 0) {
+ view.maxversion = data.version.parts;
}
+ }
+ },
- let icon = '';
- if (PVE.Utils.compare_ceph_versions(view.maxversion, nodev) > 0) {
- icon = PVE.Utils.get_ceph_icon_html('HEALTH_UPGRADE');
- } else if (PVE.Utils.compare_ceph_versions(nodev, value) > 0) {
- icon = PVE.Utils.get_ceph_icon_html('HEALTH_OLD');
- } else if (view.mixedversions) {
- icon = PVE.Utils.get_ceph_icon_html('HEALTH_OK');
- }
- return icon + value;
- },
+ init: function(view) {
+ if (view.pveSelNode) {
+ view.nodename = view.pveSelNode.data.node;
+ }
+ if (!view.nodename) {
+ throw "no node name specified";
+ }
- getMaxVersions: function(store, records, success) {
- if (!success || records.length < 1) {
- return;
- }
- let me = this;
- let view = me.getView();
-
- view.nodeversions = records[0].data.node;
- view.maxversion = [];
- view.mixedversions = false;
- for (const [_nodename, data] of Object.entries(view.nodeversions)) {
- let res = PVE.Utils.compare_ceph_versions(data.version.parts, view.maxversion);
- if (res !== 0 && view.maxversion.length > 0) {
- view.mixedversions = true;
- }
- if (res > 0) {
- view.maxversion = data.version.parts;
- }
- }
- },
+ if (!view.type) {
+ throw "no type specified";
+ }
- init: function(view) {
- if (view.pveSelNode) {
- view.nodename = view.pveSelNode.data.node;
- }
- if (!view.nodename) {
- throw "no node name specified";
- }
+ view.versionsstore = Ext.create('Proxmox.data.UpdateStore', {
+ autoStart: true,
+ interval: 10000,
+ storeid: `ceph-versions-${view.type}-list${view.nodename}`,
+ proxy: {
+ type: 'proxmox',
+ url: "/api2/json/cluster/ceph/metadata?scope=versions",
+ },
+ });
+ view.versionsstore.on('load', this.getMaxVersions, this);
+ view.on('destroy', view.versionsstore.stopUpdate);
+
+ view.rstore = Ext.create('Proxmox.data.UpdateStore', {
+ autoStart: true,
+ interval: 3000,
+ storeid: `ceph-${view.type}-list${view.nodename}`,
+ model: 'ceph-service-list',
+ proxy: {
+ type: 'proxmox',
+ url: `/api2/json/nodes/${view.nodename}/ceph/${view.type}`,
+ },
+ });
- if (!view.type) {
- throw "no type specified";
- }
+ view.setStore(Ext.create('Proxmox.data.DiffStore', {
+ rstore: view.rstore,
+ sorters: [{ property: 'name' }],
+ }));
- view.versionsstore = Ext.create('Proxmox.data.UpdateStore', {
- autoStart: true,
- interval: 10000,
- storeid: `ceph-versions-${view.type}-list${view.nodename}`,
- proxy: {
- type: 'proxmox',
- url: "/api2/json/cluster/ceph/metadata?scope=versions",
- },
- });
- view.versionsstore.on('load', this.getMaxVersions, this);
- view.on('destroy', view.versionsstore.stopUpdate);
-
- view.rstore = Ext.create('Proxmox.data.UpdateStore', {
- autoStart: true,
- interval: 3000,
- storeid: `ceph-${view.type}-list${view.nodename}`,
- model: 'ceph-service-list',
- proxy: {
- type: 'proxmox',
- url: `/api2/json/nodes/${view.nodename}/ceph/${view.type}`,
- },
- });
+ if (view.storeLoadCallback) {
+ view.rstore.on('load', view.storeLoadCallback, this);
+ }
+ view.on('destroy', view.rstore.stopUpdate);
- view.setStore(Ext.create('Proxmox.data.DiffStore', {
- rstore: view.rstore,
- sorters: [{ property: 'name' }],
- }));
+ if (view.showCephInstallMask) {
+ PVE.Utils.monitor_ceph_installed(view, view.rstore, view.nodename, true);
+ }
+ },
- if (view.storeLoadCallback) {
- view.rstore.on('load', view.storeLoadCallback, this);
- }
- view.on('destroy', view.rstore.stopUpdate);
+ service_cmd: function(rec, cmd) {
+ let view = this.getView();
+ if (!rec.data.host) {
+ Ext.Msg.alert(gettext('Error'), "entry has no host");
+ return;
+ }
+ Proxmox.Utils.API2Request({
+ url: `/nodes/${rec.data.host}/ceph/${cmd}`,
+ method: 'POST',
+ params: { service: view.type + '.' + rec.data.name },
+ success: function(response, options) {
+ Ext.create('Proxmox.window.TaskProgress', {
+ autoShow: true,
+ upid: response.result.data,
+ taskDone: () => view.rstore.load(),
+ });
+ },
+ failure: (response, _opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
+ });
+ },
+ onChangeService: function(button) {
+ let me = this;
+ let record = me.getView().getSelection()[0];
+ me.service_cmd(record, button.action);
+ },
- if (view.showCephInstallMask) {
- PVE.Utils.monitor_ceph_installed(view, view.rstore, view.nodename, true);
- }
- },
+ showSyslog: function() {
+ let view = this.getView();
+ let rec = view.getSelection()[0];
+ let service = `ceph-${view.type}@${rec.data.name}`;
+ Ext.create('Ext.window.Window', {
+ title: `${gettext('Syslog')}: ${service}`,
+ autoShow: true,
+ modal: true,
+ width: 800,
+ height: 400,
+ layout: 'fit',
+ items: [{
+ xtype: 'proxmoxLogView',
+ url: `/api2/extjs/nodes/${rec.data.host}/syslog?service=${encodeURIComponent(service)}`,
+ log_select_timespan: 1,
+ }],
+ });
+ },
- service_cmd: function(rec, cmd) {
- let view = this.getView();
- if (!rec.data.host) {
- Ext.Msg.alert(gettext('Error'), "entry has no host");
- return;
- }
- Proxmox.Utils.API2Request({
- url: `/nodes/${rec.data.host}/ceph/${cmd}`,
- method: 'POST',
- params: { service: view.type + '.' + rec.data.name },
- success: function(response, options) {
- Ext.create('Proxmox.window.TaskProgress', {
- autoShow: true,
- upid: response.result.data,
- taskDone: () => view.rstore.load(),
- });
- },
- failure: (response, _opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
- });
- },
- onChangeService: function(button) {
- let me = this;
- let record = me.getView().getSelection()[0];
- me.service_cmd(record, button.action);
- },
+ onCreate: function() {
+ let view = this.getView();
+ Ext.create('PVE.CephCreateService', {
+ autoShow: true,
+ nodename: view.nodename,
+ subject: view.getTitle(),
+ type: view.type,
+ taskDone: () => view.rstore.load(),
+ });
+ },
+});
- showSyslog: function() {
- let view = this.getView();
- let rec = view.getSelection()[0];
- let service = `ceph-${view.type}@${rec.data.name}`;
- Ext.create('Ext.window.Window', {
- title: `${gettext('Syslog')}: ${service}`,
- autoShow: true,
- modal: true,
- width: 800,
- height: 400,
- layout: 'fit',
- items: [{
- xtype: 'proxmoxLogView',
- url: `/api2/extjs/nodes/${rec.data.host}/syslog?service=${encodeURIComponent(service)}`,
- log_select_timespan: 1,
- }],
- });
- },
+Ext.define('PVE.node.CephServiceList', {
+ extend: 'Ext.grid.GridPanel',
+ xtype: 'pveNodeCephServiceList',
- onCreate: function() {
- let view = this.getView();
- Ext.create('PVE.CephCreateService', {
- autoShow: true,
- nodename: view.nodename,
- subject: view.getTitle(),
- type: view.type,
- taskDone: () => view.rstore.load(),
- });
- },
- },
+ onlineHelp: 'chapter_pveceph',
+ emptyText: gettext('No such service configured.'),
+
+ stateful: true,
+
+ // will be called when the store loads
+ storeLoadCallback: Ext.emptyFn,
+
+ // if set to true, does shows the ceph install mask if needed
+ showCephInstallMask: false,
+
+ controller: 'CephServiceList',
tbar: [
{
--
2.30.2
More information about the pve-devel
mailing list