]> git.proxmox.com Git - pve-manager.git/commitdiff
add getNodes function to PVEResource store
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 6 Oct 2016 09:52:51 +0000 (11:52 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 7 Oct 2016 06:29:22 +0000 (08:29 +0200)
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@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
www/manager6/data/ResourceStore.js

index 7e5725cffec7d619c8585a21a3afbdab6e0f9b3d..cc68b8457133badab72b0f6bfa6f8157936a9910 100644 (file)
@@ -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 */