Commit 6d78051a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

auto refresh function for projects panel implemented

parent 3dd68911
......@@ -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 = {};
......
......@@ -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>&nbsp;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);
}
});
};
......
......@@ -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 () {
......
......@@ -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]);
......
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