vylepseni admin
This commit is contained in:
@@ -1,22 +1,85 @@
|
|||||||
@inherits LayoutComponentBase
|
@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>
|
||||||
|
|
||||||
|
<button type="button"
|
||||||
|
class="admin-toggle"
|
||||||
|
title="@(collapsed ? "Rozbalit" : "Sbalit")"
|
||||||
|
@onclick="Toggle">
|
||||||
|
☰
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<AdminNavMenu />
|
<AdminNavMenu />
|
||||||
|
|
||||||
<main class="wj-main">
|
<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>
|
||||||
|
|
||||||
<header class="wj-topbar">
|
<div class="admin-main">
|
||||||
<div class="wj-topbar-label">ADMINISTRACE</div>
|
<header class="admin-topbar">
|
||||||
<div class="wj-topbar-right">
|
<div class="admin-topbar-title">@SectionTitle</div>
|
||||||
<span class="wj-status-dot"></span>
|
<div class="admin-topbar-user">
|
||||||
<span>Administrátor</span>
|
<span class="admin-dot"></span>
|
||||||
|
Administrátor
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section class="wj-content">
|
<main class="admin-content">
|
||||||
@Body
|
@Body
|
||||||
</section>
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
</div>
|
||||||
</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í */
|
/* Nový admin shell – třídy admin-*, ať se nesráží se starým app.css */
|
||||||
.wj-dashboard {
|
|
||||||
|
.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;
|
display: flex;
|
||||||
width: 100%;
|
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
margin: 0;
|
background: var(--bg);
|
||||||
padding: 0;
|
color: var(--ink);
|
||||||
overflow-x: hidden;
|
font-family: Inter, "Segoe UI", system-ui, sans-serif;
|
||||||
background: #f8f8f8;
|
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;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wj-content {
|
.admin-topbar {
|
||||||
flex: 1;
|
height: 64px;
|
||||||
width: 100%;
|
padding: 0 28px;
|
||||||
min-width: 0;
|
display: flex;
|
||||||
padding: 28px 32px;
|
align-items: center;
|
||||||
box-sizing: border-box;
|
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 */
|
.admin-topbar-title {
|
||||||
.wj-main,
|
font-size: 17px;
|
||||||
.wj-content {
|
font-weight: 700;
|
||||||
transition: all 0.25s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Menší obrazovky */
|
.admin-topbar-user {
|
||||||
@media (max-width: 768px) {
|
display: flex;
|
||||||
.wj-content {
|
align-items: center;
|
||||||
padding: 20px 16px;
|
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
|
@implements IDisposable
|
||||||
@inject NavigationManager Nav
|
@inject NavigationManager Nav
|
||||||
|
|
||||||
<aside class="wj-sidebar">
|
<nav class="admin-nav">
|
||||||
<a href="/admin" class="wj-brand">
|
<a href="/admin" class="admin-nav-link @(IsCurrent("/admin", true) ? "active" : null)">
|
||||||
<span class="wj-brand-icon">W</span>
|
<span class="admin-nav-ico">⌂</span>
|
||||||
<span>Web-Jarmark</span>
|
<span class="admin-nav-label">Přehled</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<nav class="wj-nav">
|
<a href="/admin/kategorie" class="admin-nav-link @(IsCurrent("/admin/kategorie") ? "active" : null)">
|
||||||
<a href="/admin"
|
<span class="admin-nav-ico">▤</span>
|
||||||
class="wj-nav-link @(IsCurrent("/admin", true) ? "active" : "")">
|
<span class="admin-nav-label">Kategorie</span>
|
||||||
<span>⌂</span> Přehled
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/admin/kategorie"
|
<a href="/admin/zbozi" class="admin-nav-link @(IsCurrent("/admin/zbozi") ? "active" : null)">
|
||||||
class="wj-nav-link @(IsCurrent("/admin/kategorie") ? "active" : "")">
|
<span class="admin-nav-ico">◇</span>
|
||||||
<span>▤</span> Kategorie
|
<span class="admin-nav-label">Zboží</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/admin/zbozi"
|
<a href="/admin/objednavky" class="admin-nav-link @(IsCurrent("/admin/objednavky") ? "active" : null)">
|
||||||
class="wj-nav-link @(IsCurrent("/admin/zbozi") ? "active" : "")">
|
<span class="admin-nav-ico">▣</span>
|
||||||
<span>◇</span> Zboží
|
<span class="admin-nav-label">Objednávky</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/admin/objednavky"
|
<a href="/admin/administratori" class="admin-nav-link @(IsCurrent("/admin/administratori") ? "active" : null)">
|
||||||
class="wj-nav-link @(IsCurrent("/admin/objednavky") ? "active" : "")">
|
<span class="admin-nav-ico">👤</span>
|
||||||
<span>▣</span> Objednávky
|
<span class="admin-nav-label">Administrátoři</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/admin/zakaznici"
|
<a href="/admin/sklad" class="admin-nav-link @(IsCurrent("/admin/sklad") ? "active" : null)">
|
||||||
class="wj-nav-link @(IsCurrent("/admin/zakaznici") ? "active" : "")">
|
<span class="admin-nav-ico">▥</span>
|
||||||
<span>♙</span> Zákazníci
|
<span class="admin-nav-label">Sklad</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/admin/sklad"
|
<a href="/admin/statistiky" class="admin-nav-link @(IsCurrent("/admin/statistiky") ? "active" : null)">
|
||||||
class="wj-nav-link @(IsCurrent("/admin/sklad") ? "active" : "")">
|
<span class="admin-nav-ico">▦</span>
|
||||||
<span>▥</span> Sklad
|
<span class="admin-nav-label">Statistiky</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/admin/statistiky"
|
<a href="/admin/nastaveni" class="admin-nav-link @(IsCurrent("/admin/nastaveni") ? "active" : null)">
|
||||||
class="wj-nav-link @(IsCurrent("/admin/statistiky") ? "active" : "")">
|
<span class="admin-nav-ico">⚙</span>
|
||||||
<span>▤</span> Statistiky
|
<span class="admin-nav-label">Nastavení</span>
|
||||||
</a>
|
</a>
|
||||||
|
</nav>
|
||||||
<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>
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string CurrentPath => "/" +
|
private string CurrentPath => "/" +
|
||||||
@@ -91,4 +76,3 @@
|
|||||||
Nav.LocationChanged -= HandleLocationChanged;
|
Nav.LocationChanged -= HandleLocationChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,188 +11,239 @@
|
|||||||
|
|
||||||
<PageTitle>Přehled administrace</PageTitle>
|
<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)
|
@if (loading)
|
||||||
{
|
{
|
||||||
<div class="wj-panel p-4">Načítám data obchodu…</div>
|
<div class="ap-loading">Načítám…</div>
|
||||||
}
|
}
|
||||||
else
|
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">
|
<section class="ap-metrics">
|
||||||
<div class="wj-stat-top">
|
<article class="ap-metric">
|
||||||
<span class="wj-stat-icon">↗</span>
|
<span class="ap-metric-label">Produkty</span>
|
||||||
<span class="wj-stat-caption">KATALOG</span>
|
<strong class="ap-metric-value">@productCount</strong>
|
||||||
</div>
|
<span class="ap-metric-hint">celkem v katalogu</span>
|
||||||
<div class="wj-stat-label">Celkem produktů</div>
|
</article>
|
||||||
<div class="wj-stat-value">@productCount</div>
|
<article class="ap-metric">
|
||||||
<div class="wj-stat-foot">Všechny produkty v obchodě</div>
|
<span class="ap-metric-label">Kategorie</span>
|
||||||
</div>
|
<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">
|
@* Řada grafů *@
|
||||||
<div class="wj-stat-top">
|
<section class="ap-charts">
|
||||||
<span class="wj-stat-icon">▤</span>
|
<article class="ap-panel">
|
||||||
<span class="wj-stat-caption">SORTIMENT</span>
|
<div class="ap-panel-head">
|
||||||
|
<h2>Viditelnost</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="wj-stat-label">Počet kategorií</div>
|
<div class="ap-donut-block">
|
||||||
<div class="wj-stat-value">@categoryCount</div>
|
<div class="ap-donut" style="@visibilityDonutStyle">
|
||||||
<div class="wj-stat-foot">Kategorie vašeho zboží</div>
|
<div class="ap-donut-hole">
|
||||||
|
<strong>@productCount</strong>
|
||||||
|
<small>celkem</small>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div class="wj-stat-card">
|
<article class="ap-panel">
|
||||||
<div class="wj-stat-top">
|
<div class="ap-panel-head">
|
||||||
<span class="wj-stat-icon">◉</span>
|
<h2>Stav skladu</h2>
|
||||||
<span class="wj-stat-caption">E-SHOP</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="wj-stat-label">Viditelné produkty</div>
|
<div class="ap-stack-chart">
|
||||||
<div class="wj-stat-value">@visibleCount</div>
|
<div class="ap-stack-bar">
|
||||||
<div class="wj-stat-foot">Produkty dostupné v katalogu</div>
|
<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>
|
</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>
|
||||||
|
|
||||||
<div class="wj-stat-card">
|
<article class="ap-panel">
|
||||||
<div class="wj-stat-top">
|
<div class="ap-panel-head">
|
||||||
<span class="wj-stat-icon">!</span>
|
<h2>Katalog</h2>
|
||||||
<span class="wj-stat-caption">SKLAD</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="wj-stat-label">Dochází skladem</div>
|
<div class="ap-stat-list">
|
||||||
<div class="wj-stat-value">@lowStockCount</div>
|
<div class="ap-stat-line">
|
||||||
<div class="wj-stat-foot">Produkty s 5 nebo méně kusy</div>
|
<span>Průměrná cena</span>
|
||||||
|
<strong>@avgPrice.ToString("N0") Kč</strong>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ap-stat-line">
|
||||||
|
<span>Nejvyšší cena</span>
|
||||||
|
<strong>@maxPrice.ToString("N0") Kč</strong>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div class="wj-middle-grid">
|
<section class="ap-grid">
|
||||||
|
<article class="ap-panel ap-panel-wide">
|
||||||
<section class="wj-panel">
|
<div class="ap-panel-head">
|
||||||
<div class="wj-panel-heading">
|
|
||||||
<div>
|
|
||||||
<h2>Produkty podle kategorií</h2>
|
<h2>Produkty podle kategorií</h2>
|
||||||
<p>Rozložení vašeho sortimentu</p>
|
<a href="/admin/kategorie">Spravovat</a>
|
||||||
</div>
|
|
||||||
<a href="/admin/kategorie" class="wj-text-link">Kategorie ↗</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (categoryStats.Count == 0)
|
@if (categoryStats.Count == 0)
|
||||||
{
|
{
|
||||||
<div class="wj-empty">Zatím nemáte žádné kategorie.</div>
|
<p class="ap-empty">Zatím žádné kategorie.</p>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="wj-category-list">
|
<div class="ap-rows">
|
||||||
@foreach (var category in categoryStats)
|
@foreach (var cat in categoryStats)
|
||||||
{
|
{
|
||||||
<div class="wj-category-item">
|
<div class="ap-row">
|
||||||
<div class="wj-category-info">
|
<div class="ap-row-top">
|
||||||
<span>@category.Name</span>
|
<span>@cat.Name</span>
|
||||||
<strong>@category.ProductCount</strong>
|
<span class="ap-row-num">@cat.ProductCount</span>
|
||||||
</div>
|
|
||||||
<div class="wj-progress">
|
|
||||||
<div class="wj-progress-fill"
|
|
||||||
style="@($"width: {GetWidth(category.ProductCount)}%")">
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ap-track">
|
||||||
|
<div class="ap-fill" style="@($"width:{GetWidth(cat.ProductCount)}%")"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</section>
|
</article>
|
||||||
|
|
||||||
<section class="wj-panel">
|
<article class="ap-panel">
|
||||||
<div class="wj-panel-heading">
|
<div class="ap-panel-head">
|
||||||
<div>
|
|
||||||
<h2>Rychlé akce</h2>
|
<h2>Rychlé akce</h2>
|
||||||
<p>Nejčastější úkony v administraci</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="ap-actions">
|
||||||
|
<a class="ap-action" href="/admin/zbozi/edit">
|
||||||
<div class="wj-actions">
|
<span class="ap-action-title">Nové zboží</span>
|
||||||
<a href="/admin/zbozi/edit" class="wj-action">
|
<span class="ap-action-sub">Přidat produkt</span>
|
||||||
<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>
|
||||||
|
<a class="ap-action" href="/admin/kategorie/edit">
|
||||||
<a href="/admin/kategorie/edit" class="wj-action">
|
<span class="ap-action-title">Nová kategorie</span>
|
||||||
<span class="wj-action-icon">▤</span>
|
<span class="ap-action-sub">Rozšířit sortiment</span>
|
||||||
<span>
|
|
||||||
<strong>Nová kategorie</strong>
|
|
||||||
<small>Rozšířit nabídku kategorií</small>
|
|
||||||
</span>
|
|
||||||
<span class="wj-action-arrow">→</span>
|
|
||||||
</a>
|
</a>
|
||||||
|
<a class="ap-action" href="/admin/zbozi">
|
||||||
<a href="/admin/zbozi" class="wj-action">
|
<span class="ap-action-title">Správa zboží</span>
|
||||||
<span class="wj-action-icon">◇</span>
|
<span class="ap-action-sub">Upravit katalog</span>
|
||||||
<span>
|
|
||||||
<strong>Spravovat zboží</strong>
|
|
||||||
<small>Upravit nebo skrýt produkty</small>
|
|
||||||
</span>
|
|
||||||
<span class="wj-action-arrow">→</span>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
</article>
|
||||||
</section>
|
</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>
|
</div>
|
||||||
|
|
||||||
<section class="wj-panel wj-products-panel">
|
@if (stockBars.Count == 0)
|
||||||
<div class="wj-panel-heading">
|
{
|
||||||
<div>
|
<p class="ap-empty">Zatím žádné produkty.</p>
|
||||||
<h2>Přehled produktů</h2>
|
}
|
||||||
<p>Ukázka produktů z vašeho katalogu</p>
|
else
|
||||||
|
{
|
||||||
|
<div class="ap-columns">
|
||||||
|
@foreach (var item in stockBars)
|
||||||
|
{
|
||||||
|
<div class="ap-col">
|
||||||
|
<div class="ap-col-bar-wrap">
|
||||||
|
<div class="ap-col-bar" style="@($"height:{item.HeightPct}%")"></div>
|
||||||
</div>
|
</div>
|
||||||
<a href="/admin/zbozi" class="wj-text-link">Zobrazit vše →</a>
|
<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="ap-panel ap-panel-table">
|
||||||
|
<div class="ap-panel-head">
|
||||||
|
<h2>Produkty</h2>
|
||||||
|
<a href="/admin/zbozi">Zobrazit vše</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (productPreview.Count == 0)
|
@if (productPreview.Count == 0)
|
||||||
{
|
{
|
||||||
<div class="wj-empty">Zatím nemáte žádné produkty.</div>
|
<p class="ap-empty">Zatím žádné produkty.</p>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="wj-table-wrap">
|
<div class="ap-table-wrap">
|
||||||
<table class="wj-table">
|
<table class="ap-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Produkt</th>
|
<th>Název</th>
|
||||||
<th>Kategorie</th>
|
<th>Kategorie</th>
|
||||||
<th>Cena</th>
|
<th>Cena</th>
|
||||||
<th>Skladem</th>
|
<th>Sklad</th>
|
||||||
<th>Stav</th>
|
<th>Stav</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var product in productPreview)
|
@foreach (var p in productPreview)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td class="wj-product-name">@product.Name</td>
|
<td class="ap-name">@p.Name</td>
|
||||||
<td>@product.CategoryName</td>
|
<td>@p.CategoryName</td>
|
||||||
<td class="wj-price">@product.Price.ToString("N2") Kč</td>
|
<td>@p.Price.ToString("N0") Kč</td>
|
||||||
<td>@product.StockQuantity ks</td>
|
<td>@p.StockQuantity</td>
|
||||||
<td>
|
<td>
|
||||||
@if (product.IsVisible)
|
<span class="ap-status @(p.IsVisible ? "is-on" : "is-off")">
|
||||||
{
|
@(p.IsVisible ? "Viditelné" : "Skryté")
|
||||||
<span class="wj-pill">Viditelné</span>
|
</span>
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<span class="wj-pill wj-pill-muted">Skryté</span>
|
|
||||||
}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@@ -201,6 +252,7 @@ else
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</section>
|
</section>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -209,17 +261,71 @@ else
|
|||||||
private int productCount;
|
private int productCount;
|
||||||
private int categoryCount;
|
private int categoryCount;
|
||||||
private int visibleCount;
|
private int visibleCount;
|
||||||
|
private int hiddenCount;
|
||||||
private int lowStockCount;
|
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<CategoryStat> categoryStats = new();
|
||||||
private List<ProductPreview> productPreview = new();
|
private List<ProductPreview> productPreview = new();
|
||||||
|
private List<StockBar> stockBars = new();
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
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();
|
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>()
|
var categories = await Db.Set<Category>()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@@ -231,27 +337,41 @@ else
|
|||||||
.Select(c => new CategoryStat(c.Name, c.Products.Count))
|
.Select(c => new CategoryStat(c.Name, c.Products.Count))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
productPreview = await Db.Set<Product>()
|
productPreview = products
|
||||||
.AsNoTracking()
|
|
||||||
.OrderBy(p => p.Name)
|
.OrderBy(p => p.Name)
|
||||||
.Take(5)
|
.Take(6)
|
||||||
.Select(p => new ProductPreview(
|
.Select(p => new ProductPreview(
|
||||||
p.Name,
|
p.Name,
|
||||||
p.Category.Name,
|
p.CategoryName,
|
||||||
p.Price,
|
p.Price,
|
||||||
p.StockQuantity,
|
p.StockQuantity,
|
||||||
p.IsVisible))
|
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;
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetWidth(int count)
|
private int GetWidth(int count)
|
||||||
{
|
{
|
||||||
var max = categoryStats.Count == 0 ? 1 : categoryStats.Max(c => c.ProductCount);
|
var max = categoryStats.Count == 0 ? 1 : Math.Max(1, categoryStats.Max(c => c.ProductCount));
|
||||||
return count == 0 ? 0 : Math.Max(5, (int)Math.Round(count * 100.0 / Math.Max(1, max)));
|
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 CategoryStat(string Name, int ProductCount);
|
||||||
|
|
||||||
private record ProductPreview(
|
private record ProductPreview(
|
||||||
@@ -260,4 +380,6 @@ else
|
|||||||
decimal Price,
|
decimal Price,
|
||||||
int StockQuantity,
|
int StockQuantity,
|
||||||
bool IsVisible);
|
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}"
|
@page "/admin/kategorie/edit/{Id:int}"
|
||||||
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
|
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
@using System.ComponentModel.DataAnnotations
|
|
||||||
@using System.Globalization
|
|
||||||
@using System.Text
|
|
||||||
@using System.Text.RegularExpressions
|
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using Microsoft.AspNetCore.Authorization
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using Web_Jarmark.Data
|
@using Web_Jarmark.Data
|
||||||
@@ -15,204 +11,146 @@
|
|||||||
|
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
<AuthorizeView Context="authContext">
|
<PageTitle>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</PageTitle>
|
||||||
<PageTitle>@(Id is null ? "Nová kategorie" : "Upravit kategorii")</PageTitle>
|
|
||||||
|
|
||||||
<div class="wj-admin-page container-fluid py-3">
|
<div class="ap">
|
||||||
<div class="wj-page-back">
|
<header class="ap-hero ap-hero-left">
|
||||||
<a href="/admin" class="wj-back-admin">
|
<p class="ap-eyebrow">Kategorie</p>
|
||||||
<span>←</span> Zpět na administraci
|
<h1>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</h1>
|
||||||
</a>
|
<p class="ap-sub">Název a stav kategorie v katalogu.</p>
|
||||||
</div>
|
</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 (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>
|
|
||||||
</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))
|
@if (!string.IsNullOrEmpty(error))
|
||||||
{
|
{
|
||||||
<div class="alert alert-danger rounded-4">@error</div>
|
<div class="ap-alert">@error</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="wj-field">
|
@if (notFound)
|
||||||
<label for="name">Název kategorie</label>
|
{
|
||||||
<InputText id="name"
|
<section class="ap-panel">
|
||||||
class="form-control wj-input"
|
<p class="ap-empty">Kategorie nebyla nalezena.</p>
|
||||||
placeholder="Např. Cukroví"
|
<a class="ap-btn" href="/admin/kategorie">Zpět na seznam</a>
|
||||||
@bind-Value="form.Name" />
|
</section>
|
||||||
<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>
|
|
||||||
}
|
}
|
||||||
</div>
|
else if (loading)
|
||||||
</AuthorizeView>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public int? Id { get; set; }
|
|
||||||
|
|
||||||
private CategoryForm form = new();
|
|
||||||
private string? error;
|
|
||||||
private bool notFound;
|
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
|
||||||
{
|
{
|
||||||
notFound = false;
|
<div class="ap-loading">Načítám…</div>
|
||||||
error = null;
|
|
||||||
|
|
||||||
if (Id is null) return;
|
|
||||||
|
|
||||||
var cat = await Db.Set<Category>()
|
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefaultAsync(c => c.Id == Id);
|
|
||||||
|
|
||||||
if (cat is null)
|
|
||||||
{
|
|
||||||
notFound = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
form = new CategoryForm
|
|
||||||
{
|
|
||||||
Name = cat.Name,
|
|
||||||
Slug = cat.Slug,
|
|
||||||
IsActive = cat.IsActive
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task Save()
|
|
||||||
{
|
|
||||||
error = null;
|
|
||||||
|
|
||||||
var name = form.Name.Trim();
|
|
||||||
var slug = Slugify(string.IsNullOrWhiteSpace(form.Slug) ? name : form.Slug);
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(slug))
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Slug = slug,
|
|
||||||
IsActive = form.IsActive
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var cat = await Db.Set<Category>().FindAsync(Id);
|
<section class="ap-panel ap-form-panel">
|
||||||
|
<div class="ap-field">
|
||||||
|
<label>Název</label>
|
||||||
|
<input class="ap-input" @bind="name" />
|
||||||
|
</div>
|
||||||
|
|
||||||
if (cat is null)
|
<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>
|
||||||
|
|
||||||
|
<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; }
|
||||||
|
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
notFound = true;
|
loading = true;
|
||||||
|
notFound = false;
|
||||||
|
error = null;
|
||||||
|
|
||||||
|
if (IsNew)
|
||||||
|
{
|
||||||
|
name = "";
|
||||||
|
categorySlug = "";
|
||||||
|
isActive = true;
|
||||||
|
loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cat.Name = name;
|
var entity = await Db.Categories.AsNoTracking().FirstOrDefaultAsync(c => c.Id == Id!.Value);
|
||||||
cat.Slug = slug;
|
if (entity is null)
|
||||||
cat.IsActive = form.IsActive;
|
{
|
||||||
|
notFound = true;
|
||||||
|
loading = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name = entity.Name ?? "";
|
||||||
|
categorySlug = entity.Slug ?? "";
|
||||||
|
isActive = entity.IsActive;
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveAsync()
|
||||||
|
{
|
||||||
|
saving = true;
|
||||||
|
error = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
error = "Zadejte název kategorie.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
await Db.SaveChangesAsync();
|
||||||
Nav.NavigateTo("/admin/kategorie");
|
Nav.NavigateTo("/admin/kategorie");
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
private static string Slugify(string text)
|
|
||||||
{
|
{
|
||||||
var normalized = text.Trim()
|
error = "Uložení se nezdařilo: " + ex.Message;
|
||||||
.ToLowerInvariant()
|
|
||||||
.Normalize(NormalizationForm.FormD);
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
|
|
||||||
foreach (var ch in normalized)
|
|
||||||
{
|
|
||||||
if (CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark)
|
|
||||||
sb.Append(ch);
|
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
var noDiacritics = sb.ToString().Normalize(NormalizationForm.FormC);
|
|
||||||
return Regex.Replace(noDiacritics, "[^a-z0-9]+", "-").Trim('-');
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryForm
|
|
||||||
{
|
{
|
||||||
[Required(ErrorMessage = "Zadej název kategorie.")]
|
saving = false;
|
||||||
[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
|
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using Web_Jarmark.Data
|
@using Web_Jarmark.Data
|
||||||
@using Web_Jarmark.Data.Models
|
@using Web_Jarmark.Data.Models
|
||||||
@using Microsoft.AspNetCore.Authorization
|
|
||||||
@inject ApplicationDbContext Db
|
@inject ApplicationDbContext Db
|
||||||
@inject NavigationManager Nav
|
|
||||||
|
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<PageTitle>Kategorie</PageTitle>
|
<PageTitle>Kategorie</PageTitle>
|
||||||
|
|
||||||
<div class="wj-admin-page container-fluid py-3">
|
<div class="ap">
|
||||||
<div class="wj-page-back">
|
<header class="ap-hero ap-hero-left">
|
||||||
<a href="/admin" class="wj-back-admin">
|
<p class="ap-eyebrow">Administrace</p>
|
||||||
<span aria-hidden="true">←</span>
|
<div class="ap-hero-row">
|
||||||
Zpět na administraci
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
|
|
||||||
<div>
|
<div>
|
||||||
<div class="text-muted small mb-1">ADMINISTRACE / SPRÁVA OBCHODU</div>
|
<h1>Kategorie</h1>
|
||||||
<h2 class="fw-bold mb-1">Kategorie</h2>
|
<p class="ap-sub">Správa kategorií sortimentu.</p>
|
||||||
<p class="text-muted mb-0">Spravujte kategorie svého zboží.</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<a class="ap-btn ap-btn-primary" href="/admin/kategorie/edit">Nová kategorie</a>
|
||||||
<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>
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(error))
|
@if (!string.IsNullOrEmpty(error))
|
||||||
{
|
{
|
||||||
<div class="alert alert-danger rounded-3 shadow-sm">
|
<div class="ap-alert">@error</div>
|
||||||
@error
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (categories is null)
|
@if (items is null)
|
||||||
{
|
{
|
||||||
<div class="card border-0 shadow-sm rounded-4 p-4">
|
<div class="ap-loading">Načítám kategorie…</div>
|
||||||
<div class="text-muted">Načítám kategorie…</div>
|
}
|
||||||
</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
|
else
|
||||||
{
|
{
|
||||||
<div class="card border-0 shadow-sm rounded-4 mb-4">
|
<section class="ap-panel ap-panel-table">
|
||||||
<div class="card-body p-4">
|
<div class="ap-panel-head">
|
||||||
<div class="d-flex align-items-center gap-3">
|
<h2>Seznam kategorií</h2>
|
||||||
<div class="rounded-3 bg-primary bg-opacity-10 text-primary p-3 fs-3">
|
<span class="ap-muted">@items.Count položek</span>
|
||||||
🗂️
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="text-muted small">Celkem kategorií</div>
|
|
||||||
<div class="fs-3 fw-bold">@categories.Count</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card border-0 shadow-sm rounded-4 overflow-hidden">
|
<div class="ap-table-wrap">
|
||||||
<div class="card-header bg-white border-0 px-4 pt-4 pb-3">
|
<table class="ap-table">
|
||||||
<h5 class="fw-bold mb-1">Přehled kategorií</h5>
|
<thead>
|
||||||
<div class="text-muted small">Seznam všech kategorií v obchodě</div>
|
|
||||||
</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">
|
|
||||||
<tr>
|
<tr>
|
||||||
<th class="ps-4 py-3">Název kategorie</th>
|
<th>Název</th>
|
||||||
<th class="py-3">Adresa (slug)</th>
|
<th>Slug</th>
|
||||||
<th class="text-center py-3">Počet produktů</th>
|
<th>Produkty</th>
|
||||||
<th class="text-center py-3">Stav</th>
|
<th>Stav</th>
|
||||||
<th class="text-end pe-4 py-3">Akce</th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var c in categories)
|
@foreach (var c in items)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td class="ps-4 py-3 fw-semibold">
|
<td class="ap-name">@c.Name</td>
|
||||||
<span class="me-2">📁</span>@c.Name
|
<td class="ap-muted">@c.CategorySlug</td>
|
||||||
</td>
|
<td>@c.ProductCount</td>
|
||||||
<td>
|
<td>
|
||||||
<code class="bg-light px-2 py-1 rounded">@c.Slug</code>
|
<span class="ap-status @(c.IsActive ? "is-on" : "is-off")">
|
||||||
</td>
|
@(c.IsActive ? "Aktivní" : "Neaktivní")
|
||||||
<td class="text-center">
|
|
||||||
<span class="badge bg-light text-dark rounded-pill px-3 py-2">
|
|
||||||
@c.ProductCount
|
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="ap-actions-cell">
|
||||||
@if (c.IsActive)
|
<a class="ap-btn ap-btn-ghost" href="@($"/admin/kategorie/edit/{c.Id}")">Upravit</a>
|
||||||
{
|
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
}
|
</section>
|
||||||
|
|
||||||
<div class="card-footer bg-white border-0 px-4 py-3">
|
|
||||||
<small class="text-muted">
|
|
||||||
Zobrazeno kategorií: @categories.Count
|
|
||||||
</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private List<CategoryRow>? categories;
|
private List<Row>? items;
|
||||||
private string? error;
|
private string? error;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() => await Load();
|
protected override async Task OnInitializedAsync()
|
||||||
|
|
||||||
private async Task Load()
|
|
||||||
{
|
{
|
||||||
categories = await Db.Set<Category>()
|
try
|
||||||
|
{
|
||||||
|
items = await Db.Categories
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.OrderBy(c => c.Name)
|
.OrderBy(c => c.Name)
|
||||||
.Select(c => new CategoryRow(c.Id, c.Name, c.Slug, c.IsActive, c.Products.Count))
|
.Select(c => new Row(
|
||||||
|
c.Id,
|
||||||
|
c.Name,
|
||||||
|
c.Slug,
|
||||||
|
c.IsActive,
|
||||||
|
c.Products.Count))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
private async Task ToggleActive(int id)
|
|
||||||
{
|
{
|
||||||
var cat = await Db.Set<Category>().FindAsync(id);
|
error = "Nepodařilo se načíst kategorie: " + ex.Message;
|
||||||
if (cat is null) return;
|
items = new();
|
||||||
|
}
|
||||||
cat.IsActive = !cat.IsActive;
|
|
||||||
await Db.SaveChangesAsync();
|
|
||||||
await Load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Delete(int id)
|
private sealed record Row(
|
||||||
{
|
int Id,
|
||||||
error = null;
|
string Name,
|
||||||
|
string CategorySlug,
|
||||||
var cat = await Db.Set<Category>()
|
bool IsActive,
|
||||||
.Include(c => c.Products)
|
int ProductCount);
|
||||||
.FirstOrDefaultAsync(c => c.Id == id);
|
|
||||||
|
|
||||||
if (cat is null) return;
|
|
||||||
|
|
||||||
if (cat.Products.Count > 0)
|
|
||||||
{
|
|
||||||
error = "Kategorii nelze smazat, obsahuje produkty.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Db.Set<Category>().Remove(cat);
|
|
||||||
await Db.SaveChangesAsync();
|
|
||||||
await Load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private record CategoryRow(int Id, string Name, string Slug, bool IsActive, int ProductCount);
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
@page "/admin/zbozi/edit/{Id:int}"
|
@page "/admin/zbozi/edit/{Id:int}"
|
||||||
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
|
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
@using System.ComponentModel.DataAnnotations
|
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using Microsoft.AspNetCore.Authorization
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using Web_Jarmark.Data
|
@using Web_Jarmark.Data
|
||||||
@@ -12,256 +11,200 @@
|
|||||||
|
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
|
|
||||||
<AuthorizeView Context="authContext1">
|
<PageTitle>@(IsNew ? "Nové zboží" : "Upravit zboží")</PageTitle>
|
||||||
<PageTitle>@(Id is null ? "Nové zboží" : "Upravit zboží")</PageTitle>
|
|
||||||
|
|
||||||
<div class="wj-admin-page container-fluid py-3">
|
<div class="ap">
|
||||||
<div class="wj-page-back">
|
<header class="ap-hero ap-hero-left">
|
||||||
<a href="/admin" class="wj-back-admin">
|
<p class="ap-eyebrow">Zboží</p>
|
||||||
<span>←</span> Zpět na administraci
|
<h1>@(IsNew ? "Nové zboží" : "Upravit zboží")</h1>
|
||||||
</a>
|
<p class="ap-sub">Údaje produktu v katalogu.</p>
|
||||||
</div>
|
</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 (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>
|
|
||||||
</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))
|
@if (!string.IsNullOrEmpty(error))
|
||||||
{
|
{
|
||||||
<div class="alert alert-danger rounded-4">@error</div>
|
<div class="ap-alert">@error</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="wj-field">
|
@if (notFound)
|
||||||
<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>
|
<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>
|
||||||
}
|
}
|
||||||
</InputSelect>
|
else if (loading)
|
||||||
</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>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</AuthorizeView>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public int? Id { get; set; }
|
|
||||||
|
|
||||||
private ProductForm form = new();
|
|
||||||
private List<Category>? categories;
|
|
||||||
private string? error;
|
|
||||||
private bool notFound;
|
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
|
||||||
{
|
{
|
||||||
notFound = false;
|
<div class="ap-loading">Načítám…</div>
|
||||||
error = null;
|
|
||||||
|
|
||||||
categories = await Db.Set<Category>()
|
|
||||||
.AsNoTracking()
|
|
||||||
.OrderBy(c => c.Name)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
if (Id is null) return;
|
|
||||||
|
|
||||||
var p = await Db.Set<Product>()
|
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefaultAsync(x => x.Id == Id);
|
|
||||||
|
|
||||||
if (p is null)
|
|
||||||
{
|
|
||||||
notFound = true;
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task Save()
|
|
||||||
{
|
|
||||||
error = null;
|
|
||||||
|
|
||||||
if (form.CategoryId == 0)
|
|
||||||
{
|
|
||||||
error = "Vyber kategorii.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Id is null)
|
|
||||||
{
|
|
||||||
var p = new Product();
|
|
||||||
Apply(p);
|
|
||||||
Db.Set<Product>().Add(p);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var p = await Db.Set<Product>().FindAsync(Id);
|
<section class="ap-panel ap-form-panel">
|
||||||
|
<div class="ap-field">
|
||||||
|
<label>Název</label>
|
||||||
|
<input class="ap-input" @bind="name" />
|
||||||
|
</div>
|
||||||
|
|
||||||
if (p is null)
|
<div class="ap-field">
|
||||||
|
<label>Kategorie</label>
|
||||||
|
<select class="ap-select" @bind="categoryId">
|
||||||
|
<option value="0">— vyberte —</option>
|
||||||
|
@foreach (var c in categories)
|
||||||
{
|
{
|
||||||
notFound = true;
|
<option value="@c.Id">@c.Name</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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; }
|
||||||
|
|
||||||
|
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.Categories
|
||||||
|
.AsNoTracking()
|
||||||
|
.OrderBy(c => c.Name)
|
||||||
|
.Select(c => new CatOption(c.Id, c.Name))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
if (IsNew)
|
||||||
|
{
|
||||||
|
name = "";
|
||||||
|
description = "";
|
||||||
|
categoryId = 0;
|
||||||
|
price = 0;
|
||||||
|
stockQuantity = 0;
|
||||||
|
imageUrl = "";
|
||||||
|
isVisible = true;
|
||||||
|
loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Apply(p);
|
var entity = await Db.Products.AsNoTracking().FirstOrDefaultAsync(p => p.Id == Id!.Value);
|
||||||
|
if (entity is null)
|
||||||
|
{
|
||||||
|
notFound = true;
|
||||||
|
loading = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 SaveAsync()
|
||||||
|
{
|
||||||
|
saving = true;
|
||||||
|
error = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
error = "Zadejte název produktu.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
await Db.SaveChangesAsync();
|
||||||
Nav.NavigateTo("/admin/zbozi");
|
Nav.NavigateTo("/admin/zbozi");
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
private void Apply(Product p)
|
|
||||||
{
|
{
|
||||||
p.Name = form.Name.Trim();
|
error = "Uložení se nezdařilo: " + ex.Message;
|
||||||
p.CategoryId = form.CategoryId;
|
}
|
||||||
p.Description = form.Description?.Trim() ?? "";
|
finally
|
||||||
p.Price = form.Price;
|
{
|
||||||
p.StockQuantity = form.StockQuantity;
|
saving = false;
|
||||||
p.ImageUrl = form.ImageUrl?.Trim() ?? "";
|
}
|
||||||
p.IsVisible = form.IsVisible;
|
|
||||||
p.UpdatedAt = DateTime.Now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProductForm
|
private sealed record CatOption(int Id, string Name);
|
||||||
{
|
|
||||||
[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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -12,178 +12,120 @@
|
|||||||
<AuthorizeView>
|
<AuthorizeView>
|
||||||
<PageTitle>Zboží</PageTitle>
|
<PageTitle>Zboží</PageTitle>
|
||||||
|
|
||||||
<div class="wj-admin-page container-fluid py-3">
|
<div class="ap">
|
||||||
<div class="wj-page-back">
|
<header class="ap-hero ap-hero-left">
|
||||||
<a href="/admin" class="wj-back-admin">
|
<p class="ap-eyebrow">Administrace</p>
|
||||||
<span>←</span> Zpět na administraci
|
<div class="ap-hero-row">
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="wj-heading d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
|
|
||||||
<div>
|
<div>
|
||||||
<div class="wj-eyebrow">ADMINISTRACE / SPRÁVA OBCHODU</div>
|
<h1>Zboží</h1>
|
||||||
<h2>Zboží</h2>
|
<p class="ap-sub">Přehled a správa produktů.</p>
|
||||||
<p>Přehled a správa produktů v obchodě.</p>
|
|
||||||
</div>
|
</div>
|
||||||
<a class="wj-button wj-button-primary" href="/admin/zbozi/edit">
|
<a class="ap-btn ap-btn-primary" href="/admin/zbozi/edit">Nové zboží</a>
|
||||||
+ Nové zboží
|
</div>
|
||||||
</a>
|
</header>
|
||||||
|
|
||||||
|
<div class="ap-toolbar">
|
||||||
|
<input class="ap-input"
|
||||||
|
placeholder="Hledat produkt…"
|
||||||
|
@bind="search"
|
||||||
|
@bind:event="oninput" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (!string.IsNullOrEmpty(error))
|
@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">
|
<div class="ap-loading">Načítám zboží…</div>
|
||||||
<span class="text-muted">Načítám zboží…</span>
|
}
|
||||||
</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
|
else
|
||||||
{
|
{
|
||||||
<div class="row g-3 mb-4">
|
<section class="ap-panel ap-panel-table">
|
||||||
<div class="col-sm-6 col-xl-4">
|
<div class="ap-panel-head">
|
||||||
<div class="wj-stat-card">
|
<h2>Katalog</h2>
|
||||||
<div class="wj-stat-icon">📦</div>
|
<span class="ap-muted">@Filtered.Count položek</span>
|
||||||
<div class="wj-stat-label">Celkem produktů</div>
|
|
||||||
<div class="wj-stat-value">@products.Count</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-6 col-xl-4">
|
<div class="ap-table-wrap">
|
||||||
<div class="wj-stat-card">
|
<table class="ap-table">
|
||||||
<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>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="ps-4">Název zboží</th>
|
<th>Produkt</th>
|
||||||
<th>Kategorie</th>
|
<th>Kategorie</th>
|
||||||
<th class="text-end">Cena</th>
|
<th>Cena</th>
|
||||||
<th class="text-center">Skladem</th>
|
<th>Sklad</th>
|
||||||
<th class="text-center">Viditelnost</th>
|
<th>Stav</th>
|
||||||
<th class="text-end pe-4">Akce</th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var p in FilteredProducts)
|
@foreach (var p in Filtered)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr>
|
||||||
<td class="ps-4 fw-semibold">@p.Name</td>
|
<td class="ap-name">@p.Name</td>
|
||||||
|
<td>@p.CategoryName</td>
|
||||||
|
<td>@p.Price.ToString("N0") Kč</td>
|
||||||
|
<td>@p.StockQuantity</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="wj-tag">@p.CategoryName</span>
|
<span class="ap-status @(p.IsVisible ? "is-on" : "is-off")">
|
||||||
|
@(p.IsVisible ? "Viditelné" : "Skryté")
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-end fw-semibold">@p.Price.ToString("N2") Kč</td>
|
<td class="ap-actions-cell">
|
||||||
<td class="text-center">
|
<a class="ap-btn ap-btn-ghost" href="@($"/admin/zbozi/edit/{p.Id}")">Upravit</a>
|
||||||
@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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
}
|
</section>
|
||||||
|
|
||||||
<div class="border-top px-4 py-3">
|
|
||||||
<small class="text-muted">
|
|
||||||
Zobrazeno: @FilteredProducts.Count z @products.Count produktů
|
|
||||||
</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private List<ProductRow>? products;
|
private List<Row>? items;
|
||||||
|
private string search = "";
|
||||||
private string? error;
|
private string? error;
|
||||||
private string searchTerm = "";
|
|
||||||
|
|
||||||
private List<ProductRow> FilteredProducts =>
|
private List<Row> Filtered
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
products = await Db.Set<Product>()
|
get
|
||||||
|
{
|
||||||
|
if (items is null)
|
||||||
|
{
|
||||||
|
return new List<Row>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(search))
|
||||||
|
{
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
return items.Where(p =>
|
||||||
|
p.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
p.CategoryName.Contains(search, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
items = await Db.Products
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.OrderBy(p => p.Name)
|
.OrderBy(p => p.Name)
|
||||||
.Select(p => new ProductRow(
|
.Select(p => new Row(
|
||||||
p.Id,
|
p.Id,
|
||||||
p.Name,
|
p.Name,
|
||||||
p.Category.Name,
|
p.Category.Name,
|
||||||
@@ -192,40 +134,14 @@
|
|||||||
p.IsVisible))
|
p.IsVisible))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
private async Task ToggleVisible(int id)
|
|
||||||
{
|
{
|
||||||
var p = await Db.Set<Product>().FindAsync(id);
|
error = "Nepodařilo se načíst zboží: " + ex.Message;
|
||||||
if (p is null) return;
|
items = new();
|
||||||
|
}
|
||||||
p.IsVisible = !p.IsVisible;
|
|
||||||
p.UpdatedAt = DateTime.Now;
|
|
||||||
await Db.SaveChangesAsync();
|
|
||||||
await Load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Delete(int id)
|
private sealed record Row(
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
error = $"Zboží „{p.Name}“ už je v objednávkách, nelze ho smazat. Odškrtni raději „Viditelné“.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Db.Set<Product>().Remove(p);
|
|
||||||
await Db.SaveChangesAsync();
|
|
||||||
await Load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private record ProductRow(
|
|
||||||
int Id,
|
int Id,
|
||||||
string Name,
|
string Name,
|
||||||
string CategoryName,
|
string CategoryName,
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user