Commit 2e2ed619 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

SessionData refactored to be created with project param

parent 770650a7
......@@ -1107,9 +1107,9 @@ ServerConnector.getLightAliases = function(aliasIds, projectId) {
return this.getAliases(aliasIds,projectId,"id,bounds,modelId");
};
ServerConnector.getSessionData = function() {
ServerConnector.getSessionData = function(project) {
if (this._sessionData===undefined) {
this._sessionData = new SessionData();
this._sessionData = new SessionData(project);
}
return this._sessionData;
};
......
......@@ -4,28 +4,56 @@ var SessionObjectType = require('./SessionObjectType');
var Cookies = require('js-cookie');
function SessionData() {
function SessionData(project) {
if (project === undefined) {
throw new Error("Project must be passed as an argument");
}
this.setProject(project);
}
SessionData.prototype.setProject = function(project) {
this._project = project;
}
SessionData.prototype.getProjectId = function(project) {
return this._project.getProjectId();
}
SessionData.prototype.getShowComments = function() {
return Cookies.get(SessionObjectType.SHOW_COMMENT) === "true";
var key = this.getKey(SessionObjectType.SHOW_COMMENT);
console.log("GET:",key,Cookies.get(key));
return Cookies.get(key) === "true";
};
SessionData.prototype.setShowComments = function(value) {
Cookies.set(SessionObjectType.SHOW_COMMENT, value + "");
var key = this.getKey(SessionObjectType.SHOW_COMMENT);
console.log(key,value);
Cookies.set(key, value + "");
};
SessionData.prototype.setZoomLevel = function(project, model, value) {
Cookies.set(SessionObjectType.ZOOM_LEVEL + "_" + project.getProjectId() + "_" + model.getId(), value + "");
SessionData.prototype.setZoomLevel = function(model, value) {
var key = this.getKey(SessionObjectType.ZOOM_LEVEL, [ model.getId() ]);
Cookies.set(key, value + "");
};
SessionData.prototype.getZoomLevel = function(project, model) {
var value = Cookies.get(SessionObjectType.ZOOM_LEVEL + "_" + project.getProjectId() + "_" + model.getId());
SessionData.prototype.getZoomLevel = function(model) {
var key = this.getKey(SessionObjectType.ZOOM_LEVEL, [ model.getId() ]);
var value = Cookies.get(key);
if (value !== undefined) {
value = parseInt(value);
}
return value;
};
SessionData.prototype.getKey = function(type, args) {
if (type === undefined) {
throw new Error("Undefined type");
}
if (args === undefined) {
args = [];
}
return type + "_" + this.getProjectId() + "_" + args.join("_");
};
module.exports = SessionData;
......@@ -373,7 +373,7 @@ CustomMap.prototype.createMapMenu = function() {
commentCheckbox.onclick = (function() {
var selfButton = commentCheckbox;
return function() {
ServerConnector.getSessionData().setShowComments(selfButton.checked);
ServerConnector.getSessionData(selfMap.getProject()).setShowComments(selfButton.checked);
if (selfButton.checked) {
document.getElementById('refresh_comments_button').style.display = 'inline';
} else {
......@@ -454,7 +454,7 @@ CustomMap.prototype.refreshComments = function() {
if (this.overlayCollections.hasOwnProperty(overlayName) && overlayName === "comment") {
var collection = this.overlayCollections[overlayName];
self.clearOverlayCollection(collection);
if (ServerConnector.getSessionData().getShowComments()) {
if (ServerConnector.getSessionData(self.getProject()).getShowComments()) {
return collection.refresh().then(function(){
return self.renderOverlayCollection({overlayCollection:collection});
});
......@@ -694,17 +694,17 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
var customMapSelf = this;
// listener for changing zoom level
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
ServerConnector.getSessionData().setZoomLevel(customMapSelf.getProject(),customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
ServerConnector.getSessionData(customMapSelf.getProject()).setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
ServerConnector.actualizeSessionData();
});
// if we have zoom level data stored in session then restore it
var level = ServerConnector.getSessionData().getZoomLevel(this.getProject(),this.getModel());
var level = ServerConnector.getSessionData(customMapSelf.getProject()).getZoomLevel(this.getModel());
if (parseInt(level) > 0) {
level = parseInt(level);
this.getGoogleMap().setZoom(level);
} else {
ServerConnector.getSessionData().setZoomLevel(customMapSelf.getProject(),customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
ServerConnector.getSessionData(customMapSelf.getProject()).setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom());
}
// listener for changing location of the map (moving left/reght/top/bottom
......
......@@ -24,7 +24,7 @@ function processUrlGetParams(params) {
ServerConnector.setCenterCoordinateY(GuiConnector.getParams["y"]);
}
if (GuiConnector.getParams["zoom"] !== undefined) {
ServerConnector.getSessionData().setZoomLevel(project,project.getModel(),GuiConnector.getParams["zoom"]);
ServerConnector.getSessionData(project).setZoomLevel(project.getModel(),GuiConnector.getParams["zoom"]);
}
}
}
......
......@@ -18,7 +18,8 @@ describe('SessionData', function() {
});
it('setShowComments', function() {
var session = new SessionData();
var project = helper.createProject();
var session = new SessionData(project);
session.setShowComments(true);
assert.ok(session.getShowComments());
session.setShowComments(false);
......
......@@ -539,7 +539,7 @@ describe('CustomMap', function() {
it("showComments", function() {
var map = helper.createCustomMap();
map.getControl(ControlType.COMMENT_CHECKBOX).click();
assert.ok(ServerConnector.getSessionData().getShowComments());
assert.ok(ServerConnector.getSessionData(map.getProject()).getShowComments());
});
it("refreshComments", function() {
......
......@@ -30,7 +30,7 @@ describe('minerva global', function() {
var options = helper.createCustomMapOptions();
GuiConnector.getParams["zoom"] = "5";
return minerva.create(options).then(function(result) {
assert.equal(ServerConnector.getSessionData().getZoomLevel(options.getProject(), options.getProject().getModel()), 5);
assert.equal(ServerConnector.getSessionData(options.getProject()).getZoomLevel(options.getProject().getModel()), 5);
});
});
......
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