vylepseni admin
This commit is contained in:
@@ -1,22 +1,85 @@
|
||||
@inherits LayoutComponentBase
|
||||
@implements IDisposable
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<div class="wj-dashboard">
|
||||
<div class="admin-shell @(collapsed ? "is-collapsed" : null)">
|
||||
<aside class="admin-sidebar">
|
||||
<div class="admin-sidebar-head">
|
||||
<a href="/admin" class="admin-logo">
|
||||
<span class="admin-logo-mark">W</span>
|
||||
<span class="admin-logo-text">Web-Jarmark</span>
|
||||
</a>
|
||||
|
||||
<AdminNavMenu />
|
||||
<button type="button"
|
||||
class="admin-toggle"
|
||||
title="@(collapsed ? "Rozbalit" : "Sbalit")"
|
||||
@onclick="Toggle">
|
||||
☰
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<main class="wj-main">
|
||||
<AdminNavMenu />
|
||||
|
||||
<header class="wj-topbar">
|
||||
<div class="wj-topbar-label">ADMINISTRACE</div>
|
||||
<div class="wj-topbar-right">
|
||||
<span class="wj-status-dot"></span>
|
||||
<span>Administrátor</span>
|
||||
<div class="admin-sidebar-foot">
|
||||
<span class="admin-logo-mark small">W</span>
|
||||
<div class="admin-foot-text">
|
||||
<strong>Web-Jarmark</strong>
|
||||
<small>Administrace e-shopu</small>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="admin-main">
|
||||
<header class="admin-topbar">
|
||||
<div class="admin-topbar-title">@SectionTitle</div>
|
||||
<div class="admin-topbar-user">
|
||||
<span class="admin-dot"></span>
|
||||
Administrátor
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="wj-content">
|
||||
<main class="admin-content">
|
||||
@Body
|
||||
</section>
|
||||
|
||||
</main>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,62 +1,47 @@
|
||||
@implements IDisposable
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<aside class="wj-sidebar">
|
||||
<a href="/admin" class="wj-brand">
|
||||
<span class="wj-brand-icon">W</span>
|
||||
<span>Web-Jarmark</span>
|
||||
<nav class="admin-nav">
|
||||
<a href="/admin" class="admin-nav-link @(IsCurrent("/admin", true) ? "active" : null)">
|
||||
<span class="admin-nav-ico">⌂</span>
|
||||
<span class="admin-nav-label">Přehled</span>
|
||||
</a>
|
||||
|
||||
<nav class="wj-nav">
|
||||
<a href="/admin"
|
||||
class="wj-nav-link @(IsCurrent("/admin", true) ? "active" : "")">
|
||||
<span>⌂</span> Přehled
|
||||
</a>
|
||||
<a href="/admin/kategorie" class="admin-nav-link @(IsCurrent("/admin/kategorie") ? "active" : null)">
|
||||
<span class="admin-nav-ico">▤</span>
|
||||
<span class="admin-nav-label">Kategorie</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/kategorie"
|
||||
class="wj-nav-link @(IsCurrent("/admin/kategorie") ? "active" : "")">
|
||||
<span>▤</span> Kategorie
|
||||
</a>
|
||||
<a href="/admin/zbozi" class="admin-nav-link @(IsCurrent("/admin/zbozi") ? "active" : null)">
|
||||
<span class="admin-nav-ico">◇</span>
|
||||
<span class="admin-nav-label">Zboží</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/zbozi"
|
||||
class="wj-nav-link @(IsCurrent("/admin/zbozi") ? "active" : "")">
|
||||
<span>◇</span> Zboží
|
||||
</a>
|
||||
<a href="/admin/objednavky" class="admin-nav-link @(IsCurrent("/admin/objednavky") ? "active" : null)">
|
||||
<span class="admin-nav-ico">▣</span>
|
||||
<span class="admin-nav-label">Objednávky</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/objednavky"
|
||||
class="wj-nav-link @(IsCurrent("/admin/objednavky") ? "active" : "")">
|
||||
<span>▣</span> Objednávky
|
||||
</a>
|
||||
<a href="/admin/administratori" class="admin-nav-link @(IsCurrent("/admin/administratori") ? "active" : null)">
|
||||
<span class="admin-nav-ico">👤</span>
|
||||
<span class="admin-nav-label">Administrátoři</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/zakaznici"
|
||||
class="wj-nav-link @(IsCurrent("/admin/zakaznici") ? "active" : "")">
|
||||
<span>♙</span> Zákazníci
|
||||
</a>
|
||||
<a href="/admin/sklad" class="admin-nav-link @(IsCurrent("/admin/sklad") ? "active" : null)">
|
||||
<span class="admin-nav-ico">▥</span>
|
||||
<span class="admin-nav-label">Sklad</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/sklad"
|
||||
class="wj-nav-link @(IsCurrent("/admin/sklad") ? "active" : "")">
|
||||
<span>▥</span> Sklad
|
||||
</a>
|
||||
<a href="/admin/statistiky" class="admin-nav-link @(IsCurrent("/admin/statistiky") ? "active" : null)">
|
||||
<span class="admin-nav-ico">▦</span>
|
||||
<span class="admin-nav-label">Statistiky</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/statistiky"
|
||||
class="wj-nav-link @(IsCurrent("/admin/statistiky") ? "active" : "")">
|
||||
<span>▤</span> Statistiky
|
||||
</a>
|
||||
|
||||
<a href="/admin/nastaveni"
|
||||
class="wj-nav-link @(IsCurrent("/admin/nastaveni") ? "active" : "")">
|
||||
<span>⚙</span> Nastavení
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div class="wj-sidebar-bottom">
|
||||
<div class="wj-sidebar-mark">W</div>
|
||||
<div>
|
||||
<strong>Web-Jarmark</strong>
|
||||
<small>E-shop s domácími produkty</small>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<a href="/admin/nastaveni" class="admin-nav-link @(IsCurrent("/admin/nastaveni") ? "active" : null)">
|
||||
<span class="admin-nav-ico">⚙</span>
|
||||
<span class="admin-nav-label">Nastavení</span>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
@code {
|
||||
private string CurrentPath => "/" +
|
||||
@@ -90,5 +75,4 @@
|
||||
{
|
||||
Nav.LocationChanged -= HandleLocationChanged;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,196 +11,248 @@
|
||||
|
||||
<PageTitle>Přehled administrace</PageTitle>
|
||||
|
||||
<div class="wj-page-heading">
|
||||
<div>
|
||||
<div class="wj-eyebrow">VÁŠ OBCHOD NA JEDNOM MÍSTĚ</div>
|
||||
<h1>Přehled administrace</h1>
|
||||
<p>Rychlý přehled o aktuálním stavu vašeho obchodu.</p>
|
||||
</div>
|
||||
|
||||
<div class="wj-date">
|
||||
<span>◷</span>
|
||||
@DateTime.Now.ToString("d. M. yyyy")
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (loading)
|
||||
{
|
||||
<div class="wj-panel p-4">Načítám data obchodu…</div>
|
||||
<div class="ap-loading">Načítám…</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="wj-stats-grid">
|
||||
<div class="ap">
|
||||
<header class="ap-hero">
|
||||
<p class="ap-eyebrow">Web-Jarmark</p>
|
||||
<h1>Přehled</h1>
|
||||
<p class="ap-sub">Aktuální stav vašeho obchodu na jednom místě.</p>
|
||||
</header>
|
||||
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-top">
|
||||
<span class="wj-stat-icon">↗</span>
|
||||
<span class="wj-stat-caption">KATALOG</span>
|
||||
</div>
|
||||
<div class="wj-stat-label">Celkem produktů</div>
|
||||
<div class="wj-stat-value">@productCount</div>
|
||||
<div class="wj-stat-foot">Všechny produkty v obchodě</div>
|
||||
</div>
|
||||
<section class="ap-metrics">
|
||||
<article class="ap-metric">
|
||||
<span class="ap-metric-label">Produkty</span>
|
||||
<strong class="ap-metric-value">@productCount</strong>
|
||||
<span class="ap-metric-hint">celkem v katalogu</span>
|
||||
</article>
|
||||
<article class="ap-metric">
|
||||
<span class="ap-metric-label">Kategorie</span>
|
||||
<strong class="ap-metric-value">@categoryCount</strong>
|
||||
<span class="ap-metric-hint">v sortimentu</span>
|
||||
</article>
|
||||
<article class="ap-metric">
|
||||
<span class="ap-metric-label">Viditelné</span>
|
||||
<strong class="ap-metric-value">@visibleCount</strong>
|
||||
<span class="ap-metric-hint">v e-shopu</span>
|
||||
</article>
|
||||
<article class="ap-metric">
|
||||
<span class="ap-metric-label">Nízký sklad</span>
|
||||
<strong class="ap-metric-value">@lowStockCount</strong>
|
||||
<span class="ap-metric-hint">≤ 5 kusů</span>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-top">
|
||||
<span class="wj-stat-icon">▤</span>
|
||||
<span class="wj-stat-caption">SORTIMENT</span>
|
||||
</div>
|
||||
<div class="wj-stat-label">Počet kategorií</div>
|
||||
<div class="wj-stat-value">@categoryCount</div>
|
||||
<div class="wj-stat-foot">Kategorie vašeho zboží</div>
|
||||
</div>
|
||||
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-top">
|
||||
<span class="wj-stat-icon">◉</span>
|
||||
<span class="wj-stat-caption">E-SHOP</span>
|
||||
</div>
|
||||
<div class="wj-stat-label">Viditelné produkty</div>
|
||||
<div class="wj-stat-value">@visibleCount</div>
|
||||
<div class="wj-stat-foot">Produkty dostupné v katalogu</div>
|
||||
</div>
|
||||
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-top">
|
||||
<span class="wj-stat-icon">!</span>
|
||||
<span class="wj-stat-caption">SKLAD</span>
|
||||
</div>
|
||||
<div class="wj-stat-label">Dochází skladem</div>
|
||||
<div class="wj-stat-value">@lowStockCount</div>
|
||||
<div class="wj-stat-foot">Produkty s 5 nebo méně kusy</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="wj-middle-grid">
|
||||
|
||||
<section class="wj-panel">
|
||||
<div class="wj-panel-heading">
|
||||
<div>
|
||||
<h2>Produkty podle kategorií</h2>
|
||||
<p>Rozložení vašeho sortimentu</p>
|
||||
@* Řada grafů *@
|
||||
<section class="ap-charts">
|
||||
<article class="ap-panel">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Viditelnost</h2>
|
||||
</div>
|
||||
<a href="/admin/kategorie" class="wj-text-link">Kategorie ↗</a>
|
||||
<div class="ap-donut-block">
|
||||
<div class="ap-donut" style="@visibilityDonutStyle">
|
||||
<div class="ap-donut-hole">
|
||||
<strong>@productCount</strong>
|
||||
<small>celkem</small>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="ap-legend">
|
||||
<li>
|
||||
<span class="ap-swatch is-dark"></span>
|
||||
Viditelné
|
||||
<strong>@visibleCount</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="ap-swatch is-mid"></span>
|
||||
Skryté
|
||||
<strong>@hiddenCount</strong>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="ap-panel">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Stav skladu</h2>
|
||||
</div>
|
||||
<div class="ap-stack-chart">
|
||||
<div class="ap-stack-bar">
|
||||
<div class="ap-stack-seg is-ok" style="@($"width:{stockOkPct}%")" title="V pořádku"></div>
|
||||
<div class="ap-stack-seg is-low" style="@($"width:{stockLowPct}%")" title="Nízký"></div>
|
||||
<div class="ap-stack-seg is-out" style="@($"width:{stockOutPct}%")" title="Vyprodané"></div>
|
||||
</div>
|
||||
<ul class="ap-legend">
|
||||
<li>
|
||||
<span class="ap-swatch is-dark"></span>
|
||||
V pořádku
|
||||
<strong>@stockOkCount</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="ap-swatch is-mid"></span>
|
||||
Nízký (1–5)
|
||||
<strong>@lowStockPositiveCount</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span class="ap-swatch is-light"></span>
|
||||
Vyprodané
|
||||
<strong>@outOfStockCount</strong>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article class="ap-panel">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Katalog</h2>
|
||||
</div>
|
||||
<div class="ap-stat-list">
|
||||
<div class="ap-stat-line">
|
||||
<span>Průměrná cena</span>
|
||||
<strong>@avgPrice.ToString("N0") Kč</strong>
|
||||
</div>
|
||||
<div class="ap-stat-line">
|
||||
<span>Nejvyšší cena</span>
|
||||
<strong>@maxPrice.ToString("N0") Kč</strong>
|
||||
</div>
|
||||
<div class="ap-stat-line">
|
||||
<span>Kusů skladem</span>
|
||||
<strong>@totalStock</strong>
|
||||
</div>
|
||||
<div class="ap-stat-line">
|
||||
<span>Hodnota skladu</span>
|
||||
<strong>@stockValue.ToString("N0") Kč</strong>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="ap-grid">
|
||||
<article class="ap-panel ap-panel-wide">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Produkty podle kategorií</h2>
|
||||
<a href="/admin/kategorie">Spravovat</a>
|
||||
</div>
|
||||
|
||||
@if (categoryStats.Count == 0)
|
||||
{
|
||||
<p class="ap-empty">Zatím žádné kategorie.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="ap-rows">
|
||||
@foreach (var cat in categoryStats)
|
||||
{
|
||||
<div class="ap-row">
|
||||
<div class="ap-row-top">
|
||||
<span>@cat.Name</span>
|
||||
<span class="ap-row-num">@cat.ProductCount</span>
|
||||
</div>
|
||||
<div class="ap-track">
|
||||
<div class="ap-fill" style="@($"width:{GetWidth(cat.ProductCount)}%")"></div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</article>
|
||||
|
||||
<article class="ap-panel">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Rychlé akce</h2>
|
||||
</div>
|
||||
<div class="ap-actions">
|
||||
<a class="ap-action" href="/admin/zbozi/edit">
|
||||
<span class="ap-action-title">Nové zboží</span>
|
||||
<span class="ap-action-sub">Přidat produkt</span>
|
||||
</a>
|
||||
<a class="ap-action" href="/admin/kategorie/edit">
|
||||
<span class="ap-action-title">Nová kategorie</span>
|
||||
<span class="ap-action-sub">Rozšířit sortiment</span>
|
||||
</a>
|
||||
<a class="ap-action" href="/admin/zbozi">
|
||||
<span class="ap-action-title">Správa zboží</span>
|
||||
<span class="ap-action-sub">Upravit katalog</span>
|
||||
</a>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
@* Mini sloupcový graf skladu u produktů *@
|
||||
<section class="ap-panel">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Sklad u produktů</h2>
|
||||
<a href="/admin/zbozi">Katalog</a>
|
||||
</div>
|
||||
|
||||
@if (categoryStats.Count == 0)
|
||||
@if (stockBars.Count == 0)
|
||||
{
|
||||
<div class="wj-empty">Zatím nemáte žádné kategorie.</div>
|
||||
<p class="ap-empty">Zatím žádné produkty.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="wj-category-list">
|
||||
@foreach (var category in categoryStats)
|
||||
<div class="ap-columns">
|
||||
@foreach (var item in stockBars)
|
||||
{
|
||||
<div class="wj-category-item">
|
||||
<div class="wj-category-info">
|
||||
<span>@category.Name</span>
|
||||
<strong>@category.ProductCount</strong>
|
||||
</div>
|
||||
<div class="wj-progress">
|
||||
<div class="wj-progress-fill"
|
||||
style="@($"width: {GetWidth(category.ProductCount)}%")">
|
||||
</div>
|
||||
<div class="ap-col">
|
||||
<div class="ap-col-bar-wrap">
|
||||
<div class="ap-col-bar" style="@($"height:{item.HeightPct}%")"></div>
|
||||
</div>
|
||||
<span class="ap-col-val">@item.Stock</span>
|
||||
<span class="ap-col-label" title="@item.Name">@Truncate(item.Name, 10)</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="wj-panel">
|
||||
<div class="wj-panel-heading">
|
||||
<div>
|
||||
<h2>Rychlé akce</h2>
|
||||
<p>Nejčastější úkony v administraci</p>
|
||||
</div>
|
||||
<section class="ap-panel ap-panel-table">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Produkty</h2>
|
||||
<a href="/admin/zbozi">Zobrazit vše</a>
|
||||
</div>
|
||||
|
||||
<div class="wj-actions">
|
||||
<a href="/admin/zbozi/edit" class="wj-action">
|
||||
<span class="wj-action-icon">+</span>
|
||||
<span>
|
||||
<strong>Přidat nové zboží</strong>
|
||||
<small>Vytvořit nový produkt</small>
|
||||
</span>
|
||||
<span class="wj-action-arrow">→</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/kategorie/edit" class="wj-action">
|
||||
<span class="wj-action-icon">▤</span>
|
||||
<span>
|
||||
<strong>Nová kategorie</strong>
|
||||
<small>Rozšířit nabídku kategorií</small>
|
||||
</span>
|
||||
<span class="wj-action-arrow">→</span>
|
||||
</a>
|
||||
|
||||
<a href="/admin/zbozi" class="wj-action">
|
||||
<span class="wj-action-icon">◇</span>
|
||||
<span>
|
||||
<strong>Spravovat zboží</strong>
|
||||
<small>Upravit nebo skrýt produkty</small>
|
||||
</span>
|
||||
<span class="wj-action-arrow">→</span>
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
<section class="wj-panel wj-products-panel">
|
||||
<div class="wj-panel-heading">
|
||||
<div>
|
||||
<h2>Přehled produktů</h2>
|
||||
<p>Ukázka produktů z vašeho katalogu</p>
|
||||
</div>
|
||||
<a href="/admin/zbozi" class="wj-text-link">Zobrazit vše →</a>
|
||||
</div>
|
||||
|
||||
@if (productPreview.Count == 0)
|
||||
{
|
||||
<div class="wj-empty">Zatím nemáte žádné produkty.</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="wj-table-wrap">
|
||||
<table class="wj-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Produkt</th>
|
||||
<th>Kategorie</th>
|
||||
<th>Cena</th>
|
||||
<th>Skladem</th>
|
||||
<th>Stav</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var product in productPreview)
|
||||
{
|
||||
@if (productPreview.Count == 0)
|
||||
{
|
||||
<p class="ap-empty">Zatím žádné produkty.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="ap-table-wrap">
|
||||
<table class="ap-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="wj-product-name">@product.Name</td>
|
||||
<td>@product.CategoryName</td>
|
||||
<td class="wj-price">@product.Price.ToString("N2") Kč</td>
|
||||
<td>@product.StockQuantity ks</td>
|
||||
<td>
|
||||
@if (product.IsVisible)
|
||||
{
|
||||
<span class="wj-pill">Viditelné</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="wj-pill wj-pill-muted">Skryté</span>
|
||||
}
|
||||
</td>
|
||||
<th>Název</th>
|
||||
<th>Kategorie</th>
|
||||
<th>Cena</th>
|
||||
<th>Sklad</th>
|
||||
<th>Stav</th>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var p in productPreview)
|
||||
{
|
||||
<tr>
|
||||
<td class="ap-name">@p.Name</td>
|
||||
<td>@p.CategoryName</td>
|
||||
<td>@p.Price.ToString("N0") Kč</td>
|
||||
<td>@p.StockQuantity</td>
|
||||
<td>
|
||||
<span class="ap-status @(p.IsVisible ? "is-on" : "is-off")">
|
||||
@(p.IsVisible ? "Viditelné" : "Skryté")
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
|
||||
@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<CategoryStat> categoryStats = new();
|
||||
private List<ProductPreview> productPreview = new();
|
||||
private List<StockBar> stockBars = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
productCount = await Db.Set<Product>().CountAsync();
|
||||
var products = await Db.Set<Product>()
|
||||
.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<Category>().CountAsync();
|
||||
visibleCount = await Db.Set<Product>().CountAsync(p => p.IsVisible);
|
||||
lowStockCount = await Db.Set<Product>().CountAsync(p => p.StockQuantity <= 5);
|
||||
|
||||
var categories = await Db.Set<Category>()
|
||||
.AsNoTracking()
|
||||
@@ -231,27 +337,41 @@ else
|
||||
.Select(c => new CategoryStat(c.Name, c.Products.Count))
|
||||
.ToList();
|
||||
|
||||
productPreview = await Db.Set<Product>()
|
||||
.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);
|
||||
}
|
||||
717
Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor.css
Normal file
717
Web-Jarmark/Web-Jarmark/Components/Pages/Admin/Admin.razor.css
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
<AuthorizeView Context="authContext">
|
||||
<PageTitle>@(Id is null ? "Nová kategorie" : "Upravit kategorii")</PageTitle>
|
||||
<PageTitle>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</PageTitle>
|
||||
|
||||
<div class="wj-admin-page container-fluid py-3">
|
||||
<div class="wj-page-back">
|
||||
<a href="/admin" class="wj-back-admin">
|
||||
<span>←</span> Zpět na administraci
|
||||
</a>
|
||||
</div>
|
||||
<div class="ap">
|
||||
<header class="ap-hero ap-hero-left">
|
||||
<p class="ap-eyebrow">Kategorie</p>
|
||||
<h1>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</h1>
|
||||
<p class="ap-sub">Název a stav kategorie v katalogu.</p>
|
||||
</header>
|
||||
|
||||
<div class="wj-heading mb-4">
|
||||
<div class="wj-eyebrow">ADMINISTRACE / KATEGORIE</div>
|
||||
<h2>@(Id is null ? "Nová kategorie" : "Upravit kategorii")</h2>
|
||||
<p>Vyplňte základní informace o kategorii.</p>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
<div class="ap-alert">@error</div>
|
||||
}
|
||||
|
||||
@if (notFound)
|
||||
{
|
||||
<div class="wj-panel">
|
||||
<div class="alert alert-warning rounded-4 mb-3">
|
||||
Kategorie nebyla nalezena.
|
||||
</div>
|
||||
<a class="wj-button wj-button-secondary" href="/admin/kategorie">
|
||||
Zpět na seznam
|
||||
</a>
|
||||
@if (notFound)
|
||||
{
|
||||
<section class="ap-panel">
|
||||
<p class="ap-empty">Kategorie nebyla nalezena.</p>
|
||||
<a class="ap-btn" href="/admin/kategorie">Zpět na seznam</a>
|
||||
</section>
|
||||
}
|
||||
else if (loading)
|
||||
{
|
||||
<div class="ap-loading">Načítám…</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<section class="ap-panel ap-form-panel">
|
||||
<div class="ap-field">
|
||||
<label>Název</label>
|
||||
<input class="ap-input" @bind="name" />
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="wj-form-card">
|
||||
<div class="wj-form-header">
|
||||
<div class="wj-form-icon">📁</div>
|
||||
<div>
|
||||
<h4>Informace o kategorii</h4>
|
||||
<p>Název a adresa kategorie</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<EditForm Model="form" OnValidSubmit="Save" FormName="categoryForm">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary class="text-danger mb-3" />
|
||||
|
||||
@if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
<div class="alert alert-danger rounded-4">@error</div>
|
||||
}
|
||||
|
||||
<div class="wj-field">
|
||||
<label for="name">Název kategorie</label>
|
||||
<InputText id="name"
|
||||
class="form-control wj-input"
|
||||
placeholder="Např. Cukroví"
|
||||
@bind-Value="form.Name" />
|
||||
<ValidationMessage For="@(() => form.Name)" class="text-danger small" />
|
||||
</div>
|
||||
|
||||
<div class="wj-field">
|
||||
<label for="slug">Adresa kategorie (slug)</label>
|
||||
<InputText id="slug"
|
||||
class="form-control wj-input"
|
||||
placeholder="napr-cukrovi"
|
||||
@bind-Value="form.Slug" />
|
||||
<small>Pokud pole necháte prázdné, adresa se vytvoří automaticky z názvu.</small>
|
||||
</div>
|
||||
|
||||
<div class="wj-switch-card">
|
||||
<div class="form-check form-switch">
|
||||
<InputCheckbox id="active"
|
||||
class="form-check-input"
|
||||
@bind-Value="form.IsActive" />
|
||||
<label class="form-check-label fw-semibold" for="active">
|
||||
Aktivní kategorie
|
||||
</label>
|
||||
</div>
|
||||
<small>Aktivní kategorie může být nabízena zákazníkům.</small>
|
||||
</div>
|
||||
|
||||
<div class="wj-form-actions">
|
||||
<button type="submit" class="wj-button wj-button-primary">
|
||||
Uložit kategorii
|
||||
</button>
|
||||
<a class="wj-button wj-button-secondary" href="/admin/kategorie">
|
||||
Zrušit
|
||||
</a>
|
||||
</div>
|
||||
</EditForm>
|
||||
<div class="ap-field">
|
||||
<label>Slug</label>
|
||||
<input class="ap-input" @bind="categorySlug" />
|
||||
<small class="ap-help">URL identifikátor, např. domaci-vyrobky</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
|
||||
<label class="ap-switch">
|
||||
<input type="checkbox" @bind="isActive" />
|
||||
<span>Aktivní kategorie</span>
|
||||
</label>
|
||||
|
||||
<div class="ap-form-actions">
|
||||
<button type="button" class="ap-btn ap-btn-primary" disabled="@saving" @onclick="SaveAsync">
|
||||
@(saving ? "Ukládám…" : "Uložit")
|
||||
</button>
|
||||
<a class="ap-btn" href="/admin/kategorie">Zrušit</a>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
|
||||
@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<Category>()
|
||||
.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<Category>()
|
||||
.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<Category>().Add(new Category
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
Name = name,
|
||||
Slug = slug,
|
||||
IsActive = form.IsActive
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var cat = await Db.Set<Category>().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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
<AuthorizeView>
|
||||
<PageTitle>Kategorie</PageTitle>
|
||||
|
||||
<div class="wj-admin-page container-fluid py-3">
|
||||
<div class="wj-page-back">
|
||||
<a href="/admin" class="wj-back-admin">
|
||||
<span aria-hidden="true">←</span>
|
||||
Zpět na administraci
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
|
||||
<div>
|
||||
<div class="text-muted small mb-1">ADMINISTRACE / SPRÁVA OBCHODU</div>
|
||||
<h2 class="fw-bold mb-1">Kategorie</h2>
|
||||
<p class="text-muted mb-0">Spravujte kategorie svého zboží.</p>
|
||||
<div class="ap">
|
||||
<header class="ap-hero ap-hero-left">
|
||||
<p class="ap-eyebrow">Administrace</p>
|
||||
<div class="ap-hero-row">
|
||||
<div>
|
||||
<h1>Kategorie</h1>
|
||||
<p class="ap-sub">Správa kategorií sortimentu.</p>
|
||||
</div>
|
||||
<a class="ap-btn ap-btn-primary" href="/admin/kategorie/edit">Nová kategorie</a>
|
||||
</div>
|
||||
|
||||
<a class="btn btn-primary rounded-3 px-4 py-2 shadow-sm"
|
||||
href="/admin/kategorie/edit">
|
||||
<span class="me-2">+</span> Nová kategorie
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
<div class="alert alert-danger rounded-3 shadow-sm">
|
||||
@error
|
||||
</div>
|
||||
<div class="ap-alert">@error</div>
|
||||
}
|
||||
|
||||
@if (categories is null)
|
||||
@if (items is null)
|
||||
{
|
||||
<div class="card border-0 shadow-sm rounded-4 p-4">
|
||||
<div class="text-muted">Načítám kategorie…</div>
|
||||
</div>
|
||||
<div class="ap-loading">Načítám kategorie…</div>
|
||||
}
|
||||
else if (items.Count == 0)
|
||||
{
|
||||
<section class="ap-panel">
|
||||
<p class="ap-empty">Zatím nemáte žádné kategorie.</p>
|
||||
<a class="ap-btn ap-btn-primary" href="/admin/kategorie/edit">Vytvořit první kategorii</a>
|
||||
</section>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="card border-0 shadow-sm rounded-4 mb-4">
|
||||
<div class="card-body p-4">
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<div class="rounded-3 bg-primary bg-opacity-10 text-primary p-3 fs-3">
|
||||
🗂️
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-muted small">Celkem kategorií</div>
|
||||
<div class="fs-3 fw-bold">@categories.Count</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-0 shadow-sm rounded-4 overflow-hidden">
|
||||
<div class="card-header bg-white border-0 px-4 pt-4 pb-3">
|
||||
<h5 class="fw-bold mb-1">Přehled kategorií</h5>
|
||||
<div class="text-muted small">Seznam všech kategorií v obchodě</div>
|
||||
<section class="ap-panel ap-panel-table">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Seznam kategorií</h2>
|
||||
<span class="ap-muted">@items.Count položek</span>
|
||||
</div>
|
||||
|
||||
@if (categories.Count == 0)
|
||||
{
|
||||
<div class="text-center p-5">
|
||||
<div class="fs-1 mb-3">📂</div>
|
||||
<h5 class="fw-bold">Zatím tu nejsou žádné kategorie</h5>
|
||||
<p class="text-muted">Začněte vytvořením první kategorie.</p>
|
||||
<a class="btn btn-primary rounded-3 px-4"
|
||||
href="/admin/kategorie/edit">
|
||||
+ Přidat kategorii
|
||||
</a>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light">
|
||||
<div class="ap-table-wrap">
|
||||
<table class="ap-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Název</th>
|
||||
<th>Slug</th>
|
||||
<th>Produkty</th>
|
||||
<th>Stav</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var c in items)
|
||||
{
|
||||
<tr>
|
||||
<th class="ps-4 py-3">Název kategorie</th>
|
||||
<th class="py-3">Adresa (slug)</th>
|
||||
<th class="text-center py-3">Počet produktů</th>
|
||||
<th class="text-center py-3">Stav</th>
|
||||
<th class="text-end pe-4 py-3">Akce</th>
|
||||
<td class="ap-name">@c.Name</td>
|
||||
<td class="ap-muted">@c.CategorySlug</td>
|
||||
<td>@c.ProductCount</td>
|
||||
<td>
|
||||
<span class="ap-status @(c.IsActive ? "is-on" : "is-off")">
|
||||
@(c.IsActive ? "Aktivní" : "Neaktivní")
|
||||
</span>
|
||||
</td>
|
||||
<td class="ap-actions-cell">
|
||||
<a class="ap-btn ap-btn-ghost" href="@($"/admin/kategorie/edit/{c.Id}")">Upravit</a>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var c in categories)
|
||||
{
|
||||
<tr>
|
||||
<td class="ps-4 py-3 fw-semibold">
|
||||
<span class="me-2">📁</span>@c.Name
|
||||
</td>
|
||||
<td>
|
||||
<code class="bg-light px-2 py-1 rounded">@c.Slug</code>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span class="badge bg-light text-dark rounded-pill px-3 py-2">
|
||||
@c.ProductCount
|
||||
</span>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@if (c.IsActive)
|
||||
{
|
||||
<span class="badge bg-success bg-opacity-10 text-success rounded-pill px-3 py-2">
|
||||
Aktivní
|
||||
</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-secondary bg-opacity-10 text-secondary rounded-pill px-3 py-2">
|
||||
Neaktivní
|
||||
</span>
|
||||
}
|
||||
|
||||
<div class="form-check form-switch d-flex justify-content-center mt-2">
|
||||
<input type="checkbox"
|
||||
class="form-check-input"
|
||||
checked="@c.IsActive"
|
||||
title="Změnit aktivitu"
|
||||
@onchange="() => ToggleActive(c.Id)" />
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-end pe-4">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<a class="btn btn-sm btn-outline-primary rounded-3 px-3"
|
||||
href="/admin/kategorie/edit/@c.Id">
|
||||
Upravit
|
||||
</a>
|
||||
<button class="btn btn-sm btn-outline-danger rounded-3 px-3"
|
||||
disabled="@(c.ProductCount > 0)"
|
||||
title="@(c.ProductCount > 0 ? "Kategorie obsahuje produkty" : "Smazat")"
|
||||
@onclick="() => Delete(c.Id)">
|
||||
Smazat
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="card-footer bg-white border-0 px-4 py-3">
|
||||
<small class="text-muted">
|
||||
Zobrazeno kategorií: @categories.Count
|
||||
</small>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
private List<CategoryRow>? categories;
|
||||
private List<Row>? items;
|
||||
private string? error;
|
||||
|
||||
protected override async Task OnInitializedAsync() => await Load();
|
||||
|
||||
private async Task Load()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
categories = await Db.Set<Category>()
|
||||
.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<Category>().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<Category>()
|
||||
.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<Category>().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);
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
<AuthorizeView Context="authContext1">
|
||||
<PageTitle>@(Id is null ? "Nové zboží" : "Upravit zboží")</PageTitle>
|
||||
<PageTitle>@(IsNew ? "Nové zboží" : "Upravit zboží")</PageTitle>
|
||||
|
||||
<div class="wj-admin-page container-fluid py-3">
|
||||
<div class="wj-page-back">
|
||||
<a href="/admin" class="wj-back-admin">
|
||||
<span>←</span> Zpět na administraci
|
||||
</a>
|
||||
</div>
|
||||
<div class="ap">
|
||||
<header class="ap-hero ap-hero-left">
|
||||
<p class="ap-eyebrow">Zboží</p>
|
||||
<h1>@(IsNew ? "Nové zboží" : "Upravit zboží")</h1>
|
||||
<p class="ap-sub">Údaje produktu v katalogu.</p>
|
||||
</header>
|
||||
|
||||
<div class="wj-heading mb-4">
|
||||
<div class="wj-eyebrow">ADMINISTRACE / ZBOŽÍ</div>
|
||||
<h2>@(Id is null ? "Nové zboží" : "Upravit zboží")</h2>
|
||||
<p>Vyplňte informace o produktu.</p>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
<div class="ap-alert">@error</div>
|
||||
}
|
||||
|
||||
@if (notFound)
|
||||
{
|
||||
<div class="wj-panel">
|
||||
<div class="alert alert-warning rounded-4">Zboží nebylo nalezeno.</div>
|
||||
<a class="wj-button wj-button-secondary" href="/admin/zbozi">
|
||||
Zpět na seznam
|
||||
</a>
|
||||
@if (notFound)
|
||||
{
|
||||
<section class="ap-panel">
|
||||
<p class="ap-empty">Produkt nebyl nalezen.</p>
|
||||
<a class="ap-btn" href="/admin/zbozi">Zpět na seznam</a>
|
||||
</section>
|
||||
}
|
||||
else if (loading)
|
||||
{
|
||||
<div class="ap-loading">Načítám…</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<section class="ap-panel ap-form-panel">
|
||||
<div class="ap-field">
|
||||
<label>Název</label>
|
||||
<input class="ap-input" @bind="name" />
|
||||
</div>
|
||||
}
|
||||
else if (categories is null)
|
||||
{
|
||||
<div class="wj-panel p-4">
|
||||
<span class="text-muted">Načítám…</span>
|
||||
</div>
|
||||
}
|
||||
else if (categories.Count == 0)
|
||||
{
|
||||
<div class="wj-panel">
|
||||
<div class="alert alert-warning rounded-4">
|
||||
Nejdříve musíš vytvořit alespoň jednu kategorii.
|
||||
<a href="/admin/kategorie/edit" class="alert-link">Přidat kategorii</a>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="wj-form-card wj-product-form">
|
||||
<div class="wj-form-header">
|
||||
<div class="wj-form-icon">📦</div>
|
||||
<div>
|
||||
<h4>Informace o produktu</h4>
|
||||
<p>Základní údaje, cena a sklad</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<EditForm Model="form" OnValidSubmit="Save" FormName="productForm">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary class="text-danger mb-3" />
|
||||
|
||||
@if (!string.IsNullOrEmpty(error))
|
||||
<div class="ap-field">
|
||||
<label>Kategorie</label>
|
||||
<select class="ap-select" @bind="categoryId">
|
||||
<option value="0">— vyberte —</option>
|
||||
@foreach (var c in categories)
|
||||
{
|
||||
<div class="alert alert-danger rounded-4">@error</div>
|
||||
<option value="@c.Id">@c.Name</option>
|
||||
}
|
||||
|
||||
<div class="wj-field">
|
||||
<label for="name">Název zboží</label>
|
||||
<InputText id="name"
|
||||
class="form-control wj-input"
|
||||
placeholder="Např. Domácí cukroví"
|
||||
@bind-Value="form.Name" />
|
||||
<ValidationMessage For="@(() => form.Name)" class="text-danger small" />
|
||||
</div>
|
||||
|
||||
<div class="wj-field">
|
||||
<label for="cat">Kategorie</label>
|
||||
<InputSelect id="cat"
|
||||
class="form-select wj-input"
|
||||
@bind-Value="form.CategoryId">
|
||||
<option value="0">– Vyber kategorii –</option>
|
||||
@foreach (var c in categories)
|
||||
{
|
||||
<option value="@c.Id">@c.Name@(c.IsActive ? "" : " (neaktivní)")</option>
|
||||
}
|
||||
</InputSelect>
|
||||
</div>
|
||||
|
||||
<div class="wj-field">
|
||||
<label for="desc">Popis produktu</label>
|
||||
<InputTextArea id="desc"
|
||||
class="form-control wj-input"
|
||||
rows="4"
|
||||
placeholder="Popište produkt…"
|
||||
@bind-Value="form.Description" />
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<div class="wj-field">
|
||||
<label for="price">Cena (Kč)</label>
|
||||
<InputNumber id="price"
|
||||
class="form-control wj-input"
|
||||
@bind-Value="form.Price" />
|
||||
<ValidationMessage For="@(() => form.Price)" class="text-danger small" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="wj-field">
|
||||
<label for="stock">Skladem (ks)</label>
|
||||
<InputNumber id="stock"
|
||||
class="form-control wj-input"
|
||||
@bind-Value="form.StockQuantity" />
|
||||
<ValidationMessage For="@(() => form.StockQuantity)" class="text-danger small" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wj-field">
|
||||
<label for="img">Adresa obrázku</label>
|
||||
<InputText id="img"
|
||||
class="form-control wj-input"
|
||||
placeholder="/images/produkt.jpg"
|
||||
@bind-Value="form.ImageUrl" />
|
||||
<small>Např. /images/cukrovi.jpg (soubor v wwwroot) nebo celá internetová adresa.</small>
|
||||
</div>
|
||||
|
||||
<div class="wj-switch-card">
|
||||
<div class="form-check form-switch">
|
||||
<InputCheckbox id="visible"
|
||||
class="form-check-input"
|
||||
@bind-Value="form.IsVisible" />
|
||||
<label class="form-check-label fw-semibold" for="visible">
|
||||
Viditelné v katalogu
|
||||
</label>
|
||||
</div>
|
||||
<small>Pokud je zapnuto, zákazníci produkt uvidí v e-shopu.</small>
|
||||
</div>
|
||||
|
||||
<div class="wj-form-actions">
|
||||
<button type="submit" class="wj-button wj-button-primary">
|
||||
Uložit zboží
|
||||
</button>
|
||||
<a class="wj-button wj-button-secondary" href="/admin/zbozi">
|
||||
Zrušit
|
||||
</a>
|
||||
</div>
|
||||
</EditForm>
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
|
||||
<div class="ap-field">
|
||||
<label>Popis</label>
|
||||
<textarea class="ap-textarea" @bind="description"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="ap-field">
|
||||
<label>Cena (Kč)</label>
|
||||
<input type="number" step="0.01" class="ap-input" @bind="price" />
|
||||
</div>
|
||||
|
||||
<div class="ap-field">
|
||||
<label>Sklad (ks)</label>
|
||||
<input type="number" class="ap-input" @bind="stockQuantity" />
|
||||
</div>
|
||||
|
||||
<div class="ap-field">
|
||||
<label>URL obrázku</label>
|
||||
<input class="ap-input" @bind="imageUrl" />
|
||||
</div>
|
||||
|
||||
<label class="ap-switch">
|
||||
<input type="checkbox" @bind="isVisible" />
|
||||
<span>Viditelné v e-shopu</span>
|
||||
</label>
|
||||
|
||||
<div class="ap-form-actions">
|
||||
<button type="button" class="ap-btn ap-btn-primary" disabled="@saving" @onclick="SaveAsync">
|
||||
@(saving ? "Ukládám…" : "Uložit")
|
||||
</button>
|
||||
<a class="ap-btn" href="/admin/zbozi">Zrušit</a>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public int? Id { get; set; }
|
||||
[Parameter]
|
||||
public int? Id { get; set; }
|
||||
|
||||
private ProductForm form = new();
|
||||
private List<Category>? categories;
|
||||
private string? error;
|
||||
private bool IsNew => Id is null;
|
||||
|
||||
private List<CatOption> 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<Category>()
|
||||
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<Product>()
|
||||
.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<Product>().Add(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = await Db.Set<Product>().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);
|
||||
}
|
||||
@@ -12,224 +12,140 @@
|
||||
<AuthorizeView>
|
||||
<PageTitle>Zboží</PageTitle>
|
||||
|
||||
<div class="wj-admin-page container-fluid py-3">
|
||||
<div class="wj-page-back">
|
||||
<a href="/admin" class="wj-back-admin">
|
||||
<span>←</span> Zpět na administraci
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="wj-heading d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
|
||||
<div>
|
||||
<div class="wj-eyebrow">ADMINISTRACE / SPRÁVA OBCHODU</div>
|
||||
<h2>Zboží</h2>
|
||||
<p>Přehled a správa produktů v obchodě.</p>
|
||||
<div class="ap">
|
||||
<header class="ap-hero ap-hero-left">
|
||||
<p class="ap-eyebrow">Administrace</p>
|
||||
<div class="ap-hero-row">
|
||||
<div>
|
||||
<h1>Zboží</h1>
|
||||
<p class="ap-sub">Přehled a správa produktů.</p>
|
||||
</div>
|
||||
<a class="ap-btn ap-btn-primary" href="/admin/zbozi/edit">Nové zboží</a>
|
||||
</div>
|
||||
<a class="wj-button wj-button-primary" href="/admin/zbozi/edit">
|
||||
+ Nové zboží
|
||||
</a>
|
||||
</header>
|
||||
|
||||
<div class="ap-toolbar">
|
||||
<input class="ap-input"
|
||||
placeholder="Hledat produkt…"
|
||||
@bind="search"
|
||||
@bind:event="oninput" />
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
<div class="alert alert-danger rounded-4">@error</div>
|
||||
<div class="ap-alert">@error</div>
|
||||
}
|
||||
|
||||
@if (products is null)
|
||||
@if (items is null)
|
||||
{
|
||||
<div class="wj-panel p-4">
|
||||
<span class="text-muted">Načítám zboží…</span>
|
||||
</div>
|
||||
<div class="ap-loading">Načítám zboží…</div>
|
||||
}
|
||||
else if (Filtered.Count == 0)
|
||||
{
|
||||
<section class="ap-panel">
|
||||
<p class="ap-empty">Žádné produkty k zobrazení.</p>
|
||||
<a class="ap-btn ap-btn-primary" href="/admin/zbozi/edit">Přidat produkt</a>
|
||||
</section>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row g-3 mb-4">
|
||||
<div class="col-sm-6 col-xl-4">
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-icon">📦</div>
|
||||
<div class="wj-stat-label">Celkem produktů</div>
|
||||
<div class="wj-stat-value">@products.Count</div>
|
||||
</div>
|
||||
<section class="ap-panel ap-panel-table">
|
||||
<div class="ap-panel-head">
|
||||
<h2>Katalog</h2>
|
||||
<span class="ap-muted">@Filtered.Count položek</span>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-xl-4">
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-icon">✓</div>
|
||||
<div class="wj-stat-label">Viditelné produkty</div>
|
||||
<div class="wj-stat-value">@products.Count(p => p.IsVisible)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6 col-xl-4">
|
||||
<div class="wj-stat-card">
|
||||
<div class="wj-stat-icon">📉</div>
|
||||
<div class="wj-stat-label">Dochází skladem (5 a méně)</div>
|
||||
<div class="wj-stat-value">@products.Count(p => p.StockQuantity <= 5)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wj-panel p-0 overflow-hidden">
|
||||
<div class="p-4 d-flex flex-wrap justify-content-between align-items-center gap-3">
|
||||
<div>
|
||||
<h4 class="fw-bold mb-1">Přehled produktů</h4>
|
||||
<p class="text-muted mb-0 small">Všechny produkty v e-shopu</p>
|
||||
</div>
|
||||
|
||||
<div class="wj-search">
|
||||
<span>⌕</span>
|
||||
<input class="form-control"
|
||||
placeholder="Hledat zboží nebo kategorii…"
|
||||
@bind="searchTerm"
|
||||
@bind:event="oninput" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (FilteredProducts.Count == 0)
|
||||
{
|
||||
<div class="text-center p-5">
|
||||
<div class="fs-1 mb-3">🔎</div>
|
||||
<h5 class="fw-bold">Nic jsme nenašli</h5>
|
||||
<p class="text-muted mb-0">Zkuste změnit hledaný výraz.</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-responsive">
|
||||
<table class="table wj-table align-middle mb-0">
|
||||
<thead>
|
||||
<div class="ap-table-wrap">
|
||||
<table class="ap-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Produkt</th>
|
||||
<th>Kategorie</th>
|
||||
<th>Cena</th>
|
||||
<th>Sklad</th>
|
||||
<th>Stav</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var p in Filtered)
|
||||
{
|
||||
<tr>
|
||||
<th class="ps-4">Název zboží</th>
|
||||
<th>Kategorie</th>
|
||||
<th class="text-end">Cena</th>
|
||||
<th class="text-center">Skladem</th>
|
||||
<th class="text-center">Viditelnost</th>
|
||||
<th class="text-end pe-4">Akce</th>
|
||||
<td class="ap-name">@p.Name</td>
|
||||
<td>@p.CategoryName</td>
|
||||
<td>@p.Price.ToString("N0") Kč</td>
|
||||
<td>@p.StockQuantity</td>
|
||||
<td>
|
||||
<span class="ap-status @(p.IsVisible ? "is-on" : "is-off")">
|
||||
@(p.IsVisible ? "Viditelné" : "Skryté")
|
||||
</span>
|
||||
</td>
|
||||
<td class="ap-actions-cell">
|
||||
<a class="ap-btn ap-btn-ghost" href="@($"/admin/zbozi/edit/{p.Id}")">Upravit</a>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var p in FilteredProducts)
|
||||
{
|
||||
<tr>
|
||||
<td class="ps-4 fw-semibold">@p.Name</td>
|
||||
<td>
|
||||
<span class="wj-tag">@p.CategoryName</span>
|
||||
</td>
|
||||
<td class="text-end fw-semibold">@p.Price.ToString("N2") Kč</td>
|
||||
<td class="text-center">
|
||||
@if (p.StockQuantity <= 5)
|
||||
{
|
||||
<span class="wj-stock-low">@p.StockQuantity ks</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="wj-tag">@p.StockQuantity ks</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<div class="form-check form-switch d-flex justify-content-center">
|
||||
<input type="checkbox"
|
||||
class="form-check-input"
|
||||
checked="@p.IsVisible"
|
||||
title="Změnit viditelnost"
|
||||
@onchange="() => ToggleVisible(p.Id)" />
|
||||
</div>
|
||||
<small class="text-muted">@(p.IsVisible ? "Viditelné" : "Skryté")</small>
|
||||
</td>
|
||||
<td class="text-end pe-4">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<a class="wj-small-button" href="/admin/zbozi/edit/@p.Id">
|
||||
Upravit
|
||||
</a>
|
||||
<button class="wj-small-button wj-danger-button"
|
||||
@onclick="() => Delete(p.Id)">
|
||||
Smazat
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="border-top px-4 py-3">
|
||||
<small class="text-muted">
|
||||
Zobrazeno: @FilteredProducts.Count z @products.Count produktů
|
||||
</small>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
private List<ProductRow>? products;
|
||||
private List<Row>? items;
|
||||
private string search = "";
|
||||
private string? error;
|
||||
private string searchTerm = "";
|
||||
|
||||
private List<ProductRow> 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<Row> Filtered
|
||||
{
|
||||
products = await Db.Set<Product>()
|
||||
.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<Product>().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<Product>()
|
||||
.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<Row>();
|
||||
}
|
||||
|
||||
Db.Set<Product>().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);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user