Merge backend branch and restore functionalities
This commit is contained in:
41
backendia/dashboard/.gitignore
vendored
Normal file
41
backendia/dashboard/.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
5
backendia/dashboard/AGENTS.md
Normal file
5
backendia/dashboard/AGENTS.md
Normal file
@@ -0,0 +1,5 @@
|
||||
<!-- BEGIN:nextjs-agent-rules -->
|
||||
# This is NOT the Next.js you know
|
||||
|
||||
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices.
|
||||
<!-- END:nextjs-agent-rules -->
|
||||
1
backendia/dashboard/CLAUDE.md
Normal file
1
backendia/dashboard/CLAUDE.md
Normal file
@@ -0,0 +1 @@
|
||||
@AGENTS.md
|
||||
36
backendia/dashboard/README.md
Normal file
36
backendia/dashboard/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
18
backendia/dashboard/eslint.config.mjs
Normal file
18
backendia/dashboard/eslint.config.mjs
Normal file
@@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
17
backendia/dashboard/next.config.ts
Normal file
17
backendia/dashboard/next.config.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: '127.0.0.1',
|
||||
port: '3000',
|
||||
pathname: '/uploads/**',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
6616
backendia/dashboard/package-lock.json
generated
Normal file
6616
backendia/dashboard/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
backendia/dashboard/package.json
Normal file
29
backendia/dashboard/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "dashboard",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^1.14.0",
|
||||
"next": "16.2.4",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4",
|
||||
"tailwind-merge": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.2.4",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
7
backendia/dashboard/postcss.config.mjs
Normal file
7
backendia/dashboard/postcss.config.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
1
backendia/dashboard/public/file.svg
Normal file
1
backendia/dashboard/public/file.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
1
backendia/dashboard/public/globe.svg
Normal file
1
backendia/dashboard/public/globe.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
1
backendia/dashboard/public/next.svg
Normal file
1
backendia/dashboard/public/next.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
backendia/dashboard/public/vercel.svg
Normal file
1
backendia/dashboard/public/vercel.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
1
backendia/dashboard/public/window.svg
Normal file
1
backendia/dashboard/public/window.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
104
backendia/dashboard/src/app/contributors/page.tsx
Normal file
104
backendia/dashboard/src/app/contributors/page.tsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import { fetchApi } from "@/lib/api";
|
||||
import { Users, Award, Camera, Clock } from "lucide-react";
|
||||
|
||||
interface Contributor {
|
||||
wallet_hash: string;
|
||||
photo_count: number;
|
||||
last_upload: string;
|
||||
}
|
||||
|
||||
export default async function ContributorsPage() {
|
||||
let contributors: Contributor[] = [];
|
||||
try {
|
||||
const response = await fetchApi('/api/contributors');
|
||||
contributors = response.contributors;
|
||||
} catch (error) {
|
||||
console.error("Error fetching contributors:", error);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="text-3xl font-bold tracking-tight">Top Contributeurs</h2>
|
||||
<p className="text-slate-400">Classement des utilisateurs selon leur contribution à l'entraînement de l'IA.</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-4 gap-6">
|
||||
{/* Stats Summary */}
|
||||
<div className="lg:col-span-1 space-y-6">
|
||||
<StatCard
|
||||
title="Total Contributeurs"
|
||||
value={contributors.length}
|
||||
icon={<Users className="text-indigo-400" />}
|
||||
/>
|
||||
<StatCard
|
||||
title="Total Photos"
|
||||
value={contributors.reduce((acc, c) => acc + c.photo_count, 0)}
|
||||
icon={<Camera className="text-emerald-400" />}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Table */}
|
||||
<div className="lg:col-span-3 bg-slate-900 border border-slate-800 rounded-2xl overflow-hidden">
|
||||
<table className="w-full text-left">
|
||||
<thead className="bg-slate-950/50 border-b border-slate-800">
|
||||
<tr>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-widest">Rang</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-widest">Wallet Hash</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-widest text-center">Photos</th>
|
||||
<th className="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-widest text-right">Dernier Upload</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-800">
|
||||
{contributors.map((c, index) => (
|
||||
<tr key={c.wallet_hash} className="hover:bg-slate-800/30 transition-colors">
|
||||
<td className="px-6 py-4">
|
||||
<div className="flex items-center gap-3">
|
||||
{index < 3 ? (
|
||||
<Award className={index === 0 ? "text-yellow-500" : index === 1 ? "text-slate-400" : "text-amber-700"} />
|
||||
) : (
|
||||
<span className="text-slate-500 font-mono w-6 text-center">#{index + 1}</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className="font-mono text-xs text-slate-300">{c.wallet_hash}</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-center">
|
||||
<span className="px-2 py-1 bg-indigo-500/10 text-indigo-400 rounded-md text-xs font-bold border border-indigo-500/20">
|
||||
{c.photo_count}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 text-right text-xs text-slate-400 flex items-center justify-end gap-2">
|
||||
<Clock size={14} />
|
||||
{new Date(c.last_upload).toLocaleString()}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{contributors.length === 0 && (
|
||||
<div className="py-24 text-center text-slate-500">
|
||||
Aucun contributeur enregistré pour le moment.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StatCard({ title, value, icon }: any) {
|
||||
return (
|
||||
<div className="bg-slate-900 border border-slate-800 p-6 rounded-2xl flex items-center justify-between">
|
||||
<div className="space-y-1">
|
||||
<p className="text-xs text-slate-500 font-bold uppercase tracking-widest">{title}</p>
|
||||
<p className="text-3xl font-bold">{value}</p>
|
||||
</div>
|
||||
<div className="w-12 h-12 bg-slate-800 rounded-xl flex items-center justify-center shadow-inner">
|
||||
{icon}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
BIN
backendia/dashboard/src/app/favicon.ico
Normal file
BIN
backendia/dashboard/src/app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
26
backendia/dashboard/src/app/globals.css
Normal file
26
backendia/dashboard/src/app/globals.css
Normal file
@@ -0,0 +1,26 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
67
backendia/dashboard/src/app/layout.tsx
Normal file
67
backendia/dashboard/src/app/layout.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import Link from "next/link";
|
||||
import { LayoutDashboard, Users, Image as ImageIcon } from "lucide-react";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Bully IA Dashboard",
|
||||
description: "Visualisation des données d'analyse de cibles",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="fr" className="dark">
|
||||
<body className={`${inter.className} bg-slate-950 text-slate-50 min-h-screen flex`}>
|
||||
{/* Sidebar */}
|
||||
<aside className="w-64 border-r border-slate-800 bg-slate-900/50 p-6 flex flex-col gap-8">
|
||||
<div className="flex items-center gap-3 px-2">
|
||||
<div className="w-8 h-8 bg-indigo-600 rounded-lg flex items-center justify-center font-bold">B</div>
|
||||
<h1 className="text-xl font-bold tracking-tight">Bully IA</h1>
|
||||
</div>
|
||||
|
||||
<nav className="flex flex-col gap-2">
|
||||
<Link
|
||||
href="/"
|
||||
className="flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-slate-800 transition-colors text-slate-300 hover:text-white"
|
||||
>
|
||||
<LayoutDashboard size={20} />
|
||||
Tableau de bord
|
||||
</Link>
|
||||
<Link
|
||||
href="/contributors"
|
||||
className="flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-slate-800 transition-colors text-slate-300 hover:text-white"
|
||||
>
|
||||
<Users size={20} />
|
||||
Contributeurs
|
||||
</Link>
|
||||
</nav>
|
||||
|
||||
<div className="mt-auto pt-6 border-t border-slate-800">
|
||||
<p className="text-xs text-slate-500 px-2">v1.0.0 Alpha</p>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="flex-1 flex flex-col">
|
||||
<header className="h-16 border-b border-slate-800 flex items-center px-8 bg-slate-900/20">
|
||||
<div className="flex items-center gap-2 text-sm text-slate-400">
|
||||
<span>Admin</span>
|
||||
<span>/</span>
|
||||
<span className="text-slate-200">Dashboard</span>
|
||||
</div>
|
||||
</header>
|
||||
<div className="flex-1 p-8 overflow-auto">
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
105
backendia/dashboard/src/app/page.tsx
Normal file
105
backendia/dashboard/src/app/page.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import { fetchApi, API_BASE_URL } from "@/lib/api";
|
||||
import DatasetToolbar from "@/components/DatasetToolbar";
|
||||
import { Calendar, User, Crosshair } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
|
||||
interface PlottingData {
|
||||
session_id: string;
|
||||
wallet_hash: string;
|
||||
timestamp: string;
|
||||
plotting: {
|
||||
impacts: any[];
|
||||
};
|
||||
}
|
||||
|
||||
interface PhotoData {
|
||||
filename: string;
|
||||
imageUrl: string;
|
||||
data: PlottingData | null;
|
||||
}
|
||||
|
||||
export default async function DashboardPage() {
|
||||
let photos: PhotoData[] = [];
|
||||
try {
|
||||
const response = await fetchApi('/api/all-data');
|
||||
photos = response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching photos:", error);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div className="flex flex-col md:flex-row md:items-end justify-between gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="text-3xl font-bold tracking-tight">Galerie des Sessions</h2>
|
||||
<p className="text-slate-400">Visualisez et gérez les données d'entraînement collectées.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DatasetToolbar />
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{photos.map((photo) => (
|
||||
<Link
|
||||
key={photo.filename}
|
||||
href={`/photo/${photo.filename}`}
|
||||
className="group relative bg-slate-900 rounded-xl border border-slate-800 overflow-hidden hover:border-indigo-500/50 transition-all hover:shadow-2xl hover:shadow-indigo-500/10"
|
||||
>
|
||||
{/* Image Preview */}
|
||||
<div className="aspect-[3/4] relative overflow-hidden bg-slate-800">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={`${API_BASE_URL}${photo.imageUrl}`}
|
||||
alt={photo.filename}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-slate-950 via-transparent to-transparent opacity-80" />
|
||||
|
||||
{/* Badge impacts */}
|
||||
{photo.data?.plotting?.impacts && (
|
||||
<div className="absolute top-3 right-3 bg-indigo-600/90 backdrop-blur-md px-2 py-1 rounded-md text-[10px] font-bold flex items-center gap-1">
|
||||
<Crosshair size={12} />
|
||||
{photo.data.plotting.impacts.length} IMPACTS
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 text-xs text-slate-400">
|
||||
<Calendar size={14} className="text-indigo-400" />
|
||||
{photo.data ? new Date(photo.data.timestamp).toLocaleDateString() : 'Date inconnue'}
|
||||
</div>
|
||||
{photo.data ? (
|
||||
<span className="text-[10px] bg-emerald-500/10 text-emerald-400 px-1.5 py-0.5 rounded border border-emerald-500/20 font-bold">DATA OK</span>
|
||||
) : (
|
||||
<span className="text-[10px] bg-rose-500/10 text-rose-400 px-1.5 py-0.5 rounded border border-rose-500/20 font-bold">NO DATA</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 text-xs text-slate-300 font-mono truncate">
|
||||
<User size={14} className="text-indigo-400" />
|
||||
{photo.data?.wallet_hash?.substring(0, 12) || 'Anonyme'}...
|
||||
</div>
|
||||
|
||||
<div className="pt-2 border-t border-slate-800 flex justify-between items-center">
|
||||
<span className="text-[10px] text-slate-500 uppercase tracking-widest font-bold">Session ID</span>
|
||||
<span className="text-xs text-slate-300 font-mono truncate max-w-[120px]">
|
||||
{photo.data?.session_id || 'N/A'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{photos.length === 0 && (
|
||||
<div className="flex flex-col items-center justify-center py-24 text-slate-500 gap-4 border-2 border-dashed border-slate-800 rounded-3xl">
|
||||
<Crosshair size={48} className="opacity-20" />
|
||||
<p>Aucune session d'entraînement trouvée.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
49
backendia/dashboard/src/app/photo/[id]/page.tsx
Normal file
49
backendia/dashboard/src/app/photo/[id]/page.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { fetchApi, API_BASE_URL } from "@/lib/api";
|
||||
import PhotoEditor from "@/components/PhotoEditor";
|
||||
import { ChevronLeft, Download } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function PhotoDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id: encodedId } = await params;
|
||||
const id = decodeURIComponent(encodedId);
|
||||
let photo = null;
|
||||
|
||||
try {
|
||||
const response = await fetchApi('/api/all-data');
|
||||
photo = response.data.find((p: any) => p.filename === id);
|
||||
} catch (error) {
|
||||
console.error("Error fetching photo detail:", error);
|
||||
}
|
||||
|
||||
if (!photo) {
|
||||
return <div className="p-12 text-center">Session non trouvée.</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Link
|
||||
href="/"
|
||||
className="flex items-center gap-2 text-slate-400 hover:text-white transition-colors"
|
||||
>
|
||||
<ChevronLeft size={20} />
|
||||
Retour à la galerie
|
||||
</Link>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<a
|
||||
href={`${API_BASE_URL}/uploads/images/${id}`}
|
||||
download
|
||||
className="flex items-center gap-2 bg-slate-800 hover:bg-slate-700 px-4 py-2 rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
<Download size={18} />
|
||||
Image Originale
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<PhotoEditor initialPhoto={photo} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
98
backendia/dashboard/src/components/DatasetToolbar.tsx
Normal file
98
backendia/dashboard/src/components/DatasetToolbar.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Download, Archive, AlertTriangle, Check, RefreshCw } from "lucide-react";
|
||||
import { API_BASE_URL } from "@/lib/api";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function DatasetToolbar() {
|
||||
const router = useRouter();
|
||||
const [isExporting, setIsExporting] = useState(false);
|
||||
const [isArchiving, setIsArchiving] = useState(false);
|
||||
const [showArchiveConfirm, setShowArchiveConfirm] = useState(false);
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsExporting(true);
|
||||
try {
|
||||
// On ouvre simplement l'URL dans un nouvel onglet pour déclencher le téléchargement
|
||||
window.open(`${API_BASE_URL}/api/export/zip`, '_blank');
|
||||
} catch (error) {
|
||||
console.error("Export error:", error);
|
||||
} finally {
|
||||
setIsExporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleArchive = async () => {
|
||||
setIsArchiving(true);
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/export/archive`, {
|
||||
method: "POST"
|
||||
});
|
||||
if (response.ok) {
|
||||
setShowArchiveConfirm(false);
|
||||
router.refresh(); // Rafraîchir la galerie
|
||||
} else {
|
||||
alert("Erreur lors de l'archivage");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Archive error:", error);
|
||||
alert("Erreur réseau");
|
||||
} finally {
|
||||
setIsArchiving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-slate-900 border border-slate-800 rounded-2xl p-6 flex flex-col md:flex-row items-center justify-between gap-6 shadow-xl shadow-indigo-500/5">
|
||||
<div className="space-y-1">
|
||||
<h3 className="font-bold text-lg flex items-center gap-2">
|
||||
<RefreshCw size={20} className="text-indigo-400" />
|
||||
Gestion du Dataset
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500">Exportez vos sessions étiquetées en ZIP et archivez-les pour nettoyer la galerie.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={handleExport}
|
||||
disabled={isExporting}
|
||||
className="flex items-center gap-2 bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 px-5 py-2.5 rounded-xl text-sm font-bold transition-all hover:scale-105 active:scale-95 shadow-lg shadow-indigo-600/20"
|
||||
>
|
||||
<Download size={18} />
|
||||
{isExporting ? "Préparation..." : "Télécharger ZIP"}
|
||||
</button>
|
||||
|
||||
{!showArchiveConfirm ? (
|
||||
<button
|
||||
onClick={() => setShowArchiveConfirm(true)}
|
||||
className="flex items-center gap-2 bg-slate-800 hover:bg-slate-700 px-5 py-2.5 rounded-xl text-sm font-bold transition-all border border-slate-700"
|
||||
>
|
||||
<Archive size={18} />
|
||||
Archiver les sessions
|
||||
</button>
|
||||
) : (
|
||||
<div className="flex items-center gap-2 animate-in fade-in slide-in-from-right-4 duration-300">
|
||||
<div className="flex items-center gap-2 px-4 py-2 bg-rose-500/10 border border-rose-500/20 rounded-xl text-rose-400 text-xs font-bold">
|
||||
<AlertTriangle size={14} />
|
||||
Vider la galerie ?
|
||||
</div>
|
||||
<button
|
||||
onClick={handleArchive}
|
||||
disabled={isArchiving}
|
||||
className="bg-rose-600 hover:bg-rose-500 p-2.5 rounded-xl transition-colors disabled:opacity-50"
|
||||
>
|
||||
<Check size={18} className="text-white" />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowArchiveConfirm(false)}
|
||||
className="bg-slate-800 hover:bg-slate-700 p-2.5 rounded-xl transition-colors"
|
||||
>
|
||||
<Archive size={18} className="text-slate-400" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
226
backendia/dashboard/src/components/PhotoEditor.tsx
Normal file
226
backendia/dashboard/src/components/PhotoEditor.tsx
Normal file
@@ -0,0 +1,226 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import PhotoOverlay from "./PhotoOverlay";
|
||||
import { Info, Calendar, User, Smartphone, Cpu, Save, Edit2, X, Trash2, Check, Tag } from "lucide-react";
|
||||
import { API_BASE_URL } from "@/lib/api";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
interface PhotoEditorProps {
|
||||
initialPhoto: any;
|
||||
}
|
||||
|
||||
const PREDEFINED_LABELS = ["bullet_hole", "tear", "miss", "rebound", "other"];
|
||||
|
||||
export default function PhotoEditor({ initialPhoto }: PhotoEditorProps) {
|
||||
const router = useRouter();
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [photoData, setPhotoData] = useState(initialPhoto.data);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const handleImpactsChange = (newImpacts: any[]) => {
|
||||
setPhotoData({
|
||||
...photoData,
|
||||
plotting: {
|
||||
...photoData.plotting,
|
||||
impacts: newImpacts
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const updateLabel = (index: number, label: string) => {
|
||||
const newImpacts = [...photoData.plotting.impacts];
|
||||
newImpacts[index] = { ...newImpacts[index], label };
|
||||
handleImpactsChange(newImpacts);
|
||||
};
|
||||
|
||||
const updateScore = (index: number, score: number) => {
|
||||
const newImpacts = [...photoData.plotting.impacts];
|
||||
newImpacts[index] = { ...newImpacts[index], score };
|
||||
handleImpactsChange(newImpacts);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/data/${initialPhoto.filename}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(photoData),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
setIsEditing(false);
|
||||
router.refresh();
|
||||
} else {
|
||||
alert("Erreur lors de la sauvegarde");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Save error:", error);
|
||||
alert("Erreur réseau");
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const impacts = photoData?.plotting?.impacts || [];
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 xl:grid-cols-3 gap-8">
|
||||
{/* Main View */}
|
||||
<div className="xl:col-span-2 space-y-4">
|
||||
<div className="flex items-center justify-between bg-slate-900/50 p-4 rounded-xl border border-slate-800">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className={`w-2 h-2 rounded-full ${isEditing ? 'bg-amber-500 animate-pulse' : 'bg-emerald-500'}`} />
|
||||
<span className="text-sm font-medium">
|
||||
{isEditing ? "Mode Édition Actif" : "Mode Visualisation"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
{isEditing ? (
|
||||
<>
|
||||
<button
|
||||
onClick={() => {
|
||||
setPhotoData(initialPhoto.data);
|
||||
setIsEditing(false);
|
||||
}}
|
||||
className="flex items-center gap-2 bg-slate-800 hover:bg-slate-700 px-4 py-2 rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
<X size={18} />
|
||||
Annuler
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isSaving}
|
||||
className="flex items-center gap-2 bg-indigo-600 hover:bg-indigo-500 px-4 py-2 rounded-lg text-sm font-medium transition-colors disabled:opacity-50"
|
||||
>
|
||||
<Save size={18} />
|
||||
{isSaving ? "Enregistrement..." : "Enregistrer"}
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setIsEditing(true)}
|
||||
className="flex items-center gap-2 bg-indigo-600 hover:bg-indigo-500 px-4 py-2 rounded-lg text-sm font-medium transition-colors"
|
||||
>
|
||||
<Edit2 size={18} />
|
||||
Modifier les points
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<PhotoOverlay
|
||||
imageUrl={`${API_BASE_URL}${initialPhoto.imageUrl}`}
|
||||
impacts={impacts}
|
||||
targetCorners={photoData?.plotting?.target_corners || []}
|
||||
isEditing={isEditing}
|
||||
onImpactsChange={handleImpactsChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Sidebar Info & Labeling */}
|
||||
<div className="space-y-6">
|
||||
{/* Labeling Section (Only if editing or has impacts) */}
|
||||
<div className="bg-slate-900 border border-slate-800 rounded-2xl p-6 space-y-4">
|
||||
<div className="flex items-center justify-between pb-4 border-b border-slate-800">
|
||||
<div className="flex items-center gap-3">
|
||||
<Tag className="text-indigo-400" size={20} />
|
||||
<h3 className="font-bold text-lg">Étiquetage (Impacts)</h3>
|
||||
</div>
|
||||
<span className="bg-slate-800 text-slate-400 text-[10px] font-bold px-2 py-0.5 rounded">
|
||||
{impacts.length} TOTAL
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 max-h-[400px] overflow-auto pr-2 custom-scrollbar">
|
||||
{impacts.map((impact: any, index: number) => (
|
||||
<div key={impact.id} className="bg-slate-950 p-3 rounded-xl border border-slate-800 space-y-3 group">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[10px] font-bold text-slate-500 uppercase">Impact #{impact.id}</span>
|
||||
{isEditing && (
|
||||
<button
|
||||
onClick={(e) => {
|
||||
const newImpacts = impacts.filter((_: any, i: number) => i !== index);
|
||||
handleImpactsChange(newImpacts);
|
||||
}}
|
||||
className="text-slate-600 hover:text-rose-500 transition-colors"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] text-slate-500 font-bold uppercase">Label</label>
|
||||
{isEditing ? (
|
||||
<select
|
||||
value={impact.label}
|
||||
onChange={(e) => updateLabel(index, e.target.value)}
|
||||
className="w-full bg-slate-900 border border-slate-800 rounded px-2 py-1 text-xs outline-none focus:border-indigo-500"
|
||||
>
|
||||
{PREDEFINED_LABELS.map(l => <option key={l} value={l}>{l}</option>)}
|
||||
</select>
|
||||
) : (
|
||||
<div className="text-xs text-indigo-300 font-medium">{impact.label}</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] text-slate-500 font-bold uppercase">Score</label>
|
||||
{isEditing ? (
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
max="10"
|
||||
value={impact.score}
|
||||
onChange={(e) => updateScore(index, parseInt(e.target.value) || 0)}
|
||||
className="w-full bg-slate-900 border border-slate-800 rounded px-2 py-1 text-xs outline-none focus:border-indigo-500"
|
||||
/>
|
||||
) : (
|
||||
<div className="text-xs text-emerald-400 font-bold">{impact.score}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{impacts.length === 0 && (
|
||||
<p className="text-center py-8 text-xs text-slate-500 italic">
|
||||
Aucun impact détecté. {isEditing ? "Cliquez sur l'image pour en ajouter." : ""}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Metadata Card (Read Only) */}
|
||||
<div className="bg-slate-900/50 border border-slate-800 rounded-2xl p-6 space-y-4 opacity-80">
|
||||
<div className="flex items-center gap-3 pb-2 border-b border-slate-800">
|
||||
<Info className="text-slate-400" size={18} />
|
||||
<h3 className="font-bold text-sm text-slate-300">Métadonnées Session</h3>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<InfoItem icon={<Calendar size={14} />} label="Date" value={photoData ? new Date(photoData.timestamp).toLocaleString() : 'Inconnue'} />
|
||||
<InfoItem icon={<User size={14} />} label="Contributeur" value={photoData?.wallet_hash || 'Anonyme'} isMono />
|
||||
<InfoItem icon={<Smartphone size={14} />} label="Appareil" value={photoData?.device_info?.model || 'Inconnu'} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InfoItem({ icon, label, value, isMono = false }: any) {
|
||||
return (
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-slate-500 font-bold uppercase">
|
||||
{icon}
|
||||
{label}
|
||||
</div>
|
||||
<p className={`text-xs text-slate-300 ${isMono ? 'font-mono truncate' : ''}`}>
|
||||
{value}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
183
backendia/dashboard/src/components/PhotoOverlay.tsx
Normal file
183
backendia/dashboard/src/components/PhotoOverlay.tsx
Normal file
@@ -0,0 +1,183 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
interface Point {
|
||||
norm_x: number;
|
||||
norm_y: number;
|
||||
}
|
||||
|
||||
interface Impact {
|
||||
id: number;
|
||||
label: string;
|
||||
score: number;
|
||||
coords: Point;
|
||||
}
|
||||
|
||||
interface PhotoOverlayProps {
|
||||
imageUrl: string;
|
||||
impacts: Impact[];
|
||||
targetCorners: Point[];
|
||||
isEditing?: boolean;
|
||||
onImpactsChange?: (impacts: Impact[]) => void;
|
||||
}
|
||||
|
||||
export default function PhotoOverlay({
|
||||
imageUrl,
|
||||
impacts,
|
||||
targetCorners,
|
||||
isEditing = false,
|
||||
onImpactsChange
|
||||
}: PhotoOverlayProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
||||
const [dragIndex, setDragIndex] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const updateDimensions = () => {
|
||||
if (containerRef.current) {
|
||||
setDimensions({
|
||||
width: containerRef.current.offsetWidth,
|
||||
height: containerRef.current.offsetHeight,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
updateDimensions();
|
||||
window.addEventListener("resize", updateDimensions);
|
||||
return () => window.removeEventListener("resize", updateDimensions);
|
||||
}, []);
|
||||
|
||||
const handleImageClick = (e: React.MouseEvent) => {
|
||||
if (!isEditing || !onImpactsChange || dragIndex !== null) return;
|
||||
|
||||
const rect = containerRef.current?.getBoundingClientRect();
|
||||
if (!rect) return;
|
||||
|
||||
// Calculer les coordonnées normalisées
|
||||
const x = (e.clientX - rect.left) / dimensions.width;
|
||||
const y = (e.clientY - rect.top) / dimensions.height;
|
||||
|
||||
// Créer un nouvel impact
|
||||
const newImpact: Impact = {
|
||||
id: impacts.length > 0 ? Math.max(...impacts.map(i => i.id)) + 1 : 1,
|
||||
label: "bullet_hole",
|
||||
score: 10,
|
||||
coords: { norm_x: x, norm_y: y }
|
||||
};
|
||||
|
||||
onImpactsChange([...impacts, newImpact]);
|
||||
};
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent) => {
|
||||
if (dragIndex === null || !onImpactsChange) return;
|
||||
|
||||
const rect = containerRef.current?.getBoundingClientRect();
|
||||
if (!rect) return;
|
||||
|
||||
const x = (e.clientX - rect.left) / dimensions.width;
|
||||
const y = (e.clientY - rect.top) / dimensions.height;
|
||||
|
||||
const newImpacts = [...impacts];
|
||||
newImpacts[dragIndex] = {
|
||||
...newImpacts[dragIndex],
|
||||
coords: { norm_x: x, norm_y: y }
|
||||
};
|
||||
|
||||
onImpactsChange(newImpacts);
|
||||
};
|
||||
|
||||
const deleteImpact = (e: React.MouseEvent, index: number) => {
|
||||
e.stopPropagation();
|
||||
if (!isEditing || !onImpactsChange) return;
|
||||
const newImpacts = impacts.filter((_, i) => i !== index);
|
||||
onImpactsChange(newImpacts);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`relative w-full flex items-center justify-center bg-slate-900 rounded-2xl overflow-hidden border border-slate-800 shadow-2xl min-h-[400px] ${isEditing ? 'cursor-crosshair' : ''}`}
|
||||
onClick={handleImageClick}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseUp={() => setDragIndex(null)}
|
||||
onMouseLeave={() => setDragIndex(null)}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={imageUrl}
|
||||
alt="Target Analysis"
|
||||
className="max-w-full max-h-[80vh] object-contain select-none"
|
||||
draggable={false}
|
||||
onLoad={(e) => {
|
||||
const img = e.currentTarget;
|
||||
setDimensions({ width: img.clientWidth, height: img.clientHeight });
|
||||
}}
|
||||
/>
|
||||
|
||||
{dimensions.width > 0 && (
|
||||
<svg
|
||||
className="absolute pointer-events-none"
|
||||
viewBox={`0 0 ${dimensions.width} ${dimensions.height}`}
|
||||
style={{ width: dimensions.width, height: dimensions.height }}
|
||||
>
|
||||
{/* Draw Target Box if corners exist */}
|
||||
{targetCorners && targetCorners.length === 4 && (
|
||||
<polygon
|
||||
points={targetCorners.map(c => `${c.norm_x * dimensions.width},${c.norm_y * dimensions.height}`).join(' ')}
|
||||
fill="rgba(79, 70, 229, 0.15)"
|
||||
stroke="#6366f1"
|
||||
strokeWidth="2"
|
||||
strokeDasharray="4 2"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Draw Impacts */}
|
||||
{impacts.map((impact, index) => (
|
||||
<g key={impact.id}>
|
||||
{/* Glow effect */}
|
||||
<circle
|
||||
cx={impact.coords.norm_x * dimensions.width}
|
||||
cy={impact.coords.norm_y * dimensions.height}
|
||||
r={isEditing ? "12" : "8"}
|
||||
fill={isEditing ? "rgba(244, 63, 94, 0.2)" : "rgba(244, 63, 94, 0.3)"}
|
||||
className={isEditing ? 'pointer-events-auto cursor-move' : ''}
|
||||
onMouseDown={(e) => {
|
||||
if (!isEditing) return;
|
||||
e.stopPropagation();
|
||||
setDragIndex(index);
|
||||
}}
|
||||
onContextMenu={(e) => deleteImpact(e, index)}
|
||||
/>
|
||||
{/* Main circle */}
|
||||
<circle
|
||||
cx={impact.coords.norm_x * dimensions.width}
|
||||
cy={impact.coords.norm_y * dimensions.height}
|
||||
r="5"
|
||||
fill="#f43f5e"
|
||||
stroke="white"
|
||||
strokeWidth="1.5"
|
||||
/>
|
||||
{/* Score text */}
|
||||
<text
|
||||
x={impact.coords.norm_x * dimensions.width}
|
||||
y={impact.coords.norm_y * dimensions.height - 10}
|
||||
className="text-[12px] font-bold fill-white text-center select-none"
|
||||
textAnchor="middle"
|
||||
style={{ textShadow: '0 0 4px rgba(0,0,0,0.9), 1px 1px 0 rgba(0,0,0,0.9)' }}
|
||||
>
|
||||
{impact.score}
|
||||
</text>
|
||||
</g>
|
||||
))}
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{isEditing && (
|
||||
<div className="absolute bottom-4 right-4 bg-slate-950/80 backdrop-blur-md px-3 py-1.5 rounded-full text-[10px] font-bold text-indigo-400 border border-indigo-500/30">
|
||||
MODE ÉDITION : CLIC POUR AJOUTER • DRAG POUR DÉPLACER • CLIC DROIT POUR SUPPRIMER
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
11
backendia/dashboard/src/lib/api.ts
Normal file
11
backendia/dashboard/src/lib/api.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const API_BASE_URL = 'http://127.0.0.1:3000';
|
||||
|
||||
export async function fetchApi(endpoint: string) {
|
||||
const res = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
cache: 'no-store',
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to fetch ${endpoint}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
34
backendia/dashboard/tsconfig.json
Normal file
34
backendia/dashboard/tsconfig.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user