Commit 1c710d15 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

old serverConnector methods removed

parent 35b99756
......@@ -29,17 +29,6 @@ var GuiConnector = require('./GuiConnector');
var ServerConnector = {};
ServerConnector._configurationParam = [];
/**
* List of {@link OverlayCollection} that was added to the server connector. It
* describes list of all overlays that communicate with server.
*/
ServerConnector._overlays = [];
/**
* Associative array with methods that should be used for comunication of the
* {@link OverlayCollection} from _overlays field.
*/
ServerConnector._overlayMethods = [];
/**
* Form where fields passed to/from server are stored.
......@@ -48,216 +37,6 @@ ServerConnector.formIdentifier = "_gmapForm";
ServerConnector._customMap = null;
/**
* Sets data mining query that will be handled by server.
*/
ServerConnector.setDataMiningQuery = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':missingConnectionParam').value = "" + value;
};
/**
* Sets selected polygon. This might be in futer used oto extract/analyze data
* in the polygon by the server side.
*/
ServerConnector.setSelectedPolygon = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':selectedPolygon').value = "" + value;
};
/**
* Sets identifier of the model where selected polygon (@see
* ServerConnector.setSelectedPolygon) was selected.
*/
ServerConnector.setExportModelId = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':exportModelId').value = "" + value;
};
/**
* Search for similar data mining entries on the map.
*/
ServerConnector.showSimilarDataMining = function(param) {
document.getElementById(ServerConnector.formIdentifier + ':geneName').value = "" + param;
_searchMissingConnections();
};
/**
* Sends request to server to refresh data for overlay with a given name.
*
* @param overlayName
* name of the overlay
*/
ServerConnector.sendRefreshRequest = function(overlayName) {
var functions = ServerConnector._overlayMethods[overlayName];
if (functions !== undefined) {
var refreshFunction = functions.refreshFunction;
if (refreshFunction !== undefined) {
refreshFunction();
} else {
throw new Error("Refresh function for " + overlayName + " doesn't exist");
}
} else {
throw new Error("[Refresh function] Unknown overlay: ", overlayName);
}
};
/**
* Adds {@link OverlayCollection} to ServerConnector.
*/
ServerConnector.addOverlayCollection = function(overlay) {
if (ServerConnector._overlayMethods[overlay.name] !== undefined) {
if (ServerConnector._overlays[overlay.name] !== undefined) {
logger.warn("Overlay with name " + overlay.name + " already added");
return;
}
ServerConnector._overlays[overlay.name] = overlay;
if (ServerConnector._overlayMethods[overlay.name].initFunction !== undefined) {
ServerConnector._overlayMethods[overlay.name].initFunction();
} else {
logger.warn("Cannot initialize overlay: " + overlay);
}
} else {
if (overlay.constructor.name==="OverlayCollection") {
throw new Error("Unknown overlay: ", overlay);
} else {
logger.warn("Adding collection that shouldn't be added: "+overlay.constructor.name);
}
}
};
/**
* Method that should be called by server to update data in overlay.
*
* @param overlayName
* name of overlay for which the data is sent
* @param data
* new data for overlay
* @param fitBounds
* should the map call fitBounds after update
*/
ServerConnector.updateOverlayCollection = function(overlayName, data, fitBounds) {
logger.debug("Updating: " + overlayName);
var overlay = ServerConnector._overlays[overlayName];
if (overlay !== undefined) {
overlay.updateOverlays(data, fitBounds);
} else {
logger.warn("Overlay " + overlayName + " cannot be updated. It doesn't exist");
}
};
/**
* Name of the overlay for 'data mining' overlay.
*/
ServerConnector.DATA_MINING_OVERLAY_NAME = 'missingConnection';
/**
* Name of the overlay for 'chemical' overlay.
*/
ServerConnector.CHEMICAL_OVERLAY_NAME = 'chemical';
/**
* Name of the overlay for 'mirna' overlay.
*/
ServerConnector.MI_RNA_OVERLAY_NAME = 'mirna';
/**
* Register 'data mining' overlay on the server.
*/
ServerConnector.registerDataMiningOverlay = function() {
_registerMissingConnectionOverlayCollection([ {
name : "overlayName",
value : ServerConnector.DATA_MINING_OVERLAY_NAME,
} ]);
};
/**
* Sends request to the server to refresh data in 'data mining' overlay.
*/
ServerConnector.refreshDataMiningOverlay = function() {
_refreshMissingConnectionOverlayCollection();
};
/**
* Clear data related to 'data mining' overlay.
*/
ServerConnector.clearDataMiningOverlay = function() {
_clearMissingConnectionOverlayCollection();
};
/**
* Clear data related to 'data mining' overlay.
*/
ServerConnector.clearDataMiningOverlay = function() {
_clearMissingConnectionOverlayCollection();
};
/**
* Define pack of methods for 'data minig' overlay.
*/
ServerConnector._overlayMethods[ServerConnector.DATA_MINING_OVERLAY_NAME] = {
initFunction : ServerConnector.registerDataMiningOverlay,
refreshFunction : ServerConnector.refreshDataMiningOverlay,
clearFunction : ServerConnector.clearDataMiningOverlay,
};
ServerConnector.sendClearRequest = function(overlayName) {
var functions = ServerConnector._overlayMethods[overlayName];
if (functions !== undefined) {
var clearFunction = functions.clearFunction;
if (clearFunction !== undefined) {
clearFunction();
} else {
logger.warn("Clear function for " + overlayName + " doesn't exist");
}
} else if (overlayName==="search" || overlayName==="comment" || overlayName ==="drug"|| overlayName ==="chemical" || overlayName ==="mirna"){
logger.warn("Send clear request for overlay that doesn't support it: "+overlayName);
} else {
throw new Error("[Clear function] Unknown overlay: ", overlayName);
}
};
ServerConnector.setOverlayResultIds = function(overlayName, ids) {
var overlay = this._overlays[overlayName];
if (overlay !== undefined) {
overlay.setResultsIds(ids);
} else {
logger.warn("Overlay '" + overlayName + "' doesn't exist");
}
};
ServerConnector.sendOverlayDetailDataRequest = function(overlayName, identifiedElement, general) {
var overlay = ServerConnector._overlays[overlayName];
if (overlay === undefined) {
throw new Error("Unknown overlay: " + overlayName);
}
var functions = ServerConnector._overlayMethods[overlayName];
if (functions !== undefined) {
var requestDetailDataFunction = functions.requestDetailDataFunction;
if (requestDetailDataFunction !== undefined) {
var missingData = overlay.getMissingDetailDataIds(identifiedElement, general);
if (missingData.length === 0) {
logger.warn("request of missing data called for empty data set... overlay name = ", overlayName, "general: ",
general);
}
for (var i = 0; i < missingData.length; i++) {
requestDetailDataFunction(identifiedElement, missingData[i]);
}
} else {
logger.warn("Request detail data function for " + overlayName + " doesn't exist");
}
} else {
throw new Error("[Clear function] Unknown overlay: ", overlayName);
}
};
ServerConnector.updateOverviewElementDetailData = function(overlayName, searchResultIdentifier, identifiedElement, data) {
var overlay = this._overlays[overlayName];
if (overlay !== undefined) {
overlay.updateOverviewElementDetailData(identifiedElement, searchResultIdentifier, data);
} else {
logger.warn("Overlay '" + overlayName + "' doesn't exist");
}
};
ServerConnector.setCustomMap = function(customMap) {
this._customMap = customMap;
};
......@@ -266,38 +45,6 @@ ServerConnector.getCustomMap = function() {
return this._customMap;
};
ServerConnector.addAliasesForLayout = function(layoutId, jsonAliases) {
this.setWaitingForAliasLayoutData(parseInt(layoutId), false);
this.getCustomMap().addAliasesForLayout(layoutId, jsonAliases);
};
ServerConnector.updateAliasesForLayout = function(layoutId, jsonAliases) {
var arr = JSON.parse(jsonAliases);
for (var i = 0; i < arr.length; i++) {
this.setWaitingForFullAliasLayoutData(parseInt(layoutId), parseInt(arr[i].idObject), false);
}
this.getCustomMap().updateAliasesForLayout(layoutId, jsonAliases);
};
ServerConnector.addAliases = function(aliases) {
for (var i = 0; i < aliases.length; i++) {
this.setWaitingForAliasData(parseInt(aliases[i].idObject), false);
}
this.getCustomMap().addAliases(aliases);
};
ServerConnector.addReactionsForLayout = function(layoutId, jsonReactions) {
this.setWaitingForReactionLayoutData(parseInt(layoutId), false);
this.getCustomMap().addReactionsForLayout(layoutId, jsonReactions);
};
ServerConnector.addReactions = function(jsonReactions) {
var arr = JSON.parse(jsonReactions);
for (var i = 0; i < arr.length; i++) {
this.setWaitingForReactionData(parseInt(arr[i].idObject), false);
}
this.getCustomMap().addReactions(jsonReactions);
};
ServerConnector.sendReferenceGenomeDetailRequest = function(type, version) {
logger.debug("Send request", type, version);
......
......@@ -361,8 +361,7 @@ AbstractCustomMap.prototype.registerMapClickEvents = function() {
polygon += ne.lat() + "," + eastLng + ";";
polygon += sw.lat() + "," + eastLng + ";";
polygon += sw.lat() + "," + westLng + ";";
ServerConnector.setSelectedPolygon(polygon);
ServerConnector.setExportModelId(self.getId());
self.getTopMap().setSelectedPolygon({polygon: polygon, modelId: self.getId()});
});
// context menu event
......@@ -440,8 +439,7 @@ AbstractCustomMap.prototype.turnOnDrawing = function() {
self.setSelectedArea(newShape);
newShape.position = e.latLng;
ServerConnector.setSelectedPolygon(self.areaToString(newShape));
ServerConnector.setExportModelId(self.getId());
self.getTopMap().setSelectedPolygon({polygon: self.areaToString(newShape), modelId: self.getId()});
GuiConnector.showSelectionMenu(GuiConnector.xPos, GuiConnector.yPos);
});
......
......@@ -10,7 +10,6 @@ var AliasMarker = require('./marker/AliasMarker');
var CommentDialog = require('../gui/CommentDialog');
var ControlType = require('./ControlType');
var CustomMapOptions = require('./CustomMapOptions');
var CommentDbCollection = require('./overlay/CommentDbOverlay');
var IdentifiedElement = require('./data/IdentifiedElement');
var OverlayCollection = require('./overlay/OverlayCollection');
var PointMarker = require('./marker/PointMarker');
......@@ -54,8 +53,6 @@ function CustomMap(options) {
this.createMapChangedCallbacks();
this.createClientServerListeners();
this.overlayCollections = [];
// which submap is active (where user made interaction for the last time)
......@@ -200,19 +197,6 @@ CustomMap.prototype.clearOverlays = function() {
}
};
CustomMap.prototype.refreshOverlays = function() {
var promises = [];
for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) {
var collection = this.overlayCollections[overlayName];
if ((collection instanceof CommentDbCollection) || (collection.constructor.name==="OverlayCollection")) {
promises.push(collection.refresh());
}
}
}
return Promise.all(promises);
};
/**
* Removes all markers from {@link OverlayCollection}.
*
......@@ -478,11 +462,6 @@ CustomMap.prototype.turnOnOffDrawing = function() {
CustomMap.prototype.clearData = function() {
this.clearOverlays();
for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) {
ServerConnector.sendClearRequest(overlayName);
}
}
};
CustomMap.prototype.refreshMarkers = function() {
......@@ -554,8 +533,6 @@ CustomMap.prototype.openSubmodel = function(id, htmlTag, jsVar) {
// we have to perform it on top map, because on submaps id is different
this.openLayout(this.getGoogleMap().getMapTypeId());
this.refreshOverlays();
// now we have to visualize layouts
var layouts = [];
......@@ -1392,38 +1369,6 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
});
};
/**
* Creates and register listeners to be called on events:
* <ul>
* <li>onAddAliases</li>
* <li>onAddReactions</li>
* </ul>
*/
CustomMap.prototype.createClientServerListeners = function() {
this.registerListenerType("onAddAliases");
this.registerListenerType("onAddReactions");
var refreshLayoutsFun = function(e) {
var self = e.object;
if (!ServerConnector.isWaitingForData()) {
self.refreshSelectedLayouts();
// and close "loading" dialog (if opened)
GuiConnector.closeLoadingDialog();
}
};
var refreshOverlaysFun = function(e) {
e.object.refreshMarkers();
};
this.addListener("onAddAliases", refreshLayoutsFun);
this.addListener("onAddAliases", refreshOverlaysFun);
this.addListener("onAddReactions", refreshLayoutsFun);
this.addListener("onAddReactions", refreshOverlaysFun);
};
/**
* Opens {@link AbstractInfoWindow} for a marker.
*
......@@ -1479,7 +1424,8 @@ CustomMap.prototype.retrieveOverlayDetailDataForElement = function(element, gene
if (overlay.constructor.name === "OverlayCollection") {
if (overlay.allowGeneralSearch() || overlay.allowSearchById()) {
if (overlay.isMissingDetailData(element, generalRequest)) {
ServerConnector.sendOverlayDetailDataRequest(overlayName, element, generalRequest);
logger.warn("Unsupported call for overlay collection: "+overlay.getName());
// ServerConnector.sendOverlayDetailDataRequest(overlayName, element, generalRequest);
}
}
} else {
......@@ -1792,5 +1738,12 @@ CustomMap.prototype.getSearchAutocomplete = function(query){
return this._searchAutocomplete[query];
};
CustomMap.prototype.setSelectedPolygon = function(polygonData){
this._selectedPolygon = polygonData;
};
CustomMap.prototype.getSelectedPolygon = function(){
return this._selectedPolygon;
};
module.exports = CustomMap;
......@@ -20,6 +20,7 @@ function AbstractDbOverlay(params) {
this._elementsByQuery = [];
this._elementsByQuery[""] = [];
this.registerListenerType('onSearch');
this.registerListenerType('onTargetVisibilityChange');
......
......@@ -166,7 +166,6 @@ function create(params) {
collection = new OverlayCollection(collectionParams);
result.registerSource(collection);
}
ServerConnector.addOverlayCollection(collection);
}
} else {
logger.warn("No overlay collection defined");
......@@ -174,9 +173,7 @@ function create(params) {
return new Promise(function(resolve, reject) {
result.refreshOverlays().then(function() {
return restoreSearchQuery(result);
}).then(function(){
restoreSearchQuery(result).then(function(){
return restoreDrugQuery(result);
}).then(function(){
return restoreChemicalQuery(result);
......
'use strict';
/* exported logger */
var logger = require('./logger');
var OriginalServerConnector = require('../../main/js/ServerConnector');
......@@ -13,108 +15,10 @@ ServerConnectorMock.init = function() {
this._customMap = null;
this._sessionData = undefined;
ServerConnectorMock.listeners = [];
ServerConnectorMock.selectedPolygon = null;
ServerConnectorMock.exportModelId = null;
// add listener types
ServerConnectorMock.listeners.push("onActualizeSessionData");
ServerConnectorMock.listeners.push("onActualizeParams");
ServerConnectorMock.listeners.push("onSendClearRequest");
ServerConnectorMock.listeners.push("onSendOverlayDetailDataRequest");
ServerConnectorMock.listeners.push("onRequestUpdateCommentList");
ServerConnectorMock.listeners.push("onSearchByCoord");
};
ServerConnectorMock.init();
ServerConnectorMock.addListener = function(type, fun) {
if (ServerConnectorMock.listeners.indexOf(type) < 0) {
throw new Error("Unknown listener type: " + type);
}
if (typeof fun !== "function") {
throw new Error("Second parameter must be a function but \"" + typeof (fun) + "\" found.");
}
var listenerList = this.listeners[type];
if (listenerList === null || listenerList === undefined) {
listenerList = [];
this.listeners[type] = listenerList;
}
listenerList.push(fun);
};
ServerConnectorMock.removeListener = function(type, fun) {
if (ServerConnectorMock.listeners.indexOf(type) < 0) {
throw new Error("Unknown listener type: " + type);
}
if (typeof fun !== "function") {
throw new Error("Second parameter must be a function but \"" + typeof (fun) + "\" found.");
}
var listenerList = this.listeners[type];
if (listenerList !== null && listenerList !== undefined) {
var index = listenerList.indexOf(fun);
if (index > -1) {
listenerList.splice(index, 1);
}
}
};
ServerConnectorMock.callListeners = function(type, param) {
if (ServerConnectorMock.listeners.indexOf(type) < 0) {
throw new Error("Unknown listener type: " + type);
}
var listenerList = this.listeners[type];
if (listenerList !== null && listenerList !== undefined) {
logger.debug("ServerConnector is calling: " + type + ". " + listenerList.length + " listeners found.");
for ( var i in listenerList) {
var e = {};
e.type = type;
e.object = this;
e.param = param;
listenerList[i](e);
}
} else {
logger.debug("ServerConnector is calling: " + type + ". No listeners found.");
}
};
ServerConnectorMock.setSelectedPolygon = function(value) {
this.selectedPolygon = value;
};
ServerConnectorMock.getSelectedPolygon = function() {
return this.selectedPolygon;
};
ServerConnectorMock.setExportModelId = function(value) {
this.exportModelId = value;
};
ServerConnectorMock.getExportModelId = function() {
return this.exportModelId;
};
ServerConnectorMock.sendClearRequest = function(overlayName) {
ServerConnectorMock.callListeners("onSendClearRequest", overlayName);
};
ServerConnectorMock.sendOverlayDetailDataRequest = function(overlayName, identifiedElement) {
ServerConnectorMock.callListeners("onSendOverlayDetailDataRequest", overlayName, identifiedElement);
};
ServerConnectorMock.addOverlayCollection = function(overlay) {
logger.debug("Adding overlay: " + overlay);
};
ServerConnectorMock.sendRefreshRequest = function(overlayName) {
logger.debug("Send refresh request: " + overlayName);
};
ServerConnectorMock.getMaxOverlayColorInt = function() {
return 0xFF0000;
......
......@@ -218,12 +218,6 @@ describe('CustomMap', function() {
});
it("openInfoWindowForMarker", function() {
var onSendOverlayDetailDataRequest = 0;
ServerConnector.addListener("onSendOverlayDetailDataRequest", function() {
onSendOverlayDetailDataRequest++;
});
var alias = helper.createAlias();
var map = helper.createCustomMap();
......@@ -249,8 +243,6 @@ describe('CustomMap', function() {
map.openInfoWindowForMarker(aliasMarker);
assert.equal(1, onSendOverlayDetailDataRequest);
assert.ok(map.getAliasInfoWindowById(alias.getId()));
assert.ok(map.getAliasInfoWindowById(alias.getId()).isOpened());
});
......@@ -386,12 +378,6 @@ describe('CustomMap', function() {
overlayCollection : oc
});
var onSendClearRequest = 0;
ServerConnector.addListener("onSendClearRequest", function(e) {
assert.equal(oc.getName(), e.param);
onSendClearRequest++;
});
map.clearData();
var markerCount = 0;
......@@ -402,7 +388,6 @@ describe('CustomMap', function() {
}
assert.equal(0, markerCount);
assert.equal(1, onSendClearRequest);
});