From 36cda707b6b03a7b2aa10e6b17ca780797916060 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 1 Apr 2019 19:45:15 +0200 Subject: test csv --- client/table/citations.table.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'client/table/citations.table.js') diff --git a/client/table/citations.table.js b/client/table/citations.table.js index f9599f5d..0092015f 100644 --- a/client/table/citations.table.js +++ b/client/table/citations.table.js @@ -2,10 +2,9 @@ import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { ReactTabulator } from 'react-tabulator' -import MultiValueFormatter from "react-tabulator/lib/formatters/MultiValueFormatter" import { Loader } from '../common' -import { toArray, toTuples } from '../util' +import { toArray, toTuples, domainFromUrl } from '../util' export const citationsColumns = [ { title: 'Title', field: 'title', sorter: 'string' }, @@ -42,13 +41,7 @@ class CitationsTable extends Component { : (citation.doi && citation.doi.length) ? citation.doi[0] : 'https://www.semanticscholar.org/paper/' + citation.id - let pdf_text - const pdf_partz = pdf_link.split('/')[2].split('.') - if (pdf_partz.length > 2 && pdf_partz[pdf_partz.length - 2].length == 2) { - pdf_text = pdf_partz.slice(-3).join('.') - } else { - pdf_text = pdf_partz.slice(-2).join('.') - } + let pdf_text = domainFromUrl(pdf_link) return { title: citation.title, institution: citation.addresses.map(a => a.name).sort().join('; '), @@ -83,13 +76,16 @@ class CitationsTable extends Component { if (!formattedCitations.length) return return (
- this.updateFilter(e.target.value)} - className='q' - placeholder='Enter text to search citations...' - /> +
+ this.updateFilter(e.target.value)} + className='q' + placeholder='Enter text to search citations...' + /> + Date: Mon, 1 Apr 2019 20:03:27 +0200 Subject: csv export --- client/table/citations.table.js | 29 ++++++++++++++++++++++++++++- client/table/tabulator.css | 25 ++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) (limited to 'client/table/citations.table.js') diff --git a/client/table/citations.table.js b/client/table/citations.table.js index 0092015f..bbc55047 100644 --- a/client/table/citations.table.js +++ b/client/table/citations.table.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { ReactTabulator } from 'react-tabulator' +import { saveAs } from 'file-saver' import { Loader } from '../common' import { toArray, toTuples, domainFromUrl } from '../util' @@ -71,6 +72,32 @@ class CitationsTable extends Component { } } + download() { + const { formattedCitations } = this.state + const fn = this.props.payload.data.paper.key + '.csv' + const titles = citationsColumns.map(c => c.title) + const fields = citationsColumns.map(c => c.formatterParams ? c.formatterParams.urlField : c.field) + const rows = formattedCitations.map(citation => { + const row = fields.map(field => citation[field]).map(data => { + switch (typeof data) { + case 'number': + return String(data) + default: + return '\"' + String(data) + '\"' + } + }) + return row.join(",") + }) + + const blob = new Blob([ + [ + titles.join(','), + ...rows, + ].join('\n') + ], {type: "text/csv;charset=utf-8"}); + saveAs(blob, fn); + } + render() { const { formattedCitations, filteredCitations } = this.state if (!formattedCitations.length) return @@ -84,7 +111,7 @@ class CitationsTable extends Component { className='q' placeholder='Enter text to search citations...' /> - this.download()}>Download CSV