diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js index c7033dca86742030f064690a7950fa62ed7401ef..b80fd017ee2589a824cc453e6e3c376a9a4ddc34 100644 --- a/frontend-js/src/main/js/ServerConnector.js +++ b/frontend-js/src/main/js/ServerConnector.js @@ -1057,7 +1057,7 @@ ServerConnector.getModels = function (projectId) { /** * * @param {string} [projectId] - * @return {Promise<Promise | never>} + * @return {Promise<project>| PromiseLike<Project>} */ ServerConnector.getProject = function (projectId) { var queryParams = {}; diff --git a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js index aa5e8e492d8f4c2a799181150d19971c62de980f..76117bddd8c0b562ad3d83baa044ec0468700c84 100644 --- a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js @@ -41,6 +41,8 @@ function MapsAdminPanel(params) { MapsAdminPanel.prototype = Object.create(AbstractAdminPanel.prototype); MapsAdminPanel.prototype.constructor = MapsAdminPanel; +MapsAdminPanel.AUTO_REFRESH_TIME = 5000; + /** * * @private @@ -91,7 +93,7 @@ MapsAdminPanel.prototype._createMenuRow = function () { name: "refreshProject", content: '<span class="ui-icon ui-icon-refresh"></span> REFRESH', onclick: function () { - return self.onRefreshClicked().then(null, GuiConnector.alert); + return self.onRefreshClicked().catch(GuiConnector.alert); }, xss: false }); @@ -279,6 +281,7 @@ MapsAdminPanel.prototype.setProjects = function (projects) { var self = this; return self.getServerConnector().getLoggedUser().then(function (user) { + var requireUpdate = false; var dataTable = $("[name='projectsTable']", self.getElement()).DataTable(); var data = []; var page = dataTable.page(); @@ -288,9 +291,19 @@ MapsAdminPanel.prototype.setProjects = function (projects) { var rowData = self.projectToTableRow(project, undefined, user); self.addUpdateListener(project, rowData); data.push(rowData); + if (project.getStatus().toLowerCase() !== "ok" && project.getStatus().toLowerCase() !== "failure") { + requireUpdate = true; + } } //it should be simplified, but I couldn't make it work dataTable.clear().rows.add(data).page(page).draw(false).page(page).draw(false); + + if (requireUpdate) { + setTimeout(function () { + logger.debug("Projects auto refresh"); + return self.onRefreshClicked(); + }, MapsAdminPanel.AUTO_REFRESH_TIME); + } }); }; diff --git a/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js b/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js index 37dc06d61f4493f407e2f6fc608b77a7105a4b77..2633963d10a291ecc6a4fb96f351537add1da61a 100644 --- a/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js +++ b/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js @@ -6,7 +6,8 @@ var MapsAdminPanel = require('../../../../main/js/gui/admin/MapsAdminPanel'); var ServerConnector = require('../../ServerConnector-mock'); var logger = require('../../logger'); -var assert = require('assert'); +var chai = require('chai'); +var assert = chai.assert; var Promise = require('bluebird'); function createMapsAdminPanel() { @@ -19,13 +20,40 @@ function createMapsAdminPanel() { describe('MapsAdminPanel', function () { - it('refresh', function () { - var mapTab = createMapsAdminPanel(); - return mapTab.init().then(function () { - return mapTab.onRefreshClicked(); - }).then(function () { - assert.equal(0, logger.getWarnings().length); - return mapTab.destroy(); + describe('refresh', function () { + it('default', function () { + var mapTab = createMapsAdminPanel(); + return mapTab.init().then(function () { + return mapTab.onRefreshClicked(); + }).then(function () { + assert.equal(0, logger.getWarnings().length); + return mapTab.destroy(); + }); + }); + it('with auto refresh', function () { + var mapTab = createMapsAdminPanel(); + var originalFunction = ServerConnector.getProjects; + var calls = 0; + MapsAdminPanel.AUTO_REFRESH_TIME=50; + ServerConnector.getProjects = function(){ + calls++; + var project = helper.createProject(); + project.setStatus("xyz"); + return Promise.resolve([project]); + }; + return mapTab.init().then(function () { + ServerConnector.getProjects = function(){ + calls++; + return Promise.resolve([]); + }; + return Promise.delay(60); + }).then(function () { + assert.ok(calls>=2); + }).finally(function(){ + ServerConnector.getProjects = originalFunction; + MapsAdminPanel.AUTO_REFRESH_TIME=5000; + return mapTab.destroy(); + }); }); }); it('showLogs', function () { diff --git a/frontend-js/src/test/js/helper.js b/frontend-js/src/test/js/helper.js index 7c67cfefb2e40f7b42e2b30a26a808c3f0d77203..3cf543f1ebe6e25d0d26ac9f794f674a546486c3 100644 --- a/frontend-js/src/test/js/helper.js +++ b/frontend-js/src/test/js/helper.js @@ -217,6 +217,7 @@ Helper.prototype.createProject = function (params) { } var result = new Project(); result.setProjectId("testId"); + result.setName(""); result.setId(this.idCounter++); result.addModel(this.createModel()); var overlay = this.createOverlay(result.getModels()[0]);