diff --git a/PizzaBot/Components/ArchiveListComponent.razor b/PizzaBot/Components/ArchiveListComponent.razor
index 60efb0b..1a426fd 100644
--- a/PizzaBot/Components/ArchiveListComponent.razor
+++ b/PizzaBot/Components/ArchiveListComponent.razor
@@ -1,8 +1,9 @@
@inject ArchiveService ArchiveService
+
@using Microsoft.AspNetCore.Components.QuickGrid
-
+
@if (ShowOnlyTotalPizza)
{
@@ -13,6 +14,9 @@
}
+
+
+
@@ -27,11 +31,20 @@
[Parameter]
public bool ShowOnlyTotalPizza { get; set; }
+ [Parameter]
+ public string SecretPath { get; set; }
+
PaginationState Pagination;
protected override void OnInitialized()
{
base.OnInitialized();
Pagination = new PaginationState { ItemsPerPage = Number };
+
+ EventHandler Reload = async (sender, eventArgs) =>
+ {
+ await InvokeAsync(StateHasChanged);
+ };
+ ArchiveService.OnArchiveChange += Reload;
}
}
diff --git a/PizzaBot/Components/Pages/Admin.razor b/PizzaBot/Components/Pages/Admin.razor
index cb13157..88368f3 100644
--- a/PizzaBot/Components/Pages/Admin.razor
+++ b/PizzaBot/Components/Pages/Admin.razor
@@ -30,6 +30,9 @@
Confirm Message
+
Archive
+Go to archive
+
@if (GlobalStuffService.OrdersLocked)
{
Payment
diff --git a/PizzaBot/Components/Pages/AdminArchiveEntryEdit.razor b/PizzaBot/Components/Pages/AdminArchiveEntryEdit.razor
new file mode 100644
index 0000000..dd09ef3
--- /dev/null
+++ b/PizzaBot/Components/Pages/AdminArchiveEntryEdit.razor
@@ -0,0 +1,72 @@
+@page "/admin{secretpath}/archive/{entryIDstring}"
+
+@rendermode InteractiveServer
+
+@inject NavigationManager NavigationManager
+@inject ArchiveService ArchiveService
+
+Archive @(entry.date.ToString("yy-MM-dd"))
+
+Editing archive entry from @(entry.date.ToString("yyyy-MM-dd"))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@code {
+ [Parameter]
+ public string secretpath { get; set; }
+
+ [Parameter]
+ public string entryIDstring{ get; set; }
+
+ PizzaArchiveEntry entry;
+
+ protected override void OnInitialized()
+ {
+ if (secretpath != Environment.GetEnvironmentVariable("ADMIN_PATH"))
+ {
+ NavigationManager.NavigateTo("/"); return;
+ }
+
+ entry = ArchiveService.GetEntryByID(Int32.Parse(entryIDstring));
+ }
+
+ void FormSubmitted(EditContext editContext)
+ {
+ ArchiveService.ChangeEntry(entry);
+ NavigationManager.NavigateTo("/admin" + secretpath + "/archive");
+ }
+}
diff --git a/PizzaBot/Components/Pages/AdminPizzaArchive.razor b/PizzaBot/Components/Pages/AdminPizzaArchive.razor
index 7e07ea9..8f03470 100644
--- a/PizzaBot/Components/Pages/AdminPizzaArchive.razor
+++ b/PizzaBot/Components/Pages/AdminPizzaArchive.razor
@@ -28,7 +28,7 @@ else
@code {
diff --git a/PizzaBot/Program.cs b/PizzaBot/Program.cs
index 6e1472d..6e4dc18 100644
--- a/PizzaBot/Program.cs
+++ b/PizzaBot/Program.cs
@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using PizzaBot.Components;
using PizzaBot.Models;
using PizzaBot.Services;
+using Radzen;
var builder = WebApplication.CreateBuilder(args);
diff --git a/PizzaBot/Services/ArchiveService.cs b/PizzaBot/Services/ArchiveService.cs
index 89e991b..405ffc7 100644
--- a/PizzaBot/Services/ArchiveService.cs
+++ b/PizzaBot/Services/ArchiveService.cs
@@ -5,7 +5,7 @@ namespace PizzaBot.Services
{
using PizzaArchiveType = List;
- public struct PizzaArchiveEntry
+ public class PizzaArchiveEntry
{
// id should be a random number
public int id { get; set; }
@@ -32,6 +32,8 @@ namespace PizzaBot.Services
PizzaArchiveType _pizzaArchive;
Random _rng;
+ public event EventHandler OnArchiveChange;
+
public ArchiveService(JSONService jSONService)
{
_rng = new Random();
@@ -49,10 +51,7 @@ namespace PizzaBot.Services
public PizzaArchiveType GetAllEntries()
{
- PizzaArchiveType copy = _pizzaArchive;
- PizzaArchiveType? loaded = _jsonService.GetPizzaArchive();
- _pizzaArchive = loaded == null ? new PizzaArchiveType() : loaded;
- return copy;
+ return _pizzaArchive;
}
///
@@ -67,16 +66,37 @@ namespace PizzaBot.Services
return false;
}
- entry.id = _rng.Next();
+ if (entry.id == 0)
+ {
+ entry.id = _rng.Next();
+ }
_pizzaArchive.Add(entry);
SortArchive();
_jsonService.WriteNewPizzaArchive(_pizzaArchive);
+
+ OnArchiveChange.Invoke(this, null);
+
return true;
}
+ public void ChangeEntry(PizzaArchiveEntry entry)
+ {
+ lock (this)
+ {
+ RemoveEntry(entry.id);
+ AddEntry(entry);
+ }
+ }
+
+ public PizzaArchiveEntry GetEntryByID(int id)
+ {
+ return _pizzaArchive.Find(x => x.id == id);
+ }
+
public bool RemoveEntry(PizzaArchiveEntry entry)
{
- return _pizzaArchive.Remove(entry);
+ bool succesfull = _pizzaArchive.Remove(entry);
+ return succesfull;
}
public bool RemoveEntry(int id)
@@ -87,6 +107,9 @@ namespace PizzaBot.Services
return false;
}
_pizzaArchive.RemoveAt(index);
+
+ OnArchiveChange.Invoke(this, null);
+
return true;
}