diff --git a/OrcanodeMonitor/Models/OrcanodeEvent.cs b/OrcanodeMonitor/Models/OrcanodeEvent.cs index f516026..ebbca2b 100644 --- a/OrcanodeMonitor/Models/OrcanodeEvent.cs +++ b/OrcanodeMonitor/Models/OrcanodeEvent.cs @@ -68,6 +68,8 @@ public OrcanodeEvent() Value = string.Empty; OrcanodeId = string.Empty; ID = string.Empty; + DateTimeUtc = DateTime.UtcNow; + Year = DateTimeUtc.Year; } public OrcanodeEvent(Orcanode node, string type, string value, DateTime timestamp) diff --git a/OrcanodeMonitor/Pages/Index.cshtml b/OrcanodeMonitor/Pages/Index.cshtml index 138d3c5..1c593a8 100644 --- a/OrcanodeMonitor/Pages/Index.cshtml +++ b/OrcanodeMonitor/Pages/Index.cshtml @@ -177,20 +177,20 @@

Recent State Events

- - - - - @foreach (Models.OrcanodeEvent item in Model.RecentEvents) - { + - - + + - } + + + @foreach (Models.OrcanodeEvent item in Model.RecentEvents) + { + + + + + } +
TimestampEvent
- @item.DateTimeLocal - - @item.Description - TimestampEvent
@item.DateTimeLocal.ToString("g")@item.Description
diff --git a/OrcanodeMonitor/Pages/NodeEvents.cshtml b/OrcanodeMonitor/Pages/NodeEvents.cshtml index 46effe4..480a72d 100644 --- a/OrcanodeMonitor/Pages/NodeEvents.cshtml +++ b/OrcanodeMonitor/Pages/NodeEvents.cshtml @@ -7,35 +7,45 @@

Node Events

- - - -
+ @Html.AntiForgeryToken() + +
+ + +
+

Uptime percentage: @Model.UptimePercentage%

- - - - - - @foreach (Models.OrcanodeEvent item in Model.RecentEvents) - { +
TimestampEvent
+ - - + + - } + + + @if (!Model.RecentEvents.Any()) + { + + + + } + @foreach (Models.OrcanodeEvent item in Model.RecentEvents) + { + + + + + } +
- @item.DateTimeLocal - - @item.Description - TimestampEvent
No events found for this time period.
@item.DateTimeLocal.ToString("g")@item.Description
- - diff --git a/OrcanodeMonitor/Pages/NodeEvents.cshtml.cs b/OrcanodeMonitor/Pages/NodeEvents.cshtml.cs index dde5505..b4d69a3 100644 --- a/OrcanodeMonitor/Pages/NodeEvents.cshtml.cs +++ b/OrcanodeMonitor/Pages/NodeEvents.cshtml.cs @@ -12,7 +12,7 @@ namespace OrcanodeMonitor.Pages public class NodeEventsModel : PageModel { private OrcanodeMonitorContext _databaseContext; - private readonly ILogger _logger; + private readonly ILogger _logger; private string _nodeId; public string Id => _nodeId; [BindProperty] @@ -22,7 +22,7 @@ public class NodeEventsModel : PageModel public List RecentEvents => _events; public int UptimePercentage => Orcanode.GetUptimePercentage(_nodeId, _events, SinceTime); - public NodeEventsModel(OrcanodeMonitorContext context, ILogger logger) + public NodeEventsModel(OrcanodeMonitorContext context, ILogger logger) { _databaseContext = context; _logger = logger; @@ -30,18 +30,30 @@ public NodeEventsModel(OrcanodeMonitorContext context, ILogger logge _events = new List(); } + private void FetchEvents() + { + try + { + _events = Fetcher.GetRecentEventsForNode(_databaseContext, _nodeId, SinceTime); + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to fetch events for node {NodeId}", _nodeId); + _events = new List(); + } + } + public void OnGet(string id) { _nodeId = id; - _events = Fetcher.GetRecentEventsForNode(_databaseContext, _nodeId, SinceTime); + FetchEvents(); } - public IActionResult OnPost(string selected, string id) + public void OnPost(string selected, string id) { Selected = selected; _nodeId = id; - _events = Fetcher.GetRecentEventsForNode(_databaseContext, _nodeId, SinceTime); - return Page(); + FetchEvents(); } } } diff --git a/OrcanodeMonitor/Pages/NodeEvents.cshtml.css b/OrcanodeMonitor/Pages/NodeEvents.cshtml.css index c69ab36..f3fa03f 100644 --- a/OrcanodeMonitor/Pages/NodeEvents.cshtml.css +++ b/OrcanodeMonitor/Pages/NodeEvents.cshtml.css @@ -10,3 +10,11 @@ th, td { h1 { font-size: 32px; } + +.selected { + background-color: blue; + color: white; +} +.unselected { + border-color: blue; +} \ No newline at end of file