From e4550576df85c14f78ccac461d62ded5e8453e91 Mon Sep 17 00:00:00 2001 From: Ondur Date: Wed, 4 Nov 2026 18:04:23 +0100 Subject: [PATCH] vylepseni admin --- .../Components/Layout/Admin/AdminLayout.razor | 87 ++- .../Layout/Admin/AdminLayout.razor.css | 222 +++++- .../Layout/Admin/AdminNavMenu.razor | 84 +- .../Components/Pages/Admin/Admin.razor | 472 +++++++----- .../Components/Pages/Admin/Admin.razor.css | 717 ++++++++++++++++++ .../Components/Pages/Admin/CategoriEdit.razor | 276 +++---- .../Components/Pages/Admin/CategoriList.razor | 251 ++---- .../Components/Pages/Admin/ProductEdit.razor | 369 ++++----- .../Components/Pages/Admin/ProductList.razor | 290 +++---- Web-Jarmark/Web-Jarmark/jarmark.db-shm | Bin 32768 -> 32768 bytes Web-Jarmark/Web-Jarmark/jarmark.db-wal | Bin 799312 -> 807552 bytes 11 files changed, 1767 insertions(+), 1001 deletions(-) create mode 100644 Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor.css diff --git a/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor b/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor index d03acb4..416bdf3 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor @@ -1,22 +1,85 @@ @inherits LayoutComponentBase +@implements IDisposable +@inject NavigationManager Nav -
+
+ + +
+
+
@SectionTitle
+
+ + Administrátor
-
+
@Body -
- - + +
+ +@code { + private bool collapsed; + private string SectionTitle = "Přehled"; + + protected override void OnInitialized() + { + UpdateTitle(); + Nav.LocationChanged += OnLocationChanged; + } + + private void OnLocationChanged(object? sender, LocationChangedEventArgs e) + { + UpdateTitle(); + _ = InvokeAsync(StateHasChanged); + } + + private void UpdateTitle() + { + var path = "/" + Nav.ToBaseRelativePath(Nav.Uri).Split('?', '#')[0].Trim('/'); + + SectionTitle = path switch + { + "/admin" => "Přehled", + var p when p.StartsWith("/admin/kategorie") => "Kategorie", + var p when p.StartsWith("/admin/zbozi") => "Zboží", + var p when p.StartsWith("/admin/objednavky") => "Objednávky", + var p when p.StartsWith("/admin/administratori") => "Administrátoři", + var p when p.StartsWith("/admin/zakaznici") => "Administrátoři", + var p when p.StartsWith("/admin/sklad") => "Sklad", + var p when p.StartsWith("/admin/statistiky") => "Statistiky", + var p when p.StartsWith("/admin/nastaveni") => "Nastavení", + _ => "Administrace" + }; + } + + private void Toggle() => collapsed = !collapsed; + + public void Dispose() => Nav.LocationChanged -= OnLocationChanged; +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor.css b/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor.css index 56df3cb..f0f6749 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor.css +++ b/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminLayout.razor.css @@ -1,40 +1,216 @@ -/* Administrátorské rozložení */ -.wj-dashboard { +/* Nový admin shell – třídy admin-*, ať se nesráží se starým app.css */ + +.admin-shell { + --bg: #f3f3f3; + --surface: #ffffff; + --ink: #111111; + --muted: #6b6b6b; + --line: #e4e4e4; + --hover: #f0f0f0; + --active: #111111; + --sidebar: 250px; + --sidebar-collapsed: 78px; + --radius: 12px; display: flex; - width: 100%; min-height: 100vh; - margin: 0; - padding: 0; - overflow-x: hidden; - background: #f8f8f8; + background: var(--bg); + color: var(--ink); + font-family: Inter, "Segoe UI", system-ui, sans-serif; + font-size: 14px; } -.wj-main { +/* SIDEBAR */ +.admin-sidebar { + width: var(--sidebar); + flex-shrink: 0; + position: sticky; + top: 0; + height: 100vh; + display: flex; + flex-direction: column; + background: var(--surface); + border-right: 1px solid var(--line); + transition: width 0.25s ease; + overflow: hidden; +} + +.admin-shell.is-collapsed .admin-sidebar { + width: var(--sidebar-collapsed); +} + +.admin-sidebar-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + padding: 18px 14px 10px; +} + +.admin-logo { + display: flex; + align-items: center; + gap: 10px; + text-decoration: none; + color: var(--ink); + min-width: 0; +} + +.admin-logo-mark { + width: 36px; + height: 36px; + display: grid; + place-items: center; + background: #111; + color: #fff; + border-radius: 10px; + font-weight: 800; + flex-shrink: 0; +} + + .admin-logo-mark.small { + width: 30px; + height: 30px; + font-size: 12px; + border-radius: 8px; + } + +.admin-logo-text { + font-weight: 750; + font-size: 15px; + white-space: nowrap; +} + +.admin-shell.is-collapsed .admin-logo-text, +.admin-shell.is-collapsed .admin-foot-text { + display: none; +} + +.admin-toggle { + width: 34px; + height: 34px; + border: 1px solid var(--line); + border-radius: 10px; + background: #fff; + cursor: pointer; + flex-shrink: 0; +} + + .admin-toggle:hover { + background: var(--hover); + } + +.admin-sidebar-foot { + margin-top: auto; + padding: 12px; + border-top: 1px solid var(--line); + display: flex; + align-items: center; + gap: 10px; +} + +.admin-foot-text strong { + display: block; + font-size: 12px; +} + +.admin-foot-text small { + display: block; + color: var(--muted); + font-size: 11px; + margin-top: 2px; +} + +/* MAIN */ +.admin-main { flex: 1; min-width: 0; - min-height: 100vh; display: flex; flex-direction: column; } -.wj-content { - flex: 1; - width: 100%; - min-width: 0; - padding: 28px 32px; - box-sizing: border-box; +.admin-topbar { + height: 64px; + padding: 0 28px; + display: flex; + align-items: center; + justify-content: space-between; + background: rgba(255, 255, 255, 0.92); + border-bottom: 1px solid var(--line); + position: sticky; + top: 0; + z-index: 10; } -/* Plynulé přechody */ -.wj-main, -.wj-content { - transition: all 0.25s ease; +.admin-topbar-title { + font-size: 17px; + font-weight: 700; } -/* Menší obrazovky */ -@media (max-width: 768px) { - .wj-content { - padding: 20px 16px; +.admin-topbar-user { + display: flex; + align-items: center; + gap: 8px; + font-weight: 600; + font-size: 13px; +} + +.admin-dot { + width: 8px; + height: 8px; + border-radius: 50%; + background: #111; + box-shadow: 0 0 0 3px #ececec; +} + +.admin-content { + padding: 28px 32px 40px; +} + +/* MENU uvnitř sidebaru (přes ::deep, protože je v child komponentě) */ +::deep .admin-nav { + display: flex; + flex-direction: column; + gap: 4px; + padding: 8px 10px 16px; +} + +::deep .admin-nav-link { + display: flex; + align-items: center; + gap: 12px; + padding: 11px 12px; + border-radius: 10px; + color: #444; + text-decoration: none; + font-weight: 600; + transition: background 0.15s ease, color 0.15s ease; + white-space: nowrap; +} + + ::deep .admin-nav-link:hover { + background: var(--hover); + color: #111; } + + ::deep .admin-nav-link.active { + background: #111; + color: #fff; + } + +::deep .admin-nav-ico { + width: 22px; + text-align: center; + flex-shrink: 0; + font-size: 15px; + opacity: 0.9; } +.admin-shell.is-collapsed ::deep .admin-nav-label { + display: none; +} + +.admin-shell.is-collapsed ::deep .admin-nav-link { + justify-content: center; + padding-left: 0; + padding-right: 0; +} diff --git a/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminNavMenu.razor b/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminNavMenu.razor index 54044ee..f8b0fff 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminNavMenu.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Layout/Admin/AdminNavMenu.razor @@ -1,62 +1,47 @@ @implements IDisposable @inject NavigationManager Nav - + + ⚙ + Nastavení + + @code { private string CurrentPath => "/" + @@ -90,5 +75,4 @@ { Nav.LocationChanged -= HandleLocationChanged; } -} - +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor index 3342d9c..3939ea9 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor @@ -11,196 +11,248 @@ Přehled administrace -
-
-
VÁŠ OBCHOD NA JEDNOM MÍSTĚ
-

Přehled administrace

-

Rychlý přehled o aktuálním stavu vašeho obchodu.

-
- -
- ◷ - @DateTime.Now.ToString("d. M. yyyy") -
-
- @if (loading) { -
Načítám data obchodu…
+
Načítám…
} else { -
+
+
+

Web-Jarmark

+

Přehled

+

Aktuální stav vašeho obchodu na jednom místě.

+
-
-
- ↗ - KATALOG -
-
Celkem produktů
-
@productCount
-
Všechny produkty v obchodě
-
+
+
+ Produkty + @productCount + celkem v katalogu +
+
+ Kategorie + @categoryCount + v sortimentu +
+
+ Viditelné + @visibleCount + v e-shopu +
+
+ Nízký sklad + @lowStockCount + ≤ 5 kusů +
+
-
-
- ▤ - SORTIMENT -
-
Počet kategorií
-
@categoryCount
-
Kategorie vašeho zboží
-
- -
-
- ◉ - E-SHOP -
-
Viditelné produkty
-
@visibleCount
-
Produkty dostupné v katalogu
-
- -
-
- ! - SKLAD -
-
Dochází skladem
-
@lowStockCount
-
Produkty s 5 nebo méně kusy
-
- -
- -
- -
-
-
-

Produkty podle kategorií

-

Rozložení vašeho sortimentu

+ @* Řada grafů *@ +
+
+
+

Viditelnost

- Kategorie ↗ +
+
+
+ @productCount + celkem +
+
+
    +
  • + + Viditelné + @visibleCount +
  • +
  • + + Skryté + @hiddenCount +
  • +
+
+
+ +
+
+

Stav skladu

+
+
+
+
+
+
+
+
    +
  • + + V pořádku + @stockOkCount +
  • +
  • + + Nízký (1–5) + @lowStockPositiveCount +
  • +
  • + + Vyprodané + @outOfStockCount +
  • +
+
+
+ +
+
+

Katalog

+
+
+
+ Průměrná cena + @avgPrice.ToString("N0") Kč +
+
+ Nejvyšší cena + @maxPrice.ToString("N0") Kč +
+
+ Kusů skladem + @totalStock +
+
+ Hodnota skladu + @stockValue.ToString("N0") Kč +
+
+
+
+ +
+
+
+

Produkty podle kategorií

+ Spravovat +
+ + @if (categoryStats.Count == 0) + { +

Zatím žádné kategorie.

+ } + else + { +
+ @foreach (var cat in categoryStats) + { +
+
+ @cat.Name + @cat.ProductCount +
+
+
+
+
+ } +
+ } +
+ + +
+ + @* Mini sloupcový graf skladu u produktů *@ +
+
+

Sklad u produktů

+ Katalog
- @if (categoryStats.Count == 0) + @if (stockBars.Count == 0) { -
Zatím nemáte žádné kategorie.
+

Zatím žádné produkty.

} else { -
- @foreach (var category in categoryStats) +
+ @foreach (var item in stockBars) { -
-
- @category.Name - @category.ProductCount -
-
-
-
+
+
+
+ @item.Stock + @Truncate(item.Name, 10)
}
}
-
- - -
-
-
-

Přehled produktů

-

Ukázka produktů z vašeho katalogu

-
- Zobrazit vše → -
- - @if (productPreview.Count == 0) - { -
Zatím nemáte žádné produkty.
- } - else - { -
- - - - - - - - - - - - @foreach (var product in productPreview) - { + @if (productPreview.Count == 0) + { +

Zatím žádné produkty.

+ } + else + { +
+
ProduktKategorieCenaSklademStav
+ - - - - - + + + + + - } - -
@product.Name@product.CategoryName@product.Price.ToString("N2") Kč@product.StockQuantity ks - @if (product.IsVisible) - { - Viditelné - } - else - { - Skryté - } - NázevKategorieCenaSkladStav
-
- } -
+ + + @foreach (var p in productPreview) + { + + @p.Name + @p.CategoryName + @p.Price.ToString("N0") Kč + @p.StockQuantity + + + @(p.IsVisible ? "Viditelné" : "Skryté") + + + + } + + +
+ } +
+
} @code { @@ -209,17 +261,71 @@ else private int productCount; private int categoryCount; private int visibleCount; + private int hiddenCount; private int lowStockCount; + private int lowStockPositiveCount; + private int outOfStockCount; + private int stockOkCount; + private int totalStock; + + private decimal avgPrice; + private decimal maxPrice; + private decimal stockValue; + + private double stockOkPct; + private double stockLowPct; + private double stockOutPct; + + private string visibilityDonutStyle = "background: conic-gradient(#1d1d1f 0 100%);"; private List categoryStats = new(); private List productPreview = new(); + private List stockBars = new(); protected override async Task OnInitializedAsync() { - productCount = await Db.Set().CountAsync(); + var products = await Db.Set() + .AsNoTracking() + .Select(p => new + { + p.Name, + p.Price, + p.StockQuantity, + p.IsVisible, + CategoryName = p.Category.Name + }) + .ToListAsync(); + + productCount = products.Count; + visibleCount = products.Count(p => p.IsVisible); + hiddenCount = productCount - visibleCount; + outOfStockCount = products.Count(p => p.StockQuantity <= 0); + lowStockPositiveCount = products.Count(p => p.StockQuantity > 0 && p.StockQuantity <= 5); + lowStockCount = products.Count(p => p.StockQuantity <= 5); + stockOkCount = products.Count(p => p.StockQuantity > 5); + totalStock = products.Sum(p => p.StockQuantity); + + avgPrice = productCount == 0 ? 0 : products.Average(p => p.Price); + maxPrice = productCount == 0 ? 0 : products.Max(p => p.Price); + stockValue = products.Sum(p => p.Price * p.StockQuantity); + + if (productCount > 0) + { + stockOkPct = stockOkCount * 100.0 / productCount; + stockLowPct = lowStockPositiveCount * 100.0 / productCount; + stockOutPct = outOfStockCount * 100.0 / productCount; + + var visPct = visibleCount * 100.0 / productCount; + visibilityDonutStyle = + $"background: conic-gradient(#1d1d1f 0 {visPct.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)}%, #d2d2d7 0 100%);"; + } + else + { + stockOkPct = stockLowPct = stockOutPct = 0; + visibilityDonutStyle = "background: conic-gradient(#e8e8ed 0 100%);"; + } + categoryCount = await Db.Set().CountAsync(); - visibleCount = await Db.Set().CountAsync(p => p.IsVisible); - lowStockCount = await Db.Set().CountAsync(p => p.StockQuantity <= 5); var categories = await Db.Set() .AsNoTracking() @@ -231,27 +337,41 @@ else .Select(c => new CategoryStat(c.Name, c.Products.Count)) .ToList(); - productPreview = await Db.Set() - .AsNoTracking() + productPreview = products .OrderBy(p => p.Name) - .Take(5) + .Take(6) .Select(p => new ProductPreview( p.Name, - p.Category.Name, + p.CategoryName, p.Price, p.StockQuantity, p.IsVisible)) - .ToListAsync(); + .ToList(); + + var maxStock = products.Count == 0 ? 1 : Math.Max(1, products.Max(p => p.StockQuantity)); + stockBars = products + .OrderByDescending(p => p.StockQuantity) + .Take(8) + .Select(p => new StockBar( + p.Name, + p.StockQuantity, + Math.Max(8, (int)Math.Round(p.StockQuantity * 100.0 / maxStock)))) + .ToList(); loading = false; } private int GetWidth(int count) { - var max = categoryStats.Count == 0 ? 1 : categoryStats.Max(c => c.ProductCount); - return count == 0 ? 0 : Math.Max(5, (int)Math.Round(count * 100.0 / Math.Max(1, max))); + var max = categoryStats.Count == 0 ? 1 : Math.Max(1, categoryStats.Max(c => c.ProductCount)); + return count == 0 ? 0 : Math.Max(8, (int)Math.Round(count * 100.0 / max)); } + private static string Truncate(string value, int max) + => string.IsNullOrEmpty(value) || value.Length <= max + ? value + : value[..(max - 1)] + "…"; + private record CategoryStat(string Name, int ProductCount); private record ProductPreview( @@ -260,4 +380,6 @@ else decimal Price, int StockQuantity, bool IsVisible); -} + + private record StockBar(string Name, int Stock, int HeightPct); +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor.css b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor.css new file mode 100644 index 0000000..1e603a6 --- /dev/null +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor.css @@ -0,0 +1,717 @@ +/* Apple-like přehled + grafy */ + +.ap { + max-width: 1120px; + margin: 0 auto; + padding: 8px 8px 48px; + color: #1d1d1f; + font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; + -webkit-font-smoothing: antialiased; +} + +.ap-loading { + max-width: 1120px; + margin: 40px auto; + text-align: center; + color: #6e6e73; + font-size: 15px; +} + +.ap-hero { + padding: 28px 8px 32px; + text-align: center; + animation: ap-fade 0.5s ease both; +} + +.ap-eyebrow { + margin: 0 0 8px; + font-size: 12px; + font-weight: 600; + letter-spacing: 0.08em; + text-transform: uppercase; + color: #6e6e73; +} + +.ap-hero h1 { + margin: 0; + font-size: 40px; + font-weight: 700; + letter-spacing: -0.03em; + line-height: 1.1; +} + +.ap-sub { + margin: 10px auto 0; + max-width: 420px; + font-size: 17px; + line-height: 1.4; + color: #6e6e73; +} + +.ap-metrics { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 14px; + margin-bottom: 14px; +} + +.ap-metric { + background: rgba(255, 255, 255, 0.9); + border: 1px solid rgba(0, 0, 0, 0.04); + border-radius: 22px; + padding: 22px 20px; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 12px 32px rgba(0, 0, 0, 0.04); + transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.35s ease; + animation: ap-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both; +} + + .ap-metric:nth-child(1) { + animation-delay: 0.05s; + } + + .ap-metric:nth-child(2) { + animation-delay: 0.10s; + } + + .ap-metric:nth-child(3) { + animation-delay: 0.15s; + } + + .ap-metric:nth-child(4) { + animation-delay: 0.20s; + } + + .ap-metric:hover { + transform: translateY(-3px) scale(1.01); + box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08); + } + +.ap-metric-label { + display: block; + font-size: 13px; + font-weight: 500; + color: #6e6e73; +} + +.ap-metric-value { + display: block; + margin-top: 10px; + font-size: 36px; + font-weight: 700; + letter-spacing: -0.03em; + line-height: 1; +} + +.ap-metric-hint { + display: block; + margin-top: 10px; + font-size: 12px; + color: #86868b; +} + +/* Charts row */ +.ap-charts { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 14px; + margin-bottom: 14px; +} + +.ap-grid { + display: grid; + grid-template-columns: minmax(0, 1.55fr) minmax(260px, 1fr); + gap: 14px; + margin-bottom: 14px; +} + +.ap-panel { + background: #fff; + border: 1px solid rgba(0, 0, 0, 0.045); + border-radius: 24px; + padding: 22px 22px 18px; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 14px 36px rgba(0, 0, 0, 0.035); + animation: ap-rise 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; + animation-delay: 0.18s; + margin-bottom: 0; +} + + .ap-panel + .ap-panel-table, + .ap-charts + .ap-grid { + /* spacing handled by parent gaps */ + } + +section.ap-panel { + margin-bottom: 14px; +} + +.ap-panel-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-bottom: 18px; +} + + .ap-panel-head h2 { + margin: 0; + font-size: 19px; + font-weight: 650; + letter-spacing: -0.02em; + } + + .ap-panel-head a { + font-size: 14px; + font-weight: 500; + color: #1d1d1f; + text-decoration: none; + opacity: 0.5; + transition: opacity 0.2s ease; + } + + .ap-panel-head a:hover { + opacity: 1; + } + +/* Donut */ +.ap-donut-block { + display: flex; + align-items: center; + gap: 18px; +} + +.ap-donut { + width: 120px; + height: 120px; + border-radius: 50%; + display: grid; + place-items: center; + flex-shrink: 0; + animation: ap-pop 0.7s cubic-bezier(0.22, 1, 0.36, 1) both; +} + +.ap-donut-hole { + width: 72px; + height: 72px; + border-radius: 50%; + background: #fff; + display: grid; + place-content: center; + text-align: center; + box-shadow: 0 0 0 1px #ececec; +} + + .ap-donut-hole strong { + font-size: 18px; + line-height: 1; + } + + .ap-donut-hole small { + font-size: 11px; + color: #6e6e73; + } + +/* Stacked bar */ +.ap-stack-chart { + display: flex; + flex-direction: column; + gap: 16px; +} + +.ap-stack-bar { + display: flex; + height: 14px; + border-radius: 999px; + overflow: hidden; + background: #f2f2f4; +} + +.ap-stack-seg { + height: 100%; + transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1); +} + + .ap-stack-seg.is-ok { + background: #1d1d1f; + } + + .ap-stack-seg.is-low { + background: #6e6e73; + } + + .ap-stack-seg.is-out { + background: #d2d2d7; + } + +/* Legend / stats */ +.ap-legend { + list-style: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + gap: 8px; + flex: 1; +} + + .ap-legend li { + display: grid; + grid-template-columns: 10px 1fr auto; + gap: 8px; + align-items: center; + font-size: 13px; + color: #1d1d1f; + } + +.ap-swatch { + width: 10px; + height: 10px; + border-radius: 3px; + background: #1d1d1f; +} + + .ap-swatch.is-mid { + background: #6e6e73; + } + + .ap-swatch.is-light { + background: #d2d2d7; + } + +.ap-stat-list { + display: flex; + flex-direction: column; + gap: 12px; +} + +.ap-stat-line { + display: flex; + justify-content: space-between; + gap: 12px; + padding: 12px 14px; + border-radius: 14px; + background: #f5f5f7; + font-size: 13px; +} + + .ap-stat-line span { + color: #6e6e73; + } + + .ap-stat-line strong { + font-weight: 650; + font-variant-numeric: tabular-nums; + } + +/* Category rows */ +.ap-rows { + display: flex; + flex-direction: column; + gap: 16px; +} + +.ap-row-top { + display: flex; + justify-content: space-between; + gap: 12px; + margin-bottom: 8px; + font-size: 14px; + font-weight: 500; +} + +.ap-row-num { + color: #6e6e73; + font-variant-numeric: tabular-nums; +} + +.ap-track { + height: 6px; + border-radius: 999px; + background: #f2f2f4; + overflow: hidden; +} + +.ap-fill { + height: 100%; + border-radius: 999px; + background: #1d1d1f; + transform-origin: left center; + animation: ap-grow 0.9s cubic-bezier(0.22, 1, 0.36, 1) both; +} + +/* Column chart */ +.ap-columns { + display: grid; + grid-template-columns: repeat(8, minmax(0, 1fr)); + gap: 10px; + align-items: end; + min-height: 180px; + padding-top: 8px; +} + +.ap-col { + display: flex; + flex-direction: column; + align-items: center; + gap: 6px; + min-width: 0; +} + +.ap-col-bar-wrap { + width: 100%; + height: 120px; + display: flex; + align-items: flex-end; + justify-content: center; +} + +.ap-col-bar { + width: 70%; + max-width: 36px; + border-radius: 10px 10px 4px 4px; + background: linear-gradient(180deg, #3a3a3c 0%, #1d1d1f 100%); + min-height: 6px; + transform-origin: bottom center; + animation: ap-col 0.8s cubic-bezier(0.22, 1, 0.36, 1) both; +} + +.ap-col-val { + font-size: 12px; + font-weight: 650; + font-variant-numeric: tabular-nums; +} + +.ap-col-label { + font-size: 11px; + color: #6e6e73; + max-width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + text-align: center; +} + +/* Actions */ +.ap-actions { + display: flex; + flex-direction: column; + gap: 8px; +} + +.ap-action { + display: flex; + flex-direction: column; + gap: 2px; + padding: 14px 16px; + border-radius: 16px; + background: #f5f5f7; + text-decoration: none; + color: #1d1d1f; + transition: background 0.2s ease, transform 0.2s ease; +} + + .ap-action:hover { + background: #ececef; + color: #1d1d1f; + transform: scale(1.01); + } + +.ap-action-title { + font-size: 15px; + font-weight: 600; +} + +.ap-action-sub { + font-size: 12px; + color: #6e6e73; +} + +/* Table */ +.ap-table-wrap { + overflow-x: auto; +} + +.ap-table { + width: 100%; + border-collapse: collapse; + font-size: 14px; +} + + .ap-table th { + text-align: left; + padding: 10px 8px 12px; + color: #6e6e73; + font-size: 12px; + font-weight: 500; + border-bottom: 1px solid #f0f0f2; + } + + .ap-table td { + padding: 14px 8px; + border-bottom: 1px solid #f4f4f6; + } + + .ap-table tr:last-child td { + border-bottom: 0; + } + + .ap-table tbody tr:hover { + background: #fafafa; + } + +.ap-name { + font-weight: 600; +} + +.ap-status { + display: inline-flex; + padding: 4px 10px; + border-radius: 999px; + font-size: 12px; + font-weight: 600; +} + + .ap-status.is-on { + background: #1d1d1f; + color: #fff; + } + + .ap-status.is-off { + background: #f0f0f2; + color: #6e6e73; + } + +.ap-empty { + margin: 12px 0 8px; + color: #6e6e73; + font-size: 14px; +} + +@keyframes ap-fade { + from { + opacity: 0; + transform: translateY(8px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +@keyframes ap-rise { + from { + opacity: 0; + transform: translateY(16px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +@keyframes ap-grow { + from { + transform: scaleX(0); + } + + to { + transform: scaleX(1); + } +} + +@keyframes ap-col { + from { + transform: scaleY(0); + } + + to { + transform: scaleY(1); + } +} + +@keyframes ap-pop { + from { + opacity: 0; + transform: scale(0.92); + } + + to { + opacity: 1; + transform: scale(1); + } +} + +@media (max-width: 1100px) { + .ap-charts { + grid-template-columns: 1fr; + } + + .ap-columns { + grid-template-columns: repeat(4, minmax(0, 1fr)); + } +} + +@media (max-width: 960px) { + .ap-metrics { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + + .ap-grid { + grid-template-columns: 1fr; + } + + .ap-hero h1 { + font-size: 32px; + } +} +/* ===== Seznamy a formuláře ===== */ + +.ap-hero-left { + text-align: left; + padding-left: 4px; + padding-right: 4px; +} + +.ap-hero-row { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 16px; + flex-wrap: wrap; +} + +.ap-hero-left .ap-sub { + margin-left: 0; +} + +.ap-muted { + color: #6e6e73; + font-size: 13px; +} + +.ap-btn { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 6px; + padding: 10px 16px; + border-radius: 999px; + border: 1px solid rgba(0, 0, 0, 0.08); + background: #fff; + color: #1d1d1f; + font-size: 14px; + font-weight: 600; + text-decoration: none; + cursor: pointer; +} + + .ap-btn:hover { + background: #f5f5f7; + color: #1d1d1f; + } + +.ap-btn-primary { + background: #1d1d1f; + border-color: #1d1d1f; + color: #fff; +} + + .ap-btn-primary:hover { + background: #000; + color: #fff; + } + +.ap-btn-ghost { + padding: 7px 12px; + font-size: 13px; + background: #f5f5f7; + border-color: transparent; +} + +.ap-actions-cell { + text-align: right; + white-space: nowrap; +} + +.ap-alert { + margin-bottom: 14px; + padding: 14px 16px; + border-radius: 16px; + background: #f5f5f7; + border: 1px solid #e5e5ea; + font-size: 14px; +} + +.ap-form-panel { + max-width: 560px; +} + +.ap-field { + display: flex; + flex-direction: column; + gap: 8px; + margin-bottom: 16px; +} + + .ap-field label { + font-size: 13px; + font-weight: 600; + } + +.ap-input, +.ap-select, +.ap-textarea { + width: 100%; + border: 1px solid #d2d2d7; + border-radius: 14px; + padding: 12px 14px; + font-size: 15px; + color: #1d1d1f; + background: #fff; + outline: none; +} + + .ap-input:focus, + .ap-select:focus, + .ap-textarea:focus { + border-color: #1d1d1f; + box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06); + } + +.ap-textarea { + min-height: 110px; + resize: vertical; +} + +.ap-help { + color: #6e6e73; + font-size: 12px; +} + +.ap-switch { + display: flex; + align-items: center; + gap: 10px; + margin: 8px 0 20px; + font-size: 14px; + font-weight: 500; + cursor: pointer; +} + +.ap-form-actions { + display: flex; + gap: 10px; + flex-wrap: wrap; + margin-top: 8px; +} + +.ap-toolbar { + display: flex; + gap: 10px; + margin-bottom: 14px; +} + + .ap-toolbar .ap-input { + max-width: 280px; + } \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor index c482ea2..b1ab2f1 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor @@ -2,10 +2,6 @@ @page "/admin/kategorie/edit/{Id:int}" @layout Web_Jarmark.Components.Layout.Admin.AdminLayout @rendermode InteractiveServer -@using System.ComponentModel.DataAnnotations -@using System.Globalization -@using System.Text -@using System.Text.RegularExpressions @using Microsoft.EntityFrameworkCore @using Microsoft.AspNetCore.Authorization @using Web_Jarmark.Data @@ -15,204 +11,146 @@ @attribute [Authorize] - - @(Id is null ? "Nová kategorie" : "Upravit kategorii") +@(IsNew ? "Nová kategorie" : "Upravit kategorii") -
- +
+
+

Kategorie

+

@(IsNew ? "Nová kategorie" : "Upravit kategorii")

+

Název a stav kategorie v katalogu.

+
-
-
ADMINISTRACE / KATEGORIE
-

@(Id is null ? "Nová kategorie" : "Upravit kategorii")

-

Vyplňte základní informace o kategorii.

-
+ @if (!string.IsNullOrEmpty(error)) + { +
@error
+ } - @if (notFound) - { -
-
- Kategorie nebyla nalezena. -
- - Zpět na seznam - + @if (notFound) + { +
+

Kategorie nebyla nalezena.

+ Zpět na seznam +
+ } + else if (loading) + { +
Načítám…
+ } + else + { +
+
+ +
- } - else - { -
-
-
📁
-
-

Informace o kategorii

-

Název a adresa kategorie

-
-
- - - - - @if (!string.IsNullOrEmpty(error)) - { -
@error
- } - -
- - - -
- -
- - - Pokud pole necháte prázdné, adresa se vytvoří automaticky z názvu. -
- -
-
- - -
- Aktivní kategorie může být nabízena zákazníkům. -
- -
- - - Zrušit - -
-
+
+ + + URL identifikátor, např. domaci-vyrobky
- } -
- + + + +
+ + Zrušit +
+
+ } +
@code { - [Parameter] public int? Id { get; set; } + [Parameter] + public int? Id { get; set; } - private CategoryForm form = new(); - private string? error; + private bool IsNew => Id is null; + + private string name = ""; + private string categorySlug = ""; + private bool isActive = true; + + private bool loading = true; + private bool saving; private bool notFound; + private string? error; protected override async Task OnParametersSetAsync() { + loading = true; notFound = false; error = null; - if (Id is null) return; + if (IsNew) + { + name = ""; + categorySlug = ""; + isActive = true; + loading = false; + return; + } - var cat = await Db.Set() - .AsNoTracking() - .FirstOrDefaultAsync(c => c.Id == Id); - - if (cat is null) + var entity = await Db.Categories.AsNoTracking().FirstOrDefaultAsync(c => c.Id == Id!.Value); + if (entity is null) { notFound = true; + loading = false; return; } - form = new CategoryForm - { - Name = cat.Name, - Slug = cat.Slug, - IsActive = cat.IsActive - }; + name = entity.Name ?? ""; + categorySlug = entity.Slug ?? ""; + isActive = entity.IsActive; + loading = false; } - private async Task Save() + private async Task SaveAsync() { + saving = true; error = null; - var name = form.Name.Trim(); - var slug = Slugify(string.IsNullOrWhiteSpace(form.Slug) ? name : form.Slug); - - if (string.IsNullOrEmpty(slug)) + try { - error = "Ze zadaného názvu nelze vytvořit slug."; - return; - } - - var slugTaken = await Db.Set() - .AnyAsync(c => c.Slug == slug && c.Id != (Id ?? 0)); - - if (slugTaken) - { - error = $"Slug „{slug}“ už používá jiná kategorie."; - return; - } - - if (Id is null) - { - Db.Set().Add(new Category + if (string.IsNullOrWhiteSpace(name)) { - Name = name, - Slug = slug, - IsActive = form.IsActive - }); - } - else - { - var cat = await Db.Set().FindAsync(Id); - - if (cat is null) - { - notFound = true; + error = "Zadejte název kategorie."; return; } - cat.Name = name; - cat.Slug = slug; - cat.IsActive = form.IsActive; + var finalSlug = string.IsNullOrWhiteSpace(categorySlug) + ? name.Trim().ToLowerInvariant().Replace(' ', '-') + : categorySlug.Trim(); + + Category entity; + if (IsNew) + { + entity = new Category(); + Db.Categories.Add(entity); + } + else + { + entity = await Db.Categories.FirstAsync(c => c.Id == Id!.Value); + } + + entity.Name = name.Trim(); + entity.Slug = finalSlug; + entity.IsActive = isActive; + + await Db.SaveChangesAsync(); + Nav.NavigateTo("/admin/kategorie"); } - - await Db.SaveChangesAsync(); - Nav.NavigateTo("/admin/kategorie"); - } - - private static string Slugify(string text) - { - var normalized = text.Trim() - .ToLowerInvariant() - .Normalize(NormalizationForm.FormD); - - var sb = new StringBuilder(); - - foreach (var ch in normalized) + catch (Exception ex) { - if (CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark) - sb.Append(ch); + error = "Uložení se nezdařilo: " + ex.Message; + } + finally + { + saving = false; } - - var noDiacritics = sb.ToString().Normalize(NormalizationForm.FormC); - return Regex.Replace(noDiacritics, "[^a-z0-9]+", "-").Trim('-'); } - - private class CategoryForm - { - [Required(ErrorMessage = "Zadej název kategorie.")] - [StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")] - public string Name { get; set; } = ""; - - public string? Slug { get; set; } - public bool IsActive { get; set; } = true; - } -} +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor index a4a4469..2f84bd2 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor @@ -2,211 +2,118 @@ @layout Web_Jarmark.Components.Layout.Admin.AdminLayout @rendermode InteractiveServer @using Microsoft.EntityFrameworkCore +@using Microsoft.AspNetCore.Authorization @using Web_Jarmark.Data @using Web_Jarmark.Data.Models -@using Microsoft.AspNetCore.Authorization @inject ApplicationDbContext Db -@inject NavigationManager Nav @attribute [Authorize] Kategorie -
- - -
-
-
ADMINISTRACE / SPRÁVA OBCHODU
-

Kategorie

-

Spravujte kategorie svého zboží.

+
+
+

Administrace

+
+
+

Kategorie

+

Správa kategorií sortimentu.

+
+ Nová kategorie
- - - + Nová kategorie - -
+ @if (!string.IsNullOrEmpty(error)) { -
- @error -
+
@error
} - @if (categories is null) + @if (items is null) { -
-
Načítám kategorie…
-
+
Načítám kategorie…
+ } + else if (items.Count == 0) + { +
+

Zatím nemáte žádné kategorie.

+ Vytvořit první kategorii +
} else { -
-
-
-
- 🗂️ -
-
-
Celkem kategorií
-
@categories.Count
-
-
-
-
- -
-
-
Přehled kategorií
-
Seznam všech kategorií v obchodě
+
+
+

Seznam kategorií

+ @items.Count položek
- @if (categories.Count == 0) - { -
-
📂
-
Zatím tu nejsou žádné kategorie
-

Začněte vytvořením první kategorie.

- - + Přidat kategorii - -
- } - else - { -
- - +
+
+ + + + + + + + + + + @foreach (var c in items) + { - - - - - + + + + + - - - @foreach (var c in categories) - { - - - - - - - - } - -
NázevSlugProduktyStav
Název kategorieAdresa (slug)Počet produktůStavAkce@c.Name@c.CategorySlug@c.ProductCount + + @(c.IsActive ? "Aktivní" : "Neaktivní") + + + Upravit +
- 📁@c.Name - - @c.Slug - - - @c.ProductCount - - - @if (c.IsActive) - { - - Aktivní - - } - else - { - - Neaktivní - - } - -
- -
-
-
- - Upravit - - -
-
-
- } - - -
+ }
@code { - private List? categories; + private List? items; private string? error; - protected override async Task OnInitializedAsync() => await Load(); - - private async Task Load() + protected override async Task OnInitializedAsync() { - categories = await Db.Set() - .AsNoTracking() - .OrderBy(c => c.Name) - .Select(c => new CategoryRow(c.Id, c.Name, c.Slug, c.IsActive, c.Products.Count)) - .ToListAsync(); - } - - private async Task ToggleActive(int id) - { - var cat = await Db.Set().FindAsync(id); - if (cat is null) return; - - cat.IsActive = !cat.IsActive; - await Db.SaveChangesAsync(); - await Load(); - } - - private async Task Delete(int id) - { - error = null; - - var cat = await Db.Set() - .Include(c => c.Products) - .FirstOrDefaultAsync(c => c.Id == id); - - if (cat is null) return; - - if (cat.Products.Count > 0) + try { - error = "Kategorii nelze smazat, obsahuje produkty."; - return; + items = await Db.Categories + .AsNoTracking() + .OrderBy(c => c.Name) + .Select(c => new Row( + c.Id, + c.Name, + c.Slug, + c.IsActive, + c.Products.Count)) + .ToListAsync(); + } + catch (Exception ex) + { + error = "Nepodařilo se načíst kategorie: " + ex.Message; + items = new(); } - - Db.Set().Remove(cat); - await Db.SaveChangesAsync(); - await Load(); } - private record CategoryRow(int Id, string Name, string Slug, bool IsActive, int ProductCount); -} + private sealed record Row( + int Id, + string Name, + string CategorySlug, + bool IsActive, + int ProductCount); +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor index f960060..f8b5f50 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor @@ -2,7 +2,6 @@ @page "/admin/zbozi/edit/{Id:int}" @layout Web_Jarmark.Components.Layout.Admin.AdminLayout @rendermode InteractiveServer -@using System.ComponentModel.DataAnnotations @using Microsoft.EntityFrameworkCore @using Microsoft.AspNetCore.Authorization @using Web_Jarmark.Data @@ -12,256 +11,200 @@ @attribute [Authorize] - - @(Id is null ? "Nové zboží" : "Upravit zboží") +@(IsNew ? "Nové zboží" : "Upravit zboží") -
- +
+
+

Zboží

+

@(IsNew ? "Nové zboží" : "Upravit zboží")

+

Údaje produktu v katalogu.

+
-
-
ADMINISTRACE / ZBOŽÍ
-

@(Id is null ? "Nové zboží" : "Upravit zboží")

-

Vyplňte informace o produktu.

-
+ @if (!string.IsNullOrEmpty(error)) + { +
@error
+ } - @if (notFound) - { -
-
Zboží nebylo nalezeno.
- - Zpět na seznam - + @if (notFound) + { +
+

Produkt nebyl nalezen.

+ Zpět na seznam +
+ } + else if (loading) + { +
Načítám…
+ } + else + { +
+
+ +
- } - else if (categories is null) - { -
- Načítám… -
- } - else if (categories.Count == 0) - { -
-
- Nejdříve musíš vytvořit alespoň jednu kategorii. - Přidat kategorii -
-
- } - else - { -
-
-
📦
-
-

Informace o produktu

-

Základní údaje, cena a sklad

-
-
- - - - - @if (!string.IsNullOrEmpty(error)) +
+ +
- } -
- + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + Zrušit +
+
+ } +
@code { - [Parameter] public int? Id { get; set; } + [Parameter] + public int? Id { get; set; } - private ProductForm form = new(); - private List? categories; - private string? error; + private bool IsNew => Id is null; + + private List categories = new(); + + private string name = ""; + private string description = ""; + private int categoryId; + private decimal price; + private int stockQuantity; + private string imageUrl = ""; + private bool isVisible = true; + + private bool loading = true; + private bool saving; private bool notFound; + private string? error; protected override async Task OnParametersSetAsync() { + loading = true; notFound = false; error = null; - categories = await Db.Set() + categories = await Db.Categories .AsNoTracking() .OrderBy(c => c.Name) + .Select(c => new CatOption(c.Id, c.Name)) .ToListAsync(); - if (Id is null) return; + if (IsNew) + { + name = ""; + description = ""; + categoryId = 0; + price = 0; + stockQuantity = 0; + imageUrl = ""; + isVisible = true; + loading = false; + return; + } - var p = await Db.Set() - .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == Id); - - if (p is null) + var entity = await Db.Products.AsNoTracking().FirstOrDefaultAsync(p => p.Id == Id!.Value); + if (entity is null) { notFound = true; + loading = false; return; } - form = new ProductForm - { - Name = p.Name, - CategoryId = p.CategoryId, - Description = p.Description, - Price = p.Price, - StockQuantity = p.StockQuantity, - ImageUrl = p.ImageUrl, - IsVisible = p.IsVisible - }; + name = entity.Name ?? ""; + description = entity.Description ?? ""; + categoryId = entity.CategoryId; + price = entity.Price; + stockQuantity = entity.StockQuantity; + imageUrl = entity.ImageUrl ?? ""; + isVisible = entity.IsVisible; + loading = false; } - private async Task Save() + private async Task SaveAsync() { + saving = true; error = null; - if (form.CategoryId == 0) + try { - error = "Vyber kategorii."; - return; - } - - if (Id is null) - { - var p = new Product(); - Apply(p); - Db.Set().Add(p); - } - else - { - var p = await Db.Set().FindAsync(Id); - - if (p is null) + if (string.IsNullOrWhiteSpace(name)) { - notFound = true; + error = "Zadejte název produktu."; return; } - Apply(p); + if (categoryId <= 0) + { + error = "Vyberte kategorii."; + return; + } + + Product entity; + if (IsNew) + { + entity = new Product(); + Db.Products.Add(entity); + } + else + { + entity = await Db.Products.FirstAsync(p => p.Id == Id!.Value); + } + + entity.Name = name.Trim(); + entity.Description = description?.Trim() ?? ""; + entity.CategoryId = categoryId; + entity.Price = price; + entity.StockQuantity = stockQuantity; + entity.ImageUrl = imageUrl?.Trim() ?? ""; + entity.IsVisible = isVisible; + entity.UpdatedAt = DateTime.UtcNow; + + await Db.SaveChangesAsync(); + Nav.NavigateTo("/admin/zbozi"); + } + catch (Exception ex) + { + error = "Uložení se nezdařilo: " + ex.Message; + } + finally + { + saving = false; } - - await Db.SaveChangesAsync(); - Nav.NavigateTo("/admin/zbozi"); } - private void Apply(Product p) - { - p.Name = form.Name.Trim(); - p.CategoryId = form.CategoryId; - p.Description = form.Description?.Trim() ?? ""; - p.Price = form.Price; - p.StockQuantity = form.StockQuantity; - p.ImageUrl = form.ImageUrl?.Trim() ?? ""; - p.IsVisible = form.IsVisible; - p.UpdatedAt = DateTime.Now; - } - - private class ProductForm - { - [Required(ErrorMessage = "Zadej název zboží.")] - [StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")] - public string Name { get; set; } = ""; - - public int CategoryId { get; set; } - public string? Description { get; set; } - - [Range(0, 100000, ErrorMessage = "Cena musí být 0 až 100 000 Kč.")] - public decimal Price { get; set; } - - [Range(0, 100000, ErrorMessage = "Počet kusů musí být 0 nebo více.")] - public int StockQuantity { get; set; } - - public string? ImageUrl { get; set; } - public bool IsVisible { get; set; } = true; - } -} + private sealed record CatOption(int Id, string Name); +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor index 331e59e..bd3441a 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor @@ -12,224 +12,140 @@ Zboží -
- - -
-
-
ADMINISTRACE / SPRÁVA OBCHODU
-

Zboží

-

Přehled a správa produktů v obchodě.

+
+
+

Administrace

+
+
+

Zboží

+

Přehled a správa produktů.

+
+ Nové zboží
- - + Nové zboží - +
+ +
+
@if (!string.IsNullOrEmpty(error)) { -
@error
+
@error
} - @if (products is null) + @if (items is null) { -
- Načítám zboží… -
+
Načítám zboží…
+ } + else if (Filtered.Count == 0) + { +
+

Žádné produkty k zobrazení.

+ Přidat produkt +
} else { -
-
-
-
📦
-
Celkem produktů
-
@products.Count
-
+
+
+

Katalog

+ @Filtered.Count položek
-
-
-
✓
-
Viditelné produkty
-
@products.Count(p => p.IsVisible)
-
-
- -
-
-
📉
-
Dochází skladem (5 a méně)
-
@products.Count(p => p.StockQuantity <= 5)
-
-
-
- -
-
-
-

Přehled produktů

-

Všechny produkty v e-shopu

-
- - -
- - @if (FilteredProducts.Count == 0) - { -
-
🔎
-
Nic jsme nenašli
-

Zkuste změnit hledaný výraz.

-
- } - else - { -
- - +
+
+ + + + + + + + + + + + @foreach (var p in Filtered) + { - - - - - - + + + + + + - - - @foreach (var p in FilteredProducts) - { - - - - - - - - - } - -
ProduktKategorieCenaSkladStav
Název zbožíKategorieCenaSklademViditelnostAkce@p.Name@p.CategoryName@p.Price.ToString("N0") Kč@p.StockQuantity + + @(p.IsVisible ? "Viditelné" : "Skryté") + + + Upravit +
@p.Name - @p.CategoryName - @p.Price.ToString("N2") Kč - @if (p.StockQuantity <= 5) - { - @p.StockQuantity ks - } - else - { - @p.StockQuantity ks - } - -
- -
- @(p.IsVisible ? "Viditelné" : "Skryté") -
-
- - Upravit - - -
-
-
- } - -
- - Zobrazeno: @FilteredProducts.Count z @products.Count produktů - + } + +
-
+ }
@code { - private List? products; + private List? items; + private string search = ""; private string? error; - private string searchTerm = ""; - private List FilteredProducts => - products? - .Where(p => string.IsNullOrWhiteSpace(searchTerm) - || p.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) - || p.CategoryName.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)) - .ToList() ?? new(); - - protected override async Task OnInitializedAsync() => await Load(); - - private async Task Load() + private List Filtered { - products = await Db.Set() - .AsNoTracking() - .OrderBy(p => p.Name) - .Select(p => new ProductRow( - p.Id, - p.Name, - p.Category.Name, - p.Price, - p.StockQuantity, - p.IsVisible)) - .ToListAsync(); - } - - private async Task ToggleVisible(int id) - { - var p = await Db.Set().FindAsync(id); - if (p is null) return; - - p.IsVisible = !p.IsVisible; - p.UpdatedAt = DateTime.Now; - await Db.SaveChangesAsync(); - await Load(); - } - - private async Task Delete(int id) - { - error = null; - - var p = await Db.Set() - .Include(x => x.OrderItems) - .FirstOrDefaultAsync(x => x.Id == id); - - if (p is null) return; - - if (p.OrderItems.Count > 0) + get { - error = $"Zboží „{p.Name}“ už je v objednávkách, nelze ho smazat. Odškrtni raději „Viditelné“."; - return; - } + if (items is null) + { + return new List(); + } - Db.Set().Remove(p); - await Db.SaveChangesAsync(); - await Load(); + if (string.IsNullOrWhiteSpace(search)) + { + return items; + } + + return items.Where(p => + p.Name.Contains(search, StringComparison.OrdinalIgnoreCase) || + p.CategoryName.Contains(search, StringComparison.OrdinalIgnoreCase)).ToList(); + } } - private record ProductRow( + protected override async Task OnInitializedAsync() + { + try + { + items = await Db.Products + .AsNoTracking() + .OrderBy(p => p.Name) + .Select(p => new Row( + p.Id, + p.Name, + p.Category.Name, + p.Price, + p.StockQuantity, + p.IsVisible)) + .ToListAsync(); + } + catch (Exception ex) + { + error = "Nepodařilo se načíst zboží: " + ex.Message; + items = new(); + } + } + + private sealed record Row( int Id, string Name, string CategoryName, decimal Price, int StockQuantity, bool IsVisible); -} +} \ No newline at end of file diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-shm b/Web-Jarmark/Web-Jarmark/jarmark.db-shm index 6f904984bcdf2cc98059e2044a28f07b4e5f83f3..7ce1168c098a9a98a6a5aaf3d8f641305f41b514 100644 GIT binary patch delta 175 zcmZo@U}|V!s+V}A%K!t63=9HCfE+C#Zk*nnG~e>!t$+7!1vY)0c1bh%c6r8KEN?tdfz6=z~Nvayk$nUxF3m)ks%SwD>N2#``|VP#}sVK@wA9u?TUEze6300}uf AUjP6A delta 165 zcmZo@U}|V!s+V}A%K!t63=9H?fE+C#4xYH*a_0FrXa3#071;D~+NHgB;v^33O?4$z uJRGf+7(8fl7=FLl(6~Z=eV76glW@KR5ypZ|0z~*gvUV;EL5j&Is diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-wal b/Web-Jarmark/Web-Jarmark/jarmark.db-wal index 080c88a2ac52c06092e2b487c7735f4018f13487..c508a07188f89b531669b08a5844ecdb16893807 100644 GIT binary patch delta 225 zcmccc#GqlRVM7aJ3sVbo3rh=Y3tJ0&3r7oQ3s(#G7M=hj4F(1VE+A(3ckfnU)5mF- zT5|p>L`qKb;^n`|z{0bxIq?m_^S(Y)NC_kk%xulpGXed8W9Htn^l>=fem_Ps*+=s{~Ubj9^jc((I!AvcqeW!E`17T474% delta 33 ocmZozYIxy^K|>2;3sVbo3rh=Y3tJ0&3r7oQ3s(#G7M=hj0MV=p>i_@%