]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/Dashboard.js
Dashboard: remove autoLoad from updateStores
[pmg-gui.git] / js / Dashboard.js
index 60fbebb50f7aff02935bf13ec208811b5e7c941e..378efae4c4197a4485fb3f8ae438e91bdd4def27 100644 (file)
@@ -1,3 +1,11 @@
+/*global Proxmox*/
+/*jslint confusion: true*/
+/* load is a function and string
+ * hours is a number and string
+ * timespan is a number and string
+ * bind is a function and object
+ * handler is a function and string
+ */
 Ext.define('PMG.Dashboard', {
     extend: 'Ext.panel.Panel',
     xtype: 'pmgDashboard',
@@ -17,7 +25,7 @@ Ext.define('PMG.Dashboard', {
                },
                items: [{
                    xtype: 'form',
-                   bodyPadding: 10,
+                   bodyPadding: '10 10 10 10',
                    defaultButton: 'savebutton',
                    items: [{
                        xtype: 'proxmoxintegerfield',
@@ -41,7 +49,7 @@ Ext.define('PMG.Dashboard', {
                            win.close();
                        }
                    }]
-               }],
+               }]
            }).show();
        },
 
@@ -52,7 +60,7 @@ Ext.define('PMG.Dashboard', {
            viewModel.notify();
 
            Ext.Array.forEach(['recentmails', 'receivers'], function(item) {
-               viewModel.get(item).load();
+               viewModel.getStore(item).reload();
            });
 
            if (setState) {
@@ -72,7 +80,7 @@ Ext.define('PMG.Dashboard', {
            var bytes_in = 0;
            var bytes_out = 0;
            var ptime = 0;
-           var avg_ptime = 0;
+           var avg_ptime = 'N/A';
 
            records.forEach(function(item) {
                bytes_in += item.data.bytes_in;
@@ -83,12 +91,12 @@ Ext.define('PMG.Dashboard', {
            });
 
            if (count) {
-               avg_ptime = (ptime/count).toFixed(2);
+               avg_ptime = (ptime/count).toFixed(2) + " s";
            }
 
            viewModel.set('bytes_in', Proxmox.Utils.format_size(bytes_in));
            viewModel.set('bytes_out', Proxmox.Utils.format_size(bytes_out));
-           viewModel.set('avg_ptime', avg_ptime + " s");
+           viewModel.set('avg_ptime', avg_ptime);
        },
 
        updateClusterStats: function(store, records, success) {
@@ -105,6 +113,7 @@ Ext.define('PMG.Dashboard', {
            var mem = 0;
            var hd = 0;
            var count = records.length;
+           var errors = [];
 
            records.forEach(function(item) {
                // subscription level check
@@ -119,9 +128,21 @@ Ext.define('PMG.Dashboard', {
                }
 
                // resources count
-               cpu += item.data.cpu;
-               mem += (item.data.memory.used/item.data.memory.total);
-               hd += (item.data.rootfs.used/item.data.rootfs.total);
+               cpu += item.data.cpu || 0;
+
+               var memory = item.data.memory || { used: 0, total: 1 };
+               mem += (memory.used/memory.total);
+
+               var rootfs = item.data.rootfs || { used: 0, total: 1 };
+               hd += (rootfs.used/rootfs.total);
+
+               if (item.data.conn_error && count > 1) {
+                   count--;
+                   errors.push({
+                       name: item.data.name,
+                       msg: item.data.conn_error
+                   });
+               }
            });
 
            var subscriptionPanel = me.lookup('subscription');
@@ -134,11 +155,20 @@ Ext.define('PMG.Dashboard', {
            var cpuPanel = me.lookup('cpu');
            cpuPanel.updateValue(cpu);
 
-           var memPanel = me.lookup('mem')
+           var memPanel = me.lookup('mem');
            memPanel.updateValue(mem);
 
-           var hdPanel = me.lookup('hd')
+           var hdPanel = me.lookup('hd');
            hdPanel.updateValue(hd);
+
+           if (errors.length && !viewmodel.get('error_shown')) {
+               var text = "";
+               errors.forEach(function(error) {
+                   text += error.name + ':<br>' + error.msg + '<br>';
+               });
+               Ext.Msg.alert(gettext('Error'), text);
+               viewmodel.set('error_shown', true);
+           }
        },
 
        init: function(view) {
@@ -153,9 +183,10 @@ Ext.define('PMG.Dashboard', {
        data: {
            timespan: 300, // in seconds
            hours: 12, // in hours
+           error_shown: false,
            'bytes_in': 0,
            'bytes_out': 0,
-           'avg_ptime': 0.0,
+           'avg_ptime': 0.0
        },
 
        stores: {
@@ -164,9 +195,9 @@ Ext.define('PMG.Dashboard', {
                type: 'update',
                interval: 5000,
                autoStart: true,
-               autoLoad: true,
                autoDestroy: true,
                proxy: {
+                   extraParams: { list_single_node: 1 },
                    type: 'proxmox',
                    url: '/api2/json/config/cluster/status'
                },
@@ -179,7 +210,6 @@ Ext.define('PMG.Dashboard', {
                interval: 5000,
                type: 'update',
                autoStart: true,
-               autoLoad: true,
                autoDestroy: true,
                proxy: {
                    type: 'proxmox',
@@ -237,13 +267,12 @@ Ext.define('PMG.Dashboard', {
                interval: 10000,
                type: 'update',
                autoStart: true,
-               autoLoad: true,
                autoDestroy: true,
                proxy: {
                    type: 'proxmox',
                    url: '/api2/json/statistics/recentreceivers',
                    extraParams: {
-                       hours: '{hours}',
+                       hours: '{hours}'
                    }
                },
                fields: [
@@ -259,7 +288,9 @@ Ext.define('PMG.Dashboard', {
            Ext.String.format(gettext('{0} hours'), '{hours}') + ')'
     },
 
-    layout: 'column',
+    layout: {
+       type: 'column'
+    },
     border: false,
 
     bodyPadding: '20 0 0 20',
@@ -287,7 +318,7 @@ Ext.define('PMG.Dashboard', {
            title: gettext('E-Mail Volume'),
            layout: {
                type: 'vbox',
-               align: 'stretch',
+               align: 'stretch'
            },
            defaults: {
                xtype: 'pmgMiniGraph',
@@ -308,8 +339,8 @@ Ext.define('PMG.Dashboard', {
                        highlightCfg: {
                            opacity: 1,
                            scaling: 1
-                       },
-                   },
+                       }
+                   }
                },
                {
                    fields: ['spam'],
@@ -323,9 +354,9 @@ Ext.define('PMG.Dashboard', {
                        highlightCfg: {
                            opacity: 1,
                            scaling: 1
-                       },
-                   },
-               },
+                       }
+                   }
+               }
            ]
        },
        {
@@ -333,7 +364,7 @@ Ext.define('PMG.Dashboard', {
            height: 300,
            layout: {
                type: 'vbox',
-               align: 'stretch',
+               align: 'stretch'
            },
            items: [
                {
@@ -343,11 +374,11 @@ Ext.define('PMG.Dashboard', {
                    height: 180,
                    bind: {
                        data: {
-                           'in': '{bytes_in}',
-                           'out': '{bytes_out}',
-                           'ptime': '{avg_ptime}'
+                           'bytes_in': '{bytes_in}',
+                           'bytes_out': '{bytes_out}',
+                           'avg_ptime': '{avg_ptime}'
                        }
-                   },
+                   }
                },
                {
                    iconCls: 'fa fa-ticket',
@@ -355,14 +386,14 @@ Ext.define('PMG.Dashboard', {
                    reference: 'subscription',
                    xtype: 'pmgSubscriptionInfo',
                    margin: '10 0 0 0',
-                   height: 110,
+                   height: 110
                }
            ]
        },
        {
            height: 250,
            iconCls: 'fa fa-tasks',
-           title: 'Node Resources',
+           title: gettext('Node Resources'),
            bodyPadding: '0 20 0 20',
            layout: {
                type: 'hbox',
@@ -393,7 +424,7 @@ Ext.define('PMG.Dashboard', {
            iconCls: 'fa fa-list',
            title: gettext('Top Receivers'),
 
-           bodyPadding: 20,
+           bodyPadding: '20 20 20 20',
            layout: {
                type: 'vbox',
                pack: 'center',
@@ -415,7 +446,7 @@ Ext.define('PMG.Dashboard', {
                columnLines: false,
                rowLines: false,
                viewConfig: {
-                   stripeRows: false,
+                   stripeRows: false
                },
 
                columns: [