Skip to content

Commit

Permalink
Merge pull request #268 from cmu15122/preview
Browse files Browse the repository at this point in the history
Merge slight color update and cooldown override toggle
  • Loading branch information
jacksontromero authored Apr 1, 2024
2 parents 28a0f85 + c04924a commit 4d43436
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 54 deletions.
80 changes: 49 additions & 31 deletions client/src/components/home/shared/CooldownViolationOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,59 @@ export default function CooldownViolationOverlay(props) {

const {queueData} = useContext(QueueDataContext);
function callAddQuestionAPIOverrideCooldown() {
HomeService.addQuestion(
JSON.stringify({
andrewID: andrewID,
question: question,
location: location,
topic: topic,
overrideCooldown: true,
}),
).then((res) => {
if (res.status === 200) {
setOpen(false);
}
});
if (queueData.allowCDOverride) {
HomeService.addQuestion(
JSON.stringify({
andrewID: andrewID,
question: question,
location: location,
topic: topic,
overrideCooldown: true,
}),
).then((res) => {
if (res.status === 200) {
setOpen(false);
}
});
} else return;
}

return (
<Dialog open={open} maxWidth="sm" fullWidth>
<DialogContent sx={{p: 5, textAlign: 'center'}} >
<Typography variant='h6' textAlign='center'>
You rejoined the queue too quickly! Please wait for {queueData.rejoinTime} minutes after finishing your last question, which will be in {queueData.rejoinTime - timePassed} minutes.
</Typography>
if (queueData.allowCDOverride) {
return (
<Dialog open={open} maxWidth="sm" fullWidth>
<DialogContent sx={{p: 5, textAlign: 'center'}} >
<Typography variant='h6' textAlign='center'>
You rejoined the queue too quickly! Please wait for {queueData.rejoinTime} minutes after finishing your last question, which will be in {queueData.rejoinTime - timePassed} minutes.
</Typography>

<Stack alignItems="baseline" justifyContent="space-around" direction="row" spacing={3}>
<Button onClick={() => callAddQuestionAPIOverrideCooldown()} color='error' fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Override Cooldown
</Button>
<Stack alignItems="baseline" justifyContent="space-around" direction="row" spacing={3}>
<Button onClick={() => callAddQuestionAPIOverrideCooldown()} color='error' fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Override Cooldown
</Button>
<Button onClick={() => setOpen(false)} style={{background: theme.alternateColors.cancel}} fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Close
</Button>
</Stack>

<Typography lineHeight={1.3} variant='subtitle1' textAlign='center' sx={{mt: 3}}>
Overriding the cooldown will add you to the queue, however you will be frozen until a TA approves you.
</Typography>
</DialogContent>
</Dialog>
);
} else {
return (
<Dialog open={open} maxWidth="sm" fullWidth>
<DialogContent sx={{p: 5, textAlign: 'center'}} >
<Typography variant='h6' textAlign='center'>
You rejoined the queue too quickly! Please wait for {queueData.rejoinTime} minutes after finishing your last question, which will be in {queueData.rejoinTime - timePassed} minutes.
</Typography>
<Button onClick={() => setOpen(false)} style={{background: theme.alternateColors.cancel}} fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Close
</Button>
</Stack>

<Typography lineHeight={1.3} variant='subtitle1' textAlign='center' sx={{mt: 3}}>
Overriding the cooldown will add you to the queue, however you will be frozen until a TA approves you.
</Typography>
</DialogContent>
</Dialog>
);
</DialogContent>
</Dialog>
);
}
}

