Skip to content

Commit 8e5bf5b

Browse files
committed
Various fixes
1 parent 9a61b93 commit 8e5bf5b

File tree

10 files changed

+61
-21
lines changed

10 files changed

+61
-21
lines changed

client/src/modules/Admin/Components/DevTools.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ export default function AdminTools({ token }: AdminToolsProps) {
4242
}
4343
};
4444

45+
const handleCourseEvalApiCall = async (endpoint: string, successState: keyof typeof messages, resetEvals: boolean) => {
46+
setUpdating(true)
47+
try {
48+
await axios.post(endpoint, { token, resetEvals });
49+
setUpdated(successState);
50+
} catch {
51+
setUpdated('failure');
52+
} finally {
53+
setUpdating(false);
54+
}
55+
};
56+
4557
const raffleHandler = async () => {
4658
if (!raffleStartDate) return;
4759
setUpdating(true);
@@ -79,12 +91,23 @@ export default function AdminTools({ token }: AdminToolsProps) {
7991
Add New Semester
8092
</button>
8193
<button
82-
onClick={() => handleApiCall('/api/admin/courses/add-course-evals', 'courseEval')}
94+
onClick={() =>
95+
handleCourseEvalApiCall('/api/admin/courses/add-course-evals', 'courseEval', false)
96+
}
8397
disabled={updating}
8498
className={styles.adminButtons}
8599
>
86100
Add Course Evaluations
87101
</button>
102+
<button
103+
onClick={() =>
104+
handleCourseEvalApiCall('/api/admin/courses/add-course-evals', 'courseEval', true)
105+
}
106+
disabled={updating}
107+
className={styles.adminButtons}
108+
>
109+
Delete and regenerate all Course Evaluations
110+
</button>
88111
<button
89112
onClick={() =>
90113
handleApiCall('/api/admin/professors/add', 'professors')

client/src/modules/Course/Components/Course.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export const Course = () => {
342342
<div className={styles.tabIndicator}></div>
343343

344344
{/* Add a blue active indicator that moves */}
345-
<div className={`${styles.activeIndicator} ${reviewTabSelected ? styles.firstTab : styles.secondTab}`}></div>
345+
<div className={`${courseEval != null ? styles.activeIndicator : styles.noEvalsIndicator} ${reviewTabSelected ? styles.firstTab : styles.secondTab}`}></div>
346346
</div>
347347
{reviewTabSelected && (
348348
<div className={styles.reviewscontainer}>

client/src/modules/Course/Components/CourseEval.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const CourseEval = ({courseEval}: CourseEvalProps) => {
211211
labels: ['Freshman', 'Sophomore', 'Junior', 'Senior'],
212212
datasets: [
213213
{
214-
label: '# of Students',
214+
label: ' # of Students',
215215
data: [
216216
courseEval.numFresh,
217217
courseEval.numSoph,
@@ -234,7 +234,7 @@ const CourseEval = ({courseEval}: CourseEvalProps) => {
234234
labels: ['CALS', 'AAP', 'CAS', 'COE', 'Hotel', 'HumEc', 'ILR'],
235235
datasets: [
236236
{
237-
label: '# of Students',
237+
label: ' # of Students',
238238
data: [
239239
courseEval.numAg,
240240
courseEval.numArch,
@@ -285,13 +285,14 @@ const CourseEval = ({courseEval}: CourseEvalProps) => {
285285
</div>
286286
<div className={`${styles.container} ${styles.studentYear}`}>
287287
<h1>Student Year</h1>
288-
<div style={{width:'90%', height:'90%'}}>
288+
<div style={{width:'99%', height:'99%'}}
289+
>
289290
<Pie options={pieOptions} data={yearData}/>
290291
</div>
291292
</div>
292293
<div className={`${styles.container} ${styles.schoolCollege}`}>
293294
<h1>School / College</h1>
294-
<div style={{width:'90%', height:'90%'}}>
295+
<div style={{width:'99%', height:'99%'}}>
295296
<Pie options={pieOptions} data={collegeData}/>
296297
</div>
297298
</div>

client/src/modules/Course/Styles/Course.module.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,17 @@
7878
bottom: 24px;
7979
height: 2px;
8080
background-color: var(--clr-blue-300);
81+
transition: transform 0.3s ease;
8182
width: 50%;
83+
}
84+
85+
.noEvalsIndicator {
86+
position: absolute;
87+
bottom: 24px;
88+
height: 2px;
89+
background-color: var(--clr-blue-300);
8290
transition: transform 0.3s ease;
91+
width: 100%;
8392
}
8493

8594
/* Position for first tab selected */

client/src/modules/Course/Styles/CourseEval.module.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@
8484
grid-area: reasonTaking;
8585
display: flex;
8686
flex-direction: column;
87-
justify-content: center;
87+
justify-content: space-between;
8888
gap:16px;
8989

9090
.textContainer {
91+
margin: 0 auto;
92+
height: 90%;
9193
display: flex;
9294
flex-direction: column;
9395
align-items: flex-start;
9496
gap: 24px;
95-
align-self: stretch;
9697
}
9798

9899
p {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@
2626
"typescript": "^5.4.5",
2727
"vite-plugin-eslint": "^1.8.1"
2828
},
29-
"version": "0.0.0",
30-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
29+
"version": "0.0.0"
3130
}

server/scripts/populate-course-evals.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,17 @@ const mergeCourseEvaluations = (
199199
*
200200
* @returns true if operation was successful, false otherwise
201201
* @param data course eval json data
202+
* @param resetEvals true if user wants to delete all existing
203+
* course evals and regenerate them, false if user only
204+
* wants to add new course evals
202205
*/
203206
export const addCourseEvalsFromJson = async (
204-
data: CourseEvaluationsRaw
207+
data: CourseEvaluationsRaw,
208+
resetEvals: boolean
205209
): Promise<boolean> => {
206210
const parsedData: CourseEvaluations = parseEval(data)
207211

208-
// Uncomment if you want to reset and repopulate the database,
209-
// instead of skipping over currently existing indices
210-
// await CourseEvaluations.deleteMany({})
212+
if (resetEvals) await CourseEvaluations.deleteMany({})
211213

212214
const v1 = await Promise.all(
213215
Object.entries(parsedData)
@@ -244,8 +246,8 @@ export const addCourseEvalsFromJson = async (
244246
/** Adds course evaluations to database.
245247
* !!! UNCOMMENT WHEN YOU NEED TO ADD COURSE EVALS !!!
246248
* Also uncomment in admin.controller.ts */
247-
export const addCurrCourseEvals = async () => {
248-
// await addCourseEvalsFromJson(courseData)
249+
export const addCurrCourseEvals = async (resetEvals: boolean) => {
250+
// await addCourseEvalsFromJson(courseData, resetEvals)
249251
return true
250252
};
251253

server/src/admin/admin.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,14 @@ export const addNewSemDb = async ({ auth, semester }: AdminAddSemesterType) => {
412412
*
413413
* @returns true if operation was successful, false if operations was not successful, null if token not admin
414414
*/
415-
export const addNewCourseEvals = async ({ auth }: VerifyAdminType) => {
415+
export const addNewCourseEvals = async ({ auth }: VerifyAdminType, resetEvals: boolean) => {
416416
const userIsAdmin = verifyTokenAdmin({ auth });
417417
if (!userIsAdmin) {
418418
return null;
419419
}
420420

421421
// UNCOMMENT WHEN USING FUNCTION!!!!!!
422-
// return await addCurrCourseEvals();
422+
// return await addCurrCourseEvals(resetEvals);
423423

424424
return false;
425425
};

server/src/admin/admin.router.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
AdminReviewRequestType,
66
AdminRequestType,
77
AdminUserRequestType,
8-
AdminAddSemesterRequestType
8+
AdminAddSemesterRequestType, CourseEvalRequestType
99
} from './admin.type';
1010
import {
1111
getPendingReviews,
@@ -381,10 +381,10 @@ adminRouter.post('/semester/add', async (req, res) => {
381381
* Adds all course evals to the db based on hard-coded JSON files. For admins only
382382
*/
383383
adminRouter.post('/courses/add-course-evals', async (req, res) => {
384-
const { token }: AdminRequestType = req.body;
384+
const { token, resetEvals }: CourseEvalRequestType = req.body;
385385
try {
386386
const auth = new Auth({ token });
387-
const result = await addNewCourseEvals({ auth });
387+
const result = await addNewCourseEvals({ auth }, resetEvals);
388388

389389
if (result === null) {
390390
return res.status(401).json({

server/src/admin/admin.type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface AdminRequestType {
2525
token: string;
2626
}
2727

28+
export interface CourseEvalRequestType {
29+
token: string;
30+
resetEvals: boolean;
31+
}
32+
2833
export interface VerifyAdminType {
2934
auth: Auth;
3035
}

0 commit comments

Comments
 (0)