diff --git a/frontend-js/src/main/js/gui/OverviewDialog.js b/frontend-js/src/main/js/gui/OverviewDialog.js index 6dabef39ae9f7b5ad09b411fc7a198a7d47ef14c..40d2761929c3bf75b728a3c54add46637ec453c4 100644 --- a/frontend-js/src/main/js/gui/OverviewDialog.js +++ b/frontend-js/src/main/js/gui/OverviewDialog.js @@ -36,7 +36,7 @@ OverviewDialog.prototype.constructor = OverviewDialog; /** * - * @param {number} overviewImageId + * @param {number} [overviewImageId] */ OverviewDialog.prototype.showOverview = function (overviewImageId) { var self = this; diff --git a/frontend-js/src/main/js/gui/topMenu/TopMenu.js b/frontend-js/src/main/js/gui/topMenu/TopMenu.js index 36ede3d8dcef938195261193605f4c4ada57b4b8..b58b5134414688d5b45cd16165f12e95eaa9a309 100644 --- a/frontend-js/src/main/js/gui/topMenu/TopMenu.js +++ b/frontend-js/src/main/js/gui/topMenu/TopMenu.js @@ -5,6 +5,7 @@ var Promise = require("bluebird"); /* exported logger */ var AbstractGuiElement = require('../AbstractGuiElement'); +var ConfigurationType = require('../../ConfigurationType'); var GuiConnector = require('../../GuiConnector'); var OverviewDialog = require('../OverviewDialog'); var PanelControlElementType = require('../PanelControlElementType'); @@ -31,6 +32,12 @@ function TopMenu(params) { var self = this; self._createGui(); + + self._cronFunction = function () { + return self.checkIfSessionIsGoingToExpire(); + }; + + setInterval(self._cronFunction, 1000); } TopMenu.prototype = Object.create(AbstractGuiElement.prototype); @@ -270,6 +277,7 @@ TopMenu.prototype.destroy = function () { if (self._overviewDialog !== undefined) { self._overviewDialog.destroy(); } + clearInterval(self._cronFunction); return Promise.resolve(); }; @@ -286,4 +294,35 @@ TopMenu.prototype.toggleLegend = function () { } }; +/** + * + * @returns {Promise} + */ +TopMenu.prototype.checkIfSessionIsGoingToExpire = function () { + var self = this; + var lastAccessTimestamp = self.getServerConnector().getSessionData().getLastRequestTimeStamp(); + var sessionInactivityOption = self.getConfiguration().getOption(ConfigurationType.SESSION_LENGTH); + var sessionInactivityLength = parseInt(sessionInactivityOption.getValue()); + var sessionExpireTimestamp = lastAccessTimestamp + sessionInactivityLength; + var currentTimestamp = Math.floor(Date.now() / 1000); + + //if session is going to expire in 10 minutes show information + if (sessionExpireTimestamp - currentTimestamp < 10 * 60) { + self.showSessionExpire(sessionExpireTimestamp - currentTimestamp); + } + + //if session expired 10 seconds ago force logout + if (sessionExpireTimestamp < currentTimestamp - 10) { + return self.getServerConnector().logout(); + } + return Promise.resolve(); +}; + +/** + * + */ +TopMenu.prototype.showSessionExpire = function (timeInSeconds) { + console.log("Session is going to expire in " + timeInSeconds + " seconds"); +}; + module.exports = TopMenu; \ No newline at end of file diff --git a/frontend-js/src/main/js/map/data/Project.js b/frontend-js/src/main/js/map/data/Project.js index 82cab1d4c59fd1809fdb3a0cc446c24267783e32..16884ab0d22979a3879a7e35a587e81094e2fa4e 100644 --- a/frontend-js/src/main/js/map/data/Project.js +++ b/frontend-js/src/main/js/map/data/Project.js @@ -298,7 +298,11 @@ Project.prototype.getTopOverviewImage = function () { * @param {OverviewImage} topOverviewImage */ Project.prototype.setTopOverviewImage = function (topOverviewImage) { - this._topOverviewImage = topOverviewImage; + if (topOverviewImage === null) { + this._topOverviewImage = undefined; + } else { + this._topOverviewImage = topOverviewImage; + } }; /** diff --git a/frontend-js/src/main/js/minerva.js b/frontend-js/src/main/js/minerva.js index 3d524d5e6d9c9bacf17c8467349967ce23692d68..6cdf12cd52563064b0c7238a16b6b56be47a9260 100644 --- a/frontend-js/src/main/js/minerva.js +++ b/frontend-js/src/main/js/minerva.js @@ -389,7 +389,9 @@ function create(params) { topMenu = new TopMenu({ element: functions.getElementByClassName(element, "minerva-top-menu"), - customMap: customMap + customMap: customMap, + configuration: params.getConfiguration(), + project: params.getProject() }); legend = new Legend({ diff --git a/frontend-js/src/test/js/gui/topMenu/TopMenu-test.js b/frontend-js/src/test/js/gui/topMenu/TopMenu-test.js index a09060318b5b5c00e21ce577d4d1e0092ad4b9c6..90843d5592b0a5795a2e2c8697f352e5b531bc99 100644 --- a/frontend-js/src/test/js/gui/topMenu/TopMenu-test.js +++ b/frontend-js/src/test/js/gui/topMenu/TopMenu-test.js @@ -18,7 +18,8 @@ describe('TopMenu', function () { new TopMenu({ element: testDiv, - customMap: map + customMap: map, + configuration: helper.getConfiguration() }); assert.equal(logger.getWarnings().length, 0); @@ -30,7 +31,8 @@ describe('TopMenu', function () { var topMenu = new TopMenu({ element: testDiv, - customMap: map + customMap: map, + configuration: helper.getConfiguration() }); return topMenu.init(); @@ -42,9 +44,14 @@ describe('TopMenu', function () { var topMenu = new TopMenu({ element: testDiv, - customMap: map + customMap: map, + configuration: helper.getConfiguration() + }); + var legend = new Legend({ + element: document.createElement("div"), customMap: map, + configuration: helper.getConfiguration(), + project: map.getProject() }); - var legend = new Legend({element: document.createElement("div"), customMap: map}); topMenu.setLegend(legend); return topMenu.init().then(function () { $("input", testDiv).prop('checked', true);