Skip to content

Commit

Permalink
Merge pull request #914 from nclsHart/webui-ongoing-alert-counter
Browse files Browse the repository at this point in the history
[Web UI] display ongoing alert counter in favicon
  • Loading branch information
nicolargo committed Sep 11, 2016
2 parents b9881f1 + 82b05c3 commit ba9db27
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 16 deletions.
3 changes: 2 additions & 1 deletion glances/outputs/static/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dependencies": {
"angular": "^1.5.8",
"angular-route": "^1.5.8",
"lodash": "^4.13.1"
"lodash": "^4.13.1",
"favico.js": "^0.3.10"
}
}
14 changes: 14 additions & 0 deletions glances/outputs/static/js/services/core/favicon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
glancesApp.service('favicoService', function() {

var favico = new Favico({
animation : 'none'
});

this.badge = function(nb) {
favico.badge(nb);
};

this.reset = function() {
favico.reset();
};
});
2 changes: 1 addition & 1 deletion glances/outputs/static/js/services/core/glances_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ glancesApp.service('GlancesStats', function($http, $injector, $q, GlancesPlugin)
'alert': 'GlancesPluginAlert',
'cpu': 'GlancesPluginCpu',
'diskio': 'GlancesPluginDiskio',
'irq' : 'GlancesPluginIrq',
'irq' : 'GlancesPluginIrq',
'docker': 'GlancesPluginDocker',
'ip': 'GlancesPluginIp',
'fs': 'GlancesPluginFs',
Expand Down
10 changes: 9 additions & 1 deletion glances/outputs/static/js/services/plugins/glances_alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ glancesApp.service('GlancesPluginAlert', function () {
, minutes = parseInt((duration / (1000 * 60)) % 60)
, hours = parseInt((duration / (1000 * 60 * 60)) % 24);

alert.duration = _.padLeft(hours, 2, '0') + ":" + _.padLeft(minutes, 2, '0') + ":" + _.padLeft(seconds, 2, '0');
alert.duration = _.padStart(hours, 2, '0') + ":" + _.padStart(minutes, 2, '0') + ":" + _.padStart(seconds, 2, '0');
}

_alerts.push(alert);
Expand All @@ -47,4 +47,12 @@ glancesApp.service('GlancesPluginAlert', function () {
this.count = function () {
return _alerts.length;
};

this.hasOngoingAlerts = function () {
return _.filter(_alerts, { 'ongoing': true }).length > 0;
};

this.countOngoingAlerts = function () {
return _.filter(_alerts, { 'ongoing': true }).length;
}
});
14 changes: 10 additions & 4 deletions glances/outputs/static/js/stats_controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
glancesApp.controller('statsController', function ($scope, $rootScope, $interval, GlancesStats, help, arguments) {
glancesApp.controller('statsController', function ($scope, $rootScope, $interval, GlancesStats, help, arguments, favicoService) {
$scope.help = help;
$scope.arguments = arguments;

Expand All @@ -24,7 +24,7 @@ glancesApp.controller('statsController', function ($scope, $rootScope, $interval
$scope.statsAlert = GlancesStats.getPlugin('alert');
$scope.statsCpu = GlancesStats.getPlugin('cpu');
$scope.statsDiskio = GlancesStats.getPlugin('diskio');
$scope.statsIrq = GlancesStats.getPlugin('irq');
$scope.statsIrq = GlancesStats.getPlugin('irq');
$scope.statsDocker = GlancesStats.getPlugin('docker');
$scope.statsFs = GlancesStats.getPlugin('fs');
$scope.statsFolders = GlancesStats.getPlugin('folders');
Expand All @@ -46,6 +46,12 @@ glancesApp.controller('statsController', function ($scope, $rootScope, $interval

$rootScope.title = $scope.statsSystem.hostname + ' - Glances';

if ($scope.statsAlert.hasOngoingAlerts()) {
favicoService.badge($scope.statsAlert.countOngoingAlerts());
} else {
favicoService.reset();
}

$scope.is_disconnected = false;
$scope.dataLoaded = true;
}, function() {
Expand Down Expand Up @@ -104,8 +110,8 @@ glancesApp.controller('statsController', function ($scope, $rootScope, $interval
// d => Show/hide disk I/O stats
$scope.arguments.disable_diskio = !$scope.arguments.disable_diskio;
break;
case $event.shiftKey && $event.keyCode == keycodes.Q:
// R => Show/hide IRQ
case $event.shiftKey && $event.keyCode == keycodes.Q:
// Q => Show/hide IRQ
$scope.arguments.disable_irq = !$scope.arguments.disable_irq;
break;
case !$event.shiftKey && $event.keyCode == keycodes.f:
Expand Down
2 changes: 1 addition & 1 deletion glances/outputs/static/public/js/main.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions glances/outputs/static/public/js/vendor.js

Large diffs are not rendered by default.

0 comments on commit ba9db27

Please sign in to comment.