Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion Sloth.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -8,6 +10,7 @@
using Sloth.Core.Resources;
using Sloth.Web.Identity;
using Sloth.Web.Models;
using Sloth.Web.Models.HomeViewModels;
using Sloth.Web.Resources;

namespace Sloth.Web.Controllers
Expand All @@ -29,7 +32,55 @@ public async Task<IActionResult> Index()
return RedirectToAction(nameof(TransactionsController.Index), "Transactions", new { team = team.Slug });
}

return View(teams);
var teamIds = teams.Select(t => t.Id).ToList();
var teamSlugs = teams.Select(t => t.Slug).ToList();
var stuckCutoff = DateTime.UtcNow.Date.AddDays(-1);

var teamsWithSources = await DbContext.Teams
.Include(t => t.Sources)
.Where(t => teamIds.Contains(t.Id))
.AsNoTracking()
.OrderBy(t => t.Name)
.ToListAsync();

var failedTransactionCounts = await DbContext.Transactions
.Where(t => teamSlugs.Contains(t.Source.Team.Slug)
&& t.Status == TransactionStatuses.Rejected)
.GroupBy(t => t.Source.Team.Slug)
.Select(t => new
{
Slug = t.Key,
Count = t.Count(),
})
.ToDictionaryAsync(t => t.Slug, t => t.Count);

var stuckTransactionCounts = await DbContext.Transactions
.Where(t => teamSlugs.Contains(t.Source.Team.Slug)
&& ((t.Status == TransactionStatuses.Processing && t.LastModified < stuckCutoff)
|| (t.Status == TransactionStatuses.Scheduled && t.LastModified < stuckCutoff)))
.GroupBy(t => t.Source.Team.Slug)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
.Select(t => new
{
Slug = t.Key,
Count = t.Count(),
})
.ToDictionaryAsync(t => t.Slug, t => t.Count);

var model = new HomeIndexViewModel
{
Teams = teamsWithSources
.Select(t => new HomeTeamSummaryViewModel
{
Name = t.Name,
Slug = t.Slug,
SourceNames = t.Sources?.OrderBy(s => s.Name).Select(s => s.Name).ToList() ?? new List<string>(),
FailedTransactionCount = failedTransactionCounts.TryGetValue(t.Slug, out var failedCount) ? failedCount : 0,
StuckTransactionCount = stuckTransactionCounts.TryGetValue(t.Slug, out var stuckCount) ? stuckCount : 0,
})
.ToList(),
};

return View(model);
}

[Authorize(Policy = PolicyCodes.TeamAnyRole)]
Expand Down
22 changes: 22 additions & 0 deletions Sloth.Web/Models/HomeViewModels/HomeIndexViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace Sloth.Web.Models.HomeViewModels
{
public class HomeIndexViewModel
{
public IReadOnlyList<HomeTeamSummaryViewModel> Teams { get; set; } = new List<HomeTeamSummaryViewModel>();
}

public class HomeTeamSummaryViewModel
{
public string Name { get; set; }

public string Slug { get; set; }

public IReadOnlyList<string> SourceNames { get; set; } = new List<string>();

public int FailedTransactionCount { get; set; }

public int StuckTransactionCount { get; set; }
}
}
82 changes: 54 additions & 28 deletions Sloth.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
@using Sloth.Core.Resources
@model IEnumerable<Sloth.Core.Models.Team>
@model Sloth.Web.Models.HomeViewModels.HomeIndexViewModel
@{
ViewData["Title"] = "Home Page";
}

<div class="container">
<div class="row">
<div class="col">
<h1>SLOTH</h1>
<ul>
<li>Secure <span style="text-decoration: line-through">Scrubber</span></li>
<li>Ledger <span style="text-decoration: line-through">Loader</span></li>
<li>Online</li>
<li>Transaction</li>
<li>Hub</li>
</ul>
</div>
</div>

@if (User.IsInRole(Roles.SystemAdmin))
{
<div class="container home-page">
<div class="home-heading">
<h1>S.L.O.T.H.</h1>
<p>Secure Ledger Online Transaction Hub</p>
</div>

<h2>All Teams:</h2>
<div class="home-teams">
<h2>@(User.IsInRole(Roles.SystemAdmin) ? "All Teams" : "Your Teams")</h2>

<div class="row flex-column align-items-start justify-content-center">
@foreach (var team in Model)
{
<div class="col-sm-12 col-md-5">
<a asp-controller="Home" asp-action="TeamIndex" asp-route-team="@team.Slug">
<span>@team.Name</span>
</a>
</div>
}
<div class="responsive-table">
<table id="homeTeamsTable" class="table sloth-table active-table">
<thead>
<tr>
<th>Name</th>
<th>Slug</th>
<th>Sources</th>
<th>Rejected Transactions</th>
<th>Stuck Transactions</th>
</tr>
</thead>
<tbody>
@foreach (var team in Model.Teams)
{
var teamUrl = Url.Action("TeamIndex", "Home", new { team = team.Slug });
<tr data-href="@teamUrl">
<td>
<a href="@teamUrl">@team.Name</a>
</td>
<td>@team.Slug</td>
<td>@(team.SourceNames.Any() ? string.Join(", ", team.SourceNames) : "None")</td>
<td>@team.FailedTransactionCount</td>
<td>@team.StuckTransactionCount</td>
</tr>
}
</tbody>
</table>
</div>
}
</div>
</div>

@section AdditionalScripts {
<script>
$('#homeTeamsTable').DataTable({
order: [[0, 'asc']],
pageLength: -1,
lengthMenu: [[10, 25, 50, -1], [10, 25, 50, 'All']],
language: {
searchPlaceholder: "Search Table",
search: "",
},
});

$('#homeTeamsTable tbody').on('click', 'tr', function () {
window.location = $(this).data('href');
});
</script>
}
49 changes: 49 additions & 0 deletions Sloth.Web/wwwroot/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,55 @@ footer {
.body-content {
padding-top: 2rem;
}
.home-page {
.home-heading {
width: 100%;
max-width: 960px;
margin: 0;
padding: 2.5rem 0 1.25rem;

h1 {
margin-bottom: 0.1rem;
font-size: 2rem;
line-height: 1.1;
}

p {
margin-bottom: 0;
color: $secondary-font;
font-size: 0.95rem;
text-transform: uppercase;
}
}

.home-teams {
margin-top: 3.5rem;

h2 {
display: inline-block;
margin: 0 0 1rem;
padding-bottom: 0.45rem;
border-bottom: 3px solid $primary-color;
color: $primary-color;
font-size: 1.5rem;
line-height: 1.2;
}
}

.responsive-table {
border: 1px solid $borders-sloth;
background-color: #fff;
}

table.sloth-table {
margin-bottom: 0;
border: 0;

thead th {
background-color: $bg-primary;
}
}
}
.filters-wrapper {
margin-bottom: 3%;
.status-filter {
Expand Down
Loading