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

renderOverlayCollection returns promise

parent 009ba429
......@@ -1332,12 +1332,11 @@ CustomMap.prototype.openInfoWindowForAlias = function(aliasId, modelId, onready)
* <code>true</code> if the borders should fit bounds after creating
* all elements
*/
CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBounds, onready) {
CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBounds) {
var self = this;
if (overlayCollection instanceof OverlayCollection) {
logger.warn("Deprecated method use: renderOverlayCollection(overlayCollection)");
} else {
onready = overlayCollection.onready;
fitBounds = overlayCollection.fitBounds;
overlayCollection = overlayCollection.overlayCollection;
}
......@@ -1352,7 +1351,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
var bounds;
Promise.each(
return Promise.each(
elements,
function(element) {
var model = self.getSubmodelById(element.modelId);
......@@ -1426,9 +1425,6 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
}
}
if (typeof (onready) === "function") {
onready();
}
});
};
......
......@@ -61,7 +61,7 @@ describe('CustomMap', function() {
map.openLayoutById(-1);
assert.ok(false);
} catch (exception) {
assert.ok(exception.message.indexOf("You have no privileges")>=0);
assert.ok(exception.message.indexOf("You have no privileges") >= 0);
}
});
......@@ -88,7 +88,7 @@ describe('CustomMap', function() {
var layout = helper.createLayout();
layout.setInitialized(true);
map.getModel().addLayout(layout);
return map.addSelectedLayout(layout.getId()).then(function() {
var vLayouts = JSON.parse(ServerConnector.getVisibleLayouts());
assert.equal(1, vLayouts.length);
......@@ -101,7 +101,7 @@ describe('CustomMap', function() {
var alias = helper.createAlias();
alias.setModelId(map.getId());
map.getModel().addAlias(alias);
var reaction = helper.createReaction();
map.getModel().addReaction(reaction);
......@@ -110,17 +110,17 @@ describe('CustomMap', function() {
var layoutAlias = helper.createLayoutAlias();
layoutAlias.setId(alias.getId());
layout.addAlias(layoutAlias);
var layoutReaction = helper.createLayoutReaction();
layoutReaction.setId(reaction.getId());
layout.addReaction(layoutReaction);
map.getModel().addLayout(layout);
map.addSelectedLayout(layout.getId());
map._showSelectedLayout(layout.getId(), 0, 1, function(){
map._showSelectedLayout(layout.getId(), 0, 1, function() {
assert.equal(2, map.selectedLayoutOverlays[layout.getId()].length);
assert.ok(map.selectedLayoutOverlays[layout.getId()][0] instanceof AliasOverlay);
assert.ok(map.selectedLayoutOverlays[layout.getId()][1] instanceof ReactionOverlay);
......@@ -129,11 +129,10 @@ describe('CustomMap', function() {
map._hideSelectedLayout(layout.getId());
assert.ok(map.selectedLayoutOverlays[layout.getId()]);
assert.equal(0, map.selectedLayoutOverlays[layout.getId()].length);
done();
});
});
it("openInfoWindowForAlias", function(done) {
var map = helper.createCustomMap();
......@@ -142,7 +141,7 @@ describe('CustomMap', function() {
alias.setModelId(map.getId());
var layoutAlias = helper.createLayoutAlias();
layoutAlias.setId(alias.getId());
layout.addAlias(layoutAlias);
// create layout
......@@ -163,7 +162,7 @@ describe('CustomMap', function() {
ServerConnector.addListener("onSendOverlayDetailDataRequest", function() {
onSendOverlayDetailDataRequest++;
});
var alias = helper.createAlias();
var map = helper.createCustomMap();
......@@ -182,20 +181,21 @@ describe('CustomMap', function() {
oc.elements.push(new IdentifiedElement(javaObj));
oc.setResultsIds([ 'result_id' ]);
map.renderOverlayCollection(oc);
return map.renderOverlayCollection(oc).then(function() {
var aliasMarker = new AliasMarker(alias.getId(), "marker/empty.png", alias, map);
var aliasMarker = new AliasMarker(alias.getId(), "marker/empty.png", alias, map);
map.openInfoWindowForMarker(aliasMarker);
map.openInfoWindowForMarker(aliasMarker);
assert.equal(1, onSendOverlayDetailDataRequest);
assert.equal(1, onSendOverlayDetailDataRequest);
assert.ok(map.getAliasInfoWindowById(alias.getId()));
assert.ok(map.getAliasInfoWindowById(alias.getId()).isOpened());
assert.ok(map.getAliasInfoWindowById(alias.getId()));
assert.ok(map.getAliasInfoWindowById(alias.getId()).isOpened());
});
});
it("updateOverviewElementDetailData in OverlayCollection", function(done) {
it("updateOverviewElementDetailData in OverlayCollection", function() {
var alias = helper.createAlias();
var ovName = " overlay name";
var searchResultId = 'result_id';
......@@ -217,7 +217,9 @@ describe('CustomMap', function() {
oc.elements.push(new IdentifiedElement(javaObj));
oc.setResultsIds([ searchResultId ]);
map.renderOverlayCollection({overlayCollection:oc, onready: function(){
return map.renderOverlayCollection({
overlayCollection : oc
}).then(function() {
var aliasMarker = new AliasMarker(alias.getId(), "marker/empty.png", alias, map);
alias.setType("RNA");
......@@ -239,11 +241,7 @@ describe('CustomMap', function() {
assert.ok(map.getAliasInfoWindowById(alias.getId()).getContent().innerHTML.indexOf(responseValue) >= 0);
assert.ok(map.getAliasInfoWindowById(alias.getId()).getContent().innerHTML.indexOf(searchResultId) >= 0);
done();
}}
);
});
});
it("registerSource 1", function() {
......@@ -281,7 +279,7 @@ describe('CustomMap', function() {
});
it("renderOverlayCollection for alias", function(done) {
it("renderOverlayCollection for alias", function() {
var map = helper.createCustomMap();
var reaction = helper.createReaction();
var alias = helper.createAlias();
......@@ -297,46 +295,47 @@ describe('CustomMap', function() {
type : "Alias"
}));
map.renderOverlayCollection({overlayCollection:oc, onready: function(){
return map.renderOverlayCollection({
overlayCollection : oc
}).then(function() {
var aliasMarkerCount = 0;
for ( var id in oc.aliasMarkers) {
if (oc.aliasMarkers.hasOwnProperty(id)) {
aliasMarkerCount++;
}
}
assert.equal(1, aliasMarkerCount);
done();
}});
});
});
it("renderOverlayCollection for set of aliases", function(done) {
it("renderOverlayCollection for set of aliases", function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'name');
var aliases = [];
for (var i=0;i<3;i++) {
for (var i = 0; i < 3; i++) {
var alias = helper.createAlias(map);
map.getModel().addAlias(alias);
aliases.push(alias);
oc.elements.push(helper.createIdentifiedElement(alias));
}
map.renderOverlayCollection({overlayCollection:oc, onready: function(){
return map.renderOverlayCollection({
overlayCollection : oc
}).then(function() {
var aliasMarkerCount = 0;
for ( var id in oc.aliasMarkers) {
if (oc.aliasMarkers.hasOwnProperty(id)) {
aliasMarkerCount++;
}
}
assert.equal(aliasMarkerCount,3);
done();
}});
assert.equal(aliasMarkerCount, 3);
});
});
it("renderOverlayCollection for point", function(done) {
it("renderOverlayCollection for point", function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'name');
......@@ -350,7 +349,9 @@ describe('CustomMap', function() {
oc.elements.push(new IdentifiedElement(javaObj));
map.renderOverlayCollection({overlayCollection:oc, onready: function(){
return map.renderOverlayCollection({
overlayCollection : oc
}).then(function() {
var markerCount = 0;
for ( var id in oc.pointMarkers) {
if (oc.pointMarkers.hasOwnProperty(id)) {
......@@ -358,8 +359,6 @@ describe('CustomMap', function() {
}
}
assert.equal(1, markerCount);
done();
}
});
});
......@@ -375,20 +374,20 @@ describe('CustomMap', function() {
modelId : map.getId(),
type : "Reaction",
};
oc.elements.push(new IdentifiedElement(javaObj));
map.renderOverlayCollection({overlayCollection:oc, onready: function(){
return map.renderOverlayCollection({
overlayCollection : oc
}).then(function() {
var markerCount = 0;
for ( var id in oc.reactionMarkers) {
if (oc.reactionMarkers.hasOwnProperty(id)) {
markerCount++;
}
}
assert.equal(1, markerCount);
}});
});
});
it("clearData", function() {
......@@ -407,7 +406,9 @@ describe('CustomMap', function() {
oc.elements.push(new IdentifiedElement(javaObj));
map.renderOverlayCollection({overlayCollection:oc});
map.renderOverlayCollection({
overlayCollection : oc
});
var onSendClearRequest = 0;
ServerConnector.addListener("onSendClearRequest", function(e) {
......@@ -433,13 +434,13 @@ describe('CustomMap', function() {
var map = helper.createCustomMap();
var reaction = helper.createReaction(map);
map.getModel().addReaction(reaction);
var ie = helper.createIdentifiedElement(reaction);
var infoWindow = map.getInfoWindowForIdentifiedElement(ie);
assert.equal(null, infoWindow);
return map._openInfoWindowForReaction(reaction.getId()).then(function(){
return map._openInfoWindowForReaction(reaction.getId()).then(function() {
infoWindow = map.getInfoWindowForIdentifiedElement(ie);
assert.ok(infoWindow);
......
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