[pve-devel] [RFC manager 1/2] add getNodes function to PVEResource store
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Sep 22 18:14:44 CEST 2016
Add the getNodes function to the periodically asynchronous updated
PVEResource store. This allows a component to get the node data
directly, without making an API call and waiting that it's finished,
the data is also up to date.
A usage example would be:
var data = PVE.data.ResourceStore.getNodes();
var store = Ext.create('Ext.data.Store', {
fields: [ 'node', 'mem', 'cpu', ... ], // or a model
data: data,
proxy: {
type: 'memory',
reader: {type: 'json'}
},
...
});
I'll use it in a later patch to avoid two asynchrony store loads
where I'd have logic in place for the case that either one finishes
first, this function helps me to avoid such logic while achieving
the same functionallity.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
www/manager6/data/ResourceStore.js | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/www/manager6/data/ResourceStore.js b/www/manager6/data/ResourceStore.js
index 7e5725c..cc68b84 100644
--- a/www/manager6/data/ResourceStore.js
+++ b/www/manager6/data/ResourceStore.js
@@ -8,6 +8,20 @@ Ext.define('PVE.data.ResourceStore', {
return (me.findExact('vmid', parseInt(vmid, 10)) >= 0);
},
+ // returns the cached data from all nodes
+ getNodes: function() {
+ var me = this;
+
+ var nodes = [];
+ me.each(function(record) {
+ if (record.get('type') == "node") {
+ nodes.push( record.getData() );
+ }
+ });
+
+ return nodes;
+ },
+
constructor: function(config) {
// fixme: how to avoid those warnings
/*jslint confusion: true */
--
2.1.4
More information about the pve-devel
mailing list