From ab65bdaf1b5e2c6e4dd2523708739465b86d08d6 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 27 Mar 2024 21:20:45 +0000 Subject: Added table styling and CSV button --- Pages/Report.cshtml | 10 ++++++---- Pages/Report.cshtml.cs | 28 ++++++++++++++++++++++++++++ Pages/Shared/_Layout.cshtml | 4 ++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Pages/Report.cshtml b/Pages/Report.cshtml index 624d61f..4b5907b 100644 --- a/Pages/Report.cshtml +++ b/Pages/Report.cshtml @@ -24,16 +24,18 @@

Download Details

- + + +
- + - + @foreach(Download obj in Model.Rows) { - +
TimeTime KeyInfoInfo
@obj.Time@obj.Time.ToString("o", System.Globalization.CultureInfo.InvariantCulture) @obj.Key @foreach (string s in obj.Info) diff --git a/Pages/Report.cshtml.cs b/Pages/Report.cshtml.cs index 76cfabf..d40f89d 100644 --- a/Pages/Report.cshtml.cs +++ b/Pages/Report.cshtml.cs @@ -19,6 +19,9 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Npgsql; using System.Collections.Generic; using download_admin; +using Microsoft.AspNetCore.Http.HttpResults; +using System.Text; +using System.Text.Encodings; namespace download_admin.Pages; @@ -27,7 +30,32 @@ public class ReportModel : PageModel public void OnGet() { ViewData["Title"] = "Download Repsoitory Report"; + GetData(); + } + + public IActionResult OnPost() + { + GetData(); + + StringBuilder str = new StringBuilder(); + + foreach (var row in Rows) + { + str.AppendFormat("{0},{1}", row.Time.ToString("o", System.Globalization.CultureInfo.InvariantCulture), row.Key); + foreach (var s in row.Info) + { + str.AppendFormat(",{0}", s); + } + str.AppendLine(); + } + byte[] file_data = UTF8Encoding.UTF8.GetBytes(str.ToString()); + + return File(file_data, "text/csv","downloads.csv"); + } + + private void GetData() + { try { Rows = new List(); diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index cc18cc7..fdce3ee 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -7,6 +7,10 @@ +
-- cgit v1.2.3