Commit 4fa8ac9e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

getting full info about alias when opening window

parent 11339bed
......@@ -1307,19 +1307,11 @@ CustomMap.prototype.refreshInfoWindows = function() {
* @param modelId
* identifier of {@link AbstractCustomMap}
*/
CustomMap.prototype.openInfoWindowForAlias = function(aliasId, modelId, onready) {
CustomMap.prototype.openInfoWindowForAlias = function(aliasId, modelId) {
logger.debug("Opening info window for alias: " + aliasId + ", model: " + modelId);
var model = this.getSubmodelById(modelId);
model.getModel().getAliasById(aliasId).then(function(alias) {
// if we have only simple version of the data then ask server for more
// details
if (alias === undefined || alias === null || alias.completness === 'SIMPLE') {
logger.debug("Accessing full alias: " + aliasId);
var ids = [ [ modelId, aliasId ] ];
ServerConnector.retreiveFullAliases(ids);
}
// open AliasInfoWindow in a right model
model._openInfoWindowForAlias(aliasId, onready);
return model.getModel().getAliasById(aliasId, true).then(function(alias) {
model._openInfoWindowForAlias(aliasId);
});
};
......@@ -1359,17 +1351,19 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
if (overlayCollection.aliasMarkers[element.getId()] !== undefined) {
logger.warn("More than one marker in " + overlayCollection.name + " for alias " + element.getId()
+ ". Skipping duplicates.");
return null;
} else {
model.getModel().getAliasById(element.getId()).then(function(aliasData) {
return model.getModel().getAliasById(element.getId()).then(function(aliasData) {
var aliasMarker = new AliasMarker(element.getId(), element.icon, aliasData, model);
overlayCollection.aliasMarkers[element.getId()] = aliasMarker;
bounds = aliasMarker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return aliasMarker;
});
}
} else if (element.type === "REACTION") {
model.getModel().getReactionById(element.getId()).then(function(reactionData) {
return model.getModel().getReactionById(element.getId()).then(function(reactionData) {
var marker = null;
var icon = element.getIcon();
......@@ -1388,6 +1382,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
bounds = marker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return marker;
});
} else if (element.type === "POINT") {
var pointData = model.getModel().getPointDataByPoint(element.getPoint());
......@@ -1396,6 +1391,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
bounds = pointMarker.getBounds();
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return pointMarker;
} else {
throw new Error("Unknown type of the element in overlay: " + element.type);
}
......
......@@ -117,9 +117,12 @@ MapModel.prototype.getAliases = function() {
* identifier of the {@link Alias}
* @returns {@link Alias} by identifier
*/
MapModel.prototype.getAliasById = function(id) {
MapModel.prototype.getAliasById = function(id, complete) {
var self = this;
return new Promise(function(resolve, reject) {
if (complete) {
return this.getCompleteAliasById(id);
}
return new Promise(function(resolve, reject) {
if (self._aliases[id] !== undefined) {
resolve(self._aliases[id]);
} else {
......@@ -130,6 +133,23 @@ MapModel.prototype.getAliasById = function(id) {
});
};
MapModel.prototype.getCompleteAliasById = function(id) {
var self = this;
return new Promise(function(resolve, reject) {
if (self._aliases[id].isComplete()) {
resolve(self._aliases[id]);
}
ServerConnector.getAliases([id]).then(function(aliases){
if (self._aliases[id] === undefined) {
self._aliases[id] = aliases[0];
} else {
self._aliases[id] .update(aliases[0]);
}
resolve(self._aliases[id]);
}, reject);
});
};
/**
* Returns {@link Reaction} by identifier.
*
......
......@@ -46,9 +46,15 @@ Helper.prototype.createAlias = function(map) {
return result;
};
Helper.prototype.createLayoutAlias = function() {
Helper.prototype.createLayoutAlias = function(alias) {
var id;
if (alias instanceof Alias) {
id = alias.getId();
} else {
id = this.idCounter++;
}
var result = new LayoutAlias({
idObject : this.idCounter++,
idObject : id,
value : 0.2,
color : {
a : 23
......@@ -78,11 +84,11 @@ Helper.prototype.createLayoutReaction = function(reaction) {
};
Helper.prototype.createIdentifiedElement = function(element) {
if (element ===undefined) {
if (element === undefined) {
return new IdentifiedElement({
type: "ALIAS",
idObject: this.idCounter++,
modelId: this.idCounter++,
type : "ALIAS",
idObject : this.idCounter++,
modelId : this.idCounter++,
});
}
return new IdentifiedElement(element);
......
......@@ -134,7 +134,7 @@ describe('CustomMap', function() {
});
});
it("openInfoWindowForAlias", function(done) {
it("openInfoWindowForAlias", function() {
var map = helper.createCustomMap();
var layout = helper.createLayout();
var alias = helper.createAlias();
......@@ -148,10 +148,29 @@ describe('CustomMap', function() {
map.getModel().addLayout(layout);
map.getModel().addAlias(alias);
map.openInfoWindowForAlias(alias.getId(), map.getId(), function() {
return map.openInfoWindowForAlias(alias.getId(), map.getId(), function() {
assert.ok(map.getAliasInfoWindowById(alias.getId()));
assert.ok(map.getAliasInfoWindowById(alias.getId()).isOpened());
});
});
it("openInfoWindowForAlias for incomplete alias", function() {
var map = helper.createCustomMap();
var layout = helper.createLayout();
var alias = helper.createAlias(map);
alias.setId(30001);
alias.setIsComplete(false);
var layoutAlias = helper.createLayoutAlias(alias);
layout.addAlias(layoutAlias);
// create layout
map.getModel().addLayout(layout);
map.getModel().addAlias(alias);
return map.openInfoWindowForAlias(alias.getId(), map.getId(), function() {
assert.ok(map.getAliasInfoWindowById(alias.getId()));
assert.ok(map.getAliasInfoWindowById(alias.getId()).isOpened());
done();
});
});
......
[{"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","type":"Unknown","name":"s11","bounds":{"x":105.0,"y":203.5,"width":70.0,"height":25.0},"id":30001}]
\ No newline at end of file
Supports Markdown
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