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

refresh data overlay should hide data overlays that were removed

parent 25d60a2f
Pipeline #21305 passed with stage
in 13 minutes and 24 seconds
minerva (14.0.9) stable; urgency=medium
* Bug fix: simultanous export to SBML of more than one file could result in
500 Internal Server Error (#1110)
* Bug fix: refresh data overlay did not hide data overlays that were removed
and selected (#1097)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 3 Feb 2020 15:00:00 +0200
......
......@@ -1882,7 +1882,7 @@ ServerConnector.getOverlayById = function (overlayId, projectId) {
return self.sendGetRequest(self.getOverlayByIdUrl(queryParams, filterParams));
}).then(function (content) {
return new DataOverlay(JSON.parse(content));
});
}).catch(self.processNetworkError);
};
/**
......
......@@ -608,6 +608,17 @@ OverlayPanel.prototype.refresh = function (showDefault) {
}
}
return Promise.all(promises);
}).then(function () {
return self.getMap().getVisibleDataOverlays();
}).then(function (visibleDataOverlays) {
var promises = [];
for (var i = 0; i < visibleDataOverlays.length; i++) {
var overlay = visibleDataOverlays[i];
if (self.getProject().getDataOverlayById(overlay.getId()) === undefined) {
promises.push(self.getMap().hideDataOverlay(overlay.getId()));
}
}
return Promise.all(promises);
}).then(function () {
return self.getMap().redrawSelectedDataOverlays();
});
......
......@@ -1317,15 +1317,33 @@ CustomMap.prototype.destroy = function () {
* @returns {Promise<DataOverlay[]>}
*/
CustomMap.prototype.getVisibleDataOverlays = function () {
var self = this;
var dataOverlayPromises = [];
for (var key in this._selectedOverlays) {
if (this._selectedOverlays.hasOwnProperty(key) && this._selectedOverlays[key] === true) {
dataOverlayPromises.push(this.getProject().getDataOverlayById(parseInt(key)));
for (var key in self._selectedOverlays) {
if (self._selectedOverlays.hasOwnProperty(key) && self._selectedOverlays[key] === true) {
dataOverlayPromises.push(function () {
var id = parseInt(key);
return self.getProject().getDataOverlayById(id).then(function (overlay) {
if (overlay === null) {
self._selectedOverlays[id] = false;
return self.hideSelectedLayout(id).then(function () {
return overlay;
})
} else {
return overlay;
}
});
}());
}
}
return Promise.all(dataOverlayPromises).then(function (overlays) {
overlays = overlays.filter(function (overlay) {
return overlay != null;
});
overlays.sort(function (dataOverlay1, dataOverlay2) {
if (dataOverlay1.getOrder() < dataOverlay2.getOrder())
return -1;
......
......@@ -536,8 +536,12 @@ Project.prototype.getDataOverlayById = function (overlayId) {
return Promise.resolve(self._dataOverlays[overlayId]);
} else {
return ServerConnector.getOverlayById(overlayId).then(function (overlay) {
self.addDataOverlay(overlay, false);
return self._dataOverlays[overlayId];
if (overlay !== null) {
self.addDataOverlay(overlay, false);
return self._dataOverlays[overlayId];
} else {
return null;
}
});
}
};
......
......@@ -548,7 +548,7 @@ describe('CustomMap', function () {
return map.openInfoWindowForIdentifiedElement(ie, marker).then(function () {
infoWindow = map.getInfoWindowForIdentifiedElement(ie);
assert.ok(infoWindow);
}).finally(function(){
}).finally(function () {
return map.destroy();
});
......@@ -975,7 +975,7 @@ describe('CustomMap', function () {
var map = new CustomMap(options);
return map.init().then(function () {
assert.fail();
}).catch(function(e){
}).catch(function (e) {
assert.ok(e instanceof ValidationError);
});
});
......@@ -999,6 +999,26 @@ describe('CustomMap', function () {
});
it("get visible data overlays with removed overlay", function () {
var project = helper.createProject();
var overlay1 = helper.createOverlay();
overlay1.setInputDataAvailable(true);
project.addDataOverlay(overlay1);
var options = helper.createCustomMapOptions(project);
ServerConnector.getSessionData(options.getProject()).setVisibleOverlays([overlay1.getId()]);
var map = new CustomMap(options);
return map.init().then(function () {
map._selectedOverlays[-1] = true;
map.selectedLayoutOverlays[-1] = [];
return map.getVisibleDataOverlays();
}).then(function (overlays) {
assert.equal(1, overlays.length);
assert.notOk(map._selectedOverlays[-1]);
map.destroy();
})
});
it("center button", function () {
var options = helper.createCustomMapOptions();
var map = new CustomMap(options);
......
......@@ -48,11 +48,8 @@ describe('Project', function () {
var project = helper.createProject();
var overlay = helper.createOverlay();
return project.getDataOverlayById(overlay.getId()).then(function () {
assert.ok(false, 'expected rejection');
}, function (exception) {
assert.ok(exception);
return project.getDataOverlayById(overlay.getId()).then(function (result) {
assert.equal(null, result);
project.addDataOverlay(overlay);
return project.getDataOverlayById(overlay.getId()).then(function (overlayResult) {
......
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