Commit 67bc0bc4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

refactoring (referecnces to id moved to getters/setters)

parent e5a5d4d4
......@@ -48,7 +48,7 @@ Configuration.prototype.loadFromModelView = function(modelView) {
// replace is due to some strange problem with serialization
modelView = JSON.parse(modelView.replace(/\n/g, " "));
}
this.ID_MODEL = parseInt(modelView.idObject);
this.setId(parseInt(modelView.idObject));
this.TILE_SIZE = modelView.tileSize;
this.PICTURE_SIZE = modelView.pictureSize;
this.MAX_ZOOM = modelView.maxZoom;
......@@ -82,6 +82,10 @@ Configuration.prototype.getId = function() {
return this.ID_MODEL;
};
Configuration.prototype.setId = function(id) {
this.ID_MODEL = id;
};
Configuration.prototype.setCenter = function(center) {
if (center !== undefined) {
this.CENTER_LAT = center.lat;
......
This diff is collapsed.
......@@ -11,13 +11,13 @@ var TouchMap = require('./TouchMap');
* (popup window) is initialized on demand using init function.
*
* @param customMap
* parent CustomMap
* parent CustomMap
* @param id
* identifier of the submap
* identifier of the submap
*/
function Submap(customMap, id) {
this.customMap = customMap;
this.id = id;
this.seId(id);
this.configuration = new Configuration();
this.loadSubmapConfiguration();
......@@ -43,17 +43,16 @@ Submap.prototype.constructor = Submap;
* is created and contains data, but cannot be visualized in the broswer.
*
* @param htmlTag
* html div tag where google map should be placed
* html div tag where google map should be placed
* @param jsVar
* javascript component of primefaces popup dialog where submap will
* be visualized
* javascript component of primefaces popup dialog where submap will be
* visualized
*/
Submap.prototype.init = function(htmlTag, jsVar) {
logger.debug("Initializing gui: " + this.id);
logger.debug("Initializing gui: " + this.getId());
if (jsVar.submapControler !== undefined) {
throw "Submodel with "
+ this.id
throw "Submodel with " + this.getId()
+ " cannot be created, because provided dialog window already has associated submodel";
} else {
this.htmlTag = htmlTag;
......@@ -109,16 +108,15 @@ Submap.prototype.init = function(htmlTag, jsVar) {
this.registerMapClickEvents();
// after resizing center map
var centerPoint = new google.maps.LatLng(this.configuration.CENTER_LAT,
this.configuration.CENTER_LNG);
var centerPoint = new google.maps.LatLng(this.configuration.CENTER_LAT, this.configuration.CENTER_LNG);
self.map.setCenter(centerPoint);
// and now send the zoom level to the client side
google.maps.event.addListener(this.map, 'zoom_changed', function() {
ServerConnector.setModelZoomLevel(self.id, self.map.getZoom());
ServerConnector.setModelZoomLevel(self.getId(), self.map.getZoom());
});
ServerConnector.setModelZoomLevel(self.id, self.map.getZoom());
ServerConnector.setModelZoomLevel(self.getId(), self.map.getZoom());
}
};
......@@ -133,17 +131,16 @@ Submap.prototype.loadSubmapConfiguration = function() {
var self = this;
var onConfigurationReload = function() {
var submodelFound = false;
for (var i = 0; i < self.customMap.configuration.SUBMODELS.length
&& (!submodelFound); i++) {
if (self.customMap.configuration.SUBMODELS[i].ID_MODEL === self.id) {
for (var i = 0; i < self.customMap.configuration.SUBMODELS.length && (!submodelFound); i++) {
if (self.customMap.configuration.SUBMODELS[i].getId() === self.getId()) {
self.configuration = self.customMap.configuration.SUBMODELS[i];
submodelFound = true;
}
}
if (!submodelFound) {
throw "Cannot find configuration for submodel " + self.id;
throw "Cannot find configuration for submodel " + self.getId();
}
logger.debug("Submodel config reloaded: " + self.id);
logger.debug("Submodel config reloaded: " + self.getId());
};
onConfigurationReload();
......
......@@ -9,7 +9,7 @@ var logger = require('../../logger');
* object deserialized ajax query to the server side
*/
function Alias(javaObject) {
this.id = javaObject.idObject;
this.setId(javaObject.idObject);
this._modelId = javaObject.modelId;
if (javaObject.bounds !== undefined) {
this.x = javaObject.bounds.x;
......@@ -63,6 +63,10 @@ Alias.prototype.getId = function() {
return this.id;
};
Alias.prototype.setId = function(id) {
this.id = id;
};
/**
* Returns model identifier where {@link Alias} is located.
*
......
......@@ -19,20 +19,20 @@ var logger = require('../../logger');
*/
function IdentifiedElement(javaObject) {
if (javaObject instanceof Alias) {
this.id = javaObject.getId();
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.type = "ALIAS";
} else if (javaObject instanceof Reaction) {
this.id = javaObject.getId();
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.type = "REACTION";
} else if (javaObject instanceof PointData) {
this.id = javaObject.getId();
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.type = "POINT";
} else {
// identifier of the object to visualize
this.id = javaObject.objectId;
this.setId(javaObject.objectId);
// which marker should be used to show this object
this.icon = javaObject.icon;
// on which model the element is located
......@@ -47,8 +47,8 @@ function IdentifiedElement(javaObject) {
this.type = this.type.toUpperCase();
if (this.type === "POINT") {
var tmp = this.id;
if (this.id.indexOf("Point2D.Double") >= 0) {
var tmp = this.getId();
if (tmp.indexOf("Point2D.Double") >= 0) {
tmp = tmp.replace("Point2D.Double", "");
tmp = JSON.parse(tmp);
} else {
......@@ -63,7 +63,7 @@ function IdentifiedElement(javaObject) {
throw "Unknown type of identified element: " + this.type;
}
if (this.id === undefined || this.id === null) {
if (this.getId() === undefined || this.getId() === null) {
throw "Id not defined for element: " + javaObject;
}
if (this.modelId === undefined || this.modelId === null) {
......@@ -96,6 +96,10 @@ IdentifiedElement.prototype.getId = function() {
return this.id;
};
IdentifiedElement.prototype.setId = function(id) {
this.id = id;
};
/**
* Returns model identifier where element is placed.
*
......
......@@ -8,10 +8,10 @@ var GeneVariant = require('./GeneVariant');
* Class representing alias visualized in a layout.
*
* @param javaObject
* object deserialized ajax query to the server side
* object deserialized ajax query to the server side
*/
function LayoutAlias(javaObject) {
this.id = javaObject.idObject;
this.setId(javaObject.idObject);
this.setValue(javaObject.value);
this.setColor(javaObject.color);
if (javaObject.type === undefined) {
......@@ -40,6 +40,10 @@ LayoutAlias.prototype.getId = function() {
return this.id;
};
LayoutAlias.prototype.setId = function(id) {
this.id = id;
};
LayoutAlias.prototype.getValue = function() {
return this.value;
};
......
......@@ -6,8 +6,8 @@ var logger = require('../../logger');
* Class representing data in a specific layout.
*/
function LayoutData(layoutId, name) {
this.id = layoutId;
this.name = name;
this.setId(layoutId);
this.setName(name);
this.aliases = [];
this.aliasById = [];
this.reactions = [];
......@@ -42,6 +42,14 @@ LayoutData.prototype.getName = function() {
return this.name;
};
LayoutData.prototype.setId = function(id) {
this.id = id;
};
LayoutData.prototype.setName = function(name) {
this.name = name;
};
LayoutData.prototype.updateAlias = function(layoutAlias) {
if (this.aliasById[layoutAlias.getId()] === undefined) {
logger.warn("Cannot update alias, it doesn't exist. Alias: ", layoutAlias.getId());
......
......@@ -4,10 +4,10 @@
* Class representing reaction visualized in a layout.
*
* @param javaObject
* object deserialized from ajax query to the server side
* object deserialized from ajax query to the server side
*/
function LayoutReaction(javaObject) {
this.id = javaObject.idObject;
this.setId(javaObject.idObject);
this.width = javaObject.width;
this.color = javaObject.color;
this.reverse = javaObject.reverse;
......@@ -16,6 +16,11 @@ function LayoutReaction(javaObject) {
LayoutReaction.prototype.getId = function() {
return this.id;
};
LayoutReaction.prototype.setId = function(id) {
this.id = id;
};
LayoutReaction.prototype.getWidth = function() {
return this.width;
};
......@@ -27,4 +32,3 @@ LayoutReaction.prototype.getReverse = function() {
};
module.exports = LayoutReaction;
......@@ -21,7 +21,7 @@ var Reaction = require('./Reaction');
function MapModel(configuration) {
// identifier of the map
this.id = configuration.ID_MODEL;
this.setId(configuration.getId());
// list of aliases is empty (it will be filled dynamically - when necessary)
this._aliases = [];
......@@ -58,7 +58,7 @@ MapModel.prototype.initLayoutData = function(layoutId, name) {
layout = new LayoutData(layoutId, name);
this._layoutsData[layoutId] = layout;
} else {
logger.warn("Layout " + layoutId + " already exists in a model: " + this.id);
logger.warn("Layout " + layoutId + " already exists in a model: " + this.getId());
}
};
......@@ -128,9 +128,9 @@ MapModel.prototype.addAliasForLayout = function(layoutId, aliasData) {
// if we don't have basic information about alias then mark alias to be
// missing
if (this._aliases[alias.id] === undefined) {
if (this._missingAliases[alias.id] === undefined) {
this._missingAliases[alias.id] = alias.id;
if (this._aliases[alias.getId()] === undefined) {
if (this._missingAliases[alias.getId()] === undefined) {
this._missingAliases[alias.getId()] = alias.getId();
}
}
};
......@@ -148,9 +148,9 @@ MapModel.prototype.addReactionForLayout = function(layoutId, reactionData) {
var layout = this.getLayoutDataById(layoutId);
var reaction = new LayoutReaction(reactionData);
layout.addReaction(reaction);
if (this._reactions[reaction.id] === undefined) {
if (this._missingReactions[reaction.id] === undefined) {
this._missingReactions[reaction.id] = reaction.id;
if (this._reactions[reaction.getId()] === undefined) {
if (this._missingReactions[reaction.getId()] === undefined) {
this._missingReactions[reaction.getId()] = reaction.getId();
}
}
};
......@@ -174,13 +174,13 @@ MapModel.prototype.getLayoutDataById = function(layoutId) {
*/
MapModel.prototype.addAlias = function(aliasData) {
var alias = new Alias(aliasData);
if (this._aliases[alias.id] !== undefined) {
this._aliases[alias.id].update(alias);
if (this._aliases[alias.getId()] !== undefined) {
this._aliases[alias.getId()].update(alias);
} else {
this._aliases[alias.id] = alias;
if (this._missingAliases[alias.id] !== undefined) {
this._missingAliases[alias.id] = null;
delete this._missingAliases[alias.id];
this._aliases[alias.getId()] = alias;
if (this._missingAliases[alias.getId()] !== undefined) {
this._missingAliases[alias.getId()] = null;
delete this._missingAliases[alias.getId()];
}
}
};
......@@ -198,13 +198,13 @@ MapModel.prototype.addReaction = function(reactionData) {
} else {
reaction = new Reaction(reactionData);
}
if (this._reactions[reaction.id] !== undefined) {
logger.warn("Reaction with id: " + reaction.id + " already exists");
if (this._reactions[reaction.getId()] !== undefined) {
logger.warn("Reaction with id: " + reaction.getId() + " already exists");
} else {
this._reactions[reaction.id] = reaction;
if (this._missingReactions[reaction.id] !== undefined) {
this._missingReactions[reaction.id] = null;
delete this._missingReactions[reaction.id];
this._reactions[reaction.getId()] = reaction;
if (this._missingReactions[reaction.getId()] !== undefined) {
this._missingReactions[reaction.getId()] = null;
delete this._missingReactions[reaction.getId()];
}
}
};
......@@ -280,7 +280,7 @@ MapModel.prototype.getPointDataByPoint = function(inputPoint) {
var id = this._pointToId(point);
var result = this._pointsData[id];
if (result === undefined) {
result = new PointData(point, this.id);
result = new PointData(point, this.getId());
this._pointsData[id] = result;
}
return result;
......@@ -325,12 +325,19 @@ MapModel.prototype.updateAliasForLayout = function(layoutId, aliasData) {
// if we don't have basic information about alias then mark alias to be
// missing
if (this._aliases[alias.id] === undefined) {
if (this._missingAliases[alias.id] === undefined) {
this._missingAliases[alias.id] = alias.id;
if (this._aliases[alias.getId()] === undefined) {
if (this._missingAliases[alias.getId()] === undefined) {
this._missingAliases[alias.getId()] = alias.getId();
}
}
}
};
MapModel.prototype.getId = function() {
return this.id;
};
MapModel.prototype.setId = function(id) {
this.id = id;
};
module.exports = MapModel;
......@@ -23,8 +23,8 @@ function AliasOverlay(paramObj, map, aliasData) {
var onclick = (function() {
var aliasOverlayData = self;
return function() {
self.getCustomMap().openInfoWindowForAlias(aliasOverlayData.aliasData.id,
aliasOverlayData.customMap.id);
self.getCustomMap()
.openInfoWindowForAlias(aliasOverlayData.aliasData.getId(), aliasOverlayData.customMap.getId());
};
})();
google.maps.event.addListener(paramObj, 'click', onclick);
......@@ -37,7 +37,7 @@ AliasOverlay.prototype.constructor = AliasOverlay;
* Sets Google map to this {@link AliasOverlay}.
*
* @param map
* map to set
* map to set
*/
AliasOverlay.prototype.setMap = function(map) {
this.gmapObj.setMap(map);
......@@ -53,15 +53,14 @@ AliasOverlay.prototype.getCustomMap = function() {
* visualization.
*
* @param startX
* value between 0..1 defininf where should be the start on OX axis
* value between 0..1 defininf where should be the start on OX axis
* @param endX
* value between 0..1 defininf where should be the end on OX axis
* value between 0..1 defininf where should be the end on OX axis
*/
AliasOverlay.prototype.setBoundsForAlias = function(startX, endX) {
var pointA = new google.maps.Point(this.aliasData.x + startX
* this.aliasData.width, this.aliasData.y);
var pointB = new google.maps.Point(this.aliasData.x + endX
* this.aliasData.width, this.aliasData.y + this.aliasData.height);
var pointA = new google.maps.Point(this.aliasData.x + startX * this.aliasData.width, this.aliasData.y);
var pointB = new google.maps.Point(this.aliasData.x + endX * this.aliasData.width, this.aliasData.y
+ this.aliasData.height);
var latLngA = this.customMap.fromPointToLatLng(pointA);
var latLngB = this.customMap.fromPointToLatLng(pointB);
......@@ -76,30 +75,28 @@ AliasOverlay.prototype.setBoundsForAlias = function(startX, endX) {
* Creates {@link AliasOverlay} from input data.
*
* @param layoutAlias
* {@link LayoutAlias} for which overlay is created
* {@link LayoutAlias} for which overlay is created
* @param aliasData
* {@link Alias data} of the alias
* {@link Alias data} of the alias
* @param map
* {@link AbstractCustomMap} where overlay should be placed
* {@link AbstractCustomMap} where overlay should be placed
* @param startX
* this is the ratio on OX axis that should be use as a starting
* point of the overlay. For instance when there are three layouts to
* visualize then
* <ul>
* <li>the first layout have startX=0.0; endX=0.33333</li>
* <li>second layout have startX=0.33333; endX=0.66666</li>
* <li>the last layout have startX=0.66666; endX=1.0</li>
* </ul>
* this is the ratio on OX axis that should be use as a starting point
* of the overlay. For instance when there are three layouts to
* visualize then
* <ul>
* <li>the first layout have startX=0.0; endX=0.33333</li>
* <li>second layout have startX=0.33333; endX=0.66666</li>
* <li>the last layout have startX=0.66666; endX=1.0</li>
* </ul>
* @param endX
* this is the ratio on OX axis that should be use as a starting
* point of the overlay
* this is the ratio on OX axis that should be use as a starting point
* of the overlay
* @returns {AliasOverlay}
*/
AliasOverlay.create = function(layoutAlias, aliasData, map, startX, endX) {
var pointA = new google.maps.Point(aliasData.x + startX * aliasData.width,
aliasData.y);
var pointB = new google.maps.Point(aliasData.x + endX * aliasData.width,
aliasData.y + aliasData.height);
var pointA = new google.maps.Point(aliasData.x + startX * aliasData.width, aliasData.y);
var pointB = new google.maps.Point(aliasData.x + endX * aliasData.width, aliasData.y + aliasData.height);
var latLngA = map.fromPointToLatLng(pointA);
var latLngB = map.fromPointToLatLng(pointB);
......
......@@ -22,8 +22,7 @@ function AliasInfoWindow(alias, map) {
}
if (this.alias !== undefined && this.alias !== null) {
var point = new google.maps.Point(this.alias.x + this.alias.width / 2,
this.alias.y + this.alias.height / 2);
var point = new google.maps.Point(this.alias.x + this.alias.width / 2, this.alias.y + this.alias.height / 2);
var latLng = this.customMap.fromPointToLatLng(point);
this.googleInfowindow = new google.maps.InfoWindow({
content : this.content,
......@@ -45,8 +44,8 @@ AliasInfoWindow.prototype.constructor = AliasInfoWindow;
* data.
*
* @param newAlias
* optional {@link Alias} data for which this {@link AliasInfoWindow}
* was created
* optional {@link Alias} data for which this {@link AliasInfoWindow}
* was created
*/
AliasInfoWindow.prototype.update = function(newAlias) {
if (this.alias === undefined && newAlias !== undefined) {
......@@ -150,18 +149,17 @@ AliasInfoWindow.prototype.createContentDiv = function() {
title.innerHTML = this.alias.type + ": " + this.alias.name;
result.appendChild(title);
this.layoutAliases = this.customMap
.getAliasVisibleLayoutsData(this.alias.id);
this.layoutAliases = this.customMap.getAliasVisibleLayoutsData(this.alias.getId());
this.layoutNames = this.customMap.getVisibleLayoutNames();
var selectedLayouts = this.customMap.getTopMap().getSelectedLayouts();
for (var i = 0; i < this.layoutAliases.length; i++) {
if (this.layoutAliases[i] !== undefined && this.layoutAliases[i] !== null) {
if (this.layoutAliases[i].getType() === LayoutAlias.LIGTH) {
if (!ServerConnector.isWaitingForFullAliasLayoutData(
parseInt(selectedLayouts[i]), parseInt(this.alias.getId()))) {
ServerConnector.retreiveFullAliasesForLayout(selectedLayouts[i],
this.alias.getId(), this.alias.getModelId());
if (!ServerConnector.isWaitingForFullAliasLayoutData(parseInt(selectedLayouts[i]), parseInt(this.alias
.getId()))) {
ServerConnector.retreiveFullAliasesForLayout(selectedLayouts[i], this.alias.getId(), this.alias
.getModelId());
}
}
}
......@@ -190,8 +188,7 @@ AliasInfoWindow.prototype.createContentDiv = function() {
*/
AliasInfoWindow.prototype.getOverlaysData = function(general) {
if (this.alias !== undefined && this.alias !== null) {
return this.getCustomMap().getTopMap().getOverlayDataForAlias(this.alias,
general);
return this.getCustomMap().getTopMap().getOverlayDataForAlias(this.alias, general);
} else {
return null;
}
......@@ -258,19 +255,15 @@ AliasInfoWindow.prototype.createGenomicDiv = function() {
globalGeneVariants[i].push(variant);
var genome = this.getCustomMap().getReferenceGenome(
variant.getReferenceGenomeType(),
var genome = this.getCustomMap().getReferenceGenome(variant.getReferenceGenomeType(),
variant.getReferenceGenomeVersion());
if (variant.getContig() !== undefined) {
pileupRange.contig = variant.getContig();
}
pileupRange.start = Math.min(pileupRange.start, variant
.getPosition());
var length = Math.max(variant.getModifiedDna().length, variant
.getOriginalDna().length);
pileupRange.stop = Math.max(pileupRange.stop, variant.getPosition()
+ length);
pileupRange.start = Math.min(pileupRange.start, variant.getPosition());
var length = Math.max(variant.getModifiedDna().length, variant.getOriginalDna().length);
pileupRange.stop = Math.max(pileupRange.stop, variant.getPosition() + length);
if (genome !== undefined && genome.getUrl() !== undefined) {
if (genomes[genome.getUrl()] === undefined) {
......@@ -298,8 +291,8 @@ AliasInfoWindow.prototype.createGenomicDiv = function() {
}
} else {
logger.debug("Genome for " + variant.getReferenceGenomeType()
+ "," + variant.getReferenceGenomeVersion() + " not loaded");
logger.debug("Genome for " + variant.getReferenceGenomeType() + "," + variant.getReferenceGenomeVersion()
+ " not loaded");
missingGeneVariantsData = true;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment