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

missing elements and reactions are fetched simultanously when needed

parent baec601c
......@@ -187,23 +187,40 @@ MapModel.prototype.getMissingElements = function(elements) {
}
}
}
var reactionPromise = null;
if (reactionIds.length>0){
reactionPromise = ServerConnector.getReactions(reactionIds);
}
var aliasPromise = null;
if (aliasIds.length>0){
aliasPromise = ServerConnector.getLightAliases(aliasIds);
}
return new Promise(function(resolve, reject) {
var result = [];
ServerConnector.getReactions(reactionIds).then(function(reactions){
for (var i=0;i<reactions.length;i++) {
var reaction = reactions[i];
self.addReaction(reaction);
result.push(reaction);
Promise.all([reactionPromise, aliasPromise]).then(function(values) {
var result = [];
var reactions = values[0];
var aliases = values[1];
if (reactions!==null) {
for (var i=0;i<reactions.length;i++) {
var reaction = reactions[i];
self.addReaction(reaction);
result.push(reaction);
}
}
ServerConnector.getLightAliases(aliasIds).then(function(aliases){
if (aliases!==null) {
for (var i=0;i<aliases.length;i++) {
var alias= aliases[i];
self.addAlias(alias);
result.push(alias);
}
resolve(result);
}).catch(reject);
}).catch(reject);
}
resolve(result);
}).catch(function(err) {
reject(err);
});
});
};
......
......@@ -34,7 +34,7 @@ describe('MapModel', function() {
throw new Error('expected rejection');
}).catch(function(exception){
assert.ok(exception);
model.addLayout(layout);
return model.getLayoutDataById(layout.getId()).then(function(layoutData) {
......@@ -59,20 +59,20 @@ describe('MapModel', function() {
var model = helper.createModel();
var aliasObj = {
idObject : 32,
modelId : model.id,
idObject : 32,
modelId : model.id,
};
model.addAlias(aliasObj);
model.getAliasById(32).then(function (alias){
assert.equal(alias.getName(), undefined);
var aliasObj2 = {
idObject : 32,
modelId : model.id,
name : "testName",
idObject : 32,
modelId : model.id,
name : "testName",
};
model.addAlias(aliasObj2);
......@@ -116,7 +116,7 @@ describe('MapModel', function() {
assert.equal(null, result);
}).catch(function(exception) {
assert.ok(exception.message.indexOf("no such file"));
//check if this is exception about not finding file
// check if this is exception about not finding file
model.addAlias(alias);
return model.getAliasById(alias.getId());
}).then(function(result){
......@@ -134,7 +134,7 @@ describe('MapModel', function() {
assert.equal(null, result);
}).catch(function(exception) {
assert.ok(exception.path);
//check if this is exception about not finding file
// check if this is exception about not finding file
model.addReaction(reaction);
return model.getReactionById(reaction.getId());
}).then(function(result){
......@@ -144,7 +144,7 @@ describe('MapModel', function() {
it("getReactionById 2", function() {
var model = helper.createModel();
var reaction = helper.createReaction();
model.addReaction(reaction);
assert.equal(logger.getWarnings().length, 0);
......@@ -152,4 +152,12 @@ describe('MapModel', function() {
assert.equal(logger.getWarnings().length, 1);
});
it("getMissingElements when everything is up to date", function() {
var model = helper.createModel();
return model.getMissingElements({}).then(function(result){
assert.equal(result.length,0);
});
});
});
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