diff --git a/frontend-js/src/main/js/Admin.js b/frontend-js/src/main/js/Admin.js index fa0b4cf6f0c0dea337a05931a6693b1832f6ade4..d9d4055e6f15f14499d747b2608a9c9b3a6fe8e8 100644 --- a/frontend-js/src/main/js/Admin.js +++ b/frontend-js/src/main/js/Admin.js @@ -20,157 +20,167 @@ var Functions = require('./Functions'); /** * Default constructor. - * + * * @param options * CustomMapOptions object representing all parameters needed for map * creation */ function Admin(options) { - var self = this; - self._panels = []; - self._tabIdCount = 0; - if (!(options instanceof CustomMapOptions)) { - options = new CustomMapOptions(options); - } - self.setProject(options.getProject()); - self.setElement(options.getElement()); - - self.setConfiguration(options.getConfiguration()); - self.setGuiUtils(new GuiUtils()); - self._createGui(); + var self = this; + self._panels = []; + self._tabIdCount = 0; + if (!(options instanceof CustomMapOptions)) { + options = new CustomMapOptions(options); + } + self.setProject(options.getProject()); + self.setElement(options.getElement()); + + self.setConfiguration(options.getConfiguration()); + self.setGuiUtils(new GuiUtils()); + self._createGui(); } Admin.prototype = Object.create(ObjectWithListeners.prototype); Admin.prototype.constructor = ObjectWithListeners; -Admin.prototype._createGui = function() { - var self = this; - self.getElement().innerHTML = ""; - var headerDiv = Functions.createElement({ - type : "div" - }); - self.setHeader(new Header({ - element : headerDiv, - customMap : null, - project : self.getProject(), - adminLink : false, - })); - self.getElement().appendChild(headerDiv); - - var panels = [ { - name : "COMMENTS", - panelClass : CommentsAdminPanel, - }, { - name : "PROJECTS", - panelClass : MapsAdminPanel, - }, { - name : "USERS", - panelClass : UsersAdminPanel, - }, { - name : "SERVICES", - panelClass : ServicesAdminPanel, - }, { - name : "CONFIGURATION", - panelClass : ConfigurationAdminPanel, - } ]; - - var tabDiv = Functions.createElement({ - type : "div", - name : "tabView", - className : "tabbable boxed parentTabs" - }); - self.getElement().appendChild(tabDiv); - - var tabMenuDiv = Functions.createElement({ - type : "ul", - className : "nav nav-tabs" - }); - tabDiv.appendChild(tabMenuDiv); - - var tabContentDiv = Functions.createElement({ - type : "div", - className : "tab-content" - }); - tabDiv.appendChild(tabContentDiv); - - for (var i = 0; i < panels.length; i++) { - self.addTab(panels[i], tabMenuDiv, tabContentDiv); - } +Admin.prototype._createGui = function () { + var self = this; + self.getElement().innerHTML = ""; + var headerDiv = Functions.createElement({ + type: "div" + }); + self.setHeader(new Header({ + element: headerDiv, + customMap: null, + project: self.getProject(), + adminLink: false, + })); + self.getElement().appendChild(headerDiv); + + var panels = [{ + name: "COMMENTS", + panelClass: CommentsAdminPanel, + }, { + name: "PROJECTS", + panelClass: MapsAdminPanel, + }, { + name: "USERS", + panelClass: UsersAdminPanel, + }, { + name: "SERVICES", + panelClass: ServicesAdminPanel, + }, { + name: "CONFIGURATION", + panelClass: ConfigurationAdminPanel, + }]; + + var tabDiv = Functions.createElement({ + type: "div", + name: "tabView", + className: "tabbable boxed parentTabs" + }); + self.getElement().appendChild(tabDiv); + + var tabMenuDiv = Functions.createElement({ + type: "ul", + className: "nav nav-tabs" + }); + tabDiv.appendChild(tabMenuDiv); + + var tabContentDiv = Functions.createElement({ + type: "div", + className: "tab-content" + }); + tabDiv.appendChild(tabContentDiv); + + for (var i = 0; i < panels.length; i++) { + self.addTab(panels[i], tabMenuDiv, tabContentDiv); + } }; -Admin.prototype.addTab = function(params, navElement, contentElement) { - var self = this; +Admin.prototype.addTab = function (params, navElement, contentElement) { + var self = this; - var tabId = "admin_panel_tab_" + this._tabIdCount; - self._tabIdCount++; + var tabId = "admin_panel_tab_" + this._tabIdCount; + self._tabIdCount++; - var navLi = self.getGuiUtils().createTabMenuObject({ - id : tabId, - name : params.name, - navigationBar : navElement - }); - navElement.appendChild(navLi); + var navLi = self.getGuiUtils().createTabMenuObject({ + id: tabId, + name: params.name, + navigationBar: navElement + }); + navElement.appendChild(navLi); - var contentDiv = self.getGuiUtils().createTabContentObject({ - id : tabId, - navigationObject :navLi, - }); + var contentDiv = self.getGuiUtils().createTabContentObject({ + id: tabId, + navigationObject: navLi, + }); - contentElement.appendChild(contentDiv); + contentElement.appendChild(contentDiv); - this._panels.push(new params.panelClass({ - element : contentDiv, - name : params.name, - project : self.getProject(), - configuration : self.getConfiguration(), - })); + this._panels.push(new params.panelClass({ + element: contentDiv, + name: params.name, + project: self.getProject(), + configuration: self.getConfiguration(), + })); }; -Admin.prototype.setProject = function(project) { - this._project = project; +Admin.prototype.setProject = function (project) { + this._project = project; }; -Admin.prototype.getProject = function() { - return this._project; +Admin.prototype.getProject = function () { + return this._project; }; -Admin.prototype.setElement = function(element) { - this._element = element; +Admin.prototype.setElement = function (element) { + this._element = element; }; -Admin.prototype.getElement = function() { - return this._element; +Admin.prototype.getElement = function () { + return this._element; }; -Admin.prototype.init = function() { - var promises = []; - for (var i = 0; i < this._panels.length; i++) { - promises.push(this._panels[i].init()); - } - promises.push(this.getHeader().init()); - return Promise.all(promises); +Admin.prototype.init = function () { + var promises = []; + for (var i = 0; i < this._panels.length; i++) { + promises.push(this._panels[i].init()); + } + promises.push(this.getHeader().init()); + return Promise.all(promises); }; -Admin.prototype.setConfiguration = function(configuration) { - this._configuration = configuration; +Admin.prototype.setConfiguration = function (configuration) { + this._configuration = configuration; }; -Admin.prototype.getConfiguration = function() { - return this._configuration; +Admin.prototype.getConfiguration = function () { + return this._configuration; }; -Admin.prototype.setHeader = function(header) { - this._header = header; +Admin.prototype.setHeader = function (header) { + this._header = header; }; -Admin.prototype.getHeader = function() { - return this._header; +Admin.prototype.getHeader = function () { + return this._header; }; -Admin.prototype.setGuiUtils = function(guiUtils) { - this._guiUtils = guiUtils; +Admin.prototype.setGuiUtils = function (guiUtils) { + this._guiUtils = guiUtils; }; -Admin.prototype.getGuiUtils = function() { - return this._guiUtils; +Admin.prototype.getGuiUtils = function () { + return this._guiUtils; +}; + +Admin.prototype.destroy = function () { + var self = this; + var promises = []; + promises.push(self.getHeader().destroy()); + for (var i = 0; i < self._panels.length; i++) { + promises.push(self._panels[i].destroy()); + } + return Promise.all(promises); }; module.exports = Admin; diff --git a/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js b/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js index abba9a8baeacbb00cf11d6f456b97b83b7d4b757..341e37072c1ec03619a8f953de1ecd9dd483a1da 100644 --- a/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/CommentsAdminPanel.js @@ -201,4 +201,12 @@ CommentsAdminPanel.prototype.commentToTableRow = function(comment) { return row; }; +CommentsAdminPanel.prototype.destroy = function () { + var self = this; + var table = $("[name='commentsTable']", self.getElement())[0]; + if ($.fn.DataTable.isDataTable(table)) { + $(table).DataTable().destroy(); + } +}; + module.exports = CommentsAdminPanel; diff --git a/frontend-js/src/main/js/gui/admin/EditProjectDialog.js b/frontend-js/src/main/js/gui/admin/EditProjectDialog.js index 461428927b93bec9f360e3774ffd1ad25ed5a4ec..b7293b8c72e741e49cd07f51b0e18e0a8d0f7885 100644 --- a/frontend-js/src/main/js/gui/admin/EditProjectDialog.js +++ b/frontend-js/src/main/js/gui/admin/EditProjectDialog.js @@ -559,6 +559,15 @@ EditProjectDialog.prototype.overlayToTableRow = function (overlay, users) { EditProjectDialog.prototype.destroy = function () { var self = this; var div = self.getElement(); + var usersTable = $("[name=usersTable]", self.getElement())[0]; + var overlaysTable = $("[name=overlaysTable]", self.getElement())[0]; + if ($.fn.DataTable.isDataTable(usersTable)) { + $(usersTable).DataTable().destroy(); + } + if ($.fn.DataTable.isDataTable(overlaysTable)) { + $(overlaysTable).DataTable().destroy(); + } + if ($(div).hasClass("ui-dialog-content")) { $(div).dialog("destroy"); } diff --git a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js index 29efb960b44a8009d466bfb5165bf0578474426d..b4bbd2a0617a8cc75c942c34ee25392b407cb4c3 100644 --- a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js @@ -223,6 +223,11 @@ MapsAdminPanel.prototype.destroy = function () { if (dialog !== undefined) { dialog.destroy(); } + var table = $("[name='projectsTable']", self.getElement())[0]; + if ($.fn.DataTable.isDataTable(table)) { + $(table).DataTable().destroy(); + } + }; MapsAdminPanel.prototype.onRefreshClicked = function () { diff --git a/frontend-js/src/main/js/gui/export/ElementExportPanel.js b/frontend-js/src/main/js/gui/export/ElementExportPanel.js index 59868a6b1ba66ad71ef3c8ae2247ff815f027c4b..fc9f884e7ece08df626cf736b94378cc9b1b8cb3 100644 --- a/frontend-js/src/main/js/gui/export/ElementExportPanel.js +++ b/frontend-js/src/main/js/gui/export/ElementExportPanel.js @@ -10,209 +10,209 @@ var logger = require('../../logger'); var Promise = require("bluebird"); function ElementExportPanel(params) { - params.panelName = "elementExport"; - AbstractExportPanel.call(this, params); + params.panelName = "elementExport"; + AbstractExportPanel.call(this, params); } ElementExportPanel.prototype = Object.create(AbstractExportPanel.prototype); ElementExportPanel.prototype.constructor = ElementExportPanel; -ElementExportPanel.prototype.init = function() { - var self = this; - var element = self.getElement(); - var configuration; - return ServerConnector.getConfiguration().then(function(result) { - configuration = result; - var typeDiv = self._createSelectTypeDiv(configuration.getElementTypes()); - element.appendChild(typeDiv); - element.appendChild(self._createSelectColumnDiv(self.getAllColumns())); - return ServerConnector.getProjectStatistics(self.getProject().getProjectId()); - }).then(function(statistics) { - return self._createMiriamTypeDiv(statistics.getElementAnnotations()); - }).then(function(div) { - element.appendChild(div); - return self._createSelectIncludedCompartmentDiv(); - }).then(function(div) { - element.appendChild(div); - return self._createSelectExcludedCompartmentDiv(); - }).then(function(div) { - element.appendChild(div); - element.appendChild(self._createDownloadButton()); - }).then(function() { - $(window).trigger('resize'); - }); -}; - -ElementExportPanel.prototype.createResponseString = function() { - var self = this; - var types, miriamTypes; - var includedCompartmentIds = []; - var excludedCompartmentIds = []; - var models = [ self.getProject().getModel() ]; - for (var i = 0; i < self.getProject().getModel().getSubmodels().length; i++) { - models.push(self.getProject().getModel().getSubmodels()[i]); - } - - var elements = []; - return self.getSelectedTypes().then(function(result) { - if (result.length === 0) { - return Promise.reject(new GuiMessageError("You must select at least one type")); - } - types = result; - return self.getSelectedIncludedCompartments(); - }).then(function(result) { - result.forEach(function(compartment) { - includedCompartmentIds.push(compartment.getId()); +ElementExportPanel.prototype.init = function () { + var self = this; + var element = self.getElement(); + var configuration; + return ServerConnector.getConfiguration().then(function (result) { + configuration = result; + var typeDiv = self._createSelectTypeDiv(configuration.getElementTypes()); + element.appendChild(typeDiv); + element.appendChild(self._createSelectColumnDiv(self.getAllColumns())); + return ServerConnector.getProjectStatistics(self.getProject().getProjectId()); + }).then(function (statistics) { + return self._createMiriamTypeDiv(statistics.getElementAnnotations()); + }).then(function (div) { + element.appendChild(div); + return self._createSelectIncludedCompartmentDiv(); + }).then(function (div) { + element.appendChild(div); + return self._createSelectExcludedCompartmentDiv(); + }).then(function (div) { + element.appendChild(div); + element.appendChild(self._createDownloadButton()); + }).then(function () { + $(window).trigger('resize'); }); - return self.getSelectedExcludedCompartments(); - }).then(function(result) { - result.forEach(function(compartment) { - excludedCompartmentIds.push(compartment.getId()); - }); - - var promises = []; - for (var i = 0; i < models.length; i++) { - promises.push(models[i].getAliases({ - type : types, - complete : true, - includedCompartmentIds : includedCompartmentIds, - excludedCompartmentIds : excludedCompartmentIds, - })); - } - return Promise.all(promises); - }).then(function(aliasesByModel) { - for (var i = 0; i < aliasesByModel.length; i++) { - for (var j = 0; j < aliasesByModel[i].length; j++) { - elements.push(aliasesByModel[i][j]); - } - } +}; - return self.getSelectedMiriamTypes(); - }).then(function(result) { - miriamTypes = result; - return self.getSelectedColumns(); - }).then(function(selectedColumns) { - if (selectedColumns.length === 0) { - return Promise.reject(new GuiMessageError("You must select at least one column")); +ElementExportPanel.prototype.createResponseString = function () { + var self = this; + var types, miriamTypes; + var includedCompartmentIds = []; + var excludedCompartmentIds = []; + var models = [self.getProject().getModel()]; + for (var i = 0; i < self.getProject().getModel().getSubmodels().length; i++) { + models.push(self.getProject().getModel().getSubmodels()[i]); } - var rows = []; - rows.push(self.createResponseHeader(selectedColumns, miriamTypes)); - for (var i = 0; i < elements.length; i++) { - rows.push(self.createResponseRow(elements[i], selectedColumns, miriamTypes)); - } - return rows.join("\n"); - }); + var elements = []; + return self.getSelectedTypes().then(function (result) { + if (result.length === 0) { + return Promise.reject(new GuiMessageError("You must select at least one type")); + } + types = result; + return self.getSelectedIncludedCompartments(); + }).then(function (result) { + result.forEach(function (compartment) { + includedCompartmentIds.push(compartment.getId()); + }); + return self.getSelectedExcludedCompartments(); + }).then(function (result) { + result.forEach(function (compartment) { + excludedCompartmentIds.push(compartment.getId()); + }); + + var promises = []; + for (var i = 0; i < models.length; i++) { + promises.push(models[i].getAliases({ + type: types, + complete: true, + includedCompartmentIds: includedCompartmentIds, + excludedCompartmentIds: excludedCompartmentIds, + })); + } + return Promise.all(promises); + }).then(function (aliasesByModel) { + for (var i = 0; i < aliasesByModel.length; i++) { + for (var j = 0; j < aliasesByModel[i].length; j++) { + elements.push(aliasesByModel[i][j]); + } + } + + return self.getSelectedMiriamTypes(); + }).then(function (result) { + miriamTypes = result; + return self.getSelectedColumns(); + }).then(function (selectedColumns) { + if (selectedColumns.length === 0) { + return Promise.reject(new GuiMessageError("You must select at least one column")); + } + + var rows = []; + rows.push(self.createResponseHeader(selectedColumns, miriamTypes)); + for (var i = 0; i < elements.length; i++) { + rows.push(self.createResponseRow(elements[i], selectedColumns, miriamTypes)); + } + return rows.join("\n"); + }); }; -ElementExportPanel.prototype.createResponseRow = function(alias, columns, miriamTypes) { - var stringBuilder = []; - var i, value; - for (i = 0; i < columns.length; i++) { - var column = columns[i]; - value = alias[column.method](); - if (column.formatFunction !== undefined) { - value = column.formatFunction(value); - } - if (value instanceof String || typeof value === "string") { - value = value.replace(/[\n\r]/g, ' '); +ElementExportPanel.prototype.createResponseRow = function (alias, columns, miriamTypes) { + var stringBuilder = []; + var i, value; + for (i = 0; i < columns.length; i++) { + var column = columns[i]; + value = alias[column.method](); + if (column.formatFunction !== undefined) { + value = column.formatFunction(value); + } + if (value instanceof String || typeof value === "string") { + value = value.replace(/[\n\r]/g, ' '); + } + stringBuilder.push(value); } - stringBuilder.push(value); - } - for (i = 0; i < miriamTypes.length; i++) { - value = ""; - var miriamType = miriamTypes[i]; - var references = alias.getReferences(); - for (var j = 0; j < references.length; j++) { - var reference = references[j]; - if (reference.getType() === miriamType.getName()) { - value += reference.getResource() + ","; - } + for (i = 0; i < miriamTypes.length; i++) { + value = ""; + var miriamType = miriamTypes[i]; + var references = alias.getReferences(); + for (var j = 0; j < references.length; j++) { + var reference = references[j]; + if (reference.getType() === miriamType.getName()) { + value += reference.getResource() + ","; + } + } + stringBuilder.push(value); } - stringBuilder.push(value); - } - var result = stringBuilder.join("\t"); - return result; + var result = stringBuilder.join("\t"); + return result; }; -ElementExportPanel.prototype.getAllColumns = function() { - return [ { - "columnName" : "id", - "method" : "getId", - "name" : "Id", - }, { - "columnName" : "name", - "method" : "getName", - "name" : "Name", - }, { - "columnName" : "description", - "method" : "getDescription", - "name" : "Description", - }, { - "columnName" : "modelId", - "method" : "getModelId", - "name" : "Model", - }, { - "columnName" : "type", - "method" : "getType", - "name" : "Type", - }, { - "columnName" : "complexId", - "method" : "getComplexId", - "name" : "Complex", - }, { - "columnName" : "compartmentId", - "method" : "getCompartmentId", - "name" : "Compartment", - }, { - "columnName" : "charge", - "method" : "getCharge", - "name" : "Charge", - }, { - "columnName" : "symbol", - "method" : "getSymbol", - "name" : "Symbol", - }, { - "columnName" : "fullName", - "method" : "getFullName", - "name" : "Full name", - }, { - "columnName" : "abbreviation", - "method" : "getAbbreviation", - "name" : "Abbreviation", - }, { - "columnName" : "formula", - "method" : "getFormula", - "name" : "Formula", - }, { - "columnName" : "synonyms", - "method" : "getSynonyms", - "name" : "Synonyms", - }, { - "columnName" : "formerSymbols", - "method" : "getFormerSymbols", - "name" : "Former symbols", - }, { - "columnName" : "references", - "method" : "getReferences", - "name" : "References", - "formatFunction" : function(references) { - var stringBuilder = []; - for (var i = 0; i < references.length; i++) { - var reference = references[i]; - stringBuilder.push(reference.getType() + ":" + reference.getResource()); - } - return stringBuilder.join(","); - }, - }, { - "columnName" : "linkedSubmodelId", - "method" : "getLinkedSubmodelId", - "name" : "Linked submodel", - }, { - "columnName" : "elementId", - "method" : "getElementId", - "name" : "Element external id", - }, ]; +ElementExportPanel.prototype.getAllColumns = function () { + return [{ + "columnName": "id", + "method": "getId", + "name": "Id", + }, { + "columnName": "name", + "method": "getName", + "name": "Name", + }, { + "columnName": "description", + "method": "getDescription", + "name": "Description", + }, { + "columnName": "modelId", + "method": "getModelId", + "name": "Model", + }, { + "columnName": "type", + "method": "getType", + "name": "Type", + }, { + "columnName": "complexId", + "method": "getComplexId", + "name": "Complex", + }, { + "columnName": "compartmentId", + "method": "getCompartmentId", + "name": "Compartment", + }, { + "columnName": "charge", + "method": "getCharge", + "name": "Charge", + }, { + "columnName": "symbol", + "method": "getSymbol", + "name": "Symbol", + }, { + "columnName": "fullName", + "method": "getFullName", + "name": "Full name", + }, { + "columnName": "abbreviation", + "method": "getAbbreviation", + "name": "Abbreviation", + }, { + "columnName": "formula", + "method": "getFormula", + "name": "Formula", + }, { + "columnName": "synonyms", + "method": "getSynonyms", + "name": "Synonyms", + }, { + "columnName": "formerSymbols", + "method": "getFormerSymbols", + "name": "Former symbols", + }, { + "columnName": "references", + "method": "getReferences", + "name": "References", + "formatFunction": function (references) { + var stringBuilder = []; + for (var i = 0; i < references.length; i++) { + var reference = references[i]; + stringBuilder.push(reference.getType() + ":" + reference.getResource()); + } + return stringBuilder.join(","); + }, + }, { + "columnName": "linkedSubmodelId", + "method": "getLinkedSubmodelId", + "name": "Linked submodel", + }, { + "columnName": "elementId", + "method": "getElementId", + "name": "Element external id", + },]; }; diff --git a/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js b/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js index eb5ec1203e3a5530fead452e39fc54fbc0b0b6a7..afd0d2494d6b20bff072b72835c9b6739e995c57 100644 --- a/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js +++ b/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js @@ -13,157 +13,161 @@ var Functions = require('../../Functions'); var logger = require('../../logger'); function PublicationListDialog(params) { - AbstractGuiElement.call(this, params); - var self = this; - self.createPublicationListDialogGui(); - $(self.getElement()).dialog({ - title : "Publication list", - autoOpen : false, - resizable : false, - width : Math.max(window.innerWidth / 2, window.innerWidth - 100), - height : Math.max(window.innerHeight / 2, window.innerHeight - 100), - }); + AbstractGuiElement.call(this, params); + var self = this; + self.createPublicationListDialogGui(); + $(self.getElement()).dialog({ + title: "Publication list", + autoOpen: false, + resizable: false, + width: Math.max(window.innerWidth / 2, window.innerWidth - 100), + height: Math.max(window.innerHeight / 2, window.innerHeight - 100), + }); } PublicationListDialog.prototype = Object.create(AbstractGuiElement.prototype); PublicationListDialog.prototype.constructor = PublicationListDialog; -PublicationListDialog.prototype.createPublicationListDialogGui = function() { - var self = this; - var head = Functions.createElement({ - type : "thead", - content : "<tr>" + "<th>Pubmed ID</th>" + // - "<th>Title</th>" + // - "<th>Authors</th>" + // - "<th>Journal</th>" + // - "<th>Year</th>" + // - "<th>Elements on map</th>" + // - "</tr>"// - }); - var body = Functions.createElement({ - type : "tbody", - }); - var tableElement = Functions.createElement({ - type : "table", - className : "minerva-publication-table", - style : "width: 100%", - }); - - tableElement.appendChild(head); - tableElement.appendChild(body); - - self.tableElement = tableElement; - self.getElement().appendChild(tableElement); +PublicationListDialog.prototype.createPublicationListDialogGui = function () { + var self = this; + var head = Functions.createElement({ + type: "thead", + content: "<tr>" + "<th>Pubmed ID</th>" + // + "<th>Title</th>" + // + "<th>Authors</th>" + // + "<th>Journal</th>" + // + "<th>Year</th>" + // + "<th>Elements on map</th>" + // + "</tr>"// + }); + var body = Functions.createElement({ + type: "tbody", + }); + var tableElement = Functions.createElement({ + type: "table", + className: "minerva-publication-table", + style: "width: 100%", + }); + + tableElement.appendChild(head); + tableElement.appendChild(body); + + self.tableElement = tableElement; + self.getElement().appendChild(tableElement); }; -PublicationListDialog.prototype._dataTableAjaxCall = function(data, callback) { - var self = this; - return ServerConnector.getPublications({ - start : data.start, - length : data.length, - sortColumn : self.getColumnsDefinition()[data.order[0].column].name, - sortOrder : data.order[0].dir, - search : data.search.value, - }).then(function(publicationList) { - var out = []; - var allElements = []; - for (var i = 0; i < publicationList.data.length; i++) { - var publication = publicationList.data[i].publication.article; - var elements = publicationList.data[i].elements; - - var row = []; - row[0] = "<a href='" + publication.link + "'>" + publication.id + "</a>"; - row[1] = publication.title; - row[2] = publication.authors.join(); - row[3] = publication.journal; - row[4] = publication.year; - row[5] = "<div>"; - for (var j = 0; j < elements.length; j++) { - row[5] += "<a name='" + elements[j].id + "' href='#'>" + elements[j].type + ":" + elements[j].id + "</a>, "; - allElements.push(new IdentifiedElement(elements[j])); - } - row[5] += "</div>"; - out.push(row); - } - callback({ - draw : data.draw, - recordsTotal : publicationList.totalSize, - recordsFiltered : publicationList.filteredSize, - data : out, - }); - var promises = []; - allElements.forEach(function(element) { - var model = self.getMap().getSubmapById(element.getModelId()).getModel(); - promises.push(model.getByIdentifiedElement(element, true).then(function(elementData) { - var name = null; - if (elementData instanceof Alias) { - name = elementData.getName(); - } else if (elementData instanceof Reaction) { - name = elementData.getReactionId(); +PublicationListDialog.prototype._dataTableAjaxCall = function (data, callback) { + var self = this; + return ServerConnector.getPublications({ + start: data.start, + length: data.length, + sortColumn: self.getColumnsDefinition()[data.order[0].column].name, + sortOrder: data.order[0].dir, + search: data.search.value, + }).then(function (publicationList) { + var out = []; + var allElements = []; + for (var i = 0; i < publicationList.data.length; i++) { + var publication = publicationList.data[i].publication.article; + var elements = publicationList.data[i].elements; + + var row = []; + row[0] = "<a href='" + publication.link + "'>" + publication.id + "</a>"; + row[1] = publication.title; + row[2] = publication.authors.join(); + row[3] = publication.journal; + row[4] = publication.year; + row[5] = "<div>"; + for (var j = 0; j < elements.length; j++) { + row[5] += "<a name='" + elements[j].id + "' href='#'>" + elements[j].type + ":" + elements[j].id + "</a>, "; + allElements.push(new IdentifiedElement(elements[j])); + } + row[5] += "</div>"; + out.push(row); } - $("a[name=" + elementData.getId() + "]", $(self.getElement())).html(name); - var onclick = function() { - var searchOverlay = self.getMap().getOverlayByName("search"); - var query; - if (element.getType() === "ALIAS") { - query = "element:" + element.getId(); - } else { - query = "reaction:" + element.getId(); - } - self.getMap().openSubmap(elementData.getModelId()); - return searchOverlay.searchByQuery(query, true, true).then(function() { - $(self.getElement()).dialog("close"); - }).then(null, GuiConnector.alert); - }; - $("a[name=" + elementData.getId() + "]", $(self.getElement())).click(onclick); - })); + callback({ + draw: data.draw, + recordsTotal: publicationList.totalSize, + recordsFiltered: publicationList.filteredSize, + data: out, + }); + var promises = []; + allElements.forEach(function (element) { + var model = self.getMap().getSubmapById(element.getModelId()).getModel(); + promises.push(model.getByIdentifiedElement(element, true).then(function (elementData) { + var name = null; + if (elementData instanceof Alias) { + name = elementData.getName(); + } else if (elementData instanceof Reaction) { + name = elementData.getReactionId(); + } + $("a[name=" + elementData.getId() + "]", $(self.getElement())).html(name); + var onclick = function () { + var searchOverlay = self.getMap().getOverlayByName("search"); + var query; + if (element.getType() === "ALIAS") { + query = "element:" + element.getId(); + } else { + query = "reaction:" + element.getId(); + } + self.getMap().openSubmap(elementData.getModelId()); + return searchOverlay.searchByQuery(query, true, true).then(function () { + $(self.getElement()).dialog("close"); + }).then(null, GuiConnector.alert); + }; + $("a[name=" + elementData.getId() + "]", $(self.getElement())).click(onclick); + })); + }); + return Promise.all(promises); }); - return Promise.all(promises); - }); }; -PublicationListDialog.prototype.show = function() { - var self = this; - $(self.getElement()).dialog("open"); - - if (!$.fn.DataTable.isDataTable(self.tableElement)) { - return new Promise(function(resolve) { - $(self.tableElement).dataTable({ - serverSide : true, - ordering : true, - searching : true, - ajax : function(data, callback, settings) { - resolve(self._dataTableAjaxCall(data, callback, settings)); - }, - columns : self.getColumnsDefinition(), - }); - }); - } else { - return Promise.resolve(); - } +PublicationListDialog.prototype.show = function () { + var self = this; + $(self.getElement()).dialog("open"); + + if (!$.fn.DataTable.isDataTable(self.tableElement)) { + return new Promise(function (resolve) { + $(self.tableElement).dataTable({ + serverSide: true, + ordering: true, + searching: true, + ajax: function (data, callback, settings) { + resolve(self._dataTableAjaxCall(data, callback, settings)); + }, + columns: self.getColumnsDefinition(), + }); + }); + } else { + return Promise.resolve(); + } }; -PublicationListDialog.prototype.getColumnsDefinition = function() { - return [ { - name : "pubmedId" - }, { - name : "title" - }, { - name : "authors" - }, { - name : "journal" - }, { - name : "year" - }, { - orderable : false, - searchable : false, - name : "elemnts" - } ]; +PublicationListDialog.prototype.getColumnsDefinition = function () { + return [{ + name: "pubmedId" + }, { + name: "title" + }, { + name: "authors" + }, { + name: "journal" + }, { + name: "year" + }, { + orderable: false, + searchable: false, + name: "elemnts" + }]; }; -PublicationListDialog.prototype.destroy = function() { - $(this.getElement()).dialog("destroy"); +PublicationListDialog.prototype.destroy = function () { + var self = this; + $(self.getElement()).dialog("destroy"); + if ($.fn.DataTable.isDataTable(self.tableElement)) { + $(self.tableElement).DataTable().destroy(); + } }; module.exports = PublicationListDialog; diff --git a/frontend-js/src/test/js/gui/admin/EditProjectDialog-test.js b/frontend-js/src/test/js/gui/admin/EditProjectDialog-test.js index f1d6da1d77636ce251885378e5164736d39d02b5..7d3c7d14229f22f8230ad8bb2492a2687d63cce6 100644 --- a/frontend-js/src/test/js/gui/admin/EditProjectDialog-test.js +++ b/frontend-js/src/test/js/gui/admin/EditProjectDialog-test.js @@ -8,100 +8,107 @@ var logger = require('../../logger'); var assert = require('assert'); -describe('EditProjectDialog', function() { +describe('EditProjectDialog', function () { - it('open', function() { - var dialog; - var project; - return ServerConnector.getProject().then(function(result) { - project = result; - dialog = new EditProjectDialog({ - element : testDiv, - project : project, - customMap : null, - }); - return dialog.open(); - }).then(function() { - dialog.destroy(); + it('open', function () { + var dialog; + var project; + return ServerConnector.getProject().then(function (result) { + project = result; + dialog = new EditProjectDialog({ + element: testDiv, + project: project, + customMap: null, + }); + return dialog.open(); + }).then(function () { + dialog.destroy(); + }); }); - }); - it('init', function() { - var dialog; - var project; - return ServerConnector.getProject().then(function(result) { - project = result; - dialog = new EditProjectDialog({ - element : testDiv, - project : project, - customMap : null, - }); - return dialog.init(); + it('init', function () { + var dialog; + var project; + return ServerConnector.getProject().then(function (result) { + project = result; + dialog = new EditProjectDialog({ + element: testDiv, + project: project, + customMap: null, + }); + return dialog.init(); + }).then(function () { + dialog.destroy(); + }); }); - }); - it('saveOverlay', function() { - var dialog; - var project; - return ServerConnector.getProject().then(function(result) { - project = result; - dialog = new EditProjectDialog({ - element : testDiv, - project : project, - customMap : null, - }); - return dialog.init(); - }).then(function(){ - return dialog.saveOverlay(14081); + it('saveOverlay', function () { + var dialog; + var project; + return ServerConnector.getProject().then(function (result) { + project = result; + dialog = new EditProjectDialog({ + element: testDiv, + project: project, + customMap: null, + }); + return dialog.init(); + }).then(function () { + return dialog.saveOverlay(14081); + }).then(function () { + dialog.destroy(); + }); }); - }); - it('saveUser', function() { - var dialog; - var project; - return ServerConnector.getProject().then(function(result) { - project = result; - dialog = new EditProjectDialog({ - element : testDiv, - project : project, - customMap : null, - }); - return dialog.init(); - }).then(function(){ - return dialog.saveUser("anonymous"); + it('saveUser', function () { + var dialog; + var project; + return ServerConnector.getProject().then(function (result) { + project = result; + dialog = new EditProjectDialog({ + element: testDiv, + project: project, + customMap: null, + }); + return dialog.init(); + }).then(function () { + return dialog.saveUser("anonymous"); + }).then(function () { + dialog.destroy(); + }); }); - }); - it('onSaveClicked', function() { - var dialog; - var project; - return ServerConnector.getProject().then(function(result) { - project = result; - project.setVersion("2.01"); - dialog = new EditProjectDialog({ - element : testDiv, - project : project, - customMap : null, - }); - return dialog.onSaveClicked(); - }).then(function(result) { - assert.ok(project === result); + it('onSaveClicked', function () { + var dialog; + var project; + return ServerConnector.getProject().then(function (result) { + project = result; + project.setVersion("2.01"); + dialog = new EditProjectDialog({ + element: testDiv, + project: project, + customMap: null, + }); + return dialog.onSaveClicked(); + }).then(function (result) { + assert.ok(project === result); + dialog.destroy(); + }); }); - }); - it('openAddOverlayDialog', function() { - var dialog; - return ServerConnector.getProject().then(function(result) { - var project = result; - dialog= new EditProjectDialog({ - element : testDiv, - project : project, - customMap : null, - }); - return dialog.openAddOverlayDialog(); - }).then(function() { - dialog.destroy(); + it('openAddOverlayDialog', function () { + var dialog; + return ServerConnector.getProject().then(function (result) { + var project = result; + dialog = new EditProjectDialog({ + element: testDiv, + project: project, + customMap: null, + }); + return dialog.openAddOverlayDialog(); + }).then(function () { + dialog.destroy(); + }); }); - }); }); diff --git a/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js b/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js index 8de9f0087e1c00fa62d4e893399064d85b08731e..388e434d659c5056962c93e2721384b212d15b77 100644 --- a/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js +++ b/frontend-js/src/test/js/gui/admin/MapsAdminPanel-test.js @@ -25,6 +25,8 @@ describe('MapsAdminPanel', function () { return mapTab.init(); }).then(function () { return mapTab.onRefreshClicked(); + }).then(function () { + return mapTab.destroy(); }); }); diff --git a/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js b/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js index 18f4bd29fd3e30349968b60948fcfc6727b5491e..58068fddd668ba88ede7d3541292d26f1949a659 100644 --- a/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js +++ b/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js @@ -8,43 +8,43 @@ var chai = require('chai'); var assert = chai.assert; var logger = require('../../logger'); -describe('PublicationListDialog', function() { +describe('PublicationListDialog', function () { - it('contructor', function() { - var div = testDiv; + it('contructor', function () { + var div = testDiv; - var map = helper.createCustomMap(); + var map = helper.createCustomMap(); - var dialog = new PublicationListDialog({ - element : div, - customMap : map + var dialog = new PublicationListDialog({ + element: div, + customMap: map + }); + assert.equal(logger.getWarnings().length, 0); + + dialog.destroy(); }); - assert.equal(logger.getWarnings().length, 0); - - dialog.destroy(); - }); - - it('_dataTableAjaxCall', function() { - var dialog; - var callbackCalled = false; - return ServerConnector.getProject().then(function(project) { - dialog = new PublicationListDialog({ - element : testDiv, - customMap : helper.createCustomMap(project), - }); - return dialog._dataTableAjaxCall({ - start : 0, - length : 10, - order: [ { column: 0, dir: 'asc' } ], - search: { value: '', regex: false } - }, function(){ - callbackCalled = true; - }); - }).then(function() { - assert.ok(callbackCalled); - }).finally(function() { - dialog.destroy(); + + it('_dataTableAjaxCall', function () { + var dialog; + var callbackCalled = false; + return ServerConnector.getProject().then(function (project) { + dialog = new PublicationListDialog({ + element: testDiv, + customMap: helper.createCustomMap(project), + }); + return dialog._dataTableAjaxCall({ + start: 0, + length: 10, + order: [{column: 0, dir: 'asc'}], + search: {value: '', regex: false} + }, function () { + callbackCalled = true; + }); + }).then(function () { + assert.ok(callbackCalled); + }).finally(function () { + dialog.destroy(); + }); }); - }); }); diff --git a/frontend-js/src/test/js/minerva-test.js b/frontend-js/src/test/js/minerva-test.js index 6f041dace449adce3cfef11aeefb079b6f18b6f9..db73ca216f4edc9b20bc833e5b7d1eeecfc134e0 100644 --- a/frontend-js/src/test/js/minerva-test.js +++ b/frontend-js/src/test/js/minerva-test.js @@ -511,28 +511,28 @@ describe('minerva global', function () { return ServerConnectorMock.getProject().then(function (project) { options = helper.createCustomMapOptions(project); - return minerva.createAdmin(options); - }).then(function(result) { - assert.ok(result); - assert.equal(logger.getWarnings().length, 0); + return minerva.createAdmin(options); + }).then(function (result) { + assert.ok(result); + assert.equal(logger.getWarnings().length, 0); + return result.destroy(); + }); }); - }); - - it("getAllBioEntities", function() { - var options = { - projectId : "sample", - element : testDiv - }; - var globalResult; - return minerva.create(options).then(function(result) { - globalResult = result; - return result.getAllBioEntities(); - }).then(function(result) { - assert.ok(result); - assert.ok(result.length > 0); - }).then(function() { - globalResult.destroy(); + it("getAllBioEntities", function () { + var options = { + projectId: "sample", + element: testDiv + }; + var globalResult; + return minerva.create(options).then(function (result) { + globalResult = result; + return result.getAllBioEntities(); + }).then(function (result) { + assert.ok(result); + assert.ok(result.length > 0); + }).then(function () { + globalResult.destroy(); + }); }); - }); }); diff --git a/frontend-js/src/test/js/mocha-config.js b/frontend-js/src/test/js/mocha-config.js index ea9699eb20e7507f3deeb8d8d34d355c68c5fdcf..f5043a77a917afadb8059543cbb3219fd504d498 100644 --- a/frontend-js/src/test/js/mocha-config.js +++ b/frontend-js/src/test/js/mocha-config.js @@ -130,11 +130,14 @@ beforeEach(function () { afterEach(function () { document.body.removeChild(global.testDiv); delete global.testDiv; - if (document.body.hasChildNodes()) { - var content = document.body.innerHTML; - document.body.innerHTML = ""; - if (this.currentTest.state !== 'failed') { + if (this.currentTest.state !== 'failed') { + if (document.body.hasChildNodes()) { + var content = document.body.innerHTML; + document.body.innerHTML = ""; this.test.error(new Error("Test didn't left clean document. Found: " + content)); + } else if ($._data(window, "events").resize) { + logger.debug($._data(window, "events").resize); + this.test.error(new Error("Test didn't left clean resize events handlers.")); } } });