Commit e701559a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '975-refreshing-general-overlays-list-in-left-panel-and-in-info-window' into 'master'

Resolve "refreshing general-overlays list in left panel and in info window"

Closes #974 and #975

See merge request minerva/core!963
parents 9d07245f 5691acb9
......@@ -4,6 +4,14 @@ minerva (14.0.3) stable; urgency=medium
* Bug fix: verificatin of version length added when uploading project
implemented (#978)
* Bug fix: CLEAR button disappeard when plugin tab used to much space (#976)
* Bug fix: removing data overlay refreshes list of overlays in info window
(#974)
* Bug fix: general overlays are always on top of data overlays in info window
(#975)
* Bug fix: refresh button in overlay panel synchronise list of general and
user provided data overlays (#975)
* Bug fix: changing order of data overlays is reflected in info window
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 16 Oct 2019 9:00:00 +0200
......
......@@ -468,12 +468,9 @@ OverlayPanel.prototype.refresh = function (showDefault) {
selectedOverlay[visibleDataOverlays[j].getId()] = true;
}
return self.getServerConnector().getOverlays({
publicOverlay: false,
creator: user.getLogin()
});
}).then(function (customOverlays) {
self.getProject().addOrUpdateDataOverlays(customOverlays);
return self.getServerConnector().getOverlays();
}).then(function (overlaysFromServer) {
self.getProject().addOrUpdateDataOverlays(overlaysFromServer);
if (!showDefault) {
var id = self.getMap().getBackgroundDataOverlay().getId();
......@@ -486,15 +483,22 @@ OverlayPanel.prototype.refresh = function (showDefault) {
var overlay;
var overlays = self.getProject().getDataOverlays();
var customOverlays = [];
var defaultOverlay = null;
for (var i = 0; i < overlays.length; i++) {
overlay = overlays[i];
if (overlay.getCreator() === undefined || overlay.getCreator() === "") {
generalOverlays.push(overlay);
if (showDefault && overlay.isDefaultOverlay()) {
selectedOverlay[overlay.getId()] = true;
defaultOverlay = overlay;
}
} else {
customOverlays.push(overlay);
}
}
if (defaultOverlay !== null) {
selectedOverlay[defaultOverlay.getId()] = true;
}
var table = self.getControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE);
table.appendChild(self.createTableHeader());
......@@ -578,6 +582,8 @@ OverlayPanel.prototype.refresh = function (showDefault) {
}
}
return Promise.all(promises);
}).then(function () {
return self.getMap().redrawSelectedDataOverlays();
});
};
......@@ -705,6 +711,7 @@ OverlayPanel.prototype.removeOverlay = function (overlay) {
return self.getMap().hideDataOverlay(overlay.getId()).then(function () {
return self.getServerConnector().removeOverlay({overlayId: overlay.getId()});
}).then(function () {
self.getProject().removeDataOverlay(overlay);
return self.refresh();
})
};
......
......@@ -42,6 +42,7 @@ function CustomMap(options) {
this.registerListenerType("onBioEntityClick");
this.registerListenerType("onShowOverlay");
this.registerListenerType("onHideOverlay");
this.registerListenerType("onRedrawSelectedOverlays");
this.registerListenerType("onBackgroundOverlayChange");
this.registerListenerType("onSubmapOpen");
this.registerListenerType("onSubmapClose");
......@@ -625,6 +626,8 @@ CustomMap.prototype.redrawSelectedDataOverlays = function () {
}
}
return Promise.all(promises);
}).then(function () {
return self.callListeners("onRedrawSelectedOverlays");
});
};
......
......@@ -414,6 +414,9 @@ DataOverlay.prototype.isGoogleLicenseConsent = function () {
* @param {DataOverlay} overlay
*/
DataOverlay.prototype.update = function (overlay) {
this.setPublicOverlay(overlay.getPublicOverlay());
this.setOrder(overlay.getOrder());
this.setCreator(overlay.getCreator());
this.setName(overlay.getName());
this.setDescription(overlay.getDescription());
};
......
......@@ -32,6 +32,10 @@ function Project(data) {
ObjectWithListeners.call(this);
this.registerListenerType("onreload");
/**
* @type {Array<DataOverlay>}
* @private
*/
this._dataOverlays = [];
this._models = [];
this._elementsPointingToSubmap = [];
......@@ -452,6 +456,19 @@ Project.prototype.addDataOverlay = function (overlay, updateWhenExists) {
}
};
/**
*
* @param {DataOverlay} overlay
*/
Project.prototype.removeDataOverlay = function (overlay) {
var object = this._dataOverlays[overlay.getId()];
if (object === undefined) {
throw new Error("Overlay " + overlay.getId() + " doesn't exist in a project " + this.getProjectId());
} else {
delete this._dataOverlays[overlay.getId()];
}
};
/**
*
* @param {DataOverlay} overlay
......
......@@ -53,6 +53,7 @@ function AliasInfoWindow(params) {
params.map.getTopMap().addListener("onShowOverlay", overlayListChanged);
params.map.getTopMap().addListener("onHideOverlay", overlayListChanged);
params.map.getTopMap().addListener("onRedrawSelectedOverlays", overlayListChanged);
var drugDbOverlay = params.map.getTopMap().getOverlayByName("drug");
if (drugDbOverlay !== undefined) {
......@@ -98,6 +99,23 @@ AliasInfoWindow.prototype.init = function () {
});
};
/**
*
* @param {DataOverlay} overlay
* @return {string}
* @package
*/
AliasInfoWindow.prototype._getPrintableOverlayName = function (overlay) {
var name = overlay.getName();
if (name.length > 20) {
name = name.substr(0, 20) + "...";
}
if (!overlay.getPublicOverlay()) {
name = "[" + overlay.getOrder() + "] " + name;
}
return name;
};
/**
* Creates and returns chart representing data related to alias on different
* overlays.
......@@ -114,6 +132,16 @@ AliasInfoWindow.prototype.createChartDiv = function (params) {
var promises = [];
var self = this;
overlays.sort(function (overlayA, overlayB) {
if (overlayA.getPublicOverlay() !== overlayB.getPublicOverlay()) {
if (overlayA.getPublicOverlay()) {
return -1;
}
return 1;
}
return overlayA.getOrder() - overlayB.getOrder();
});
overlays.forEach(function (overlay, i) {
promises.push(overlay.getFullAliasById(self.getAlias().getId()).then(function (data) {
var rowDiv = document.createElement("div");
......@@ -122,11 +150,7 @@ AliasInfoWindow.prototype.createChartDiv = function (params) {
} else {
rowDiv.className = "minerva-chart-row-odd";
}
var name = overlays[i].getName();
if (name.length > 20) {
name = name.substr(0, 20) + "...";
}
name = "[" + overlays[i].getOrder() + "] " + name;
var name = self._getPrintableOverlayName(overlays[i]);
var nameDiv = document.createElement("div");
nameDiv.className = "minerva-chart-name";
nameDiv.innerHTML = name + "&nbsp;";
......
......@@ -39,6 +39,7 @@ describe('OverlayPanel', function () {
describe('refresh', function () {
it('anonymous', function () {
var map = helper.createCustomMap();
map.getProject().addDataOverlay(helper.createBackgroundOverlay());
var panel = new OverlayPanel({
element: testDiv,
......@@ -55,6 +56,7 @@ describe('OverlayPanel', function () {
it('admin', function () {
helper.loginAsAdmin();
var map = helper.createCustomMap();
map.getProject().addDataOverlay(helper.createBackgroundOverlay());
var panel = new OverlayPanel({
element: testDiv,
......@@ -119,9 +121,7 @@ describe('OverlayPanel', function () {
it('download', function () {
var map = helper.createCustomMap();
var overlay = helper.createOverlay();
overlay.setInputDataAvailable(true);
map.getProject().addDataOverlay(overlay);
map.getProject().addDataOverlay(helper.createBackgroundOverlay());
var panel = new OverlayPanel({
element: testDiv,
......
......@@ -434,6 +434,19 @@ Helper.prototype.createOverlay = function (model) {
});
};
/**
*
* @param {MapModel} [model]
* @returns {DataOverlay}
*/
Helper.prototype.createBackgroundOverlay = function (model) {
var result = this.createOverlay(model);
result.setInputDataAvailable(true);
result.setDefaultOverlay(true);
result.setName("empty");
return result;
};
/**
*
* @param {Project} [project]
......
......@@ -362,6 +362,23 @@ describe('AliasInfoWindow', function () {
assert.ok(functions.isDomElement(aliasWindow.createWaitingContentDiv()));
});
it("getPrintableOverlayName", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
alias.setIsComplete(true);
var aliasWindow = new AliasInfoWindow({
alias: alias,
map: map,
marker: helper.createMarker({element: alias, map: map})
});
var overlay = helper.createOverlay();
overlay.setPublicOverlay(true);
overlay.setOrder(137778);
assert.equal(-1, aliasWindow._getPrintableOverlayName(overlay).indexOf(overlay.getOrder() + ""));
});
describe("createChartDiv ", function () {
it("on submap map", function () {
helper.setUrl("http://test/?id=complex_model_with_submaps");
......@@ -427,6 +444,37 @@ describe('AliasInfoWindow', function () {
assert.ok(div);
});
});
it("overlay order", function () {
var map = helper.createCustomMap();
var alias = helper.createAlias(map);
var aliasWindow = new AliasInfoWindow({
alias: alias,
map: map,
marker: helper.createMarker({element: alias, map: map})
});
var overlay1 = helper.createOverlay();
overlay1.setOrder(2);
var overlay2 = helper.createOverlay();
overlay2.setPublicOverlay(true);
overlay2.setOrder(10);
var overlay3 = helper.createOverlay();
overlay3.setPublicOverlay(true);
overlay3.setOrder(9);
var overlay4 = helper.createOverlay();
overlay4.setOrder(1);
var overlays = [overlay1, overlay2, overlay3, overlay4];
return aliasWindow.createChartDiv({overlays: overlays}).then(function (htmlDiv) {
var overlay1Position = htmlDiv.innerHTML.indexOf(overlay1.getName());
var overlay2Position = htmlDiv.innerHTML.indexOf(overlay2.getName());
var overlay3Position = htmlDiv.innerHTML.indexOf(overlay3.getName());
var overlay4Position = htmlDiv.innerHTML.indexOf(overlay4.getName());
assert.ok(overlay3Position < overlay2Position);
assert.ok(overlay2Position < overlay4Position);
assert.ok(overlay4Position < overlay1Position);
});
});
});
it("createVcfString ", function () {
......
[{"defaultOverlay":false,"deprecatedColumns":[],"description":null,"googleLicenseConsent":false,"idObject":17987,"images":[{"modelId":19397,"path":"_nested0"},{"modelId":19399,"path":"_nested3"},{"modelId":19398,"path":"_nested1"},{"modelId":19400,"path":"_nested2"}],"inputDataAvailable":false,"name":"Pathways and compartments","order":1,"publicOverlay":true},{"defaultOverlay":false,"deprecatedColumns":[],"description":null,"googleLicenseConsent":false,"idObject":17988,"images":[{"modelId":19397,"path":"_normal0"},{"modelId":19399,"path":"_normal3"},{"modelId":19398,"path":"_normal1"},{"modelId":19400,"path":"_normal2"}],"inputDataAvailable":false,"name":"Network","order":1,"publicOverlay":true},{"defaultOverlay":false,"deprecatedColumns":[],"description":null,"googleLicenseConsent":false,"idObject":17989,"images":[{"modelId":19397,"path":"_empty0"},{"modelId":19399,"path":"_empty3"},{"modelId":19398,"path":"_empty1"},{"modelId":19400,"path":"_empty2"}],"inputDataAvailable":false,"name":"Empty","order":1,"publicOverlay":true}]
\ No newline at end of file
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