diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-12-16 18:11:12 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-12-16 18:11:12 +0100 |
| commit | 6431d06048791763f3644b3a0457cc9c4f1df6d3 (patch) | |
| tree | 0162ef07f7bd78695e185849bbf253cd431ff65b /client/tables.js | |
| parent | 17dea19bfff556d990f664a608881a135f33071a (diff) | |
csvs and citations
Diffstat (limited to 'client/tables.js')
| -rw-r--r-- | client/tables.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/client/tables.js b/client/tables.js index 4a6c666f..a30abc32 100644 --- a/client/tables.js +++ b/client/tables.js @@ -16,13 +16,14 @@ const citationsColumns = [ ] function getColumns(payload) { - if (payload.cmd === 'citations') { + let { cmd, url, fields } = payload + if (cmd === 'citations') { return citationsColumns } - if (payload.opt.match('datasets.csv')) { + if (url && url.match('datasets.csv')) { return datasetColumns } - return (payload.fields || '').split(', ').map(field => { + return ((fields && fields.length) ? fields[0] : '').split(', ').map(field => { switch (field) { default: return { title: field, field: field.toLowerCase(), sorter: 'string' } @@ -39,8 +40,8 @@ function getCitations(dataset) { } export default function append(el, payload) { - let url = payload.opt const columns = getColumns(payload) + console.log(columns) const table = new Tabulator(el, { height: '311px', layout: 'fitColumns', @@ -50,18 +51,25 @@ export default function append(el, payload) { // let path = payload.opt // console.log(path, columns) + console.log(payload.cmd, payload.url, payload.dataset) if (payload.cmd === 'citations') { let { data } = payload const citations = getCitations(data) console.log(citations) table.setData(citations) } else { - fetch(url, { mode: 'cors' }) + fetch(payload.url, { mode: 'cors' }) .then(r => r.text()) .then(text => { - const data = csv.toJSON(text, { headers: { included: true } }) - console.log(data) - table.setData(data) + try { + const data = csv.toJSON(text, { headers: { included: true } }) + // console.log(data) + table.setData(data) + } catch (e) { + console.error("error parsing json:", payload.url) + console.error(e) + // console.log(text) + } }) } } |
