diff --git a/iop4api/static/iop4api/gui.js b/iop4api/static/iop4api/gui.js index c73c70e6..bdc6821a 100644 --- a/iop4api/static/iop4api/gui.js +++ b/iop4api/static/iop4api/gui.js @@ -124,6 +124,27 @@ function make_nice_table() { }, ] }, + downloadEncoder:function(fileContents, mimeType){ + // if its csv format, add some comments at the top of the file + console.log("mimeType", mimeType); + if(mimeType === "text/csv"){ + console.log("Adding comments to csv file"); + // add citation instructions + headerText = "# IOP4. Cite: https://dx.doi.org/10.3847/1538-3881/ad5a80\n" + // if download-include-helptext is checked, add the columns help text as comments + if (document.getElementById("download-include-helptext").checked) { + headerText += "# Columns:\n"; + for (let col of table.getColumns()) { + if (col.isVisible()) { + col_def = col.getDefinition(); + headerText += col_def.field ? `# - ${col_def.field}: ${col_def.headerTooltip}\n` : `# - ${col_def.title}\n`; + } + } + } + fileContents = headerText + fileContents; + } + return new Blob([fileContents], {type:mimeType}); + }, }); // link table controls to this table diff --git a/iop4api/templates/iop4api/data.html b/iop4api/templates/iop4api/data.html index cd71b625..1da6af55 100644 --- a/iop4api/templates/iop4api/data.html +++ b/iop4api/templates/iop4api/data.html @@ -11,8 +11,9 @@
+ - +