From ad6284a2040837e7373b4d89644a01306f181dd5 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 28 Mar 2019 14:45:07 +0100 Subject: fetch papers by single dataset --- scraper/client/actions.js | 7 +++- scraper/client/paper/paper.citations.js | 42 +++++++++++--------- scraper/client/paper/paper.verify.js | 68 +++++++++++++++++++++++++-------- 3 files changed, 81 insertions(+), 36 deletions(-) (limited to 'scraper/client') diff --git a/scraper/client/actions.js b/scraper/client/actions.js index 734a8cbd..1b5152ea 100644 --- a/scraper/client/actions.js +++ b/scraper/client/actions.js @@ -1,9 +1,10 @@ import { get, post } from './util' import * as types from './types' -export const api = (dispatch, method, tag, url, params) => { +export const api = (dispatch, method, tag, url, params, after) => { dispatch({ type: types.api.loading, tag }) return method(url, params).then(data => { + if (after) data = after(data) dispatch({ type: types.api.loaded, tag, data }) return data }).catch(err => { @@ -36,6 +37,10 @@ export const getVerifications = () => dispatch => ( api(dispatch, get, 'verifications', '/api/verifications', {}) ) +export const getVerificationsDataset = dataset => dispatch => ( + api(dispatch, get, 'verifications', '/api/verifications/' + dataset, {}) +) + export const getVerification = sha256 => dispatch => ( api(dispatch, get, 'verify', '/api/verify/' + sha256, {}) ) diff --git a/scraper/client/paper/paper.citations.js b/scraper/client/paper/paper.citations.js index 5c8e0e0c..c55599e0 100644 --- a/scraper/client/paper/paper.citations.js +++ b/scraper/client/paper/paper.citations.js @@ -5,26 +5,32 @@ import { Link } from 'react-router-dom' import * as actions from '../actions' -import { TableObject } from '../common' +import { TableObject, Loader } from '../common' import { USES_DATASET } from '../types' class PaperCitations extends Component { - componentDidMount() { - this.props.actions.getVerifications() + componentDidUpdate(prevProps) { + if (this.props.api.paperInfo.dataset !== prevProps.api.paperInfo.dataset) { + this.props.actions.getVerificationsDataset(this.props.api.paperInfo.dataset.key) + } } render() { - const { dataset, citations } = this.props.api.paperInfo - let { verifications } = this.props.api.verifications - verifications = verifications || {} - if (!dataset || !citations) return null - console.log('rendering citations...') - // console.log(citations) + const { paperInfo, unknownCitations, verifications } = this.props.api + const { dataset, citations } = paperInfo + if (!dataset || !citations || !verifications[dataset.key]) return + let verifiedLookup = verifications[dataset.key] || {} + // console.log(verifications) + return (

{dataset.name_full}: Citations

    - {citations.map((citation, i) => { + {citations.concat(unknownCitations.citations) + .map(citation => [citation.title, verifiedLookup[citation.id] ? verifiedLookup[citation.id].uses_dataset : USES_DATASET.UNKNOWN, citation]) + .sort((a,b) => (b[1] - a[1] || (a[0].localeCompare(b[0])))) + .map((pair, i) => { + const [ title, uses_dataset, citation ] = pair let cite = { ...citation } cite.id = { _raw: true, @@ -32,7 +38,9 @@ class PaperCitations extends Component { } cite.pdf = { _raw: true, - value: (cite.pdf && cite.pdf.length) ? [pdf] : "no pdf" + value: (cite.pdf && cite.pdf.length) + ? cite.pdf.map((pdf, i) => [pdf]) + : "no pdf" } cite.s2 = { _raw: true, @@ -45,23 +53,19 @@ class PaperCitations extends Component { } cite.addresses = { _raw: true, - value: cite.addresses.map((address, j) => ( + value: (cite.addresses || []).map((address, j) => (
    {address.name}{', '}{address.type}
    )) } - if (citation.id in verifications && verifications[citation.id].dataset === dataset.key) { - const verification = verifications[citation.id] + if (citation.id in verifiedLookup) { + const verification = verifiedLookup[citation.id] cite.verified = { _raw: true, value: verification.uses_dataset === USES_DATASET.YES ? uses dataset : verification.uses_dataset === USES_DATASET.NO ? {"doesn't use dataset"} - : verification.uses_dataset === 'TRUE' - ? uses dataset - : verification.uses_dataset === 'FALSE' - ? {"doesn't use dataset"} - : {"not enough information"} + : {"not enough information"} } } else { diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 65342adf..1b55186a 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -9,13 +9,16 @@ import { USES_DATASET } from '../types' const initialState = { citation: null, + address: {}, uses_dataset: USES_DATASET.UNKNOWN, images_in_paper: "FALSE", used_as_model: "FALSE", verified_by: localStorage.getItem('verify.username') || '', reference: '', notes: '', + location: '', pdf_index: 0, + isUnknown: false, } class PaperVerify extends Component { @@ -26,6 +29,7 @@ class PaperVerify extends Component { componentDidMount() { const { sha256 } = this.props.match.params this.props.actions.getInstitutions() + this.props.actions.getAddress(sha256) this.props.actions.getVerification(sha256) const citationState = this.getCitationState(sha256) console.log('DID MOUNT') @@ -34,52 +38,66 @@ class PaperVerify extends Component { componentDidUpdate(oldProps) { const { sha256 } = this.props.match.params - const { verify } = this.props.api + const { address, verify } = this.props.api const { sha256: oldSha256 } = oldProps.match.params - const { verify: oldVerify } = oldProps.api + const { verify: oldVerify, address: oldAddress } = oldProps.api const oldPaper = oldVerify ? oldVerify.paper : null const paper = verify ? verify.paper : null + let newState = {} if (oldSha256 && sha256 !== oldSha256) { console.log('update verification') + this.props.actions.getAddress(sha256) this.props.actions.getVerification(sha256) const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...initialState, ...citationState, - }) + ...address.paper, + } + this.setState(newState) } else if (verify && !verify.loading && verify.paper && (!oldPaper || oldPaper !== verify.paper)) { if (paper.error) { console.log('USING PAPER VERIFICATION') const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...initialState, ...citationState, - }) + ...address.paper, + } + this.setState(newState) } else { // console.log(paper) console.log('GOT CUSTOM CITATION STATE', paper) const citationState = this.getCitationState(sha256) - this.setState({ + newState = { ...citationState, + ...address.paper, uses_dataset: paper.uses_dataset === "TRUE", images_in_paper: paper.images_in_paper === "TRUE", verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, - }) + } + this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { const citationState = this.getCitationState(sha256) - this.setState(citationState) + newState = citationState + this.setState(newState) } } getCitationState(sha256) { const { paperInfo, unknownCitations } = this.props.api let citation = (unknownCitations.citations || []).find(f => f.id === sha256) - if (!citation) { + if (citation) { + citation.isUnknown = true + } else { citation = (paperInfo.citations || []).find(f => f.id === sha256) + if (citation) { + citation.isUnknown = false + } } // console.log(sha256, citation) let state = { citation } @@ -148,7 +166,7 @@ class PaperVerify extends Component { } render() { - let { paperInfo } = this.props.api + const { paperInfo, unknownCitations } = this.props.api if (paperInfo.loading) return // console.log(this.state) const { citation } = this.state @@ -185,6 +203,8 @@ class PaperVerify extends Component {
+ {this.renderLocationForm()} +
{'Uses dataset'} @@ -194,7 +214,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.YES || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.YES, })} @@ -207,7 +227,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.NO || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.NO, })} @@ -220,7 +240,7 @@ class PaperVerify extends Component { className='vetting' type='radio' name='uses_dataset' - checked={this.state.uses_dataset === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} + checked={parseInt(this.state.uses_dataset) === USES_DATASET.UNKNOWN || this.state.uses_dataset === "FALSE"} onChange={e => this.setState({ uses_dataset: USES_DATASET.UNKNOWN, })} @@ -230,8 +250,8 @@ class PaperVerify extends Component {
{'Paper shows images'} @@ -355,6 +375,22 @@ class PaperVerify extends Component {
) } + renderLocationForm() { + if (!this.state.citation.isUnknown) return + return ( +
+
+ + this.setState({ institution_1: e.target.value })} + /> +
+
+ ) + } } /* -- cgit v1.2.3-70-g09d2