new Dashboard
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
// Local Namespaces
|
||||
using Watcher.Data;
|
||||
using Watcher.Models;
|
||||
using Watcher.ViewModels;
|
||||
|
||||
namespace Watcher.Controllers
|
||||
@@ -41,7 +42,17 @@ namespace Watcher.Controllers
|
||||
OfflineServers = await _context.Servers.CountAsync(s => !s.IsOnline),
|
||||
RunningContainers = await _context.Containers.CountAsync(c => c.IsRunning),
|
||||
FailedContainers = await _context.Containers.CountAsync(c => !c.IsRunning),
|
||||
LastLogin = user?.LastLogin ?? DateTime.MinValue
|
||||
LastLogin = user?.LastLogin ?? DateTime.MinValue,
|
||||
Servers = await _context.Servers
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync(),
|
||||
RecentEvents = await _context.LogEvents
|
||||
.OrderByDescending(e => e.Timestamp)
|
||||
.Take(20)
|
||||
.ToListAsync(),
|
||||
Containers = await _context.Containers
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
@@ -49,7 +60,7 @@ namespace Watcher.Controllers
|
||||
|
||||
// Funktion für /Views/Home/Index.cshtml um das DashboardStats-Partial neu zu laden.
|
||||
// Die Funktion wird nicht direkt aufgerufen, sondern nur der /Home/DashboardStats Endpoint angefragt.
|
||||
public IActionResult DashboardStats()
|
||||
public async Task<IActionResult> DashboardStats()
|
||||
{
|
||||
var servers = _context.Servers.ToList();
|
||||
var containers = _context.Containers.ToList();
|
||||
@@ -58,14 +69,20 @@ namespace Watcher.Controllers
|
||||
|
||||
var model = new DashboardViewModel
|
||||
{
|
||||
ActiveServers = servers.Count(s => (now - s.LastSeen).TotalSeconds <= 120),
|
||||
OfflineServers = servers.Count(s => (now - s.LastSeen).TotalSeconds > 120),
|
||||
|
||||
//TODO: anwendbar, wenn Container implementiert wurden.
|
||||
//RunningContainers = containers.Count(c => (now - c.LastSeen).TotalSeconds <= 120),
|
||||
//FailedContainers = containers.Count(c => (now - c.LastSeen).TotalSeconds > 120),
|
||||
|
||||
LastLogin = DateTime.Now
|
||||
ActiveServers = await _context.Servers.CountAsync(s => s.IsOnline),
|
||||
OfflineServers = await _context.Servers.CountAsync(s => !s.IsOnline),
|
||||
RunningContainers = await _context.Containers.CountAsync(c => c.IsRunning),
|
||||
FailedContainers = await _context.Containers.CountAsync(c => !c.IsRunning),
|
||||
Servers = await _context.Servers
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync(),
|
||||
RecentEvents = await _context.LogEvents
|
||||
.OrderByDescending(e => e.Timestamp)
|
||||
.Take(20)
|
||||
.ToListAsync(),
|
||||
Containers = await _context.Containers
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync()
|
||||
};
|
||||
|
||||
return PartialView("_DashboardStats", model);
|
||||
|
Reference in New Issue
Block a user