From 7cac6c0b4ced39eca3531f8985549a93ae4cb266 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 18 Apr 2023 23:39:44 +1200 Subject: [PATCH 1/6] A warning symbol now displays next to the percentage. --- src/course-viewer/CourseViewerHeader.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/course-viewer/CourseViewerHeader.jsx b/src/course-viewer/CourseViewerHeader.jsx index e42b687..1cc7012 100644 --- a/src/course-viewer/CourseViewerHeader.jsx +++ b/src/course-viewer/CourseViewerHeader.jsx @@ -34,6 +34,7 @@ import { isMobile } from "react-device-detect"; import DeleteIcon from "@mui/icons-material/Delete"; import LaunchIcon from "@mui/icons-material/Launch"; import CourseViewerMobileActionButtons from "./CourseViewerMobileActionButtons"; +import WarningRoundedIcon from '@mui/icons-material/WarningRounded'; /** * The main header for the course viewer, changes based on @@ -119,13 +120,22 @@ const CurrentlyAchievedDisplay = (props) => { courseLetter, } = props; + let sum = courseData.assessments.map((assessment) => assessment.weight).reduce((a, b) => a + b, 0); + return ( Currently Achieved: - - + + + + {sum < 100 && ( + This course may have incomplete assessments as the weights don't add to 100} arrow> + } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} /> + + )} + From a20f18f5ca06c8a0341f1c691c9946fe872d84f6 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 24 Apr 2023 16:20:46 +1200 Subject: [PATCH 2/6] Added a dialog so mobile users can see the warning message on click --- src/course-viewer/CourseViewerHeader.jsx | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/course-viewer/CourseViewerHeader.jsx b/src/course-viewer/CourseViewerHeader.jsx index 1cc7012..188ce66 100644 --- a/src/course-viewer/CourseViewerHeader.jsx +++ b/src/course-viewer/CourseViewerHeader.jsx @@ -21,6 +21,9 @@ import { Box, Button, Chip, + Dialog, + DialogActions, + DialogContent, Divider, IconButton, Stack, @@ -121,6 +124,8 @@ const CurrentlyAchievedDisplay = (props) => { } = props; let sum = courseData.assessments.map((assessment) => assessment.weight).reduce((a, b) => a + b, 0); + + const [incompleteDialogOpen, setIncompleteDialogOpen] = React.useState(false); return ( @@ -131,9 +136,22 @@ const CurrentlyAchievedDisplay = (props) => { {sum < 100 && ( - This course may have incomplete assessments as the weights don't add to 100} arrow> - } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} /> - + <> + This course may have incomplete assessments as the weights don't add to 100} arrow> + } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} onClick={() => setIncompleteDialogOpen(true)} /> + + + + + + This course may have incomplete assessments as the weights don't add to 100. + + + + + + + )} From dcd89a6a13a2b5f2e8108a31b16495229d52c306 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 24 Apr 2023 16:59:15 +1200 Subject: [PATCH 3/6] Added a confirmation dialog when creating and updating --- src/course-manipulation/TemplateEditor.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/course-manipulation/TemplateEditor.jsx b/src/course-manipulation/TemplateEditor.jsx index 34fe470..3e3216b 100644 --- a/src/course-manipulation/TemplateEditor.jsx +++ b/src/course-manipulation/TemplateEditor.jsx @@ -74,6 +74,7 @@ const TemplateEditor = (props) => { const [errorText, setErrorText] = React.useState(""); const [loading, setLoading] = React.useState(false); const [closeDialog, setCloseDialog] = React.useState(false); + const [confirmDialog, setConfirmDialog] = React.useState(false); const [isKeyPress, setIsKeyPress] = React.useState(false); const openR = React.useRef(); openR.current = open; @@ -250,6 +251,7 @@ const TemplateEditor = (props) => { }); setLoading(false); + setConfirmDialog(false); }; /** @@ -288,6 +290,7 @@ const TemplateEditor = (props) => { }); setLoading(false); + setConfirmDialog(false); }; /** Closes the creator dialog. */ @@ -296,6 +299,14 @@ const TemplateEditor = (props) => { onClose(false, keyPressed); }, [isKeyPress, onClose]); + /** Checks if the assessment weights sum up to more than 100. */ + const needConfirmation = () => { + let sum = assessments.map((assessment) => assessment.weight).reduce((a, b) => parseFloat(a) + parseFloat(b), 0); + + if (sum < 100) setConfirmDialog(true); + else editCode !== "" ? updateCourse() : createCourse(); + } + /** * Closes the editor unless changes have been made in the * current editor session, in which case a confirmation dialog @@ -367,7 +378,7 @@ const TemplateEditor = (props) => { { editCode !== "" ? "Editing " + editCode : "Create New Course for Trimester " + activeTri.tri } - @@ -442,6 +453,10 @@ const TemplateEditor = (props) => { {setCloseDialog(false)}} buttonText={"Stop"} message={"Stop template creation?"} subMessage={"Any inputted data will be lost."} confirmAction={stopCreating} /> + + setConfirmDialog(false)} buttonText={"Proceed"} message={"Assessment weights"} + subMessage={"The assessment weights don't add up to 100. Are you sure you want to proceed?"} confirmAction={editCode !== "" ? updateCourse : createCourse} + /> setSnackbar("none")} anchorOrigin={{ vertical:"bottom", horizontal: isMobile ? "center" : "left" }} sx={{zIndex: 1, mb: !isMobile && editCode !== "" ? 10 : 0}} From 42284424e11ea0a3167433020a6274b5be41d849 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 25 Apr 2023 22:49:52 +1200 Subject: [PATCH 4/6] Updated so you can't click the icon on desktop --- src/course-viewer/CourseViewerHeader.jsx | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/course-viewer/CourseViewerHeader.jsx b/src/course-viewer/CourseViewerHeader.jsx index 188ce66..1ec2afb 100644 --- a/src/course-viewer/CourseViewerHeader.jsx +++ b/src/course-viewer/CourseViewerHeader.jsx @@ -136,22 +136,26 @@ const CurrentlyAchievedDisplay = (props) => { {sum < 100 && ( - <> - This course may have incomplete assessments as the weights don't add to 100} arrow> + isMobile ? ( + <> } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} onClick={() => setIncompleteDialogOpen(true)} /> + + + + + This course may have incomplete assessments as the weights don't add to 100. + + + + + + + + ) : ( + This course may have incomplete assessments as the weights don't add to 100} arrow> + } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} /> - - - - - This course may have incomplete assessments as the weights don't add to 100. - - - - - - - + ) )} From 5e132a828f43ea786dbd8a7fa80536a34b35e6e3 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 25 Apr 2023 22:56:30 +1200 Subject: [PATCH 5/6] Swapped dialog to use the ConfirmDialog --- src/course-viewer/CourseViewerHeader.jsx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/course-viewer/CourseViewerHeader.jsx b/src/course-viewer/CourseViewerHeader.jsx index 1ec2afb..7790d89 100644 --- a/src/course-viewer/CourseViewerHeader.jsx +++ b/src/course-viewer/CourseViewerHeader.jsx @@ -21,9 +21,6 @@ import { Box, Button, Chip, - Dialog, - DialogActions, - DialogContent, Divider, IconButton, Stack, @@ -31,6 +28,7 @@ import { Typography, } from "@mui/material"; +import ConfirmDialog from "../ConfirmDialog"; import dayjs from "dayjs"; import { isMobile } from "react-device-detect"; @@ -139,17 +137,10 @@ const CurrentlyAchievedDisplay = (props) => { isMobile ? ( <> } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} onClick={() => setIncompleteDialogOpen(true)} /> - - - - - This course may have incomplete assessments as the weights don't add to 100. - - - - - - + + setIncompleteDialogOpen(false)} buttonText={"Ok"} message={"Assessment weights"} + subMessage={"The assessment weights don't add up to 100. Are you sure you want to proceed?"} + /> ) : ( This course may have incomplete assessments as the weights don't add to 100} arrow> From 72f9697554dcf3330d01293a3922b058bd7825fe Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 25 Apr 2023 23:05:45 +1200 Subject: [PATCH 6/6] Updated dialog/ tooltip text --- src/course-manipulation/TemplateEditor.jsx | 2 +- src/course-viewer/CourseViewerHeader.jsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/course-manipulation/TemplateEditor.jsx b/src/course-manipulation/TemplateEditor.jsx index 3e3216b..acaca3d 100644 --- a/src/course-manipulation/TemplateEditor.jsx +++ b/src/course-manipulation/TemplateEditor.jsx @@ -455,7 +455,7 @@ const TemplateEditor = (props) => { /> setConfirmDialog(false)} buttonText={"Proceed"} message={"Assessment weights"} - subMessage={"The assessment weights don't add up to 100. Are you sure you want to proceed?"} confirmAction={editCode !== "" ? updateCourse : createCourse} + subMessage={"The assessment weights don't add up to 100%. Are you sure you want to proceed?"} confirmAction={editCode !== "" ? updateCourse : createCourse} /> setSnackbar("none")} diff --git a/src/course-viewer/CourseViewerHeader.jsx b/src/course-viewer/CourseViewerHeader.jsx index 7790d89..ce859fa 100644 --- a/src/course-viewer/CourseViewerHeader.jsx +++ b/src/course-viewer/CourseViewerHeader.jsx @@ -139,11 +139,11 @@ const CurrentlyAchievedDisplay = (props) => { } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} onClick={() => setIncompleteDialogOpen(true)} /> setIncompleteDialogOpen(false)} buttonText={"Ok"} message={"Assessment weights"} - subMessage={"The assessment weights don't add up to 100. Are you sure you want to proceed?"} + subMessage={"The assessment weights don't add up to 100%. This likely means that the course may have incomplete assessments."} /> ) : ( - This course may have incomplete assessments as the weights don't add to 100} arrow> + The assessment weights don't add up to 100%. This likely means that the course may have incomplete assessments.} arrow> } color="secondary" sx={{ py: 3, fontSize:30, backgroundColor:"error.main", borderRadius: 1 }} /> )