Skip to content
Snippets Groups Projects
Commit bd6f29a0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

frontend uses new api

parent 31163db5
No related branches found
No related tags found
1 merge request!983Resolve "Admin panel: structured log"
...@@ -2843,6 +2843,18 @@ ServerConnector.uploadFile = function (params) { ...@@ -2843,6 +2843,18 @@ ServerConnector.uploadFile = function (params) {
}; };
/**
*
* @param {Object} [params]
* @param {number} [params.start]
* @param {number} [params.length]
* @param {string} [params.sortColumn]
* @param {string} [params.sortOrder]
* @param {string} [params.search]
* @param {string} [params.level]
* @param {string} [params.projectId]
* @return {Promise}
*/
ServerConnector.getProjectLogs = function (params) { ServerConnector.getProjectLogs = function (params) {
var self = this; var self = this;
if (params === undefined) { if (params === undefined) {
......
...@@ -18,7 +18,8 @@ var GuiConnector = require('../../GuiConnector'); ...@@ -18,7 +18,8 @@ var GuiConnector = require('../../GuiConnector');
* @param {CustomMap} [params.customMap] * @param {CustomMap} [params.customMap]
* @param {Configuration} params.configuration * @param {Configuration} params.configuration
* @param {Project} [params.project] * @param {Project} [params.project]
* @param {ServerConnector} [params.serverConnector] * @param {string} params.projectId
* @param {ServerConnector} params.serverConnector
* *
* @constructor * @constructor
* @extends AbstractGuiElement * @extends AbstractGuiElement
...@@ -27,7 +28,11 @@ function LogListDialog(params) { ...@@ -27,7 +28,11 @@ function LogListDialog(params) {
AbstractGuiElement.call(this, params); AbstractGuiElement.call(this, params);
var self = this; var self = this;
self.createLogListDialogGui(); self.createLogListDialogGui();
self._level = params.level;
/**
* @type {string}
* @private
*/
self._projectId = params.projectId; self._projectId = params.projectId;
} }
...@@ -41,9 +46,10 @@ LogListDialog.prototype.createLogListDialogGui = function () { ...@@ -41,9 +46,10 @@ LogListDialog.prototype.createLogListDialogGui = function () {
var self = this; var self = this;
var head = Functions.createElement({ var head = Functions.createElement({
type: "thead", type: "thead",
content: "<tr>" + "<th>ID</th>" + content: "<tr>" +
"<th>Content</th>" + "<th>ID</th>" +
"</tr>" "<th>Content</th>" +
"</tr>"
}); });
var body = Functions.createElement({ var body = Functions.createElement({
type: "tbody" type: "tbody"
...@@ -95,20 +101,24 @@ LogListDialog.prototype.createLogListDialogGui = function () { ...@@ -95,20 +101,24 @@ LogListDialog.prototype.createLogListDialogGui = function () {
/** /**
* *
* @param {Object} data * @param {Object} data
* @param {number} data.start
* @param {number} data.length
* @param {Object} data.search
* @param {Object} data.draw
* @param {Array} data.order
* @param {function} callback * @param {function} callback
* @returns {Promise} * @returns {Promise}
* @private * @private
*/ */
LogListDialog.prototype._dataTableAjaxCall = function (data, callback) { LogListDialog.prototype._dataTableAjaxCall = function (data, callback) {
var self = this; var self = this;
return ServerConnector.getProjectLogs({ return self.getServerConnector().getProjectLogs({
start: data.start, start: data.start,
length: data.length, length: data.length,
sortColumn: self.getColumnsDefinition()[data.order[0].column].name, sortColumn: self.getColumnsDefinition()[data.order[0].column].name,
sortOrder: data.order[0].dir, sortOrder: data.order[0].dir,
search: data.search.value, search: data.search.value,
projectId: self._projectId, projectId: self._projectId
level: self._level
}).then(function (logEntries) { }).then(function (logEntries) {
var out = []; var out = [];
for (var i = 0; i < logEntries.data.length; i++) { for (var i = 0; i < logEntries.data.length; i++) {
...@@ -130,16 +140,13 @@ LogListDialog.prototype._dataTableAjaxCall = function (data, callback) { ...@@ -130,16 +140,13 @@ LogListDialog.prototype._dataTableAjaxCall = function (data, callback) {
/** /**
* *
* @param {Object} data
* @param {function} callback
* @returns {Promise} * @returns {Promise}
*/ */
LogListDialog.prototype.downloadAll = function (data, callback) { LogListDialog.prototype.downloadAll = function () {
var self = this; var self = this;
return ServerConnector.getProjectLogs({ return self.getServerConnector().getProjectLogs({
length: 2147483646, length: 2147483646,
projectId: self._projectId, projectId: self._projectId
level: self._level
}).then(function (logEntries) { }).then(function (logEntries) {
var tmp = []; var tmp = [];
for (var i = 0; i < logEntries.data.length; i++) { for (var i = 0; i < logEntries.data.length; i++) {
...@@ -170,8 +177,8 @@ LogListDialog.prototype.open = function () { ...@@ -170,8 +177,8 @@ LogListDialog.prototype.open = function () {
serverSide: true, serverSide: true,
ordering: true, ordering: true,
searching: true, searching: true,
ajax: function (data, callback, settings) { ajax: function (data, callback) {
resolve(self._dataTableAjaxCall(data, callback, settings)); resolve(self._dataTableAjaxCall(data, callback));
}, },
columns: self.getColumnsDefinition() columns: self.getColumnsDefinition()
}); });
......
...@@ -174,15 +174,11 @@ MapsAdminPanel.prototype._createProjectTableRow = function () { ...@@ -174,15 +174,11 @@ MapsAdminPanel.prototype._createProjectTableRow = function () {
$(projectsTable).on("click", "[name='showEditDialog']", function () { $(projectsTable).on("click", "[name='showEditDialog']", function () {
var button = this; var button = this;
return self.showEditDialog($(button).attr("data")).then(null, GuiConnector.alert); return self.showEditDialog($(button).attr("data")).catch(GuiConnector.alert);
}); });
$(projectsTable).on("click", "[name='showErrors']", function () { $(projectsTable).on("click", "[name='showLogEntries']", function () {
var button = this; var button = this;
return self.showLogs($(button).attr("data"), 'error').then(null, GuiConnector.alert); return self.showLogs($(button).attr("data")).catch(GuiConnector.alert);
});
$(projectsTable).on("click", "[name='showWarnings']", function () {
var button = this;
return self.showLogs($(button).attr("data"), 'warning').then(null, GuiConnector.alert);
}); });
return projectsRow; return projectsRow;
...@@ -237,18 +233,10 @@ MapsAdminPanel.prototype.projectToTableRow = function (project, row, user) { ...@@ -237,18 +233,10 @@ MapsAdminPanel.prototype.projectToTableRow = function (project, row, user) {
user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_CURATOR)); user.hasPrivilege(self.getConfiguration().getPrivilegeType(PrivilegeType.IS_CURATOR));
var icon; var icon;
if (project.hasErrors()) { if (project.hasLogEntries()) {
icon = "<i class='fa fa-exclamation-triangle' style='font-size:18px; font-weight:400; padding-right:10px;color:red'></i>";
if (isAdmin) {
status += "<a name='showErrors' href='#' data='" + project.getProjectId() + "'>" + icon + "</a>";
} else {
status += icon;
}
}
if (project.hasWarnings()) {
icon = "<i class='fa fa-exclamation-triangle' style='font-size:18px; font-weight:400; padding-right:10px;color:black'></i>"; icon = "<i class='fa fa-exclamation-triangle' style='font-size:18px; font-weight:400; padding-right:10px;color:black'></i>";
if (isAdmin) { if (isAdmin) {
status += "<a name='showWarnings' href='#' data='" + project.getProjectId() + "'>" + icon + "</a>"; status += "<a name='showLogEntries' href='#' data='" + project.getProjectId() + "'>" + icon + "</a>";
} else { } else {
status += icon; status += icon;
} }
...@@ -502,15 +490,14 @@ MapsAdminPanel.prototype.getDialog = function (project) { ...@@ -502,15 +490,14 @@ MapsAdminPanel.prototype.getDialog = function (project) {
/** /**
* *
* @param {string} projectId * @param {string} projectId
* @param {string} level
* @returns {Promise<LogListDialog>} * @returns {Promise<LogListDialog>}
*/ */
MapsAdminPanel.prototype.getLogDialog = function (projectId, level) { MapsAdminPanel.prototype.getLogDialog = function (projectId) {
var self = this; var self = this;
if (self._logDialogs === undefined) { if (self._logDialogs === undefined) {
self._logDialogs = []; self._logDialogs = [];
} }
var dialog = self._logDialogs[projectId + "-" + level]; var dialog = self._logDialogs[projectId];
if (dialog === undefined) { if (dialog === undefined) {
dialog = new LogListDialog({ dialog = new LogListDialog({
element: Functions.createElement({ element: Functions.createElement({
...@@ -518,10 +505,10 @@ MapsAdminPanel.prototype.getLogDialog = function (projectId, level) { ...@@ -518,10 +505,10 @@ MapsAdminPanel.prototype.getLogDialog = function (projectId, level) {
}), }),
configuration: self.getConfiguration(), configuration: self.getConfiguration(),
projectId: projectId, projectId: projectId,
customMap: null, serverConnector: self.getServerConnector(),
level: level customMap: null
}); });
self._logDialogs[projectId + "-" + level] = dialog; self._logDialogs[projectId] = dialog;
return dialog.init().then(function () { return dialog.init().then(function () {
return dialog; return dialog;
}); });
...@@ -550,13 +537,12 @@ MapsAdminPanel.prototype.showEditDialog = function (id) { ...@@ -550,13 +537,12 @@ MapsAdminPanel.prototype.showEditDialog = function (id) {
/** /**
* *
* @param {string} id projectId * @param {string} id projectId
* @param {string} level
* @returns {Promise<LogListDialog>} * @returns {Promise<LogListDialog>}
*/ */
MapsAdminPanel.prototype.showLogs = function (id, level) { MapsAdminPanel.prototype.showLogs = function (id) {
var self = this; var self = this;
GuiConnector.showProcessing(); GuiConnector.showProcessing();
return self.getLogDialog(id, level).then(function (dialog) { return self.getLogDialog(id).then(function (dialog) {
return dialog.open(); return dialog.open();
}).finally(function () { }).finally(function () {
GuiConnector.hideProcessing(); GuiConnector.hideProcessing();
......
...@@ -78,8 +78,7 @@ Project.prototype.loadFromData = function (data) { ...@@ -78,8 +78,7 @@ Project.prototype.loadFromData = function (data) {
self.setStatus(data.status); self.setStatus(data.status);
self.setNotifyEmail(data.notifyEmail); self.setNotifyEmail(data.notifyEmail);
self.setProgress(data.progress); self.setProgress(data.progress);
self.setHasWarnings(data.warnings); self.setHasLogEntries(data.logEntries);
self.setHasErrors(data.errors);
self.setMapCanvasType(data.mapCanvasType); self.setMapCanvasType(data.mapCanvasType);
} }
}; };
...@@ -114,8 +113,7 @@ Project.prototype._update = function (data) { ...@@ -114,8 +113,7 @@ Project.prototype._update = function (data) {
self.setStatus(data.getStatus()); self.setStatus(data.getStatus());
self.setProgress(data.getProgress()); self.setProgress(data.getProgress());
self.setNotifyEmail(data.getNotifyEmail()); self.setNotifyEmail(data.getNotifyEmail());
self.setHasWarnings(data.hasWarnings()); self.setHasLogEntries(data.hasLogEntries());
self.setHasErrors(data.hasErrors());
self.setMapCanvasType(data.getMapCanvasType()); self.setMapCanvasType(data.getMapCanvasType());
if (data.getModels() !== undefined) { if (data.getModels() !== undefined) {
...@@ -146,33 +144,18 @@ Project.prototype.setId = function (id) { ...@@ -146,33 +144,18 @@ Project.prototype.setId = function (id) {
* *
* @returns {boolean} * @returns {boolean}
*/ */
Project.prototype.hasErrors = function () { Project.prototype.hasLogEntries = function () {
return this._hasErrors === true; return this._hasLogEntries === true;
}; };
/** /**
* *
* @param {boolean} hasErrors * @param {boolean} hasLogEntries
*/ */
Project.prototype.setHasErrors = function (hasErrors) { Project.prototype.setHasLogEntries = function (hasLogEntries) {
this._hasErrors = hasErrors; this._hasLogEntries = hasLogEntries;
}; };
/**
*
* @returns {boolean}
*/
Project.prototype.hasWarnings = function () {
return this._hasWarnings === true;
};
/**
*
* @param {boolean} hasWarnings
*/
Project.prototype.setHasWarnings = function (hasWarnings) {
this._hasWarnings = hasWarnings;
};
/** /**
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment