Commit 621ff8d7 by Johannes Stelzer

Add Web Notifications

If an application is changing state while the page is open a desktop notification is shown.
parent d92b66f3
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
......@@ -15,7 +15,17 @@
*/
'use strict';
module.exports = function ($scope, $location, $interval, $q, Application) {
module.exports = function ($scope, $location, $interval, $q, $state, Application, Notification) {
var createNote = function(app) {
var title = app.name + (app.status === 'UP' ? ' is back ' : ' went ') + app.status;
var options = { tag: app.id,
body: 'Instance ' + app.id,
icon: (app.status === 'UP' ? 'img/ok.png' : 'img/error.png'),
timeout: 150000,
url: $state.href('apps.details', {id: app.id}, {absolute: true}) };
Notification.notify(title, options);
};
var getInfo = function (app) {
return app.getInfo()
.success(function (response) {
......@@ -28,9 +38,14 @@ module.exports = function ($scope, $location, $interval, $q, Application) {
});
};
var getHealth = function (app) {
var oldstatus = app.status;
return app.getHealth()
.success(function (response) {
app.status = response.status || 'UP';
if (oldstatus !== undefined && oldstatus !== app.status) {
createNote(app);
}
})
.error(function (response, httpStatus) {
if (httpStatus === 503) {
......@@ -40,6 +55,9 @@ module.exports = function ($scope, $location, $interval, $q, Application) {
} else {
app.status = 'UNKNOWN';
}
if (oldstatus !== undefined && oldstatus !== app.status) {
createNote(app);
}
});
};
var getLogfile = function (app) {
......@@ -65,8 +83,7 @@ module.exports = function ($scope, $location, $interval, $q, Application) {
Application.query(function (applications) {
function refresh(app) {
//find application in known applications and copy state --> less flickering
for (var j = 0; $scope.applications != null && j < $scope.applications
.length; j++) {
for (var j = 0; $scope.applications != null && j < $scope.applications.length; j++) {
if (app.id === $scope.applications[j].id) {
app.info = $scope.applications[j].info;
app.version = $scope.applications[j].version;
......
......@@ -4,9 +4,9 @@ var angular = require('angular');
var springBootAdmin = angular.module('springBootAdmin');
springBootAdmin.factory('Application', require('./application'));
springBootAdmin.service('ApplicationLogging', require('./applicationLogging'));
springBootAdmin.service('ApplicationJMX', require('./applicationJmx'));
springBootAdmin.service('Abbreviator', require('./abbreviator'));
springBootAdmin.service('jolokia', require('./jolokia'));
springBootAdmin.service('MetricsHelper', require('./metricsHelper'));
springBootAdmin.service('Notification', require('./notification'));
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
module.exports = function () {
var granted = false;
if ('Notification' in window) {
granted = (window.Notification.permission === 'granted');
if (!granted && window.Notification.permission !== 'denied') {
window.Notification.requestPermission(function (permission) {
granted = (permission === 'granted');
});
}
}
this.notify = function(title, options) {
if (granted) {
var note = new window.Notification(title, options);
if (options.url !== null) {
note.onclick = function() {
window.focus();
window.open(options.url, '_self');
};
}
if (options.timeout > 0) {
note.onshow = function() {
setTimeout(function() {
note.close();
}, options.timeout);
};
}
}
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment