diff --git a/frontend-js/src/main/js/gui/export/NetworkExportPanel.js b/frontend-js/src/main/js/gui/export/NetworkExportPanel.js index 67be353d052dd7282105e9bc3304430bae5d95ef..9d9f6f655f40a7be5431459f820366d32b3da343 100644 --- a/frontend-js/src/main/js/gui/export/NetworkExportPanel.js +++ b/frontend-js/src/main/js/gui/export/NetworkExportPanel.js @@ -7,6 +7,7 @@ var AbstractExportPanel = require('./AbstractExportPanel'); var Promise = require("bluebird"); var logger = require('../../logger'); var GuiMessageError = require('../GuiMessageError'); +var Functions = require('../../Functions'); /** * @@ -257,18 +258,10 @@ NetworkExportPanel.prototype.createResponseString = function () { * @returns {Promise<string>} */ NetworkExportPanel.prototype.createResponseRow = function (reaction, columns, miriamTypes, elementIds) { - var stringBuilder = []; + var valuePromises = []; var i, value; for (i = 0; i < columns.length; i++) { - var column = columns[i]; - value = reaction[column.method](); - if (column.formatFunction !== undefined) { - value = column.formatFunction(value, reaction, elementIds); - } - if (value instanceof String || typeof value === "string") { - value = value.replace(/[\n\r]/g, ' '); - } - stringBuilder.push(value); + valuePromises.push(this._createResponseCell(reaction, columns[i], elementIds)); } for (i = 0; i < miriamTypes.length; i++) { value = ""; @@ -280,9 +273,38 @@ NetworkExportPanel.prototype.createResponseRow = function (reaction, columns, mi value += reference.getResource() + ","; } } - stringBuilder.push(value); + valuePromises.push(value); + } + return Promise.all(valuePromises).then(function (values) { + return values.join("\t"); + }); +}; + +/** + * + * @param {Reaction} reaction + * @param {ExportColumn} column + * @param {Object<string,boolean>} elementIds + * @returns {Promise<string>} + * @private + */ +NetworkExportPanel.prototype._createResponseCell = function (reaction, column, elementIds) { + var valuePromise; + if (Functions.isString(column.method)) { + valuePromise = Promise.resolve(reaction[column.method]()); + } else { + valuePromise = Promise.resolve(column.method(reaction, this.getProject())); } - return Promise.resolve(stringBuilder.join("\t")); + + return valuePromise.then(function (value) { + if (column.formatFunction !== undefined) { + value = column.formatFunction(value, reaction, elementIds); + } + if (Functions.isString(value)) { + value = value.replace(/[\n\r]/g, ' '); + } + return value; + }); }; module.exports = NetworkExportPanel;