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");
var logger = require('./logger');
function processUrlGetParams(params) {
var project = params.project;
if (project === undefined) {
project = params.getProject();
}
var project = params.getProject();
var sessionData = ServerConnector.getSessionData(project);
var modelId = project.getModel().getId();
......@@ -184,17 +181,11 @@ function createResult(customMap) {
return dbOverlay.getIdentifiedElements().then(function(identifiedElements) {
return getFullElements(customMap, identifiedElements);
});
}
},
};
}
function create(params) {
if (!(params instanceof CustomMapOptions)) {
params = new CustomMapOptions(params);
}
var element = params.getElement();
function initGlobals(params) {
if (global.GuiConnector === undefined) {
global.GuiConnector = OriginalGuiConnector;
global.ServerConnector = OriginalServerConnector;
......@@ -208,6 +199,10 @@ function create(params) {
logger.warn("global GuiConnector found");
}
}
function verifyBrowser(params) {
var browser = functions.browser;
if (browser.name === "IE") {
if (browser.version <= 8 || browser.compatibilityMode) {
......@@ -218,53 +213,78 @@ function create(params) {
+ "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"
+ "\n" + "Alternatively, please, use other browsers: Chrome, Firefox or Safari.";
alert(message);
logger.warn(message);
GuiConnector.alert(message);
}
}
}
processUrlGetParams(params);
function getProject(params) {
if (params.getProject() !== undefined) {
return Promise.resolve(params.getProject());
} else {
return ServerConnector.getProject(params.getProjectId());
}
};
createDivStructure(element);
params.setElement(functions.getElementByName(element, "mapDiv"));
function create(params) {
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({
map : customMap
});
verifyBrowser();
var leftPanel = new LeftPanel({
element : functions.getElementByName(element, "leftPanelDiv"),
customMap : customMap
});
processUrlGetParams(params);
var topMenu = new TopMenu({
element : functions.getElementByName(element, "menuDiv"),
customMap : customMap
});
createDivStructure(element);
params.setElement(functions.getElementByName(element, "mapDiv"));
var legend = new Legend({
element : functions.getElementByName(element, "legendDiv"),
customMap : customMap
});
customMap = new CustomMap(params);
var mapContextMenu = new MapContextMenu({
element : functions.getElementByName(element, "contextMenu"),
customMap : customMap
});
customMap.setContextMenu(mapContextMenu);
new DbOverlayCollection({
map : customMap
});
var selectionContextMenu = new SelectionContextMenu({
element : functions.getElementByName(element, "selectionContextMenu"),
customMap : customMap
});
customMap.setSelectionContextMenu(selectionContextMenu);
leftPanel = new LeftPanel({
element : functions.getElementByName(element, "leftPanelDiv"),
customMap : customMap
});
topMenu = new TopMenu({
element : functions.getElementByName(element, "menuDiv"),
customMap : customMap
});
legend = new Legend({
element : functions.getElementByName(element, "legendDiv"),
customMap : customMap
});
topMenu.setLegend(legend);
topMenu.setLeftPanel(leftPanel);
mapContextMenu = new MapContextMenu({
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);
}).then(function() {
return leftPanel.init();
......
......@@ -31,9 +31,12 @@ describe('minerva global', 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.equal(logger.getWarnings().length, 0);
});
......@@ -69,18 +72,23 @@ describe('minerva global', function() {
it("contructor with GET zoom param", function() {
helper.setUrl("http://test/?zoom=5");
var options = helper.createCustomMapOptions();
return minerva.create(options).then(
function() {
assert.equal(ServerConnector.getSessionData(options.getProject()).getZoomLevel(
options.getProject().getModel()), 5);
});
var options;
return ServerConnector.getProject().then(function(project) {
options = helper.createCustomMapOptions(project);
return minerva.create(options);
}).then(function() {
var sessionData = ServerConnector.getSessionData(options.getProject());
assert.equal(sessionData.getZoomLevel(options.getProject().getModel()), 5);
});
});
it("contructor with GET coord param", function() {
helper.setUrl("http://test/?x=5&y=6");
var options = helper.createCustomMapOptions();
return minerva.create(options).then(function() {
var options;
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());
assert.ok(center instanceof google.maps.Point);
assert.equal(center.x, 5);
......@@ -89,68 +97,62 @@ describe('minerva global', function() {
});
it('create with layout', function() {
var project = helper.createProject();
var layout = helper.createLayout();
layout.setInputDataAvailable(false);
var layoutName = layout.getName();
var layoutId = layout.getId();
project.getModel().addLayout(layout);
var layout;
var project;
return ServerConnector.getProject().then(function(result) {
project = result;
var options = helper.createCustomMapOptions(project);
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);
// input file is not available so it's the background
return result.getVisibleDataOverlays();
}).then(function(visibleDataOverlays){
}).then(function(visibleDataOverlays) {
// input file is available so it's not the background file but overlay
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);
});
});
it('create with layout from session data', function() {
var project = helper.createProject();
var layout = helper.createLayout();
layout.setInputDataAvailable(false);
project.getModel().addLayout(layout);
var layout;
return ServerConnector.getProject().then(function(project) {
var options = helper.createCustomMapOptions(project);
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){
assert.equal(ServerConnector.getSessionData().getSelectedBackgroundOverlay(),layout.getId());
return minerva.create(options);
}).then(function(customMap) {
assert.equal(ServerConnector.getSessionData().getSelectedBackgroundOverlay(), layout.getId());
});
});
it('create with layout 2', function() {
var project = helper.createProject();
var layout = helper.createLayout();
layout.setInputDataAvailable(true);
// disable upload of the data from server
layout.setInitialized(true);
var layoutName = layout.getName();
project.getModel().addLayout(layout);
helper.setUrl("http://test/?layout=" + layoutName);
helper.setUrl("http://test/?layout="+layoutName);
var options = helper.createOptions(project);
return ServerConnector.getProject().then(function(project) {
project.getModel().addLayout(layout);
return minerva.create(options).then(function(result) {
var options = helper.createCustomMapOptions(project);
return minerva.create(options);
}).then(function(result) {
assert.ok(result);
return result.getVisibleDataOverlays();
}).then(function(visibleDataOverlays){
}).then(function(visibleDataOverlays) {
// input file is available so it's not the background file but overlay
assert.equal(visibleDataOverlays.length, 1);
assert.equal(logger.getWarnings().length, 0);
......@@ -160,12 +162,10 @@ describe('minerva global', function() {
it('create with search overlay and GET search param', function() {
helper.setUrl("http://test/?search=s1");
var project = helper.createProject();
project.getModel().setId(15781);
var options = helper.createOptions(project);
return minerva.create(options).then(function(result) {
return ServerConnector.getProject().then(function(project) {
var options = helper.createCustomMapOptions(project);
return minerva.create(options);
}).then(function(result) {
return result.getHiglightedElements("search");
}).then(function(elements) {
assert.ok(elements.length > 0);
......@@ -178,25 +178,20 @@ describe('minerva global', function() {
var project = helper.createProject();
project.getModel().setId(15781);
var options = helper.createOptions(project);
return minerva.create(options);
});
return ServerConnector.getProject().then(function(project) {
var options = helper.createCustomMapOptions(project);
it("contructor with touch enabled", function() {
var options = helper.createCustomMapOptions();
options.setCustomTouchInterface(true);
return minerva.create(options).then(function(result) {
assert.ok(result);
return minerva.create(options);
});
});
it('test if authentication problem is passed properly from constructor', function() {
var options = helper.createCustomMapOptions();
options.setCustomTouchInterface(true);
ServerConnector.getSessionData(null).setToken("UNKNOWN_TOKEN_ID");
return minerva.create(options).catch(function(exception){
assert.ok(exception.message.indexOf("UNKNOWN_TOKEN_ID")>=0);
it("contructor with touch enabled", function() {
return ServerConnector.getProject().then(function(project) {
var options = helper.createCustomMapOptions(project);
options.setCustomTouchInterface(true);
return minerva.create(options).then(function(result) {
assert.ok(result);
});
});
});
......@@ -207,8 +202,8 @@ describe('minerva global', function() {
options.setDebug(true);
return minerva.create(options);
}).then(function(result) {
result.addListener("search", "onSearch", function(elements){
callbackOk = elements.length>0;
result.addListener("search", "onSearch", function(elements) {
callbackOk = elements.length > 0;
});
return result.customMap.getOverlayByName("search").searchByQuery("s1");
}).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 @@
<wb-module deploy-name="MapViewer-rest-api">
<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/test/resources"/>
</wb-module>
</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