File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 11<script setup lang="ts">
2+ import { downloadTsv } from " @/utils/tsv" ;
3+
24const props = defineProps <{
35 hits: any [];
46}>();
57
68function getAreaLink(hit : any ) {
79 return ` /area?record=${hit .s_acc }&start=${hit .s_rec_start }&end=${hit .s_rec_end } ` ;
810}
11+
12+ function triggerDownload(){
13+ downloadTsv (props .hits , ' clusterblast_results.tsv' );
14+ }
915 </script >
1016
1117<template >
1218 <div v-if =" props.hits.length > 0" >
19+ <button class =" dl-button" @click =" triggerDownload" >Download TSV</button >
1320 <table >
1421 <thead >
1522 <tr >
@@ -38,4 +45,7 @@ function getAreaLink(hit: any) {
3845.identity {
3946 text-align : right ;
4047}
48+ .dl-button {
49+ float : right ;
50+ }
4151 </style >
Original file line number Diff line number Diff line change 11<script setup lang="ts">
2+ import { downloadTsv } from " @/utils/tsv" ;
3+
24const props = defineProps <{
35 hits: any [];
46}>();
57
68function getAreaLink(hit : any ) {
79 return ` /area?record=${hit .s_acc }&start=${hit .s_rec_start }&end=${hit .s_rec_end } ` ;
810}
11+
12+ function triggerDownload(){
13+ downloadTsv (props .hits , ' clusterblast_results.tsv' );
14+ }
915 </script >
1016
1117<template >
1218 <div v-if =" props.hits.length > 0" >
19+ <button class =" dl-button" @click =" triggerDownload" >Download TSV</button >
1320 <table >
1421 <thead >
1522 <tr >
@@ -40,4 +47,7 @@ function getAreaLink(hit: any) {
4047.identity {
4148 text-align : right ;
4249}
50+ .dl-button {
51+ float : right ;
52+ }
4353 </style >
Original file line number Diff line number Diff line change 1+ export const downloadTsv = (
2+ data : object [ ] ,
3+ filename : string ,
4+ headers ?: string [ ] ,
5+ separator ?: string ,
6+ ) => {
7+ if ( ! data || ! data . length ) {
8+ return ;
9+ }
10+ if ( separator === undefined ) {
11+ separator = "\t" ;
12+ }
13+
14+ const keys : string [ ] = Object . keys ( data [ 0 ] ) ;
15+
16+ let columnHeaders : string [ ] ;
17+
18+ if ( headers ) {
19+ columnHeaders = headers ;
20+ } else {
21+ columnHeaders = keys ;
22+ }
23+
24+ const contentRows = data . map ( dataItem => {
25+ return keys . map ( key => {
26+ if ( dataItem [ key ] === null || dataItem [ key ] === undefined ) {
27+ return "" ;
28+ }
29+ return String ( dataItem [ key ] ) . replace ( / \t / g, " " ) ;
30+ } ) . join ( separator ) ;
31+ } ) ;
32+
33+ const tsvData = [ columnHeaders . join ( separator ) , ...contentRows ] . join ( "\n" )
34+
35+ const blob = new Blob ( [ tsvData ] , { type : "text/csv;charset=utf-8" } ) ;
36+ const link = document . createElement ( "a" ) ;
37+ link . href = window . URL . createObjectURL ( blob ) ;
38+ link . download = filename ;
39+ link . click ( ) ;
40+ } ;
41+
42+
You can’t perform that action at this time.
0 commit comments