basic Dashboard

This commit is contained in:
2025-06-14 20:35:42 +02:00
parent 30758bbd88
commit 1597409365
8 changed files with 409 additions and 26 deletions

View File

@@ -1,33 +1,41 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
using Watcher.Data;
using Watcher.Models;
using Watcher.ViewModels;
namespace Watcher.Controllers;
[Authorize]
public class HomeController : Controller
namespace Watcher.Controllers
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
[Authorize]
public class HomeController : Controller
{
_logger = logger;
}
private readonly AppDbContext _context;
public IActionResult Index()
{
return View();
}
public HomeController(AppDbContext context)
{
_context = context;
}
public IActionResult Privacy()
{
return View();
}
public async Task<IActionResult> Index()
{
var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
var user = await _context.Users
.Where(u => u.PocketId == userId)
.FirstOrDefaultAsync();
var viewModel = new DashboardViewModel
{
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),
LastLogin = user?.LastLogin ?? DateTime.MinValue
};
return View(viewModel);
}
}
}