From 00adfd896265f29aaaa8500789f0acace2113da3 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 30 Apr 2018 14:00:34 +0200 Subject: [PATCH] fixing calls from SearchDbOverlay.prototype.searchByTarget --- .../main/js/map/overlay/AbstractDbOverlay.js | 1 + .../overlay/AbstractTargettingDbOverlay.js | 5 +++++ .../main/js/map/overlay/SearchDbOverlay.js | 13 +++++++++---- frontend-js/src/test/js/helper.js | 5 +++++ .../js/map/overlay/SearchDbOverlay-test.js | 19 +++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/frontend-js/src/main/js/map/overlay/AbstractDbOverlay.js b/frontend-js/src/main/js/map/overlay/AbstractDbOverlay.js index 564b6f2b2d..8c92adff93 100644 --- a/frontend-js/src/main/js/map/overlay/AbstractDbOverlay.js +++ b/frontend-js/src/main/js/map/overlay/AbstractDbOverlay.js @@ -188,6 +188,7 @@ AbstractDbOverlay.prototype.refresh = function () { /** * * @param {IdentifiedElement} element + * @returns {Promise} */ AbstractDbOverlay.prototype.searchByTarget = function (element) { throw new Error("Not implemented"); diff --git a/frontend-js/src/main/js/map/overlay/AbstractTargettingDbOverlay.js b/frontend-js/src/main/js/map/overlay/AbstractTargettingDbOverlay.js index 5fda2343e1..50540c08d7 100644 --- a/frontend-js/src/main/js/map/overlay/AbstractTargettingDbOverlay.js +++ b/frontend-js/src/main/js/map/overlay/AbstractTargettingDbOverlay.js @@ -111,6 +111,11 @@ AbstractTargettingDbOverlay.prototype.getIdentifiedElements = function () { }); }; +/** + * + * @param {IdentifiedElement} element + * @returns {Promise} + */ AbstractTargettingDbOverlay.prototype.searchByTarget = function (element) { return this.searchNamesByTarget(element); }; diff --git a/frontend-js/src/main/js/map/overlay/SearchDbOverlay.js b/frontend-js/src/main/js/map/overlay/SearchDbOverlay.js index b0f9b429dd..5f199aad9f 100644 --- a/frontend-js/src/main/js/map/overlay/SearchDbOverlay.js +++ b/frontend-js/src/main/js/map/overlay/SearchDbOverlay.js @@ -16,6 +16,12 @@ var SearchBioEntityGroup = require('../data/SearchBioEntityGroup'); var ServerConnector = require('../../ServerConnector'); +/** + * + * @param params + * @constructor + * @extends AbstractDbOverlay + */ function SearchDbOverlay(params) { params.iconType = "marker"; params.iconColorStart = 0; @@ -260,7 +266,7 @@ SearchDbOverlay.prototype.searchBySingleQuery = function (originalQuery, perfect /** * * @param {IdentifiedElement} element - * @returns {Bluebird<any>} + * @returns {Promise|PromiseLike} */ SearchDbOverlay.prototype.searchByTarget = function (element) { var self = this; @@ -271,7 +277,7 @@ SearchDbOverlay.prototype.searchByTarget = function (element) { if (self._elementsByQuery[query] === undefined) { self._elementsByQuery[query] = [element]; } - return self.getMap().fetchIdentifiedElements(element, true).then(function () { + return self.getMap().fetchIdentifiedElements([element], true).then(function () { self.setQueries([query]); return self.callListeners('onSearch', { fitBounds: false, @@ -281,7 +287,6 @@ SearchDbOverlay.prototype.searchByTarget = function (element) { }).then(function () { return Promise.resolve(self._elementsByQuery[query]); }); - }; @@ -292,7 +297,7 @@ SearchDbOverlay.prototype.getIdentifiedElements = function () { return Promise.each(queries, function (query, index) { var identifiedElements = self._elementsByQuery[query]; - return self.getMap().fetchIdentifiedElements(identifiedElements).then(function (elements) { + return self.getMap().fetchIdentifiedElements(identifiedElements, true).then(function (elements) { var iconCounter = 1; var groups = []; for (var i = 0; i < elements.length; i++) { diff --git a/frontend-js/src/test/js/helper.js b/frontend-js/src/test/js/helper.js index de0f857afc..31951dc59d 100644 --- a/frontend-js/src/test/js/helper.js +++ b/frontend-js/src/test/js/helper.js @@ -65,6 +65,11 @@ Helper.prototype.createCommentDbOverlay = function (map) { return result; }; +/** + * + * @param {CustomMap} map + * @returns {SearchDbOverlay} + */ Helper.prototype.createSearchDbOverlay = function (map) { var result = new SearchDbOverlay({ map: map, diff --git a/frontend-js/src/test/js/map/overlay/SearchDbOverlay-test.js b/frontend-js/src/test/js/map/overlay/SearchDbOverlay-test.js index 5ce146a78a..f88dfeda4c 100644 --- a/frontend-js/src/test/js/map/overlay/SearchDbOverlay-test.js +++ b/frontend-js/src/test/js/map/overlay/SearchDbOverlay-test.js @@ -223,4 +223,23 @@ describe('SearchDbOverlay', function () { }); }); + it("searchByTarget", function () { + var target = new IdentifiedElement({ + type: "ALIAS", + id: 329170, + modelId: 15781 + }); + + var map; + return ServerConnector.getProject().then(function (project) { + map = helper.createCustomMap(project); + var searchDb = helper.createSearchDbOverlay(map); + + return searchDb.searchByTarget(target); + }).then(function (result) { + assert.ok(map.getModel().isAvailable(target)); + }); + }); + + }); -- GitLab