Commit 6cb307dd authored by Piotr Gawron's avatar Piotr Gawron
Browse files

OverlayCollection takes one param in a constructor

parent c05cb51f
......@@ -15,37 +15,27 @@ var IdentifiedElement = require('../data/IdentifiedElement');
* name of the collection used to distinguish it from the other
* sources.
*/
function OverlayCollection(map, name, allowSearchById, allowGeneralSearch) {
function OverlayCollection(params) {
// map, name, allowSearchById, allowGeneralSearch
var self = this;
if (params.map === undefined) {
throw new Error("map param must be defined");
}
this.elements = [];
this.name = name;
this.setMap(map);
this.setName(params.name);
this.setMap(params.map);
this._ids = [];
// 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") {
this._allowSearchById = allowSearchById;
} else if (allowSearchById === undefined) {
this._allowSearchById = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowSearchById);
}
if (typeof allowGeneralSearch === "boolean") {
this._allowGeneralSearch = allowGeneralSearch;
} else if (allowGeneralSearch === undefined) {
this._allowGeneralSearch = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowGeneralSearch);
}
this.setAllowSearchById(params.allowSearchById);
this.setAllowGeneralSearch(params.allowGeneralSearch);
this._detailDataByIdentifiedElement = [];
// register source in the map
map.registerSource(self);
this.getMap().registerSource(self);
}
/**
......@@ -216,4 +206,34 @@ OverlayCollection.prototype.getMap = function() {
return this._map;
};
OverlayCollection.prototype.setName = function(name) {
this.name = name;
};
OverlayCollection.prototype.getName = function() {
return this.name;
};
OverlayCollection.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") {
this._allowSearchById = allowSearchById;
} else if (allowSearchById === undefined) {
this._allowSearchById = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowSearchById);
}
};
OverlayCollection.prototype.setAllowGeneralSearch = function(allowGeneralSearch) {
if (typeof allowGeneralSearch === "boolean") {
this._allowGeneralSearch = allowGeneralSearch;
} else if (allowGeneralSearch === undefined) {
this._allowGeneralSearch = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowGeneralSearch);
}
};
module.exports = OverlayCollection;
......@@ -63,9 +63,9 @@ function create(params) {
if (params.dataCollections !== undefined) {
for (var i = 0; i < params.dataCollections.length; i++) {
var collection = params.dataCollections[i];
ServerConnector.addOverlayCollection(new OverlayCollection(result, collection.name, collection.allowSearchById,
collection.allowGeneralSearch));
var collectionParams = params.dataCollections[i];
collectionParams.map = result;
ServerConnector.addOverlayCollection(new OverlayCollection(collectionParams));
}
result.refreshOverlays();
} else {
......
......@@ -11,6 +11,7 @@ var LayoutAlias = require("../../main/js/map/data/LayoutAlias");
var LayoutData = require("../../main/js/map/data/LayoutData");
var LayoutReaction = require("../../main/js/map/data/LayoutReaction");
var Model = require("../../main/js/map/data/MapModel");
var OverlayCollection = require("../../main/js/map/overlay/OverlayCollection");
var Project = require("../../main/js/map/data/Project");
var Reaction = require("../../main/js/map/data/Reaction");
......@@ -18,6 +19,30 @@ function Helper() {
this.idCounter = 1000000;
}
Helper.prototype.createCommentDbOverlay = function(map) {
var result = this.createDbOverlay(map);
result.setName('comment');
result.setAllowGeneralSearch(true);
return result;
};
Helper.prototype.createDrugDbOverlay = function(map) {
var result = this.createDbOverlay(map);
result.setName('drug');
result.setAllowGeneralSearch(true);
result.setAllowSearchById(true);
return result;
};
Helper.prototype.createDbOverlay = function(map) {
var result = new OverlayCollection({
map : map,
name : "overlay name: " + (this.idCounter++),
allowGeneralSearch : true
});
return result;
};
Helper.prototype.createProject = function() {
var result = new Project();
result.setId(this.idCounter++);
......
......@@ -203,7 +203,12 @@ describe('CustomMap', function() {
alias.setModelId(map.getId());
map.getModel().addAlias(alias);
var oc = new OverlayCollection(map, ovName, true, false);
var oc = new OverlayCollection({
map : map,
name : ovName,
allowSearchById : true,
allowGeneralSearch : false
});
var javaObj = {
objectId : "Point2D.Double[117.685546875, 204.6923828125001]",
......@@ -239,7 +244,12 @@ describe('CustomMap', function() {
alias.setModelId(map.getModel().getId());
map.getModel().addAlias(alias);
var oc = new OverlayCollection(map, ovName, true, false);
var oc = new OverlayCollection({
map : map,
name : ovName,
allowSearchById : true,
allowGeneralSearch : false
});
var javaObj = {
objectId : "Point2D.Double[117.685546875, 204.6923828125001]",
......@@ -285,7 +295,10 @@ describe('CustomMap', function() {
map.registerSource = function(overlayCollection) {
tmp = overlayCollection;
};
var oc = new OverlayCollection(map, 'testOV');
var oc = new OverlayCollection({
map : map,
name : 'testOV'
});
assert.equal(tmp, oc);
});
......@@ -300,7 +313,10 @@ describe('CustomMap', function() {
}
}
assert.equal(0, overlays1);
new OverlayCollection(map, 'testOV');
new OverlayCollection({
map : map,
name : 'testOV'
});
var overlays2 = 0;
for ( var key2 in map.overlayCollections) {
......@@ -320,7 +336,7 @@ describe('CustomMap', function() {
map.getModel().addAlias(alias);
map.getModel().addReaction(reaction);
var oc = new OverlayCollection(map, 'name');
var oc = helper.createDbOverlay(map);
oc.elements.push(new IdentifiedElement({
objectId : alias.getId(),
......@@ -345,7 +361,7 @@ describe('CustomMap', function() {
it("renderOverlayCollection for set of aliases", function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'name');
var oc = helper.createDbOverlay(map);
var aliases = [];
for (var i = 0; i < 3; i++) {
......@@ -372,7 +388,7 @@ describe('CustomMap', function() {
it("renderOverlayCollection for point", function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'name');
var oc = helper.createDbOverlay(map);
var javaObj = {
objectId : "Point2D.Double[117.685546875, 204.6923828125001]",
......@@ -401,7 +417,7 @@ describe('CustomMap', function() {
var reaction = helper.createReaction();
map.getModel().addReaction(reaction);
var oc = new OverlayCollection(map, 'name');
var oc = helper.createDbOverlay(map);
var javaObj = {
objectId : reaction.getId(),
......@@ -427,9 +443,7 @@ describe('CustomMap', function() {
it("clearData", function() {
var map = helper.createCustomMap();
var ovName = 'sopme name';
var oc = new OverlayCollection(map, ovName);
var oc = helper.createDbOverlay(map);
var javaObj = {
objectId : "Point2D.Double[117.685546875, 204.6923828125001]",
......@@ -446,7 +460,7 @@ describe('CustomMap', function() {
var onSendClearRequest = 0;
ServerConnector.addListener("onSendClearRequest", function(e) {
assert.equal(ovName, e.param);
assert.equal(oc.getName(), e.param);
onSendClearRequest++;
});
......
"use strict";
var Helper = require('../../Helper');
var IdentifiedElement = require('../../../../main/js/map/data/IdentifiedElement');
var OverlayCollection = require('../../../../main/js/map/overlay/OverlayCollection');
var assert = require('assert');
describe('OverlayCollection', function() {
var mapMock = {
registerSource : function() {
},
refreshInfoWindows : function() {
},
updateInfoWindowForIdentifiedElement : function() {
},
};
it("constructor 1", function() {
var oc = new OverlayCollection(mapMock, 'test name');
assert.ok(oc);
});
it("constructor 2", function() {
var oc = new OverlayCollection(mapMock, 'test name', true);
assert.ok(oc);
});
it("constructor 3", function() {
var oc = new OverlayCollection(mapMock, 'test name', false, true);
assert.ok(oc);
});
it("updateOverviewElementDetailData", function() {
var searchId = 'some_id';
var helper;
before(function() {
helper = new Helper();
});
var mapMock = {
registerSource : function() {
},
refreshInfoWindows : function() {
},
updateInfoWindowForIdentifiedElement : function() {
},
};
var oc = new OverlayCollection(mapMock, 'test name', true);
assert.ok(oc);
it("constructor 1", function() {
var oc = new OverlayCollection({
map : mapMock,
name : 'test name'
});
assert.ok(oc);
assert.equal(oc.getName(), 'test name');
});
it("constructor 2", function() {
var oc = new OverlayCollection({
map : mapMock,
name : 'test name',
allowSearchById : true
});
assert.ok(oc);
assert.ok(oc.allowSearchById());
});
it("constructor 3", function() {
var oc = new OverlayCollection({
map : mapMock,
name : 'test name',
allowSearchById : false,
allowGeneralSearch : true
});
assert.ok(oc);
assert.ok(oc.allowGeneralSearch());
});
it("updateOverviewElementDetailData", function() {
var searchId = 'some_id';
var oc = helper.createDrugDbOverlay(mapMock);
assert.ok(oc);
var javaObj = {
objectId : "31165",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var javaObj2 = {
objectId : "31166",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var ie = new IdentifiedElement(javaObj);
var ie2 = new IdentifiedElement(javaObj2);
var javaObj = {
objectId : "31165",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var javaObj2 = {
objectId : "31166",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var ie = new IdentifiedElement(javaObj);
var ie2 = new IdentifiedElement(javaObj2);
var data = oc.getDetailDataByIdentifiedElement(ie, false);
var data = oc.getDetailDataByIdentifiedElement(ie, false);
assert.deepEqual([], data);
assert.deepEqual([], data);
oc.setResultsIds([ searchId ]);
oc.setResultsIds([ searchId ]);
var result = {
field : 'val'
};
var result = {
field : 'val'
};
oc.updateOverviewElementDetailData(javaObj, searchId, result);
oc.updateOverviewElementDetailData(javaObj, searchId, result);
data = oc.getDetailDataByIdentifiedElement(ie, false);
assert.deepEqual(result, data[searchId]);
data = oc.getDetailDataByIdentifiedElement(ie, false);
assert.deepEqual(result, data[searchId]);
var data2 = oc.getDetailDataByIdentifiedElement(ie2, false);
assert.deepEqual(result, data[searchId]);
assert.equal(null, data2[searchId]);
var data2 = oc.getDetailDataByIdentifiedElement(ie2, false);
assert.deepEqual(result, data[searchId]);
assert.equal(null, data2[searchId]);
});
it("getMissingDetailDataIds", function() {
var oc = helper.createDbOverlay(mapMock);
assert.ok(oc);
});
it("getMissingDetailDataIds", function() {
var oc = new OverlayCollection(mapMock, 'test name', false, true);
assert.ok(oc);
var javaObj = {
objectId : "31165",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var ie = new IdentifiedElement(javaObj);
var javaObj = {
objectId : "31165",
modelId : 269,
type : "alias",
icon : "marker/marker/marker_red_1.png"
};
var ie = new IdentifiedElement(javaObj);
var data = oc.getMissingDetailDataIds(ie, true);
var data = oc.getMissingDetailDataIds(ie, true);
assert.deepEqual([ null ], data);
assert.deepEqual([ null ], data);
var result = {
field : 'val'
};
var result = {
field : 'val'
};
oc.updateOverviewElementDetailData(javaObj, '__FULL__', result);
oc.updateOverviewElementDetailData(javaObj, '__FULL__', result);
data = oc.getMissingDetailDataIds(ie, true);
data = oc.getMissingDetailDataIds(ie, true);
assert.deepEqual([], data);
});
assert.deepEqual([], data);
});
});
......@@ -159,7 +159,12 @@ describe('AliasInfoWindow', function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'test name', false, true);
var oc = new OverlayCollection({
map : map,
name : 'test name',
allowSearchById : false,
allowGeneralSearch : true
});
var alias = new Alias({
idObject : aliasId,
......@@ -192,7 +197,7 @@ describe('AliasInfoWindow', function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'drug', true, true);
var oc = helper.createDrugDbOverlay(map);
var alias = new Alias({
idObject : aliasId,
......@@ -232,7 +237,7 @@ describe('AliasInfoWindow', function() {
var map = helper.createCustomMap();
var oc = new OverlayCollection(map, 'comment', false, true);
var oc = helper.createCommentDbOverlay(map);
var alias = new Alias({
idObject : aliasId,
......
Markdown is supported
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