objednavky detail pro admin
This commit is contained in:
593
Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Objednavky.razor
Normal file
593
Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Objednavky.razor
Normal file
@@ -0,0 +1,593 @@
|
||||
@page "/admin/objednavky"
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using Web_Jarmark.Data
|
||||
@using Web_Jarmark.Data.Models
|
||||
@inject ApplicationDbContext DbContext
|
||||
|
||||
<PageTitle>Objednávky | Web-Jarmark</PageTitle>
|
||||
|
||||
<main class="orders-page">
|
||||
<header class="orders-header">
|
||||
<div>
|
||||
<span class="orders-eyebrow">WEB-JARMARK / TESTOVACÍ REŽIM</span>
|
||||
<h1>Objednávky</h1>
|
||||
<p>Přehled všech objednávek a jejich aktuálního stavu.</p>
|
||||
</div>
|
||||
|
||||
<a href="/admin" class="back-link">← Administrace</a>
|
||||
</header>
|
||||
|
||||
@if (isLoading)
|
||||
{
|
||||
<div class="orders-message">Načítám objednávky...</div>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
<div class="orders-message error">@errorMessage</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<section class="orders-stats">
|
||||
<article class="stat-card">
|
||||
<span>Celkem objednávek</span>
|
||||
<strong>@orders.Count</strong>
|
||||
</article>
|
||||
|
||||
<article class="stat-card">
|
||||
<span>Čeká na zaplacení</span>
|
||||
<strong>@orders.Count(o => o.Status == OrderStatus.Pending)</strong>
|
||||
</article>
|
||||
|
||||
<article class="stat-card">
|
||||
<span>Zaplaceno</span>
|
||||
<strong>@orders.Count(o => o.Status == OrderStatus.Paid)</strong>
|
||||
</article>
|
||||
|
||||
<article class="stat-card">
|
||||
<span>Celková hodnota</span>
|
||||
<strong>@orders.Sum(o => o.TotalAmount).ToString("N0") Kč</strong>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="orders-panel">
|
||||
<div class="orders-panel-header">
|
||||
<div>
|
||||
<h2>Seznam objednávek</h2>
|
||||
<p>Celkem nalezeno: @FilteredOrders.Count</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="orders-filters">
|
||||
<input type="text"
|
||||
placeholder="Hledat podle čísla objednávky..."
|
||||
@bind="searchText"
|
||||
@bind:event="oninput" />
|
||||
|
||||
<select @bind="statusFilter">
|
||||
<option value="Vše">Všechny stavy</option>
|
||||
<option value="Čeká na zaplacení">Čeká na zaplacení</option>
|
||||
<option value="Zaplaceno">Zaplaceno</option>
|
||||
<option value="Odesláno">Odesláno</option>
|
||||
<option value="Dokončeno">Dokončeno</option>
|
||||
<option value="Zrušeno">Zrušeno</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@if (FilteredOrders.Count == 0)
|
||||
{
|
||||
<div class="orders-empty">
|
||||
<h3>Žádné objednávky</h3>
|
||||
<p>Zatím zde nejsou žádné objednávky odpovídající filtru.</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="orders-table-wrap">
|
||||
<table class="orders-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Objednávka</th>
|
||||
<th>Datum</th>
|
||||
<th>Platba</th>
|
||||
<th>Produkty</th>
|
||||
<th>Celkem</th>
|
||||
<th>Stav</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach (var order in FilteredOrders)
|
||||
{
|
||||
<tr @key="order.Id">
|
||||
<td class="order-code">#@order.Code</td>
|
||||
|
||||
<td>
|
||||
@order.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")
|
||||
</td>
|
||||
|
||||
<td>@GetPaymentText(order.PreferredPayment)</td>
|
||||
|
||||
<td>@order.OrderItems.Sum(i => i.Quantity) ks</td>
|
||||
|
||||
<td class="order-price">
|
||||
@order.TotalAmount.ToString("N0") Kč
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<span class="status-badge @GetStatusClass(order.Status)">
|
||||
@GetStatusText(order.Status)
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<button class="detail-button"
|
||||
@onclick="() => ToggleDetail(order.Id)">
|
||||
@(selectedOrderId == order.Id ? "Zavřít" : "Detail")
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@if (selectedOrderId == order.Id)
|
||||
{
|
||||
<tr class="detail-row">
|
||||
<td colspan="7">
|
||||
<div class="order-detail">
|
||||
<h3>Objednávka #@order.Code</h3>
|
||||
|
||||
<div class="detail-info">
|
||||
<div>
|
||||
<span>Datum vytvoření</span>
|
||||
<strong>
|
||||
@order.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>Způsob platby</span>
|
||||
<strong>
|
||||
@GetPaymentText(order.PreferredPayment)
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>Stav objednávky</span>
|
||||
<strong>
|
||||
@GetStatusText(order.Status)
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4>Objednané produkty</h4>
|
||||
|
||||
<div class="detail-products">
|
||||
@foreach (var item in order.OrderItems)
|
||||
{
|
||||
<div class="detail-product" @key="item.Id">
|
||||
<div>
|
||||
<strong>@item.ProductName</strong>
|
||||
<span>
|
||||
@item.Quantity ks ×
|
||||
@item.UnitPrice.ToString("N0") Kč
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<strong>
|
||||
@((item.Quantity * item.UnitPrice).ToString("N0")) Kč
|
||||
</strong>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="detail-total">
|
||||
<span>Celková cena</span>
|
||||
<strong>
|
||||
@order.TotalAmount.ToString("N0") Kč
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.orders-page {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
padding: 45px 24px 70px;
|
||||
color: var(--bs-body-color, #222);
|
||||
}
|
||||
|
||||
.orders-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.orders-eyebrow {
|
||||
color: #2878ff;
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
.orders-header h1 {
|
||||
margin: 10px 0;
|
||||
font-size: clamp(28px, 4vw, 40px);
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.orders-header p,
|
||||
.orders-panel-header p {
|
||||
opacity: .65;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
text-decoration: none;
|
||||
font-weight: 700;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.orders-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 16px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.stat-card,
|
||||
.orders-panel {
|
||||
background: var(--bs-body-bg, white);
|
||||
border: 1px solid rgba(128,128,128,.2);
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 5px 20px rgba(0,0,0,.035);
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 22px;
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.stat-card span {
|
||||
font-size: 13px;
|
||||
opacity: .65;
|
||||
}
|
||||
|
||||
.stat-card strong {
|
||||
font-size: 27px;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.orders-panel {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.orders-panel-header {
|
||||
padding: 23px 25px;
|
||||
}
|
||||
|
||||
.orders-panel-header h2 {
|
||||
margin: 0 0 6px;
|
||||
font-size: 21px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.orders-filters {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 0 25px 22px;
|
||||
}
|
||||
|
||||
.orders-filters input,
|
||||
.orders-filters select {
|
||||
min-height: 44px;
|
||||
padding: 10px 13px;
|
||||
border: 1px solid rgba(128,128,128,.3);
|
||||
border-radius: 9px;
|
||||
background: var(--bs-body-bg, white);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.orders-filters input {
|
||||
flex: 1;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.orders-filters select {
|
||||
min-width: 210px;
|
||||
}
|
||||
|
||||
.orders-table-wrap {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.orders-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.orders-table th {
|
||||
padding: 15px 18px;
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .5px;
|
||||
opacity: .6;
|
||||
background: rgba(128,128,128,.06);
|
||||
}
|
||||
|
||||
.orders-table td {
|
||||
padding: 17px 18px;
|
||||
border-top: 1px solid rgba(128,128,128,.13);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.order-code {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.order-price {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 6px 10px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.status-pending {
|
||||
background: #fff3d6;
|
||||
color: #996500;
|
||||
}
|
||||
|
||||
.status-paid {
|
||||
background: #e3f8eb;
|
||||
color: #167b40;
|
||||
}
|
||||
|
||||
.status-shipped {
|
||||
background: #e5efff;
|
||||
color: #2863b5;
|
||||
}
|
||||
|
||||
.status-delivered {
|
||||
background: #e3f8eb;
|
||||
color: #167b40;
|
||||
}
|
||||
|
||||
.status-cancelled {
|
||||
background: #ffe8e8;
|
||||
color: #b52d2d;
|
||||
}
|
||||
|
||||
.detail-button {
|
||||
padding: 8px 13px;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: #2878ff;
|
||||
color: white;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.detail-row td {
|
||||
padding: 0;
|
||||
background: rgba(128,128,128,.045);
|
||||
}
|
||||
|
||||
.order-detail {
|
||||
padding: 25px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.order-detail h3 {
|
||||
margin: 0 0 22px;
|
||||
font-size: 20px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.detail-info {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 20px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.detail-info div {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.detail-info span,
|
||||
.detail-product span {
|
||||
font-size: 13px;
|
||||
opacity: .65;
|
||||
}
|
||||
|
||||
.order-detail h4 {
|
||||
margin-bottom: 12px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.detail-product,
|
||||
.detail-total {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding: 14px 0;
|
||||
border-top: 1px solid rgba(128,128,128,.15);
|
||||
}
|
||||
|
||||
.detail-product div {
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.detail-total {
|
||||
margin-top: 10px;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.detail-total strong {
|
||||
font-size: 23px;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.orders-empty,
|
||||
.orders-message {
|
||||
padding: 45px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.orders-empty p {
|
||||
opacity: .65;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #c33;
|
||||
}
|
||||
|
||||
@@media (max-width: 850px) {
|
||||
.orders-stats {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.orders-header {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
@@media (max-width: 550px) {
|
||||
.orders-page {
|
||||
padding: 25px 12px 45px;
|
||||
}
|
||||
|
||||
.orders-filters {
|
||||
flex-direction: column;
|
||||
padding: 0 15px 18px;
|
||||
}
|
||||
|
||||
.orders-filters select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.detail-info {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.stat-card strong {
|
||||
font-size: 22px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@code {
|
||||
private List<Order> orders = new();
|
||||
|
||||
private bool isLoading = true;
|
||||
private string? errorMessage;
|
||||
|
||||
private string searchText = "";
|
||||
private string statusFilter = "Vše";
|
||||
|
||||
private int? selectedOrderId;
|
||||
|
||||
private List<Order> FilteredOrders =>
|
||||
orders
|
||||
.Where(o =>
|
||||
string.IsNullOrWhiteSpace(searchText) ||
|
||||
o.Code.Contains(searchText.Trim(), StringComparison.OrdinalIgnoreCase))
|
||||
.Where(o =>
|
||||
statusFilter == "Vše" ||
|
||||
GetStatusText(o.Status) == statusFilter)
|
||||
.ToList();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
orders = await DbContext.Orders
|
||||
.AsNoTracking()
|
||||
.Include(o => o.OrderItems)
|
||||
.OrderByDescending(o => o.CreatedAt)
|
||||
.ToListAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
errorMessage = "Objednávky se nepodařilo načíst.";
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleDetail(int orderId)
|
||||
{
|
||||
selectedOrderId = selectedOrderId == orderId
|
||||
? null
|
||||
: orderId;
|
||||
}
|
||||
|
||||
private static string GetStatusText(OrderStatus status)
|
||||
{
|
||||
return status switch
|
||||
{
|
||||
OrderStatus.Pending => "Čeká na zaplacení",
|
||||
OrderStatus.Paid => "Zaplaceno",
|
||||
OrderStatus.Shipped => "Odesláno",
|
||||
OrderStatus.Delivered => "Dokončeno",
|
||||
OrderStatus.Cancelled => "Zrušeno",
|
||||
_ => "Neznámý stav"
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetStatusClass(OrderStatus status)
|
||||
{
|
||||
return status switch
|
||||
{
|
||||
OrderStatus.Pending => "status-pending",
|
||||
OrderStatus.Paid => "status-paid",
|
||||
OrderStatus.Shipped => "status-shipped",
|
||||
OrderStatus.Delivered => "status-delivered",
|
||||
OrderStatus.Cancelled => "status-cancelled",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetPaymentText(PaymentMethod method)
|
||||
{
|
||||
return method switch
|
||||
{
|
||||
PaymentMethod.BankTransfer => "Bankovní převod",
|
||||
PaymentMethod.Cash => "Hotově",
|
||||
PaymentMethod.CreditCard => "Platební karta",
|
||||
PaymentMethod.PayPal => "PayPal",
|
||||
_ => "Neznámý způsob"
|
||||
};
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user