From 7f99330b4cb49b12597f51098fef3f2dd7bc228d Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Fri, 8 Mar 2024 12:51:27 -0800 Subject: [PATCH] WIP --- Sloth.Web/Controllers/ReportsController.cs | 10 +++--- .../TransfersReportViewModel.cs | 2 +- Sloth.Web/Sloth.Web.csproj | 2 ++ Sloth.Web/Startup.cs | 13 ++++++++ .../Reports/DownloadableTransactions.cshtml | 33 +++++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 Sloth.Web/Views/Reports/DownloadableTransactions.cshtml diff --git a/Sloth.Web/Controllers/ReportsController.cs b/Sloth.Web/Controllers/ReportsController.cs index c81852ee..4f3dd5a4 100644 --- a/Sloth.Web/Controllers/ReportsController.cs +++ b/Sloth.Web/Controllers/ReportsController.cs @@ -66,6 +66,8 @@ public async Task FailedTransactions() return View("FailedTransactions", model); } + [Route("{team}/reports/downloadabletransactions/{filter?}")] + [HttpGet] public async Task DownloadableTransactions(TransactionsFilterModel filter = null) { if (string.IsNullOrWhiteSpace(TeamSlug)) @@ -76,19 +78,19 @@ public async Task DownloadableTransactions(TransactionsFilterMode if (filter == null) filter = new TransactionsFilterModel(); - filter.From = filter.From = new DateTime(2023, 10, 12); - filter.To = filter.To = new DateTime(2023, 10, 15); - FilterHelpers.SanitizeTransactionsFilter(filter); var model = new TransfersReportViewModel { - filter = filter, + Filter = filter, }; model.Transactions = await DbContext.Transactions.Include(a => a.Transfers).Include(a => a.Metadata) .Where(t => t.Source.Team.Slug == TeamSlug && t.TransactionDate >= filter.From && t.TransactionDate <= filter.To).Select(TransactionWithTransfers.Projection()).ToListAsync(); + var team = await DbContext.Teams.FirstAsync(t => t.Slug == TeamSlug); + ViewBag.Title = $"Transactions with Transfers - {team.Name}"; + return View(model); } diff --git a/Sloth.Web/Models/ReportViewModels/TransfersReportViewModel.cs b/Sloth.Web/Models/ReportViewModels/TransfersReportViewModel.cs index 91189cdf..6e7367d5 100644 --- a/Sloth.Web/Models/ReportViewModels/TransfersReportViewModel.cs +++ b/Sloth.Web/Models/ReportViewModels/TransfersReportViewModel.cs @@ -12,7 +12,7 @@ namespace Sloth.Web.Models.ReportViewModels { public class TransfersReportViewModel { - public TransactionsFilterModel filter { get; set; } + public TransactionsFilterModel Filter { get; set; } public IList Transactions { get; set; } } diff --git a/Sloth.Web/Sloth.Web.csproj b/Sloth.Web/Sloth.Web.csproj index 4841b318..4b20a2e1 100644 --- a/Sloth.Web/Sloth.Web.csproj +++ b/Sloth.Web/Sloth.Web.csproj @@ -22,6 +22,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Sloth.Web/Startup.cs b/Sloth.Web/Startup.cs index 1d577b19..e0ee9373 100644 --- a/Sloth.Web/Startup.cs +++ b/Sloth.Web/Startup.cs @@ -164,6 +164,19 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseEndpoints(routes => { + + //A team specific reports route (needed because this report has a filter) + //I replaced this with a route on the action + //routes.MapControllerRoute( + // name: "team-report-downloadable-transactions", + // pattern: "{team}/reports/downloadabletransactions", + // defaults: new { controller = "Reports", action = "DownloadableTransactions" }, + // constraints: new + // { + // team = new CompositeRouteConstraint(new IRouteConstraint[] { + // new RegexInlineRouteConstraint(Team.SlugRegex), + // }) + // }); // non team root routes routes.MapControllerRoute( name: "non-team-routes", diff --git a/Sloth.Web/Views/Reports/DownloadableTransactions.cshtml b/Sloth.Web/Views/Reports/DownloadableTransactions.cshtml new file mode 100644 index 00000000..2c4454e7 --- /dev/null +++ b/Sloth.Web/Views/Reports/DownloadableTransactions.cshtml @@ -0,0 +1,33 @@ +@model Sloth.Web.Models.ReportViewModels.TransfersReportViewModel + +@using Microsoft.AspNetCore.Http +@using Microsoft.AspNetCore.Routing +@inject IHttpContextAccessor HttpContextAccessor +@{ + var teamSlug = HttpContextAccessor.HttpContext.GetRouteData().Values["team"] as string; +} + + +
+

@ViewBag.Title

+ +

Filters

+
+
+
+
+ + to + +
+ + +
+ +
+
+
@teamSlug
+ +
@Model.Transactions.Count
+ +