Completed Archive

some funcionality should be added later. This includes the option to
show total ordered pizzas and to show stats computed by using the
anonymizedorders
This commit is contained in:
Tea 2024-03-07 15:58:45 +01:00
parent 077b8e7f48
commit bb5ae96b31
6 changed files with 121 additions and 9 deletions

View file

@ -1,8 +1,9 @@
@inject ArchiveService ArchiveService
@using Microsoft.AspNetCore.Components.QuickGrid
<QuickGrid Pagination="Pagination" Items="@ArchiveService.GetAllEntries().AsQueryable()">
<PropertyColumn Property="@(e => e.date)" Format="yyyy.MM.dd" Sortable="true" />
<PropertyColumn Property="@(e => e.date)" Format="yyyy.MM.dd" Sortable="true" InitialSortDirection="SortDirection.Descending" IsDefaultSortColumn="true" />
@if (ShowOnlyTotalPizza)
{
<PropertyColumn Title="Pizzas" Property="@(e => (e.MeatPizzas + e.VeggiePizzas + e.VeganPizzas))" Sortable="true" />
@ -13,6 +14,9 @@
}
<PropertyColumn Title="🍾" Property="@(e => e.Bottles)" Sortable="false" />
<PropertyColumn Title="€" Property="@(e=>e.TotalCost)" />
<TemplateColumn Title="🔧" Sortable="false">
<a href="/admin@(SecretPath)/archive/@(context.id)"><button class="btn btn-info" style="width: 2em; height: 2em; padding: 0; text-align:center;">🔧</button></a>
</TemplateColumn>
</QuickGrid>
<Paginator State="@Pagination" />
@ -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;
}
}

View file

@ -30,6 +30,9 @@
Confirm Message
</button>
<h4>Archive</h4>
<a href="/admin@(secretpath)/archive"><div class="btn btn-primary">Go to archive</div></a>
@if (GlobalStuffService.OrdersLocked)
{
<h4>Payment</h4>

View file

@ -0,0 +1,72 @@
@page "/admin{secretpath}/archive/{entryIDstring}"
@rendermode InteractiveServer
@inject NavigationManager NavigationManager
@inject ArchiveService ArchiveService
<PageTitle>Archive @(entry.date.ToString("yy-MM-dd"))</PageTitle>
<h3>Editing archive entry from @(entry.date.ToString("yyyy-MM-dd"))</h3>
<EditForm Model="@entry" OnValidSubmit="@FormSubmitted" FormName="EntryEditForm">
<div class="form-goup">
<label for="datePicker">Date</label>
<InputDate @bind-Value=entry.date class="form-control" id="datePicker" />
</div>
<div class="row" id="PiecesGroup">
<div class="form-group col">
<label for="meatPieces">🍖</label>
<InputNumber @bind-Value=entry.MeatPizzas class="form-control" id="meatPieces" ParsingErrorMessage="Must be integer value" />
</div>
<div class="form-group col">
<label for="vegetarianPieces">🍄 + 🧀</label>
<InputNumber @bind-Value=entry.VeggiePizzas class="form-control" id="vegetarianPieces" ParsingErrorMessage="Must be integer value" />
</div>
<div class="form-group col">
<label for="veganPieces">🌽</label>
<InputNumber @bind-Value=entry.VeganPizzas class="form-control" id="veganPieces" ParsingErrorMessage="Must be integer value" />
</div>
</div>
<div class="row">
<div class="form-group col">
<label for="cost">Total Cost</label>
<InputNumber TValue="float" @bind-Value=entry.TotalCost class="form-control" id="cost" ParsingErrorMessage="Must be float" />
</div>
<div class="form-goup col">
<label for="bottles">Bottles returned</label>
<InputNumber @bind-Value=entry.Bottles class="form-control" id="bottles" />
</div>
</div>
<div class="form-group">
<label for="annotation">Annotation</label>
<InputTextArea @bind-Value=entry.Annotation class="form-control" id="annotation" />
</div>
<input type="submit" value="💾 Save Changes 💾" class="btn btn-primary" />
</EditForm>
@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");
}
}

View file

@ -28,7 +28,7 @@ else
<hr>
<div style="overflow-x:scroll;">
<ArchiveListComponent Number="25" />
<ArchiveListComponent Number="25" SecretPath="@(Environment.GetEnvironmentVariable("ADMIN_PATH"))" />
</div>
@code {

View file

@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using PizzaBot.Components;
using PizzaBot.Models;
using PizzaBot.Services;
using Radzen;
var builder = WebApplication.CreateBuilder(args);

View file

@ -5,7 +5,7 @@ namespace PizzaBot.Services
{
using PizzaArchiveType = List<PizzaArchiveEntry>;
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;
}
/// <summary>
@ -67,16 +66,37 @@ namespace PizzaBot.Services
return false;
}
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;
}