diff options
| author | adamhrv <adam@ahprojects.com> | 2019-03-28 20:01:11 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-03-28 20:01:11 +0100 |
| commit | 21fd4284ac0f14ec860ccda1032ef380ccfa7b2f (patch) | |
| tree | 6751b86621a1ad76ebab1ffe9f0d1a6ab053bacc /scraper/client/paper/paper.verify.js | |
| parent | b2c61d7ebc142b41f8cb15b00764319801d1bf5d (diff) | |
| parent | 5309b381e64f59b8f57014ad41e55d7f87ca0628 (diff) | |
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'scraper/client/paper/paper.verify.js')
| -rw-r--r-- | scraper/client/paper/paper.verify.js | 142 |
1 files changed, 113 insertions, 29 deletions
diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 65342adf..f5dbc13c 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -4,18 +4,27 @@ import { connect } from 'react-redux' import * as actions from '../actions' import { history } from '../store' -import { Loader } from '../common' +import { Loader, Autocomplete } from '../common' 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, + institution_1: '', + institution_2: '', + institution_3: '', + validate_1: false, + validate_2: false, + validate_3: false, } class PaperVerify extends Component { @@ -26,6 +35,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 +44,67 @@ 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, - uses_dataset: paper.uses_dataset === "TRUE", - images_in_paper: paper.images_in_paper === "TRUE", + ...address.paper, + uses_dataset: paper.uses_dataset, + images_in_paper: paper.images_in_paper, verified_by: paper.verified_by, reference: paper.reference, notes: paper.notes, - }) + } + this.setState(newState) } } else if (oldProps.api.unknownCitations !== this.props.api.unknownCitations) { + console.log('loaded unknown citations') 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 } @@ -107,15 +132,23 @@ class PaperVerify extends Component { reference: this.state.reference, notes: this.state.notes, date: dateString, + isUnknown: this.state.citation.isUnknown, + institution_1: this.state.institution_1, + validate_1: this.state.validate_1, + institution_2: this.state.institution_2, + validate_2: this.state.validate_2, + institution_3: this.state.institution_3, + validate_3: this.state.validate_3, }) - this.next(false) + this.next() } prev() { const { key } = this.props.api.paperInfo.dataset - const { paperInfo } = this.props.api - let citationIndex = (paperInfo.citations || []) - .findIndex(f => f.id === this.state.citation.id) + const { paperInfo, sortedCitations } = this.props.api + const citations = sortedCitations || paperInfo.citations || [] + let citationIndex = citations.findIndex(f => f.id === this.state.citation.id) + if (citationIndex === -1) { history.push('/paper/' + key + '/info/') } else { @@ -123,7 +156,7 @@ class PaperVerify extends Component { if (citationIndex < 0) { history.push('/paper/' + key + '/info/') } else { - let nextId = paperInfo.citations[citationIndex].id + let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } @@ -131,24 +164,25 @@ class PaperVerify extends Component { next() { const { key } = this.props.api.paperInfo.dataset - const { paperInfo } = this.props.api - let citationIndex = (paperInfo.citations || []) - .findIndex(f => f.id === this.state.citation.id) + const { paperInfo, sortedCitations } = this.props.api + const citations = sortedCitations || paperInfo.citations || [] + let citationIndex = citations.findIndex(f => f.id === this.state.citation.id) + if (citationIndex === -1) { history.push('/paper/' + key + '/info/') } else { citationIndex += 1 - if (citationIndex >= paperInfo.citations.length) { + if (citationIndex >= citations.length) { history.push('/paper/' + key + '/info/') } else { - let nextId = paperInfo.citations[citationIndex].id + let nextId = citations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } } render() { - let { paperInfo } = this.props.api + const { paperInfo, unknownCitations } = this.props.api if (paperInfo.loading) return <Loader /> // console.log(this.state) const { citation } = this.state @@ -185,6 +219,8 @@ class PaperVerify extends Component { </a> </div> + {this.renderLocationForm()} + <div className='row vettingRow'> <div className='rowHeading'> {'Uses dataset'} @@ -194,7 +230,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={String(this.state.uses_dataset) === USES_DATASET.YES} onChange={e => this.setState({ uses_dataset: USES_DATASET.YES, })} @@ -207,7 +243,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={String(this.state.uses_dataset) === USES_DATASET.NO} onChange={e => this.setState({ uses_dataset: USES_DATASET.NO, })} @@ -220,7 +256,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={String(this.state.uses_dataset) !== USES_DATASET.YES && String(this.state.uses_dataset) !== USES_DATASET.NO} onChange={e => this.setState({ uses_dataset: USES_DATASET.UNKNOWN, })} @@ -230,8 +266,8 @@ class PaperVerify extends Component { </div> <div - className={this.state.uses_dataset === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} - disabled={this.state.uses_dataset === USES_DATASET.YES ? false : true} + className={String(this.state.uses_dataset) === USES_DATASET.YES ? 'row vettingRow' : 'row vettingRow disabled'} + disabled={String(this.state.uses_dataset) === USES_DATASET.YES ? false : true} > <div className='rowHeading'> {'Paper shows images'} @@ -355,6 +391,54 @@ class PaperVerify extends Component { </div> ) } + renderLocationForm() { + if (!this.state.citation.isUnknown) return + return ( + <div> + <div className='param'> + <label>Institution #1</label> + <Autocomplete + placeholder='Institution #1' + value={this.state.institution_1} + onSelect={(institution_1, validate_1) => { + this.setState({ institution_1, validate_1 }) + }} + onCancel={value => { + this.setState({ institution_1: '', validate_1: false }) + }} + /> + </div> + + <div className='param'> + <label>Institution #2</label> + <Autocomplete + placeholder='Institution #2' + value={this.state.institution_2} + onSelect={(institution_2, validate_2) => { + this.setState({ institution_2, validate_2 }) + }} + onCancel={value => { + this.setState({ institution_2: '', validate_2: false }) + }} + /> + </div> + + <div className='param'> + <label>Institution #3</label> + <Autocomplete + placeholder='Institution #3' + value={this.state.institution_3} + onSelect={(institution_3, validate_3) => { + this.setState({ institution_3, validate_3 }) + }} + onCancel={value => { + this.setState({ institution_3: '', validate_3: false }) + }} + /> + </div> + </div> + ) + } } /* |
