From 0bede27de3bcc0c7f03d16c7607a0ae693daebc7 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 1 Apr 2019 10:23:29 +0200 Subject: citations table in react --- package-lock.json | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 4 deletions(-) (limited to 'package-lock.json') diff --git a/package-lock.json b/package-lock.json index 6d36e3ff..4e9d6fac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -216,6 +216,28 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.38.tgz", "integrity": "sha512-EibsnbJerd0hBFaDjJStFrVbVBAtOy4dgL8zZFw0uOvPqzBAX59Ci8cgjg3+RgJIWhsB5A4c+pi+D4P9tQQh/A==" }, + "@types/prop-types": { + "version": "15.7.0", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.0.tgz", + "integrity": "sha512-eItQyV43bj4rR3JPV0Skpl1SncRCdziTEK9/v8VwXmV6d/qOUO8/EuWeHBbCZcsfSHfzI5UyMJLCSXtxxznyZg==" + }, + "@types/react": { + "version": "16.8.10", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.10.tgz", + "integrity": "sha512-7bUQeZKP4XZH/aB4i7k1i5yuwymDu/hnLMhD9NjVZvQQH7ZUgRN3d6iu8YXzx4sN/tNr0bj8jgguk8hhObzGvA==", + "requires": { + "@types/prop-types": "*", + "csstype": "^2.2.0" + } + }, + "@types/react-tag-autocomplete": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/@types/react-tag-autocomplete/-/react-tag-autocomplete-5.6.0.tgz", + "integrity": "sha512-EsUrbpKW5agXs/NbMUQRgwtZInQbUIIPBXiUz+XcJeUP7U6BRCWjw96sQmsEPRUwO0CdPfQEd82zwpCIGEr4Ew==", + "requires": { + "@types/react": "*" + } + }, "accepts": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", @@ -2249,6 +2271,11 @@ "integrity": "sha1-yBSQPkViM3GgR3tAEJqq++6t27Q=", "dev": true }, + "csstype": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.3.tgz", + "integrity": "sha512-rINUZXOkcBmoHWEyu7JdHu5JMzkGRoMX4ov9830WNgxf5UYxcBUO0QTKAqeJ5EZfSdlrcJYkC8WwfVW7JYi4yg==" + }, "csv-parse": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-4.2.0.tgz", @@ -4647,6 +4674,11 @@ "wbuf": "^1.1.0" } }, + "html-attributes": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/html-attributes/-/html-attributes-1.1.0.tgz", + "integrity": "sha1-ggJ6T6x6YHDqbBjMOIauoY1t6gk=" + }, "html-entities": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.2.1.tgz", @@ -5594,9 +5626,9 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "js-yaml": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", - "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.0.tgz", + "integrity": "sha512-pZZoSxcCYco+DIKBTimr67J6Hy+EYGZDY/HCWC+iAEA9h1ByhMXAIVUXMcMFpOCxQ/xjXmPI2MkDL5HRm5eFrQ==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -5781,6 +5813,11 @@ "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=" }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, "lodash.merge": { "version": "4.6.1", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz", @@ -6710,6 +6747,16 @@ "sha.js": "^2.4.8" } }, + "pick-react-known-prop": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/pick-react-known-prop/-/pick-react-known-prop-0.1.5.tgz", + "integrity": "sha512-SnDf64AVdvqoAFpHeZUKT9kdn40Ellj84CPALRxYWqNJ6r6f44eAAT+Jtkb0Suhiw7yg5BdOFAQ25OJnjG+afw==", + "requires": { + "html-attributes": "^1.1.0", + "lodash.isplainobject": "^4.0.6", + "svg-attributes": "^1.0.0" + } + }, "pify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", @@ -7274,6 +7321,36 @@ "spin.js": "^2.0.1" } }, + "react-tabulator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/react-tabulator/-/react-tabulator-0.9.1.tgz", + "integrity": "sha512-KLkO17TZbGKzwaCPD8c84cG94OkSpU0zyvlhOleKJELQWcHEL99+63DEamEaXOsguDfxM474lxu3K+jqG2bW/Q==", + "requires": { + "@types/react-tag-autocomplete": "^5.6.0", + "date-fns": "v2.0.0-alpha.25", + "dotenv": "^6.1.0", + "pick-react-known-prop": "^0.1.5", + "react-tag-autocomplete": "^5.7.1", + "tabulator-tables": "^4.2.3" + }, + "dependencies": { + "date-fns": { + "version": "2.0.0-alpha.25", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.0.0-alpha.25.tgz", + "integrity": "sha512-iQzJkHF0L4wah9Ae9PkvwemwFz6qmRLuNZcghmvf2t+ptLs1qXzONLiGtjmPQzL6+JpC01JjlTopY2AEy4NFAg==" + }, + "tabulator-tables": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/tabulator-tables/-/tabulator-tables-4.2.3.tgz", + "integrity": "sha512-vMQ/8/HSKzOdn1zd9uv7EmnBnMTlX8JMhfxAxEUkM12qYiqhapWp/iN2ErtDX2cVi+4CUaEn61qydSFJyKjdYA==" + } + } + }, + "react-tag-autocomplete": { + "version": "5.8.2", + "resolved": "https://registry.npmjs.org/react-tag-autocomplete/-/react-tag-autocomplete-5.8.2.tgz", + "integrity": "sha512-GkOQrSLjvWo98IeqRuGgc77zaxSMyMjy+b2Rc+m9jMKTWopF9h5Lf2F/X1oK9hcnUCeUmJ5QVpc/dx9MgOA2Iw==" + }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -8546,7 +8623,7 @@ }, "sprintf-js": { "version": "1.0.3", - "resolved": "http://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, @@ -8722,6 +8799,11 @@ "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", "dev": true }, + "svg-attributes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/svg-attributes/-/svg-attributes-1.0.0.tgz", + "integrity": "sha1-tcWWjzYke32+OFMgfyqcaK2Aa/w=" + }, "svgtodatauri": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/svgtodatauri/-/svgtodatauri-0.0.0.tgz", -- cgit v1.2.3-70-g09d2 From 36cda707b6b03a7b2aa10e6b17ca780797916060 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 1 Apr 2019 19:45:15 +0200 Subject: test csv --- .gitignore | 3 +++ client/index.js | 8 +++++-- client/table/citations.table.js | 28 ++++++++++------------ client/table/file.table.js | 42 +++++++++++++++++++++++++-------- client/util/index.js | 9 +++++++ package-lock.json | 8 +++---- package.json | 2 +- site/content/pages/test/assets/test.csv | 8 +++++++ site/content/pages/test/csv.md | 4 ++-- site/public/datasets/index.html | 12 +++++----- site/public/test/csv/index.html | 2 +- 11 files changed, 84 insertions(+), 42 deletions(-) create mode 100644 site/content/pages/test/assets/test.csv (limited to 'package-lock.json') diff --git a/.gitignore b/.gitignore index 74a8a054..e41e7c36 100644 --- a/.gitignore +++ b/.gitignore @@ -170,3 +170,6 @@ site/public/user_content site/datasets/final/*.csv +flask.log +flask.log.* + diff --git a/client/index.js b/client/index.js index 668aebfb..5e36d341 100644 --- a/client/index.js +++ b/client/index.js @@ -65,14 +65,17 @@ function runApplets() { let opt = null payload.cmd = cmd payload.partz = cmdPartz + if (payload.cmd === 'load_file') { + payload.url = 'https://nyc3.digitaloceanspaces.com/megapixels/v1' + cmdPartz.shift() + return [el, payload] + } + if (payload.partz.length) { opt = payload.partz.shift().trim() if (opt.indexOf('http') === 0) { dataset = null url = opt } else if (opt.indexOf('assets') === 0) { - let pathname = window.location.pathname.replace('index.html', '') - url = 'https://nyc3.digitaloceanspaces.com/megapixels/v1' + pathname + opt dataset = null // console.log(url) } else { @@ -95,6 +98,7 @@ function runApplets() { } payload.dataset = dataset payload.url = url + console.log(payload) return [el, payload] }).filter(a => !!a) const withDataset = applets.map(a => a[1].dataset ? a[1] : null).filter(a => !!a) 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...' + /> + r.text()) .then(text => { try { + const keys = text.split('\n')[0].split(',').map(s => s.trim().replace(/\"/,'')) const data = csv.toJSON(text, { headers: { included: true } }) - this.setState({ data }) + // console.log(data) + const columns = this.getColumns(keys, data, payload.fields) + this.setState({ keys, data, columns }) } catch (e) { console.error("error making json:", payload.url) console.error(e) @@ -27,26 +34,41 @@ class FileTable extends Component { }) } - getColumns(payload) { - let { cmd, url, fields } = payload - return ((fields && fields.length) ? fields[0] : '').split(', ').map(field => { + getColumns(keys, data, fields) { + let titles = fields.length ? fields[0].split(', ') : keys + let numberFields = [] + let columns = keys.map((field, i) => { + const title = titles[i] || field + if (field.match('url')) { + let textField = field.replace('url', 'label') + data.forEach(el => el[textField] = domainFromUrl(el[field])) + return { + title, + field: textField, + formatter: 'link', + formatterParams: { target: "_blank", urlField: field, }, + sorter: 'string' + } + } switch (field) { + case 'images': + case 'year': + return { title, field: field.toLowerCase(), sorter: 'number' } default: - return { title: field, field: field.toLowerCase(), sorter: 'string' } + return { title, field: field.toLowerCase(), sorter: 'string' } } }) + return columns } render() { const { payload } = this.props - const { paper, citations } = payload.data - const columns = getColumns(payload) if (!this.state.data.length) { return } return ( (n * 100).toFixed(1) + '%' export const px = (n, w) => Math.round(n * w) + 'px' export const clamp = (n, a, b) => n < a ? a : n < b ? n : b +export const domainFromUrl = url => { + const partz = url.split('/')[2].split('.') + if (partz.length > 2 && partz[partz.length - 2].length == 2) { + return partz.slice(-3).join('.') + } else { + return partz.slice(-2).join('.') + } +} + /* URLs */ export const preloadImage = opt => { diff --git a/package-lock.json b/package-lock.json index 4e9d6fac..43ee0cbf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3673,9 +3673,9 @@ } }, "file-saver": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.0.tgz", - "integrity": "sha512-cYM1ic5DAkg25pHKgi5f10ziAM7RJU37gaH1XQlyNDrtUnzhC/dfoV9zf2OmF0RMKi42jG5B0JWBnPQqyj/G6g==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.1.tgz", + "integrity": "sha512-dCB3K7/BvAcUmtmh1DzFdv0eXSVJ9IAFt1mw3XZfAexodNRoE29l3xB2EX4wH2q8m/UTzwzEPq/ArYk98kUkBQ==" }, "filename-regex": { "version": "2.0.1", @@ -8623,7 +8623,7 @@ }, "sprintf-js": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "resolved": "http://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, diff --git a/package.json b/package.json index 6238e7e3..75fbebb7 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "exif-reader": "^1.0.2", "exifreader": "^2.5.0", "fetch-jsonp": "^1.1.3", - "file-saver": "^2.0.0-rc.3", + "file-saver": "^2.0.1", "history": "^4.7.2", "leaflet": "^1.3.4", "leaflet-arc": "^1.0.2", diff --git a/site/content/pages/test/assets/test.csv b/site/content/pages/test/assets/test.csv new file mode 100644 index 00000000..7156a814 --- /dev/null +++ b/site/content/pages/test/assets/test.csv @@ -0,0 +1,8 @@ +name,images,year,gender,description,url +aardvark,100,2019,m,bim da,https://asdf.us/ +bobcat,10,2017,f,in a tree,https://asdf.us/ +cow,20,2012,f,moooo,https://asdf.us/ +doe,2,2016,f,doe a deer,https://asdf.us/ +earwig,1,2017,m,just a bug,https://i.asdf.us/ +frog,17,2018,f,ribbit ribbit,https://i.asdf.us/ +giraffe,23,2009,m,i get around,https://adsf.us/ diff --git a/site/content/pages/test/csv.md b/site/content/pages/test/csv.md index b5f37754..85f714b4 100644 --- a/site/content/pages/test/csv.md +++ b/site/content/pages/test/csv.md @@ -15,6 +15,6 @@ authors: Megapixels ### [← Back to test index](/test/) ``` -load_file /datasets/lfw/assets/lfw_names_gender_kg_min.csv -Name, Images, Gender, Description +load_file /site/test/assets/test.csv +Name, Images, Year, Gender, Description, URL ``` diff --git a/site/public/datasets/index.html b/site/public/datasets/index.html index 1d2630e1..3a2dbd52 100644 --- a/site/public/datasets/index.html +++ b/site/public/datasets/index.html @@ -42,8 +42,8 @@ Brainwash
2015
-
Decoding image into set of people detections.
-
11,918 images
+
Head detection
+
11,917 images
@@ -90,7 +90,7 @@ MS Celeb
2016
-
face recognition
+
Large-scale face recognition
1,000,000 images
100,000
@@ -114,9 +114,9 @@ Unconstrained College Students
2018
-
Unconstrained face recognition
+
Face recognition, face detection
16,149 images
-
4,362
+
1,732
@@ -126,7 +126,7 @@ VIPeR
2007
-
pedestrian re-identification
+
Person re-identification
1,264 images
632
diff --git a/site/public/test/csv/index.html b/site/public/test/csv/index.html index 3257716f..70a7d257 100644 --- a/site/public/test/csv/index.html +++ b/site/public/test/csv/index.html @@ -28,7 +28,7 @@

CSV Test

← Back to test index

-
+