]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/Dashboard.js
mobile quarantine: add dark theme support to the mobile quarantine
[pmg-gui.git] / js / Dashboard.js
index 1fa2ea14a2bf55612c60068b842468d603c865f1..a08e2c90a9aae73a8cd4aefb97c74bfb3c5db8e8 100644 (file)
@@ -1,11 +1,3 @@
-/*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',
@@ -21,7 +13,7 @@ Ext.define('PMG.Dashboard', {
                width: 300,
                title: gettext('Dashboard Options'),
                layout: {
-                   type: 'auto'
+                   type: 'auto',
                },
                items: [{
                    xtype: 'form',
@@ -36,7 +28,7 @@ Ext.define('PMG.Dashboard', {
                        minValue: 1,
                        maxValue: 24,
                        value: viewModel.get('hours'),
-                       fieldLabel: gettext('Hours to show')
+                       fieldLabel: gettext('Hours to show'),
                    }],
                    buttons: [{
                        text: gettext('Save'),
@@ -47,9 +39,9 @@ Ext.define('PMG.Dashboard', {
                            var hours = win.down('#hours').getValue();
                            me.setHours(hours, true);
                            win.close();
-                       }
-                   }]
-               }]
+                       },
+                   }],
+               }],
            }).show();
        },
 
@@ -60,7 +52,7 @@ Ext.define('PMG.Dashboard', {
            viewModel.notify();
 
            Ext.Array.forEach(['recentmails', 'receivers'], function(item) {
-               viewModel.get(item).load();
+               viewModel.getStore(item).reload();
            });
 
            if (setState) {
@@ -113,6 +105,7 @@ Ext.define('PMG.Dashboard', {
            var mem = 0;
            var hd = 0;
            var count = records.length;
+           var errors = [];
 
            records.forEach(function(item) {
                // subscription level check
@@ -126,15 +119,35 @@ Ext.define('PMG.Dashboard', {
                    subStatus = 0;
                }
 
+               if (item.data.name === Proxmox.NodeName) {
+                   let repoStatus = me.lookup('nodeInfo').down('#repositoryStatus');
+                   repoStatus.setSubscriptionStatus(!!item.data.level);
+               }
+
                // 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');
            subscriptionPanel.setSubStatus(subStatus);
 
+           // the node info already displays this information in case there is no cluster
+           me.lookup('clusterResources').setHidden(records.length === 1);
+
            cpu = cpu/count;
            mem = mem/count;
            hd = hd/count;
@@ -147,6 +160,25 @@ Ext.define('PMG.Dashboard', {
 
            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);
+           }
+       },
+
+       updateRepositoryStatus: function(store, records, success) {
+           if (!success) {
+               return;
+           }
+
+           let me = this;
+           let repoStatus = me.lookup('nodeInfo').down('#repositoryStatus');
+           repoStatus.setRepositoryInfo(records[0].data['standard-repos']);
        },
 
        init: function(view) {
@@ -154,16 +186,17 @@ Ext.define('PMG.Dashboard', {
            var sp = Ext.state.Manager.getProvider();
            var hours = sp.get('dashboard-hours') || 12;
            me.setHours(hours, false);
-       }
+       },
     },
 
     viewModel: {
        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: {
@@ -172,104 +205,116 @@ 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'
+                   url: '/api2/json/config/cluster/status',
                },
                listeners: {
-                   load: 'updateClusterStats'
-               }
+                   load: 'updateClusterStats',
+               },
            },
            recentmails: {
                storeid: 'dash-recent',
                interval: 5000,
                type: 'update',
                autoStart: true,
-               autoLoad: true,
                autoDestroy: true,
                proxy: {
                    type: 'proxmox',
                    url: '/api2/json/statistics/recent',
                    extraParams: {
                        hours: '{hours}',
-                       timespan: '{timespan}'
-                   }
+                       timespan: '{timespan}',
+                   },
                },
                fields: [
                    {
                        type: 'number', name: 'count',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'count_in',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'count_out',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'spam',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'spam_in',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'spam_out',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'virus',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    {
                        type: 'number', name: 'virus_in',
-                       convert: PMG.Utils.convert_field_to_per_min
+                       convert: PMG.Utils.convert_field_to_per_min,
                    },
                    { type: 'integer', name: 'virus_out' },
                    { type: 'integer', name: 'bytes_in' },
                    { type: 'integer', name: 'bytes_out' },
                    { type: 'number', name: 'ptimesum' },
-                   { type: 'date', dateFormat: 'timestamp', name: 'time' }
+                   { type: 'date', dateFormat: 'timestamp', name: 'time' },
                ],
                listeners: {
-                   load: 'updateMailStats'
-               }
+                   load: 'updateMailStats',
+               },
            },
            receivers: {
                storeid: 'dash-receivers',
                interval: 10000,
                type: 'update',
                autoStart: true,
-               autoLoad: true,
                autoDestroy: true,
                proxy: {
                    type: 'proxmox',
                    url: '/api2/json/statistics/recentreceivers',
                    extraParams: {
-                       hours: '{hours}'
-                   }
+                       hours: '{hours}',
+                   },
                },
                fields: [
                    { type: 'integer', name: 'count' },
-                   { type: 'string', name: 'receiver' }
-               ]
-           }
-       }
+                   { type: 'string', name: 'receiver' },
+               ],
+           },
+           repositories: {
+               storeid: 'dash-repositories',
+               type: 'update',
+               interval: 15000,
+               autoStart: true,
+               autoLoad: true,
+               autoDestroy: true,
+               proxy: {
+                   type: 'proxmox',
+                   url: '/api2/json/nodes/localhost/apt/repositories',
+               },
+               listeners: {
+                   load: 'updateRepositoryStatus',
+               },
+           },
+       },
     },
 
     bind: {
        title: gettext('Dashboard') + ' (' +
-           Ext.String.format(gettext('{0} hours'), '{hours}') + ')'
+           Ext.String.format(gettext('{0} hours'), '{hours}') + ')',
     },
 
     layout: {
-       type: 'column'
+       type: 'column',
     },
     border: false,
 
@@ -278,14 +323,14 @@ Ext.define('PMG.Dashboard', {
     defaults: {
        columnWidth: 0.5,
        xtype: 'panel',
-       margin: '0 20 20 0'
+       margin: '0 20 20 0',
     },
 
     tools: [
        {
            type: 'gear',
-           handler: 'openDashboardOptions'
-       }
+           handler: 'openDashboardOptions',
+       },
     ],
 
     scrollable: true,
@@ -298,53 +343,53 @@ Ext.define('PMG.Dashboard', {
            title: gettext('E-Mail Volume'),
            layout: {
                type: 'vbox',
-               align: 'stretch'
+               align: 'stretch',
            },
            defaults: {
                xtype: 'pmgMiniGraph',
                bind: {
-                   store: '{recentmails}'
-               }
+                   store: '{recentmails}',
+               },
            },
            items: [
                {
                    fields: ['count'],
-                   fieldTitles: [ gettext('Mails / min') ],
+                   fieldTitles: [gettext('Mails / min')],
                    seriesConfig: {
-                       colors: [ '#00617F' ],
+                       colors: ['#00617F'],
                        style: {
                            opacity: 0.60,
-                           lineWidth: 1
+                           lineWidth: 1,
                        },
                        highlightCfg: {
                            opacity: 1,
-                           scaling: 1
-                       }
-                   }
+                           scaling: 1,
+                       },
+                   },
                },
                {
                    fields: ['spam'],
-                   fieldTitles: [ gettext('Spam / min') ],
+                   fieldTitles: [gettext('Spam / min')],
                    seriesConfig: {
-                       colors: [ '#E67300' ],
+                       colors: ['#E67300'],
                        style: {
                            opacity: 0.60,
-                           lineWidth: 1
+                           lineWidth: 1,
                        },
                        highlightCfg: {
                            opacity: 1,
-                           scaling: 1
-                       }
-                   }
-               }
-           ]
+                           scaling: 1,
+                       },
+                   },
+               },
+           ],
        },
        {
            xtype: 'container',
            height: 300,
            layout: {
                type: 'vbox',
-               align: 'stretch'
+               align: 'stretch',
            },
            items: [
                {
@@ -356,51 +401,29 @@ Ext.define('PMG.Dashboard', {
                        data: {
                            'bytes_in': '{bytes_in}',
                            'bytes_out': '{bytes_out}',
-                           'avg_ptime': '{avg_ptime}'
-                       }
-                   }
+                           'avg_ptime': '{avg_ptime}',
+                       },
+                   },
                },
                {
                    iconCls: 'fa fa-ticket',
-                   title: 'Subscription',
+                   title: gettext('Subscription'),
                    reference: 'subscription',
                    xtype: 'pmgSubscriptionInfo',
                    margin: '10 0 0 0',
-                   height: 110
-               }
-           ]
+                   height: 110,
+               },
+           ],
        },
        {
-           height: 250,
+           xtype: 'pmgNodeInfoPanel',
+           reference: 'nodeInfo',
+           height: 275,
+           bodyPadding: '15 5 15 5',
            iconCls: 'fa fa-tasks',
-           title: 'Node Resources',
-           bodyPadding: '0 20 0 20',
-           layout: {
-               type: 'hbox',
-               align: 'center'
-           },
-           defaults: {
-               xtype: 'proxmoxGauge',
-               spriteFontSize: '20px',
-               flex: 1
-           },
-           items: [
-               {
-                   title: gettext('CPU'),
-                   reference: 'cpu'
-               },
-               {
-                   title: gettext('Memory'),
-                   reference: 'mem'
-               },
-               {
-                   title: gettext('Storage'),
-                   reference: 'hd'
-               }
-           ]
        },
        {
-           height: 250,
+           height: 275,
            iconCls: 'fa fa-list',
            title: gettext('Top Receivers'),
 
@@ -408,16 +431,14 @@ Ext.define('PMG.Dashboard', {
            layout: {
                type: 'vbox',
                pack: 'center',
-               align: 'stretch'
+               align: 'stretch',
            },
            items: [{
                xtype: 'grid',
                bind: {
-                   store: '{receivers}'
+                   store: '{receivers}',
                },
-
                emptyText: gettext('No data in database'),
-
                // remove all borders/lines/headers
                border: false,
                bodyBorder: false,
@@ -426,22 +447,52 @@ Ext.define('PMG.Dashboard', {
                columnLines: false,
                rowLines: false,
                viewConfig: {
-                   stripeRows: false
+                   stripeRows: false,
                },
-
                columns: [
                    {
                        dataIndex: 'receiver',
                        flex: 1,
-                       text: gettext('Receiver')
+                       text: gettext('Receiver'),
                    },
                    {
                        dataIndex: 'count',
                        align: 'right',
-                       text: gettext('Count')
-                   }
-               ]
-           }]
-       }
-    ]
+                       text: gettext('Count'),
+                   },
+               ],
+           }],
+       },
+       {
+           height: 250,
+           iconCls: 'fa fa-tasks',
+           title: gettext('Cluster Resources (average)'),
+           reference: 'clusterResources',
+           hidden: true,
+           bodyPadding: '0 20 0 20',
+           layout: {
+               type: 'hbox',
+               align: 'center',
+           },
+           defaults: {
+               xtype: 'proxmoxGauge',
+               spriteFontSize: '20px',
+               flex: 1,
+           },
+           items: [
+               {
+                   title: gettext('CPU'),
+                   reference: 'cpu',
+               },
+               {
+                   title: gettext('Memory'),
+                   reference: 'mem',
+               },
+               {
+                   title: gettext('Storage'),
+                   reference: 'hd',
+               },
+           ],
+       },
+    ],
 });