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

separation of backgrounds and data overlays

parent 3d196903
minerva (16.0.0~beta.1) stable; urgency=medium
* Backward incompatibility: layout parameter in minerva url is not supported
anymore
* Small improvement: info about background and dat aoverlays is separated in
edit project panel (#1515)
* 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
......
......@@ -108,12 +108,18 @@ ServerConnector.init = function () {
self.removeListener("onRemoveDataOverlay", listeners[i]);
}
listeners = self.getListeners("onRemoveBackground");
for (i = 0; i < listeners.length; i++) {
self.removeListener("onRemoveBackground", listeners[i]);
}
self.MAX_NUMBER_OF_IDS_IN_GET_QUERY = 100;
};
ServerConnector.registerListenerType("onDataLoadStart");
ServerConnector.registerListenerType("onDataLoadStop");
ServerConnector.registerListenerType("onAddDataOverlay");
ServerConnector.registerListenerType("onRemoveDataOverlay");
ServerConnector.registerListenerType("onRemoveBackground");
ServerConnector.init();
......@@ -788,6 +794,12 @@ ServerConnector.updateOverlayUrl = function (queryParams) {
});
};
ServerConnector.updateBackgroundUrl = function (queryParams) {
return this.getApiUrl({
url: this.getBackgroundByIdUrl(queryParams)
});
};
ServerConnector.updateModelUrl = function (queryParams) {
return this.getApiUrl({
url: this.getModelsUrl(queryParams)
......@@ -800,6 +812,12 @@ ServerConnector.deleteOverlayUrl = function (queryParams) {
});
};
ServerConnector.deleteBackgroundUrl = function (queryParams) {
return this.getApiUrl({
url: this.getBackgroundByIdUrl(queryParams)
});
};
ServerConnector.deleteCommentUrl = function (queryParams) {
return this.getApiUrl({
url: this.getProjectUrl(queryParams) + "comments/" + queryParams.commentId + "/"
......@@ -844,7 +862,13 @@ ServerConnector.getOverlayByIdUrl = function (queryParams, filterParams) {
url: this.getOverlaysUrl(queryParams) + queryParams.overlayId + "/",
params: filterParams
});
};
ServerConnector.getBackgroundByIdUrl = function (queryParams, filterParams) {
return this.getApiUrl({
url: this.getBackgroundsUrl(queryParams) + queryParams.backgroundId + "/",
params: filterParams
});
};
ServerConnector.getOverlayElementsUrl = function (queryParams, filterParams) {
......@@ -2658,6 +2682,37 @@ ServerConnector.updateOverlay = function (overlay, project) {
};
/**
*
* @param {Background} background
* @param {Project} [project]
* @return {Promise}
*/
ServerConnector.updateBackground = function (background, project) {
var self = this;
var queryParams = {
backgroundId: background.getId()
};
if (project !== undefined) {
queryParams.projectId = project.getProjectId();
}
var filterParams = {
name: background.getName(),
description: background.getDescription(),
defaultOverlay: background.isDefaultOverlay()
};
return self.getProjectId(queryParams.projectId).then(function (projectId) {
queryParams.projectId = projectId;
return self.sendPatchRequest(self.updateBackgroundUrl(queryParams), filterParams);
}).catch(function (e) {
if (e instanceof NetworkError && e.statusCode === HttpStatus.BAD_REQUEST) {
throw new ValidationError(e.content.reason);
} else {
return self.processNetworkError(e);
}
});
};
/**
*
* @param {Object} params
......@@ -2704,6 +2759,27 @@ ServerConnector.removeOverlay = function (params) {
});
};
/**
*
* @param {Object} params
* @param {number} params.backgroundId
* @param {string} params.projectId
* @return {PromiseLike<T> | Promise<T>}
*/
ServerConnector.removeBackground = function (params) {
var self = this;
var queryParams = {
backgroundId: params.backgroundId
};
var filterParams = {};
return self.getProjectId(params.projectId).then(function (result) {
queryParams.projectId = result;
return self.sendDeleteRequest(self.deleteBackgroundUrl(queryParams), filterParams);
}).then(function () {
return self.callListeners("onRemoveBackground", params.backgroundId);
});
};
/**
*
* @param {Object} params
......
......@@ -54,6 +54,13 @@ function EditProjectDialog(params) {
*/
self._overlayById = [];
/**
@name EditProjectDialog#_backgroundById
@type Background[]
@private
*/
self._backgroundById = [];
/**
@name EditProjectDialog#_mapsById
@type MapModel[]
......@@ -86,6 +93,11 @@ EditProjectDialog.prototype.createGui = function () {
content: self.createGeneralTabContent()
});
guiUtils.addTab(self, {
name: "BACKGROUNDS",
content: self.createBackgroundsTabContent()
});
guiUtils.addTab(self, {
name: "OVERLAYS",
content: self.createOverlaysTabContent()
......@@ -440,6 +452,20 @@ EditProjectDialog.prototype.createOverlaysTabContent = function () {
return result;
};
/**
*
* @returns {HTMLElement}
*/
EditProjectDialog.prototype.createBackgroundsTabContent = function () {
var self = this;
var result = Functions.createElement({
type: "div",
className: "minerva-project-backgrounds-tab"
});
result.appendChild(self._createBackgroundsTable());
return result;
};
/**
*
* @returns {HTMLElement}
......@@ -504,11 +530,6 @@ EditProjectDialog.prototype._createOverlayTable = function () {
var overlayId = parseInt($(button).attr("data"));
var overlay = self._overlayById[overlayId];
var confirmationMessage = "Do you want to delete overlay: " + overlay.getName() + "?";
if (!overlay.getInputDataAvailable()) {
confirmationMessage += "<br/><span style='color:red;font-weight:bold'>Warning: This contains one of the map's " +
"diagrams and is required<br/>" +
"for map display. Removing it cannot be undone.</span>"
}
return GuiConnector.showConfirmationDialog({
message: confirmationMessage
}).then(function (confirmation) {
......@@ -584,6 +605,98 @@ EditProjectDialog.prototype._createOverlayTable = function () {
return result;
};
/**
*
* @returns {HTMLElement}
* @private
*/
EditProjectDialog.prototype._createBackgroundsTable = function () {
var self = this;
var result = Functions.createElement({
type: "div",
style: "margin-top:10px;"
});
var backgroundsTable = Functions.createElement({
type: "table",
name: "backgroundsTable",
className: "display",
style: "width:100%"
});
result.appendChild(backgroundsTable);
// noinspection JSUnusedGlobalSymbols
$(backgroundsTable).DataTable({
fnRowCallback: function (nRow, aData) {
nRow.setAttribute('id', "background-" + aData[0]);
},
columns: [{
title: 'Id'
}, {
title: 'Name'
}, {
title: 'Description'
}, {
title: 'Default',
orderable: false
}, {
title: 'Remove',
orderable: false
}],
columnDefs: [
{
orderDataType: "dom-input",
type: "string",
targets: [1, 2]
}
]
});
$(backgroundsTable).on("click", "[name='removeBackground']", function () {
var button = this;
var backgroundId = parseInt($(button).attr("data"));
var background = self._backgroundById[backgroundId];
var confirmationMessage = "Do you want to delete background: " + background.getName() + "?" +
"<br/><span style='color:red;font-weight:bold'>Warning: This contains one of the map's " +
"diagrams and is required<br/>" +
"for map display. Removing it cannot be undone.</span>"
return GuiConnector.showConfirmationDialog({
message: confirmationMessage
}).then(function (confirmation) {
if (confirmation) {
$(button).attr("disabled", true);
return self.removeBackground(backgroundId).catch(GuiConnector.alert);
}
});
});
$(backgroundsTable).on("change", "[name='backgroundName']", function () {
var backgroundId = parseInt($(this).attr("data"));
var background = self._backgroundById[backgroundId];
background.setName($(this).val());
return self.updateBackground(background);
});
$(backgroundsTable).on("change", "[name='backgroundDescription']", function () {
var backgroundId = parseInt($(this).attr("data"));
var background = self._backgroundById[backgroundId];
background.setDescription($(this).val());
return self.updateBackground(background);
});
$(backgroundsTable).on("change", "[name='defaultBackground']", function () {
var backgroundId = parseInt($(this).attr("data"));
var background = self._backgroundById[backgroundId];
background.setDefaultOverlay($(this).prop('checked'));
return self.updateBackground(background);
});
return result;
};
/**
*
* @returns {HTMLElement}
......@@ -728,13 +841,13 @@ EditProjectDialog.prototype.refresh = function () {
self.projectDataUpdated(project);
return self.refreshUsers().then(function () {
return self.refreshMaps();
}).then(function () {
return self.refreshOverlays();
}).then(function () {
return self.refreshComments();
}).then(function () {
return Promise.all([
self.refreshUsers(),
self.refreshMaps(),
self.refreshOverlays(),
self.refreshBackgrounds(),
self.refreshComments()
]).then(function () {
var configuration = self.getConfiguration();
var mapCanvasTypes = configuration.getMapCanvasTypes();
var select = $("[name='project-map-canvas-type']", self.getElement())[0];
......@@ -803,6 +916,28 @@ EditProjectDialog.prototype.refreshOverlays = function () {
});
};
/**
*
* @returns {Promise}
*/
EditProjectDialog.prototype.refreshBackgrounds = function () {
var self = this;
return self.getServerConnector().getLoggedUser().then(function (user) {
var curatorPrivilege = self.getConfiguration().getPrivilegeType(PrivilegeType.IS_CURATOR);
var adminPrivilege = self.getConfiguration().getPrivilegeType(PrivilegeType.IS_ADMIN);
//we need to refresh users as well because of privileges
if (user.hasPrivilege(curatorPrivilege) || user.hasPrivilege(adminPrivilege)) {
return self.getServerConnector().getBackgrounds({
projectId: self.getProject().getProjectId()
}).then(function (backgrounds) {
return self.setBackgrounds(backgrounds);
});
} else {
guiUtils.disableTab($(".minerva-project-backgrounds-tab", self.getElement())[0], "You have no privileges to manage users data");
}
});
};
/**
*
* @returns {Promise}
......@@ -857,6 +992,27 @@ EditProjectDialog.prototype.setOverlays = function (overlays) {
});
};
/**
*
* @param {Background[]} backgrounds
* @returns {Promise}
*/
EditProjectDialog.prototype.setBackgrounds = function (backgrounds) {
var self = this;
self._backgroundById = [];
return ServerConnector.getUsers().then(function (users) {
var dataTable = $($("[name='backgroundsTable']", self.getElement())[0]).DataTable();
var data = [];
for (var i = 0; i < backgrounds.length; i++) {
var background = backgrounds[i];
self._backgroundById[background.getId()] = background;
var rowData = self.backgroundToTableRow(background, users);
data.push(rowData);
}
dataTable.clear().rows.add(data).draw();
});
};
/**
*
* @param {MapModel[]} maps
......@@ -995,7 +1151,7 @@ EditProjectDialog.prototype.overlayToTableRow = function (overlay, users) {
var publicOverlayCheckbox = "<input type='checkbox' data='" + id + "' name='publicOverlay' " + checked + disabled + "/>";
var downloadSourceButton = "<button name='downloadSource' data='" + id + "'" + disabled + ">"
+ "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>" + "</button>";
+ "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>" + "</button>";
row[0] = id;
row[1] = "<input data='" + id + "' name='overlayName' value='" + overlay.getName() + "'" + disabled + "/>";
......@@ -1010,6 +1166,30 @@ EditProjectDialog.prototype.overlayToTableRow = function (overlay, users) {
return row;
};
/**
*
* @param {Background} background
* @returns {Array}
*/
EditProjectDialog.prototype.backgroundToTableRow = function (background) {
var row = [];
var id = background.getId();
var checked = '';
if (background.isDefaultOverlay()) {
checked = "checked";
}
var defaultCheckbox = "<input type='checkbox' data='" + id + "' name='defaultBackground' " + checked + "/>";
row[0] = id;
row[1] = "<input data='" + id + "' name='backgroundName' value='" + background.getName() + "'/>";
row[2] = "<input data='" + id + "' name='backgroundDescription' value='" + background.getDescription() + "'/>";
row[3] = defaultCheckbox;
row[4] = "<button name='removeBackground' data='" + id + "'><i class='fa fa-trash-alt'></button>";
return row;
};
/**
*
* @param value
......@@ -1170,6 +1350,17 @@ EditProjectDialog.prototype.updateOverlay = function (overlay) {
return self.getServerConnector().updateOverlay(overlay, self.getProject()).catch(GuiConnector.alert).finally(GuiConnector.hideProcessing);
};
/**
*
* @param {Background} background
* @returns {Promise}
*/
EditProjectDialog.prototype.updateBackground = function (background) {
var self = this;
GuiConnector.showProcessing();
return self.getServerConnector().updateBackground(background, self.getProject()).catch(GuiConnector.alert).finally(GuiConnector.hideProcessing);
};
/**
*
* @param {MapModel} map
......@@ -1234,6 +1425,21 @@ EditProjectDialog.prototype.removeOverlay = function (overlayId) {
});
};
/**
*
* @param {number} backgroundId
* @returns {Promise}
*/
EditProjectDialog.prototype.removeBackground = function (backgroundId) {
var self = this;
return self.getServerConnector().removeBackground({
backgroundId: backgroundId,
projectId: self.getProject().getProjectId()
}).then(function () {
return self.refreshBackgrounds();
});
};
/**
*
* @returns {Promise<AddOverlayDialog>}
......@@ -1290,6 +1496,7 @@ EditProjectDialog.prototype.destroy = function () {
var div = self.getElement();
var usersTable = $("[name=usersTable]", self.getElement())[0];
var overlaysTable = $("[name=overlaysTable]", self.getElement())[0];
var backgroundsTable = $("[name=backgroundsTable]", self.getElement())[0];
var mapsTable = $("[name=mapsTable]", self.getElement())[0];
if ($.fn.DataTable.isDataTable(usersTable)) {
$(usersTable).DataTable().destroy();
......@@ -1297,6 +1504,9 @@ EditProjectDialog.prototype.destroy = function () {
if ($.fn.DataTable.isDataTable(overlaysTable)) {
$(overlaysTable).DataTable().destroy();
}
if ($.fn.DataTable.isDataTable(backgroundsTable)) {
$(backgroundsTable).DataTable().destroy();
}
if ($.fn.DataTable.isDataTable(mapsTable)) {
$(mapsTable).DataTable().destroy();
}
......
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