Commit 11daeefe authored by Thomas Roos's avatar Thomas Roos

Manual cleanups according to standard style

parent fd12d725
......@@ -3,7 +3,6 @@ import EmptyPDF from '../components/EmptyPDF.jsx'
import { Document, Page } from 'react-pdf'
// worker is prefered but need to convince webpack to cooperate
/* global PDFJS */
PDFJS.workerSrc = true
class GeneratedExamPreview extends React.Component {
......
......@@ -53,13 +53,13 @@ const GraderDropdown = (props) => (
)
const ExportDropdown = (props) => {
const export_formats = [
const exportFormats = [
{label: 'Excel Spreadsheet', format: 'xlsx'},
{label: 'Detailed Excel Spreadsheet', format: 'xlsx_detailed'},
{label: 'Pandas Dataframe', format: 'dataframe'}
]
const export_url = format => `/api/export/${format}/${props.exam.id}`
const exportUrl = format => `/api/export/${format}/${props.exam.id}`
return (
<div className='navbar-item has-dropdown is-hoverable' style={props.style}>
......@@ -67,11 +67,11 @@ const ExportDropdown = (props) => {
Export
</div>
<div className='navbar-dropdown'>
{export_formats.map((export_format, i) =>
{exportFormats.map((exportFormat, i) =>
<a className='navbar-item'
href={export_url(export_format.format)}
href={exportUrl(exportFormat.format)}
key={i}>
{export_format.label}
{exportFormat.label}
</a>
)}
<hr className='navbar-divider' />
......
......@@ -50,7 +50,6 @@ class PanelGenerate extends React.Component {
copies_start: this.state.copyRangeStart,
copies_end: this.state.copyRangeEnd
}
const type = this.state.type
this.setState({
isGenerating: true
}, () => {
......
......@@ -3,7 +3,7 @@ import 'font-awesome/css/font-awesome.css'
import React from 'react'
import ReactDOM from 'react-dom'
import Loadable from 'react-loadable'
import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom'
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
import * as api from './api.jsx'
......@@ -73,7 +73,7 @@ class App extends React.Component {
}))
}
updateSubmission = (index, sub) => {
if (index == undefined) {
if (index === undefined) {
api.get('submissions/' + this.state.exam.id)
.then(subs => this.setState({
exam: {
......@@ -83,7 +83,7 @@ class App extends React.Component {
}))
} else {
if (sub) {
if (JSON.stringify(sub) != JSON.stringify(this.state.exam.submissions[index])) {
if (JSON.stringify(sub) !== JSON.stringify(this.state.exam.submissions[index])) {
let newList = this.state.exam.submissions
newList[index] = sub
this.setState({
......@@ -96,7 +96,7 @@ class App extends React.Component {
} else {
api.get('submissions/' + this.state.exam.id + '/' + this.state.exam.submissions[index].id)
.then(sub => {
if (JSON.stringify(sub) != JSON.stringify(this.state.exam.submissions[index])) {
if (JSON.stringify(sub) !== JSON.stringify(this.state.exam.submissions[index])) {
let newList = this.state.exam.submissions
newList[index] = sub
this.setState({
......
import React from 'react'
import Dropzone from 'react-dropzone'
import { Document, Page } from 'react-pdf'
import * as api from '../api.jsx'
import Hero from '../components/Hero.jsx'
import DropzoneContent from '../components/DropzoneContent.jsx'
import { Document, Page } from 'react-pdf'
// worker is prefered but need to convince webpack to cooperate
PDFJS.workerSrc = true
import * as api from '../api.jsx'
class Exams extends React.Component {
state = {
pdf: null,
......@@ -49,7 +48,7 @@ class Exams extends React.Component {
alert('Please upload a PDF.')
return
}
const data = new FormData()
const data = new window.FormData()
data.append('pdf', this.state.pdf)
data.append('exam_name', this.state.exam_name)
api.post('exams', data)
......
......@@ -22,7 +22,7 @@ class Exams extends React.Component {
}
static getDerivedStateFromProps = (newProps, prevState) => {
if (newProps.exam.id != prevState.examID) {
if (newProps.exam.id !== prevState.examID) {
// initialize array to size of pdf
const widgets = []
newProps.exam.problems.forEach(problem => {
......
......@@ -23,7 +23,7 @@ class ExamEditor extends React.Component {
getPDFUrl = () => {
let whichPDF = this.props.finalized ? 'preview' : 'source_pdf'
return this.props.examID && `/api/exams/${this.props.examID}/${whichPDF}` || null
return this.props.examID >= 0 ? `/api/exams/${this.props.examID}/${whichPDF}` : null
}
getCoordinatesForEvent = (e) => {
......@@ -90,7 +90,7 @@ class ExamEditor extends React.Component {
width: Math.round(selectionBox.width),
height: Math.round(selectionBox.height)
}
const formData = new FormData()
const formData = new window.FormData()
formData.append('exam_id', this.props.examID)
formData.append('name', problemData.name)
formData.append('page', problemData.page)
......@@ -169,11 +169,11 @@ class ExamEditor extends React.Component {
// Only render when numPage is set
if (this.props.numPages !== null && this.props.widgets) {
const widgets = this.props.widgets.filter(widget => {
if (widget.name == 'student_id_widget' ||
widget.name == 'barcode_widget') {
if (widget.name === 'student_id_widget' ||
widget.name === 'barcode_widget') {
return !this.props.finalized
} else if (widget.problem) {
return widget.problem.page == this.props.page
return widget.problem.page === this.props.page
} else {
return true
}
......@@ -184,7 +184,7 @@ class ExamEditor extends React.Component {
let view
let enableResizing
return widgets.map((widget) => {
const isSelected = widget.id == this.props.selectedWidgetId
const isSelected = widget.id === this.props.selectedWidgetId
if (widget.problem) {
minWidth = this.props.problemMinWidth
......@@ -197,11 +197,11 @@ class ExamEditor extends React.Component {
enableResizing = true
} else {
let image
if (widget.name == 'barcode_widget') {
if (widget.name === 'barcode_widget') {
minWidth = barcodeExampleImageSize.width
minHeight = barcodeExampleImageSize.height
image = barcodeExampleImage
} else if (this.props.page == 0 && widget.name == 'student_id_widget') {
} else if (this.props.page === 0 && widget.name === 'student_id_widget') {
minWidth = studentIdExampleImageSize.width
minHeight = studentIdExampleImageSize.height
image = studentIdExampleImage
......@@ -296,7 +296,7 @@ class ExamEditor extends React.Component {
render = () => {
return (
<div
ref={c => this.selectionArea = c}
ref={c => (this.selectionArea = c)}
className='selection-area'
>
<Document
......
......@@ -115,7 +115,7 @@ class Grade extends React.Component {
}
static getDerivedStateFromProps = (newProps, prevState) => {
if (newProps.exam.id != prevState.examID && newProps.exam.submissions.length) {
if (newProps.exam.id !== prevState.examID && newProps.exam.submissions.length) {
return {
input: Grade.inputString(newProps.exam.submissions[0]),
sIndex: 0,
......
......@@ -40,7 +40,7 @@ class CheckStudents extends React.Component {
}
static getDerivedStateFromProps = (newProps, prevState) => {
if (newProps.exam.id != prevState.examID && newProps.exam.submissions.length) {
if (newProps.exam.id !== prevState.examID && newProps.exam.submissions.length) {
return {
input: newProps.exam.submissions[0].id,
index: 0,
......@@ -153,8 +153,6 @@ class CheckStudents extends React.Component {
width: '5em'
}
const maxSubmission = Math.max(...this.props.exam.submissions.map(o => o.id))
const subm = this.props.exam.submissions[this.state.index]
return (
......
......@@ -37,7 +37,7 @@ class Submissions extends React.Component {
updateScans = () => {
api.get('scans/' + this.props.exam.id)
.then(scans => {
if (JSON.stringify(scans) != JSON.stringify(this.state.scans)) {
if (JSON.stringify(scans) !== JSON.stringify(this.state.scans)) {
this.setState({
scans: scans
})
......@@ -66,7 +66,7 @@ class Submissions extends React.Component {
return
}
accepted.map(file => {
const data = new FormData()
const data = new window.FormData()
data.append('pdf', file)
api.post('scans/' + this.props.exam.id, data)
.then(() => {
......@@ -85,7 +85,7 @@ class Submissions extends React.Component {
// has been solved. This is a
api.get('students')
.then(students => {
if (students.length == 0) {
if (students.length === 0) {
alert('You have not yet uploaded any students. ' +
"If you don't upload students before the scans " +
"then we can't automatically assign students " +
......@@ -99,16 +99,16 @@ class Submissions extends React.Component {
}
render () {
const missing_submissions = this.state.submissions.filter(s => s.missing.length > 0)
const missingSubmissions = this.state.submissions.filter(s => s.missing.length > 0)
const missing_submissions_status = (
missing_submissions.length > 0
const missingSubmissionsStatus = (
missingSubmissions.length > 0
? <div>
<p className='menu-label'>
Missing Pages
</p>
<ul className='menu-list'>
{missing_submissions.map(sub =>
{missingSubmissions.map(sub =>
<li key={sub.id}>
Copy {sub.id} is missing pages {sub.missing.join(',')}
</li>
......@@ -143,7 +143,7 @@ class Submissions extends React.Component {
Uploaded submissions: {this.state.submissions.length}
</p>
{missing_submissions_status}
{missingSubmissionsStatus}
<p className='menu-label'>
Upload History
......
import React from 'react'
import * as api from '../../api.jsx'
import { startOfToday } from 'date-fns'
const BackButton = (props) => (
<button className='button is-light is-fullwidth' onClick={props.onClick}>
......
......@@ -12,7 +12,7 @@ class FeedbackPanel extends React.Component {
}
static getDerivedStateFromProps (nextProps, prevState) {
if (prevState.problemID != nextProps.problem.id || prevState.submissionID != nextProps.submissionID) {
if (prevState.problemID !== nextProps.problem.id || prevState.submissionID !== nextProps.submissionID) {
return {
remark: nextProps.solution.remark,
problemID: nextProps.problem.id,
......
......@@ -114,7 +114,7 @@ class EditPanel extends React.Component {
return
}
accepted.map(file => {
const data = new FormData()
const data = new window.FormData()
data.append('csv', file)
api.post('students', data)
.then(() => {
......
......@@ -63,8 +63,8 @@ class SearchPanel extends React.Component {
event.preventDefault()
let sel = this.state.selected
if (event.keyCode == 38 && sel > 0) sel--
if (event.keyCode == 40 && sel < this.state.result.length - 1) sel++
if (event.keyCode === 38 && sel > 0) sel--
if (event.keyCode === 40 && sel < this.state.result.length - 1) sel++
this.setState({
...this.state,
......@@ -84,7 +84,7 @@ class SearchPanel extends React.Component {
if (event.target.selected) {
this.props.matchStudent(this.state.result[this.state.selected])
} else {
const index = this.state.result.findIndex(result => result.id == event.target.id)
const index = this.state.result.findIndex(result => result.id === event.target.id)
this.setState({
...this.state,
selected: index
......@@ -93,7 +93,7 @@ class SearchPanel extends React.Component {
}
static getDerivedStateFromProps = (nextProps, prevState) => {
if (prevState.subIndex != nextProps.subIndex) {
if (prevState.subIndex !== nextProps.subIndex) {
return {
input: '',
selected: 0,
......
......@@ -12,7 +12,7 @@
},
"standard": {
"parser": "babel-eslint",
"globals": [ "__COMMIT_HASH__", "alert" ]
"globals": [ "__COMMIT_HASH__", "alert", "confirm", "PDFJS" ]
},
"dependencies": {
"babel-plugin-syntax-dynamic-import": "^6.18.0",
......
......@@ -11,7 +11,7 @@ module.exports = merge(common, {
mode: 'development',
module: {
rules: [
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ] }
]
},
devServer: {
......
......@@ -15,7 +15,7 @@ module.exports = merge(common, {
mode: 'production',
module: {
rules: [
{ test: /\.css$/, use: [ MiniCssExtractPlugin.loader, 'css-loader' ]}
{ test: /\.css$/, use: [ MiniCssExtractPlugin.loader, 'css-loader' ] }
]
},
devtool: 'source-map',
......@@ -29,7 +29,7 @@ module.exports = merge(common, {
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.optimize\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: {removeAll: true } },
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: true
})
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment