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

frontend handles backgrounds API call

parent a55dc0c8
minerva (16.0.0~beta.1) stable; urgency=medium
* Backward incompatibility: layout parameter in minerva url is not supported
anymore
* Bug fix: there was issue with updating data overlay in admin panel "Unknown
parameter: defaultOverlay"
* Bug fix: data overlays uploaded in complex map were not processed properly
......
......@@ -249,7 +249,6 @@ GuiConnector.prototype.hideProcessing = function () {
* @param {string} content
*/
GuiConnector.prototype.showErrorDialog = function (title, content) {
console.log(this._configuration);
if (this._configuration !== undefined && this._configuration !== null) {
var option = this._configuration.getOption(ConfigurationType.REQUEST_ACCOUNT_EMAIL);
if (option !== null && option !== undefined) {
......
......@@ -50,6 +50,7 @@ var ObjectWithListeners = require('./ObjectWithListeners');
var Point = require('./map/canvas/Point');
var ZipEntry = require('./gui/admin/ZipEntry');
var Background = require("./map/data/Background");
/**
* This object contains methods that will communicate with server.
......@@ -812,6 +813,12 @@ ServerConnector.getOverlaysUrl = function (queryParams, filterParams) {
});
};
ServerConnector.getBackgroundsUrl = function (queryParams) {
return this.getApiUrl({
url: this.getProjectUrl(queryParams) + "backgrounds/"
});
};
ServerConnector.getCommentsUrl = function (queryParams, filterParams) {
var modelId = this.getIdOrAsterisk(queryParams.modelId);
var url = this.getProjectUrl(queryParams) + "comments/models/" + modelId + "/";
......@@ -1210,6 +1217,12 @@ ServerConnector.getProject = function (projectId) {
});
}).then(function (overlays) {
project.addOrUpdateDataOverlays(overlays);
return self.getBackgrounds({
projectId: projectId,
publicOverlay: true
});
}).then(function (backgrounds) {
project.addOrUpdateBackgrounds(backgrounds);
return self.getLoggedUser();
}).then(function (user) {
return self.getOverlays({
......@@ -1846,6 +1859,33 @@ ServerConnector.getOverlays = function (params) {
});
};
/**
*
* @param {Object} [params]
* @param {string} [params.projectId]
*
* @returns {Promise<Array>}
*/
ServerConnector.getBackgrounds = function (params) {
var self = this;
if (params === undefined) {
params = {};
}
var queryParams = {};
return self.getProjectId(params.projectId).then(function (result) {
queryParams.projectId = result;
return self.sendGetRequest(self.getBackgroundsUrl(queryParams));
}).then(function (content) {
var arr = JSON.parse(content);
var result = [];
for (var i = 0; i < arr.length; i++) {
var background = new Background(arr[i]);
result.push(background);
}
return result;
});
};
/**
*
* @param {number} overlayId
......@@ -2602,7 +2642,6 @@ ServerConnector.updateOverlay = function (overlay, project) {
description: overlay.getDescription(),
creator: overlay.getCreator(),
publicOverlay: overlay.getPublicOverlay(),
defaultOverlay: overlay.isDefaultOverlay(),
googleLicenseConsent: overlay.isGoogleLicenseConsent()
}
};
......
......@@ -475,9 +475,6 @@ EditProjectDialog.prototype._createOverlayTable = function () {
}, {
title: 'Public',
orderable: false
}, {
title: 'Default',
orderable: false
}, {
title: 'Owner',
orderable: false
......@@ -543,13 +540,6 @@ EditProjectDialog.prototype._createOverlayTable = function () {
return self.updateOverlay(overlay);
});
$(overlaysTable).on("change", "[name='defaultOverlay']", function () {
var overlayId = parseInt($(this).attr("data"));
var overlay = self._overlayById[overlayId];
overlay.setDefaultOverlay($(this).prop('checked'));
return self.updateOverlay(overlay);
});
$(overlaysTable).on("change", "[name='creator']", function () {
var overlayId = parseInt($(this).attr("data"));
var overlay = self._overlayById[overlayId];
......@@ -1004,34 +994,18 @@ EditProjectDialog.prototype.overlayToTableRow = function (overlay, users) {
}
var publicOverlayCheckbox = "<input type='checkbox' data='" + id + "' name='publicOverlay' " + checked + disabled + "/>";
checked = '';
if (overlay.isDefaultOverlay()) {
checked = "checked";
}
var defaultOverlayCheckbox;
var downloadSourceButton;
if (overlay.getInputDataAvailable()) {
defaultOverlayCheckbox = "";
overlay.setDefaultOverlay(undefined);
downloadSourceButton = "<button name='downloadSource' data='" + id + "'" + disabled + ">"
var downloadSourceButton = "<button name='downloadSource' data='" + id + "'" + disabled + ">"
+ "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>" + "</button>";
} else {
downloadSourceButton = "N/A";
defaultOverlayCheckbox = "<input type='checkbox' data='" + id + "' name='defaultOverlay' " + checked + disabled + "/>";
}
row[0] = id;
row[1] = "<input data='" + id + "' name='overlayName' value='" + overlay.getName() + "'" + disabled + "/>";
row[2] = "<input data='" + id + "' name='overlayDescription' value='" + overlay.getDescription() + "'" + disabled + "/>";
row[3] = publicOverlayCheckbox;
row[4] = defaultOverlayCheckbox;
row[5] = creatorSelect;
row[6] = downloadSourceButton;
row[4] = creatorSelect;
row[5] = downloadSourceButton;
row[7] = "<button name='removeOverlay' data='" + id + "'" + disabled + "><i class='fa fa-trash-alt'></button>";
row[6] = "<button name='removeOverlay' data='" + id + "'" + disabled + "><i class='fa fa-trash-alt'></button>";
return row;
};
......
......@@ -78,7 +78,7 @@ function OverlayPanel(params) {
});
$(self.getElement()).on("click", "[name='overlayLink']", function () {
var overlayId = $(this).attr("data");
return self.getMap().openDataOverlay(overlayId);
return self.getMap().openBackground(overlayId);
});
self.getMap().addListener("onBackgroundOverlayChange", function (e) {
var overlayId = e.arg.toString();
......@@ -242,59 +242,52 @@ OverlayPanel.prototype.createTableHeader = function (edit) {
OverlayPanel.prototype.createOverlayRow = function (overlay, checked, disabled) {
var result = document.createElement("tr");
if (checked && !overlay.getInputDataAvailable()) {
result.className = "active";
}
var nameTd = Functions.createElement({type: "td", content: overlay.getName(), className: "word_wrap", xss: true});
result.appendChild(nameTd);
var viewTd = document.createElement("td");
if (overlay.getInputDataAvailable()) {
var checkbox = Functions.createElement({
type: "input",
inputType: "checkbox",
name: "overlayToggle",
data: overlay.getId()
});
checkbox.checked = checked;
$(checkbox).prop("disabled", disabled);
if (disabled) {
var warningDiv = Functions.createElement({
type: "div",
content: "<i class='fa fa-exclamation-triangle' style='font-size:18px; padding-right:10px;color:orange'></i>",
xss: false
});
warningDiv.title = "You did not consent to terms of the license of Google Maps Platform. Click the \"Edit\" button to do so.";
viewTd.appendChild(warningDiv)
} else {
viewTd.appendChild(checkbox);
}
} else {
var link = Functions.createElement({
type: "a",
href: "#",
className: "minerva-search-link",
name: "overlayLink",
data: overlay.getId(),
content: "<i class='minerva-search-button'></i>",
var checkbox = Functions.createElement({
type: "input",
inputType: "checkbox",
name: "overlayToggle",
data: overlay.getId()
});
checkbox.checked = checked;
$(checkbox).prop("disabled", disabled);
if (disabled) {
var warningDiv = Functions.createElement({
type: "div",
content: "<i class='fa fa-exclamation-triangle' style='font-size:18px; padding-right:10px;color:orange'></i>",
xss: false
});
viewTd.appendChild(link);
warningDiv.title = "You did not consent to terms of the license of Google Maps Platform. Click the \"Edit\" button to do so.";
viewTd.appendChild(warningDiv)
} else {
viewTd.appendChild(checkbox);
}
// var link = Functions.createElement({
// type: "a",
// href: "#",
// className: "minerva-search-link",
// name: "overlayLink",
// data: overlay.getId(),
// content: "<i class='minerva-search-button'></i>",
// xss: false
// });
// viewTd.appendChild(link);
result.appendChild(viewTd);
var dataTd = document.createElement("td");
if (overlay.getInputDataAvailable()) {
var button = Functions.createElement({
type: "button",
name: "download-overlay",
data: overlay.getId(),
content: "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>",
xss: false
});
dataTd.appendChild(button);
}
var button = Functions.createElement({
type: "button",
name: "download-overlay",
data: overlay.getId(),
content: "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>",
xss: false
});
dataTd.appendChild(button);
result.appendChild(dataTd);
......@@ -314,6 +307,43 @@ OverlayPanel.prototype.createOverlayRow = function (overlay, checked, disabled)
return result;
};
/**
*
* @param {Background} background
* @param {boolean} [checked=false]
* @returns {HTMLElement}
*/
OverlayPanel.prototype.createBackgroundRow = function (background, checked) {
var result = document.createElement("tr");
if (checked) {
result.className = "active";
}
var nameTd = Functions.createElement({type: "td", content: background.getName(), className: "word_wrap", xss: true});
result.appendChild(nameTd);
var viewTd = document.createElement("td");
var link = Functions.createElement({
type: "a",
href: "#",
className: "minerva-search-link",
name: "overlayLink",
data: background.getId(),
content: "<i class='minerva-search-button'></i>",
xss: false
});
viewTd.appendChild(link);
result.appendChild(viewTd);
var dataTd = document.createElement("td");
result.appendChild(dataTd);
result.title = background.getDescription();
return result;
};
/**
*
* @param {DataOverlay} overlay
......@@ -326,24 +356,19 @@ OverlayPanel.prototype.overlayToDataRow = function (overlay, checked, disabled)
result[0] = overlay.getOrder();
result[1] = overlay.getName();
if (overlay.getInputDataAvailable()) {
if (disabled) {
result[2] = "<div title='You did not consent to terms of the license of Google Maps Platform. Click the \"Edit\" button to do so.'>" +
"<i class='fa fa-exclamation-triangle' style='font-size:18px; padding-right:10px;color:orange'></i></div>";
} else {
var checkedString = "";
if (checked) {
checkedString = " checked ";
}
result[2] = "<input type='checkbox' " + checkedString + " data='" + overlay.getId() + "' name='overlayToggle'/>";
}
result[3] = "<button data='" + overlay.getId() + "' name='download-overlay'><span class='ui-icon ui-icon-arrowthickstop-1-s'></span></button>";
if (disabled) {
result[2] = "<div title='You did not consent to terms of the license of Google Maps Platform. Click the \"Edit\" button to do so.'>" +
"<i class='fa fa-exclamation-triangle' style='font-size:18px; padding-right:10px;color:orange'></i></div>";
} else {
result[2] = "<a href='#' class='minerva-search-link' data='" + overlay.getId() + "' name='overlayLink'><i class='minerva-search-button'></i></a>";
result[3] = "";
var checkedString = "";
if (checked) {
checkedString = " checked ";
}
result[2] = "<input type='checkbox' " + checkedString + " data='" + overlay.getId() + "' name='overlayToggle'/>";
}
result[3] = "<button data='" + overlay.getId() + "' name='download-overlay'><span class='ui-icon ui-icon-arrowthickstop-1-s'></span></button>";
if (overlay.getCreator() !== "" && overlay.getCreator() !== undefined) {
result[4] = "<button data='" + overlay.getId() + "' name='editButton'><span class='ui-icon ui-icon-document'></span></button>";
} else {
......@@ -360,6 +385,36 @@ OverlayPanel.prototype.overlayToDataRow = function (overlay, checked, disabled)
return result;
};
/**
*
* @param {Background} background
* @param {boolean} checked
* @returns {Array}
*/
OverlayPanel.prototype.backgroundToDataRow = function (background, checked) {
var result = [];
result[0] = background.getOrder();
result[1] = background.getName();
result[2] = "<a href='#' class='minerva-search-link' data='" + background.getId() + "' name='overlayLink'><i class='minerva-search-button'></i></a>";
result[3] = "";
if (background.getCreator() !== "" && background.getCreator() !== undefined) {
result[4] = "<button data='" + background.getId() + "' name='editButton'><span class='ui-icon ui-icon-document'></span></button>";
} else {
result[4] = "";
}
if (background.getDescription() !== "") {
for (var i = 1; i < result.length; i++) {
result[i] = "<div class=\"minerva-tooltip\">" + result[i] +
"<span class=\"minerva-tooltip-text\">" + background.getDescription() + "</span>" +
"</div>";
}
}
return result;
};
/**
*
* @param {DataOverlay} overlay
......@@ -448,14 +503,12 @@ OverlayPanel.prototype.refresh = function (showDefault) {
var self = this;
var user = null;
var overlayTypes = [];
var selectedOverlay = [];
var selectedBackground = self.getMap().getBackgroundDataOverlay();
var overlaysFromServer = [];
var backgrounds = [];
return self.getServerConnector().getOverlayTypes().then(function (types) {
overlayTypes = types;
return self.getServerConnector().getLoggedUser();
}).then(function (loggedUser) {
return self.getServerConnector().getLoggedUser().then(function (loggedUser) {
user = loggedUser;
return self.getMap().getVisibleDataOverlays();
}).then(function (visibleDataOverlays) {
......@@ -463,6 +516,10 @@ OverlayPanel.prototype.refresh = function (showDefault) {
selectedOverlay[visibleDataOverlays[j].getId()] = true;
}
return self.getServerConnector().getBackgrounds();
}).then(function (result) {
backgrounds = result;
self.getProject().addOrUpdateBackgrounds(backgrounds);
return self.getServerConnector().getOverlays({creator: user.getLogin()});
}).then(function (userOverlays) {
overlaysFromServer = userOverlays;
......@@ -485,15 +542,20 @@ OverlayPanel.prototype.refresh = function (showDefault) {
}
}
if (backgrounds.length === 0) {
return Promise.reject(new ValidationError("Project doesn't have a background defined. Please re-upload map in admin panel."));
}
if (!showDefault) {
if (overlaysFromServer.length === 0) {
return Promise.reject(new ValidationError("Project doesn't have a background defined. Please re-upload map in admin panel."));
}
if (self.getMap().getBackgroundDataOverlay() == null) {
return Promise.reject(new ValidationError("Project doesn't have a background defined. Please re-upload map in admin panel."));
}
var id = self.getMap().getBackgroundDataOverlay().getId();
selectedOverlay[id] = true;
} else {
selectedBackground = backgrounds[0];
backgrounds.forEach(function (background) {
if (background.isDefaultOverlay()) {
selectedBackground = background;
}
});
}
self.clear();
......@@ -503,22 +565,14 @@ OverlayPanel.prototype.refresh = function (showDefault) {
overlays = self.getProject().getDataOverlays();
var customOverlays = [];
var defaultOverlay = null;
for (var i = 0; i < overlays.length; i++) {
overlay = overlays[i];
if (overlay.getPublicOverlay()) {
generalOverlays.push(overlay);
if (showDefault && overlay.isDefaultOverlay()) {
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());
......@@ -540,6 +594,10 @@ OverlayPanel.prototype.refresh = function (showDefault) {
}
return 0;
});
for (i = 0; i < backgrounds.length; i++) {
var background = backgrounds[i];
body.appendChild(self.createBackgroundRow(background, background === selectedBackground));
}
for (i = 0; i < generalOverlays.length; i++) {
overlay = generalOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()], false));
......@@ -577,9 +635,6 @@ OverlayPanel.prototype.refresh = function (showDefault) {
self.setGoogleLicenseConsentRequired(false);
for (i = 0; i < customOverlays.length; i++) {
overlay = customOverlays[i];
if (showDefault && overlay.isDefaultOverlay()) {
selectedOverlay[overlay.getId()] = true;
}
var disabled = !overlay.isGoogleLicenseConsent() && self.getMap().getProject().getMapCanvasType() === "GOOGLE_MAPS_API";
data.push(self.overlayToDataRow(overlay, selectedOverlay[overlay.getId()], disabled));
if (disabled) {
......@@ -599,6 +654,7 @@ OverlayPanel.prototype.refresh = function (showDefault) {
promises.push(self.getMap().openDataOverlay(key));
}
}
self.getMap().openBackground(selectedBackground.getId());
}
return Promise.all(promises);
}).then(function () {
......
......@@ -133,17 +133,15 @@ AbstractCustomMap.prototype.createMapOptions = function () {
}
}
var overlays = this.getProject().getDataOverlays();
var backgrounds = this.getProject().getBackgrounds();
var backgroundOverlays = [];
for (var i = 0; i < overlays.length; i++) {
var overlay = overlays[i];
if (!overlay.getInputDataAvailable()) {
backgroundOverlays.push({
directory: "../map_images/" + self.getProject().getDirectory() + "/" + overlay.getImagesDirectory(self.getId()),
id: overlay.getId(),
name: overlay.getName()
});
}
for (var i = 0; i < backgrounds.length; i++) {
var background = backgrounds[i];
backgroundOverlays.push({
directory: "../map_images/" + self.getProject().getDirectory() + "/" + background.getImagesDirectory(self.getId()),
id: background.getId(),
name: background.getName()
});
}
return {
......
......@@ -95,7 +95,7 @@ CustomMap.prototype.init = function () {
// if we have user data overlays stored in the session then restore it
var ids = sessionData.getVisibleOverlays();
if (mapType !== undefined && !isNaN(mapType)) {
ids.push(mapType);
self.openBackground(mapType);
}
// center map and zoom in to fit into browser window if there is no
......@@ -128,10 +128,10 @@ CustomMap.prototype.init = function () {
return self.openDataOverlay(overlayId).catch(function (e) {
if (e instanceof SecurityError) {
logger.debug(e.message);
if (self.getProject().getDataOverlays().length === 0) {
if (self.getProject().getBackgrounds().length === 0) {
return Promise.reject(new ValidationError("Project doesn't have a background defined. Please re-upload map in admin panel."));
}
sessionData.setSelectedBackgroundOverlay(self.getProject().getDataOverlays()[0].getId());
sessionData.setSelectedBackgroundOverlay(self.getProject().getBackgrounds()[0].getId());
} else {
return Promise.reject(e);
}
......@@ -246,53 +246,37 @@ CustomMap.prototype.openDataOverlay = function (param) {
overlayToOpen = overlay;
}
}
if (overlayToOpen === null) {
return Promise.reject(new SecurityError("You have no privileges for selected overlay"));
} else {
return overlayToOpen.init().then(function () {
if (overlayToOpen.getInputDataAvailable()) {
if (self._selectedOverlays[identifier] === true) {
logger.warn("Overlay " + identifier + " already selected");
return Promise.resolve();
} else {
self._selectedOverlays[identifier] = true;
return self.getVisibleDataOverlays().then(function (visibleDataOverlays) {
var ids = [];
for (var i = 0; i < visibleDataOverlays.length; i++) {
ids.push(visibleDataOverlays[i].getId());
}
self.getServerConnector().getSessionData(self.getProject()).setVisibleOverlays(ids);
return self.redrawSelectedDataOverlays();
}).then(function () {
var backgroundToOpen;
var overlays = self.getProject().getDataOverlays();
for (var i = 0; i < overlays.length; i++) {
var overlay = overlays[i];
if (overlay.getName().toLowerCase() === "empty") {
backgroundToOpen = overlay;
}
}
if (backgroundToOpen === undefined) {
logger.warn("Cannot find empty background overlay");
} else {
return self.openDataOverlay(backgroundToOpen.getId());
}
});
}
if (self._selectedOverlays[identifier] === true) {
logger.warn("Overlay " + identifier + " already selected");
return Promise.resolve();
} else {
if (identifier.toString() === self.getMapCanvas().getBackgroundId()) {
return Promise.resolve();
} else {
self.getMapCanvas().setBackgroundId(identifier.toString());
var submaps = self.getSubmaps();
for (var i = 0; i < submaps.length; i++) {
var submap = submaps[i];
submap.openDataOverlay(identifier);
self._selectedOverlays[identifier] = true;
return self.getVisibleDataOverlays().then(function (visibleDataOverlays) {
var ids = [];