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

additional structures to support new way of obtaining data

parent 1aab8aab
No related branches found
No related tags found
1 merge request!5Frontend refactor
......@@ -23,6 +23,7 @@
},
"dependencies": {
"log4js": "0.6.38",
"pileup": "^0.6.8"
"pileup": "^0.6.8",
"promise": "^7.1.1"
}
}
This diff is collapsed.
......@@ -17,7 +17,7 @@ var TouchMap = require('./TouchMap');
*/
function Submap(customMap, id) {
this.customMap = customMap;
this.seId(id);
this.setId(id);
this.configuration = new Configuration();
this.loadSubmapConfiguration();
......
......@@ -3,6 +3,7 @@
var logger = require('../../logger');
var Alias = require('./Alias');
var Configuration = require('../../Configuration');
var LayoutAlias = require('./LayoutAlias');
var LayoutData = require('./LayoutData');
var LayoutReaction = require('./LayoutReaction');
......@@ -20,9 +21,6 @@ var Reaction = require('./Reaction');
*/
function MapModel(configuration) {
// identifier of the map
this.setId(configuration.getId());
// list of aliases is empty (it will be filled dynamically - when necessary)
this._aliases = [];
......@@ -44,6 +42,23 @@ function MapModel(configuration) {
// associated to the point,
// but it can be extended)
this._pointsData = [];
if (configuration instanceof Configuration) {
this.setId(configuration.getId());
} else {
this.setId(configuration.idObject);
this.setName(configuration.name);
this.setTileSize(configuration.tileSize);
this.setWidth(configuration.width);
this.setHeight(configuration.height);
this.setMinZoom(configuration.minZoom);
this.setMaxZoom(configuration.maxZoom);
this.addLayouts(configuration.layouts);
this.setCenterLatLng(configuration.centerLatLng);
this.setTopLeftLatLng(configuration.topLeftLatLng);
this.setBottomRightLatLng(configuration.bottomRightLatLng);
}
}
/**
......@@ -340,4 +355,87 @@ MapModel.prototype.getId = function() {
MapModel.prototype.setId = function(id) {
this.id = id;
};
MapModel.prototype.getWidth = function() {
return this._width;
};
MapModel.prototype.setWidth = function(width) {
this._width = width;
};
MapModel.prototype.getHeight = function() {
return this._height;
};
MapModel.prototype.setHeight = function(height) {
this._height = height;
};
MapModel.prototype.getName = function() {
return this._name;
};
MapModel.prototype.setName = function(name) {
this._name = name;
};
MapModel.prototype.getMinZoom = function() {
return this._minZoom;
};
MapModel.prototype.setMinZoom = function(minZoom) {
this._minZoom = minZoom;
};
MapModel.prototype.setCenterLatLng = function(centerLatLng) {
this._centerLatLng = new google.maps.LatLng(centerLatLng.lat, centerLatLng.lng);
};
MapModel.prototype.getCenterLatLng = function() {
return this._centerLatLng;
};
MapModel.prototype.getCenterLatLng = function() {
return this._centerLatLng;
};
MapModel.prototype.setTopLeftLatLng = function(topLeftLatLng) {
this._topLeftLatLng = new google.maps.LatLng(topLeftLatLng.lat, topLeftLatLng.lng);
};
MapModel.prototype.getTopLeftLatLng = function() {
return this._topLeftLatLng;
};
MapModel.prototype.setBottomRightLatLng = function(bottomRightLatLng) {
this._bottomRightLatLng = new google.maps.LatLng(bottomRightLatLng.lat, bottomRightLatLng.lng);
};
MapModel.prototype.getBottomRightLatLng = function() {
return this._bottomRightLatLng;
};
MapModel.prototype.getMaxZoom = function() {
return this._maxZoom;
};
MapModel.prototype.setMaxZoom = function(maxZoom) {
this._maxZoom = maxZoom;
};
MapModel.prototype.getTileSize = function() {
return this._tileSize;
};
MapModel.prototype.setTileSize = function(tileSize) {
this._tileSize = tileSize;
};
MapModel.prototype.addLayouts = function(layouts) {
for (var i = 0; i < layouts.length; i++) {
this.initLayoutData(layouts[i].idObject, layouts[i].name);
}
};
module.exports = MapModel;
"use strict";
var ObjectWithListeners = require('../../ObjectWithListeners');
var Model = require('./MapModel');
function Project(data) {
// call super constructor
ObjectWithListeners.call(this);
this.registerListenerType("onreload");
if (data !== undefined) {
this.loadFromData(data);
}
}
// this class inherits from ObjectWithListeners class where generic methods for
// listeners are set
Project.prototype = Object.create(ObjectWithListeners.prototype);
Project.prototype.constructor = Project;
Project.prototype.loadFromData = function(data) {
if (typeof data === "string") {
// replace is due to some strange problem with serialization
data = JSON.parse(data.replace(/\n/g, " "));
}
this.setId(parseInt(data.idObject));
this.setProjectId(data.projectId);
this.setVersion(data.version);
this.setName(data.name);
this.setDescription(data.description);
this.setOverviewImages(data.overviewImageViews);
this.setTopOverviewImage(data.topOverviewImage);
this.setModel(new Model(data.map));
this.callListeners("onreload");
};
Project.prototype.getId = function() {
return this._id;
};
Project.prototype.setId = function(id) {
this._id = id;
};
Project.prototype.getProjectId = function() {
return this._projectId;
};
Project.prototype.setProjectId = function(projectId) {
this._projectId = projectId;
};
Project.prototype.getVersion = function() {
return this._version;
};
Project.prototype.setVersion = function(version) {
this._version = version;
};
Project.prototype.getName = function() {
return this._name;
};
Project.prototype.setName = function(name) {
this._name = name;
};
Project.prototype.getModel = function() {
return this._model;
};
Project.prototype.setModel = function(model) {
this._model = model;
};
Project.prototype.getOverviewImages = function() {
return this._overviewImages;
};
Project.prototype.setOverviewImages = function(overviewImages) {
this._overviewImages = overviewImages;
};
Project.prototype.getTopOverviewImage = function() {
return this._topOverviewImage;
};
Project.prototype.setTopOverviewImage = function(topOverviewImage) {
this._topOverviewImage = topOverviewImage;
};
Project.prototype.getDescription = function() {
return this._description;
};
Project.prototype.setDescription = function(description) {
this._description = description;
};
module.exports = Project;
"use strict";
var Project = require('../../../../main/js/map/data/Project');
var ServerConnector = require('../../../../main/js/ServerConnector');
var logger = require('../../logger');
var chai = require('chai');
var assert = chai.assert;
describe('Project', function() {
it("contructor", function() {
return ServerConnector.readFile("testFiles/project.json").then(function(res) {
var project = new Project(res);
assert.ok(project);
assert.equal(project.getVersion(), "0");
assert.equal(project.getId(), 14898);
assert.equal(project.getName(), "UNKNOWN DISEASE MAP");
assert.equal(project.getProjectId(), "sample");
assert.equal(project.getDescription(), "");
var model = project.getModel();
assert.equal(model.getName(), "UNKNOWN DISEASE MAP2");
assert.equal(model.getId(), 15781);
assert.equal(model.getTileSize(), 256);
assert.equal(model.getWidth(), 1305);
assert.equal(model.getHeight(), 473);
assert.equal(model.getMinZoom(), 2);
assert.equal(model.getMaxZoom(), 5);
assert.equal(model.getLayoutsData().length, 3);
assert.equal(model.getCenterLatLng().lat(), 79.18277721779353);
assert.equal(model.getCenterLatLng().lng(), -135.06093781915757);
assert.equal(model.getTopLeftLatLng().lat(), 85.05112877980659);
assert.equal(model.getTopLeftLatLng().lng(), -180.0);
assert.equal(model.getBottomRightLatLng().lat(), 81.26928406550978);
assert.equal(model.getBottomRightLatLng().lng(), -90.0);
});
});
});
{"version":"0","idObject":14898,"name":"UNKNOWN DISEASE MAP","projectId":"sample","description":"","map":{"name":"UNKNOWN DISEASE MAP2","idObject":15781,"tileSize":256,"width":1305,"height":473,"minZoom":2,"maxZoom":5,"layouts":[{"modelId":15781,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_nested0","creator":"","inputDataAvailable":"false","idObject":14081},{"modelId":15781,"name":"Network","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_normal0","creator":"","inputDataAvailable":"false","idObject":14082},{"modelId":15781,"name":"Empty","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_empty0","creator":"","inputDataAvailable":"false","idObject":14083}],"submodels":[],"centerLatLng":{"lat":79.18277721779353,"lng":-135.06093781915757},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":81.26928406550978,"lng":-90.0}},"overviewImageViews":[]}
\ No newline at end of file
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