ENCOA-266
This commit is contained in:
@@ -68,6 +68,7 @@ export default function Dashboard({ user, users, userCounts, entities, assignmen
|
||||
const teachers = useMemo(() => users.filter((u) => u.type === "teacher"), [users]);
|
||||
|
||||
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
||||
const allowedStudentPerformance = useAllowedEntities(user, entities, 'view_student_performance')
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -127,12 +128,14 @@ export default function Dashboard({ user, users, userCounts, entities, assignmen
|
||||
color="purple"
|
||||
/>
|
||||
)}
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/users/performance")}
|
||||
label="Student Performance"
|
||||
value={userCounts.student}
|
||||
color="purple"
|
||||
/>
|
||||
{allowedStudentPerformance.length > 0 && (
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/users/performance")}
|
||||
label="Student Performance"
|
||||
value={students.length}
|
||||
color="purple"
|
||||
/>
|
||||
)}
|
||||
<IconCard
|
||||
Icon={BsClock}
|
||||
label="Expiration Date"
|
||||
|
||||
@@ -76,16 +76,7 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
||||
const router = useRouter();
|
||||
|
||||
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
||||
|
||||
const UserDisplay = (displayUser: User) => (
|
||||
<div className="flex w-full p-4 gap-4 items-center hover:bg-mti-purple-ultralight cursor-pointer transition ease-in-out duration-300">
|
||||
<img src={displayUser.profilePicture} alt={displayUser.name} className="rounded-full w-10 h-10" />
|
||||
<div className="flex flex-col gap-1 items-start">
|
||||
<span>{displayUser.name}</span>
|
||||
<span className="text-sm opacity-75">{displayUser.email}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
const allowedStudentPerformance = useAllowedEntities(user, entities, 'view_student_performance')
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -131,12 +122,14 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
||||
color="purple"
|
||||
/>
|
||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/users/performance")}
|
||||
label="Student Performance"
|
||||
value={students.length}
|
||||
color="purple"
|
||||
/>
|
||||
{allowedStudentPerformance.length > 0 && (
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/users/performance")}
|
||||
label="Student Performance"
|
||||
value={students.length}
|
||||
color="purple"
|
||||
/>
|
||||
)}
|
||||
{allowedEntityStatistics.length > 0 && (
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/statistical")}
|
||||
|
||||
@@ -60,31 +60,7 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
||||
const router = useRouter();
|
||||
|
||||
const allowedEntityStatistics = useAllowedEntities(user, entities, 'view_entity_statistics')
|
||||
|
||||
const averageLevelCalculator = (studentStats: Stat[]) => {
|
||||
const formattedStats = studentStats
|
||||
.map((s) => ({
|
||||
focus: students.find((u) => u.id === s.user)?.focus,
|
||||
score: s.score,
|
||||
module: s.module,
|
||||
}))
|
||||
.filter((f) => !!f.focus);
|
||||
const bandScores = formattedStats.map((s) => ({
|
||||
module: s.module,
|
||||
level: calculateBandScore(s.score.correct, s.score.total, s.module, s.focus!),
|
||||
}));
|
||||
|
||||
const levels: { [key in Module]: number } = {
|
||||
reading: 0,
|
||||
listening: 0,
|
||||
writing: 0,
|
||||
speaking: 0,
|
||||
level: 0,
|
||||
};
|
||||
bandScores.forEach((b) => (levels[b.module] += b.level));
|
||||
|
||||
return calculateAverageLevel(levels);
|
||||
};
|
||||
const allowedStudentPerformance = useAllowedEntities(user, entities, 'view_student_performance')
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -121,6 +97,14 @@ export default function Dashboard({ user, users, entities, assignments, stats, g
|
||||
color="purple"
|
||||
/>
|
||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||
{allowedStudentPerformance.length > 0 && (
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/users/performance")}
|
||||
label="Student Performance"
|
||||
value={students.length}
|
||||
color="purple"
|
||||
/>
|
||||
)}
|
||||
{allowedEntityStatistics.length > 0 && (
|
||||
<IconCard Icon={BsPersonFillGear}
|
||||
onClick={() => router.push("/statistical")}
|
||||
|
||||
@@ -93,7 +93,8 @@ const ENTITY_MANAGEMENT: PermissionLayout[] = [
|
||||
{ label: "Assign Role to User", key: "assign_to_role" },
|
||||
{ label: "Delete Entity Role", key: "delete_entity_role" },
|
||||
{ label: "Download Statistics Report", key: "download_statistics_report" },
|
||||
{ label: "Edit Grading System", key: "edit_grading_system" }
|
||||
{ label: "Edit Grading System", key: "edit_grading_system" },
|
||||
{ label: "View Student Performance", key: "view_student_performance" }
|
||||
]
|
||||
|
||||
const ASSIGNMENT_MANAGEMENT: PermissionLayout[] = [
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import useFilterRecordsByUser from "@/hooks/useFilterRecordsByUser";
|
||||
import useGroups from "@/hooks/useGroups";
|
||||
import useUsers, {userHashStudent} from "@/hooks/useUsers";
|
||||
import {Group, Stat, StudentUser, User} from "@/interfaces/user";
|
||||
import {getUserCompanyName} from "@/resources/user";
|
||||
import useUsers, { userHashStudent } from "@/hooks/useUsers";
|
||||
import { Group, Stat, StudentUser, User } from "@/interfaces/user";
|
||||
import { getUserCompanyName } from "@/resources/user";
|
||||
import clsx from "clsx";
|
||||
import {useRouter} from "next/router";
|
||||
import {BsArrowLeft, BsArrowRepeat, BsChevronLeft} from "react-icons/bs";
|
||||
import { useRouter } from "next/router";
|
||||
import { BsArrowLeft, BsArrowRepeat, BsChevronLeft } from "react-icons/bs";
|
||||
import { mapBy, serialize } from "@/utils";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { getEntitiesUsers, getUsers } from "@/utils/users.be";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { checkAccess } from "@/utils/permissions";
|
||||
import { getEntities } from "@/utils/entities.be";
|
||||
import { checkAccess, findAllowedEntities } from "@/utils/permissions";
|
||||
import { getEntities, getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
import { Entity } from "@/interfaces/entity";
|
||||
import { getParticipantGroups, getParticipantsGroups } from "@/utils/groups.be";
|
||||
import StudentPerformanceList from "../(admin)/Lists/StudentPerformanceList";
|
||||
@@ -21,21 +21,25 @@ import Layout from "@/components/High/Layout";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { redirect } from "@/utils";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res, query}) => {
|
||||
export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => {
|
||||
const user = await requestUser(req, res)
|
||||
if (!user) return redirect("/login")
|
||||
|
||||
const entityIDs = mapBy(user.entities, 'id')
|
||||
|
||||
const entities = await getEntities(checkAccess(user, ["admin", 'developer']) ? undefined : entityIDs)
|
||||
const entities = await getEntitiesWithRoles(checkAccess(user, ["admin", 'developer']) ? undefined : entityIDs)
|
||||
const allowedEntities = findAllowedEntities(user, entities, "view_student_performance")
|
||||
|
||||
if (allowedEntities.length === 0) return redirect("/")
|
||||
|
||||
const students = await (checkAccess(user, ["admin", 'developer'])
|
||||
? getUsers({type: 'student'})
|
||||
: getEntitiesUsers(entityIDs, {type: 'student'})
|
||||
? getUsers({ type: 'student' })
|
||||
: getEntitiesUsers(mapBy(allowedEntities, 'id'), { type: 'student' })
|
||||
)
|
||||
const groups = await getParticipantsGroups(mapBy(students, 'id'))
|
||||
|
||||
return {
|
||||
props: serialize({user, students, entities, groups}),
|
||||
props: serialize({ user, students, entities, groups }),
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
@@ -46,8 +50,8 @@ interface Props {
|
||||
groups: Group[]
|
||||
}
|
||||
|
||||
const StudentPerformance = ({user, students, entities, groups}: Props) => {
|
||||
const {data: stats} = useFilterRecordsByUser<Stat[]>();
|
||||
const StudentPerformance = ({ user, students, entities, groups }: Props) => {
|
||||
const { data: stats } = useFilterRecordsByUser<Stat[]>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -58,7 +62,7 @@ const StudentPerformance = ({user, students, entities, groups}: Props) => {
|
||||
}));
|
||||
|
||||
return (
|
||||
<>
|
||||
<>
|
||||
<Head>
|
||||
<title>EnCoach</title>
|
||||
<meta
|
||||
@@ -70,7 +74,7 @@ const StudentPerformance = ({user, students, entities, groups}: Props) => {
|
||||
</Head>
|
||||
<ToastContainer />
|
||||
|
||||
<Layout user={user}>
|
||||
<Layout user={user}>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => {
|
||||
@@ -79,9 +83,9 @@ const StudentPerformance = ({user, students, entities, groups}: Props) => {
|
||||
className="text-mti-purple hover:text-mti-purple-dark transition ease-in-out duration-300 text-xl">
|
||||
<BsChevronLeft />
|
||||
</button>
|
||||
<h2 className="font-bold text-2xl">Student Performance ({ students.length })</h2>
|
||||
<h2 className="font-bold text-2xl">Student Performance ({students.length})</h2>
|
||||
</div>
|
||||
<StudentPerformanceList items={performanceStudents} stats={stats} />
|
||||
<StudentPerformanceList items={performanceStudents} stats={stats} />
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -58,7 +58,8 @@ export type RolePermission =
|
||||
"delete_code" |
|
||||
"view_statistics" |
|
||||
"download_statistics_report" |
|
||||
"edit_grading_system"
|
||||
"edit_grading_system" |
|
||||
"view_student_performance"
|
||||
|
||||
export const DEFAULT_PERMISSIONS: RolePermission[] = [
|
||||
"view_students",
|
||||
@@ -130,5 +131,6 @@ export const ADMIN_PERMISSIONS: RolePermission[] = [
|
||||
"delete_code",
|
||||
"view_statistics",
|
||||
"download_statistics_report",
|
||||
"edit_grading_system"
|
||||
"edit_grading_system",
|
||||
"view_student_performance"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user