Commit f86df197 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

project is obtained via promise in minerva.create

parent 87227b44
...@@ -23,10 +23,7 @@ var Promise = require("bluebird"); ...@@ -23,10 +23,7 @@ var Promise = require("bluebird");
var logger = require('./logger'); var logger = require('./logger');
function processUrlGetParams(params) { function processUrlGetParams(params) {
var project = params.project; var project = params.getProject();
if (project === undefined) {
project = params.getProject();
}
var sessionData = ServerConnector.getSessionData(project); var sessionData = ServerConnector.getSessionData(project);
var modelId = project.getModel().getId(); var modelId = project.getModel().getId();
...@@ -184,17 +181,11 @@ function createResult(customMap) { ...@@ -184,17 +181,11 @@ function createResult(customMap) {
return dbOverlay.getIdentifiedElements().then(function(identifiedElements) { return dbOverlay.getIdentifiedElements().then(function(identifiedElements) {
return getFullElements(customMap, identifiedElements); return getFullElements(customMap, identifiedElements);
}); });
} },
}; };
} }
function create(params) { function initGlobals(params) {
if (!(params instanceof CustomMapOptions)) {
params = new CustomMapOptions(params);
}
var element = params.getElement();
if (global.GuiConnector === undefined) { if (global.GuiConnector === undefined) {
global.GuiConnector = OriginalGuiConnector; global.GuiConnector = OriginalGuiConnector;
global.ServerConnector = OriginalServerConnector; global.ServerConnector = OriginalServerConnector;
...@@ -208,6 +199,10 @@ function create(params) { ...@@ -208,6 +199,10 @@ function create(params) {
logger.warn("global GuiConnector found"); logger.warn("global GuiConnector found");
} }
}
function verifyBrowser(params) {
var browser = functions.browser; var browser = functions.browser;
if (browser.name === "IE") { if (browser.name === "IE") {
if (browser.version <= 8 || browser.compatibilityMode) { if (browser.version <= 8 || browser.compatibilityMode) {
...@@ -218,53 +213,78 @@ function create(params) { ...@@ -218,53 +213,78 @@ function create(params) {
+ "Select the 'Compatibility View' settings option. \n" + "Select the 'Compatibility View' settings option. \n"
+ "Make sure the 'Display all websites in Compatibility View' check box is unchecked and that the 'Compatibility View; list of websites is cleared.\n" + "Make sure the 'Display all websites in Compatibility View' check box is unchecked and that the 'Compatibility View; list of websites is cleared.\n"
+ "\n" + "Alternatively, please, use other browsers: Chrome, Firefox or Safari."; + "\n" + "Alternatively, please, use other browsers: Chrome, Firefox or Safari.";
alert(message); GuiConnector.alert(message);
logger.warn(message);
} }
} }
}
processUrlGetParams(params); function getProject(params) {
if (params.getProject() !== undefined) {
return Promise.resolve(params.getProject());
} else {
return ServerConnector.getProject(params.getProjectId());
}
};
createDivStructure(element); function create(params) {
params.setElement(functions.getElementByName(element, "mapDiv")); var customMap;
var leftPanel;
var topMenu;
var legend, mapContextMenu, selectionContextMenu;
if (!(params instanceof CustomMapOptions)) {
params = new CustomMapOptions(params);
}
return getProject(params).then(function(project) {
params.setProject(project);
var element = params.getElement();
var customMap = new CustomMap(params); initGlobals(params);
new DbOverlayCollection({ verifyBrowser();
map : customMap
});
var leftPanel = new LeftPanel({ processUrlGetParams(params);
element : functions.getElementByName(element, "leftPanelDiv"),
customMap : customMap
});
var topMenu = new TopMenu({ createDivStructure(element);
element : functions.getElementByName(element, "menuDiv"), params.setElement(functions.getElementByName(element, "mapDiv"));
customMap : customMap
});
var legend = new Legend({ customMap = new CustomMap(params);
element : functions.getElementByName(element, "legendDiv"),
customMap : customMap
});
var mapContextMenu = new MapContextMenu({ new DbOverlayCollection({
element : functions.getElementByName(element, "contextMenu"), map : customMap
customMap : customMap });
});
customMap.setContextMenu(mapContextMenu);
var selectionContextMenu = new SelectionContextMenu({ leftPanel = new LeftPanel({
element : functions.getElementByName(element, "selectionContextMenu"), element : functions.getElementByName(element, "leftPanelDiv"),
customMap : customMap customMap : customMap
}); });
customMap.setSelectionContextMenu(selectionContextMenu);
topMenu = new TopMenu({
element : functions.getElementByName(element, "menuDiv"),
customMap : customMap
});
legend = new Legend({
element : functions.getElementByName(element, "legendDiv"),
customMap : customMap
});
topMenu.setLegend(legend); mapContextMenu = new MapContextMenu({
topMenu.setLeftPanel(leftPanel); element : functions.getElementByName(element, "contextMenu"),
customMap : customMap
});
customMap.setContextMenu(mapContextMenu);
return customMap.init().then(function() { selectionContextMenu = new SelectionContextMenu({
element : functions.getElementByName(element, "selectionContextMenu"),
customMap : customMap
});
customMap.setSelectionContextMenu(selectionContextMenu);
topMenu.setLegend(legend);
topMenu.setLeftPanel(leftPanel);
return customMap.init();
}).then(function() {
return insertGoogleAnalyticsCode(customMap); return insertGoogleAnalyticsCode(customMap);
}).then(function() { }).then(function() {
return leftPanel.init(); return leftPanel.init();
......
...@@ -31,9 +31,12 @@ describe('minerva global', function() { ...@@ -31,9 +31,12 @@ describe('minerva global', function() {
}); });
it('create', function() { it('create', function() {
var options = helper.createOptions(); var options = null;
return ServerConnector.getProject().then(function(project) {
options = helper.createCustomMapOptions(project);
return minerva.create(options).then(function(result) { return minerva.create(options);
}).then(function(result) {
assert.ok(result); assert.ok(result);
assert.equal(logger.getWarnings().length, 0); assert.equal(logger.getWarnings().length, 0);
}); });
...@@ -69,18 +72,23 @@ describe('minerva global', function() { ...@@ -69,18 +72,23 @@ describe('minerva global', function() {
it("contructor with GET zoom param", function() { it("contructor with GET zoom param", function() {
helper.setUrl("http://test/?zoom=5"); helper.setUrl("http://test/?zoom=5");
var options = helper.createCustomMapOptions(); var options;
return minerva.create(options).then( return ServerConnector.getProject().then(function(project) {
function() { options = helper.createCustomMapOptions(project);
assert.equal(ServerConnector.getSessionData(options.getProject()).getZoomLevel( return minerva.create(options);
options.getProject().getModel()), 5); }).then(function() {
}); var sessionData = ServerConnector.getSessionData(options.getProject());
assert.equal(sessionData.getZoomLevel(options.getProject().getModel()), 5);
});
}); });
it("contructor with GET coord param", function() { it("contructor with GET coord param", function() {
helper.setUrl("http://test/?x=5&y=6"); helper.setUrl("http://test/?x=5&y=6");
var options = helper.createCustomMapOptions(); var options;
return minerva.create(options).then(function() { return ServerConnector.getProject().then(function(project) {
options = helper.createCustomMapOptions(project);
return minerva.create(options);
}).then(function() {
var center = ServerConnector.getSessionData(options.getProject()).getCenter(options.getProject().getModel()); var center = ServerConnector.getSessionData(options.getProject()).getCenter(options.getProject().getModel());
assert.ok(center instanceof google.maps.Point); assert.ok(center instanceof google.maps.Point);
assert.equal(center.x, 5); assert.equal(center.x, 5);
...@@ -89,68 +97,62 @@ describe('minerva global', function() { ...@@ -89,68 +97,62 @@ describe('minerva global', function() {
}); });
it('create with layout', function() { it('create with layout', function() {
var project = helper.createProject(); var layout;
var project;
var layout = helper.createLayout(); return ServerConnector.getProject().then(function(result) {
layout.setInputDataAvailable(false); project = result;
var layoutName = layout.getName(); var options = helper.createCustomMapOptions(project);
var layoutId = layout.getId();
project.getModel().addLayout(layout);
helper.setUrl("http://test/?layout="+layoutName); layout = project.getModel().getLayouts()[1];
var options = helper.createOptions(project); helper.setUrl("http://test/?layout=" + layout.getName());
return minerva.create(options).then(function(result) { return minerva.create(options);
}).then(function(result) {
assert.ok(result); assert.ok(result);
// input file is not available so it's the background // input file is not available so it's the background
return result.getVisibleDataOverlays(); return result.getVisibleDataOverlays();
}).then(function(visibleDataOverlays){ }).then(function(visibleDataOverlays) {
// input file is available so it's not the background file but overlay // input file is available so it's not the background file but overlay
assert.equal(visibleDataOverlays.length, 0); assert.equal(visibleDataOverlays.length, 0);
assert.equal(ServerConnector.getSessionData(project).getSelectedBackgroundOverlay(), layoutId); assert.equal(ServerConnector.getSessionData(project).getSelectedBackgroundOverlay(), layout.getId());
assert.equal(logger.getWarnings().length, 0); assert.equal(logger.getWarnings().length, 0);
}); });
}); });
it('create with layout from session data', function() { it('create with layout from session data', function() {
var project = helper.createProject(); var layout;
return ServerConnector.getProject().then(function(project) {
var layout = helper.createLayout(); var options = helper.createCustomMapOptions(project);
layout.setInputDataAvailable(false);
project.getModel().addLayout(layout);
ServerConnector.getSessionData(project).setSelectedBackgroundOverlay(layout.getId()); layout = project.getModel().getLayouts()[1];
var options = helper.createOptions(project); ServerConnector.getSessionData(project).setSelectedBackgroundOverlay(layout.getId());
return minerva.create(options).then(function(customMap){ return minerva.create(options);
assert.equal(ServerConnector.getSessionData().getSelectedBackgroundOverlay(),layout.getId()); }).then(function(customMap) {
assert.equal(ServerConnector.getSessionData().getSelectedBackgroundOverlay(), layout.getId());
}); });
}); });
it('create with layout 2', function() { it('create with layout 2', function() {
var project = helper.createProject();
var layout = helper.createLayout(); var layout = helper.createLayout();
layout.setInputDataAvailable(true); layout.setInputDataAvailable(true);
// disable upload of the data from server // disable upload of the data from server
layout.setInitialized(true); layout.setInitialized(true);
var layoutName = layout.getName(); var layoutName = layout.getName();
project.getModel().addLayout(layout); helper.setUrl("http://test/?layout=" + layoutName);
helper.setUrl("http://test/?layout="+layoutName); return ServerConnector.getProject().then(function(project) {
project.getModel().addLayout(layout);
var options = helper.createOptions(project);
return minerva.create(options).then(function(result) { var options = helper.createCustomMapOptions(project);
return minerva.create(options);
}).then(function(result) {
assert.ok(result); assert.ok(result);
return result.getVisibleDataOverlays(); return result.getVisibleDataOverlays();
}).then(function(visibleDataOverlays){ }).then(function(visibleDataOverlays) {
// input file is available so it's not the background file but overlay // input file is available so it's not the background file but overlay
assert.equal(visibleDataOverlays.length, 1); assert.equal(visibleDataOverlays.length, 1);
assert.equal(logger.getWarnings().length, 0); assert.equal(logger.getWarnings().length, 0);
...@@ -160,12 +162,10 @@ describe('minerva global', function() { ...@@ -160,12 +162,10 @@ describe('minerva global', function() {
it('create with search overlay and GET search param', function() { it('create with search overlay and GET search param', function() {
helper.setUrl("http://test/?search=s1"); helper.setUrl("http://test/?search=s1");
var project = helper.createProject(); return ServerConnector.getProject().then(function(project) {
project.getModel().setId(15781); var options = helper.createCustomMapOptions(project);
return minerva.create(options);
var options = helper.createOptions(project); }).then(function(result) {
return minerva.create(options).then(function(result) {
return result.getHiglightedElements("search"); return result.getHiglightedElements("search");
}).then(function(elements) { }).then(function(elements) {
assert.ok(elements.length > 0); assert.ok(elements.length > 0);
...@@ -178,25 +178,20 @@ describe('minerva global', function() { ...@@ -178,25 +178,20 @@ describe('minerva global', function() {
var project = helper.createProject(); var project = helper.createProject();
project.getModel().setId(15781); project.getModel().setId(15781);
var options = helper.createOptions(project); return ServerConnector.getProject().then(function(project) {
var options = helper.createCustomMapOptions(project);
return minerva.create(options);
});
it("contructor with touch enabled", function() { return minerva.create(options);
var options = helper.createCustomMapOptions();
options.setCustomTouchInterface(true);
return minerva.create(options).then(function(result) {
assert.ok(result);
}); });
}); });
it('test if authentication problem is passed properly from constructor', function() { it("contructor with touch enabled", function() {
var options = helper.createCustomMapOptions(); return ServerConnector.getProject().then(function(project) {
options.setCustomTouchInterface(true); var options = helper.createCustomMapOptions(project);
ServerConnector.getSessionData(null).setToken("UNKNOWN_TOKEN_ID"); options.setCustomTouchInterface(true);
return minerva.create(options).catch(function(exception){ return minerva.create(options).then(function(result) {
assert.ok(exception.message.indexOf("UNKNOWN_TOKEN_ID")>=0); assert.ok(result);
});
}); });
}); });
...@@ -207,8 +202,8 @@ describe('minerva global', function() { ...@@ -207,8 +202,8 @@ describe('minerva global', function() {
options.setDebug(true); options.setDebug(true);
return minerva.create(options); return minerva.create(options);
}).then(function(result) { }).then(function(result) {
result.addListener("search", "onSearch", function(elements){ result.addListener("search", "onSearch", function(elements) {
callbackOk = elements.length>0; callbackOk = elements.length > 0;
}); });
return result.customMap.getOverlayByName("search").searchByQuery("s1"); return result.customMap.getOverlayByName("search").searchByQuery("s1");
}).then(function() { }).then(function() {
......
{"version":"0","idObject":18115,"name":"UNKNOWN DISEASE MAP","projectId":"complex_model_with_images","description":"","map":{"name":"main","idObject":19397,"tileSize":256,"width":495,"height":357,"minZoom":2,"maxZoom":3,"layouts":[{"modelId":19397,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_nested0","creator":"","inputDataAvailable":"false","idObject":17987},{"modelId":19397,"name":"Network","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_normal0","creator":"","inputDataAvailable":"false","idObject":17988},{"modelId":19397,"name":"Empty","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_empty0","creator":"","inputDataAvailable":"false","idObject":17989}],"submodels":[{"name":"s2","idObject":19400,"tileSize":256,"width":451,"height":253,"minZoom":2,"maxZoom":3,"layouts":[{"modelId":19400,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_nested2","creator":"","inputDataAvailable":"false","idObject":17984},{"modelId":19400,"name":"Network","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_normal2","creator":"","inputDataAvailable":"false","idObject":17985},{"modelId":19400,"name":"Empty","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_empty2","creator":"","inputDataAvailable":"false","idObject":17986}],"submodels":[],"centerLatLng":{"lat":79.19006423440219,"lng":-135.09977827050997},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":78.0903352323621,"lng":-90.0}},{"name":"s3","idObject":19399,"tileSize":256,"width":421,"height":315,"minZoom":2,"maxZoom":3,"layouts":[{"modelId":19399,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_nested3","creator":"","inputDataAvailable":"false","idObject":17978},{"modelId":19399,"name":"Network","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_normal3","creator":"","inputDataAvailable":"false","idObject":17979},{"modelId":19399,"name":"Empty","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_empty3","creator":"","inputDataAvailable":"false","idObject":17980}],"submodels":[],"centerLatLng":{"lat":79.19139766235872,"lng":-135.10688836104512},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":74.06362505154212,"lng":-90.0}},{"name":"s1","idObject":19398,"tileSize":256,"width":571,"height":276,"minZoom":2,"maxZoom":4,"layouts":[{"modelId":19398,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_nested1","creator":"","inputDataAvailable":"false","idObject":17981},{"modelId":19398,"name":"Network","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_normal1","creator":"","inputDataAvailable":"false","idObject":17982},{"modelId":19398,"name":"Empty","status":"Not available","progress":"0.00","directory":"fbdbe43de73fe38f62889b89cb863adb/_empty1","creator":"","inputDataAvailable":"false","idObject":17983}],"submodels":[],"centerLatLng":{"lat":79.18613072613702,"lng":-135.07880910683014},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":79.44906929997262,"lng":-90.0}}],"centerLatLng":{"lat":79.18840067864828,"lng":-135.0909090909091},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":74.71754541589858,"lng":-90.0}},"overviewImageViews":[{"filename":"fbdbe43de73fe38f62889b89cb863adb/sub_image.png","width":963,"height":639,"links":[{"polygon":[{"x":200.0,"y":200.0},{"x":200.0,"y":400.0},{"x":400.0,"y":400.0},{"x":400.0,"y":200.0}],"zoomLevel":1,"latLng":{"lat":84.89177465079632,"lng":-161.8181818181818},"modelLinkId":19397,"type":"OverviewModelLink","idObject":2369}],"idObject":1261},{"filename":"fbdbe43de73fe38f62889b89cb863adb/test.png","width":963,"height":639,"links":[{"polygon":[{"x":10.0,"y":10.0},{"x":100.0,"y":10.0},{"x":100.0,"y":100.0},{"x":10.0,"y":100.0}],"imageLinkId":1261,"type":"OverviewImageLink","idObject":2370},{"polygon":[{"x":200.0,"y":200.0},{"x":200.0,"y":400.0},{"x":400.0,"y":400.0},{"x":400.0,"y":200.0}],"zoomLevel":0,"latLng":{"lat":84.89177465079632,"lng":-178.1818181818182},"modelLinkId":19397,"type":"OverviewModelLink","idObject":2371}],"idObject":1262}],"topOverviewImage":{"filename":"fbdbe43de73fe38f62889b89cb863adb/test.png","width":963,"height":639,"links":[{"polygon":[{"x":10.0,"y":10.0},{"x":100.0,"y":10.0},{"x":100.0,"y":100.0},{"x":10.0,"y":100.0}],"imageLinkId":1261,"type":"OverviewImageLink","idObject":2370},{"polygon":[{"x":200.0,"y":200.0},{"x":200.0,"y":400.0},{"x":400.0,"y":400.0},{"x":400.0,"y":200.0}],"zoomLevel":0,"latLng":{"lat":84.89177465079632,"lng":-178.1818181818182},"modelLinkId":19397,"type":"OverviewModelLink","idObject":2371}],"idObject":1262}}
\ No newline at end of file
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
<wb-module deploy-name="MapViewer-rest-api"> <wb-module deploy-name="MapViewer-rest-api">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/> <wb-resource deploy-path="/" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/src/test/resources"/>
</wb-module> </wb-module>
</project-modules> </project-modules>
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