Commit 7e4928e1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

visible overlays are stored in JS session

parent f573ac5a
......@@ -41,46 +41,8 @@ ServerConnector._overlayMethods = [];
*/
ServerConnector.formIdentifier = "_gmapForm";
/**
* Variable describing when was last transmition of data (location of the map,
* zoom level, etc.) to the server session.
*/
ServerConnector.lastActualization = 0;
ServerConnector._customMap = null;
/**
* Sets list of layouts visualized by javascript.
*/
ServerConnector.setVisibleLayouts = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':visibleLayouts').value = value;
};
/**
* Sends data about coordinates/zoom level etc. to the server. Method checks if
* the transmition is not done to often (at most once per second)
*/
ServerConnector.actualizeSessionData = function() {
var timestamp = new Date().getTime();
// we send the data with at least 1 second time distance
if (timestamp > ServerConnector.lastActualization) {
ServerConnector.lastActualization = timestamp + 1000;
setTimeout(function() {
ServerConnector.actualizeParams();
}, 1000);
}
};
/**
* Sends data about coordinates/zoom level etc. to the server. Sending is
* performed immediatelly.
*
* @see ServerConnector.actualizeSessionData
*/
ServerConnector.actualizeParams = function() {
_actualizeParams();
};
/**
* Sets search query that will be handled by server.
*/
......
......@@ -39,7 +39,21 @@ SessionData.prototype.setSelectedBackgroundOverlay = function(value) {
Cookies.set(key, value + "");
};
SessionData.prototype.getVisibleOverlays = function() {
var key = this.getKey(SessionObjectType.VISIBLE_OVERLAYS);
var value = Cookies.get(key);
if (value === undefined || value === "") {
value = [];
} else {
value = value.split(",");
}
return value;
};
SessionData.prototype.setVisibleOverlays = function(value) {
var key = this.getKey(SessionObjectType.VISIBLE_OVERLAYS);
Cookies.set(key, value + "");
};
SessionData.prototype.setZoomLevel = function(model, value) {
var key = this.getKey(SessionObjectType.ZOOM_LEVEL, [ model.getId() ]);
......
......@@ -3,6 +3,7 @@
var SessionObjectType = {
SHOW_COMMENT : "SHOW_COMMENT",
SELECTED_BACKGROUND_OVERLAY : "SELECTED_BACKGROUND_OVERLAY",
VISIBLE_OVERLAYS : "VISIBLE_OVERLAYS",
CENTER : "CENTER",
ZOOM_LEVEL : "ZOOM_LEVEL",
......
......@@ -87,9 +87,6 @@ function CustomMap(options) {
var commentDialog = new CommentDialog(document.getElementById("feedbackContent"), this);
this.setCommentDialog(commentDialog);
ServerConnector.actualizeSessionData();
}
CustomMap.prototype = Object.create(AbstractCustomMap.prototype);
......@@ -1077,10 +1074,9 @@ CustomMap.prototype.addSelectedLayout = function(identifier) {
resolve();
} else {
self.selectedLayouts[identifier] = true;
ServerConnector.getSessionData(self.getProject()).setVisibleOverlays(self.getSelectedLayouts());
return self.getModel().initLayoutDataByLayoutId(identifier).then(function() {
return self.refreshSelectedLayouts();
}).then(function() {
return ServerConnector.setVisibleLayouts(JSON.stringify(self.getSelectedLayouts()));
}).then(function() {
resolve();
}).catch(function(exception){
......@@ -1123,7 +1119,7 @@ CustomMap.prototype.removeSelectedLayout = function(identifier) {
} else {
this.selectedLayouts[identifier] = false;
this.refreshSelectedLayouts();
ServerConnector.setVisibleLayouts(JSON.stringify(this.getSelectedLayouts()));
ServerConnector.getSessionData(this.getProject()).setVisibleOverlays(this.getSelectedLayouts());
}
};
......
......@@ -100,22 +100,6 @@ ServerConnectorMock.getExportModelId = function() {
return this.exportModelId;
};
ServerConnectorMock.actualizeSessionData = function() {
ServerConnectorMock.callListeners("onActualizeSessionData");
};
ServerConnectorMock.actualizeParams = function() {
ServerConnectorMock.callListeners("onActualizeParams");
};
ServerConnectorMock.setVisibleLayouts = function(value) {
this.visibleLayouts = value;
};
ServerConnectorMock.getVisibleLayouts = function() {
return this.visibleLayouts;
};
ServerConnectorMock.sendClearRequest = function(overlayName) {
ServerConnectorMock.callListeners("onSendClearRequest", overlayName);
};
......
......@@ -26,4 +26,22 @@ describe('SessionData', function() {
assert.notOk(session.getShowComments());
assert.equal(logger.getWarnings().length, 0);
});
it('setVisibleOverlays', function() {
var project = helper.createProject();
var session = new SessionData(project);
var overlays = session.getVisibleOverlays();
assert.ok(overlays);
assert.equal(overlays.length, 0);
session.setVisibleOverlays([1,3]);
overlays = session.getVisibleOverlays();
assert.ok(overlays);
assert.equal(overlays.length, 2);
assert.equal(overlays[0],1);
assert.equal(overlays[1],3);
});
});
......@@ -89,12 +89,25 @@ describe('CustomMap', function() {
map.getModel().addLayout(layout);
return map.addSelectedLayout(layout.getId()).then(function() {
var vLayouts = JSON.parse(ServerConnector.getVisibleLayouts());
var vLayouts = ServerConnector.getSessionData(map.getProject()).getVisibleOverlays();
assert.equal(1, vLayouts.length);
assert.equal(layout.getId(), vLayouts[0]);
});
});
it("removeSelectedLayout", function() {
var map = helper.createCustomMap();
var layout = helper.createLayout();
layout.setInitialized(true);
map.getModel().addLayout(layout);
return map.addSelectedLayout(layout.getId()).then(function() {
map.removeSelectedLayout(layout.getId());
var vLayouts = ServerConnector.getSessionData(map.getProject()).getVisibleOverlays();
assert.equal(0, vLayouts.length);
});
});
it("addSelectedLayout with data download", function() {
var map = helper.createCustomMap();
var layout = helper.createLayout();
......@@ -102,7 +115,7 @@ describe('CustomMap', function() {
map.getModel().addLayout(layout);
return map.addSelectedLayout(layout.getId()).then(function() {
var vLayouts = JSON.parse(ServerConnector.getVisibleLayouts());
var vLayouts = ServerConnector.getSessionData(map.getProject()).getVisibleOverlays();
assert.equal(1, vLayouts.length);
assert.equal(layout.getId(), vLayouts[0]);
......
......@@ -33,7 +33,6 @@
<p:contextMenu id="selectionContextMenu" model="#{exportMB.imageExportMenu}" for="gmapElement"/>
<h:inputHidden id="selectedPolygon" value="#{exportMB.selectedPolygon}"/>
<h:inputHidden id="visibleLayouts" value="#{exportMB.visibleLayouts}"/>
<h:inputHidden id="exportModelId" value="#{exportMB.selectedModelId}"/>
<h:inputHidden id="selectedDrugPolygon" value="#{drugMB.polygon}"/>
......
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