From 05fc975a313aa38483d904cb9ad07a029641d086 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 16 Dec 2018 16:29:04 +0100 Subject: rebuild --- client/tables.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 client/tables.js (limited to 'client/tables.js') diff --git a/client/tables.js b/client/tables.js new file mode 100644 index 00000000..6b00bbde --- /dev/null +++ b/client/tables.js @@ -0,0 +1,43 @@ +import Tabulator from 'tabulator-tables' +import csv from 'parse-csv' + +const datasetColumns = [ + { title: 'Title', field: 'title', sorter: 'string' }, + { title: 'Images', field: 'images', sorter: 'number' }, + { title: 'People', field: 'people', sorter: 'number' }, + { title: 'Year', field: 'year', sorter: 'number' }, + { title: 'Citations', field: 'citations', sorter: 'number' }, + { title: 'Influenced', field: 'influenced', sorter: 'number' }, + // { title: 'Origin', field: 'origin', sorter: 'string' }, +] + +function getColumns(payload) { + if (payload.opt.match('datasets.csv')) { + return datasetColumns + } + return (payload.fields || '').split(', ').map(field => { + switch (field) { + default: + return { title: field, field: field.toLowerCase(), sorter: 'string' } + } + }) +} + +export default function append(el, payload) { + const columns = getColumns(payload) + const table = new Tabulator(el, { + height: '311px', + layout: 'fitDataFill', + placeholder: 'No Data Set', + columns, + }) + // let path = payload.opt + // console.log(path, columns) + fetch(payload.opt, { mode: 'cors' }) + .then(r => r.text()) + .then(text => { + const data = csv.toJSON(text, { headers: { included: true } }) + console.log(data) + table.setData(data) + }) +} -- cgit v1.2.3-70-g09d2