Skip to content

Commit

Permalink
ADD autograde results download button
Browse files Browse the repository at this point in the history
  • Loading branch information
wabscale committed Feb 20, 2022
1 parent a7ea596 commit eb58135
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 18 additions & 2 deletions web/src/pages/core/admin/Autograde/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import AutogradeVisuals from '../../../../components/core/Visuals/AutogradeVisua
import Button from '@material-ui/core/Button';
import RefreshIcon from '@material-ui/icons/Refresh';
import ArchiveIcon from '@material-ui/icons/Archive';
import downloadTextFile from '../../../../utils/downloadTextFile';
import {nonStupidDatetimeFormat} from '../../../../utils/datetime';

const useStyles = makeStyles((theme) => ({
paper: {
Expand Down Expand Up @@ -96,8 +98,6 @@ export default function Results() {
const [stats, setStats] = useState([]);
const [rows, setRows] = useState([]);
const [loading, setLoading] = useState(true);
const [pageSize, setPageSize] = useState(10);
const [page, setPage] = useState(0);
const [selected, setSelected] = useState(null);
const [searched, setSearched] = useState(null);
const [error, setError] = useState(null);
Expand Down Expand Up @@ -230,6 +230,22 @@ export default function Results() {
</Button>
</Grid>

{/* Reset questions icon */}
<Grid item>
<Button
startIcon={<ArchiveIcon/>}
color={'primary'}
variant={'contained'}
onClick={() => downloadTextFile(
`anubis-autograde-${assignment?.course_id}-${assignment?.name}-${nonStupidDatetimeFormat(new Date())}.json`,
JSON.stringify(stats),
'application/json',
)}
>
Autograde Data
</Button>
</Grid>

</Grid>
</Grid>
<Grid item xs={12}>
Expand Down
3 changes: 3 additions & 0 deletions web/src/utils/downloadTextFile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default function downloadTextFile(filename, text, content_type) {
filename = filename.replaceAll(/:/g, '');
filename = filename.replaceAll(/ /g, '-');
filename = filename.toLowerCase();
const element = document.createElement('a');
element.hidden = true;
const file = new Blob([text], {type: content_type});
Expand Down

0 comments on commit eb58135

Please sign in to comment.