Skip to content

Commit

Permalink
HZN-956: Migrated js to assets
Browse files Browse the repository at this point in the history
  • Loading branch information
fooker committed Jan 17, 2019
1 parent 0c5470d commit a53687a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 78 deletions.
42 changes: 42 additions & 0 deletions core/web-assets/src/main/assets/js/apps/notifications/index.js
@@ -0,0 +1,42 @@
/**
* @copyright 2016-2019 The OpenNMS Group, Inc.
*/

'use strict';

import Util from 'lib/util';

if ('Notification' in window) {
let notificationSocket = null;

let connect = function () {
notificationSocket = new WebSocket((Util.getBaseHref() + 'notification/stream').replace(/^http/, 'ws'));

notificationSocket.onclose = function () {
setTimeout(connect, 1000);
};
notificationSocket.onerror = function () {
setTimeout(connect, 5000);
};
notificationSocket.onmessage = function (event) {
let message = JSON.parse(event.data);
let notification = new Notification(message.head, {
body: message.body,
icon: Util.getBaseHref() + 'images/o-512.png',
badge: Util.getBaseHref() + 'favicon.ico',
tag: 'opennms:notification:' + message.id
});
};
};

if (Notification.permission === 'granted') {
connect();
} else if (Notification.permission !== 'denied') {
Notification.requestPermission()
.then(function (permission) {
if (permission === 'granted') {
connect();
}
});
}
}
6 changes: 5 additions & 1 deletion opennms-webapp/src/main/webapp/includes/bootstrap-footer.jsp
Expand Up @@ -83,7 +83,11 @@
</footer>

<!-- Browser notification support -->
<jsp:include page="notifications.jsp"/>
<c:if test="${!empty pageContext.request.remoteUser}">
<jsp:include page="/assets/load-assets.jsp" flush="false">
<jsp:param name="asset" value="notifications" />
</jsp:include>
</c:if>
</c:otherwise>
</c:choose>

Expand Down
77 changes: 0 additions & 77 deletions opennms-webapp/src/main/webapp/includes/notifications.jsp

This file was deleted.

0 comments on commit a53687a

Please sign in to comment.