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

searching for queries that should have "," or ";" is resolved properly

first the full query is sent to server, if it resolves properly then we
have result if not then we check all info separated by comma
parent 34b7c8ec
No related branches found
No related tags found
1 merge request!109Resolve "test issues"
......@@ -41,77 +41,84 @@ AbstractDbOverlay.prototype = Object.create(ObjectWithListeners.prototype);
AbstractDbOverlay.prototype.constructor = AbstractDbOverlay;
AbstractDbOverlay.QueryType = {
SEARCH_BY_COORDINATES : "SEARCH_BY_COORDINATES",
SEARCH_BY_TARGET : "SEARCH_BY_TARGET",
SEARCH_BY_QUERY : "SEARCH_BY_QUERY",
SEARCH_BY_COORDINATES: "SEARCH_BY_COORDINATES",
SEARCH_BY_TARGET: "SEARCH_BY_TARGET",
SEARCH_BY_QUERY: "SEARCH_BY_QUERY",
};
AbstractDbOverlay.prototype.encodeQuery = function(type, arg0, arg1, arg2) {
AbstractDbOverlay.prototype.encodeQuery = function (type, arg0, arg1, arg2) {
if (type === AbstractDbOverlay.QueryType.SEARCH_BY_COORDINATES) {
var modelId = arg0;
var coordinates = arg1;
var zoom = arg2;
return JSON.stringify({
type : type,
modelId : modelId,
coordinates : coordinates,
zoom : zoom,
type: type,
modelId: modelId,
coordinates: coordinates,
zoom: zoom,
});
} else if (type === AbstractDbOverlay.QueryType.SEARCH_BY_TARGET) {
var target = arg0;
return JSON.stringify({
type : type,
target : target,
type: type,
target: target,
});
} else if (type === AbstractDbOverlay.QueryType.SEARCH_BY_QUERY) {
var query = arg0;
var perfect = arg1;
return JSON.stringify({
type : type,
query : query,
perfect : perfect,
type: type,
query: query,
perfect: perfect,
});
} else {
throw new Error("Unknown query type: " + type);
}
};
AbstractDbOverlay.prototype.decodeQuery = function(query) {
AbstractDbOverlay.prototype.decodeQuery = function (query) {
return JSON.parse(query);
};
AbstractDbOverlay.prototype.searchByQuery = function(originalQuery, perfect, fitBounds) {
AbstractDbOverlay.prototype.searchByQuery = function (originalQuery, perfect, fitBounds) {
var self = this;
var query = self.encodeQuery(AbstractDbOverlay.QueryType.SEARCH_BY_QUERY, originalQuery, perfect);
ServerConnector.getSessionData().setQuery({
type : self.getName(),
query : query
type: self.getName(),
query: query
});
var queries = self.splitQuery(originalQuery);
var res;
var encodedQueries = [];
var promises = [];
for (var i = 0; i < queries.length; i++) {
encodedQueries.push(self.encodeQuery(AbstractDbOverlay.QueryType.SEARCH_BY_QUERY, queries[i], perfect));
promises.push(self.searchBySingleQuery(queries[i], perfect));
}
return self.searchBySingleQuery(originalQuery, perfect).then(function (results) {
if (results.length > 0) {
encodedQueries.push(query);
return [results];
} else {
var queries = self.splitQuery(originalQuery);
var promises = [];
for (var i = 0; i < queries.length; i++) {
encodedQueries.push(self.encodeQuery(AbstractDbOverlay.QueryType.SEARCH_BY_QUERY, queries[i], perfect));
promises.push(self.searchBySingleQuery(queries[i], perfect));
}
var res;
return Promise.all(promises).then(function(results) {
return Promise.all(promises);
}
}).then(function (results) {
self.setQueries(encodedQueries);
res = results;
return self.callListeners('onSearch', {
fitBounds : fitBounds,
identifiedElements : res,
type : AbstractDbOverlay.QueryType.SEARCH_BY_QUERY,
fitBounds: fitBounds,
identifiedElements: res,
type: AbstractDbOverlay.QueryType.SEARCH_BY_QUERY,
});
}).then(function() {
}).then(function () {
return res;
});
};
AbstractDbOverlay.prototype.searchNamesByTarget = function(element) {
AbstractDbOverlay.prototype.searchNamesByTarget = function (element) {
var self = this;
var query = self.encodeQuery(AbstractDbOverlay.QueryType.SEARCH_BY_TARGET, element);
......@@ -119,23 +126,23 @@ AbstractDbOverlay.prototype.searchNamesByTarget = function(element) {
return Promise.resolve(self._elementsByQuery[query]);
} else {
return self.getNamesByTargetFromServer({
target : element
}).then(function(drugNames) {
target: element
}).then(function (drugNames) {
self._elementsByQuery[query] = drugNames;
return self._elementsByQuery[query];
});
}
};
AbstractDbOverlay.prototype.setQueries = function(queries) {
AbstractDbOverlay.prototype.setQueries = function (queries) {
this._queries = queries;
};
AbstractDbOverlay.prototype.getQueries = function() {
AbstractDbOverlay.prototype.getQueries = function () {
return this._queries;
};
AbstractDbOverlay.prototype.createIdentifiedElementsForTargetingClass = function(targetingElement, colourId) {
AbstractDbOverlay.prototype.createIdentifiedElementsForTargetingClass = function (targetingElement, colourId) {
var self = this;
var result = [];
var iconCounter = 1;
......@@ -160,11 +167,11 @@ AbstractDbOverlay.prototype.createIdentifiedElementsForTargetingClass = function
return result;
};
AbstractDbOverlay.prototype.refresh = function() {
AbstractDbOverlay.prototype.refresh = function () {
throw new Error("Refreshing shouldn't be called");
};
AbstractDbOverlay.prototype.searchByEncodedQuery = function(originalQuery, fitBounds) {
AbstractDbOverlay.prototype.searchByEncodedQuery = function (originalQuery, fitBounds) {
var query = this.decodeQuery(originalQuery);
query.fitBounds = fitBounds;
if (query.type === AbstractDbOverlay.QueryType.SEARCH_BY_QUERY) {
......@@ -179,9 +186,9 @@ AbstractDbOverlay.prototype.searchByEncodedQuery = function(originalQuery, fitBo
}
};
AbstractDbOverlay.prototype.clear = function() {
AbstractDbOverlay.prototype.clear = function () {
var self = this;
return self.searchByQuery("").then(function() {
return self.searchByQuery("").then(function () {
return self.callListeners('onClear');
});
};
......@@ -189,38 +196,38 @@ AbstractDbOverlay.prototype.clear = function() {
/**
* Returns true if overlay allows to get general data for element.
*/
AbstractDbOverlay.prototype.allowGeneralSearch = function() {
AbstractDbOverlay.prototype.allowGeneralSearch = function () {
return this._allowGeneralSearch;
};
AbstractDbOverlay.prototype.getName = function() {
AbstractDbOverlay.prototype.getName = function () {
return this.name;
};
/**
* Returns true if overlay allows to get data for element by search id.
*/
AbstractDbOverlay.prototype.allowSearchById = function() {
AbstractDbOverlay.prototype.allowSearchById = function () {
return this._allowSearchById;
};
AbstractDbOverlay.prototype.setMap = function(map) {
AbstractDbOverlay.prototype.setMap = function (map) {
this._map = map;
};
AbstractDbOverlay.prototype.getMap = function() {
AbstractDbOverlay.prototype.getMap = function () {
return this._map;
};
AbstractDbOverlay.prototype.setName = function(name) {
AbstractDbOverlay.prototype.setName = function (name) {
this.name = name;
};
AbstractDbOverlay.prototype.getName = function() {
AbstractDbOverlay.prototype.getName = function () {
return this.name;
};
AbstractDbOverlay.prototype.setAllowSearchById = function(allowSearchById) {
AbstractDbOverlay.prototype.setAllowSearchById = function (allowSearchById) {
// configure if the overlay can contain detailed data about elements that
// should be visualized in detailed mode of the Info Window
if (typeof allowSearchById === "boolean") {
......@@ -232,7 +239,7 @@ AbstractDbOverlay.prototype.setAllowSearchById = function(allowSearchById) {
}
};
AbstractDbOverlay.prototype.setAllowGeneralSearch = function(allowGeneralSearch) {
AbstractDbOverlay.prototype.setAllowGeneralSearch = function (allowGeneralSearch) {
if (typeof allowGeneralSearch === "boolean") {
this._allowGeneralSearch = allowGeneralSearch;
} else if (allowGeneralSearch === undefined) {
......@@ -242,22 +249,22 @@ AbstractDbOverlay.prototype.setAllowGeneralSearch = function(allowGeneralSearch)
}
};
AbstractDbOverlay.prototype.setIconType = function(iconType) {
AbstractDbOverlay.prototype.setIconType = function (iconType) {
this._iconType = iconType;
};
AbstractDbOverlay.prototype.setIconStart = function(iconStart) {
AbstractDbOverlay.prototype.setIconStart = function (iconStart) {
this._iconStart = iconStart;
};
AbstractDbOverlay.IconColors = [ "red", "blue", "green", "purple", "yellow", "pink", "paleblue", "brown", "orange" ];
AbstractDbOverlay.IconColors = ["red", "blue", "green", "purple", "yellow", "pink", "paleblue", "brown", "orange"];
AbstractDbOverlay.prototype.getColor = function(colorId) {
AbstractDbOverlay.prototype.getColor = function (colorId) {
var id = colorId + this._iconStart;
id %= AbstractDbOverlay.IconColors.length;
return AbstractDbOverlay.IconColors[id];
};
AbstractDbOverlay.prototype.getIcon = function(colorId, id) {
AbstractDbOverlay.prototype.getIcon = function (colorId, id) {
if (id >= 100) {
id = 1;
}
......@@ -265,7 +272,7 @@ AbstractDbOverlay.prototype.getIcon = function(colorId, id) {
return "marker/" + this._iconType + "/" + this._iconType + "_" + color + "_" + id + ".png";
};
AbstractDbOverlay.prototype.splitQuery = function(query, useFullName) {
AbstractDbOverlay.prototype.splitQuery = function (query, useFullName) {
var result = [];
if (query.indexOf(";") >= 0) {
result = query.split(";");
......
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