feat(monitoring): T23 - Surveillance automatique des libraries
- Ajout scheduler dans l'indexer (vérifie toutes les minutes) - Migration 0004: colonnes monitor_enabled, scan_mode, next_scan_at - API: GET /libraries avec champs monitoring - API: PATCH /libraries/:id/monitoring pour configuration - Composant MonitoringForm (client) avec checkbox et select - Badge Auto/Manual avec couleurs différentes - Affichage temps restant avant prochain scan - Proxy route /api/libraries/:id/monitoring Le scheduler crée automatiquement des jobs quand next_scan_at <= NOW()
This commit is contained in:
62
apps/backoffice/app/components/MonitoringForm.tsx
Normal file
62
apps/backoffice/app/components/MonitoringForm.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
"use client";
|
||||
|
||||
import { useTransition } from "react";
|
||||
|
||||
interface MonitoringFormProps {
|
||||
libraryId: string;
|
||||
monitorEnabled: boolean;
|
||||
scanMode: string;
|
||||
}
|
||||
|
||||
export function MonitoringForm({ libraryId, monitorEnabled, scanMode }: MonitoringFormProps) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const handleSubmit = (formData: FormData) => {
|
||||
startTransition(async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/libraries/${libraryId}/monitoring`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
monitor_enabled: formData.get("monitor_enabled") === "true",
|
||||
scan_mode: formData.get("scan_mode"),
|
||||
}),
|
||||
});
|
||||
if (response.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to update monitoring:", error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<form action={handleSubmit} className="monitoring-form">
|
||||
<input type="hidden" name="id" value={libraryId} />
|
||||
<label className={`monitor-toggle ${isPending ? 'pending' : ''}`}>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="monitor_enabled"
|
||||
value="true"
|
||||
defaultChecked={monitorEnabled}
|
||||
disabled={isPending}
|
||||
/>
|
||||
Auto
|
||||
</label>
|
||||
<select
|
||||
name="scan_mode"
|
||||
defaultValue={scanMode}
|
||||
disabled={isPending}
|
||||
>
|
||||
<option value="manual">Manual only</option>
|
||||
<option value="hourly">Hourly</option>
|
||||
<option value="daily">Daily</option>
|
||||
<option value="weekly">Weekly</option>
|
||||
</select>
|
||||
<button type="submit" className="update-btn" disabled={isPending}>
|
||||
{isPending ? '...' : 'Update'}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -1171,3 +1171,66 @@ tr.job-highlighted td {
|
||||
0%, 100% { box-shadow: inset 0 0 0 1px hsl(198 78% 37% / 0.3); }
|
||||
50% { box-shadow: inset 0 0 0 2px hsl(198 78% 37% / 0.6); }
|
||||
}
|
||||
|
||||
/* Monitoring styles */
|
||||
.monitoring-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.monitor-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.monitor-auto {
|
||||
background: hsl(142 60% 45% / 0.2);
|
||||
color: hsl(142 60% 35%);
|
||||
border: 1px solid hsl(142 60% 45% / 0.5);
|
||||
}
|
||||
|
||||
.monitor-manual {
|
||||
background: hsl(220 13% 80% / 0.2);
|
||||
color: hsl(220 13% 40%);
|
||||
border: 1px solid hsl(220 13% 80% / 0.5);
|
||||
}
|
||||
|
||||
.scan-mode {
|
||||
font-size: 0.7rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.next-scan {
|
||||
font-size: 0.7rem;
|
||||
color: hsl(198 78% 37%);
|
||||
}
|
||||
|
||||
.monitoring-form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.monitor-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.monitor-toggle input[type="checkbox"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.monitoring-form select {
|
||||
font-size: 0.75rem;
|
||||
padding: 2px 4px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user