Skip to content
Snippets Groups Projects
Commit 87aa89fc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

allow user to search reactions by set of elements

parent 50362940
No related branches found
No related tags found
1 merge request!12Resolve "new JS API calls"
......@@ -196,29 +196,29 @@ function createMarkerElements(options) {
function getElements(elementIdentifiers, customMap) {
var identifiedElements = [];
var elementsByModelId = [];
for (var i=0;i<elementIdentifiers.length;i++) {
for (var i = 0; i < elementIdentifiers.length; i++) {
var identifiedElement = new IdentifiedElement(elementIdentifiers[i]);
if (elementsByModelId[identifiedElement.getModelId()]===undefined) {
if (elementsByModelId[identifiedElement.getModelId()] === undefined) {
elementsByModelId[identifiedElement.getModelId()] = [];
}
elementsByModelId[identifiedElement.getModelId()].push(identifiedElement);
identifiedElements.push(identifiedElement);
}
var modelScopePromises = [];
for (var key in elementsByModelId) {
for ( var key in elementsByModelId) {
if (elementsByModelId.hasOwnProperty(key)) {
var model = customMap.getModel().getSubmodelById(parseInt(key));
modelScopePromises.push(model.getByIdentifiedElements(elementsByModelId[key], true));
}
}
}
//first promise fetch all data
return Promise.all(modelScopePromises).then(function(){
//this promise return result in the right order
// first promise fetch all data
return Promise.all(modelScopePromises).then(function() {
// this promise return result in the right order
var elementPromises = [];
for (var i=0;i<identifiedElements.length;i++) {
for (var i = 0; i < identifiedElements.length; i++) {
var element = identifiedElements[i];
var model = customMap.getModel().getSubmodelById(element.getModelId());
var promise = model.getByIdentifiedElement(element, true);
......@@ -228,6 +228,35 @@ function getElements(elementIdentifiers, customMap) {
});
}
function getReactionsForElements(elementIdentifiers, customMap) {
var elementsByModelId = [];
for (var i = 0; i < elementIdentifiers.length; i++) {
var identifiedElement = new IdentifiedElement(elementIdentifiers[i]);
if (elementsByModelId[identifiedElement.getModelId()] === undefined) {
elementsByModelId[identifiedElement.getModelId()] = [];
}
elementsByModelId[identifiedElement.getModelId()].push(identifiedElement);
}
var modelScopePromises = [];
var result = [];
for ( var key in elementsByModelId) {
if (elementsByModelId.hasOwnProperty(key)) {
var model = customMap.getModel().getSubmodelById(parseInt(key));
var promise = model.getReactionsForElements(elementsByModelId[key], true).then(function(reactions) {
result = result.concat(reactions);
});
modelScopePromises.push(promise);
}
}
// first promise fetch all data
return Promise.all(modelScopePromises).then(function() {
return result;
});
}
function createResult(customMap) {
return {
getVisibleDataOverlays : function() {
......@@ -283,9 +312,7 @@ function createResult(customMap) {
if (param.length === undefined) {
param = [ param ];
isArray = false;
}
return getElements(param, customMap).then(function(result) {
if (!isArray) {
return result[0];
......@@ -295,9 +322,10 @@ function createResult(customMap) {
});
},
getReactionsWithElement : function(param) {
var identifiedElement = new IdentifiedElement(param);
var model = customMap.getModel().getSubmodelById(identifiedElement.getModelId());
return model.getReactionsForElement(identifiedElement, true);
if (param.length === undefined) {
param = [ param ];
}
return getReactionsForElements(param, customMap);
},
destroy : function() {
return leftPanel.destroy().then(function() {
......
......@@ -382,4 +382,27 @@ describe('minerva global', function() {
});
});
it("getReactionByParticipantId", function() {
var ie = {
modelId : 15781,
type : "ALIAS",
id : 329167
};
var options = {
projectId : "sample",
element : testDiv
};
var globalResult;
return minerva.create(options).then(function(result) {
globalResult = result;
return result.getReactionsWithElement(ie);
}).then(function(reactions) {
assert.equal(reactions.length, 5);
}).then(function() {
globalResult.destroy();
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment