Skip to content
Snippets Groups Projects
Commit 91d25c59 authored by Joseph Weston's avatar Joseph Weston
Browse files

update frontend for new PDF status display

parent 75eb394b
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import Hero from '../components/Hero'; ...@@ -4,6 +4,7 @@ import Hero from '../components/Hero';
import Footer from '../components/Footer'; import Footer from '../components/Footer';
import Dropzone from 'react-dropzone' import Dropzone from 'react-dropzone'
import Spinner from 'react-spinkit'
import * as api from '../api' import * as api from '../api'
...@@ -21,11 +22,13 @@ class Exams extends React.Component { ...@@ -21,11 +22,13 @@ class Exams extends React.Component {
pdfs: [], pdfs: [],
}, },
}; };
this.onDropYAML = this.onDropYAML.bind(this); this.onDropYAML = this.onDropYAML.bind(this);
this.onDropPDF = this.onDropPDF.bind(this); this.onDropPDF = this.onDropPDF.bind(this);
this.putYaml = this.putYaml.bind(this); this.putYaml = this.putYaml.bind(this);
this.updateYaml = this.updateYaml.bind(this); this.updateYaml = this.updateYaml.bind(this);
this.selectExam = this.selectExam.bind(this); this.selectExam = this.selectExam.bind(this);
this.pdfStatus= this.pdfStatus.bind(this);
} }
...@@ -44,9 +47,7 @@ class Exams extends React.Component { ...@@ -44,9 +47,7 @@ class Exams extends React.Component {
exams: [...prev.exams, new_exam], exams: [...prev.exams, new_exam],
})) }))
} }
this.setState(prev => ({ this.selectExam(new_exam.id)
selected_exam: Object.assign(prev.selected_exam, new_exam),
}))
alert('Thank you for your upload, it was delicious') alert('Thank you for your upload, it was delicious')
}) })
.catch(resp => { .catch(resp => {
...@@ -88,7 +89,18 @@ class Exams extends React.Component { ...@@ -88,7 +89,18 @@ class Exams extends React.Component {
) )
} }
pdfStatus(pdf) {
switch(pdf.status) {
case "processing":
const style = {display: "inline-block", top: "6px"}
return <div>{pdf.name} <Spinner name="circle" style={style} fadeIn='none'/> <i>{pdf.message}</i></div>
case "success":
return <div>{pdf.name} <i className="fa fa-check"></i>{pdf.message}</div>
case "error":
return <div>{pdf.name} <i className="fa fa-times"></i><i>{pdf.message}</i></div>
}
}
onDropPDF(accepted, rejected) { onDropPDF(accepted, rejected) {
if (rejected.length > 0) { if (rejected.length > 0) {
alert('Please upload a PDF..') alert('Please upload a PDF..')
...@@ -98,6 +110,12 @@ class Exams extends React.Component { ...@@ -98,6 +110,12 @@ class Exams extends React.Component {
data.append('pdf', accepted[0]) data.append('pdf', accepted[0])
api.post('pdfs/' + this.state.selected_exam.id, data) api.post('pdfs/' + this.state.selected_exam.id, data)
.then(() => { .then(() => {
api.get('pdfs/' + this.state.selected_exam.id)
.then(pdfs =>
this.setState(prev => ({
selected_exam: Object.assign(prev.selected_exam, {pdfs: pdfs})
}))
)
alert('Thank you for your upload, it was delicious') alert('Thank you for your upload, it was delicious')
}) })
.catch(resp => { .catch(resp => {
...@@ -221,7 +239,7 @@ class Exams extends React.Component { ...@@ -221,7 +239,7 @@ class Exams extends React.Component {
</p> </p>
<ul className="menu-list"> <ul className="menu-list">
{this.state.selected_exam.pdfs.map(pdf => {this.state.selected_exam.pdfs.map(pdf =>
<li>{pdf.name}</li> <li>{this.pdfStatus(pdf)}</li>
)} )}
</ul> </ul>
</aside> </aside>
......
...@@ -26,18 +26,14 @@ class Pdfs(Resource): ...@@ -26,18 +26,14 @@ class Pdfs(Resource):
name: str name: str
filename of the uploaded PDF filename of the uploaded PDF
""" """
return self._get(exam_id) return [
{
# Do not call this method without wrapping it in 'orm.db_session' 'id': 1,
def _get(self, exam_id): 'name': 'hello.pdf',
data_dir = app.config['DATA_DIRECTORY'] 'status': 'processing',
exam = Exam[exam_id] 'message': 'extracting images',
}
exam_data_dir = os.path.join(data_dir, f'{exam.name}_data') ]
pdfs = [pdf for pdf in os.listdir(exam_data_dir) if pdf.endswith('.pdf')]
return [{'name': pdf} for pdf in pdfs]
post_parser = reqparse.RequestParser() post_parser = reqparse.RequestParser()
post_parser.add_argument('pdf', type=FileStorage, required=True, post_parser.add_argument('pdf', type=FileStorage, required=True,
...@@ -51,6 +47,18 @@ class Pdfs(Resource): ...@@ -51,6 +47,18 @@ class Pdfs(Resource):
---------- ----------
exam_id : int exam_id : int
pdf : FileStorage pdf : FileStorage
Returns
-------
id : int
name : str
status : str
message : str
""" """
args = self.post_parser.parse_args() args = self.post_parser.parse_args()
# process PDF return {
'id': 1,
'name': 'hello.pdf',
'status': 'processing',
'message': 'going',
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment