Skip to content

Commit

Permalink
Address coderabbit feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Oct 25, 2024
1 parent e8fae34 commit 467e3ce
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 44 deletions.
2 changes: 2 additions & 0 deletions OrcanodeMonitor/Models/OrcanodeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions OrcanodeMonitor/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@
<p/>
<h1 class="display-4"><a href="/api/ifttt/v1/triggers/nodestateevents">Recent State Events</a></h1>
<table>
<tr>
<th>Timestamp</th>
<th>Event</th>
</tr>
@foreach (Models.OrcanodeEvent item in Model.RecentEvents)
{
<thead>
<tr>
<td>
@item.DateTimeLocal
</td>
<td>
@item.Description
</td>
<th>Timestamp</th>
<th>Event</th>
</tr>
}
</thead>
<tbody>
@foreach (Models.OrcanodeEvent item in Model.RecentEvents)
{
<tr>
<td>@item.DateTimeLocal.ToString("g")</td>
<td align="left">@item.Description</td>
</tr>
}
</tbody>
</table>
</div>
60 changes: 35 additions & 25 deletions OrcanodeMonitor/Pages/NodeEvents.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,45 @@
<div class="text-center">
<h1 class="display-4">Node Events</h1>
<form method="post">
<input type="hidden" name="Id" value="@Model.Id" />
<button type="submit" name="Selected" value="week" class="@(Model.Selected == "week" ? "selected" : "")">Past Week</button>
<button type="submit" name="Selected" value="month" class="@(Model.Selected == "month" ? "selected" : "")">Past Month</button>
</form>
@Html.AntiForgeryToken()
<input type="hidden" name="Id" value="@Model.Id" />
<div role="group" aria-label="Time period selection">
<button type="submit" name="Selected" value="week"
class="btn @(Model.Selected == "week" ? "selected" : "unselected")"
aria-pressed="@(Model.Selected == "week" ? "true" : "false")" >
Past Week
</button>
<button type="submit" name="Selected" value="month"
class="btn @(Model.Selected == "month" ? "selected" : "unselected")"
aria-pressed="@(Model.Selected == "month" ? "true" : "false")">
Past Month
</button>
</div>
</form>
<p>
Uptime percentage: @Model.UptimePercentage%
</p>
<table>
<tr>
<th>Timestamp</th>
<th>Event</th>
</tr>
@foreach (Models.OrcanodeEvent item in Model.RecentEvents)
{
<table class="table">
<thead>
<tr>
<td>
@item.DateTimeLocal
</td>
<td>
@item.Description
</td>
<th>Timestamp</th>
<th>Event</th>
</tr>
}
</thead>
<tbody>
@if (!Model.RecentEvents.Any())
{
<tr>
<td colspan="2" class="text-center">No events found for this time period.</td>
</tr>
}
@foreach (Models.OrcanodeEvent item in Model.RecentEvents)
{
<tr>
<td>@item.DateTimeLocal.ToString("g")</td>
<td align="left">@item.Description</td>
</tr>
}
</tbody>
</table>
</div>

<style>
.selected {
background-color: blue;
color: white;
}
</style>
24 changes: 18 additions & 6 deletions OrcanodeMonitor/Pages/NodeEvents.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OrcanodeMonitor.Pages
public class NodeEventsModel : PageModel
{
private OrcanodeMonitorContext _databaseContext;
private readonly ILogger<IndexModel> _logger;
private readonly ILogger<NodeEventsModel> _logger;
private string _nodeId;
public string Id => _nodeId;
[BindProperty]
Expand All @@ -22,26 +22,38 @@ public class NodeEventsModel : PageModel
public List<OrcanodeEvent> RecentEvents => _events;
public int UptimePercentage => Orcanode.GetUptimePercentage(_nodeId, _events, SinceTime);

public NodeEventsModel(OrcanodeMonitorContext context, ILogger<IndexModel> logger)
public NodeEventsModel(OrcanodeMonitorContext context, ILogger<NodeEventsModel> logger)
{
_databaseContext = context;
_logger = logger;
_nodeId = string.Empty;
_events = new List<OrcanodeEvent>();
}

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<OrcanodeEvent>();
}
}

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();
}
}
}
8 changes: 8 additions & 0 deletions OrcanodeMonitor/Pages/NodeEvents.cshtml.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ th, td {
h1 {
font-size: 32px;
}

.selected {
background-color: blue;
color: white;
}
.unselected {
border-color: blue;
}

0 comments on commit 467e3ce

Please sign in to comment.