Moved usc systems to seperate controller
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
protected override async void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
UpdateTable();
|
||||
await UpdateTable();
|
||||
|
||||
while (await refreshTimer.WaitForNextTickAsync())
|
||||
{
|
||||
@@ -49,8 +49,8 @@
|
||||
|
||||
private async Task UpdateTable()
|
||||
{
|
||||
using MonitorDbContext db = _contextFactory.CreateDbContext();
|
||||
camsList = db.AxisCams.OrderBy(o => o.Device).ToList();
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync();
|
||||
camsList = await db.AxisCams.OrderBy(o => o.Device).ToListAsync();
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
while (await refreshTimer.WaitForNextTickAsync())
|
||||
{
|
||||
await UpdateTable();
|
||||
UpdateTable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
refreshTimer?.Dispose();
|
||||
}
|
||||
|
||||
private async Task UpdateTable()
|
||||
private void UpdateTable()
|
||||
{
|
||||
prtgsList = _monitorHandler.GetPRTGDevices().OrderBy(o => o.DeviceName).ToList();
|
||||
this.StateHasChanged();
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
protected override async void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
UpdateTable();
|
||||
await UpdateTable();
|
||||
|
||||
while (await refreshTimer.WaitForNextTickAsync())
|
||||
{
|
||||
@@ -49,8 +49,8 @@
|
||||
|
||||
private async Task UpdateTable()
|
||||
{
|
||||
using MonitorDbContext db = _contextFactory.CreateDbContext();
|
||||
routersList = db.Routers.OrderBy(o => o.Device).ToList();
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync();
|
||||
routersList = await db.Routers.OrderBy(o => o.Device).ToListAsync();
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +128,6 @@
|
||||
using MonitorDbContext db = _contextFactory.CreateDbContext();
|
||||
routersList = db.Routers.GroupBy(rout => rout.Device).Select(x => x.OrderBy(t => t.Timestamp).Last()).ToList();
|
||||
|
||||
//routersList = SortTable(db.Routers.GroupBy(rout => rout.Device).Select(x => x.OrderBy(t => t.Timestamp).Last()));
|
||||
|
||||
this.StateHasChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
|
||||
while (await refreshTimer.WaitForNextTickAsync())
|
||||
{
|
||||
await UpdateTable();
|
||||
UpdateTable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
private async Task UpdateTable()
|
||||
private void UpdateTable()
|
||||
{
|
||||
using MonitorDbContext db = _contextFactory.CreateDbContext();
|
||||
system = db.UCSSystems.Where(i => i.UCSSystemId == Id).Include(d => d.Devices).SingleOrDefault();
|
||||
|
||||
@@ -14,17 +14,20 @@
|
||||
<li class="list-group-item py-2">Uptime: @system.Uptime</li>
|
||||
<li class="list-group-item py-2">Last: @system.LastMessageTime.FormatDateTime()</li>
|
||||
<li class="list-group-item py-2">
|
||||
<a href="Home/OverviewDevice?id=@system.UCSSystemId">
|
||||
<i class="bi-building" style="color: white;"></i>
|
||||
@if (system.Devices.Any())
|
||||
{
|
||||
<a href="UCSSystems/Devices?id=@system.UCSSystemId">
|
||||
<i class="bi-building p-1" style="color: white;"></i>
|
||||
</a>
|
||||
}
|
||||
<a href="UCSSystems/Logging?id=@system.UCSSystemId">
|
||||
<i class="bi-calendar-check p-1" style="color: white;"></i>
|
||||
</a>
|
||||
<a href="Home/Logging?id=@system.UCSSystemId">
|
||||
<i class="bi-calendar-check" style="color: white;"></i>
|
||||
<a href="UCSSystems/Errors?id=@system.UCSSystemId">
|
||||
<i class="bi-bug p-1" style="color: white;"></i>
|
||||
</a>
|
||||
<a href="Home/LogErrors?id=@system.UCSSystemId">
|
||||
<i class="bi-bug" style="color: white;"></i>
|
||||
</a>
|
||||
<a href="Home/SystemDetails?id=@system.UCSSystemId">
|
||||
<i class="bi-info" style="color: white;"></i>
|
||||
<a href="UCSSystems/Details?id=@system.UCSSystemId">
|
||||
<i class="bi-info p-1" style="color: white;"></i>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -41,7 +44,7 @@
|
||||
protected override async void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
UpdateTable();
|
||||
await UpdateTable();
|
||||
|
||||
while (await refreshTimer.WaitForNextTickAsync())
|
||||
{
|
||||
@@ -56,8 +59,8 @@
|
||||
|
||||
private async Task UpdateTable()
|
||||
{
|
||||
using MonitorDbContext db = _contextFactory.CreateDbContext();
|
||||
ucssystemsList = db.UCSSystems.Include(d => d.Devices).OrderBy(o => o.ComputerName).ToList();
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync();
|
||||
ucssystemsList = await db.UCSSystems.Include(d => d.Devices).OrderBy(o => o.ComputerName).ToListAsync();
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -176,16 +176,19 @@
|
||||
{
|
||||
<tr class="table-@system.BootstrapColor()">
|
||||
<td>
|
||||
<a href="Home/OverviewDevice?id=@system.UCSSystemId">
|
||||
<i class="bi-building" style="color: black;"></i>
|
||||
</a>
|
||||
<a href="Home/Logging?id=@system.UCSSystemId">
|
||||
@if (system.Devices.Any())
|
||||
{
|
||||
<a href="UCSSystems/Devices?id=@system.UCSSystemId">
|
||||
<i class="bi-building" style="color: black;"></i>
|
||||
</a>
|
||||
}
|
||||
<a href="UCSSystems/Logging?id=@system.UCSSystemId">
|
||||
<i class="bi-calendar-check" style="color: black;"></i>
|
||||
</a>
|
||||
<a href="Home/LogErrors?id=@system.UCSSystemId">
|
||||
<a href="UCSSystems/Errors?id=@system.UCSSystemId">
|
||||
<i class="bi-bug" style="color: black;"></i>
|
||||
</a>
|
||||
<a href="Home/SystemDetails?id=@system.UCSSystemId">
|
||||
<a href="UCSSystems/Details?id=@system.UCSSystemId">
|
||||
<i class="bi-info" style="color: black;"></i>
|
||||
</a>
|
||||
</td>
|
||||
@@ -208,7 +211,7 @@
|
||||
<td>@system.USBDisks</td>
|
||||
<td>@system.LastMessageTime.FormatDateTime()</td>
|
||||
<td>
|
||||
<a href="Home/Delete?id=@system.UCSSystemId">
|
||||
<a href="UCSSystems/Delete?id=@system.UCSSystemId">
|
||||
<i class="bi-trash" style="color: black;"></i>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
@@ -2,24 +2,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UCS_Status_Monitor.Database;
|
||||
using UCS_Status_Monitor.Extensions;
|
||||
using UCS_Status_Monitor.Models;
|
||||
using UCS_Status_Monitor.Models.Database;
|
||||
using UCS_Status_Monitor.Monitor;
|
||||
using UCS_Status_Monitor.Telegram;
|
||||
|
||||
namespace UCS_Status_Monitor.Controllers
|
||||
{
|
||||
public class HomeController(ITelegramBotService telegramBot, IDbContextFactory<MonitorDbContext> contextFactory, MonitorHandler monitorHandler) : Controller
|
||||
public class HomeController(IDbContextFactory<MonitorDbContext> contextFactory) : Controller
|
||||
{
|
||||
private readonly ITelegramBotService _telegramBot = telegramBot;
|
||||
private readonly IDbContextFactory<MonitorDbContext> _contextFactory = contextFactory;
|
||||
private readonly MonitorHandler _monitorHandler = monitorHandler;
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
@@ -28,138 +22,6 @@ namespace UCS_Status_Monitor.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public IActionResult Overview()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> SystemDetails(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id)
|
||||
.Include(d => d.Devices)
|
||||
.Include(d => d.Errors.OrderByDescending(o => o.TimeGenerated))
|
||||
.SingleOrDefaultAsync(token);
|
||||
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
return View(system);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public IActionResult OverviewDevice(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id to display");
|
||||
}
|
||||
return View(id);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Delete(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id to delete");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id)
|
||||
.Include(d => d.Devices)
|
||||
.Include(d => d.Loggings)
|
||||
.Include(d => d.Errors)
|
||||
.SingleOrDefaultAsync(token);
|
||||
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
|
||||
if (system.Devices.Count != 0)
|
||||
db.UCSDevices.RemoveRange(system.Devices);
|
||||
|
||||
if (system.Loggings.Count != 0)
|
||||
db.Loggings.RemoveRange(system.Loggings);
|
||||
|
||||
if (system.Errors.Count != 0)
|
||||
db.Errors.RemoveRange(system.Errors);
|
||||
|
||||
db.UCSSystems.Remove(system);
|
||||
await db.SaveChangesAsync(token);
|
||||
|
||||
await _telegramBot.Send($"🚮 <b>{system.ComputerName} - {system.ConfigFileName}</b>{Environment.NewLine} Removed from UCS monitor", token);
|
||||
|
||||
return RedirectToAction("Overview", "Home");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Logging(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id).Include(l => l.Loggings).SingleOrDefaultAsync(token);
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
LoggingViewModel loggingView = new()
|
||||
{
|
||||
UCSSystem = system,
|
||||
Loggings = system.Loggings.OrderByDescending(d => d.Date).Take(10)
|
||||
};
|
||||
|
||||
if (loggingView.Loggings.Any())
|
||||
{
|
||||
//last 10 logs
|
||||
foreach (var log in loggingView.Loggings.Reverse())
|
||||
{
|
||||
loggingView.LoggingChart.Data.Add(Convert.ToInt32(log.State));
|
||||
loggingView.LoggingChart.Labels.Add(log.Date);
|
||||
}
|
||||
}
|
||||
return View(loggingView);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> LogErrors(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id)
|
||||
.Include(d => d.Errors.OrderByDescending(o => o.TimeGenerated))
|
||||
.SingleOrDefaultAsync(token);
|
||||
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
return View(system);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Sensors(string sortOrder, CancellationToken token)
|
||||
|
||||
159
UCS_Status_Monitor/Controllers/UCSsystemsController.cs
Normal file
159
UCS_Status_Monitor/Controllers/UCSsystemsController.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UCS_Status_Monitor.Database;
|
||||
using UCS_Status_Monitor.Models;
|
||||
using UCS_Status_Monitor.Models.Database;
|
||||
using UCS_Status_Monitor.Telegram;
|
||||
|
||||
namespace UCS_Status_Monitor.Controllers
|
||||
{
|
||||
public class UCSSystemsController(ITelegramBotService telegramBot, IDbContextFactory<MonitorDbContext> contextFactory) : Controller
|
||||
{
|
||||
private readonly ITelegramBotService _telegramBot = telegramBot;
|
||||
private readonly IDbContextFactory<MonitorDbContext> _contextFactory = contextFactory;
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public IActionResult Grid()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public IActionResult List()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Details(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id)
|
||||
.Include(d => d.Devices)
|
||||
.Include(d => d.Errors.OrderByDescending(o => o.TimeGenerated))
|
||||
.SingleOrDefaultAsync(token);
|
||||
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
return View(system);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public IActionResult Devices(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id to display");
|
||||
}
|
||||
return View(id);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Delete(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id to delete");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id)
|
||||
.Include(d => d.Devices)
|
||||
.Include(d => d.Loggings)
|
||||
.Include(d => d.Errors)
|
||||
.SingleOrDefaultAsync(token);
|
||||
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
|
||||
if (system.Devices.Count != 0)
|
||||
db.UCSDevices.RemoveRange(system.Devices);
|
||||
|
||||
if (system.Loggings.Count != 0)
|
||||
db.Loggings.RemoveRange(system.Loggings);
|
||||
|
||||
if (system.Errors.Count != 0)
|
||||
db.Errors.RemoveRange(system.Errors);
|
||||
|
||||
db.UCSSystems.Remove(system);
|
||||
await db.SaveChangesAsync(token);
|
||||
|
||||
await _telegramBot.Send($"🚮 <b>{system.ComputerName} - {system.ConfigFileName}</b>{Environment.NewLine} Removed from UCS monitor", token);
|
||||
|
||||
return RedirectToAction("Overview", "Home");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Logging(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id).Include(l => l.Loggings).SingleOrDefaultAsync(token);
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
LoggingViewModel loggingView = new()
|
||||
{
|
||||
UCSSystem = system,
|
||||
Loggings = system.Loggings.OrderByDescending(d => d.Date).Take(10)
|
||||
};
|
||||
|
||||
if (loggingView.Loggings.Any())
|
||||
{
|
||||
//last 10 logs
|
||||
foreach (var log in loggingView.Loggings.Reverse())
|
||||
{
|
||||
loggingView.LoggingChart.Data.Add(Convert.ToInt32(log.State));
|
||||
loggingView.LoggingChart.Labels.Add(log.Date);
|
||||
}
|
||||
}
|
||||
return View(loggingView);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Errors(int? id, CancellationToken token)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return BadRequest("No id");
|
||||
}
|
||||
|
||||
using MonitorDbContext db = await _contextFactory.CreateDbContextAsync(token);
|
||||
UCSSystem? system = await db.UCSSystems.Where(i => i.UCSSystemId == id)
|
||||
.Include(d => d.Errors.OrderByDescending(o => o.TimeGenerated))
|
||||
.SingleOrDefaultAsync(token);
|
||||
|
||||
if (system == null)
|
||||
{
|
||||
return BadRequest("Not found in the database");
|
||||
}
|
||||
return View(system);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,21 +105,7 @@ namespace UCS_Status_Monitor
|
||||
endpoints.MapControllerRoute(name: "tgwebhook", pattern: $"bot/{apikey}", new { controller = "Webhook", action = "Post" });
|
||||
|
||||
endpoints.MapBlazorHub();
|
||||
//endpoints.MapRazorPages();
|
||||
//endpoints.MapRazorComponents<UCS_Status_Monitor.Components.App>().AddInteractiveServerRenderMode();
|
||||
//endpoints.MapRazorComponents().AddInteractiveServerRenderMode();
|
||||
});
|
||||
|
||||
//app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
//app.MapBlazorHub();
|
||||
//app.MapBlazorHub("/Aperio/");
|
||||
|
||||
//.net8
|
||||
//app.MapRazorComponents<UCS_Status_Monitor.Components.App>().AddInteractiveServerRenderMode();
|
||||
|
||||
//app.MapBlazorHub();
|
||||
//app.MapRazorComponents<UCS_Status_Monitor.Components.Cameras>().AddInteractiveServerRenderMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
@if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
<li class="nav-item">
|
||||
@Html.ActionLink("Home", "Index", "Home", null, new { @class = "nav-link" })
|
||||
@Html.ActionLink("Home", "Grid", "UCSSystems", null, new { @class = "nav-link" })
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
@Html.ActionLink("Overview", "Overview", "Home", null, new { @class = "nav-link" })
|
||||
@Html.ActionLink("Overview", "List", "UCSSystems", null, new { @class = "nav-link" })
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
@Html.ActionLink("Sensors", "Sensors", "Home", null, new { @class = "nav-link" })
|
||||
|
||||
4
UCS_Status_Monitor/Views/UCSSystems/Grid.cshtml
Normal file
4
UCS_Status_Monitor/Views/UCSSystems/Grid.cshtml
Normal file
@@ -0,0 +1,4 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
<component type="typeof(UCS_Status_Monitor.Components.UCSSystems.Grid)" render-mode="Server" />
|
||||
Reference in New Issue
Block a user