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

promises are simplified

parent 346827ea
No related branches found
No related tags found
1 merge request!5Frontend refactor
...@@ -34,7 +34,7 @@ var TouchMap = require('./TouchMap'); ...@@ -34,7 +34,7 @@ var TouchMap = require('./TouchMap');
*/ */
function CustomMap(options) { function CustomMap(options) {
this._controls = []; this._controls = [];
if (!(options instanceof CustomMapOptions)) { if (!(options instanceof CustomMapOptions)) {
options = new CustomMapOptions(options); options = new CustomMapOptions(options);
} }
...@@ -56,7 +56,7 @@ function CustomMap(options) { ...@@ -56,7 +56,7 @@ function CustomMap(options) {
// list of reference genomes // list of reference genomes
this._referenceGenome = []; this._referenceGenome = [];
if (options.isCustomTouchInterface()) { if (options.isCustomTouchInterface()) {
this._touchInterface = new TouchMap(this); this._touchInterface = new TouchMap(this);
} }
...@@ -79,7 +79,7 @@ CustomMap.prototype.createSubmaps = function() { ...@@ -79,7 +79,7 @@ CustomMap.prototype.createSubmaps = function() {
CustomMap.prototype.createLogo = function() { CustomMap.prototype.createLogo = function() {
var logoControlDiv2 = document.createElement('DIV'); var logoControlDiv2 = document.createElement('DIV');
var logo2 = document.createElement('IMG'); var logo2 = document.createElement('IMG');
ServerConnector.getLogoImg().then(function(url){ ServerConnector.getLogoImg().then(function(url) {
if (!/^(f|ht)tps?:\/\//i.test(url)) { if (!/^(f|ht)tps?:\/\//i.test(url)) {
url = GuiConnector.getImgPrefix() + url; url = GuiConnector.getImgPrefix() + url;
} }
...@@ -89,13 +89,13 @@ CustomMap.prototype.createLogo = function() { ...@@ -89,13 +89,13 @@ CustomMap.prototype.createLogo = function() {
logo2.style.width = "80px"; logo2.style.width = "80px";
logo2.id = ControlType.LOGO_2_IMG; logo2.id = ControlType.LOGO_2_IMG;
this.addControl(logo2); this.addControl(logo2);
logoControlDiv2.appendChild(logo2); logoControlDiv2.appendChild(logo2);
google.maps.event.addDomListener(logo2, 'click', function() { google.maps.event.addDomListener(logo2, 'click', function() {
return ServerConnector.getLogoLink().then(function(url){ return ServerConnector.getLogoLink().then(function(url) {
var win = window.open(url, '_blank'); var win = window.open(url, '_blank');
win.focus(); win.focus();
}).catch(GuiConnector.alert); });
}); });
logoControlDiv2.index = 0; // used for ordering logoControlDiv2.index = 0; // used for ordering
this.getGoogleMap().controls[google.maps.ControlPosition.LEFT_BOTTOM].push(logoControlDiv2); this.getGoogleMap().controls[google.maps.ControlPosition.LEFT_BOTTOM].push(logoControlDiv2);
...@@ -123,9 +123,9 @@ CustomMap.prototype.clearOverlays = function() { ...@@ -123,9 +123,9 @@ CustomMap.prototype.clearOverlays = function() {
for ( var overlayName in this.overlayCollections) { for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) { if (this.overlayCollections.hasOwnProperty(overlayName)) {
var collection = this.overlayCollections[overlayName]; var collection = this.overlayCollections[overlayName];
if (collection.constructor.name==="OverlayCollection") { if (collection.constructor.name === "OverlayCollection") {
this.clearOverlayCollection(collection); this.clearOverlayCollection(collection);
}else { } else {
collection.clear(); collection.clear();
} }
} }
...@@ -177,7 +177,10 @@ CustomMap.prototype.clearOverlayCollection = function(collection) { ...@@ -177,7 +177,10 @@ CustomMap.prototype.clearOverlayCollection = function(collection) {
*/ */
CustomMap.prototype.updateOverlayCollection = function(overlayCollection, fitBounds) { CustomMap.prototype.updateOverlayCollection = function(overlayCollection, fitBounds) {
this.clearOverlayCollection(overlayCollection); this.clearOverlayCollection(overlayCollection);
return this.renderOverlayCollection({overlayCollection:overlayCollection, fitBounds:fitBounds}); return this.renderOverlayCollection({
overlayCollection : overlayCollection,
fitBounds : fitBounds
});
}; };
/** /**
...@@ -189,7 +192,7 @@ CustomMap.prototype.updateOverlayCollection = function(overlayCollection, fitBou ...@@ -189,7 +192,7 @@ CustomMap.prototype.updateOverlayCollection = function(overlayCollection, fitBou
*/ */
CustomMap.prototype.openLayout = function(identifier) { CustomMap.prototype.openLayout = function(identifier) {
var self = this; var self = this;
logger.debug("Opening layout: " + identifier); logger.debug("Opening layout: " + identifier);
this.getGoogleMap().setMapTypeId(identifier); this.getGoogleMap().setMapTypeId(identifier);
...@@ -263,16 +266,17 @@ CustomMap.prototype.registerSource = function(overlayCollection) { ...@@ -263,16 +266,17 @@ CustomMap.prototype.registerSource = function(overlayCollection) {
overlayCollection.pointMarkers = []; overlayCollection.pointMarkers = [];
overlayCollection.reactionMarkers = []; overlayCollection.reactionMarkers = [];
if (overlayCollection.getName()==="search") { if (overlayCollection.getName() === "search") {
overlayCollection.addListener("onSearch", function() { overlayCollection.addListener("onSearch", function() {
return self.updateOverlayCollection(overlayCollection, false); return self.updateOverlayCollection(overlayCollection, false);
}); });
} }
if (overlayCollection.getName() === "drug" || overlayCollection.getName() === "chemical" ||overlayCollection.getName() === "mirna" ) { if (overlayCollection.getName() === "drug" || overlayCollection.getName() === "chemical"
|| overlayCollection.getName() === "mirna") {
overlayCollection.addListener("onSearch", function() { overlayCollection.addListener("onSearch", function() {
return self.updateOverlayCollection(overlayCollection, false); return self.updateOverlayCollection(overlayCollection, false);
}); });
overlayCollection.addListener("onTargetVisibilityChange", function() { overlayCollection.addListener("onTargetVisibilityChange", function() {
return self.updateOverlayCollection(overlayCollection, false); return self.updateOverlayCollection(overlayCollection, false);
}); });
...@@ -282,13 +286,15 @@ CustomMap.prototype.registerSource = function(overlayCollection) { ...@@ -282,13 +286,15 @@ CustomMap.prototype.registerSource = function(overlayCollection) {
CustomMap.prototype.refreshComments = function() { CustomMap.prototype.refreshComments = function() {
var self = this; var self = this;
var collection = self.getOverlayByName("comment"); var collection = self.getOverlayByName("comment");
if (collection!==undefined) { if (collection !== undefined) {
self.clearOverlayCollection(collection); self.clearOverlayCollection(collection);
if (ServerConnector.getSessionData(self.getProject()).getShowComments()) { if (ServerConnector.getSessionData(self.getProject()).getShowComments()) {
return collection.refresh().then(function(){ return collection.refresh().then(function() {
return self.renderOverlayCollection({overlayCollection:collection}); return self.renderOverlayCollection({
overlayCollection : collection
});
}); });
} else { } else {
return collection.clear(); return collection.clear();
...@@ -372,8 +378,10 @@ CustomMap.prototype.getSubmapDialogDiv = function(id) { ...@@ -372,8 +378,10 @@ CustomMap.prototype.getSubmapDialogDiv = function(id) {
dialogDiv.setAttribute("name", "dialog-" + id); dialogDiv.setAttribute("name", "dialog-" + id);
this._dialogs[id] = dialogDiv; this._dialogs[id] = dialogDiv;
$(dialogDiv).dialog({autoOpen: false}); $(dialogDiv).dialog({
autoOpen : false
});
} }
return dialogDiv; return dialogDiv;
}; };
...@@ -384,7 +392,7 @@ CustomMap.prototype.openSubmodel = function(id) { ...@@ -384,7 +392,7 @@ CustomMap.prototype.openSubmodel = function(id) {
if (submap === null) { if (submap === null) {
throw new Error("Unknown submap for id: " + id); throw new Error("Unknown submap for id: " + id);
} }
if (submap!==this) { if (submap !== this) {
var dialogDiv = self.getSubmapDialogDiv(id); var dialogDiv = self.getSubmapDialogDiv(id);
...@@ -427,7 +435,7 @@ CustomMap.prototype.customizeGoogleMapView = function(div) { ...@@ -427,7 +435,7 @@ CustomMap.prototype.customizeGoogleMapView = function(div) {
// center map and zoom in to fit into browser window if there is no // center map and zoom in to fit into browser window if there is no
// information about coordinates in the session // information about coordinates in the session
if (ServerConnector.getSessionData(this.getProject()).getCenter(this.getModel())===undefined) { if (ServerConnector.getSessionData(this.getProject()).getCenter(this.getModel()) === undefined) {
var bounds = new google.maps.LatLngBounds(); var bounds = new google.maps.LatLngBounds();
bounds.extend(this.getTopLeftLatLng()); bounds.extend(this.getTopLeftLatLng());
bounds.extend(this.getBottomRightLatLng()); bounds.extend(this.getBottomRightLatLng());
...@@ -471,10 +479,10 @@ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) { ...@@ -471,10 +479,10 @@ CustomMap.prototype.setZoom = function(mapIdentifier, zoom) {
*/ */
CustomMap.prototype.createMapChangedCallbacks = function() { CustomMap.prototype.createMapChangedCallbacks = function() {
var customMapSelf = this; var customMapSelf = this;
var sessionData = ServerConnector.getSessionData(customMapSelf.getProject()); var sessionData = ServerConnector.getSessionData(customMapSelf.getProject());
// listener for changing zoom level // listener for changing zoom level
google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() { google.maps.event.addListener(this.getGoogleMap(), 'zoom_changed', function() {
sessionData.setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom()); sessionData.setZoomLevel(customMapSelf.getModel(), customMapSelf.getGoogleMap().getZoom());
}); });
// if we have zoom level data stored in session then restore it // if we have zoom level data stored in session then restore it
...@@ -483,14 +491,14 @@ CustomMap.prototype.createMapChangedCallbacks = function() { ...@@ -483,14 +491,14 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
level = parseInt(level); level = parseInt(level);
this.getGoogleMap().setZoom(level); this.getGoogleMap().setZoom(level);
} else { } else {
sessionData.setZoomLevel(customMapSelf.getModel(),customMapSelf.getGoogleMap().getZoom()); sessionData.setZoomLevel(customMapSelf.getModel(), customMapSelf.getGoogleMap().getZoom());
} }
// listener for changing location of the map (moving left/reght/top/bottom // listener for changing location of the map (moving left/reght/top/bottom
google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function() { google.maps.event.addListener(this.getGoogleMap(), 'center_changed', function() {
var coord = customMapSelf.getGoogleMap().getCenter(); var coord = customMapSelf.getGoogleMap().getCenter();
var point = customMapSelf.fromLatLngToPoint(coord); var point = customMapSelf.fromLatLngToPoint(coord);
sessionData.setCenter(customMapSelf.getModel(),point); sessionData.setCenter(customMapSelf.getModel(), point);
}); });
// listener for changing type of layout // listener for changing type of layout
...@@ -522,7 +530,7 @@ CustomMap.prototype.getSubmodelById = function(identifier) { ...@@ -522,7 +530,7 @@ CustomMap.prototype.getSubmodelById = function(identifier) {
return this.submaps[i]; return this.submaps[i];
} }
} }
logger.warn("Cannot find submodel with id: "+identifier); logger.warn("Cannot find submodel with id: " + identifier);
return null; return null;
}; };
...@@ -548,7 +556,6 @@ CustomMap.prototype.showModel = function(id, point, zoomLevel) { ...@@ -548,7 +556,6 @@ CustomMap.prototype.showModel = function(id, point, zoomLevel) {
} }
}; };
/** /**
* Adds layout to be visualized. * Adds layout to be visualized.
* *
...@@ -557,24 +564,18 @@ CustomMap.prototype.showModel = function(id, point, zoomLevel) { ...@@ -557,24 +564,18 @@ CustomMap.prototype.showModel = function(id, point, zoomLevel) {
*/ */
CustomMap.prototype.addSelectedLayout = function(identifier) { CustomMap.prototype.addSelectedLayout = function(identifier) {
var self = this; var self = this;
return new Promise(function(resolve, reject) { logger.debug("Selecting layout: " + identifier);
logger.debug("Selecting layout: " + identifier);
if (self.selectedLayouts[identifier] === true) { if (self.selectedLayouts[identifier] === true) {
logger.warn("Layout " + identifier + " already selected"); logger.warn("Layout " + identifier + " already selected");
resolve(); return Promise.resolve();
} else { } else {
self.selectedLayouts[identifier] = true; self.selectedLayouts[identifier] = true;
ServerConnector.getSessionData(self.getProject()).setVisibleOverlays(self.getSelectedLayouts()); ServerConnector.getSessionData(self.getProject()).setVisibleOverlays(self.getSelectedLayouts());
return self.getModel().initLayoutDataByLayoutId(identifier).then(function() { return self.getModel().initLayoutDataByLayoutId(identifier).then(function() {
return self.refreshSelectedLayouts(); return self.refreshSelectedLayouts();
}).then(function() { });
resolve(); }
}).catch(function(exception){
reject(exception);
});
}
});
}; };
/** /**
...@@ -641,7 +642,7 @@ CustomMap.prototype.refreshSelectedLayouts = function() { ...@@ -641,7 +642,7 @@ CustomMap.prototype.refreshSelectedLayouts = function() {
} }
} }
} }
return self.refreshInfoWindows(); return self.refreshInfoWindows();
}); });
}; };
...@@ -774,7 +775,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou ...@@ -774,7 +775,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
fitBounds = overlayCollection.fitBounds; fitBounds = overlayCollection.fitBounds;
overlayCollection = overlayCollection.overlayCollection; overlayCollection = overlayCollection.overlayCollection;
} }
var elements; var elements;
var boundsArray = []; var boundsArray = [];
boundsArray[self.getId()] = new google.maps.LatLngBounds(); boundsArray[self.getId()] = new google.maps.LatLngBounds();
...@@ -782,14 +783,13 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou ...@@ -782,14 +783,13 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
boundsArray[self.submaps[j].getId()] = new google.maps.LatLngBounds(); boundsArray[self.submaps[j].getId()] = new google.maps.LatLngBounds();
} }
return overlayCollection.getIdentifiedElements().then(function(identifiedElements){ return overlayCollection.getIdentifiedElements().then(
elements = identifiedElements; function(identifiedElements) {
elements = identifiedElements;
var bounds; var bounds;
return Promise.each( return Promise.each(elements, function(element) {
elements,
function(element) {
var model = self.getSubmodelById(element.modelId); var model = self.getSubmodelById(element.modelId);
if (element.getType() === "ALIAS") { if (element.getType() === "ALIAS") {
if (overlayCollection.aliasMarkers[element.getId()] !== undefined) { if (overlayCollection.aliasMarkers[element.getId()] !== undefined) {
...@@ -831,7 +831,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou ...@@ -831,7 +831,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
}); });
} else if (element.getType() === "POINT") { } else if (element.getType() === "POINT") {
var pointData = model.getModel().getPointDataByPoint(element.getPoint()); var pointData = model.getModel().getPointDataByPoint(element.getPoint());
if (overlayCollection.pointMarkers[pointData.getId()] === undefined) { if (overlayCollection.pointMarkers[pointData.getId()] === undefined) {
var pointMarker = new PointMarker(pointData, element.icon, model); var pointMarker = new PointMarker(pointData, element.icon, model);
overlayCollection.pointMarkers[pointData.getId()] = pointMarker; overlayCollection.pointMarkers[pointData.getId()] = pointMarker;
bounds = pointMarker.getBounds(); bounds = pointMarker.getBounds();
...@@ -843,7 +843,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou ...@@ -843,7 +843,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
throw new Error("Unknown type of the element in overlay: " + element.type); throw new Error("Unknown type of the element in overlay: " + element.type);
} }
}); });
}).then(function() { }).then(function() {
for (var i = 0; i < elements.length; i++) { for (var i = 0; i < elements.length; i++) {
var element = elements[i]; var element = elements[i];
...@@ -860,7 +860,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou ...@@ -860,7 +860,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
var map = self.getSubmodelById(mapId).getGoogleMap(); var map = self.getSubmodelById(mapId).getGoogleMap();
var bounds = boundsArray[mapId]; var bounds = boundsArray[mapId];
if (map !== undefined && !bounds.isEmpty()) { if (map !== undefined && !bounds.isEmpty()) {
map.fitBounds(bounds); map.fitBounds(bounds);
} }
} }
} }
...@@ -1011,18 +1011,20 @@ CustomMap.prototype.getOverlayDataForIdentifiedElement = function(identifiedElem ...@@ -1011,18 +1011,20 @@ CustomMap.prototype.getOverlayDataForIdentifiedElement = function(identifiedElem
generalFlag = false; generalFlag = false;
} }
overlays.push(overlay); overlays.push(overlay);
promises.push(overlay.getDetailDataByIdentifiedElement(identifiedElement, !overlay.allowSearchById() || generalFlag)); promises.push(overlay.getDetailDataByIdentifiedElement(identifiedElement, !overlay.allowSearchById()
|| generalFlag));
} }
} }
} }
return new Promise(function(resolve,reject){ return Promise.all(promises).then(function(values) {
Promise.all(promises).then(function(values){ var result = [];
var result = []; for (var i = 0; i < values.length; i++) {
for (var i=0;i<values.length;i++){ result.push({
result.push({overlay:overlays[i], data:values[i]}); overlay : overlays[i],
} data : values[i]
resolve(result); });
}).catch(reject); }
return result;
}); });
}; };
...@@ -1063,7 +1065,7 @@ CustomMap.prototype.setActiveSubmapId = function(submapId) { ...@@ -1063,7 +1065,7 @@ CustomMap.prototype.setActiveSubmapId = function(submapId) {
CustomMap.prototype.setActiveSubmapClickCoordinates = function(coordinates) { CustomMap.prototype.setActiveSubmapClickCoordinates = function(coordinates) {
if (!(coordinates instanceof google.maps.Point)) { if (!(coordinates instanceof google.maps.Point)) {
throw new Error("Coordinates must be provided as google.maps.Point object, but found: "+coordinates ); throw new Error("Coordinates must be provided as google.maps.Point object, but found: " + coordinates);
} }
this._activeSubmapCoordinates = coordinates; this._activeSubmapCoordinates = coordinates;
}; };
...@@ -1073,20 +1075,20 @@ CustomMap.prototype.getActiveSubmapClickCoordinates = function() { ...@@ -1073,20 +1075,20 @@ CustomMap.prototype.getActiveSubmapClickCoordinates = function() {
CustomMap.prototype.getReferenceGenome = function(type, version) { CustomMap.prototype.getReferenceGenome = function(type, version) {
var self = this; var self = this;
if (self.getProject().getOrganism()===undefined) { if (self.getProject().getOrganism() === undefined) {
return Promise.resolve(new ReferenceGenome(null)); return Promise.resolve(new ReferenceGenome(null));
} }
if (self._referenceGenome[type] === undefined) { if (self._referenceGenome[type] === undefined) {
self._referenceGenome[type] = []; self._referenceGenome[type] = [];
} }
if (self._referenceGenome[type][version] === undefined) { if (self._referenceGenome[type][version] === undefined) {
return ServerConnector.getReferenceGenome({ return ServerConnector.getReferenceGenome({
type:type, type : type,
version:version, version : version,
organism:self.getProject().getOrganism().name, organism : self.getProject().getOrganism().name,
}).then(function(genome){ }).then(function(genome) {
self._referenceGenome[type][version] =genome; self._referenceGenome[type][version] = genome;
return genome; return genome;
}); });
} else { } else {
...@@ -1111,16 +1113,16 @@ CustomMap.prototype.getTopOverviewImage = function() { ...@@ -1111,16 +1113,16 @@ CustomMap.prototype.getTopOverviewImage = function() {
CustomMap.prototype.addControl = function(element) { CustomMap.prototype.addControl = function(element) {
if (this._controls[element.id] !== undefined) { if (this._controls[element.id] !== undefined) {
throw new Error("Element with id "+element.id+" already added to controls"); throw new Error("Element with id " + element.id + " already added to controls");
} }
if (ControlType[element.id]===undefined) { if (ControlType[element.id] === undefined) {
throw new Error("Unknown control type: "+element.id); throw new Error("Unknown control type: " + element.id);
} }
this._controls[element.id]= element; this._controls[element.id] = element;
}; };
CustomMap.prototype.getControl = function(type) { CustomMap.prototype.getControl = function(type) {
if (ControlType[type]===undefined) { if (ControlType[type] === undefined) {
throw new Error("Unknown control type: " + type); throw new Error("Unknown control type: " + type);
} }
return this._controls[type]; return this._controls[type];
...@@ -1152,16 +1154,24 @@ CustomMap.prototype.getSelectionContextMenu = function() { ...@@ -1152,16 +1154,24 @@ CustomMap.prototype.getSelectionContextMenu = function() {
CustomMap.prototype.openCommentDialog = function() { CustomMap.prototype.openCommentDialog = function() {
var self = this; var self = this;
return ServerConnector.getClosestElementsByCoordinates({modelId:this.getActiveSubmapId(), coordinates:this.getActiveSubmapClickCoordinates()}).then(function(elements){ return ServerConnector.getClosestElementsByCoordinates({
modelId : this.getActiveSubmapId(),
coordinates : this.getActiveSubmapClickCoordinates()
}).then(function(elements) {
var commentDialog = self.getCommentDialog(); var commentDialog = self.getCommentDialog();
if (commentDialog===undefined) { if (commentDialog === undefined) {
var div = Functions.createElement({type: "div"}); var div = Functions.createElement({
type : "div"
});
self.getElement().appendChild(div); self.getElement().appendChild(div);
commentDialog = new CommentDialog({element:div, customMap:self}); commentDialog = new CommentDialog({
element : div,
customMap : self
});
self.setCommentDialog(commentDialog); self.setCommentDialog(commentDialog);
} }
self.setCommentDialog(commentDialog); self.setCommentDialog(commentDialog);
return commentDialog.open(elements); return commentDialog.open(elements);
}); });
}; };
...@@ -1170,86 +1180,83 @@ CustomMap.prototype.fetchIdentifiedElements = function(elements, complete) { ...@@ -1170,86 +1180,83 @@ CustomMap.prototype.fetchIdentifiedElements = function(elements, complete) {
var modelIds = []; var modelIds = [];
var modelElements = []; var modelElements = [];
var i; var i;
for (i=0;i<elements.length;i++) { for (i = 0; i < elements.length; i++) {
var element = elements[i]; var element = elements[i];
if (modelElements[element.getModelId()]===undefined) { if (modelElements[element.getModelId()] === undefined) {
modelIds.push(element.getModelId()); modelIds.push(element.getModelId());
modelElements[element.getModelId()]=[]; modelElements[element.getModelId()] = [];
} }
modelElements[element.getModelId()].push(element); modelElements[element.getModelId()].push(element);
} }
var promises = []; var promises = [];
for (i=0;i<modelIds.length;i++) { for (i = 0; i < modelIds.length; i++) {
var modelId = modelIds[i]; var modelId = modelIds[i];
promises.push(this.getSubmodelById(modelId).getModel().getByIdentifiedElements(modelElements[modelId], complete)); promises.push(this.getSubmodelById(modelId).getModel().getByIdentifiedElements(modelElements[modelId], complete));
} }
return Promise.all(promises); return Promise.all(promises);
}; };
CustomMap.prototype.refreshSearchAutocomplete = function(){ CustomMap.prototype.refreshSearchAutocomplete = function() {
var self = this; var self = this;
self._searchAutocomplete=[]; self._searchAutocomplete = [];
return new Promise(function(resolve, reject){ return ServerConnector.getSuggestedQueryList().then(function(queries) {
return ServerConnector.getSuggestedQueryList().then(function(queries){ for (var i = 0; i < queries.length; i++) {
for (var i = 0; i < queries.length; i++) { var mainString = queries[i];
var mainString = queries[i]; for (var j = 0; j < mainString.length; j++) {
for (var j = 0; j < mainString.length; j++) { var substring = mainString.substring(0, j + 1);
var substring = mainString.substring(0, j + 1); if (self._searchAutocomplete[substring] !== undefined) {
if (self._searchAutocomplete[substring] !== undefined) { continue;
continue; }
}
var list = []; var list = [];
for (var k = 0; k < 5; k++) { for (var k = 0; k < 5; k++) {
if (k + i >= queries.length) { if (k + i >= queries.length) {
break; break;
} else if (queries[k + i].toLowerCase().startsWith(substring.toLowerCase())) { } else if (queries[k + i].toLowerCase().startsWith(substring.toLowerCase())) {
list.push(queries[k + i]); list.push(queries[k + i]);
}
} }
self._searchAutocomplete[substring]=list;
} }
self._searchAutocomplete[substring] = list;
} }
resolve(self._searchAutocomplete); }
}).catch(reject); return self._searchAutocomplete;
}); });
}; };
CustomMap.prototype.getSearchAutocomplete = function(query){ CustomMap.prototype.getSearchAutocomplete = function(query) {
if (this._searchAutocomplete===undefined) { if (this._searchAutocomplete === undefined) {
this.refreshSearchAutocomplete(); this.refreshSearchAutocomplete();
return []; return [];
} }
return this._searchAutocomplete[query]; return this._searchAutocomplete[query];
}; };
CustomMap.prototype.setSelectedPolygon = function(polygonData){ CustomMap.prototype.setSelectedPolygon = function(polygonData) {
this._selectedPolygon = polygonData; this._selectedPolygon = polygonData;
}; };
CustomMap.prototype.getSelectedPolygon = function(){ CustomMap.prototype.getSelectedPolygon = function() {
return this._selectedPolygon; return this._selectedPolygon;
}; };
CustomMap.prototype.getSubmaps = function(){ CustomMap.prototype.getSubmaps = function() {
var submaps = this.submaps; var submaps = this.submaps;
if (submaps===undefined) { if (submaps === undefined) {
submaps=[]; submaps = [];
} }
return submaps; return submaps;
}; };
CustomMap.prototype.destroy = function(){ CustomMap.prototype.destroy = function() {
var self = this; var self = this;
var commentDialog = self.getCommentDialog(); var commentDialog = self.getCommentDialog();
if (commentDialog!==undefined) { if (commentDialog !== undefined) {
commentDialog.destroy(); commentDialog.destroy();
} }
}; };
module.exports = CustomMap; module.exports = CustomMap;
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