Initial commit
This commit is contained in:
13
svar-gantt-app/src/app.d.ts
vendored
Normal file
13
svar-gantt-app/src/app.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
12
svar-gantt-app/src/app.html
Normal file
12
svar-gantt-app/src/app.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
32
svar-gantt-app/src/lib/GanttClientOnly.svelte
Normal file
32
svar-gantt-app/src/lib/GanttClientOnly.svelte
Normal file
@ -0,0 +1,32 @@
|
||||
<script>
|
||||
import { onMount } from "svelte";
|
||||
import { Gantt, Willow } from "wx-svelte-gantt";
|
||||
|
||||
export let tasks = [];
|
||||
export let links = [];
|
||||
export let scales = [];
|
||||
|
||||
let mounted = false;
|
||||
onMount(() => (mounted = true));
|
||||
</script>
|
||||
|
||||
{#if mounted}
|
||||
<div class="gantt-wrapper">
|
||||
<Willow>
|
||||
<Gantt {tasks} {links} {scales} />
|
||||
</Willow>
|
||||
</div>
|
||||
{:else}
|
||||
<p>Chargement du Gantt…</p>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.gantt-wrapper {
|
||||
background: white;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
min-height: 600px;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
4
svar-gantt-app/src/lib/db.ts
Normal file
4
svar-gantt-app/src/lib/db.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import Database from 'better-sqlite3';
|
||||
|
||||
// Ouvre la base de données. Le fichier doit être à la racine du projet.
|
||||
export const db = new Database('gantt.db');
|
||||
8
svar-gantt-app/src/lib/db/database.js
Normal file
8
svar-gantt-app/src/lib/db/database.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { Kysely, SqliteDialect } from 'kysely'
|
||||
import Database from 'better-sqlite3'
|
||||
|
||||
export const db = new Kysely({
|
||||
dialect: new SqliteDialect({
|
||||
database: new Database('data.db')
|
||||
})
|
||||
})
|
||||
10
svar-gantt-app/src/lib/db/schema.js
Normal file
10
svar-gantt-app/src/lib/db/schema.js
Normal file
@ -0,0 +1,10 @@
|
||||
export const schema = {
|
||||
tasks: {
|
||||
id: 'string',
|
||||
name: 'string',
|
||||
estimation: 'number',
|
||||
sprint: 'string',
|
||||
status: 'string',
|
||||
remaining: 'number'
|
||||
}
|
||||
}
|
||||
7
svar-gantt-app/src/lib/server/db.ts
Normal file
7
svar-gantt-app/src/lib/server/db.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import { resolve } from 'path';
|
||||
|
||||
// 📁 chemin absolu vers la BDD SQLite
|
||||
const db = new Database(resolve('data.db'));
|
||||
|
||||
export default db;
|
||||
108
svar-gantt-app/src/routes/+layout.svelte
Normal file
108
svar-gantt-app/src/routes/+layout.svelte
Normal file
@ -0,0 +1,108 @@
|
||||
<script>
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
$: current = $page.url.pathname;
|
||||
|
||||
function resetData() {
|
||||
localStorage.removeItem("gantt-tasks");
|
||||
localStorage.removeItem("gantt-links");
|
||||
|
||||
// Recharge la page proprement après un petit délai
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 100);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="app">
|
||||
<aside class="sidebar">
|
||||
<div class="menu-toggle">
|
||||
☰
|
||||
</div>
|
||||
<h1>📊</h1>
|
||||
<nav>
|
||||
<a href="/" class:selected={current === "/"} title="Accueil">🏠</a>
|
||||
<a href="/gantt" class:selected={current === "/gantt"} title="Gantt">📅</a>
|
||||
<a href="/import" class:selected={current === "/import"} title="Importer">📂</a>
|
||||
<a href="/config" class:selected={current === "/config"} title="Config">⚙️</a>
|
||||
</nav>
|
||||
<button class="reset-btn" on:click={resetData} title="Réinitialiser les données">
|
||||
🔁
|
||||
</button>
|
||||
</aside>
|
||||
|
||||
<main class="content">
|
||||
<slot />
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.app {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 60px;
|
||||
background-color: #2d2d2d;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.menu-toggle {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
nav {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
nav a {
|
||||
color: white;
|
||||
font-size: 1.3rem;
|
||||
text-decoration: none;
|
||||
padding: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
nav a.selected,
|
||||
nav a:hover {
|
||||
background-color: #444;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 1.3rem;
|
||||
cursor: pointer;
|
||||
margin-top: auto;
|
||||
padding: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.reset-btn:hover {
|
||||
background-color: #444;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex-grow: 1;
|
||||
padding: 2rem;
|
||||
background-color: #f5f5f5;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
3
svar-gantt-app/src/routes/+page.svelte
Normal file
3
svar-gantt-app/src/routes/+page.svelte
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
<h1>Bienvenue 👋</h1>
|
||||
<p>Utilisez le menu à gauche pour naviguer dans l'application.</p>
|
||||
50
svar-gantt-app/src/routes/api/tasks/+server.ts
Normal file
50
svar-gantt-app/src/routes/api/tasks/+server.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import db from '$lib/server/db';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export async function GET() {
|
||||
const tasks = db.prepare('SELECT * FROM tasks').all();
|
||||
const links = db.prepare('SELECT * FROM links').all();
|
||||
return json({ tasks, links });
|
||||
}
|
||||
|
||||
export async function POST({ request }) {
|
||||
try {
|
||||
const { tasks, links } = await request.json();
|
||||
|
||||
const insertTask = db.prepare(`
|
||||
INSERT INTO tasks (id, text, start, end, duration, progress, type, parent, lazy)
|
||||
VALUES (@id, @text, @start, @end, @duration, @progress, @type, @parent, @lazy)
|
||||
`);
|
||||
|
||||
const insertLink = db.prepare(`
|
||||
INSERT INTO links (id, source, target, type)
|
||||
VALUES (@id, @source, @target, @type)
|
||||
`);
|
||||
|
||||
const taskTx = db.transaction((all) => {
|
||||
db.prepare('DELETE FROM tasks').run();
|
||||
db.prepare('DELETE FROM links').run();
|
||||
|
||||
for (const task of all.tasks) {
|
||||
insertTask.run({
|
||||
...task,
|
||||
start: typeof task.start === 'object' ? new Date(task.start).toISOString() : task.start,
|
||||
end: typeof task.end === 'object' ? new Date(task.end).toISOString() : task.end,
|
||||
lazy: task.lazy ? 1 : 0, // ⚠️ SQLite ne supporte pas le type boolean natif
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
for (const link of all.links) {
|
||||
insertLink.run(link);
|
||||
}
|
||||
});
|
||||
|
||||
taskTx({ tasks, links });
|
||||
|
||||
return json({ ok: true });
|
||||
} catch (error) {
|
||||
console.error('Erreur POST /api/tasks:', error);
|
||||
return new Response('Erreur interne', { status: 500 });
|
||||
}
|
||||
}
|
||||
57
svar-gantt-app/src/routes/boilerplate/+page.svelte
Normal file
57
svar-gantt-app/src/routes/boilerplate/+page.svelte
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
<script>
|
||||
import { Gantt, Willow } from "wx-svelte-gantt";
|
||||
import "wx-svelte-gantt/theme/index.css";
|
||||
|
||||
const tasks = [
|
||||
{
|
||||
id: 20,
|
||||
text: "New Task",
|
||||
start: new Date(2024, 5, 11),
|
||||
end: new Date(2024, 6, 12),
|
||||
duration: 1,
|
||||
progress: 2,
|
||||
type: "task",
|
||||
lazy: false,
|
||||
},
|
||||
{
|
||||
id: 47,
|
||||
text: "[1] Master project",
|
||||
start: new Date(2024, 5, 12),
|
||||
end: new Date(2024, 7, 12),
|
||||
duration: 8,
|
||||
progress: 0,
|
||||
parent: 0,
|
||||
type: "summary",
|
||||
},
|
||||
{
|
||||
id: 22,
|
||||
text: "Task",
|
||||
start: new Date(2024, 7, 11),
|
||||
end: new Date(2024, 8, 12),
|
||||
duration: 8,
|
||||
progress: 0,
|
||||
parent: 47,
|
||||
type: "task",
|
||||
},
|
||||
{
|
||||
id: 21,
|
||||
text: "New Task 2",
|
||||
start: new Date(2024, 7, 10),
|
||||
end: new Date(2024, 8, 12),
|
||||
duration: 3,
|
||||
progress: 0,
|
||||
type: "task",
|
||||
lazy: false,
|
||||
},
|
||||
];
|
||||
|
||||
const links = [{ id: 1, source: 20, target: 21, type: "e2e" }];
|
||||
|
||||
const scales = [
|
||||
{ unit: "month", step: 1, format: "MMMM yyy" },
|
||||
{ unit: "day", step: 1, format: "d" },
|
||||
];
|
||||
</script>
|
||||
|
||||
<Gantt {tasks} {links} {scales} theme={Willow} />
|
||||
2
svar-gantt-app/src/routes/config/+page.svelte
Normal file
2
svar-gantt-app/src/routes/config/+page.svelte
Normal file
@ -0,0 +1,2 @@
|
||||
<h2>Configuration</h2>
|
||||
<p>Page pour les paramètres futurs.</p>
|
||||
26
svar-gantt-app/src/routes/gantt/+page.svelte
Normal file
26
svar-gantt-app/src/routes/gantt/+page.svelte
Normal file
@ -0,0 +1,26 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { Gantt, Willow } from 'wx-svelte-gantt';
|
||||
|
||||
let tasks = [];
|
||||
let links = [];
|
||||
const scales = [
|
||||
{ unit: 'month', step: 1, format: 'MMMM yyyy' },
|
||||
{ unit: 'day', step: 1, format: 'd' }
|
||||
];
|
||||
|
||||
onMount(async () => {
|
||||
const res = await fetch('/api/tasks');
|
||||
if (res.ok) {
|
||||
const { tasks: loadedTasks, links: loadedLinks } = await res.json();
|
||||
tasks = loadedTasks;
|
||||
links = loadedLinks;
|
||||
} else {
|
||||
console.error('Erreur de chargement des données depuis la base.');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<Willow>
|
||||
<Gantt {tasks} {links} {scales} />
|
||||
</Willow>
|
||||
63
svar-gantt-app/src/routes/import/+page.svelte
Normal file
63
svar-gantt-app/src/routes/import/+page.svelte
Normal file
@ -0,0 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import Papa from 'papaparse';
|
||||
|
||||
let preview = '';
|
||||
let importé = false;
|
||||
|
||||
async function handleFile(event: Event) {
|
||||
const file = (event.target as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
const text = await file.text();
|
||||
preview = text;
|
||||
|
||||
const parsed = Papa.parse(text, {
|
||||
header: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
|
||||
const tasks = parsed.data.map((entry: any, index: number) => {
|
||||
const today = new Date();
|
||||
const start = new Date(today.getTime() + index * 86400000); // un jour de décalage par tâche
|
||||
const end = new Date(start.getTime() + 86400000); // tâche dure 1 jour par défaut
|
||||
|
||||
return {
|
||||
id: index + 1,
|
||||
text: entry['Nom Ticket'],
|
||||
start: start.toISOString().split('T')[0], // ⬅️ Converti en string
|
||||
end: end.toISOString().split('T')[0], // ⬅️ Converti en string
|
||||
duration: Number(entry['Estimation (j)']) || 1,
|
||||
progress: Number(entry['RAF']) || 0,
|
||||
type: 'task',
|
||||
parent: null,
|
||||
lazy: false
|
||||
};
|
||||
});
|
||||
|
||||
const response = await fetch('/api/tasks', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ tasks, links: [] })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
importé = true;
|
||||
} else {
|
||||
alert("Erreur lors de l'import.");
|
||||
}
|
||||
}
|
||||
|
||||
function allerAuGantt() {
|
||||
goto('/gantt');
|
||||
}
|
||||
</script>
|
||||
|
||||
<h2>Importer un fichier CSV</h2>
|
||||
<input type="file" accept=".csv" on:change={handleFile} />
|
||||
|
||||
{#if preview}
|
||||
<h3>Prévisualisation</h3>
|
||||
<pre>{preview}</pre>
|
||||
<button on:click={allerAuGantt}>Voir le Gantt</button>
|
||||
{/if}
|
||||
8
svar-gantt-app/src/src/lib/db/database.js
Normal file
8
svar-gantt-app/src/src/lib/db/database.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { Kysely, SqliteDialect } from 'kysely'
|
||||
import Database from 'better-sqlite3'
|
||||
|
||||
export const db = new Kysely({
|
||||
dialect: new SqliteDialect({
|
||||
database: new Database('data.db')
|
||||
})
|
||||
})
|
||||
10
svar-gantt-app/src/src/lib/db/schema.js
Normal file
10
svar-gantt-app/src/src/lib/db/schema.js
Normal file
@ -0,0 +1,10 @@
|
||||
export const schema = {
|
||||
tasks: {
|
||||
id: 'string',
|
||||
name: 'string',
|
||||
estimation: 'number',
|
||||
sprint: 'string',
|
||||
status: 'string',
|
||||
remaining: 'number'
|
||||
}
|
||||
}
|
||||
36
svar-gantt-app/src/src/routes/api/tasks/+server.js
Normal file
36
svar-gantt-app/src/src/routes/api/tasks/+server.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { db } from '$lib/db/database'
|
||||
|
||||
await db.schema
|
||||
.createTable('tasks')
|
||||
.ifNotExists()
|
||||
.addColumn('id', 'text', col => col.primaryKey())
|
||||
.addColumn('name', 'text')
|
||||
.addColumn('estimation', 'integer')
|
||||
.addColumn('sprint', 'text')
|
||||
.addColumn('status', 'text')
|
||||
.addColumn('remaining', 'integer')
|
||||
.execute()
|
||||
|
||||
export async function GET() {
|
||||
const tasks = await db.selectFrom('tasks').selectAll().execute()
|
||||
return new Response(JSON.stringify(tasks))
|
||||
}
|
||||
|
||||
export async function POST({ request }) {
|
||||
const data = await request.json()
|
||||
|
||||
await db.deleteFrom('tasks').execute()
|
||||
|
||||
for (const task of data) {
|
||||
await db.insertInto('tasks').values({
|
||||
id: task.id,
|
||||
name: task.name,
|
||||
estimation: task.estimation,
|
||||
sprint: task.sprint,
|
||||
status: task.status,
|
||||
remaining: task.remaining
|
||||
}).execute()
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ ok: true }))
|
||||
}
|
||||
Reference in New Issue
Block a user