Initial commit: EduBox V2 platform
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { signIn } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function LoginForm() {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
const res = await signIn("credentials", { email, password, redirect: false });
|
||||
setLoading(false);
|
||||
if (res?.error) {
|
||||
setError("Email ou mot de passe invalide");
|
||||
} else {
|
||||
router.push("/dashboard");
|
||||
router.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{error && <div className="text-sm text-destructive text-center">{error}</div>}
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Email</label>
|
||||
<Input type="email" value={email} onChange={(e) => setEmail(e.target.value)} required />
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Mot de passe</label>
|
||||
<Input type="password" value={password} onChange={(e) => setPassword(e.target.value)} required />
|
||||
</div>
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading ? "Connexion..." : "Se connecter"}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import LoginForm from "./LoginForm";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gray-50">
|
||||
<div className="w-full max-w-md p-8 space-y-6 bg-white rounded-lg shadow-md">
|
||||
<h1 className="text-2xl font-bold text-center text-gray-900">EduBox V2</h1>
|
||||
<p className="text-center text-muted-foreground">Connexion à la plateforme</p>
|
||||
<LoginForm />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import NextAuth from "next-auth";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
|
||||
const handler = NextAuth(authOptions);
|
||||
|
||||
export { handler as GET, handler as POST };
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const establishmentId = searchParams.get("establishmentId");
|
||||
if (!establishmentId) return NextResponse.json({ error: "Missing establishmentId" }, { status: 400 });
|
||||
|
||||
const classes = await prisma.class.findMany({
|
||||
where: { establishmentId },
|
||||
include: { _count: { select: { students: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return NextResponse.json(classes);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { establishmentId, name, level } = body;
|
||||
const cls = await prisma.class.create({
|
||||
data: { establishmentId, name, level },
|
||||
});
|
||||
return NextResponse.json(cls, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({
|
||||
windows: "/agent/edubox-agent.exe",
|
||||
linux: "/agent/edubox-agent",
|
||||
mac: "/agent/edubox-agent-mac",
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { hashPassword } from "@/lib/auth";
|
||||
|
||||
export async function GET() {
|
||||
const establishments = await prisma.establishment.findMany({
|
||||
include: { subscription: true, _count: { select: { users: true, classes: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return NextResponse.json(establishments);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { name, slug, adminEmail, adminPassword } = body;
|
||||
|
||||
const establishment = await prisma.establishment.create({
|
||||
data: { name, slug },
|
||||
});
|
||||
|
||||
await prisma.subscription.create({
|
||||
data: { establishmentId: establishment.id, plan: "trial", status: "active" },
|
||||
});
|
||||
|
||||
if (adminEmail && adminPassword) {
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
email: adminEmail,
|
||||
password: await hashPassword(adminPassword),
|
||||
role: "admin",
|
||||
establishmentId: establishment.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json(establishment, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { sendToNode } from "@/lib/websocket";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const nodeId = searchParams.get("nodeId");
|
||||
const establishmentId = searchParams.get("establishmentId");
|
||||
|
||||
let where: any = {};
|
||||
if (nodeId) where.nodeId = nodeId;
|
||||
if (establishmentId) {
|
||||
const classes = await prisma.class.findMany({ where: { establishmentId }, select: { id: true } });
|
||||
const students = await prisma.student.findMany({ where: { classId: { in: classes.map((c) => c.id) } }, select: { id: true } });
|
||||
const nodes = await prisma.node.findMany({ where: { studentId: { in: students.map((s) => s.id) } }, select: { id: true } });
|
||||
where.nodeId = { in: nodes.map((n) => n.id) };
|
||||
}
|
||||
|
||||
const instances = await prisma.instance.findMany({
|
||||
where,
|
||||
include: { node: { include: { student: { include: { class: true } } } }, template: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return NextResponse.json(instances);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { nodeId, templateId, port } = body;
|
||||
|
||||
const template = await prisma.template.findUnique({ where: { id: templateId } });
|
||||
if (!template) return NextResponse.json({ error: "Template not found" }, { status: 404 });
|
||||
|
||||
const instance = await prisma.instance.create({
|
||||
data: { nodeId, templateId, port: port || 8080, status: "stopped" },
|
||||
});
|
||||
|
||||
const sent = sendToNode(nodeId, {
|
||||
action: "start",
|
||||
instanceId: instance.id,
|
||||
type: template.type,
|
||||
port: instance.port,
|
||||
composeConfig: template.composeConfig.replace(/{PORT}/g, String(instance.port)).replace(/{INSTANCE_ID}/g, instance.id),
|
||||
});
|
||||
|
||||
if (!sent) {
|
||||
await prisma.instance.update({ where: { id: instance.id }, data: { status: "error" } });
|
||||
}
|
||||
|
||||
return NextResponse.json(instance, { status: 201 });
|
||||
}
|
||||
|
||||
export async function PATCH(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { id, action } = body;
|
||||
const instance = await prisma.instance.findUnique({ where: { id }, include: { template: true } });
|
||||
if (!instance) return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
|
||||
if (action === "stop") {
|
||||
sendToNode(instance.nodeId, { action: "stop", instanceId: instance.id });
|
||||
await prisma.instance.update({ where: { id }, data: { status: "stopped" } });
|
||||
} else if (action === "start") {
|
||||
const sent = sendToNode(instance.nodeId, {
|
||||
action: "start",
|
||||
instanceId: instance.id,
|
||||
type: instance.template.type,
|
||||
port: instance.port,
|
||||
composeConfig: instance.template.composeConfig.replace(/{PORT}/g, String(instance.port)).replace(/{INSTANCE_ID}/g, instance.id),
|
||||
});
|
||||
if (!sent) await prisma.instance.update({ where: { id }, data: { status: "error" } });
|
||||
} else if (action === "reset") {
|
||||
sendToNode(instance.nodeId, { action: "reset", instanceId: instance.id });
|
||||
}
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
if (!id) return NextResponse.json({ error: "Missing id" }, { status: 400 });
|
||||
const instance = await prisma.instance.findUnique({ where: { id } });
|
||||
if (instance) sendToNode(instance.nodeId, { action: "stop", instanceId: instance.id });
|
||||
await prisma.instance.delete({ where: { id } });
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const establishmentId = searchParams.get("establishmentId");
|
||||
|
||||
let where: any = {};
|
||||
if (establishmentId) {
|
||||
const classes = await prisma.class.findMany({ where: { establishmentId }, select: { id: true } });
|
||||
const students = await prisma.student.findMany({ where: { classId: { in: classes.map((c) => c.id) } }, select: { id: true } });
|
||||
where.studentId = { in: students.map((s) => s.id) };
|
||||
}
|
||||
|
||||
const nodes = await prisma.node.findMany({
|
||||
where,
|
||||
include: { student: { include: { class: true } }, instances: true },
|
||||
orderBy: { lastSeen: "desc" },
|
||||
});
|
||||
return NextResponse.json(nodes);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
function generateCode(length = 6) {
|
||||
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
let code = "";
|
||||
for (let i = 0; i < length; i++) code += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
return code;
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const classId = searchParams.get("classId");
|
||||
const establishmentId = searchParams.get("establishmentId");
|
||||
|
||||
const where: any = {};
|
||||
if (classId) where.classId = classId;
|
||||
if (establishmentId) {
|
||||
const classes = await prisma.class.findMany({ where: { establishmentId }, select: { id: true } });
|
||||
where.classId = { in: classes.map((c) => c.id) };
|
||||
}
|
||||
|
||||
const students = await prisma.student.findMany({
|
||||
where,
|
||||
include: { class: true, nodes: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return NextResponse.json(students);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { classId, firstName, lastName, email } = body;
|
||||
const student = await prisma.student.create({
|
||||
data: {
|
||||
classId,
|
||||
firstName,
|
||||
lastName,
|
||||
email,
|
||||
activationCode: generateCode(),
|
||||
},
|
||||
});
|
||||
return NextResponse.json(student, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const establishmentId = searchParams.get("establishmentId");
|
||||
|
||||
const templates = await prisma.template.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ isPublic: true },
|
||||
...(establishmentId ? [{ establishmentId }] : []),
|
||||
],
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return NextResponse.json(templates);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { name, type, dockerImage, composeConfig, isPublic, establishmentId, createdBy } = body;
|
||||
const template = await prisma.template.create({
|
||||
data: { name, type, dockerImage, composeConfig, isPublic, establishmentId, createdBy },
|
||||
});
|
||||
return NextResponse.json(template, { status: 201 });
|
||||
}
|
||||
|
||||
export async function PUT(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { id, ...data } = body;
|
||||
const template = await prisma.template.update({ where: { id }, data });
|
||||
return NextResponse.json(template);
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
if (!id) return NextResponse.json({ error: "Missing id" }, { status: 400 });
|
||||
await prisma.template.delete({ where: { id } });
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { hashPassword } from "@/lib/auth";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const establishmentId = searchParams.get("establishmentId");
|
||||
const role = searchParams.get("role");
|
||||
|
||||
const where: any = {};
|
||||
if (establishmentId) where.establishmentId = establishmentId;
|
||||
if (role) where.role = role;
|
||||
|
||||
const users = await prisma.user.findMany({
|
||||
where,
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
return NextResponse.json(users);
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { email, password, role, establishmentId } = body;
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email,
|
||||
password: await hashPassword(password),
|
||||
role,
|
||||
establishmentId,
|
||||
},
|
||||
});
|
||||
return NextResponse.json(user, { status: 201 });
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
if (!id) return NextResponse.json({ error: "Missing id" }, { status: 400 });
|
||||
await prisma.user.delete({ where: { id } });
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { WebSocketServer } from "ws";
|
||||
import { initWebSocketServer } from "@/lib/websocket";
|
||||
|
||||
const globalWss = globalThis as typeof globalThis & { __eduboxWss?: WebSocketServer };
|
||||
|
||||
if (!globalWss.__eduboxWss) {
|
||||
try {
|
||||
globalWss.__eduboxWss = new WebSocketServer({ port: 3001 });
|
||||
initWebSocketServer(globalWss.__eduboxWss);
|
||||
} catch {
|
||||
// Port may be in use during build or hot reload
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return new Response("WebSocket server running on port 3001", { status: 200 });
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { signOut } from "next-auth/react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const links = [
|
||||
{ href: "/dashboard", label: "Accueil" },
|
||||
{ href: "/dashboard/classes", label: "Classes" },
|
||||
{ href: "/dashboard/students", label: "Étudiants" },
|
||||
{ href: "/dashboard/nodes", label: "Nœuds" },
|
||||
{ href: "/dashboard/instances", label: "Instances" },
|
||||
{ href: "/dashboard/templates", label: "Templates" },
|
||||
{ href: "/dashboard/download", label: "Téléchargements" },
|
||||
];
|
||||
|
||||
const superadminLinks = [
|
||||
{ href: "/superadmin", label: "Super Admin" },
|
||||
{ href: "/superadmin/establishments", label: "Établissements" },
|
||||
];
|
||||
|
||||
export default function DashboardNav({ role }: { role: string }) {
|
||||
const pathname = usePathname();
|
||||
|
||||
return (
|
||||
<nav className="w-64 bg-white border-r flex flex-col">
|
||||
<div className="p-6 border-b">
|
||||
<h2 className="text-xl font-bold text-primary">EduBox</h2>
|
||||
</div>
|
||||
<div className="flex-1 p-4 space-y-1">
|
||||
{links.map((link) => (
|
||||
<Link
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className={cn(
|
||||
"block px-3 py-2 rounded-md text-sm font-medium transition-colors",
|
||||
pathname === link.href ? "bg-primary text-primary-foreground" : "text-gray-700 hover:bg-gray-100"
|
||||
)}
|
||||
>
|
||||
{link.label}
|
||||
</Link>
|
||||
))}
|
||||
{role === "superadmin" && (
|
||||
<div className="pt-4 mt-4 border-t">
|
||||
<p className="px-3 text-xs font-semibold text-muted-foreground uppercase mb-2">Super Admin</p>
|
||||
{superadminLinks.map((link) => (
|
||||
<Link
|
||||
key={link.href}
|
||||
href={link.href}
|
||||
className={cn(
|
||||
"block px-3 py-2 rounded-md text-sm font-medium transition-colors",
|
||||
pathname === link.href ? "bg-primary text-primary-foreground" : "text-gray-700 hover:bg-gray-100"
|
||||
)}
|
||||
>
|
||||
{link.label}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="p-4 border-t">
|
||||
<button
|
||||
onClick={() => signOut({ callbackUrl: "/login" })}
|
||||
className="w-full text-left px-3 py-2 text-sm font-medium text-destructive hover:bg-destructive/10 rounded-md transition-colors"
|
||||
>
|
||||
Déconnexion
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function ClassesPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
const classes = await prisma.class.findMany({
|
||||
where: establishmentId ? { establishmentId } : {},
|
||||
include: { _count: { select: { students: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Classes</h1>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Niveau</TableHead>
|
||||
<TableHead>Étudiants</TableHead>
|
||||
<TableHead>Créée le</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{classes.map((cls) => (
|
||||
<TableRow key={cls.id}>
|
||||
<TableCell className="font-medium">{cls.name}</TableCell>
|
||||
<TableCell>{cls.level}</TableCell>
|
||||
<TableCell>{cls._count.students}</TableCell>
|
||||
<TableCell>{new Date(cls.createdAt).toLocaleDateString("fr-FR")}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{classes.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4} className="text-center text-muted-foreground">Aucune classe</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default function DownloadPage() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Téléchargements Agent</h1>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Windows</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground mb-4">Agent EduBox pour Windows (64 bits)</p>
|
||||
<a href="/agent/edubox-agent.exe" download className="inline-flex items-center justify-center rounded-md text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full">Télécharger (.exe)</a>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Linux</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground mb-4">Agent EduBox pour Linux (64 bits)</p>
|
||||
<a href="/agent/edubox-agent" download className="inline-flex items-center justify-center rounded-md text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full">Télécharger</a>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>macOS</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground mb-4">Agent EduBox pour macOS (Intel & Apple Silicon)</p>
|
||||
<a href="/agent/edubox-agent-mac" download className="inline-flex items-center justify-center rounded-md text-sm font-medium bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full">Télécharger</a>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function InstanceActions({ instanceId, status }: { instanceId: string; status: string }) {
|
||||
const [loading, setLoading] = useState<string | null>(null);
|
||||
|
||||
async function action(type: string) {
|
||||
setLoading(type);
|
||||
await fetch("/api/instances", {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ id: instanceId, action: type }),
|
||||
});
|
||||
setLoading(null);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
{status !== "running" && (
|
||||
<Button size="sm" variant="outline" onClick={() => action("start")} disabled={!!loading}>
|
||||
{loading === "start" ? "..." : "Démarrer"}
|
||||
</Button>
|
||||
)}
|
||||
{status === "running" && (
|
||||
<Button size="sm" variant="outline" onClick={() => action("stop")} disabled={!!loading}>
|
||||
{loading === "stop" ? "..." : "Arrêter"}
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" variant="outline" onClick={() => action("reset")} disabled={!!loading}>
|
||||
{loading === "reset" ? "..." : "Réinitialiser"}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select } from "@/components/ui/select";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export default function AssignForm({ templates, nodes }: { templates: any[]; nodes: any[] }) {
|
||||
const [templateId, setTemplateId] = useState("");
|
||||
const [nodeId, setNodeId] = useState("");
|
||||
const [port, setPort] = useState("8080");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
await fetch("/api/instances", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ templateId, nodeId, port: parseInt(port) }),
|
||||
});
|
||||
setLoading(false);
|
||||
router.push("/dashboard/instances");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4 bg-white p-6 rounded-lg border shadow-sm">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Template</label>
|
||||
<Select value={templateId} onChange={(e) => setTemplateId(e.target.value)} required>
|
||||
<option value="">Choisir un template</option>
|
||||
{templates.map((t) => (
|
||||
<option key={t.id} value={t.id}>{t.name}</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Nœud (étudiant)</label>
|
||||
<Select value={nodeId} onChange={(e) => setNodeId(e.target.value)} required>
|
||||
<option value="">Choisir un nœud</option>
|
||||
{nodes.map((n) => (
|
||||
<option key={n.id} value={n.id}>
|
||||
{n.id} {n.student ? `- ${n.student.firstName} ${n.student.lastName}` : ""}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Port</label>
|
||||
<Input type="number" value={port} onChange={(e) => setPort(e.target.value)} required />
|
||||
</div>
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading ? "Attribution..." : "Attribuer"}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import AssignForm from "./AssignForm";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AssignPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
const templates = await prisma.template.findMany({
|
||||
where: { OR: [{ isPublic: true }, ...(establishmentId ? [{ establishmentId }] : [])] },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
const nodes = await prisma.node.findMany({
|
||||
where: establishmentId
|
||||
? { student: { class: { establishmentId } } }
|
||||
: {},
|
||||
include: { student: { include: { class: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-xl">
|
||||
<h1 className="text-3xl font-bold">Attribuer une instance</h1>
|
||||
<AssignForm templates={templates} nodes={nodes} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import InstanceActions from "./InstanceActions";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function InstancesPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
const instances = await prisma.instance.findMany({
|
||||
where: establishmentId
|
||||
? { node: { student: { class: { establishmentId } } } }
|
||||
: {},
|
||||
include: { node: { include: { student: { include: { class: true } } } }, template: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-3xl font-bold">Instances</h1>
|
||||
<Link href="/dashboard/instances/assign">
|
||||
<Button>Attribuer une instance</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>ID</TableHead>
|
||||
<TableHead>Template</TableHead>
|
||||
<TableHead>Nœud</TableHead>
|
||||
<TableHead>Étudiant</TableHead>
|
||||
<TableHead>Port</TableHead>
|
||||
<TableHead>Statut</TableHead>
|
||||
<TableHead>Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{instances.map((inst) => (
|
||||
<TableRow key={inst.id}>
|
||||
<TableCell className="font-medium">{inst.id.slice(0, 8)}...</TableCell>
|
||||
<TableCell>{inst.template.name}</TableCell>
|
||||
<TableCell>{inst.node.id.slice(0, 8)}...</TableCell>
|
||||
<TableCell>{inst.node.student ? `${inst.node.student.firstName} ${inst.node.student.lastName}` : "-"}</TableCell>
|
||||
<TableCell>{inst.port}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={inst.status === "running" ? "success" : inst.status === "error" ? "destructive" : "secondary"}>{inst.status}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<InstanceActions instanceId={inst.id} status={inst.status} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{instances.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-center text-muted-foreground">Aucune instance</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import DashboardNav from "./DashboardNav";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function DashboardLayout({ children }: { children: React.ReactNode }) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen bg-gray-50">
|
||||
<DashboardNav role={session.user.role} />
|
||||
<main className="flex-1 p-6 overflow-auto">{children}</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function NodesPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
const nodes = await prisma.node.findMany({
|
||||
where: establishmentId
|
||||
? { student: { class: { establishmentId } } }
|
||||
: {},
|
||||
include: { student: { include: { class: true } }, instances: true },
|
||||
orderBy: { lastSeen: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Nœuds</h1>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>ID</TableHead>
|
||||
<TableHead>Étudiant</TableHead>
|
||||
<TableHead>IP Tailscale</TableHead>
|
||||
<TableHead>Statut</TableHead>
|
||||
<TableHead>Instances</TableHead>
|
||||
<TableHead>Dernière vue</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{nodes.map((n) => (
|
||||
<TableRow key={n.id}>
|
||||
<TableCell className="font-medium">{n.id}</TableCell>
|
||||
<TableCell>{n.student ? `${n.student.firstName} ${n.student.lastName}` : "-"}</TableCell>
|
||||
<TableCell>{n.tailscaleIp || "-"}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={n.status === "online" ? "success" : "secondary"}>{n.status}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>{n.instances.length}</TableCell>
|
||||
<TableCell>{n.lastSeen ? new Date(n.lastSeen).toLocaleString("fr-FR") : "-"}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{nodes.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-muted-foreground">Aucun nœud</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
|
||||
const isSuperadmin = session.user.role === "superadmin";
|
||||
const establishmentId = session.user.establishmentId;
|
||||
|
||||
const where = isSuperadmin ? {} : { establishmentId };
|
||||
|
||||
const nodesCount = await prisma.node.count({
|
||||
where: isSuperadmin ? {} : { student: { class: { establishmentId } } },
|
||||
});
|
||||
const onlineNodes = await prisma.node.count({
|
||||
where: isSuperadmin ? { status: "online" } : { status: "online", student: { class: { establishmentId } } },
|
||||
});
|
||||
const instancesRunning = await prisma.instance.count({
|
||||
where: isSuperadmin ? { status: "running" } : { status: "running", node: { student: { class: { establishmentId } } } },
|
||||
});
|
||||
const studentsCount = await prisma.student.count({
|
||||
where: isSuperadmin ? {} : { class: { establishmentId } },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Tableau de bord</h1>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">Nœuds</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-3xl font-bold">{nodesCount}</div>
|
||||
<Badge variant="success" className="mt-2">{onlineNodes} en ligne</Badge>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">Instances actives</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-3xl font-bold">{instancesRunning}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">Étudiants</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-3xl font-bold">{studentsCount}</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">Statut</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Badge variant="success">Opérationnel</Badge>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function StudentsPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
const students = await prisma.student.findMany({
|
||||
where: establishmentId ? { class: { establishmentId } } : {},
|
||||
include: { class: true, nodes: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Étudiants</h1>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Classe</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Code activation</TableHead>
|
||||
<TableHead>Nœud</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{students.map((s) => {
|
||||
const node = s.nodes[0];
|
||||
return (
|
||||
<TableRow key={s.id}>
|
||||
<TableCell className="font-medium">{s.firstName} {s.lastName}</TableCell>
|
||||
<TableCell>{s.class.name}</TableCell>
|
||||
<TableCell>{s.email}</TableCell>
|
||||
<TableCell>{s.activationCode || "-"}</TableCell>
|
||||
<TableCell>
|
||||
{node ? (
|
||||
<Badge variant={node.status === "online" ? "success" : "secondary"}>{node.status}</Badge>
|
||||
) : (
|
||||
<Badge variant="outline">Non lié</Badge>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
{students.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-center text-muted-foreground">Aucun étudiant</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function TemplatesPage() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
const templates = await prisma.template.findMany({
|
||||
where: { OR: [{ isPublic: true }, ...(establishmentId ? [{ establishmentId }] : [])] },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Templates</h1>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Type</TableHead>
|
||||
<TableHead>Image Docker</TableHead>
|
||||
<TableHead>Visibilité</TableHead>
|
||||
<TableHead>Créé par</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{templates.map((t) => (
|
||||
<TableRow key={t.id}>
|
||||
<TableCell className="font-medium">{t.name}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="secondary">{t.type}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>{t.dockerImage}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={t.isPublic ? "success" : "outline"}>{t.isPublic ? "Public" : "Privé"}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>{t.createdBy}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{templates.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-center text-muted-foreground">Aucun template</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--background: 0 0% 100%;
|
||||
--foreground: 222.2 84% 4.9%;
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 222.2 84% 4.9%;
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 222.2 84% 4.9%;
|
||||
--primary: 221.2 83.2% 53.3%;
|
||||
--primary-foreground: 210 40% 98%;
|
||||
--secondary: 210 40% 96.1%;
|
||||
--secondary-foreground: 222.2 47.4% 11.2%;
|
||||
--muted: 210 40% 96.1%;
|
||||
--muted-foreground: 215.4 16.3% 46.9%;
|
||||
--accent: 210 40% 96.1%;
|
||||
--accent-foreground: 222.2 47.4% 11.2%;
|
||||
--destructive: 0 84.2% 60.2%;
|
||||
--destructive-foreground: 210 40% 98%;
|
||||
--border: 214.3 31.8% 91.4%;
|
||||
--input: 214.3 31.8% 91.4%;
|
||||
--ring: 221.2 83.2% 53.3%;
|
||||
--radius: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "EduBox V2",
|
||||
description: "Plateforme de gestion d'instances pour l'enseignement BTS",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<html lang="fr">
|
||||
<body className={inter.className}>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
export default function Home() {
|
||||
redirect('/dashboard')
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function EstablishmentsPage() {
|
||||
const establishments = await prisma.establishment.findMany({
|
||||
include: { subscription: true, _count: { select: { users: true, classes: true } } },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Établissements</h1>
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Slug</TableHead>
|
||||
<TableHead>Plan</TableHead>
|
||||
<TableHead>Statut</TableHead>
|
||||
<TableHead>Utilisateurs</TableHead>
|
||||
<TableHead>Classes</TableHead>
|
||||
<TableHead>Expiration</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{establishments.map((e) => (
|
||||
<TableRow key={e.id}>
|
||||
<TableCell className="font-medium">{e.name}</TableCell>
|
||||
<TableCell>{e.slug}</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant="secondary">{e.subscription?.plan || "-"}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={e.subscription?.status === "active" ? "success" : "destructive"}>{e.subscription?.status || "-"}</Badge>
|
||||
</TableCell>
|
||||
<TableCell>{e._count.users}</TableCell>
|
||||
<TableCell>{e._count.classes}</TableCell>
|
||||
<TableCell>{e.subscription?.expiresAt ? new Date(e.subscription.expiresAt).toLocaleDateString("fr-FR") : "-"}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{establishments.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-center text-muted-foreground">Aucun établissement</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function SuperAdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user || session.user.role !== "superadmin") redirect("/dashboard");
|
||||
return <>{children}</>;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function SuperAdminPage() {
|
||||
const establishments = await prisma.establishment.count();
|
||||
const users = await prisma.user.count();
|
||||
const students = await prisma.student.count();
|
||||
const nodesOnline = await prisma.node.count({ where: { status: "online" } });
|
||||
const instancesRunning = await prisma.instance.count({ where: { status: "running" } });
|
||||
const activeSubs = await prisma.subscription.count({ where: { status: "active" } });
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-3xl font-bold">Super Admin — Vue globale</h1>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-3 gap-4">
|
||||
<Card>
|
||||
<CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Établissements</CardTitle></CardHeader>
|
||||
<CardContent><div className="text-3xl font-bold">{establishments}</div></CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Utilisateurs</CardTitle></CardHeader>
|
||||
<CardContent><div className="text-3xl font-bold">{users}</div></CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Étudiants</CardTitle></CardHeader>
|
||||
<CardContent><div className="text-3xl font-bold">{students}</div></CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Nœuds en ligne</CardTitle></CardHeader>
|
||||
<CardContent><div className="text-3xl font-bold">{nodesOnline}</div></CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Instances running</CardTitle></CardHeader>
|
||||
<CardContent><div className="text-3xl font-bold">{instancesRunning}</div></CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Abonnements actifs</CardTitle></CardHeader>
|
||||
<CardContent><div className="text-3xl font-bold">{activeSubs}</div></CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user