Skip to content

Commit

Permalink
Add citation and column descriptions in downloaded CSV (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanep97 authored Nov 26, 2024
1 parent 9279294 commit 74cb4df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
21 changes: 21 additions & 0 deletions iop4api/static/iop4api/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion iop4api/templates/iop4api/data.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<div v-show="showDataTable" id="tableControlsContainer">
<button class="button" id="download-csv">Download as csv</button>
<button class="button" id="download-pdf">Download as pdf</button>
<label style="display: flex; align-items: center; gap: 4px;"><input type="checkbox" id="download-include-helptext" name="download-include-helptext" />include columns help</label>
<button class="button" id="column-visibilities" onclick="show_column_visibility_modal_form()">Toggle columns</button>
<button class="button" id="column-visibilities" @click="showDataTableFilters=true;">Set filters</button>
<button class="button" id="table-filters" @click="showDataTableFilters=true;">Set filters</button>
<!-- Column modal form -->
<div id="column_visibility_modal_form" class="modal">
<div class="modal-content">
Expand Down
8 changes: 4 additions & 4 deletions iop4api/templates/iop4api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<link href="https://cdn.jsdelivr.net/npm/quasar@2.12.5/dist/quasar.prod.css" rel="stylesheet" type="text/css">

<!-- Tabulator -->
<link href="https://unpkg.com/tabulator-tables@5.4.2/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.4.2/dist/js/tabulator.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js" integrity="sha512-qZvrmS2ekKPF2mSznTQsxqPgnpkI4DNTlrdUmTzrDgektczlKNRRhy5X5AAOnx5S09ydFYWWNSfcEqDTTHgtNA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.25/jspdf.plugin.autotable.min.js" integrity="sha512-SgWewGM3r8xXm8LNXt4ZHqKVKu/7eKrJ1aBCbMaX44xXXaCcIvCAvD2kj9qnC1lhyjAu04mcPiTzcc/CaACnUQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link href="https://unpkg.com/tabulator-tables@6.3.0/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@6.3.0/dist/js/tabulator.min.js" integrity="sha384-gb+8dgIcSEcX2zwyEPEEKZiwD8km3OTz47IVU3CXdP/pYz4fRAdb9pJdlHW8VvM0" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/jspdf@2.5.2/dist/jspdf.umd.min.js" integrity="sha384-en/ztfPSRkGfME4KIm05joYXynqzUgbsG5nMrj/xEFAHXkeZfO3yMK8QQ+mP7p1/" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/jspdf-autotable@3.8.4/dist/jspdf.plugin.autotable.min.js" integrity="sha384-Xl/CUCfJbzsngMp0CFxkmF0VW/8C160IsGujqeQlIhaGxKz2+JsIGORFqtCPeldF" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<!-- jquery gui required for bokeh datatable reorder -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
Expand Down

0 comments on commit 74cb4df

Please sign in to comment.