5 changes: 3 additions & 2 deletions client/src/components/home/student/YourEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default function YourEntry(props) {
const {queueData} = useContext(QueueDataContext);
const {studentData} = useContext(StudentDataContext);

const cooldownMsg = queueData.allowCDOverride ? 'You have been frozen in line. This means you will not advance in the queue until a TA approves your entry.' : 'You have been frozen in line. You will not advance in the queue! Please wait for your cooldown to end before joining the queue again.';

return (
<BaseCard>
<CardContent sx={{m: 1, textAlign: 'left'}}>
Expand All @@ -41,8 +43,7 @@ export default function YourEntry(props) {
<Stack direction='row' display='flex' alignItems='center'>
<PauseIcon color='error' sx={{pr: 1}} />
<Typography color='error' sx={{fontWeight: 'bold'}}>
You have been frozen in line. This means you will not advance in the queue
until a TA approves your entry.
{cooldownMsg}
</Typography>
</Stack>
</div>
Expand Down
10 changes: 9 additions & 1 deletion client/src/components/home/ta/EntryTails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import StudentStatus from './TailOptions/StudentStatus';
import LeapStudentActions from './TailOptions/LeapStudentActions';

import {StudentStatusValues} from '../../../services/StudentStatus';
import PersistentOptions from './TailOptions/PersistentOptions';

export default function EntryTails(props) {
const {student, index, isHelping, helpIdx} = props;

const showApproval = props.showCooldownApproval;

const status = student.status;

const themeHook = useTheme();
Expand All @@ -30,8 +33,13 @@ export default function EntryTails(props) {
case StudentStatusValues.WAITING: return (ActionsHelp(props));
case StudentStatusValues.FIXING_QUESTION: return (ActionsHelp(props));
case StudentStatusValues.FROZEN: return (ActionsFreeze(props));
case StudentStatusValues.COOLDOWN_VIOLATION: return (LeapStudentActions(props));
case StudentStatusValues.RECEIVED_MESSAGE: return (ActionsHelp(props));
case StudentStatusValues.COOLDOWN_VIOLATION:
if (showApproval) {
return (LeapStudentActions(props));
} else {
return (ActionsHelp({...props, color: 'secondary'}));
}
default: return;
}
};
Expand Down
14 changes: 12 additions & 2 deletions client/src/components/home/ta/StudentEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState, useEffect, useRef} from 'react';
import React, {useState, useEffect, useRef, useContext} from 'react';
import {
Stack, TableCell, Typography,
} from '@mui/material';
Expand All @@ -7,16 +7,21 @@ import PauseIcon from '@mui/icons-material/Pause';
import EntryTails from './EntryTails';
import ItemRow from '../../common/table/ItemRow';

import {QueueDataContext} from '../../../contexts/QueueDataContext';

import HomeService from '../../../services/HomeService';
import {StudentStatusValues} from '../../../services/StudentStatus';
import {Settings} from '@mui/icons-material';
import {debug} from 'util';

export default function StudentEntry(props) {
const {queueData} = useContext(QueueDataContext);
const {student, index, handleClickHelp, removeStudent, handleClickUnfreeze} = props;

const [confirmRemove, setConfirmRemove] = useState(false);
const removeRef = useRef();

const [showCooldownApproval, setShowCooldownApproval] = useState(student['status'] === StudentStatusValues.COOLDOWN_VIOLATION);
const [showCooldownApproval, setShowCooldownApproval] = useState(queueData.allowCDOverride && student['status'] === StudentStatusValues.COOLDOWN_VIOLATION);

useEffect(() => {
const closeExpanded = (e) => {
Expand All @@ -32,6 +37,11 @@ export default function StudentEntry(props) {
};
}, []);

// Update showCooldownApproval when allowCDOverride changes
useEffect(() => {
setShowCooldownApproval(queueData.allowCDOverride && student['status'] === StudentStatusValues.COOLDOWN_VIOLATION);
}, [queueData.allowCDOverride, student['status']]);

function handleRemoveButton() {
if (confirmRemove) {
setConfirmRemove(false);
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/home/ta/TailOptions/ActionsHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export default function ActionsHelp(props) {
student, index, isHelping, handleClickHelp,
} = props;

const buttonColor = props.color == null ? 'info' : props.color;

return (
<Stack
direction={{xs: 'column', sm: 'row'}}
sx={{alignItems: 'center', justifyContent: 'flex-end'}}
>
<Button disabled={student.status === StudentStatusValues.BEING_HELPED || isHelping} color="info" variant="contained" onClick={() => handleClickHelp(index)} sx={{m: 0.5}}>
<Button disabled={student.status === StudentStatusValues.BEING_HELPED || isHelping} color={buttonColor} variant="contained" onClick={() => handleClickHelp(index)} sx={{m: 0.5}}>
Help
</Button>
{PersistentOptions(props)}
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/metrics/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export default function Graph() {
label: 'Number of Students',
data: numStudentsPerDayLastWeek.map((day) => day.students),
fill: false,
backgroundColor: theme.palette.primary.main,
borderColor: theme.palette.primary.main,
backgroundColor: theme.palette.secondary.main,
borderColor: theme.palette.secondary.main,
borderWidth: 3,
tension: 0.3,
},
Expand Down Expand Up @@ -172,8 +172,8 @@ export default function Graph() {
label: 'Number of Students',
data: numStudentsOverall.map((day) => day.students),
fill: false,
backgroundColor: theme.palette.primary.main,
borderColor: theme.palette.primary.main,
backgroundColor: theme.palette.secondary.main,
borderColor: theme.palette.secondary.main,
borderWidth: 3,
tension: 0.3,
},
Expand Down Expand Up @@ -239,8 +239,8 @@ export default function Graph() {
{
label: 'Number of Students',
data: numStudentsPerDay.map((day) => day.students),
backgroundColor: theme.palette.primary.main,
borderColor: theme.palette.primary.main,
backgroundColor: theme.palette.secondary.main,
borderColor: theme.palette.secondary.main,
borderWidth: 3,
},
],
Expand Down
34 changes: 33 additions & 1 deletion client/src/components/settings/admin/ConfigSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ export default function ConfigSettings(props) {
const [slackURL, setSlackURL] = useState('');
const [questionsURL, setQuestionsURL] = useState('');
const [enforceCMUEmail, setEnforceCMUEmail] = useState(true);
const [allowCDOverride, setAllowCDOverride] = useState(true);

useEffect(() => {
setCurrSem(adminSettings.currSem);
setSlackURL(adminSettings.slackURL);
setEnforceCMUEmail(adminSettings.enforceCMUEmail);
}, [adminSettings]);
useEffect(() => {
setAllowCDOverride(queueData.allowCDOverride);
setQuestionsURL(queueData.questionsURL);
}, [adminSettings, queueData]);
}, [queueData]);

const handleUpdateSemester = (event) => {
event.preventDefault();
Expand Down Expand Up @@ -72,6 +76,16 @@ export default function ConfigSettings(props) {
);
};

const handleCooldownOverrideEnabled = (event) => {
event.preventDefault();

SettingsService.updateAllowCDOverride(
JSON.stringify({
allowCDOverride: allowCDOverride,
}),
);
};

return (
<BaseCard>
<CardContent>
Expand Down Expand Up @@ -117,6 +131,24 @@ export default function ConfigSettings(props) {
</Grid>
</Grid>
</form>
<form onSubmit={handleCooldownOverrideEnabled}>
<Grid container spacing={2} sx={{mb: 2}}>
<Grid className="d-flex" item sx={{mt: 1, ml: 1}}>
Allow Cooldown Override:
<Checkbox
size="small"
sx={{ml: 1}}
checked={allowCDOverride}
onChange={(e) => {
setAllowCDOverride(e.target.checked);
}}
/>
</Grid>
<Grid className="d-flex" item sx={{mt: 1, mr: 2}}>
<Button type="submit" variant="contained">Save</Button>
</Grid>
</Grid>
</form>
<form onSubmit={handleUpdateSlackURL}>
<Grid container spacing={2} sx={{mt: 1, mb: 2}}>
<Grid className="d-flex" item sx={{mx: 1}} xs={10}>
Expand Down
1 change: 1 addition & 0 deletions client/src/contexts/QueueDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const QueueDataContextProvider = ({children}: {children: React.ReactNode}) => {
title: '15-122 Office Hours Queue',
uninitializedSem: false,
queueFrozen: true,
allowCDOverride: true,

numStudents: 0,
rejoinTime: 15,
Expand Down
3 changes: 3 additions & 0 deletions client/src/services/SettingsService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class SettingsDataService {
updateEnforceCmuEmail(data) {
return http.post('/settings/config/enforcecmuemail/update', data);
}
updateAllowCDOverride(data) {
return http.post('/settings/config/allowcdoverride/update', data);
}
updatePreferredName(data) {
return http.post('/settings/preferredname/update', data);
}
Expand Down
14 changes: 7 additions & 7 deletions client/src/themes/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const lightTheme = createTheme({
mode: 'light',
primary: {
// main: '#EF8EC3',
main: '#015122',
main: '#014122',
},
secondary: {
main: '#EA3947',
main: '#f4cd2a',
},
success: {
main: '#43a047',
Expand All @@ -49,7 +49,7 @@ const lightTheme = createTheme({
cancel: '#9e9e9e',
unfreeze: '#ba68c8',
// navbar: '#EF8EC3',
navbar: '#015122',
navbar: '#014122',
},
components: {
MuiButton: {
Expand Down Expand Up @@ -121,10 +121,10 @@ const darkTheme = createTheme({
mode: 'dark',
primary: {
// main: '#EF8EC3',
main: '#015122',
main: '#014122',
},
secondary: {
main: '#e8152e',
main: '#f4cd2a',
},
success: {
main: '#09e312',
Expand All @@ -142,12 +142,12 @@ const darkTheme = createTheme({
},
alternateColors: {
// darkerPrimary: '#e36bac',
darkerPrimary: '#013122',
darkerPrimary: '#014122',
alternatePaper: '#575757',
cancel: '#9e9e9e',
unfreeze: '#ba68c8',
// navbar: '#e36bac',
navbar: '#013122',
navbar: '#014122',
},
components: {
MuiButton: {
Expand Down
13 changes: 12 additions & 1 deletion server/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function buildQueueData() {
title: "15-122 Office Hours Queue",
uninitializedSem: adminSettings.currSem == null,
queueFrozen: queueFrozen,
allowCDOverride: adminSettings.allowCDOverride,

// global stats
numStudents: ohq.size(),
Expand Down Expand Up @@ -515,8 +516,12 @@ exports.post_add_question = function (req, res) {
if (!student) {
throw new Error('No existing student account with provided andrew ID.');
}


let allowCDOverride = settings.get_admin_settings().allowCDOverride;
// check for cooldown violation
if (overrideCooldown && !allowCDOverride) {
throw new Error('Cooldown override is disabled');
}
let rejoinTime = settings.get_admin_settings().rejoinTime
return Promise.props({
questions: models.question.findAll({
Expand Down Expand Up @@ -888,6 +893,12 @@ exports.post_approve_cooldown_override = function (req, res) {
respond_error(req, res, "This request was not made by a TA", 400);
return
}

let cooldownAllowed = settings.get_admin_settings().allowCDOverride
if (!cooldownAllowed) {
respond_error(req, res, "Cooldown Override has been disabled", 400)
return
}

let id = req.body.andrewID
if (ohq.getPosition(id) === -1) {
Expand Down
Loading

0 comments on commit 4d43436

Please sign in to comment.