summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2024-03-27 21:20:45 +0000
committerIan C <ianc@noddybox.co.uk>2024-03-27 21:20:45 +0000
commitab65bdaf1b5e2c6e4dd2523708739465b86d08d6 (patch)
tree2ea3f6e6396ef615a337e8533067cd4517e747bc
parent57acc97e1f9d76c2edbb4eeabae4ea3dd635bb77 (diff)
Added table styling and CSV buttonHEAD1.1master
-rw-r--r--Pages/Report.cshtml10
-rw-r--r--Pages/Report.cshtml.cs28
-rw-r--r--Pages/Shared/_Layout.cshtml4
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 @@
<h1>Download Details</h1>
-<table style width="100%">
+<form method="post" enctype="application/x-www-form-urlencoded"><input type="submit" name="csv" value="Download CSV"></form>
+
+<table style="width=100%;">
<tr>
- <td style="width:20%;"><b>Time</b></td>
+ <td style="width:25%;"><b>Time</b></td>
<td style="width:15%;"><b>Key</b></td>
- <td style="width:65%;"><b>Info</b></td>
+ <td style="width:60%;"><b>Info</b></td>
</tr>
@foreach(Download obj in Model.Rows)
{
<tr>
- <td>@obj.Time</td>
+ <td>@obj.Time.ToString("o", System.Globalization.CultureInfo.InvariantCulture)</td>
<td>@obj.Key</td>
<td>
@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<Download>();
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 @@
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/download_admin.styles.css" asp-append-version="true" />
+ <style>
+ table {border: 1px solid black;border-collapse:collapse;}
+ td {border: 1px solid black;border-collapse:collapse;text-align: left;vertical-align: top;padding: 5px;}
+ </style>
</head>
<body>
<header>