feat: Implement course gradebook with cohort filtering, CSV export, and extend analytics with cohort selection.
This commit is contained in:
@@ -884,6 +884,46 @@ pub async fn get_leaderboard(
|
|||||||
Ok(Json(response))
|
Ok(Json(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_course_grades(
|
||||||
|
Org(org_ctx): Org,
|
||||||
|
State(pool): State<PgPool>,
|
||||||
|
Path(course_id): Path<Uuid>,
|
||||||
|
Query(filter): Query<AnalyticsFilter>,
|
||||||
|
) -> Result<Json<Vec<common::models::StudentGradeReport>>, (StatusCode, String)> {
|
||||||
|
let rows = sqlx::query_as::<_, common::models::StudentGradeReport>(
|
||||||
|
r#"
|
||||||
|
SELECT
|
||||||
|
u.id as user_id,
|
||||||
|
u.full_name,
|
||||||
|
u.email,
|
||||||
|
COALESCE(e.progress, 0)::float4 as progress,
|
||||||
|
AVG(g.score)::float4 as average_score,
|
||||||
|
e.updated_at as last_active_at
|
||||||
|
FROM users u
|
||||||
|
JOIN enrollments e ON u.id = e.user_id
|
||||||
|
AND e.course_id = $1
|
||||||
|
AND e.organization_id = $2
|
||||||
|
LEFT JOIN user_grades g ON u.id = g.user_id AND g.course_id = $1
|
||||||
|
WHERE ($3::uuid IS NULL OR EXISTS (
|
||||||
|
SELECT 1 FROM user_cohorts uc WHERE uc.user_id = u.id AND uc.cohort_id = $3
|
||||||
|
))
|
||||||
|
GROUP BY u.id, u.full_name, u.email, e.progress, e.updated_at
|
||||||
|
ORDER BY u.full_name
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(course_id)
|
||||||
|
.bind(org_ctx.id)
|
||||||
|
.bind(filter.cohort_id)
|
||||||
|
.fetch_all(&pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
tracing::error!("Failed to fetch course grades: {}", e);
|
||||||
|
(StatusCode::INTERNAL_SERVER_ERROR, e.to_string())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(Json(rows))
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_user_course_grades(
|
pub async fn get_user_course_grades(
|
||||||
Org(_org_ctx): Org,
|
Org(_org_ctx): Org,
|
||||||
State(pool): State<PgPool>,
|
State(pool): State<PgPool>,
|
||||||
@@ -900,27 +940,51 @@ pub async fn get_user_course_grades(
|
|||||||
|
|
||||||
Ok(Json(grades))
|
Ok(Json(grades))
|
||||||
}
|
}
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct AnalyticsFilter {
|
||||||
|
pub cohort_id: Option<Uuid>,
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_course_analytics(
|
pub async fn get_course_analytics(
|
||||||
Org(org_ctx): Org,
|
Org(org_ctx): Org,
|
||||||
State(pool): State<PgPool>,
|
State(pool): State<PgPool>,
|
||||||
Path(course_id): Path<Uuid>,
|
Path(course_id): Path<Uuid>,
|
||||||
|
Query(filter): Query<AnalyticsFilter>,
|
||||||
) -> Result<Json<CourseAnalytics>, (StatusCode, String)> {
|
) -> Result<Json<CourseAnalytics>, (StatusCode, String)> {
|
||||||
// 1. Total Enrollments
|
// 1. Total Enrollments
|
||||||
let total_enrollments: i64 = sqlx::query_scalar(
|
let total_enrollments: i64 = sqlx::query_scalar(
|
||||||
"SELECT COUNT(*) FROM enrollments WHERE course_id = $1 AND organization_id = $2",
|
r#"
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM enrollments e
|
||||||
|
WHERE e.course_id = $1
|
||||||
|
AND e.organization_id = $2
|
||||||
|
AND ($3::uuid IS NULL OR EXISTS (
|
||||||
|
SELECT 1 FROM user_cohorts uc WHERE uc.user_id = e.user_id AND uc.cohort_id = $3
|
||||||
|
))
|
||||||
|
"#,
|
||||||
)
|
)
|
||||||
.bind(course_id)
|
.bind(course_id)
|
||||||
.bind(org_ctx.id)
|
.bind(org_ctx.id)
|
||||||
|
.bind(filter.cohort_id)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||||
|
|
||||||
// 2. Average Course Score (Overall)
|
// 2. Average Course Score (Overall)
|
||||||
let average_score: Option<f32> = sqlx::query_scalar(
|
let average_score: Option<f32> = sqlx::query_scalar(
|
||||||
"SELECT AVG(score)::float4 FROM user_grades WHERE course_id = $1 AND organization_id = $2",
|
r#"
|
||||||
|
SELECT AVG(score)::float4
|
||||||
|
FROM user_grades g
|
||||||
|
WHERE g.course_id = $1
|
||||||
|
AND g.organization_id = $2
|
||||||
|
AND ($3::uuid IS NULL OR EXISTS (
|
||||||
|
SELECT 1 FROM user_cohorts uc WHERE uc.user_id = g.user_id AND uc.cohort_id = $3
|
||||||
|
))
|
||||||
|
"#,
|
||||||
)
|
)
|
||||||
.bind(course_id)
|
.bind(course_id)
|
||||||
.bind(org_ctx.id)
|
.bind(org_ctx.id)
|
||||||
|
.bind(filter.cohort_id)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||||
@@ -936,6 +1000,9 @@ pub async fn get_course_analytics(
|
|||||||
COUNT(g.id) as submission_count
|
COUNT(g.id) as submission_count
|
||||||
FROM lessons l
|
FROM lessons l
|
||||||
LEFT JOIN user_grades g ON l.id = g.lesson_id
|
LEFT JOIN user_grades g ON l.id = g.lesson_id
|
||||||
|
AND ($3::uuid IS NULL OR EXISTS (
|
||||||
|
SELECT 1 FROM user_cohorts uc WHERE uc.user_id = g.user_id AND uc.cohort_id = $3
|
||||||
|
))
|
||||||
WHERE l.module_id IN (SELECT id FROM modules WHERE course_id = $1) AND l.organization_id = $2
|
WHERE l.module_id IN (SELECT id FROM modules WHERE course_id = $1) AND l.organization_id = $2
|
||||||
GROUP BY l.id, l.title, l.position
|
GROUP BY l.id, l.title, l.position
|
||||||
ORDER BY l.position
|
ORDER BY l.position
|
||||||
@@ -943,6 +1010,7 @@ pub async fn get_course_analytics(
|
|||||||
)
|
)
|
||||||
.bind(course_id)
|
.bind(course_id)
|
||||||
.bind(org_ctx.id)
|
.bind(org_ctx.id)
|
||||||
|
.bind(filter.cohort_id)
|
||||||
.fetch_all(&pool)
|
.fetch_all(&pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ async fn main() {
|
|||||||
"/courses/{id}/analytics",
|
"/courses/{id}/analytics",
|
||||||
get(handlers::get_course_analytics),
|
get(handlers::get_course_analytics),
|
||||||
)
|
)
|
||||||
|
.route("/courses/{id}/grades", get(handlers::get_course_grades))
|
||||||
.route(
|
.route(
|
||||||
"/courses/{id}/analytics/advanced",
|
"/courses/{id}/analytics/advanced",
|
||||||
get(handlers::get_advanced_analytics),
|
get(handlers::get_advanced_analytics),
|
||||||
|
|||||||
@@ -481,6 +481,16 @@ pub struct AddMemberPayload {
|
|||||||
pub user_id: Uuid,
|
pub user_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow, Clone)]
|
||||||
|
pub struct StudentGradeReport {
|
||||||
|
pub user_id: Uuid,
|
||||||
|
pub full_name: String,
|
||||||
|
pub email: String,
|
||||||
|
pub progress: f32,
|
||||||
|
pub average_score: Option<f32>,
|
||||||
|
pub last_active_at: Option<DateTime<Utc>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { cmsApi, Course, CourseAnalytics } from "@/lib/api";
|
import { cmsApi, Cohort, Course, CourseAnalytics, lmsApi } from "@/lib/api";
|
||||||
import { useAuth } from "@/context/AuthContext";
|
import { useAuth } from "@/context/AuthContext";
|
||||||
import {
|
import {
|
||||||
BarChart3,
|
BarChart3,
|
||||||
@@ -24,6 +24,8 @@ export default function AnalyticsPage() {
|
|||||||
const [analytics, setAnalytics] = useState<CourseAnalytics | null>(null);
|
const [analytics, setAnalytics] = useState<CourseAnalytics | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [authError, setAuthError] = useState<string | null>(null);
|
const [authError, setAuthError] = useState<string | null>(null);
|
||||||
|
const [cohorts, setCohorts] = useState<Cohort[]>([]);
|
||||||
|
const [selectedCohortId, setSelectedCohortId] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -39,9 +41,13 @@ export default function AnalyticsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Fetch cohorts once
|
||||||
|
const cohortsData = await lmsApi.getCohorts();
|
||||||
|
setCohorts(cohortsData);
|
||||||
|
|
||||||
const [courseData, analyticsData] = await Promise.all([
|
const [courseData, analyticsData] = await Promise.all([
|
||||||
cmsApi.getCourseWithFullOutline(id),
|
cmsApi.getCourseWithFullOutline(id),
|
||||||
cmsApi.getCourseAnalytics(id)
|
cmsApi.getCourseAnalytics(id, selectedCohortId || undefined)
|
||||||
]);
|
]);
|
||||||
setCourse(courseData);
|
setCourse(courseData);
|
||||||
setAnalytics(analyticsData);
|
setAnalytics(analyticsData);
|
||||||
@@ -53,7 +59,7 @@ export default function AnalyticsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchData();
|
fetchData();
|
||||||
}, [id, user, router]);
|
}, [id, user, router, selectedCohortId]);
|
||||||
|
|
||||||
if (loading) return (
|
if (loading) return (
|
||||||
<div className="min-h-screen bg-gray-900 flex items-center justify-center">
|
<div className="min-h-screen bg-gray-900 flex items-center justify-center">
|
||||||
@@ -102,6 +108,14 @@ export default function AnalyticsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
|
<select
|
||||||
|
value={selectedCohortId}
|
||||||
|
onChange={(e) => setSelectedCohortId(e.target.value)}
|
||||||
|
className="bg-white/5 text-white border border-white/10 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/50"
|
||||||
|
>
|
||||||
|
<option value="">All Students</option>
|
||||||
|
{cohorts.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
|
||||||
|
</select>
|
||||||
<button
|
<button
|
||||||
onClick={() => router.push(`/courses/${id}/analytics/advanced`)}
|
onClick={() => router.push(`/courses/${id}/analytics/advanced`)}
|
||||||
className="btn-premium !bg-purple-600/10 !text-purple-400 border border-purple-500/20 hover:!bg-purple-600/20 !shadow-none gap-2 text-xs py-2"
|
className="btn-premium !bg-purple-600/10 !text-purple-400 border border-purple-500/20 hover:!bg-purple-600/20 !shadow-none gap-2 text-xs py-2"
|
||||||
|
|||||||
@@ -0,0 +1,261 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
import { lmsApi, cmsApi, StudentGradeReport, Cohort } from "@/lib/api";
|
||||||
|
import { useAuth } from "@/context/AuthContext";
|
||||||
|
import CourseEditorLayout from "@/components/CourseEditorLayout";
|
||||||
|
import {
|
||||||
|
ArrowLeft,
|
||||||
|
Search,
|
||||||
|
GraduationCap,
|
||||||
|
Download,
|
||||||
|
CheckCircle,
|
||||||
|
AlertCircle,
|
||||||
|
User,
|
||||||
|
Mail,
|
||||||
|
Clock
|
||||||
|
} from "lucide-react";
|
||||||
|
|
||||||
|
export default function GradebookPage() {
|
||||||
|
const { id } = useParams() as { id: string };
|
||||||
|
const router = useRouter();
|
||||||
|
const { user } = useAuth();
|
||||||
|
const [students, setStudents] = useState<StudentGradeReport[]>([]);
|
||||||
|
const [filteredStudents, setFilteredStudents] = useState<StudentGradeReport[]>([]);
|
||||||
|
const [cohorts, setCohorts] = useState<Cohort[]>([]);
|
||||||
|
const [selectedCohortId, setSelectedCohortId] = useState<string>("");
|
||||||
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [courseTitle, setCourseTitle] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!user) return;
|
||||||
|
if (user.role !== 'admin' && user.role !== 'instructor') {
|
||||||
|
router.push('/');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const [gradesData, cohortsData, courseData] = await Promise.all([
|
||||||
|
lmsApi.getCourseGrades(id, selectedCohortId || undefined),
|
||||||
|
lmsApi.getCohorts(),
|
||||||
|
cmsApi.getCourse(id)
|
||||||
|
]);
|
||||||
|
setStudents(gradesData);
|
||||||
|
setCohorts(cohortsData);
|
||||||
|
setCourseTitle(courseData.title);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to load gradebook data", err);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchData();
|
||||||
|
}, [id, user, router, selectedCohortId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let result = students;
|
||||||
|
if (searchQuery) {
|
||||||
|
const q = searchQuery.toLowerCase();
|
||||||
|
result = result.filter(s =>
|
||||||
|
s.full_name.toLowerCase().includes(q) ||
|
||||||
|
s.email.toLowerCase().includes(q)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
setFilteredStudents(result);
|
||||||
|
}, [students, searchQuery]);
|
||||||
|
|
||||||
|
const averageScore = students.length > 0
|
||||||
|
? students.reduce((acc, s) => acc + (s.average_score || 0), 0) / students.length
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
const exportCSV = () => {
|
||||||
|
const headers = ["Name", "Email", "Progress", "Average Score", "Last Active"];
|
||||||
|
const rows = filteredStudents.map(s => [
|
||||||
|
s.full_name,
|
||||||
|
s.email,
|
||||||
|
`${(s.progress * 100).toFixed(1)}%`,
|
||||||
|
s.average_score ? `${(s.average_score * 100).toFixed(1)}%` : "N/A",
|
||||||
|
s.last_active_at ? new Date(s.last_active_at).toLocaleDateString() : "Never"
|
||||||
|
]);
|
||||||
|
|
||||||
|
const csvContent = "data:text/csv;charset=utf-8,"
|
||||||
|
+ [headers.join(","), ...rows.map(r => r.join(","))].join("\n");
|
||||||
|
|
||||||
|
const encodedUri = encodeURI(csvContent);
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.setAttribute("href", encodedUri);
|
||||||
|
link.setAttribute("download", `${courseTitle}_gradebook.csv`);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loading && students.length === 0) return (
|
||||||
|
<div className="min-h-screen bg-[#0f1115] flex items-center justify-center">
|
||||||
|
<div className="w-12 h-12 border-4 border-blue-500/20 border-t-blue-500 rounded-full animate-spin"></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-[#0f1115] text-white p-8">
|
||||||
|
<div className="max-w-7xl mx-auto">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="flex items-center justify-between mb-12">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<button
|
||||||
|
onClick={() => router.back()}
|
||||||
|
className="p-2 hover:bg-white/10 rounded-full transition-colors"
|
||||||
|
>
|
||||||
|
<ArrowLeft className="w-6 h-6" />
|
||||||
|
</button>
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold bg-gradient-to-r from-blue-400 to-indigo-400 bg-clip-text text-transparent">
|
||||||
|
Gradebook
|
||||||
|
</h1>
|
||||||
|
<p className="text-gray-400 mt-1">Student, progress, and performance tracking</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<button
|
||||||
|
onClick={exportCSV}
|
||||||
|
className="btn-premium px-4 flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<Download size={16} /> Export CSV
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CourseEditorLayout activeTab="grades">
|
||||||
|
<div className="p-8 space-y-8">
|
||||||
|
{/* Controls & Stats */}
|
||||||
|
<div className="flex flex-col md:flex-row gap-6 justify-between items-center bg-white/5 border border-white/10 rounded-2xl p-6">
|
||||||
|
<div className="flex items-center gap-4 w-full md:w-auto">
|
||||||
|
<div className="relative">
|
||||||
|
<select
|
||||||
|
value={selectedCohortId}
|
||||||
|
onChange={(e) => setSelectedCohortId(e.target.value)}
|
||||||
|
className="appearance-none bg-black/20 text-white border border-white/10 rounded-xl pl-4 pr-10 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/50 min-w-[200px]"
|
||||||
|
>
|
||||||
|
<option value="">All Cohorts</option>
|
||||||
|
{cohorts.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
|
||||||
|
</select>
|
||||||
|
<div className="absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-gray-500">
|
||||||
|
▼
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="relative flex-1 md:w-64">
|
||||||
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 w-4 h-4" />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search students..."
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
className="w-full bg-black/20 border border-white/10 rounded-xl pl-10 pr-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/50 text-white placeholder-gray-600"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-8 border-l border-white/10 pl-8">
|
||||||
|
<div>
|
||||||
|
<p className="text-xs font-bold text-gray-500 uppercase tracking-wider mb-1">Students</p>
|
||||||
|
<p className="text-2xl font-black">{filteredStudents.length}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs font-bold text-gray-500 uppercase tracking-wider mb-1">Avg Score</p>
|
||||||
|
<p className={`text-2xl font-black ${averageScore < 0.7 ? 'text-orange-400' : 'text-green-400'}`}>
|
||||||
|
{(averageScore * 100).toFixed(0)}%
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Student List */}
|
||||||
|
<div className="rounded-3xl border border-white/10 bg-white/[0.02] overflow-hidden">
|
||||||
|
<table className="w-full text-left border-collapse">
|
||||||
|
<thead>
|
||||||
|
<tr className="bg-white/5 border-b border-white/5">
|
||||||
|
<th className="p-6 text-xs font-black uppercase tracking-widest text-gray-500">Student</th>
|
||||||
|
<th className="p-6 text-xs font-black uppercase tracking-widest text-gray-500">Progress</th>
|
||||||
|
<th className="p-6 text-xs font-black uppercase tracking-widest text-gray-500">Avg. Score</th>
|
||||||
|
<th className="p-6 text-xs font-black uppercase tracking-widest text-gray-500">Last Active</th>
|
||||||
|
<th className="p-6 text-xs font-black uppercase tracking-widest text-gray-500 text-right">Status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-white/5">
|
||||||
|
{filteredStudents.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={5} className="p-12 text-center text-gray-600 italic">No students found.</td>
|
||||||
|
</tr>
|
||||||
|
) : filteredStudents.map((s) => (
|
||||||
|
<tr key={s.user_id} className="hover:bg-white/[0.02] transition-colors group">
|
||||||
|
<td className="p-6">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-indigo-600 flex items-center justify-center text-white font-bold text-sm">
|
||||||
|
{s.full_name.charAt(0)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="font-bold text-white group-hover:text-blue-400 transition-colors">{s.full_name}</div>
|
||||||
|
<div className="text-xs text-gray-500 flex items-center gap-1 mt-0.5">
|
||||||
|
<Mail size={10} /> {s.email}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="p-6 align-middle">
|
||||||
|
<div className="w-full max-w-[140px]">
|
||||||
|
<div className="flex justify-between text-xs mb-1 font-bold text-gray-400">
|
||||||
|
<span>{(s.progress * 100).toFixed(0)}%</span>
|
||||||
|
</div>
|
||||||
|
<div className="h-1.5 bg-white/10 rounded-full overflow-hidden">
|
||||||
|
<div
|
||||||
|
className="h-full bg-blue-500 rounded-full"
|
||||||
|
style={{ width: `${s.progress * 100}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="p-6 align-middle">
|
||||||
|
{s.average_score !== null ? (
|
||||||
|
<span className={`font-black ${(s.average_score || 0) >= 0.8 ? 'text-green-400' : (s.average_score || 0) >= 0.6 ? 'text-yellow-400' : 'text-red-400'}`}>
|
||||||
|
{((s.average_score || 0) * 100).toFixed(0)}%
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-600 text-xs italic">No grades</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="p-6 align-middle">
|
||||||
|
<div className="text-sm text-gray-400 flex items-center gap-2">
|
||||||
|
<Clock size={14} />
|
||||||
|
{s.last_active_at ? new Date(s.last_active_at).toLocaleDateString() : 'Never'}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="p-6 text-right align-middle">
|
||||||
|
{s.progress >= 1 ? (
|
||||||
|
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-widest bg-green-500/10 text-green-400 border border-green-500/20">
|
||||||
|
<CheckCircle size={12} /> Completed
|
||||||
|
</span>
|
||||||
|
) : s.last_active_at && (Date.now() - new Date(s.last_active_at).getTime() > 7 * 24 * 60 * 60 * 1000) ? (
|
||||||
|
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-widest bg-red-500/10 text-red-400 border border-red-500/20">
|
||||||
|
<AlertCircle size={12} /> Inactive
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-widest bg-blue-500/10 text-blue-400 border border-blue-500/20">
|
||||||
|
<GraduationCap size={12} /> Active
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CourseEditorLayout>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { Layout, CheckCircle2, Calendar, BarChart2, Settings, Folder } from "lucide-react";
|
import { Layout, CheckCircle2, Calendar, BarChart2, Settings, Folder, GraduationCap } from "lucide-react";
|
||||||
|
|
||||||
interface CourseEditorLayoutProps {
|
interface CourseEditorLayoutProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
activeTab: "outline" | "grading" | "calendar" | "analytics" | "settings" | "files";
|
activeTab: "outline" | "grading" | "calendar" | "analytics" | "settings" | "files" | "grades";
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CourseEditorLayout({ children, activeTab }: CourseEditorLayoutProps) {
|
export default function CourseEditorLayout({ children, activeTab }: CourseEditorLayoutProps) {
|
||||||
@@ -15,7 +15,8 @@ export default function CourseEditorLayout({ children, activeTab }: CourseEditor
|
|||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{ key: "outline", label: "Outline", icon: Layout, href: `/courses/${id}` },
|
{ key: "outline", label: "Outline", icon: Layout, href: `/courses/${id}` },
|
||||||
{ key: "grading", label: "Grading", icon: CheckCircle2, href: `/courses/${id}/grading` },
|
{ key: "grading", label: "Grading Policy", icon: CheckCircle2, href: `/courses/${id}/grading` },
|
||||||
|
{ key: "grades", label: "Gradebook", icon: GraduationCap, href: `/courses/${id}/grades` },
|
||||||
{ key: "calendar", label: "Calendar", icon: Calendar, href: `/courses/${id}/calendar` },
|
{ key: "calendar", label: "Calendar", icon: Calendar, href: `/courses/${id}/calendar` },
|
||||||
{ key: "analytics", label: "Analytics", icon: BarChart2, href: `/courses/${id}/analytics` },
|
{ key: "analytics", label: "Analytics", icon: BarChart2, href: `/courses/${id}/analytics` },
|
||||||
{ key: "files", label: "Files & Uploads", icon: Folder, href: `/courses/${id}/files` },
|
{ key: "files", label: "Files & Uploads", icon: Folder, href: `/courses/${id}/files` },
|
||||||
|
|||||||
@@ -291,6 +291,15 @@ export interface AddMemberPayload {
|
|||||||
user_id: string;
|
user_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface StudentGradeReport {
|
||||||
|
user_id: string;
|
||||||
|
full_name: string;
|
||||||
|
email: string;
|
||||||
|
progress: number;
|
||||||
|
average_score: number | null;
|
||||||
|
last_active_at: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
const getToken = () => typeof window !== 'undefined' ? localStorage.getItem('studio_token') : null;
|
const getToken = () => typeof window !== 'undefined' ? localStorage.getItem('studio_token') : null;
|
||||||
const getSelectedOrgId = () => typeof window !== 'undefined' ? localStorage.getItem('studio_selected_org_id') : null;
|
const getSelectedOrgId = () => typeof window !== 'undefined' ? localStorage.getItem('studio_selected_org_id') : null;
|
||||||
|
|
||||||
@@ -362,8 +371,14 @@ export const cmsApi = {
|
|||||||
|
|
||||||
// Admin & Analytics
|
// Admin & Analytics
|
||||||
getAuditLogs: (): Promise<AuditLog[]> => apiFetch('/audit-logs'),
|
getAuditLogs: (): Promise<AuditLog[]> => apiFetch('/audit-logs'),
|
||||||
getCourseAnalytics: (id: string): Promise<CourseAnalytics> => apiFetch(`/courses/${id}/analytics`),
|
getCourseAnalytics: (id: string, cohortId?: string): Promise<CourseAnalytics> => {
|
||||||
getAdvancedAnalytics: (id: string): Promise<AdvancedAnalytics> => apiFetch(`/courses/${id}/analytics/advanced`),
|
const query = cohortId ? `?cohort_id=${cohortId}` : '';
|
||||||
|
return apiFetch(`/courses/${id}/analytics${query}`, {}, true);
|
||||||
|
},
|
||||||
|
getAdvancedAnalytics: (id: string, cohortId?: string): Promise<AdvancedAnalytics> => {
|
||||||
|
const query = cohortId ? `?cohort_id=${cohortId}` : '';
|
||||||
|
return apiFetch(`/courses/${id}/analytics/advanced${query}`, {}, true);
|
||||||
|
},
|
||||||
getLessonHeatmap: (lessonId: string): Promise<{ second: number, count: number }[]> => apiFetch(`/lessons/${lessonId}/heatmap`),
|
getLessonHeatmap: (lessonId: string): Promise<{ second: number, count: number }[]> => apiFetch(`/lessons/${lessonId}/heatmap`),
|
||||||
exportCourse: (id: string): Promise<Record<string, unknown>> => apiFetch(`/courses/${id}/export`),
|
exportCourse: (id: string): Promise<Record<string, unknown>> => apiFetch(`/courses/${id}/export`),
|
||||||
importCourse: (data: Record<string, unknown>): Promise<Course> => apiFetch(`/courses/import`, {
|
importCourse: (data: Record<string, unknown>): Promise<Course> => apiFetch(`/courses/import`, {
|
||||||
@@ -489,6 +504,10 @@ export const lmsApi = {
|
|||||||
addMember: (cohortId: string, userId: string): Promise<UserCohort> => apiFetch(`/cohorts/${cohortId}/members`, { method: 'POST', body: JSON.stringify({ user_id: userId }) }, true),
|
addMember: (cohortId: string, userId: string): Promise<UserCohort> => apiFetch(`/cohorts/${cohortId}/members`, { method: 'POST', body: JSON.stringify({ user_id: userId }) }, true),
|
||||||
removeMember: (cohortId: string, userId: string): Promise<void> => apiFetch(`/cohorts/${cohortId}/members/${userId}`, { method: 'DELETE' }, true),
|
removeMember: (cohortId: string, userId: string): Promise<void> => apiFetch(`/cohorts/${cohortId}/members/${userId}`, { method: 'DELETE' }, true),
|
||||||
getMembers: (id: string): Promise<string[]> => apiFetch(`/cohorts/${id}/members`, {}, true),
|
getMembers: (id: string): Promise<string[]> => apiFetch(`/cohorts/${id}/members`, {}, true),
|
||||||
|
getCourseGrades: (id: string, cohortId?: string): Promise<StudentGradeReport[]> => {
|
||||||
|
const query = cohortId ? `?cohort_id=${cohortId}` : '';
|
||||||
|
return apiFetch(`/courses/${id}/grades${query}`, {}, true);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface BackgroundTask {
|
export interface BackgroundTask {
|
||||||
|
|||||||
Reference in New Issue
Block a user