Partials erstellt und auto-repload auf 30 Sekunden Interval gesetzt
This commit is contained in:
@@ -13,124 +13,28 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
@foreach (var s in Model.Servers)
|
||||
{
|
||||
<div class="bg-blue rounded-xl shadow p-5 border border-gray-200 flex flex-col gap-4">
|
||||
<div class="flex justify-between items-center">
|
||||
<h2 class="text-lg font-semibold text-gray-800">
|
||||
<i class="bi bi-cpu me-1 text-gray-600"></i>(#@s.Id) @s.Name
|
||||
</h2>
|
||||
<span class="text-sm px-2 py-1 rounded font-medium
|
||||
@(s.IsOnline ? "bg-green-100 text-green-700" : "bg-red-100 text-red-700")">
|
||||
<i class="bi @(s.IsOnline ? "bi-check-circle" : "bi-x-circle") me-1"></i>
|
||||
@(s.IsOnline ? "Online" : "Offline")
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-6">
|
||||
<!-- Linke Seite: Infos, nimmt ca. 40% Breite -->
|
||||
<div class="flex-1 max-w-[40%] text-sm space-y-1 text-gray-700">
|
||||
<div><i class="bi bi-globe me-1 text-gray-500"></i><strong>IP:</strong> @s.IPAddress</div>
|
||||
<div><i class="bi bi-hdd me-1 text-gray-500"></i><strong>Typ:</strong> @s.Type</div>
|
||||
<div><i class="bi bi-calendar-check me-1 text-gray-500"></i><strong>Erstellt:</strong>
|
||||
@s.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</div>
|
||||
<div><i class="bi bi-clock me-1 text-gray-500"></i><strong>Last-Seen:</strong>
|
||||
@s.LastSeen.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</div>
|
||||
</div>
|
||||
|
||||
<!-- Rechte Seite: Zwei Diagramme nebeneinander, je ca. 50% von 60% = 30% insgesamt -->
|
||||
<div class="flex-1 flex gap-4 max-w-[60%]">
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3">
|
||||
<a asp-action="EditServer" asp-route-id="@s.Id" class="text-blue-600 hover:text-blue-800 font-medium">
|
||||
<i class="bi bi-pencil-square me-1"></i>Bearbeiten
|
||||
</a>
|
||||
|
||||
<form asp-action="Delete" asp-route-id="@s.Id" method="post"
|
||||
onsubmit="return confirm('Diesen Server wirklich löschen?');">
|
||||
<button type="submit" class="text-red-600 hover:text-red-800 font-medium">
|
||||
<i class="bi bi-trash me-1"></i>Löschen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div id="server-cards-container">
|
||||
@await Html.PartialAsync("_ServerCard", Model.Servers)
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
@foreach (var s in Model.Servers)
|
||||
{
|
||||
<text>
|
||||
var ctxCpu_@s.Id = document.getElementById("cpuChart-@s.Id").getContext('2d');
|
||||
var cpuChart_@s.Id = new Chart(ctxCpu_@s.Id, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ['0s', '5s', '10s', '15s', '20s'],
|
||||
datasets: [{
|
||||
label: 'CPU %',
|
||||
data: [12, 19, 7, 15, 10], // Beispielwerte
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.7)', // Tailwind blue-500 transparent
|
||||
borderColor: 'rgba(59, 130, 246, 1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
animation: false,
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 100
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
}
|
||||
<script>
|
||||
async function loadServerCards() {
|
||||
try {
|
||||
const response = await fetch('/Server/ServerCardsPartial');
|
||||
if (response.ok) {
|
||||
const html = await response.text();
|
||||
document.getElementById('server-cards-container').innerHTML = html;
|
||||
} else {
|
||||
console.error('Fehler beim Nachladen der Serverkarten');
|
||||
}
|
||||
});
|
||||
|
||||
var ctxRam_@s.Id = document.getElementById("ramChart-@s.Id").getContext('2d');
|
||||
var ramChart_@s.Id = new Chart(ctxRam_@s.Id, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ['0s', '5s', '10s', '15s', '20s'],
|
||||
datasets: [{
|
||||
label: 'RAM %',
|
||||
data: [45, 40, 55, 48, 50], // Beispielwerte
|
||||
backgroundColor: 'rgba(16, 185, 129, 0.7)', // Tailwind green-500 transparent
|
||||
borderColor: 'rgba(16, 185, 129, 1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
animation: false,
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 100
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</text>
|
||||
} catch (err) {
|
||||
console.error('Netzwerkfehler beim Nachladen der Serverkarten:', err);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
// Initial laden und dann alle 30 Sekunden
|
||||
loadServerCards();
|
||||
setInterval(loadServerCards, 30000);
|
||||
</script>
|
||||
}
|
||||
|
Reference in New Issue
Block a user