Commit 5e77fc72 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

plugin API allows to create remove data overlays

parent 12c993d2
Pipeline #28634 passed with stage
in 11 minutes and 20 seconds
minerva (15.1.0) unstable; urgency=medium
* Small improvement: annotations are exported in SBGN extension that can be
opened by newt (#1296)
* Small improvement: plugin API allows to add/remove data overlays (#1153)
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 18 Jun 2020 16:00:00 +0200
minerva (15.0.0~beta.5) unstable; urgency=medium
* Backward incompatible: truncation/association/dissocation points are
......
......@@ -93,10 +93,22 @@ ServerConnector.init = function () {
self.removeListener("onDataLoadStop", listeners[i]);
}
listeners = self.getListeners("onAddDataOverlay");
for (i = 0; i < listeners.length; i++) {
self.removeListener("onAddDataOverlay", listeners[i]);
}
listeners = self.getListeners("onRemoveDataOverlay");
for (i = 0; i < listeners.length; i++) {
self.removeListener("onRemoveDataOverlay", listeners[i]);
}
self.MAX_NUMBER_OF_IDS_IN_GET_QUERY = 100;
};
ServerConnector.registerListenerType("onDataLoadStart");
ServerConnector.registerListenerType("onDataLoadStop");
ServerConnector.registerListenerType("onAddDataOverlay");
ServerConnector.registerListenerType("onRemoveDataOverlay");
ServerConnector.init();
ServerConnector.getMinOverlayColorInt = function () {
......@@ -2512,11 +2524,15 @@ ServerConnector.addOverlay = function (params) {
type: overlay.getType(),
fileId: params.fileId
};
return self.getProjectId(params.projectId).then(function (result) {
queryParams.projectId = result;
return self.sendPostRequest(self.addOverlayUrl(queryParams), data);
}).then(function (content) {
return new DataOverlay(JSON.parse(content));
overlay = new DataOverlay(JSON.parse(content));
return self.callListeners("onAddDataOverlay", overlay);
}).then(function () {
return overlay;
}).catch(self.processNetworkError);
};
......@@ -2631,6 +2647,8 @@ ServerConnector.removeOverlay = function (params) {
return self.getProjectId(params.projectId).then(function (result) {
queryParams.projectId = result;
return self.sendDeleteRequest(self.deleteOverlayUrl(queryParams), filterParams);
}).then(function () {
return self.callListeners("onRemoveDataOverlay", params.overlayId);
});
};
......
......@@ -36,7 +36,6 @@ var TextEncoder = require('text-encoding').TextEncoder;
function AddOverlayDialog(params) {
AbstractGuiElement.call(this, params);
var self = this;
self.registerListenerType("onAddOverlay");
self.createGui();
}
......@@ -278,10 +277,8 @@ AddOverlayDialog.prototype.addOverlay = function () {
overlay: overlay,
projectId: self.getProject().getProjectId()
});
}).then(function (result) {
overlay = result;
}).finally(function () {
GuiConnector.hideProcessing();
return self.callListeners("onAddOverlay", overlay);
});
};
......
......@@ -679,6 +679,11 @@ EditProjectDialog.prototype.init = function () {
self.getProject().addListener("onreload", function () {
self.projectDataUpdated(self.getProject());
});
self.getServerConnector().addListener("onAddDataOverlay", function () {
return self.refreshOverlays();
});
return self.initUsersTab().then(function () {
return self.getServerConnector().getLoggedUser();
}).then(function (loggedUser) {
......@@ -1267,9 +1272,6 @@ EditProjectDialog.prototype.openAddOverlayDialog = function () {
configuration: self.getConfiguration(),
serverConnector: self.getServerConnector()
});
self._addOverlayDialog.addListener("onAddOverlay", function () {
return self.refreshOverlays();
});
return self._addOverlayDialog.init().then(function () {
return self._addOverlayDialog.open();
}).then(function () {
......
......@@ -659,10 +659,6 @@ OverlayPanel.prototype.openAddOverlayDialog = function () {
element: document.createElement("div"),
configuration: self.getConfiguration()
});
self._addOverlayDialog.addListener("onAddOverlay", function (e) {
self.getProject().addDataOverlay(e.arg);
return self.refresh();
});
return self._addOverlayDialog.init().then(function () {
return self._addOverlayDialog.open();
});
......@@ -724,6 +720,17 @@ OverlayPanel.prototype.init = function () {
return Promise.all(promises);
});
self.getServerConnector().addListener("onAddDataOverlay", function (e) {
self.getProject().addDataOverlay(e.arg);
return self.refresh();
});
self.getServerConnector().addListener("onRemoveDataOverlay", function (e) {
self.getProject().removeDataOverlay(e.arg);
return self.refresh();
});
return this.refresh(showDefault);
};
......@@ -750,9 +757,6 @@ OverlayPanel.prototype.removeOverlay = function (overlay) {
var self = this;
return self.getMap().hideDataOverlay(overlay.getId()).then(function () {
return self.getServerConnector().removeOverlay({overlayId: overlay.getId()});
}).then(function () {
self.getProject().removeDataOverlay(overlay);
return self.refresh();
})
};
......
......@@ -8,6 +8,8 @@ var Annotation = require("./Annotation");
var DataOverlay = require("./DataOverlay");
var Model = require('./MapModel');
var Functions = require('../../Functions');
var Promise = require('bluebird');
// noinspection JSUnusedLocalSymbols
......@@ -441,14 +443,20 @@ Project.prototype.addDataOverlay = function (overlay, updateWhenExists) {
/**
*
* @param {DataOverlay} overlay
* @param {DataOverlay|number} overlay
*/
Project.prototype.removeDataOverlay = function (overlay) {
var object = this._dataOverlays[overlay.getId()];
var id;
if (Functions.isInt(overlay)) {
id = overlay;
} else {
id = overlay.getId();
}
var object = this._dataOverlays[id];
if (object === undefined) {
throw new Error("Overlay " + overlay.getId() + " doesn't exist in a project " + this.getProjectId());
throw new Error("Overlay " + id + " doesn't exist in a project " + this.getProjectId());
} else {
delete this._dataOverlays[overlay.getId()];
delete this._dataOverlays[id];
}
};
......
......@@ -9,6 +9,8 @@ var IdentifiedElement = require('../map/data/IdentifiedElement');
var MiRna = require('../map/data/MiRna');
var UserDbOverlay = require('../map/overlay/UserDbOverlay');
var SearchDbOverlay = require('../map/overlay/SearchDbOverlay');
var LayoutAlias = require('../map/data/LayoutAlias');
var DataOverlay = require('../map/data/DataOverlay');
var Configuration = require('../Configuration');
var Bounds = require('../map/canvas/Bounds');
......@@ -16,6 +18,8 @@ var Point = require('../map/canvas/Point');
var GuiConnector = require('../GuiConnector');
var TextEncoder = require('text-encoding').TextEncoder;
// noinspection JSUnusedLocalSymbols
var logger = require('../logger');
......@@ -206,6 +210,42 @@ function createProjectData(options) {
}
return result;
},
/**
*
* @param {number} overlayId
* @return {PromiseLike|Promise}
*/
removeDataOverlay: function (overlayId) {
return map.getServerConnector().removeOverlay({overlayId: overlayId, projectId: map.getProject().getProjectId()});
},
addDataOverlay: function (param) {
if (param.type === undefined || param.type === null) {
param.type = LayoutAlias.GENERIC;
}
if (param.filename === undefined || param.filename === "") {
param.filename = "unknown.txt";
}
var overlay = new DataOverlay({
name: param.name,
description: param.description,
filename: param.filename,
googleLicenseConsent: param.googleLicenseConsent === true,
type: param.type
});
GuiConnector.showProcessing();
return map.getServerConnector().uploadFile({
filename: param.filename,
content: new TextEncoder().encode(param.content)
}).then(function (file) {
return map.getServerConnector().addOverlay({
fileId: file.id,
overlay: overlay,
projectId: map.getProject().getProjectId()
});
}).finally(GuiConnector.hideProcessing);
},
/**
* Export part of the map that includes bioEntities into a known format.
*
......
......@@ -168,19 +168,6 @@ describe('OverlayPanel', function () {
});
});
it('trigger onAddOverlay event handler', function () {
var map = helper.createCustomMap();
var panel = createOverlayPanel(map);
return panel.init().then(function () {
return panel.openAddOverlayDialog();
}).then(function () {
var overlay = helper.createOverlay(panel.getProject().getModels()[0]);
return panel._addOverlayDialog.callListeners("onAddOverlay", overlay);
}).then(function () {
return panel.destroy();
});
});
});
});
......
......@@ -90,6 +90,39 @@ describe('MinervaPluginProxy', function () {
});
});
it('add data overlay', function () {
var callbackOk = false;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
var proxy = createProxy(map);
return proxy.project.data.addDataOverlay({
name: "test-name",
content: "tmp",
description: "desc",
filename:"unknown.txt",
googleLicenseConsent: true});
}).then(function (overlay) {
return map.destroy();
});
});
it('remove data overlay', function () {
var map, proxy, overlay;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
overlay = getDataOverlayFromProject(project);
return proxy.project.data.removeDataOverlay(overlay.getId());
}).then(function () {
return map.destroy();
});
});
describe('removeListener', function () {
it('valid listener', function () {
var callbackOk = false;
......
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