commit
ff93a4c2d3
|
@ -8,7 +8,6 @@ export async function getGrade(testId: number, userId: number) {
|
|||
grade: true,
|
||||
id: true,
|
||||
testId: true,
|
||||
note: true,
|
||||
createdAt: true,
|
||||
},
|
||||
where: {
|
||||
|
@ -24,7 +23,6 @@ export async function addGrade(testId: number, userId: number, grade: number, no
|
|||
const newGrade = await prisma.grade.create({
|
||||
data: {
|
||||
grade: grade,
|
||||
note: note,
|
||||
testId: testId,
|
||||
userId: userId,
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ export async function getActiveTest(date: Date) {
|
|||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
isPassed: true,
|
||||
testOf: {
|
||||
select: {
|
||||
id: true,
|
||||
|
@ -30,7 +29,6 @@ export async function getActiveTest(date: Date) {
|
|||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
isPassed: false,
|
||||
testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())),
|
||||
},
|
||||
});
|
||||
|
@ -41,7 +39,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) {
|
|||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
isPassed: true,
|
||||
testOf: {
|
||||
select: {
|
||||
id: true,
|
||||
|
@ -54,7 +51,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) {
|
|||
select: {
|
||||
id: true,
|
||||
grade: true,
|
||||
note: true,
|
||||
createdAt: true,
|
||||
},
|
||||
take: 1,
|
||||
|
@ -67,7 +63,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) {
|
|||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
isPassed: false,
|
||||
testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())),
|
||||
},
|
||||
});
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
"use server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export interface Results {
|
||||
name: string;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export async function getResults(testId: number) {
|
||||
const grades = await prisma.grade.findMany({ where: { testId: testId, user: { isTeacher: false } } });
|
||||
|
||||
const allGrades = ['1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5', '5.5', '6'];
|
||||
let gradeOccurences = new Array(allGrades.length).fill(0);
|
||||
const gradeList = grades.map((grade) => grade.grade);
|
||||
|
||||
for (let i = 0; i < gradeList.length; i++) {
|
||||
gradeOccurences[allGrades.indexOf(gradeList[i].toString())]++;
|
||||
}
|
||||
|
||||
let data: Results[] = [];
|
||||
for (let i = 0; i < gradeOccurences.length; i++) {
|
||||
data.push({
|
||||
name: allGrades[i],
|
||||
total: gradeOccurences[i],
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getTeacherResult(testId: number) {
|
||||
return await prisma.grade.findFirst({ where: { testId: testId, user: { isTeacher: true } } });
|
||||
}
|
|
@ -1,18 +1,16 @@
|
|||
import prisma from '@/lib/prisma';
|
||||
import ActiveCard from './ActiveCard';
|
||||
import { getAuthServerSession } from '@/lib/authenticate';
|
||||
import { red } from 'next/dist/lib/picocolors';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default async function Dashboard() {
|
||||
const authSession = await getAuthServerSession();
|
||||
console.log(authSession);
|
||||
if (!authSession || !authSession.user.isTeacher) return redirect('/');
|
||||
if (!authSession) return redirect('/');
|
||||
|
||||
const tests = await prisma.test.findMany({ select: { isActive: true, isPassed: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } });
|
||||
const tests = await prisma.test.findMany({ select: { isActive: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } });
|
||||
|
||||
const activeTests = tests.filter((test) => test.isActive);
|
||||
const passedTests = tests.filter((test) => test.isPassed);
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
'use server';
|
||||
'use client';
|
||||
import { Chart } from '@components/custom/chart';
|
||||
import logo from '@images/logo.svg';
|
||||
import Image from 'next/image';
|
||||
import Prisma from '@lib/prisma';
|
||||
import ginger from '@images/ginger.png';
|
||||
import { getResults, getTeacherResult, Results } from '@/actions/results';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
interface data {
|
||||
name: string;
|
||||
total: number;
|
||||
}
|
||||
export default function Page({ params }: { params: { id: string } }) {
|
||||
const testId = parseInt(params.id);
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const teacherGrade = await Prisma.grade.findFirst({ where: { testId: parseInt(params.id), user: { isTeacher: true } } });
|
||||
const [teacherGrade, setTeacherGrade] = useState<number>(0);
|
||||
const [data, setData] = useState<Results[]>([]);
|
||||
|
||||
const grades = await Prisma.grade.findMany({where: {testId: parseInt(params.id), user: {isTeacher: false}}});
|
||||
function featchResults(testId: number) {
|
||||
getTeacherResult(testId)
|
||||
.then((res) => setTeacherGrade(res?.grade || 0))
|
||||
.catch((err) => console.error(err));
|
||||
|
||||
const allGrades = ['1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5', '5.5', '6'];
|
||||
let gradeOccurences = new Array(allGrades.length).fill(0);
|
||||
const gradeList = grades.map((grade) => grade.grade);
|
||||
|
||||
|
||||
for (let i = 0; i < gradeList.length; i++) {
|
||||
gradeOccurences[allGrades.indexOf(gradeList[i].toString())]++;
|
||||
getResults(testId)
|
||||
.then((res) => setData(res))
|
||||
.catch((err) => console.error(err));
|
||||
}
|
||||
|
||||
let data: data[] = [];
|
||||
for (let i = 0; i < gradeOccurences.length; i++) {
|
||||
data.push({
|
||||
name: allGrades[i],
|
||||
total: gradeOccurences[i],
|
||||
});
|
||||
}
|
||||
useEffect(() => {
|
||||
featchResults(testId);
|
||||
setTimeout(() => {
|
||||
featchResults(testId);
|
||||
}, 5000);
|
||||
}, [testId]);
|
||||
|
||||
return (
|
||||
<div className={'p-4 md:p-12 w-full h-screen bg-black flex flex-col justify-between gap-y-4'}>
|
||||
<Image src={logo} alt={'Logo'} width={100} height={200} className={'mx-auto w-full md:w-[400px]'} />
|
||||
{teacherGrade && (
|
||||
<div className={'flex flex-col gap-y-2'}>
|
||||
<p className="text-white">Mme Tixhon :</p>
|
||||
<h2 className={'text-4xl font-bold text-white'}>{teacherGrade.grade}</h2>
|
||||
<div className={'flex justify-center relative w-full'}>
|
||||
<div className={'flex items-center text-center'}>
|
||||
<Image src={ginger} alt={'Logo'} width={120} height={120} className={'inline-flex'} />
|
||||
<h2 className={'text-4xl font-bold text-white absolute top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]'}>{teacherGrade}</h2>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Chart data={data} />
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
"use client"
|
||||
'use client';
|
||||
|
||||
import {Santa} from "@components/custom/santa";
|
||||
import { Santa } from '@components/custom/santa';
|
||||
|
||||
interface ChartProps {
|
||||
data: {
|
||||
name: string
|
||||
total: number
|
||||
}[]
|
||||
name: string;
|
||||
total: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
export function Chart({...props}: ChartProps) {
|
||||
export function Chart({ ...props }: ChartProps) {
|
||||
return (
|
||||
<div className={"text-[#F0F0F0] flex-1 flex items-end"}>
|
||||
<div className={"w-full"}>
|
||||
<div className={"flex flex-row justify-between w-full items-end"}>
|
||||
<div className={'text-[#F0F0F0] flex-1 flex items-end'}>
|
||||
<div className={'w-full'}>
|
||||
<div className={'flex flex-row justify-between w-full items-end'}>
|
||||
{props.data.map((item, index) => (
|
||||
<Santa height={item.total} key={index}/>
|
||||
<Santa height={item.total} key={index} />
|
||||
))}
|
||||
</div>
|
||||
<div className={"flex flex-row justify-between w-full items-end mt-2"}>
|
||||
<div className={'flex flex-row justify-between w-full items-end mt-2'}>
|
||||
{props.data.map((item, index) => (
|
||||
<div className={"w-[100px] h-fit flex flex-col items-center"} key={index}>
|
||||
<div className={"h-[14px] w-[3pt] bg-white"}/>
|
||||
<span className={""}>{item.name}</span>
|
||||
<div className={'w-[100px] h-fit flex flex-col items-center'} key={index}>
|
||||
<div className={'h-[14px] w-[3pt] bg-white'} />
|
||||
<span className={''}>{item.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { Session } from 'next-auth';
|
|||
import { addGrade } from '@/actions/grades';
|
||||
|
||||
export function GradingForm({ session, testId }: { session: Session; testId: number }) {
|
||||
const [grade, setGrade] = useState<number>(0);
|
||||
const [grade, setGrade] = useState<number>(4);
|
||||
const [hasVoted, setHasVoted] = useState<boolean>(false);
|
||||
|
||||
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
||||
|
@ -39,7 +39,7 @@ export function GradingForm({ session, testId }: { session: Session; testId: num
|
|||
<div className={'w-full md:w-[400px]'}>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div>
|
||||
<input type="range" min="2" max="12" id="gradeSelector" className={'w-full h-4 bg-white range range:bg-white text-white'} onChange={(e) => setGrade(Number(e.target.value) / 2)} />
|
||||
<input type="range" value={grade} step="0.5" min="1" max="6" id="gradeSelector" className={"w-full appearance-none bg-transparent [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-primary/75 accent-accent"} onChange={(e) => setGrade(Number(e.target.value))} />
|
||||
</div>
|
||||
<div className={'flex flex-row justify-evenly'}>
|
||||
<Image src={YourGrade} alt={YourGrade} width={100} />
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 170 KiB |
|
@ -14,6 +14,7 @@ model Users {
|
|||
firstName String
|
||||
lastName String
|
||||
isTeacher Boolean @default(false)
|
||||
isAdmin Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
grades Grade[]
|
||||
test Test?
|
||||
|
@ -27,14 +28,11 @@ model Test {
|
|||
testOf Users @relation(fields: [testOfId], references: [id])
|
||||
grades Grade[]
|
||||
isActive Boolean @default(false)
|
||||
isPassed Boolean @default(false)
|
||||
teacherGrade Float?
|
||||
}
|
||||
|
||||
model Grade {
|
||||
id Int @id @default(autoincrement())
|
||||
userId Int
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
grade Float
|
||||
testId Int
|
||||
|
|
Loading…
Reference in New Issue