Compare commits

..

37 Commits

Author SHA1 Message Date
maja
e476e36855 zmena pro lidi 2026-11-25 17:36:29 +01:00
Ondur
69a8138226 objednavky 2026-11-18 18:14:43 +01:00
Ondur
b6f81a12ea ZMENY 2026-11-18 17:47:44 +01:00
Ondur
28316b58ab program 2026-11-18 17:33:30 +01:00
maja
2c593a53a1 data 2026-11-18 17:28:09 +01:00
maja
fe1487a1f5 datasbaze 2026-11-18 17:27:18 +01:00
Ondur
26c82eca08 oprava tokenu 2026-11-18 17:26:16 +01:00
Ondur
217adaba63 Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-11-11 18:34:53 +01:00
Ondur
083da573e0 hodne admin 2026-11-11 18:34:51 +01:00
maja
e212712cac ... 2026-11-11 18:31:33 +01:00
maja
e5bc6cfbc0 ... 2026-11-11 18:29:11 +01:00
Ondur
dc74a416d0 macinka 2026-11-11 18:04:02 +01:00
Ondur
bfd3b54154 moc moc mocinky zmen jako macinka 2026-11-11 18:03:36 +01:00
maja
31de50c40a upraveni uziv. rozhrani 2026-11-11 18:02:50 +01:00
Ondur
acce73329a nevmenu 2026-11-11 17:20:50 +01:00
Ondur
8e6a4db0ad ... 2026-11-11 17:19:33 +01:00
Ondur
1dad6cc160 Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-11-11 17:16:22 +01:00
Ondur
89fd7a2f46 admin 2026-11-11 17:16:20 +01:00
maja
f583062d54 zemny 2026-11-11 17:00:26 +01:00
Ondur
257fd7481a admin 2026-11-11 16:53:32 +01:00
Marek Jarolimek
1506bfcf09 hezci disgn katalogu a uvodi stranky 2026-11-07 09:48:25 +01:00
Marek Jarolimek
b3a5f42980 Po kliknuti na celou kartu se otevre detail produtu 2026-11-06 20:51:23 +01:00
Marek Jarolimek
66489a918f uprvaveni onfa kosik i v deteil vyrovku 2026-11-06 20:45:16 +01:00
Marek Jarolimek
4dcec14dac pridani onfo o kosiku 2026-11-06 20:26:09 +01:00
Marek Jarolimek
7e77301838 Pridani info o tom ze jsi neco pridal do kosiku 2026-11-06 20:23:46 +01:00
Marek Jarolimek
2ad874af33 odstraneni FF z bocniho menu 2026-11-06 20:14:36 +01:00
Marek Jarolimek
ec94b0320d objednavky detail pro admin 2026-11-06 19:55:20 +01:00
Marek Jarolimek
2d1ee8338e udelani detail objednavek a pokracovat v objednavce 2026-11-06 19:17:22 +01:00
maja
ce3fa4f689 vytovreni stranky nobaobjed 2026-11-04 18:43:20 +01:00
maja
2a2baba4a4 vytvoreni stranky nova objednavkja 2026-11-04 18:41:47 +01:00
Ondur
83488e97a9 admin prava 2026-11-04 18:40:50 +01:00
Ondur
fcaf17eacd admin 2026-11-04 18:18:30 +01:00
Ondur
59c47f2b03 admin 2026-11-04 18:18:12 +01:00
maja
1a8a3ee563 zmena barvz do kosiku 2026-11-04 18:17:49 +01:00
Ondur
962aad7c86 admin 2026-11-04 18:07:22 +01:00
Ondur
1d546191c1 vylepsteni admin 2026-11-04 18:05:15 +01:00
Ondur
e4550576df vylepseni admin 2026-11-04 18:04:23 +01:00
43 changed files with 13223 additions and 1798 deletions

2
.gitignore vendored
View File

@@ -414,3 +414,5 @@ FodyWeavers.xsd
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix
/Web-Jarmark/Web-Jarmark/jarmark.db-shm
/Web-Jarmark/Web-Jarmark/jarmark.db-wal

View File

@@ -127,7 +127,7 @@
if (result.Succeeded) if (result.Succeeded)
{ {
Logger.LogInformation("User logged in."); Logger.LogInformation("User logged in.");
RedirectManager.RedirectTo(ReturnUrl); RedirectManager.RedirectTo(string.IsNullOrWhiteSpace(ReturnUrl) ? "admin" : ReturnUrl);
} }
else if (result.RequiresTwoFactor) else if (result.RequiresTwoFactor)
{ {

View File

@@ -6,37 +6,21 @@
@inject UserManager<ApplicationUser> UserManager @inject UserManager<ApplicationUser> UserManager
@inject IdentityRedirectManager RedirectManager @inject IdentityRedirectManager RedirectManager
<PageTitle>Personal Data</PageTitle> <PageTitle>Osobní údaje</PageTitle>
<StatusMessage /> <h3>Osobní údaje</h3>
<h3>Personal Data</h3>
<div class="row">
<div class="col-md-6">
<p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p>
<p> <p>
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong> V účtu jsou uložené osobní údaje, které jsi zadal. Tady si je můžeš stáhnout nebo účet smazat.
</p> </p>
<form action="Account/Manage/DownloadPersonalData" method="post"> <p>
<strong>Smazání údajů trvale odstraní účet a nelze to vrátit zpět.</strong>
</p>
<div class="manage-actions">
<form method="post" action="Account/Manage/DownloadPersonalData">
<AntiforgeryToken /> <AntiforgeryToken />
<button class="btn btn-primary" type="submit">Download</button> <button type="submit" class="btn btn-primary">Stáhnout data</button>
</form> </form>
<p>
<a href="Account/Manage/DeletePersonalData" class="btn btn-danger">Delete</a>
</p>
</div>
</div>
@code { <a class="btn btn-primary" href="Account/Manage/DeletePersonalData">Smazat účet</a>
[CascadingParameter] </div>
private HttpContext HttpContext { get; set; } = default!;
protected override async Task OnInitializedAsync()
{
var user = await UserManager.GetUserAsync(HttpContext.User);
if (user is null)
{
RedirectManager.RedirectToInvalidUser(UserManager, HttpContext);
}
}
}

View File

@@ -1,17 +1,23 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
@layout Web_Jarmark.Components.Layout.MainLayout @layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@using Microsoft.AspNetCore.Authorization
<h1>Manage your account</h1> @attribute [Authorize(Roles = "Admin")]
<div> <div class="ap ao manage-shell">
<h2>Change your account settings</h2> <header class="ao-hero">
<hr /> <p class="ao-eyebrow">Účet</p>
<div class="row"> <h1>Správa účtu</h1>
<div class="col-lg-3"> <p class="ao-sub">Profil, heslo a zabezpečení.</p>
</header>
<div class="manage-grid">
<aside class="manage-nav-card">
<p class="manage-nav-title">Nastavení</p>
<ManageNavMenu /> <ManageNavMenu />
</div> </aside>
<div class="col-lg-9"> <section class="manage-content-card">
@Body @Body
</div> </section>
</div> </div>
</div> </div>

View File

@@ -1,34 +1,23 @@
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Web_Jarmark.Data @using Web_Jarmark.Data
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<ApplicationUser> SignInManager
<ul class="nav nav-pills flex-column"> <nav class="manage-nav">
<li class="nav-item"> <NavLink class="manage-nav-link" href="Account/Manage" Match="NavLinkMatch.All">Profil</NavLink>
<NavLink class="nav-link" href="Account/Manage" Match="NavLinkMatch.All">Profile</NavLink> <NavLink class="manage-nav-link" href="Account/Manage/Email">E-mail</NavLink>
</li> <NavLink class="manage-nav-link" href="Account/Manage/ChangePassword">Heslo</NavLink>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/Email">Email</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/ChangePassword">Password</NavLink>
</li>
@if (hasExternalLogins) @if (hasExternalLogins)
{ {
<li class="nav-item"> <NavLink class="manage-nav-link" href="Account/Manage/ExternalLogins">Externí přihlášení</NavLink>
<NavLink class="nav-link" href="Account/Manage/ExternalLogins">External logins</NavLink>
</li>
} }
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/TwoFactorAuthentication">Two-factor authentication</NavLink> <NavLink class="manage-nav-link" href="Account/Manage/TwoFactorAuthentication">2FA</NavLink>
</li> <NavLink class="manage-nav-link" href="Account/Manage/Passkeys">Passkeys</NavLink>
<li class="nav-item"> <NavLink class="manage-nav-link" href="Account/Manage/PersonalData">Osobní údaje</NavLink>
<NavLink class="nav-link" href="Account/Manage/Passkeys">Passkeys</NavLink>
</li> <a class="manage-nav-link manage-nav-back" href="/admin">← Admin</a>
<li class="nav-item"> </nav>
<NavLink class="nav-link" href="Account/Manage/PersonalData">Personal data</NavLink>
</li>
</ul>
@code { @code {
private bool hasExternalLogins; private bool hasExternalLogins;

View File

@@ -1,22 +1,89 @@
@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">
<div class="admin-foot-card">
<span class="admin-logo-mark small">W</span>
<div class="admin-foot-text">
<strong>Web-Jarmark</strong>
<small>Administrace</small>
</div>
</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 class="admin-dot"></span>
<span>Administrátor</span> <span>Administrátor</span>
</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";
private void Toggle() => collapsed = !collapsed;
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/sklad") => "Sklad",
var p when p.StartsWith("/admin/statistiky") => "Statistiky",
var p when p.StartsWith("/admin/nastaveni") => "Nastavení",
_ => "Administrace"
};
}
public void Dispose()
{
Nav.LocationChanged -= OnLocationChanged;
}
}

View File

@@ -1,40 +1,279 @@
/* Administrátorské rozložení */ /* Apple-like admin – plovoucí, hodně zaoblené */
.wj-dashboard {
display: flex; .admin-shell {
width: 100%; --bg: #f5f5f7;
--ink: #1d1d1f;
--muted: #6e6e73;
--line: rgba(0, 0, 0, 0.06);
--sidebar-w: 280px;
--sidebar-w-collapsed: 92px;
min-height: 100vh; min-height: 100vh;
margin: 0; display: flex;
padding: 0; gap: 14px;
overflow-x: hidden; padding: 14px;
background: #f8f8f8; box-sizing: border-box;
background: var(--bg);
color: var(--ink);
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
} }
.wj-main { /* ===== SIDEBAR CARD ===== */
.admin-sidebar {
width: var(--sidebar-w);
flex-shrink: 0;
position: sticky;
top: 14px;
height: calc(100vh - 28px);
display: flex;
flex-direction: column;
background: rgba(255, 255, 255, 0.86);
border: 1px solid rgba(0, 0, 0, 0.04);
border-radius: 28px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
backdrop-filter: blur(18px);
overflow: hidden;
transition: width 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.admin-shell.is-collapsed .admin-sidebar {
width: var(--sidebar-w-collapsed);
}
.admin-sidebar-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 18px 16px 12px;
}
.admin-logo {
display: flex;
align-items: center;
gap: 12px;
text-decoration: none;
color: var(--ink);
min-width: 0;
}
.admin-logo-mark {
width: 40px;
height: 40px;
border-radius: 14px;
background: #1d1d1f;
color: #fff;
display: grid;
place-items: center;
font-weight: 800;
font-size: 15px;
flex-shrink: 0;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.admin-logo-mark.small {
width: 32px;
height: 32px;
border-radius: 11px;
font-size: 12px;
}
.admin-logo-text {
font-weight: 700;
font-size: 16px;
letter-spacing: -0.03em;
white-space: nowrap;
}
.admin-toggle {
width: 38px;
height: 38px;
border: 0;
border-radius: 13px;
background: #f0f0f2;
color: var(--ink);
cursor: pointer;
flex-shrink: 0;
transition: background 0.2s ease, transform 0.15s ease;
}
.admin-toggle:hover {
background: #e6e6ea;
transform: scale(1.03);
}
/* NAV */
::deep .admin-nav {
display: flex;
flex-direction: column;
gap: 6px;
padding: 8px 12px 12px;
flex: 1;
overflow-y: auto;
}
::deep .admin-nav-link {
display: flex;
align-items: center;
gap: 12px;
padding: 13px 14px;
border-radius: 16px;
text-decoration: none;
color: var(--muted);
font-weight: 600;
font-size: 14px;
letter-spacing: -0.01em;
transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
white-space: nowrap;
}
::deep .admin-nav-link:hover {
background: rgba(0, 0, 0, 0.04);
color: var(--ink);
}
::deep .admin-nav-link.active {
background: #1d1d1f;
color: #fff;
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}
::deep .admin-nav-ico {
width: 22px;
text-align: center;
flex-shrink: 0;
font-size: 15px;
}
::deep .admin-nav-label {
overflow: hidden;
}
/* FOOT */
.admin-sidebar-foot {
padding: 10px 12px 14px;
}
.admin-foot-card {
display: flex;
align-items: center;
gap: 10px;
padding: 12px;
border-radius: 18px;
background: #f5f5f7;
}
.admin-foot-text {
min-width: 0;
overflow: hidden;
}
.admin-foot-text strong {
display: block;
font-size: 13px;
font-weight: 700;
letter-spacing: -0.02em;
}
.admin-foot-text small {
display: block;
font-size: 11px;
color: var(--muted);
}
/* ===== MAIN CARD ===== */
.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;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(0, 0, 0, 0.04);
border-radius: 28px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.04);
backdrop-filter: blur(18px);
overflow: hidden;
}
.admin-topbar {
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 0 28px;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
background: rgba(255, 255, 255, 0.55);
}
.admin-topbar-title {
font-size: 20px;
font-weight: 700;
letter-spacing: -0.03em;
}
.admin-topbar-user {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-radius: 999px;
background: #f5f5f7;
font-size: 13px;
font-weight: 600;
color: var(--muted);
}
.admin-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #1d1d1f;
}
.admin-content {
padding: 22px 28px 36px;
flex: 1;
overflow: auto;
}
/* Collapsed */
.admin-shell.is-collapsed .admin-logo-text,
.admin-shell.is-collapsed ::deep .admin-nav-label,
.admin-shell.is-collapsed .admin-foot-text {
display: none;
}
.admin-shell.is-collapsed ::deep .admin-nav-link {
justify-content: center;
padding-left: 0;
padding-right: 0;
}
.admin-shell.is-collapsed .admin-sidebar-head {
justify-content: center;
flex-direction: column;
} }
.wj-content { .admin-shell.is-collapsed .admin-foot-card {
flex: 1; justify-content: center;
width: 100%;
min-width: 0;
padding: 28px 32px;
box-sizing: border-box;
} }
/* Plynulé přechody */ .admin-shell.is-collapsed .admin-logo {
.wj-main, justify-content: center;
.wj-content { }
transition: all 0.25s ease; /* SVG ikony v menu */
::deep .admin-nav-ico {
width: 22px;
height: 22px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
} }
/* Menší obrazovky */ ::deep .admin-nav-ico svg {
@media (max-width: 768px) { width: 20px;
.wj-content { height: 20px;
padding: 20px 16px; display: block;
} }
}

View File

@@ -1,63 +1,97 @@
@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="/" class="admin-nav-link">
<span class="wj-brand-icon">W</span> <span class="admin-nav-ico" aria-hidden="true">
<span>Web-Jarmark</span> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 18 9 12l6-6" />
</svg>
</span>
<span class="admin-nav-label">E-shop</span>
</a> </a>
<nav class="wj-nav"> <a href="/admin" class="admin-nav-link @(IsCurrent("/admin", true) ? "active" : null)">
<a href="/admin" <span class="admin-nav-ico" aria-hidden="true">
class="wj-nav-link @(IsCurrent("/admin", true) ? "active" : "")"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<span>⌂</span> Přehled <path d="M4 10.5 12 4l8 6.5V20a1 1 0 0 1-1 1h-5v-6H10v6H5a1 1 0 0 1-1-1v-9.5Z" />
</svg>
</span>
<span class="admin-nav-label">Přehled</span>
</a> </a>
<a href="/admin/kategorie" <a href="/admin/kategorie" class="admin-nav-link @(IsCurrent("/admin/kategorie") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/kategorie") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>▤</span> Kategorie <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<rect x="4" y="4" width="7" height="7" rx="1.5" />
<rect x="13" y="4" width="7" height="7" rx="1.5" />
<rect x="4" y="13" width="7" height="7" rx="1.5" />
<rect x="13" y="13" width="7" height="7" rx="1.5" />
</svg>
</span>
<span class="admin-nav-label">Kategorie</span>
</a> </a>
<a href="/admin/zbozi" <a href="/admin/zbozi" class="admin-nav-link @(IsCurrent("/admin/zbozi") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/zbozi") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>◇</span> Zboží <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 7h10l1.2 12.2a1.5 1.5 0 0 1-1.5 1.6H7.3a1.5 1.5 0 0 1-1.5-1.6L7 7Z" />
<path d="M9 7a3 3 0 0 1 6 0" />
</svg>
</span>
<span class="admin-nav-label">Zboží</span>
</a> </a>
<a href="/admin/objednavky" <a href="/admin/objednavky" class="admin-nav-link @(IsCurrent("/admin/objednavky") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/objednavky") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>▣</span> Objednávky <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 4h10a2 2 0 0 1 2 2v14l-3-2-3 2-3-2-3 2V6a2 2 0 0 1 2-2Z" />
<path d="M9 9h6M9 13h6" />
</svg>
</span>
<span class="admin-nav-label">Objednávky</span>
</a> </a>
<a href="/admin/zakaznici" <a href="/admin/administratori" class="admin-nav-link @(IsCurrent("/admin/administratori") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/zakaznici") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>♙</span> Zákazníci <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="8" r="3.5" />
<path d="M5.5 19a6.5 6.5 0 0 1 13 0" />
</svg>
</span>
<span class="admin-nav-label">Administrátoři</span>
</a> </a>
<a href="/admin/sklad" <a href="/admin/sklad" class="admin-nav-link @(IsCurrent("/admin/sklad") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/sklad") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>▥</span> Sklad <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 8.5 12 4l8 4.5V19a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8.5Z" />
<path d="M12 12v8M8 10.5 12 12l4-1.5" />
</svg>
</span>
<span class="admin-nav-label">Sklad</span>
</a> </a>
<a href="/admin/statistiky" <a href="/admin/statistiky" class="admin-nav-link @(IsCurrent("/admin/statistiky") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/statistiky") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>▤</span> Statistiky <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 19V11M12 19V5M19 19v-7" />
</svg>
</span>
<span class="admin-nav-label">Statistiky</span>
</a> </a>
<a href="/admin/nastaveni" <a href="/admin/nastaveni" class="admin-nav-link @(IsCurrent("/admin/nastaveni") ? "active" : null)">
class="wj-nav-link @(IsCurrent("/admin/nastaveni") ? "active" : "")"> <span class="admin-nav-ico" aria-hidden="true">
<span>⚙</span> Nastavení <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3" />
<path d="M12 3.5v2.2M12 18.3v2.2M4.9 6.4l1.6 1.6M17.5 16l1.6 1.6M3.5 12h2.2M18.3 12h2.2M4.9 17.6l1.6-1.6M17.5 8l1.6-1.6" />
</svg>
</span>
<span class="admin-nav-label">Nastavení</span>
</a> </a>
</nav> </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 => "/" +
Nav.ToBaseRelativePath(Nav.Uri) Nav.ToBaseRelativePath(Nav.Uri)
@@ -91,4 +125,3 @@
Nav.LocationChanged -= HandleLocationChanged; Nav.LocationChanged -= HandleLocationChanged;
} }
} }

View File

@@ -1,23 +1,41 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
<div class="page"> <div class="page public-layout">
<div class="sidebar">
<a href="#public-main-content"
class="public-skip-link visually-hidden-focusable">
Přeskočit na hlavní obsah
</a>
<header class="sidebar public-header">
<NavMenu /> <NavMenu />
</div> </header>
<main> <main id="public-main-content"
<div class="top-row px-4"> class="main-content public-main"
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a> tabindex="-1">
</div>
<article class="content px-4"> <article class="content public-container">
@Body @Body
</article> </article>
</main> </main>
</div> </div>
<div id="blazor-error-ui" data-nosnippet> <div id="blazor-error-ui" data-nosnippet>
An unhandled error has occurred. <span role="alert">
<a href="." class="reload">Reload</a> Nastala neočekávaná chyba.
<span class="dismiss">🗙</span> </span>
<a href="." class="reload">
Obnovit stránku
</a>
<button type="button"
class="dismiss"
aria-label="Zavřít chybové hlášení"
style="background: none; border: none; color: inherit;">
&#215;
</button>
</div> </div>

View File

@@ -1,98 +1,406 @@
.page {
/* ========================================
SKOLNI JARMARK - PUBLIC LAYOUT
======================================== */
.page.public-layout {
--public-primary: #244b36;
--public-primary-hover: #193b29;
--public-secondary: #e6eddf;
--public-background: #f7f7f2;
--public-surface: #ffffff;
--public-text: #26372b;
--public-muted: #59665b;
--public-border: #dce3d9;
--public-radius-sm: 4px;
--public-radius-md: 8px;
--public-radius-lg: 12px;
--public-space-1: 4px;
--public-space-2: 8px;
--public-space-3: 12px;
--public-space-4: 16px;
--public-space-5: 20px;
--public-space-6: 24px;
--public-space-8: 32px;
--public-space-12: 48px;
--public-space-16: 64px;
position: relative; position: relative;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: stretch;
width: 100%;
min-width: 0;
min-height: 100vh;
min-height: 100dvh;
margin: 0;
padding: 0;
background: var(--public-background);
color: var(--public-text);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
font-size: 16px;
line-height: 1.6;
box-sizing: border-box;
} }
main {
flex: 1; /* ========================================
BOX SIZING
======================================== */
.public-layout,
.public-layout ::deep *,
.public-layout ::deep *::before,
.public-layout ::deep *::after {
box-sizing: border-box;
} }
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); /* ========================================
PUBLIC HEADER - OVERLAP FIX
======================================== */
.public-layout > .sidebar.public-header {
position: relative !important;
top: auto !important;
right: auto !important;
bottom: auto !important;
left: auto !important;
display: block;
flex: 0 0 auto;
align-self: stretch;
width: 100% !important;
min-width: 0 !important;
max-width: 100%;
height: auto !important;
min-height: 0 !important;
max-height: none;
margin: 0;
padding: 0;
background: var(--public-surface);
border-right: none !important;
border-bottom: 1px solid var(--public-border);
transform: none;
z-index: 100;
} }
.top-row {
background-color: #f7f7f7; /* ========================================
border-bottom: 1px solid #d6d5d5; NAVIGATION CONTAINER
justify-content: flex-end; ======================================== */
height: 3.5rem;
display: flex; .public-header ::deep .nav-panel {
align-items: center; position: relative;
width: 100%;
min-width: 0;
height: auto;
min-height: 68px;
max-height: none;
margin: 0 auto;
} }
.top-row ::deep a, .top-row ::deep .btn-link { .public-header ::deep .nav-scrollable {
position: static;
height: auto;
min-height: 0;
max-height: none;
overflow: visible;
}
/* ========================================
MAIN CONTENT - OVERLAP FIX
======================================== */
.public-layout > .main-content.public-main {
position: relative !important;
top: auto;
left: auto;
right: auto;
bottom: auto;
display: block;
flex: 1 0 auto;
width: 100% !important;
min-width: 0;
max-width: 100%;
height: auto;
min-height: 0;
margin: 0 !important;
padding: 0 !important;
background: var(--public-background);
transform: none;
scroll-margin-top: 16px;
}
/* ========================================
CONTENT CONTAINER
======================================== */
.public-main > .content.public-container {
position: relative;
display: block;
width: 100%;
max-width: 1440px;
min-width: 0;
margin: 0 auto !important;
padding: 32px 32px 64px !important;
box-sizing: border-box;
}
/* ========================================
TYPOGRAPHY
======================================== */
.public-container ::deep h1,
.public-container ::deep h2,
.public-container ::deep h3 {
color: var(--public-text);
font-family: Georgia, "Times New Roman", serif;
font-weight: 700;
line-height: 1.2;
letter-spacing: normal;
}
.public-container ::deep h1 {
font-size: clamp(28px, 4vw, 44px);
}
.public-container ::deep h2 {
font-size: clamp(24px, 3vw, 32px);
}
.public-container ::deep h3 {
font-size: clamp(18px, 2vw, 24px);
}
.public-container ::deep p {
line-height: 1.6;
}
/* ========================================
LINKS
======================================== */
.public-container ::deep a {
text-underline-offset: 3px;
}
/* ========================================
KEYBOARD ACCESSIBILITY
======================================== */
.public-layout ::deep a:focus-visible,
.public-layout ::deep button:focus-visible,
.public-layout ::deep input:focus-visible,
.public-layout ::deep select:focus-visible,
.public-layout ::deep textarea:focus-visible,
.public-layout ::deep [tabindex]:focus-visible {
outline: 3px solid #527b49;
outline-offset: 3px;
}
.public-main:focus-visible {
outline: 3px solid #527b49;
outline-offset: -3px;
}
/* ========================================
SKIP NAVIGATION LINK
======================================== */
.public-skip-link {
position: absolute;
top: 12px;
left: 12px;
z-index: 1100;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap; white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
} }
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover { .public-skip-link:focus {
width: auto;
height: auto;
padding: 12px 16px;
overflow: visible;
clip-path: none;
background: var(--public-primary);
color: #ffffff;
border-radius: var(--public-radius-md);
font-size: 14px;
font-weight: 600;
text-decoration: none;
white-space: normal;
}
/* ========================================
BLAZOR ERROR MESSAGE
======================================== */
#blazor-error-ui {
display: none;
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
width: 100%;
padding: 16px 56px 16px 24px;
background: #fff4d6;
color: #58451b;
border-top: 1px solid #e5d4a1;
box-sizing: border-box;
color-scheme: light;
font-size: 14px;
line-height: 1.5;
}
#blazor-error-ui .reload {
display: inline-block;
margin-left: 8px;
color: #244b36;
font-weight: 700;
text-decoration: underline; text-decoration: underline;
} }
.top-row ::deep a:first-child { #blazor-error-ui .dismiss {
overflow: hidden; position: absolute;
text-overflow: ellipsis; top: 50%;
right: 8px;
transform: translateY(-50%);
display: flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
padding: 0;
background: transparent;
color: #58451b;
border: none;
border-radius: 4px;
font-size: 24px;
cursor: pointer;
} }
@media (max-width: 640.98px) { #blazor-error-ui .dismiss:focus-visible,
.top-row { #blazor-error-ui .reload:focus-visible {
justify-content: space-between; outline: 3px solid #527b49;
outline-offset: 2px;
} }
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0; /* ========================================
TABLET - MAX 1024 PX
======================================== */
@media (max-width: 1024px) {
.public-main > .content.public-container {
padding: 24px 24px 48px !important;
}
.public-layout > .sidebar.public-header {
position: relative !important;
width: 100% !important;
height: auto !important;
min-height: 0 !important;
} }
} }
@media (min-width: 641px) {
.page { /* ========================================
flex-direction: row; MOBILE - MAX 640 PX
======================================== */
@media (max-width: 640px) {
.page.public-layout {
flex-direction: column;
width: 100%;
font-size: 15px;
} }
.sidebar { .public-layout > .sidebar.public-header {
width: 250px; position: relative !important;
height: 100vh; top: auto !important;
position: sticky; width: 100% !important;
top: 0; min-width: 0 !important;
height: auto !important;
min-height: 0 !important;
} }
.top-row { .public-layout > .main-content.public-main {
position: sticky; width: 100% !important;
top: 0; min-width: 0;
z-index: 1; margin: 0 !important;
padding: 0 !important;
} }
.top-row.auth ::deep a:first-child { .public-main > .content.public-container {
flex: 1; width: 100%;
text-align: right; padding: 16px 16px 32px !important;
width: 0;
} }
.top-row, article { .public-container ::deep h1 {
padding-left: 2rem !important; font-size: 28px;
padding-right: 1.5rem !important;
} }
.public-container ::deep h2 {
font-size: 24px;
}
.public-container ::deep h3 {
font-size: 20px;
} }
#blazor-error-ui { #blazor-error-ui {
color-scheme: light only; padding: 12px 56px 12px 16px;
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
box-sizing: border-box;
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
} }
#blazor-error-ui .dismiss { #blazor-error-ui .reload {
cursor: pointer; margin-left: 0;
position: absolute; margin-top: 4px;
right: 0.75rem; }
top: 0.5rem; }
/* ========================================
SMALL MOBILE - MAX 360 PX
======================================== */
@media (max-width: 360px) {
.public-main > .content.public-container {
padding: 12px 12px 24px !important;
}
.public-container ::deep h1 {
font-size: 26px;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@media (prefers-reduced-motion: reduce) {
.public-layout,
.public-layout ::deep *,
.public-layout ::deep *::before,
.public-layout ::deep *::after {
scroll-behavior: auto !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
} }

View File

@@ -1,82 +1,212 @@
@implements IDisposable
@implements IDisposable
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<div class="top-row ps-3 navbar navbar-dark"> <div class="nav-panel">
<div class="container-fluid">
<a class="navbar-brand" href="">Web-Jarmark</a> <div class="nav-brand-area">
</div> <a class="navbar-brand" href="/">
<svg class="brand-symbol"
width="32"
height="32"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.6"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M20 4C10 4 5 8 5 15
c0 3 2 5 5 5
C17 20 20 12 20 4Z" />
<path d="M3 22L15 10" />
</svg>
<span class="brand-text">
<strong>Školní jarmark</strong>
</span>
</a>
</div> </div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler" /> <input type="checkbox"
id="public-menu-toggle"
title="Navigační menu"
aria-label="Rozbalit nebo sbalit navigační menu"
aria-controls="public-navigation"
class="navbar-toggler" />
<div class="nav-scrollable"
id="public-navigation">
<nav class="nav public-nav-links"
aria-label="Hlavní navigace">
<div class="nav-item">
<NavLink class="nav-link"
href=""
Match="NavLinkMatch.All"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Katalog</span>
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="nav flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink> </NavLink>
</div> </div>
<div class="nav-item px-3"> <AuthorizeView Roles="Admin">
<NavLink class="nav-link" href="kosik">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Kosik
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="FF">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> FF
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="NovaObjednavka">
<span class="bi bi-lock-nav-menu" aria-hidden="true"></span> Nova objednavka
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="DetailObjednavky">
<span class="bi bi-lock-nav-menu" aria-hidden="true"></span> Detail objednavky
</NavLink>
</div>
<AuthorizeView>
<Authorized> <Authorized>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Manage"> <div class="nav-item">
<span class="bi bi-person-fill-nav-menu" aria-hidden="true"></span> @context.User.Identity?.Name <NavLink class="nav-link"
href="admin"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Administrace</span>
</NavLink> </NavLink>
</div> </div>
<div class="nav-item px-3">
<form action="Account/Logout" method="post">
<AntiforgeryToken />
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
<button type="submit" class="nav-link">
<span class="bi bi-arrow-bar-left-nav-menu" aria-hidden="true"></span> Logout
</button>
</form>
</div>
</Authorized> </Authorized>
<NotAuthorized>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Register">
<span class="bi bi-person-nav-menu" aria-hidden="true"></span> Register
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Login">
<span class="bi bi-person-badge-nav-menu" aria-hidden="true"></span> Login
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="admin">
<span class="bi bi-gear-nav-menu" aria-hidden="true"></span> Admin
</NavLink>
</div>
</NotAuthorized>
</AuthorizeView> </AuthorizeView>
</nav> </nav>
<div class="nav-bottom public-account-links">
<AuthorizeView>
<Authorized>
<div class="nav-item account-item">
<NavLink class="nav-link"
href="Account/Manage"
onclick="document.getElementById('public-menu-toggle').checked = false">
<svg class="nav-icon"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<circle cx="12"
cy="8"
r="4" />
<path d="M4 21v-2
a8 8 0 0 1 16 0
v2" />
</svg>
<span class="user-name">
@context.User.Identity?.Name
</span>
</NavLink>
</div>
<div class="nav-item">
<form action="Account/Logout"
method="post">
<AntiforgeryToken />
<input type="hidden"
name="ReturnUrl"
value="@currentUrl" />
<button type="submit"
class="nav-link logout-link">
<span>Odhlásit</span>
</button>
</form>
</div>
</Authorized>
<NotAuthorized>
<div class="nav-item">
<NavLink class="nav-link"
href="Account/Login"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Přihlášení</span>
</NavLink>
</div>
<div class="nav-item">
<NavLink class="nav-link"
href="Account/Register"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Registrace</span>
</NavLink>
</div>
</NotAuthorized>
</AuthorizeView>
<div class="nav-item cart-item">
<NavLink class="nav-link public-cart-link"
href="kosik"
onclick="document.getElementById('public-menu-toggle').checked = false">
<svg class="nav-icon"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M3 3h2l3.5 13h10
l3-10H6" />
<circle cx="10"
cy="20"
r="1" />
<circle cx="18"
cy="20"
r="1" />
</svg>
<span>Košík</span>
</NavLink>
</div>
</div>
</div>
</div> </div>
@code { @code {
@@ -84,14 +214,20 @@
protected override void OnInitialized() protected override void OnInitialized()
{ {
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri); currentUrl = NavigationManager.ToBaseRelativePath(
NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged; NavigationManager.LocationChanged += OnLocationChanged;
} }
private void OnLocationChanged(object? sender, LocationChangedEventArgs e) private void OnLocationChanged(
object? sender,
LocationChangedEventArgs e)
{ {
currentUrl = NavigationManager.ToBaseRelativePath(e.Location); currentUrl = NavigationManager.ToBaseRelativePath(
StateHasChanged(); e.Location);
_ = InvokeAsync(StateHasChanged);
} }
public void Dispose() public void Dispose()

View File

@@ -1,211 +1,522 @@
/* ========================================== /* ========================================
WEB JARMARK – MODERNÍ BOČNÍ NAVIGACE SKOLNI JARMARK - PUBLIC NAVIGATION
========================================== */ ======================================== */
.top-row { .nav-panel {
min-height: 76px; --nav-primary: #244b36;
--nav-primary-hover: #193b29;
--nav-secondary: #e6eddf;
--nav-text: #26372b;
--nav-muted: #59665b;
--nav-border: #dce3d9;
--nav-surface: #ffffff;
position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
padding: 0 24px !important; gap: 32px;
background: linear-gradient(135deg, #10233f, #183d68); width: 100%;
border-bottom: 1px solid rgba(255, 255, 255, .08); max-width: 1440px;
min-width: 0;
min-height: 76px;
margin: 0 auto;
padding: 12px 32px;
background: var(--nav-surface);
color: var(--nav-text);
box-sizing: border-box;
}
/* ========================================
BRAND
======================================== */
.nav-brand-area {
display: flex;
align-items: center;
flex-shrink: 0;
min-width: 0;
} }
.navbar-brand { .navbar-brand {
color: #ffffff !important; display: inline-flex;
font-size: 21px; align-items: center;
font-weight: 800; gap: 8px;
letter-spacing: -.5px; min-height: 44px;
transition: color .25s ease; margin: 0;
padding: 0;
color: var(--nav-primary);
text-decoration: none;
} }
.navbar-brand:hover { .navbar-brand:hover {
color: #8fc5ff !important; color: var(--nav-primary-hover);
} }
/* Pozadí navigace */ .brand-symbol {
display: block;
width: 32px;
height: 32px;
flex-shrink: 0;
color: var(--nav-primary);
}
.brand-text {
display: block;
}
.brand-text strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 700;
line-height: 1.2;
letter-spacing: normal;
white-space: nowrap;
}
/* ========================================
NAVIGATION STRUCTURE
======================================== */
.nav-scrollable { .nav-scrollable {
background: linear-gradient(180deg, #142b4a 0%, #10223b 100%); display: flex;
min-height: calc(100vh - 76px); align-items: center;
padding: 22px 13px; justify-content: space-between;
flex: 1;
gap: 16px;
min-width: 0;
}
.public-nav-links {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 4px;
margin: 0;
padding: 0;
}
.public-account-links {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
flex-wrap: wrap;
gap: 8px;
min-width: 0;
margin: 0 0 0 auto;
padding: 0;
} }
/* Položky menu */
.nav-item { .nav-item {
display: block;
min-width: 0;
margin: 0;
padding: 0;
font-size: 14px; font-size: 14px;
font-weight: 600; font-weight: 600;
margin-bottom: 7px;
} }
/* Odkazy */
/* ========================================
NAVIGATION LINKS
======================================== */
.nav-item ::deep .nav-link { .nav-item ::deep .nav-link {
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
width: 100%; justify-content: flex-start;
min-height: 49px; gap: 8px;
padding: 0 16px; min-height: 44px;
margin: 0;
padding: 8px 12px;
border: 1px solid transparent; border: 1px solid transparent;
border-radius: 12px; border-radius: 6px;
background: transparent; background: transparent;
color: #b9c9dc; color: var(--nav-muted);
font-family: inherit;
font-size: 14px;
font-weight: 600;
line-height: 1.4;
text-align: left;
text-decoration: none; text-decoration: none;
line-height: normal; white-space: nowrap;
transition: background .25s ease, color .25s ease, border-color .25s ease, transform .25s ease, box-shadow .25s ease; transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
} }
/* Hover efekt */
.nav-item ::deep .nav-link:hover { .nav-item ::deep .nav-link:hover {
color: #ffffff; background: #f1f4ef;
background: rgba(255, 255, 255, .09); color: var(--nav-primary);
border-color: rgba(255, 255, 255, .08); text-decoration: none;
transform: translateX(4px);
} }
/* Aktivní stránka */ .nav-item ::deep a.nav-link.active {
.nav-item ::deep a.active { background: var(--nav-secondary);
color: #ffffff; color: var(--nav-primary);
background: linear-gradient( 100deg, rgba(40, 130, 235, .32), rgba(40, 130, 235, .12) ); border-color: #dce5d7;
border-color: rgba(105, 175, 255, .25); font-weight: 700;
box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
} }
/* Modrý indikátor aktivní stránky */
.nav-item ::deep a.active::before {
content: "";
position: absolute;
left: -13px;
top: 10px;
bottom: 10px;
width: 3px;
border-radius: 0 5px 5px 0;
background: #58a6ff;
}
/* Ikony */ /* ========================================
.nav-item ::deep .bi { ICONS
width: 21px; ======================================== */
height: 21px;
margin-right: 13px; .nav-icon {
display: block;
width: 20px;
height: 20px;
flex-shrink: 0; flex-shrink: 0;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
opacity: .85;
transition: transform .25s ease, opacity .25s ease;
} }
.nav-item ::deep .nav-link:hover .bi,
.nav-item ::deep a.active .bi { /* ========================================
opacity: 1; USER ACCOUNT
transform: scale(1.08); ======================================== */
.account-item {
min-width: 0;
max-width: 200px;
}
.user-name {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
} }
/* Odhlášení */
.nav-item ::deep form { .nav-item ::deep form {
width: 100%; margin: 0;
padding: 0;
} }
.nav-item ::deep button.nav-link { .nav-item ::deep button.nav-link {
text-align: left; width: 100%;
font-family: inherit; font-family: inherit;
font-size: inherit;
cursor: pointer; cursor: pointer;
} }
/* Mobilní tlačítko */ .nav-item ::deep .logout-link {
color: #8b4038;
}
.nav-item ::deep .logout-link:hover {
background: #fbefed;
color: #74342d;
border-color: #efd8d4;
}
/* ========================================
SHOPPING CART - PRIMARY ACTION
======================================== */
.cart-item {
margin-left: 4px;
}
.cart-item ::deep .public-cart-link {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 44px;
padding: 10px 20px;
border: 1px solid var(--nav-primary);
border-radius: 6px;
background: var(--nav-primary);
color: #ffffff;
font-weight: 700;
}
.cart-item ::deep .public-cart-link:hover {
background: var(--nav-primary-hover);
border-color: var(--nav-primary-hover);
color: #ffffff;
}
.cart-item ::deep a.public-cart-link.active {
background: var(--nav-primary-hover);
border-color: var(--nav-primary-hover);
color: #ffffff;
text-decoration: underline;
text-underline-offset: 4px;
}
/* ========================================
KEYBOARD ACCESSIBILITY
======================================== */
.navbar-brand:focus-visible,
.navbar-toggler:focus-visible,
.nav-panel ::deep .nav-link:focus-visible {
outline: 3px solid #527b49;
outline-offset: 3px;
box-shadow: none;
}
/* ========================================
MOBILE MENU TOGGLE
======================================== */
.navbar-toggler { .navbar-toggler {
appearance: none;
width: 43px;
height: 39px;
position: absolute;
top: 18px;
right: 16px;
border: 1px solid rgba(255, 255, 255, .2);
border-radius: 10px;
background-color: rgba(255, 255, 255, .08);
cursor: pointer;
transition: background .2s ease;
}
.navbar-toggler:hover,
.navbar-toggler:checked {
background-color: rgba(255, 255, 255, .18);
}
/* Plynulé otevření menu na mobilu */
.nav-scrollable {
overflow: hidden;
}
.navbar-toggler:not(:checked) ~ .nav-scrollable {
display: none; display: none;
appearance: none;
-webkit-appearance: none;
position: absolute;
top: 12px;
right: 24px;
width: 44px;
height: 44px;
margin: 0;
padding: 0;
border: 1px solid var(--nav-border);
border-radius: 6px;
background: var(--nav-surface);
color: var(--nav-primary);
cursor: pointer;
box-sizing: border-box;
}
.navbar-toggler::before,
.navbar-toggler::after {
content: "";
position: absolute;
left: 11px;
width: 20px;
height: 2px;
background: currentColor;
border-radius: 1px;
}
.navbar-toggler::before {
top: 14px;
box-shadow: 0 6px 0 currentColor;
}
.navbar-toggler::after {
top: 26px;
}
.navbar-toggler:checked {
background: var(--nav-secondary);
}
.navbar-toggler:checked::before {
top: 20px;
transform: rotate(45deg);
box-shadow: none;
}
.navbar-toggler:checked::after {
top: 20px;
transform: rotate(-45deg);
}
.navbar-toggler:hover {
background-color: var(--nav-secondary);
}
/* ========================================
COMPACT DESKTOP
======================================== */
@media (max-width: 1200px) {
.nav-panel {
gap: 16px;
padding: 12px 24px;
}
.brand-text strong {
font-size: 21px;
}
.public-account-links {
gap: 4px;
}
.nav-item ::deep .nav-link {
padding: 8px 12px;
}
.cart-item ::deep .public-cart-link {
padding: 10px 16px;
}
.account-item {
max-width: 160px;
}
}
/* ========================================
TABLET AND MOBILE
======================================== */
@media (max-width: 1024px) {
.nav-panel {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 0;
min-height: 68px;
padding: 0;
}
.nav-brand-area {
display: flex;
align-items: center;
min-height: 68px;
padding: 12px 84px 12px 24px;
}
.navbar-toggler {
display: block;
}
.nav-scrollable {
display: none;
flex-direction: column;
align-items: stretch;
gap: 16px;
width: 100%;
padding: 16px 24px 24px;
border-top: 1px solid var(--nav-border);
} }
.navbar-toggler:checked ~ .nav-scrollable { .navbar-toggler:checked ~ .nav-scrollable {
display: block; display: flex;
animation: menuEnter .28s ease both;
} }
@keyframes menuEnter { .public-nav-links {
from { display: flex;
opacity: 0; flex-direction: column;
transform: translateY(-8px); align-items: stretch;
gap: 4px;
width: 100%;
} }
to { .public-account-links {
opacity: 1; display: flex;
transform: translateY(0); flex-direction: column;
} align-items: stretch;
} gap: 4px;
width: 100%;
/* Scrollbar */ margin: 0;
.nav-scrollable::-webkit-scrollbar { padding-top: 16px;
width: 5px; border-top: 1px solid var(--nav-border);
}
.nav-scrollable::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, .2);
border-radius: 10px;
}
/* Desktop */
@media (min-width: 641px) {
.navbar-toggler {
display: none;
}
.nav-scrollable {
display: block !important;
height: calc(100vh - 76px);
overflow-y: auto;
}
}
/* Menší displeje */
@media (max-width: 640px) {
.top-row {
min-height: 70px;
}
.nav-scrollable {
min-height: auto;
padding: 12px;
} }
.nav-item { .nav-item {
margin-bottom: 5px; width: 100%;
}
.nav-item ::deep .nav-link {
width: 100%;
min-height: 48px;
padding: 12px 16px;
font-size: 15px;
}
.account-item {
max-width: none;
}
.cart-item {
margin: 12px 0 0;
}
.cart-item ::deep .public-cart-link {
width: 100%;
min-height: 48px;
justify-content: center;
} }
} }
/* ========================================
MOBILE - MAX 640 PX
======================================== */
@media (max-width: 640px) {
.nav-brand-area {
padding: 12px 76px 12px 16px;
}
.navbar-toggler {
right: 16px;
}
.brand-symbol {
width: 28px;
height: 28px;
}
.brand-text strong {
font-size: 20px;
}
.nav-scrollable {
padding: 12px 16px 20px;
}
}
/* ========================================
SMALL MOBILE
======================================== */
@media (max-width: 360px) {
.brand-text strong {
font-size: 18px;
}
.brand-symbol {
width: 24px;
height: 24px;
}
.navbar-brand {
gap: 8px;
}
.nav-brand-area {
padding-left: 12px;
padding-right: 68px;
}
.navbar-toggler {
right: 12px;
}
.nav-scrollable {
padding: 12px 12px 16px;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
.nav-item ::deep .nav-link,
.nav-item ::deep .bi {
transition: none;
}
.navbar-toggler:checked ~ .nav-scrollable { .navbar-brand,
animation: none; .navbar-toggler,
.nav-panel ::deep .nav-link {
transition: none !important;
animation: none !important;
} }
} }

View File

@@ -7,257 +7,350 @@
@using Web_Jarmark.Data.Models @using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db @inject ApplicationDbContext Db
@attribute [Authorize] @attribute [Authorize(Roles = "Admin")]
<PageTitle>Přehled administrace</PageTitle> <PageTitle>Přehled administrace</PageTitle>
<div class="wj-page-heading"> <div class="dash">
<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="ao-loading">Načítám přehled…</div>
}
else if (!string.IsNullOrEmpty(error))
{
<div class="ao-alert">@error</div>
} }
else else
{ {
<div class="wj-stats-grid"> <header class="dash-hero">
<div class="wj-stat-card">
<div class="wj-stat-top">
<span class="wj-stat-icon">↗</span>
<span class="wj-stat-caption">KATALOG</span>
</div>
<div class="wj-stat-label">Celkem produktů</div>
<div class="wj-stat-value">@productCount</div>
<div class="wj-stat-foot">Všechny produkty v obchodě</div>
</div>
<div class="wj-stat-card">
<div class="wj-stat-top">
<span class="wj-stat-icon">▤</span>
<span class="wj-stat-caption">SORTIMENT</span>
</div>
<div class="wj-stat-label">Počet kategorií</div>
<div class="wj-stat-value">@categoryCount</div>
<div class="wj-stat-foot">Kategorie vašeho zboží</div>
</div>
<div class="wj-stat-card">
<div class="wj-stat-top">
<span class="wj-stat-icon">◉</span>
<span class="wj-stat-caption">E-SHOP</span>
</div>
<div class="wj-stat-label">Viditelné produkty</div>
<div class="wj-stat-value">@visibleCount</div>
<div class="wj-stat-foot">Produkty dostupné v katalogu</div>
</div>
<div class="wj-stat-card">
<div class="wj-stat-top">
<span class="wj-stat-icon">!</span>
<span class="wj-stat-caption">SKLAD</span>
</div>
<div class="wj-stat-label">Dochází skladem</div>
<div class="wj-stat-value">@lowStockCount</div>
<div class="wj-stat-foot">Produkty s 5 nebo méně kusy</div>
</div>
</div>
<div class="wj-middle-grid">
<section class="wj-panel">
<div class="wj-panel-heading">
<div> <div>
<h2>Produkty podle kategorií</h2> <p class="dash-eyebrow">Web-Jarmark</p>
<p>Rozložení vašeho sortimentu</p> <h1>Přehled</h1>
<p class="dash-sub">Aktuální stav obchodu na jednom místě.</p>
</div> </div>
<a href="/admin/kategorie" class="wj-text-link">Kategorie ↗</a> <div class="dash-hero-actions">
<a class="ap-btn ap-btn-primary" href="/admin/objednavky">Objednávky</a>
<a class="ap-btn" href="/admin/zbozi">Zboží</a>
<a class="ap-btn" href="/admin/sklad">Sklad</a>
</div> </div>
</header>
@if (categoryStats.Count == 0) <section class="dash-kpis">
{ <article class="dash-kpi" style="--i:0">
<div class="wj-empty">Zatím nemáte žádné kategorie.</div> <span>Objednávky</span>
} <strong class="dash-count">@orderCount</strong>
else <small>@pendingCount čeká na platbu</small>
{ </article>
<div class="wj-category-list"> <article class="dash-kpi" style="--i:1">
@foreach (var category in categoryStats) <span>Tržby</span>
{ <strong class="dash-count">@revenue.ToString("N0")</strong>
<div class="wj-category-item"> <small>Kč uhrazené / dokončené</small>
<div class="wj-category-info"> </article>
<span>@category.Name</span> <article class="dash-kpi" style="--i:2">
<strong>@category.ProductCount</strong> <span>Produkty</span>
</div> <strong class="dash-count">@productCount</strong>
<div class="wj-progress"> <small>@visibleCount viditelných</small>
<div class="wj-progress-fill" </article>
style="@($"width: {GetWidth(category.ProductCount)}%")"> <article class="dash-kpi" style="--i:3">
</div> <span>Sklad</span>
</div> <strong class="dash-count">@stockUnits</strong>
</div> <small>@stockValue.ToString("N0") Kč hodnota</small>
} </article>
</div> <article class="dash-kpi" style="--i:4">
} <span>Nízký sklad</span>
<strong class="dash-count">@lowStockCount</strong>
<small>≤ 5 ks</small>
</article>
<article class="dash-kpi" style="--i:5">
<span>Kategorie</span>
<strong class="dash-count">@categoryCount</strong>
<small>@activeCategoryCount aktivních</small>
</article>
</section> </section>
<section class="wj-panel"> <section class="dash-row-3">
<div class="wj-panel-heading"> <article class="dash-card" style="--i:6">
<div class="dash-card-head">
<h2>Viditelnost</h2>
<p>Katalog v e-shopu</p>
</div>
<div class="dash-stack">
<div class="dash-stack-top">
<strong>@productCount</strong>
<span>produktů celkem</span>
</div>
<div class="dash-progress">
<div class="dash-progress-fill is-dark" style="width:@visPercent%"></div>
</div>
<div class="dash-split">
<div class="dash-split-item">
<span class="dash-dot is-on"></span>
<div> <div>
<strong>@visibleCount</strong>
<small>Viditelné</small>
</div>
</div>
<div class="dash-split-item">
<span class="dash-dot is-off"></span>
<div>
<strong>@hiddenCount</strong>
<small>Skryté</small>
</div>
</div>
</div>
</div>
</article>
<article class="dash-card" style="--i:7">
<div class="dash-card-head">
<h2>Stav skladu</h2>
<p>Produkty podle zásob</p>
</div>
<div class="dash-stack">
<div class="dash-stack-top">
<strong>@stockUnits</strong>
<span>ks na skladě · @stockValue.ToString("N0") Kč</span>
</div>
<div class="dash-progress dash-progress-multi">
<div class="dash-progress-fill is-dark" style="width:@okPercent%"></div>
<div class="dash-progress-fill is-mid" style="width:@lowPercent%"></div>
<div class="dash-progress-fill is-light" style="width:@outPercent%"></div>
</div>
<div class="dash-split three">
<div class="dash-split-item">
<span class="dash-dot is-on"></span>
<div>
<strong>@okStockCount</strong>
<small>V pořádku</small>
</div>
</div>
<div class="dash-split-item">
<span class="dash-dot is-mid"></span>
<div>
<strong>@lowStockCount</strong>
<small>Nízký</small>
</div>
</div>
<div class="dash-split-item">
<span class="dash-dot is-off"></span>
<div>
<strong>@outOfStockCount</strong>
<small>Prázdný</small>
</div>
</div>
</div>
</div>
</article>
<article class="dash-card" style="--i:8">
<div class="dash-card-head">
<h2>Objednávky</h2>
<p>Podle stavu</p>
</div>
<div class="dash-bars">
@foreach (var b in orderBars)
{
<div class="dash-bar-row">
<div class="dash-bar-label">
<span>@b.Label</span>
<strong>@b.Count</strong>
</div>
<div class="dash-bar-track">
<div class="dash-bar-fill" style="width:@b.Percent%"></div>
</div>
</div>
}
</div>
</article>
</section>
<section class="dash-row-2">
<article class="dash-card" style="--i:9">
<div class="dash-card-head">
<h2>Rychlé akce</h2> <h2>Rychlé akce</h2>
<p>Nejčastější úkony v administraci</p> <p>Nejčastější správa</p>
</div> </div>
<div class="dash-actions">
<a class="dash-action" href="/admin/objednavky"><strong>Objednávky</strong><span>@pendingCount čeká</span></a>
<a class="dash-action" href="/admin/zbozi"><strong>Zboží</strong><span>@productCount produktů</span></a>
<a class="dash-action" href="/admin/sklad"><strong>Sklad</strong><span>@lowStockCount nízký</span></a>
<a class="dash-action" href="/admin/kategorie"><strong>Kategorie</strong><span>@categoryCount položek</span></a>
<a class="dash-action" href="/admin/statistiky"><strong>Statistiky</strong><span>detailní přehled</span></a>
<a class="dash-action" href="/admin/administratori"><strong>Uživatelé</strong><span>správa účtů</span></a>
</div> </div>
</article>
<div class="wj-actions"> <article class="dash-card" style="--i:10">
<a href="/admin/zbozi/edit" class="wj-action"> <div class="dash-card-head">
<span class="wj-action-icon">+</span> <h2>Pozor na sklad</h2>
<span> <p>Nízký stav a vyprodané</p>
<strong>Přidat nové zboží</strong>
<small>Vytvořit nový produkt</small>
</span>
<span class="wj-action-arrow">→</span>
</a>
<a href="/admin/kategorie/edit" class="wj-action">
<span class="wj-action-icon">▤</span>
<span>
<strong>Nová kategorie</strong>
<small>Rozšířit nabídku kategorií</small>
</span>
<span class="wj-action-arrow">→</span>
</a>
<a href="/admin/zbozi" class="wj-action">
<span class="wj-action-icon">◇</span>
<span>
<strong>Spravovat zboží</strong>
<small>Upravit nebo skrýt produkty</small>
</span>
<span class="wj-action-arrow">→</span>
</a>
</div> </div>
</section> @if (attentionProducts.Count == 0)
{
</div> <div class="dash-empty">Všechny produkty mají dostatek kusů.</div>
}
<section class="wj-panel wj-products-panel"> else
<div class="wj-panel-heading"> {
<div class="dash-mini-list">
@foreach (var p in attentionProducts)
{
<a class="dash-mini-item" href="@($"/admin/zbozi/edit/{p.Id}")">
<div> <div>
<h2>Přehled produktů</h2> <strong>@p.Name</strong>
<p>Ukázka produktů z vašeho katalogu</p> <span>@p.CategoryName</span>
</div> </div>
<a href="/admin/zbozi" class="wj-text-link">Zobrazit vše →</a> <span class="ao-badge @(p.StockQuantity <= 0 ? "is-cancel" : "is-pending")">
@p.StockQuantity ks
</span>
</a>
}
</div>
}
</article>
</section>
<section class="dash-card" style="--i:11">
<div class="dash-card-head row">
<div>
<h2>Poslední objednávky</h2>
<p>Nejnovějších 8</p>
</div>
<a class="ap-btn ap-btn-ghost" href="/admin/objednavky">Všechny</a>
</div> </div>
@if (productPreview.Count == 0) @if (recentOrders.Count == 0)
{ {
<div class="wj-empty">Zatím nemáte žádné produkty.</div> <div class="dash-empty">Zatím žádné objednávky.</div>
} }
else else
{ {
<div class="wj-table-wrap"> <div class="dash-orders">
<table class="wj-table"> @foreach (var o in recentOrders)
<thead>
<tr>
<th>Produkt</th>
<th>Kategorie</th>
<th>Cena</th>
<th>Skladem</th>
<th>Stav</th>
</tr>
</thead>
<tbody>
@foreach (var product in productPreview)
{ {
<tr> <article class="dash-order" style="--i:@o.Index">
<td class="wj-product-name">@product.Name</td> <div>
<td>@product.CategoryName</td> <strong>#@o.Code</strong>
<td class="wj-price">@product.Price.ToString("N2") Kč</td> <span>@o.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")</span>
<td>@product.StockQuantity ks</td> </div>
<td> <div class="dash-order-mid">
@if (product.IsVisible) @(string.IsNullOrWhiteSpace(o.CustomerName) ? "—" : o.CustomerName)
{ </div>
<span class="wj-pill">Viditelné</span> <div class="dash-order-right">
<strong>@o.TotalAmount.ToString("N0") Kč</strong>
<span class="ao-badge @StatusBadge(o.Status)">@StatusText(o.Status)</span>
</div>
</article>
} }
else
{
<span class="wj-pill wj-pill-muted">Skryté</span>
}
</td>
</tr>
}
</tbody>
</table>
</div> </div>
} }
</section> </section>
} }
</div>
@code { @code {
private bool loading = true; private bool loading = true;
private string? error;
private int productCount; private int productCount, visibleCount, hiddenCount, categoryCount, activeCategoryCount;
private int categoryCount; private int stockUnits, lowStockCount, outOfStockCount, okStockCount;
private int visibleCount; private int orderCount, pendingCount, paidCount, shippedCount, deliveredCount, cancelledCount;
private int lowStockCount; private decimal revenue, stockValue;
private List<CategoryStat> categoryStats = new(); private int visPercent, okPercent, lowPercent, outPercent;
private List<ProductPreview> productPreview = new();
private List<BarItem> orderBars = new();
private List<RecentOrder> recentOrders = new();
private List<AttentionProduct> attentionProducts = new();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
productCount = await Db.Set<Product>().CountAsync(); try
categoryCount = await Db.Set<Category>().CountAsync(); {
visibleCount = await Db.Set<Product>().CountAsync(p => p.IsVisible); var products = await Db.Products.AsNoTracking().Include(p => p.Category).ToListAsync();
lowStockCount = await Db.Set<Product>().CountAsync(p => p.StockQuantity <= 5); productCount = products.Count;
visibleCount = products.Count(p => p.IsVisible);
hiddenCount = productCount - visibleCount;
stockUnits = products.Sum(p => p.StockQuantity);
stockValue = products.Sum(p => p.Price * p.StockQuantity);
lowStockCount = products.Count(p => p.StockQuantity > 0 && p.StockQuantity <= 5);
outOfStockCount = products.Count(p => p.StockQuantity <= 0);
okStockCount = products.Count(p => p.StockQuantity > 5);
var categories = await Db.Set<Category>() categoryCount = await Db.Categories.CountAsync();
.AsNoTracking() activeCategoryCount = await Db.Categories.CountAsync(c => c.IsActive);
.Include(c => c.Products)
.OrderBy(c => c.Name)
.ToListAsync();
categoryStats = categories var orders = await Db.Orders.AsNoTracking().ToListAsync();
.Select(c => new CategoryStat(c.Name, c.Products.Count)) orderCount = orders.Count;
pendingCount = orders.Count(o => o.Status == OrderStatus.Pending);
paidCount = orders.Count(o => o.Status == OrderStatus.Paid);
shippedCount = orders.Count(o => o.Status == OrderStatus.Shipped);
deliveredCount = orders.Count(o => o.Status == OrderStatus.Delivered);
cancelledCount = orders.Count(o => o.Status == OrderStatus.Cancelled);
revenue = orders
.Where(o => o.Status is OrderStatus.Paid or OrderStatus.Shipped or OrderStatus.Delivered)
.Sum(o => o.TotalAmount);
visPercent = productCount == 0 ? 0 : (int)Math.Round(100.0 * visibleCount / productCount);
okPercent = productCount == 0 ? 0 : (int)Math.Round(100.0 * okStockCount / productCount);
lowPercent = productCount == 0 ? 0 : (int)Math.Round(100.0 * lowStockCount / productCount);
outPercent = productCount == 0 ? 0 : Math.Max(0, 100 - okPercent - lowPercent);
var total = Math.Max(orderCount, 1);
orderBars = new List<BarItem>
{
new("Čeká na zaplacení", pendingCount, pendingCount * 100 / total),
new("Zaplaceno", paidCount, paidCount * 100 / total),
new("Odesláno", shippedCount, shippedCount * 100 / total),
new("Dokončeno", deliveredCount, deliveredCount * 100 / total),
new("Zrušeno", cancelledCount, cancelledCount * 100 / total),
};
recentOrders = orders
.OrderByDescending(o => o.CreatedAt)
.Take(8)
.Select((o, idx) => new RecentOrder(o.Code, o.CustomerName, o.TotalAmount, o.Status, o.CreatedAt, idx))
.ToList(); .ToList();
productPreview = await Db.Set<Product>() attentionProducts = products
.AsNoTracking() .Where(p => p.StockQuantity <= 5)
.OrderBy(p => p.Name) .OrderBy(p => p.StockQuantity)
.Take(5) .ThenBy(p => p.Name)
.Select(p => new ProductPreview( .Take(8)
p.Name, .Select(p => new AttentionProduct(p.Id, p.Name, p.Category?.Name ?? "—", p.StockQuantity))
p.Category.Name, .ToList();
p.Price, }
p.StockQuantity, catch (Exception ex)
p.IsVisible)) {
.ToListAsync(); error = "Přehled se nepodařilo načíst: " + ex.Message;
}
finally
{
loading = false; loading = false;
} }
}
private int GetWidth(int count) private static string StatusText(OrderStatus s) => s switch
{ {
var max = categoryStats.Count == 0 ? 1 : categoryStats.Max(c => c.ProductCount); OrderStatus.Pending => "Čeká",
return count == 0 ? 0 : Math.Max(5, (int)Math.Round(count * 100.0 / Math.Max(1, max))); OrderStatus.Paid => "Zaplaceno",
} OrderStatus.Shipped => "Odesláno",
OrderStatus.Delivered => "Dokončeno",
OrderStatus.Cancelled => "Zrušeno",
_ => "?"
};
private record CategoryStat(string Name, int ProductCount); private static string StatusBadge(OrderStatus s) => s switch
{
OrderStatus.Pending => "is-pending",
OrderStatus.Paid => "is-paid",
OrderStatus.Shipped => "is-shipped",
OrderStatus.Delivered => "is-done",
OrderStatus.Cancelled => "is-cancel",
_ => ""
};
private record ProductPreview( private sealed record BarItem(string Label, int Count, int Percent);
string Name, private sealed record RecentOrder(string Code, string CustomerName, decimal TotalAmount, OrderStatus Status, DateTime CreatedAt, int Index);
string CategoryName, private sealed record AttentionProduct(int Id, string Name, string CategoryName, int StockQuantity);
decimal Price,
int StockQuantity,
bool IsVisible);
} }

View File

@@ -0,0 +1,498 @@
/* Plná šířka dashboard */
.dash {
width: 100%;
max-width: none;
margin: 0;
color: #1d1d1f;
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
.dash-hero {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
flex-wrap: wrap;
padding: 4px 2px 22px;
animation: dash-in 0.45s ease both;
}
.dash-eyebrow {
margin: 0 0 6px;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #6e6e73;
}
.dash-hero h1 {
margin: 0;
font-size: 34px;
font-weight: 750;
letter-spacing: -0.03em;
}
.dash-sub {
margin: 8px 0 0;
color: #6e6e73;
font-size: 15px;
}
.dash-hero-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.dash-kpis {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
gap: 12px;
margin-bottom: 14px;
}
.dash-kpi {
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.05);
border-radius: 22px;
padding: 16px 14px;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.04);
animation: dash-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.05s);
transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.dash-kpi:hover {
transform: translateY(-3px);
box-shadow: 0 16px 36px rgba(0, 0, 0, 0.07);
}
.dash-kpi span {
display: block;
font-size: 12px;
font-weight: 650;
color: #6e6e73;
}
.dash-kpi strong.dash-count {
display: block;
margin-top: 8px;
font-size: 26px;
font-weight: 750;
letter-spacing: -0.03em;
line-height: 1;
animation: dash-pop 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.05s + 0.1s);
}
.dash-kpi small {
display: block;
margin-top: 8px;
font-size: 11px;
color: #86868b;
}
.dash-row-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
margin-bottom: 12px;
}
.dash-row-2 {
display: grid;
grid-template-columns: 1.2fr 0.8fr;
gap: 12px;
margin-bottom: 12px;
}
.dash-card {
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.05);
border-radius: 24px;
padding: 18px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
animation: dash-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.05s);
}
.dash-card-head {
margin-bottom: 14px;
}
.dash-card-head.row {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
}
.dash-card-head h2 {
margin: 0;
font-size: 17px;
font-weight: 700;
letter-spacing: -0.02em;
}
.dash-card-head p {
margin: 4px 0 0;
font-size: 13px;
color: #6e6e73;
}
/* Progress verze místo donutů */
.dash-stack {
display: flex;
flex-direction: column;
gap: 16px;
}
.dash-stack-top strong {
display: block;
font-size: 28px;
font-weight: 750;
letter-spacing: -0.03em;
line-height: 1;
}
.dash-stack-top span {
display: block;
margin-top: 6px;
font-size: 13px;
color: #6e6e73;
}
.dash-progress {
height: 12px;
border-radius: 999px;
background: #f0f0f2;
overflow: hidden;
}
.dash-progress-multi {
display: flex;
background: #f0f0f2;
}
.dash-progress-fill {
height: 100%;
border-radius: 999px;
transform-origin: left center;
animation: dash-bar 0.85s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.dash-progress-multi .dash-progress-fill {
border-radius: 0;
}
.dash-progress-multi .dash-progress-fill:first-child {
border-radius: 999px 0 0 999px;
}
.dash-progress-multi .dash-progress-fill:last-child {
border-radius: 0 999px 999px 0;
}
.dash-progress-fill.is-dark {
background: #1d1d1f;
}
.dash-progress-fill.is-mid {
background: #8e8e93;
}
.dash-progress-fill.is-light {
background: #d2d2d7;
}
.dash-split {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.dash-split.three {
grid-template-columns: 1fr 1fr 1fr;
}
.dash-split-item {
display: flex;
align-items: flex-start;
gap: 8px;
padding: 12px;
border-radius: 14px;
background: #f5f5f7;
}
.dash-split-item strong {
display: block;
font-size: 18px;
font-weight: 750;
line-height: 1.1;
}
.dash-split-item small {
display: block;
margin-top: 3px;
font-size: 12px;
color: #6e6e73;
}
.dash-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #e8e8ed;
flex-shrink: 0;
margin-top: 4px;
}
.dash-dot.is-on {
background: #1d1d1f;
}
.dash-dot.is-mid {
background: #8e8e93;
}
.dash-dot.is-off {
background: #e8e8ed;
border: 1px solid #d2d2d7;
}
.dash-bars {
display: flex;
flex-direction: column;
gap: 12px;
}
.dash-bar-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font-size: 12px;
color: #6e6e73;
}
.dash-bar-label strong {
color: #1d1d1f;
}
.dash-bar-track {
height: 8px;
border-radius: 999px;
background: #f0f0f2;
overflow: hidden;
}
.dash-bar-fill {
height: 100%;
border-radius: 999px;
background: #1d1d1f;
transform-origin: left center;
animation: dash-bar 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.dash-actions {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
}
.dash-action {
display: flex;
flex-direction: column;
gap: 4px;
padding: 14px;
border-radius: 16px;
background: #f5f5f7;
text-decoration: none;
color: inherit;
transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.dash-action:hover {
background: #fff;
transform: translateY(-2px);
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
color: inherit;
}
.dash-action strong {
font-size: 14px;
font-weight: 700;
}
.dash-action span {
font-size: 12px;
color: #6e6e73;
}
.dash-mini-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.dash-mini-item {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
padding: 12px 14px;
border-radius: 14px;
background: #f5f5f7;
text-decoration: none;
color: inherit;
transition: background 0.2s ease, transform 0.15s ease;
}
.dash-mini-item:hover {
background: #ececee;
transform: translateX(2px);
color: inherit;
}
.dash-mini-item strong {
display: block;
font-size: 13px;
}
.dash-mini-item span {
font-size: 12px;
color: #6e6e73;
}
.dash-empty {
padding: 18px;
text-align: center;
color: #6e6e73;
font-size: 14px;
}
.dash-orders {
display: flex;
flex-direction: column;
gap: 8px;
}
.dash-order {
display: grid;
grid-template-columns: 1.2fr 1fr auto;
gap: 12px;
align-items: center;
padding: 14px 16px;
border-radius: 16px;
background: #f7f7f8;
animation: dash-rise 0.45s ease both;
animation-delay: calc(var(--i, 0) * 0.04s);
transition: background 0.2s ease, transform 0.15s ease;
}
.dash-order:hover {
background: #f0f0f2;
transform: translateX(2px);
}
.dash-order strong {
display: block;
font-size: 14px;
}
.dash-order span {
font-size: 12px;
color: #6e6e73;
}
.dash-order-mid {
font-size: 13px;
color: #6e6e73;
}
.dash-order-right {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4px;
}
@keyframes dash-in {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes dash-rise {
from {
opacity: 0;
transform: translateY(16px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes dash-pop {
from {
opacity: 0;
transform: scale(0.92);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes dash-bar {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
@media (max-width: 1200px) {
.dash-kpis {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.dash-row-3 {
grid-template-columns: 1fr;
}
.dash-row-2 {
grid-template-columns: 1fr;
}
}
@media (max-width: 700px) {
.dash-kpis {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.dash-actions {
grid-template-columns: 1fr 1fr;
}
.dash-order {
grid-template-columns: 1fr;
}
.dash-split.three {
grid-template-columns: 1fr;
}
}

View File

@@ -0,0 +1,321 @@
@page "/admin/administratori"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.EntityFrameworkCore
@using Web_Jarmark.Data
@inject UserManager<ApplicationUser> UserManager
@inject RoleManager<IdentityRole> RoleManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Registrovaní uživatelé</PageTitle>
<div class="ap">
<header class="ap-hero ap-hero-left">
<p class="ap-eyebrow">Administrace</p>
<div class="ap-hero-row">
<div>
<h1>Uživatelé</h1>
<p class="ap-sub">Správa registrovaných účtů a administrátorských oprávnění.</p>
</div>
</div>
</header>
@if (!string.IsNullOrEmpty(message))
{
<div class="ap-alert">@message</div>
}
@if (loading)
{
<div class="ap-loading">Načítám uživatele…</div>
}
else if (users.Count == 0)
{
<section class="ap-panel">
<p class="ap-empty">Zatím žádní registrovaní uživatelé.</p>
</section>
}
else
{
<section class="ap-panel ap-panel-table">
<div class="ap-panel-head">
<h2>Registrované účty</h2>
<span class="ap-muted">@users.Count účtů</span>
</div>
<div class="ap-table-wrap">
<table class="ap-table">
<thead>
<tr>
<th>E-mail</th>
<th>Potvrzený</th>
<th>Admin</th>
<th>Stav</th>
<th>Akce</th>
</tr>
</thead>
<tbody>
@foreach (var u in users)
{
<tr @key="u.Id">
<td class="ap-name">@u.Email</td>
<td>
<span class="ap-status @(u.EmailConfirmed ? "is-on" : "is-off")">
@(u.EmailConfirmed ? "Ano" : "Ne")
</span>
</td>
<td>
<span class="ap-status @(u.IsAdmin ? "is-on" : "is-off")">
@(u.IsAdmin ? "Admin" : "Uživatel")
</span>
</td>
<td>
<span class="ap-status @(u.IsLocked ? "is-off" : "is-on")">
@(u.IsLocked ? "Zamčený" : "Aktivní")
</span>
</td>
<td class="ap-actions-cell">
<button type="button"
class="ap-btn ap-btn-ghost"
disabled="@busy"
@onclick="() => ToggleAdminAsync(u)">
@(u.IsAdmin ? "Odebrat admin" : "Udělat admin")
</button>
<button type="button"
class="ap-btn ap-btn-ghost"
disabled="@busy"
@onclick="() => ToggleLockAsync(u)">
@(u.IsLocked ? "Odemknout" : "Zamknout")
</button>
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
}
</div>
@code {
private List<UserRow> users = new();
private bool loading = true;
private bool busy;
private string? message;
private const string AdminRole = "Admin";
protected override async Task OnInitializedAsync()
{
await EnsureAdminRoleAsync();
await LoadUsersAsync();
loading = false;
}
private async Task EnsureAdminRoleAsync()
{
if (!await RoleManager.RoleExistsAsync(AdminRole))
{
var result = await RoleManager.CreateAsync(
new IdentityRole(AdminRole));
if (!result.Succeeded)
{
message = "Nepodařilo se vytvořit roli Admin: "
+ string.Join(", ", result.Errors.Select(e => e.Description));
}
}
}
private async Task LoadUsersAsync()
{
var list = await UserManager.Users
.AsNoTracking()
.OrderBy(u => u.Email)
.ToListAsync();
users = new List<UserRow>();
foreach (var user in list)
{
var roles = await UserManager.GetRolesAsync(user);
var isLocked = user.LockoutEnd.HasValue
&& user.LockoutEnd > DateTimeOffset.UtcNow;
users.Add(new UserRow(
user.Id,
user.Email ?? "(bez e-mailu)",
user.EmailConfirmed,
roles.Contains(AdminRole),
isLocked));
}
}
private async Task ToggleAdminAsync(UserRow row)
{
if (busy)
return;
busy = true;
message = null;
try
{
var user = await UserManager.FindByIdAsync(row.Id);
if (user is null)
{
message = "Uživatel nebyl nalezen.";
return;
}
if (!await RoleManager.RoleExistsAsync(AdminRole))
{
var createRoleResult = await RoleManager.CreateAsync(
new IdentityRole(AdminRole));
if (!createRoleResult.Succeeded)
{
message = "Nepodařilo se vytvořit roli Admin: "
+ string.Join(", ", createRoleResult.Errors.Select(e => e.Description));
return;
}
}
if (row.IsAdmin)
{
var admins = await UserManager.GetUsersInRoleAsync(AdminRole);
if (admins.Count <= 1)
{
message = "Nelze odebrat roli poslednímu administrátorovi.";
return;
}
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var currentUserId = UserManager.GetUserId(authState.User);
if (currentUserId == user.Id)
{
message = "Nemůžeš odebrat administrátorskou roli sám sobě.";
return;
}
}
IdentityResult result;
if (row.IsAdmin)
{
result = await UserManager.RemoveFromRoleAsync(user, AdminRole);
}
else
{
result = await UserManager.AddToRoleAsync(user, AdminRole);
}
if (!result.Succeeded)
{
message = "Změna role se nepodařila: "
+ string.Join(", ", result.Errors.Select(e => e.Description));
return;
}
message = row.IsAdmin
? $"Administrátorská role byla odebrána: {row.Email}"
: $"Administrátorská role byla přidána: {row.Email}";
await LoadUsersAsync();
}
catch (Exception ex)
{
message = "Chyba při změně role: " + ex.Message;
}
finally
{
busy = false;
}
}
private async Task ToggleLockAsync(UserRow row)
{
if (busy)
return;
busy = true;
message = null;
try
{
var user = await UserManager.FindByIdAsync(row.Id);
if (user is null)
{
message = "Uživatel nebyl nalezen.";
return;
}
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var currentUserId = UserManager.GetUserId(authState.User);
if (currentUserId == user.Id)
{
message = "Nemůžeš zamknout vlastní účet.";
return;
}
IdentityResult result;
if (row.IsLocked)
{
result = await UserManager.SetLockoutEndDateAsync(user, null);
}
else
{
result = await UserManager.SetLockoutEnabledAsync(user, true);
if (result.Succeeded)
{
result = await UserManager.SetLockoutEndDateAsync(
user, DateTimeOffset.UtcNow.AddYears(100));
}
}
if (!result.Succeeded)
{
message = "Změna stavu účtu se nepodařila: "
+ string.Join(", ", result.Errors.Select(e => e.Description));
return;
}
message = row.IsLocked
? $"Účet byl odemčen: {row.Email}"
: $"Účet byl zamčen: {row.Email}";
await LoadUsersAsync();
}
catch (Exception ex)
{
message = "Chyba: " + ex.Message;
}
finally
{
busy = false;
}
}
private sealed record UserRow(
string Id,
string Email,
bool EmailConfirmed,
bool IsAdmin,
bool IsLocked);
}

View File

@@ -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
@@ -13,206 +9,148 @@
@inject ApplicationDbContext Db @inject ApplicationDbContext Db
@inject NavigationManager Nav @inject NavigationManager Nav
@attribute [Authorize] @attribute [Authorize(Roles = "Admin")]
<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 ao">
<div class="wj-page-back"> <header class="ao-hero">
<a href="/admin" class="wj-back-admin"> <p class="ao-eyebrow">Kategorie</p>
<span>←</span> Zpět na administraci <h1>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</h1>
</a> <p class="ao-sub">Název a stav kategorie.</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="ao-alert">@error</div>
} }
<div class="wj-field"> @if (notFound)
<label for="name">Název kategorie</label> {
<InputText id="name" <div class="ao-empty">Kategorie nebyla nalezena.</div>
class="form-control wj-input" <div style="text-align:center;margin-top:12px">
placeholder="Např. Cukroví" <a class="ap-btn" href="/admin/kategorie">Zpět</a>
@bind-Value="form.Name" />
<ValidationMessage For="@(() => form.Name)" class="text-danger small" />
</div>
<div class="wj-field">
<label for="slug">Adresa kategorie (slug)</label>
<InputText id="slug"
class="form-control wj-input"
placeholder="napr-cukrovi"
@bind-Value="form.Slug" />
<small>Pokud pole necháte prázdné, adresa se vytvoří automaticky z názvu.</small>
</div>
<div class="wj-switch-card">
<div class="form-check form-switch">
<InputCheckbox id="active"
class="form-check-input"
@bind-Value="form.IsActive" />
<label class="form-check-label fw-semibold" for="active">
Aktivní kategorie
</label>
</div>
<small>Aktivní kategorie může být nabízena zákazníkům.</small>
</div>
<div class="wj-form-actions">
<button type="submit" class="wj-button wj-button-primary">
Uložit kategorii
</button>
<a class="wj-button wj-button-secondary" href="/admin/kategorie">
Zrušit
</a>
</div>
</EditForm>
</div> </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="ao-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="ao-panel" style="max-width:560px;margin:0 auto">
<div class="ap-field">
<label>Název</label>
<input class="ao-input" @bind="name" />
</div>
if (cat is null) <div class="ap-field">
<label>Slug</label>
<input class="ao-input" @bind="categorySlug" />
<small class="ap-help">Když necháš prázdné, vytvoří se z názvu.</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); finally
var sb = new StringBuilder();
foreach (var ch in normalized)
{ {
if (CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark) saving = false;
sb.Append(ch); }
}
var noDiacritics = sb.ToString().Normalize(NormalizationForm.FormC);
return Regex.Replace(noDiacritics, "[^a-z0-9]+", "-").Trim('-');
}
private class CategoryForm
{
[Required(ErrorMessage = "Zadej název kategorie.")]
[StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")]
public string Name { get; set; } = "";
public string? Slug { get; set; }
public bool IsActive { get; set; } = true;
} }
} }

View File

@@ -2,211 +2,106 @@
@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(Roles = "Admin")]
<AuthorizeView>
<PageTitle>Kategorie</PageTitle> <PageTitle>Kategorie</PageTitle>
<div class="wj-admin-page container-fluid py-3"> <div class="ap ao">
<div class="wj-page-back"> <header class="ao-hero">
<a href="/admin" class="wj-back-admin"> <p class="ao-eyebrow">Administrace</p>
<span aria-hidden="true">←</span> <h1>Kategorie</h1>
Zpět na administraci <p class="ao-sub">Správa kategorií sortimentu.</p>
</a> <div style="margin-top:16px">
</div> <a class="ap-btn ap-btn-primary" href="/admin/kategorie/edit">Nová kategorie</a>
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
<div>
<div class="text-muted small mb-1">ADMINISTRACE / SPRÁVA OBCHODU</div>
<h2 class="fw-bold mb-1">Kategorie</h2>
<p class="text-muted mb-0">Spravujte kategorie svého zboží.</p>
</div>
<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="ao-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="ao-loading">Načítám kategorie…</div>
<div class="text-muted">Načítám kategorie…</div> }
</div> else if (items.Count == 0)
{
<div class="ao-empty">Zatím žádné kategorie.</div>
} }
else else
{ {
<div class="card border-0 shadow-sm rounded-4 mb-4"> <section class="ao-panel">
<div class="card-body p-4"> <div class="ao-panel-head">
<div class="d-flex align-items-center gap-3">
<div class="rounded-3 bg-primary bg-opacity-10 text-primary p-3 fs-3">
🗂️
</div>
<div> <div>
<div class="text-muted small">Celkem kategorií</div> <h2>Seznam kategorií</h2>
<div class="fs-3 fw-bold">@categories.Count</div> <p>@items.Count položek</p>
</div>
</div>
</div> </div>
</div> </div>
<div class="card border-0 shadow-sm rounded-4 overflow-hidden"> <div class="ao-list">
<div class="card-header bg-white border-0 px-4 pt-4 pb-3"> @foreach (var c in items)
<h5 class="fw-bold mb-1">Přehled kategorií</h5> {
<div class="text-muted small">Seznam všech kategorií v obchodě</div> <article class="ao-card" @key="c.Id">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">@c.Name</span>
<span class="ao-date">@c.Slug</span>
</div> </div>
<div class="ao-card-mid">
@if (categories.Count == 0) <span class="ao-pay">@c.ProductCount produktů</span>
{
<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> </div>
} <div class="ao-card-right">
else <span class="ao-badge @(c.IsActive ? "is-paid" : "is-cancel")">
{ @(c.IsActive ? "Aktivní" : "Neaktivní")
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th class="ps-4 py-3">Název kategorie</th>
<th class="py-3">Adresa (slug)</th>
<th class="text-center py-3">Počet produktů</th>
<th class="text-center py-3">Stav</th>
<th class="text-end pe-4 py-3">Akce</th>
</tr>
</thead>
<tbody>
@foreach (var c in categories)
{
<tr>
<td class="ps-4 py-3 fw-semibold">
<span class="me-2">📁</span>@c.Name
</td>
<td>
<code class="bg-light px-2 py-1 rounded">@c.Slug</code>
</td>
<td class="text-center">
<span class="badge bg-light text-dark rounded-pill px-3 py-2">
@c.ProductCount
</span> </span>
</td>
<td class="text-center">
@if (c.IsActive)
{
<span class="badge bg-success bg-opacity-10 text-success rounded-pill px-3 py-2">
Aktivní
</span>
}
else
{
<span class="badge bg-secondary bg-opacity-10 text-secondary rounded-pill px-3 py-2">
Neaktivní
</span>
}
<div class="form-check form-switch d-flex justify-content-center mt-2">
<input type="checkbox"
class="form-check-input"
checked="@c.IsActive"
title="Změnit aktivitu"
@onchange="() => ToggleActive(c.Id)" />
</div>
</td>
<td class="text-end pe-4">
<div class="d-flex justify-content-end gap-2">
<a class="btn btn-sm btn-outline-primary rounded-3 px-3"
href="/admin/kategorie/edit/@c.Id">
Upravit
</a>
<button class="btn btn-sm btn-outline-danger rounded-3 px-3"
disabled="@(c.ProductCount > 0)"
title="@(c.ProductCount > 0 ? "Kategorie obsahuje produkty" : "Smazat")"
@onclick="() => Delete(c.Id)">
Smazat
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
}
<div class="card-footer bg-white border-0 px-4 py-3">
<small class="text-muted">
Zobrazeno kategorií: @categories.Count
</small>
</div> </div>
</div> </div>
<div class="sklad-row">
<a class="ap-btn ap-btn-ghost" href="@($"/admin/kategorie/edit/{c.Id}")">Upravit</a>
</div>
</article>
}
</div>
</section>
} }
</div> </div>
</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 Slug,
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);
} }

View File

@@ -0,0 +1,130 @@
@page "/admin/nastaveni"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthState
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Nastavení</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Nastavení</h1>
<p class="ao-sub">Účet, e-shop a rychlé odkazy.</p>
</header>
@if (loading)
{
<div class="ao-loading">Načítám…</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat">
<span>Uživatelé</span>
<strong>@userCount</strong>
<small>registrovaných</small>
</article>
<article class="ao-stat">
<span>Administrátoři</span>
<strong>@adminCount</strong>
<small>role Admin</small>
</article>
<article class="ao-stat">
<span>Produkty</span>
<strong>@productCount</strong>
<small>v katalogu</small>
</article>
<article class="ao-stat">
<span>Objednávky</span>
<strong>@orderCount</strong>
<small>celkem</small>
</article>
</section>
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Tvůj účet</h2>
<p>Přihlášený administrátor</p>
</div>
</div>
<div class="ao-list">
<div class="ao-item">
<div><strong>E-mail</strong><span>přihlášení</span></div>
<strong>@currentEmail</strong>
</div>
<div class="ao-item">
<div><strong>Role</strong><span>oprávnění</span></div>
<strong>@currentRoles</strong>
</div>
</div>
<div class="sklad-row">
<a class="ap-btn ap-btn-ghost" href="/Account/Manage">Správa účtu</a>
<a class="ap-btn ap-btn-ghost" href="/Account/Manage/ChangePassword">Změna hesla</a>
</div>
</section>
<section class="ao-panel" style="margin-top:14px">
<div class="ao-panel-head">
<div>
<h2>Rychlé odkazy</h2>
<p>Administrace e-shopu</p>
</div>
</div>
<div class="sklad-row">
<a class="ap-btn" href="/">E-shop</a>
<a class="ap-btn" href="/admin">Přehled</a>
<a class="ap-btn" href="/admin/administratori">Uživatelé</a>
<a class="ap-btn" href="/admin/sklad">Sklad</a>
<a class="ap-btn" href="/admin/objednavky">Objednávky</a>
<a class="ap-btn" href="/admin/statistiky">Statistiky</a>
</div>
</section>
}
</div>
@code {
private bool loading = true;
private int userCount, adminCount, productCount, orderCount;
private string currentEmail = "—";
private string currentRoles = "—";
protected override async Task OnInitializedAsync()
{
try
{
userCount = await UserManager.Users.CountAsync();
var admins = await UserManager.GetUsersInRoleAsync("Admin");
adminCount = admins.Count;
productCount = await Db.Products.CountAsync();
orderCount = await Db.Orders.CountAsync();
var state = await AuthState.GetAuthenticationStateAsync();
var user = state.User;
if (user.Identity?.IsAuthenticated == true)
{
currentEmail = user.Identity?.Name ?? "—";
var appUser = await UserManager.FindByEmailAsync(currentEmail);
if (appUser is not null)
{
var roles = await UserManager.GetRolesAsync(appUser);
currentRoles = roles.Count == 0 ? "bez role" : string.Join(", ", roles);
}
}
}
finally
{
loading = false;
}
}
}

View File

@@ -0,0 +1,231 @@
@page "/admin/objednavky"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Objednávky</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Objednávky</h1>
<p class="ao-sub">Přehled všech objednávek a jejich aktuálního stavu.</p>
</header>
@if (isLoading)
{
<div class="ao-loading">Načítám objednávky…</div>
}
else if (!string.IsNullOrEmpty(errorMessage))
{
<div class="ao-alert">@errorMessage</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat" style="--i:0">
<span>Celkem</span>
<strong>@orders.Count</strong>
<small>objednávek</small>
</article>
<article class="ao-stat" style="--i:1">
<span>Čeká na zaplacení</span>
<strong>@orders.Count(o => o.Status == OrderStatus.Pending)</strong>
<small>k vyřízení</small>
</article>
<article class="ao-stat" style="--i:2">
<span>Zaplaceno</span>
<strong>@orders.Count(o => o.Status == OrderStatus.Paid)</strong>
<small>uhrazeno</small>
</article>
<article class="ao-stat" style="--i:3">
<span>Hodnota</span>
<strong>@orders.Sum(o => o.TotalAmount).ToString("N0")</strong>
<small>Kč celkem</small>
</article>
</section>
<section class="ao-panel" style="--i:4">
<div class="ao-panel-head">
<div>
<h2>Seznam objednávek</h2>
<p>@FilteredOrders.Count zobrazených</p>
</div>
</div>
<div class="ao-filters">
<input class="ao-input"
placeholder="Hledat podle kódu…"
@bind="searchText"
@bind:event="oninput" />
<select class="ao-select" @bind="statusFilter">
<option value="Vše">Všechny stavy</option>
<option value="Čeká na zaplacení">Čeká na zaplacení</option>
<option value="Zaplaceno">Zaplaceno</option>
<option value="Odesláno">Odesláno</option>
<option value="Dokončeno">Dokončeno</option>
<option value="Zrušeno">Zrušeno</option>
</select>
</div>
@if (FilteredOrders.Count == 0)
{
<div class="ao-empty">Žádné objednávky k zobrazení.</div>
}
else
{
<div class="ao-list">
@foreach (var order in FilteredOrders)
{
var open = selectedOrderId == order.Id;
<article class="ao-card @(open ? "is-open" : null)" @key="order.Id">
<button type="button" class="ao-card-main" @onclick="() => ToggleDetail(order.Id)">
<div class="ao-card-left">
<span class="ao-code">#@order.Code</span>
<span class="ao-date">@order.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@GetPaymentText(order.PreferredPayment)</span>
<span class="ao-qty">@order.OrderItems.Sum(i => i.Quantity) ks</span>
</div>
<div class="ao-card-right">
<span class="ao-price">@order.TotalAmount.ToString("N0") Kč</span>
<span class="ao-badge @GetBadgeClass(order.Status)">@GetStatusText(order.Status)</span>
</div>
<span class="ao-chevron @(open ? "is-open" : null)">›</span>
</button>
@if (open)
{
<div class="ao-detail">
<div class="ao-detail-grid">
<div>
<span>Zákazník</span>
<strong>@(string.IsNullOrWhiteSpace(order.CustomerName) ? "—" : order.CustomerName)</strong>
</div>
<div>
<span>E-mail</span>
<strong>@(string.IsNullOrWhiteSpace(order.Email) ? "—" : order.Email)</strong>
</div>
<div>
<span>Telefon</span>
<strong>@(string.IsNullOrWhiteSpace(order.Phone) ? "—" : order.Phone)</strong>
</div>
<div>
<span>Stav</span>
<strong>@GetStatusText(order.Status)</strong>
</div>
</div>
@if (!string.IsNullOrWhiteSpace(order.Note))
{
<p class="ao-note">@order.Note</p>
}
<div class="ao-items">
@foreach (var item in order.OrderItems)
{
<div class="ao-item">
<div>
<strong>@item.ProductName</strong>
<span>@item.Quantity ks × @item.UnitPrice.ToString("N0") Kč</span>
</div>
<strong>@((item.Quantity * item.UnitPrice).ToString("N0")) Kč</strong>
</div>
}
</div>
<div class="ao-total">
<span>Celkem</span>
<strong>@order.TotalAmount.ToString("N0") Kč</strong>
</div>
</div>
}
</article>
}
</div>
}
</section>
}
</div>
@code {
private List<Order> orders = new();
private bool isLoading = true;
private string? errorMessage;
private string searchText = "";
private string statusFilter = "Vše";
private int? selectedOrderId;
private List<Order> FilteredOrders =>
orders
.Where(o =>
string.IsNullOrWhiteSpace(searchText) ||
o.Code.Contains(searchText.Trim(), StringComparison.OrdinalIgnoreCase))
.Where(o =>
statusFilter == "Vše" ||
GetStatusText(o.Status) == statusFilter)
.ToList();
protected override async Task OnInitializedAsync()
{
try
{
orders = await Db.Orders
.AsNoTracking()
.Include(o => o.OrderItems)
.OrderByDescending(o => o.CreatedAt)
.ToListAsync();
}
catch
{
errorMessage = "Objednávky se nepodařilo načíst.";
}
finally
{
isLoading = false;
}
}
private void ToggleDetail(int orderId)
{
selectedOrderId = selectedOrderId == orderId ? null : orderId;
}
private static string GetStatusText(OrderStatus status) => status switch
{
OrderStatus.Pending => "Čeká na zaplacení",
OrderStatus.Paid => "Zaplaceno",
OrderStatus.Shipped => "Odesláno",
OrderStatus.Delivered => "Dokončeno",
OrderStatus.Cancelled => "Zrušeno",
_ => "Neznámý stav"
};
private static string GetBadgeClass(OrderStatus status) => status switch
{
OrderStatus.Pending => "is-pending",
OrderStatus.Paid => "is-paid",
OrderStatus.Shipped => "is-shipped",
OrderStatus.Delivered => "is-done",
OrderStatus.Cancelled => "is-cancel",
_ => ""
};
private static string GetPaymentText(PaymentMethod method) => method switch
{
PaymentMethod.BankTransfer => "Bankovní převod",
PaymentMethod.Cash => "Hotově",
PaymentMethod.CreditCard => "Karta",
PaymentMethod.PayPal => "PayPal",
_ => "—"
};
}

View File

@@ -0,0 +1,426 @@
/* Apple-like objednávky */
.ao {
max-width: 980px;
margin: 0 auto;
color: #1d1d1f;
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
.ao-hero {
text-align: center;
padding: 18px 8px 28px;
animation: ao-in 0.45s ease both;
}
.ao-eyebrow {
margin: 0 0 8px;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #6e6e73;
}
.ao-hero h1 {
margin: 0;
font-size: 36px;
font-weight: 700;
letter-spacing: -0.03em;
}
.ao-sub {
margin: 10px auto 0;
max-width: 420px;
color: #6e6e73;
font-size: 16px;
}
.ao-loading,
.ao-empty,
.ao-alert {
padding: 20px;
border-radius: 20px;
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.05);
color: #6e6e73;
text-align: center;
}
.ao-alert {
color: #1d1d1f;
margin-bottom: 14px;
}
/* Stats */
.ao-stats {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12px;
margin-bottom: 16px;
}
.ao-stat {
background: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(0, 0, 0, 0.04);
border-radius: 22px;
padding: 18px 16px;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.04);
animation: ao-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.06s);
transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.ao-stat:hover {
transform: translateY(-3px);
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.07);
}
.ao-stat span {
display: block;
font-size: 12px;
font-weight: 600;
color: #6e6e73;
}
.ao-stat strong {
display: block;
margin-top: 8px;
font-size: 28px;
font-weight: 750;
letter-spacing: -0.03em;
line-height: 1;
}
.ao-stat small {
display: block;
margin-top: 8px;
font-size: 12px;
color: #86868b;
}
/* Panel */
.ao-panel {
background: rgba(255, 255, 255, 0.92);
border: 1px solid rgba(0, 0, 0, 0.045);
border-radius: 26px;
padding: 18px 18px 12px;
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.04);
animation: ao-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.06s);
}
.ao-panel-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding: 4px 6px 14px;
}
.ao-panel-head h2 {
margin: 0;
font-size: 18px;
font-weight: 700;
letter-spacing: -0.02em;
}
.ao-panel-head p {
margin: 4px 0 0;
color: #6e6e73;
font-size: 13px;
}
.ao-filters {
display: flex;
gap: 10px;
flex-wrap: wrap;
padding: 0 6px 16px;
}
.ao-input,
.ao-select {
border: 1px solid #d2d2d7;
border-radius: 14px;
padding: 12px 14px;
font-size: 14px;
background: #fff;
color: #1d1d1f;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ao-input {
flex: 1;
min-width: 180px;
}
.ao-select {
min-width: 190px;
}
.ao-input:focus,
.ao-select:focus {
border-color: #1d1d1f;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
/* Cards list */
.ao-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.ao-card {
border: 1px solid rgba(0, 0, 0, 0.05);
border-radius: 20px;
background: #fafafa;
overflow: hidden;
transition: background 0.2s ease, box-shadow 0.25s ease, transform 0.2s ease;
}
.ao-card:hover {
background: #f5f5f7;
}
.ao-card.is-open {
background: #fff;
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
}
.ao-card-main {
width: 100%;
border: 0;
background: transparent;
display: grid;
grid-template-columns: 1.2fr 1fr 1fr auto;
gap: 12px;
align-items: center;
padding: 16px 16px;
text-align: left;
cursor: pointer;
color: inherit;
}
.ao-card-left,
.ao-card-mid,
.ao-card-right {
display: flex;
flex-direction: column;
gap: 4px;
min-width: 0;
}
.ao-card-right {
align-items: flex-end;
}
.ao-code {
font-weight: 750;
font-size: 15px;
letter-spacing: -0.02em;
}
.ao-date,
.ao-pay,
.ao-qty {
font-size: 12px;
color: #6e6e73;
}
.ao-price {
font-weight: 750;
font-size: 15px;
}
.ao-badge {
display: inline-flex;
align-items: center;
padding: 4px 10px;
border-radius: 999px;
font-size: 11px;
font-weight: 700;
background: #f0f0f2;
color: #6e6e73;
}
.ao-badge.is-pending {
background: #f0f0f2;
color: #1d1d1f;
}
.ao-badge.is-paid {
background: #1d1d1f;
color: #fff;
}
.ao-badge.is-shipped {
background: #3a3a3c;
color: #fff;
}
.ao-badge.is-done {
background: #1d1d1f;
color: #fff;
}
.ao-badge.is-cancel {
background: #e8e8ed;
color: #6e6e73;
}
.ao-chevron {
font-size: 22px;
color: #aeaeb2;
transform: rotate(0deg);
transition: transform 0.25s ease;
line-height: 1;
}
.ao-chevron.is-open {
transform: rotate(90deg);
color: #1d1d1f;
}
/* Detail */
.ao-detail {
padding: 0 16px 16px;
animation: ao-detail 0.28s ease both;
}
.ao-detail-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
margin-bottom: 12px;
}
.ao-detail-grid span {
display: block;
font-size: 11px;
color: #6e6e73;
margin-bottom: 3px;
}
.ao-detail-grid strong {
font-size: 13px;
font-weight: 650;
}
.ao-note {
margin: 0 0 12px;
padding: 12px 14px;
border-radius: 14px;
background: #f5f5f7;
color: #6e6e73;
font-size: 13px;
}
.ao-items {
display: flex;
flex-direction: column;
gap: 8px;
}
.ao-item {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 12px 14px;
border-radius: 14px;
background: #f5f5f7;
}
.ao-item span {
display: block;
margin-top: 2px;
font-size: 12px;
color: #6e6e73;
}
.ao-total {
margin-top: 12px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 4px 0;
font-size: 15px;
}
.ao-total strong {
font-size: 18px;
font-weight: 750;
letter-spacing: -0.02em;
}
@keyframes ao-in {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes ao-rise {
from {
opacity: 0;
transform: translateY(14px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes ao-detail {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 900px) {
.ao-stats {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ao-card-main {
grid-template-columns: 1fr auto;
grid-template-areas:
"left chev"
"mid chev"
"right chev";
}
.ao-card-left {
grid-area: left;
}
.ao-card-mid {
grid-area: mid;
}
.ao-card-right {
grid-area: right;
align-items: flex-start;
}
.ao-chevron {
grid-area: chev;
}
.ao-detail-grid {
grid-template-columns: 1fr 1fr;
}
}

View File

@@ -1,267 +1,317 @@
@page "/admin/zbozi/edit" ```razor
@page "/admin/zbozi/edit"
@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
@using Web_Jarmark.Data.Models @using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db @inject ApplicationDbContext Db
@inject NavigationManager Nav @inject NavigationManager Nav
@attribute [Authorize] @attribute [Authorize(Roles = "Admin")]
<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 ao">
<div class="wj-page-back"> <header class="ao-hero">
<a href="/admin" class="wj-back-admin"> <p class="ao-eyebrow">Zboží</p>
<span>←</span> Zpět na administraci <h1>@(IsNew ? "Nové zboží" : "Upravit zboží")</h1>
</a> <p class="ao-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="ao-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> <div class="ao-empty">Produkt nebyl nalezen.</div>
} <div style="text-align:center;margin-top:12px">
</InputSelect> <a class="ap-btn" href="/admin/zbozi">Zpět</a>
</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>
} }
</div> else if (loading)
</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="ao-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="ao-panel" style="max-width:560px;margin:0 auto">
<div class="ap-field">
<label>Název</label>
<input class="ao-input" maxlength="150" @bind="name" />
</div>
if (p is null) <div class="ap-field">
<label>Kategorie</label>
<select class="ao-select" style="width:100%" @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="ao-input"
maxlength="5000"
style="min-height:110px;resize:vertical"
@bind="description"></textarea>
</div>
<div class="ap-field">
<label>Cena (Kč)</label>
<input type="number"
min="0"
step="0.01"
class="ao-input"
@bind="price" />
</div>
<div class="ap-field">
<label>Sklad (ks)</label>
<input type="number"
min="0"
step="1"
class="ao-input"
@bind="stockQuantity" />
</div>
<div class="ap-field">
<label>URL obrázku</label>
<input class="ao-input"
maxlength="2048"
@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()
{
if (saving)
return;
saving = true;
error = null;
try
{
name = name?.Trim() ?? "";
description = description?.Trim() ?? "";
imageUrl = imageUrl?.Trim() ?? "";
if (string.IsNullOrWhiteSpace(name))
{
error = "Zadejte název produktu.";
return;
}
if (name.Length > 150)
{
error = "Název může mít maximálně 150 znaků.";
return;
}
if (description.Length > 5000)
{
error = "Popis může mít maximálně 5000 znaků.";
return;
}
if (price < 0 || price > 100000000)
{
error = "Cena musí být mezi 0 a 100 000 000 Kč.";
return;
}
if (decimal.Round(price, 2) != price)
{
error = "Cena může mít maximálně dvě desetinná místa.";
return;
}
if (stockQuantity < 0)
{
error = "Počet kusů na skladě nemůže být záporný.";
return;
}
if (categoryId <= 0 ||
!await Db.Categories.AnyAsync(c => c.Id == categoryId))
{
error = "Vyberte platnou kategorii.";
return;
}
if (!IsValidImageUrl(imageUrl))
{
error = "Obrázek musí mít platnou HTTPS adresu nebo bezpečnou relativní cestu.";
return;
}
Product entity;
if (IsNew)
{
entity = new Product();
Db.Products.Add(entity);
}
else
{
entity = await Db.Products
.FirstOrDefaultAsync(p => p.Id == Id!.Value);
if (entity is null)
{
notFound = true;
error = "Produkt již neexistuje.";
return;
}
}
entity.Name = name;
entity.Description = description;
entity.CategoryId = categoryId;
entity.Price = price;
entity.StockQuantity = stockQuantity;
entity.ImageUrl = imageUrl;
entity.IsVisible = isVisible;
entity.UpdatedAt = DateTime.UtcNow;
await Db.SaveChangesAsync(); await Db.SaveChangesAsync();
Nav.NavigateTo("/admin/zbozi"); Nav.NavigateTo("/admin/zbozi");
} }
catch (DbUpdateException)
private void Apply(Product p)
{ {
p.Name = form.Name.Trim(); error = "Produkt se nepodařilo uložit. Zkontrolujte zadané údaje.";
p.CategoryId = form.CategoryId;
p.Description = form.Description?.Trim() ?? "";
p.Price = form.Price;
p.StockQuantity = form.StockQuantity;
p.ImageUrl = form.ImageUrl?.Trim() ?? "";
p.IsVisible = form.IsVisible;
p.UpdatedAt = DateTime.Now;
} }
catch (Exception)
private class ProductForm
{ {
[Required(ErrorMessage = "Zadej název zboží.")] error = "Při ukládání nastala neočekávaná chyba.";
[StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")] }
public string Name { get; set; } = ""; finally
{
public int CategoryId { get; set; } saving = false;
public string? Description { get; set; }
[Range(0, 100000, ErrorMessage = "Cena musí být 0 až 100 000 Kč.")]
public decimal Price { get; set; }
[Range(0, 100000, ErrorMessage = "Počet kusů musí být 0 nebo více.")]
public int StockQuantity { get; set; }
public string? ImageUrl { get; set; }
public bool IsVisible { get; set; } = true;
} }
} }
private static bool IsValidImageUrl(string value)
{
if (string.IsNullOrWhiteSpace(value))
return true;
if (value.Length > 2048)
return false;
if (value.StartsWith("//") ||
value.Contains('\\') ||
value.Any(char.IsControl))
return false;
if (Uri.TryCreate(value, UriKind.Absolute, out var uri))
{
return uri.Scheme == Uri.UriSchemeHttps &&
!string.IsNullOrWhiteSpace(uri.Host);
}
return value.StartsWith('/') &&
!value.StartsWith("//") &&
!value.Contains("..");
}
private sealed record CatOption(int Id, string Name);
}
```

View File

@@ -7,183 +7,101 @@
@using Web_Jarmark.Data.Models @using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db @inject ApplicationDbContext Db
@attribute [Authorize] @attribute [Authorize(Roles = "Admin")]
<AuthorizeView>
<PageTitle>Zboží</PageTitle> <PageTitle>Zboží</PageTitle>
<div class="wj-admin-page container-fluid py-3"> <div class="ap ao">
<div class="wj-page-back"> <header class="ao-hero">
<a href="/admin" class="wj-back-admin"> <p class="ao-eyebrow">Administrace</p>
<span>←</span> Zpět na administraci <h1>Zboží</h1>
</a> <p class="ao-sub">Přehled a správa produktů.</p>
</div> <div style="margin-top:16px">
<a class="ap-btn ap-btn-primary" href="/admin/zbozi/edit">Nové zboží</a>
<div class="wj-heading d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
<div>
<div class="wj-eyebrow">ADMINISTRACE / SPRÁVA OBCHODU</div>
<h2>Zboží</h2>
<p>Přehled a správa produktů v obchodě.</p>
</div>
<a class="wj-button wj-button-primary" href="/admin/zbozi/edit">
+ Nové zboží
</a>
</div> </div>
</header>
@if (!string.IsNullOrEmpty(error)) @if (!string.IsNullOrEmpty(error))
{ {
<div class="alert alert-danger rounded-4">@error</div> <div class="ao-alert">@error</div>
} }
@if (products is null) <div class="ao-filters">
{ <input class="ao-input" placeholder="Hledat produkt…" @bind="search" @bind:event="oninput" />
<div class="wj-panel p-4">
<span class="text-muted">Načítám zboží…</span>
</div> </div>
@if (items is null)
{
<div class="ao-loading">Načítám zboží…</div>
}
else if (Filtered.Count == 0)
{
<div class="ao-empty">Žádné produkty.</div>
} }
else else
{ {
<div class="row g-3 mb-4"> <section class="ao-panel">
<div class="col-sm-6 col-xl-4"> <div class="ao-panel-head">
<div class="wj-stat-card">
<div class="wj-stat-icon">📦</div>
<div class="wj-stat-label">Celkem produktů</div>
<div class="wj-stat-value">@products.Count</div>
</div>
</div>
<div class="col-sm-6 col-xl-4">
<div class="wj-stat-card">
<div class="wj-stat-icon">✓</div>
<div class="wj-stat-label">Viditelné produkty</div>
<div class="wj-stat-value">@products.Count(p => p.IsVisible)</div>
</div>
</div>
<div class="col-sm-6 col-xl-4">
<div class="wj-stat-card">
<div class="wj-stat-icon">📉</div>
<div class="wj-stat-label">Dochází skladem (5 a méně)</div>
<div class="wj-stat-value">@products.Count(p => p.StockQuantity <= 5)</div>
</div>
</div>
</div>
<div class="wj-panel p-0 overflow-hidden">
<div class="p-4 d-flex flex-wrap justify-content-between align-items-center gap-3">
<div> <div>
<h4 class="fw-bold mb-1">Přehled produktů</h4> <h2>Katalog</h2>
<p class="text-muted mb-0 small">Všechny produkty v e-shopu</p> <p>@Filtered.Count položek</p>
</div>
<div class="wj-search">
<span>⌕</span>
<input class="form-control"
placeholder="Hledat zboží nebo kategorii…"
@bind="searchTerm"
@bind:event="oninput" />
</div> </div>
</div> </div>
@if (FilteredProducts.Count == 0) <div class="ao-list">
@foreach (var p in Filtered)
{ {
<div class="text-center p-5"> <article class="ao-card" @key="p.Id">
<div class="fs-1 mb-3">🔎</div> <div class="ao-card-main" style="cursor:default">
<h5 class="fw-bold">Nic jsme nenašli</h5> <div class="ao-card-left">
<p class="text-muted mb-0">Zkuste změnit hledaný výraz.</p> <span class="ao-code">@p.Name</span>
<span class="ao-date">@p.CategoryName</span>
</div> </div>
} <div class="ao-card-mid">
else <span class="ao-pay">@p.Price.ToString("N0") Kč</span>
{ <span class="ao-qty">@p.StockQuantity ks</span>
<div class="table-responsive">
<table class="table wj-table align-middle mb-0">
<thead>
<tr>
<th class="ps-4">Název zboží</th>
<th>Kategorie</th>
<th class="text-end">Cena</th>
<th class="text-center">Skladem</th>
<th class="text-center">Viditelnost</th>
<th class="text-end pe-4">Akce</th>
</tr>
</thead>
<tbody>
@foreach (var p in FilteredProducts)
{
<tr>
<td class="ps-4 fw-semibold">@p.Name</td>
<td>
<span class="wj-tag">@p.CategoryName</span>
</td>
<td class="text-end fw-semibold">@p.Price.ToString("N2") Kč</td>
<td class="text-center">
@if (p.StockQuantity <= 5)
{
<span class="wj-stock-low">@p.StockQuantity ks</span>
}
else
{
<span class="wj-tag">@p.StockQuantity ks</span>
}
</td>
<td class="text-center">
<div class="form-check form-switch d-flex justify-content-center">
<input type="checkbox"
class="form-check-input"
checked="@p.IsVisible"
title="Změnit viditelnost"
@onchange="() => ToggleVisible(p.Id)" />
</div> </div>
<small class="text-muted">@(p.IsVisible ? "Viditelné" : "Skryté")</small> <div class="ao-card-right">
</td> <span class="ao-badge @(p.IsVisible ? "is-paid" : "is-cancel")">
<td class="text-end pe-4"> @(p.IsVisible ? "Viditelné" : "Skryté")
<div class="d-flex justify-content-end gap-2"> </span>
<a class="wj-small-button" href="/admin/zbozi/edit/@p.Id">
Upravit
</a>
<button class="wj-small-button wj-danger-button"
@onclick="() => Delete(p.Id)">
Smazat
</button>
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
}
<div class="border-top px-4 py-3">
<small class="text-muted">
Zobrazeno: @FilteredProducts.Count z @products.Count produktů
</small>
</div> </div>
</div> </div>
<div class="sklad-row">
<a class="ap-btn ap-btn-ghost" href="@($"/admin/zbozi/edit/{p.Id}")">Upravit</a>
</div>
</article>
}
</div>
</section>
} }
</div> </div>
</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();
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 +110,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,

View File

@@ -0,0 +1,419 @@
@page "/admin/sklad"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Sklad</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Sklad</h1>
<p class="ao-sub">Sledování zásob, rychlé úpravy a upozornění na nízký stav.</p>
</header>
@if (!string.IsNullOrEmpty(message))
{
<div class="ao-alert">@message</div>
}
@if (loading)
{
<div class="ao-loading">Načítám sklad…</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat" style="--i:0">
<span>Produktů</span>
<strong>@items.Count</strong>
<small>ve skladu</small>
</article>
<article class="ao-stat" style="--i:1">
<span>Nízký sklad</span>
<strong>@items.Count(i => i.StockQuantity > 0 && i.StockQuantity <= LowThreshold)</strong>
<small>≤ @LowThreshold ks</small>
</article>
<article class="ao-stat" style="--i:2">
<span>Vyprodané</span>
<strong>@items.Count(i => i.StockQuantity <= 0)</strong>
<small>0 ks</small>
</article>
<article class="ao-stat" style="--i:3">
<span>Hodnota skladu</span>
<strong>@items.Sum(i => i.Price * i.StockQuantity).ToString("N0")</strong>
<small>@items.Sum(i => i.StockQuantity) ks celkem</small>
</article>
</section>
<div class="ao-filters">
<input class="ao-input" placeholder="Hledat produkt nebo kategorii…"
@bind="search" @bind:event="oninput" />
<select class="ao-select" @bind="stockFilter">
<option value="all">Stav: vše</option>
<option value="ok">V pořádku (&gt;@LowThreshold)</option>
<option value="low">Nízký (1–@LowThreshold)</option>
<option value="out">Vyprodané (0)</option>
</select>
<select class="ao-select" @bind="categoryFilter">
<option value="all">Kategorie: vše</option>
@foreach (var c in categoryNames)
{
<option value="@c">@c</option>
}
</select>
<select class="ao-select" @bind="sortBy">
<option value="stock_asc">Řadit: nejméně kusů</option>
<option value="stock_desc">Řadit: nejvíce kusů</option>
<option value="name">Řadit: název</option>
<option value="value">Řadit: hodnota</option>
</select>
</div>
<div class="sklad-row" style="padding-left:0;padding-right:0">
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy" @onclick="ReloadAsync">Obnovit</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy || !HasPending" @onclick="SaveAllAsync">
Uložit všechny změny @(HasPending ? $"({PendingCount})" : "")
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy" @onclick="() => QuickFilterOut()">
Jen vyprodané
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy" @onclick="() => QuickFilterLow()">
Jen nízký sklad
</button>
</div>
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Zásoby</h2>
<p>@Filtered.Count položek</p>
</div>
</div>
@if (Filtered.Count == 0)
{
<div class="ao-empty">Nic nenalezeno.</div>
}
else
{
<div class="ao-list">
@foreach (var p in Filtered)
{
var qty = GetEditQty(p.Id);
var dirty = IsDirty(p.Id, p.StockQuantity);
<article class="ao-card @(dirty ? "is-open" : null)" @key="p.Id">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">@p.Name</span>
<span class="ao-date">@p.CategoryName</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@p.Price.ToString("N0") Kč / ks</span>
<span class="ao-qty">hodnota @((p.Price * qty).ToString("N0")) Kč</span>
</div>
<div class="ao-card-right">
<span class="ao-badge @StockBadge(qty)">
@StockLabel(qty)
</span>
@if (dirty)
{
<span class="ao-date">neuloženo</span>
}
</div>
</div>
<div class="sklad-row">
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, -5)">
−5
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, -1)">
−
</button>
<input type="number" min="0" class="ao-input sklad-input"
value="@qty"
@onchange="e => OnStockInput(p.Id, e)" />
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, 1)">
+
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, 5)">
+5
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, 10)">
+10
</button>
<button type="button" class="ap-btn ap-btn-primary" disabled="@busy"
@onclick="() => SaveOneAsync(p.Id)">
Uložit
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => SetQty(p.Id, 0)">
Na 0
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => ToggleVisibleAsync(p)">
@(p.IsVisible ? "Skrýt" : "Zobrazit")
</button>
<a class="ap-btn ap-btn-ghost" href="@($"/admin/zbozi/edit/{p.Id}")">Upravit</a>
</div>
</article>
}
</div>
}
</section>
}
</div>
@code {
private const int LowThreshold = 5;
private List<StockRow> items = new();
private readonly Dictionary<int, int> edits = new();
private List<string> categoryNames = new();
private bool loading = true;
private bool busy;
private string? message;
private string search = "";
private string stockFilter = "all";
private string categoryFilter = "all";
private string sortBy = "stock_asc";
private bool HasPending => items.Any(i => IsDirty(i.Id, i.StockQuantity));
private int PendingCount => items.Count(i => IsDirty(i.Id, i.StockQuantity));
private List<StockRow> Filtered
{
get
{
IEnumerable<StockRow> q = items;
if (!string.IsNullOrWhiteSpace(search))
{
q = q.Where(p =>
p.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
p.CategoryName.Contains(search, StringComparison.OrdinalIgnoreCase));
}
if (categoryFilter != "all")
{
q = q.Where(p => p.CategoryName == categoryFilter);
}
q = stockFilter switch
{
"ok" => q.Where(p => GetEditQty(p.Id) > LowThreshold),
"low" => q.Where(p =>
{
var n = GetEditQty(p.Id);
return n > 0 && n <= LowThreshold;
}),
"out" => q.Where(p => GetEditQty(p.Id) <= 0),
_ => q
};
q = sortBy switch
{
"stock_desc" => q.OrderByDescending(p => GetEditQty(p.Id)).ThenBy(p => p.Name),
"name" => q.OrderBy(p => p.Name),
"value" => q.OrderByDescending(p => p.Price * GetEditQty(p.Id)),
_ => q.OrderBy(p => GetEditQty(p.Id)).ThenBy(p => p.Name)
};
return q.ToList();
}
}
protected override async Task OnInitializedAsync()
{
await ReloadAsync();
loading = false;
}
private async Task ReloadAsync()
{
items = await Db.Products
.AsNoTracking()
.OrderBy(p => p.Name)
.Select(p => new StockRow(
p.Id,
p.Name,
p.Category.Name,
p.Price,
p.StockQuantity,
p.IsVisible))
.ToListAsync();
categoryNames = items
.Select(i => i.CategoryName)
.Distinct()
.OrderBy(x => x)
.ToList();
edits.Clear();
foreach (var i in items)
edits[i.Id] = i.StockQuantity;
message = null;
}
private int GetEditQty(int id) =>
edits.TryGetValue(id, out var v) ? v : 0;
private bool IsDirty(int id, int original) =>
edits.TryGetValue(id, out var v) && v != original;
private void OnStockInput(int id, ChangeEventArgs e)
{
if (int.TryParse(e.Value?.ToString(), out var val))
edits[id] = Math.Max(0, val);
}
private void Adjust(int id, int delta)
{
edits[id] = Math.Max(0, GetEditQty(id) + delta);
}
private void SetQty(int id, int qty)
{
edits[id] = Math.Max(0, qty);
}
private void QuickFilterOut()
{
stockFilter = "out";
sortBy = "name";
}
private void QuickFilterLow()
{
stockFilter = "low";
sortBy = "stock_asc";
}
private async Task SaveOneAsync(int id)
{
busy = true;
message = null;
try
{
var entity = await Db.Products.FirstOrDefaultAsync(p => p.Id == id);
if (entity is null)
{
message = "Produkt nebyl nalezen.";
return;
}
var qty = GetEditQty(id);
entity.StockQuantity = qty;
entity.UpdatedAt = DateTime.UtcNow;
await Db.SaveChangesAsync();
message = $"Uloženo: {entity.Name} → {qty} ks";
await ReloadAsync();
}
catch (Exception ex)
{
message = "Chyba: " + ex.Message;
}
finally
{
busy = false;
}
}
private async Task SaveAllAsync()
{
busy = true;
message = null;
try
{
var changed = items.Where(i => IsDirty(i.Id, i.StockQuantity)).ToList();
if (changed.Count == 0)
{
message = "Žádné změny k uložení.";
return;
}
var ids = changed.Select(c => c.Id).ToList();
var entities = await Db.Products.Where(p => ids.Contains(p.Id)).ToListAsync();
foreach (var entity in entities)
{
entity.StockQuantity = GetEditQty(entity.Id);
entity.UpdatedAt = DateTime.UtcNow;
}
await Db.SaveChangesAsync();
message = $"Uloženo změn: {entities.Count}";
await ReloadAsync();
}
catch (Exception ex)
{
message = "Hromadné uložení selhalo: " + ex.Message;
}
finally
{
busy = false;
}
}
private async Task ToggleVisibleAsync(StockRow row)
{
busy = true;
message = null;
try
{
var entity = await Db.Products.FirstAsync(p => p.Id == row.Id);
entity.IsVisible = !entity.IsVisible;
entity.UpdatedAt = DateTime.UtcNow;
await Db.SaveChangesAsync();
message = entity.IsVisible ? $"Zobrazeno: {entity.Name}" : $"Skryto v e-shopu: {entity.Name}";
await ReloadAsync();
}
catch (Exception ex)
{
message = ex.Message;
}
finally
{
busy = false;
}
}
private static string StockLabel(int q) =>
q <= 0 ? "Vyprodané" : q <= LowThreshold ? "Nízký sklad" : "V pořádku";
private static string StockBadge(int q) =>
q <= 0 ? "is-cancel" : q <= LowThreshold ? "is-pending" : "is-paid";
private sealed record StockRow(
int Id,
string Name,
string CategoryName,
decimal Price,
int StockQuantity,
bool IsVisible);
}

View File

@@ -0,0 +1,200 @@
@page "/admin/statistiky"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Statistiky</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Statistiky</h1>
<p class="ao-sub">Přehled e-shopu ze skutečných dat.</p>
</header>
@if (loading)
{
<div class="ao-loading">Načítám statistiky…</div>
}
else if (!string.IsNullOrEmpty(error))
{
<div class="ao-alert">@error</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat">
<span>Objednávky</span>
<strong>@orderCount</strong>
<small>celkem</small>
</article>
<article class="ao-stat">
<span>Tržby</span>
<strong>@revenue.ToString("N0")</strong>
<small>Kč</small>
</article>
<article class="ao-stat">
<span>Produkty</span>
<strong>@productCount</strong>
<small>@visibleCount viditelných</small>
</article>
<article class="ao-stat">
<span>Sklad</span>
<strong>@stockUnits</strong>
<small>@stockValue.ToString("N0") Kč</small>
</article>
</section>
<section class="ao-stats">
<article class="ao-stat">
<span>Čeká na zaplacení</span>
<strong>@pendingCount</strong>
<small>objednávek</small>
</article>
<article class="ao-stat">
<span>Zaplaceno</span>
<strong>@paidCount</strong>
<small>objednávek</small>
</article>
<article class="ao-stat">
<span>Odesláno / dokončeno</span>
<strong>@(shippedCount + deliveredCount)</strong>
<small>objednávek</small>
</article>
<article class="ao-stat">
<span>Zrušeno</span>
<strong>@cancelledCount</strong>
<small>objednávek</small>
</article>
</section>
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Katalog a sklad</h2>
<p>Aktuální stav</p>
</div>
</div>
<div class="ao-list">
<div class="ao-item">
<div><strong>Kategorie</strong><span>celkem</span></div>
<strong>@categoryCount</strong>
</div>
<div class="ao-item">
<div><strong>Aktivní kategorie</strong><span>v e-shopu</span></div>
<strong>@activeCategoryCount</strong>
</div>
<div class="ao-item">
<div><strong>Nízký sklad</strong><span>≤ 5 ks</span></div>
<strong>@lowStockCount</strong>
</div>
<div class="ao-item">
<div><strong>Vyprodané</strong><span>0 ks</span></div>
<strong>@outOfStockCount</strong>
</div>
</div>
</section>
<section class="ao-panel" style="margin-top:14px">
<div class="ao-panel-head">
<div>
<h2>Poslední objednávky</h2>
<p>Nejnovějších 8</p>
</div>
<a class="ap-btn ap-btn-ghost" href="/admin/objednavky">Všechny</a>
</div>
@if (recentOrders.Count == 0)
{
<div class="ao-empty">Žádné objednávky.</div>
}
else
{
<div class="ao-list">
@foreach (var o in recentOrders)
{
<article class="ao-card">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">#@o.Code</span>
<span class="ao-date">@o.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@(string.IsNullOrWhiteSpace(o.CustomerName) ? "—" : o.CustomerName)</span>
</div>
<div class="ao-card-right">
<span class="ao-price">@o.TotalAmount.ToString("N0") Kč</span>
</div>
</div>
</article>
}
</div>
}
</section>
}
</div>
@code {
private bool loading = true;
private string? error;
private int orderCount, pendingCount, paidCount, shippedCount, deliveredCount, cancelledCount;
private int productCount, visibleCount, categoryCount, activeCategoryCount;
private int stockUnits, lowStockCount, outOfStockCount;
private decimal revenue, stockValue;
private List<RecentOrder> recentOrders = new();
protected override async Task OnInitializedAsync()
{
try
{
var orders = await Db.Orders.AsNoTracking().ToListAsync();
orderCount = orders.Count;
pendingCount = orders.Count(o => o.Status == OrderStatus.Pending);
paidCount = orders.Count(o => o.Status == OrderStatus.Paid);
shippedCount = orders.Count(o => o.Status == OrderStatus.Shipped);
deliveredCount = orders.Count(o => o.Status == OrderStatus.Delivered);
cancelledCount = orders.Count(o => o.Status == OrderStatus.Cancelled);
revenue = orders
.Where(o => o.Status == OrderStatus.Paid
|| o.Status == OrderStatus.Shipped
|| o.Status == OrderStatus.Delivered)
.Sum(o => o.TotalAmount);
var products = await Db.Products.AsNoTracking().ToListAsync();
productCount = products.Count;
visibleCount = products.Count(p => p.IsVisible);
stockUnits = products.Sum(p => p.StockQuantity);
stockValue = products.Sum(p => p.Price * p.StockQuantity);
lowStockCount = products.Count(p => p.StockQuantity > 0 && p.StockQuantity <= 5);
outOfStockCount = products.Count(p => p.StockQuantity <= 0);
categoryCount = await Db.Categories.CountAsync();
activeCategoryCount = await Db.Categories.CountAsync(c => c.IsActive);
recentOrders = orders
.OrderByDescending(o => o.CreatedAt)
.Take(8)
.Select(o => new RecentOrder(o.Code, o.CustomerName, o.TotalAmount, o.CreatedAt))
.ToList();
}
catch (Exception ex)
{
error = "Statistiky se nepodařilo načíst: " + ex.Message;
}
finally
{
loading = false;
}
}
private sealed record RecentOrder(string Code, string CustomerName, decimal TotalAmount, DateTime CreatedAt);
}

View File

@@ -8,87 +8,822 @@
@inject IHttpContextAccessor HttpContextAccessor @inject IHttpContextAccessor HttpContextAccessor
@inject PersistentComponentState ApplicationState @inject PersistentComponentState ApplicationState
<PageTitle>Detail produktu</PageTitle> @implements IDisposable
<PageTitle>Detail produktu | Školní jarmark</PageTitle>
<div class="jarmark-product-detail">
<!-- NOTIFIKACE -->
@if (showNotification)
{
<div class="jarmark-detail-notification"
role="status"
aria-live="polite">
<svg width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<circle cx="12" cy="12" r="9" />
<path d="m8 12 3 3 5-6" />
</svg>
<span>@notificationMessage</span>
</div>
}
<!-- NÁVRAT DO KATALOGU -->
<a href="/" class="jarmark-detail-back">
<svg width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M19 12H5M12 19l-7-7 7-7" />
</svg>
<span>Zpět do katalogu</span>
</a>
<!-- NAČÍTÁNÍ -->
@if (loading) @if (loading)
{ {
<p>Načítám produkt...</p> <div class="jarmark-detail-empty"
role="status"
aria-live="polite">
<h2>Načítáme výrobek</h2>
<p>Informace o výrobku se právě načítají.</p>
</div>
} }
else if (product == null) else if (product == null)
{ {
<h3>Produkt nebyl nalezen.</h3> <div class="jarmark-detail-empty">
<svg width="48"
height="48"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.4"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<circle cx="11" cy="11" r="7" />
<path d="m20 20-4-4" />
</svg>
<h2>Výrobek nebyl nalezen</h2>
<p>
Tento výrobek již nemusí být dostupný.
Další výrobky najdete v katalogu.
</p>
<a href="/"
class="jarmark-detail-button">
Prohlédnout nabídku
</a>
</div>
} }
else else
{ {
<article class="jarmark-detail-card">
<!-- FOTOGRAFIE -->
<div class="jarmark-detail-image">
@if (!string.IsNullOrWhiteSpace(product.ImageUrl)
&& !imageFailed)
{ {
<div class="detail-container"> <img src="@product.ImageUrl"
<a href="/katalog" class="back-link">← Zpět do katalogu</a> alt="@product.Name"
decoding="async"
@onerror="HandleImageError" />
}
else
{
<div class="jarmark-detail-placeholder">
<svg width="80"
height="80"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<rect x="3"
y="3"
width="18"
height="18"
rx="2" />
<circle cx="8.5"
cy="8.5"
r="1.5" />
<path d="m21 15-5-5L5 21" />
</svg>
<span>Fotografie není dostupná</span>
</div>
}
<div class="detail-card">
<div class="detail-image">
<img src="@product.ImageUrl" alt="@product.Name" />
</div> </div>
<div class="detail-info">
<span class="detail-category"> <!-- INFORMACE O VÝROBKU -->
@product.Category?.Name
<div class="jarmark-detail-info">
@if (product.Category is not null)
{
<span class="jarmark-detail-category">
@product.Category.Name
</span>
}
<h1 class="jarmark-detail-title">
@product.Name
</h1>
@if (!string.IsNullOrWhiteSpace(product.Description))
{
<p class="jarmark-detail-description">
@product.Description
</p>
}
<!-- SKLADOVÁ DOSTUPNOST -->
<div class="jarmark-detail-stock @(product.StockQuantity > 0 ? "is-available" : "is-unavailable")">
<span class="jarmark-detail-stock-dot"
aria-hidden="true">
</span> </span>
<h1>@product.Name</h1> @if (product.StockQuantity > 0)
{
<p class="detail-description"> <span>
@product.Description
</p>
<div class="detail-stock">
<span class="stock-dot"></span>
Skladem: @product.StockQuantity ks Skladem: @product.StockQuantity ks
</span>
}
else
{
<span>Není skladem</span>
}
</div> </div>
<div class="detail-divider"></div>
<div class="detail-bottom"> <!-- CENA A NÁKUP -->
<div>
<span class="price-label">Cena produktu</span> <div class="jarmark-detail-purchase">
<div class="detail-price">
<div class="jarmark-detail-price-area">
<span class="jarmark-detail-price-label">
Cena produktu
</span>
<strong class="jarmark-detail-price">
@product.Price.ToString("N0") Kč @product.Price.ToString("N0") Kč
</div>
</strong>
</div> </div>
<button type="button"
class="jarmark-detail-button"
<button class="detail-cart-button"
disabled="@(product.StockQuantity <= 0)" disabled="@(product.StockQuantity <= 0)"
@onclick="() => HandleAddToCart(product)"> @onclick="() => HandleAddToCart(product)">
🛒 Přidat do košíku
@if (product.StockQuantity > 0)
{
<svg width="22"
height="22"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M3 3h2l3.5 13h10l3-10H6" />
<circle cx="10"
cy="20"
r="1" />
<circle cx="18"
cy="20"
r="1" />
</svg>
<span>Přidat do košíku</span>
}
else
{
<span>Vyprodáno</span>
}
</button> </button>
</div> </div>
</div> </div>
</article>
}
</div> </div>
</div>
<style>
/* ========================================
PUBLIC PRODUCT DETAIL
======================================== */
.jarmark-product-detail {
--detail-primary: #244b36;
--detail-primary-hover: #193b29;
--detail-secondary: #e6eddf;
--detail-surface: #ffffff;
--detail-text: #26372b;
--detail-muted: #59665b;
--detail-border: #dce3d9;
width: 100%;
max-width: 1200px;
min-width: 0;
margin: 0 auto;
color: var(--detail-text);
font-family: inherit;
box-sizing: border-box;
}
/* ========================================
BACK LINK
======================================== */
.jarmark-product-detail .jarmark-detail-back {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 44px;
margin: 0 0 20px;
padding: 8px 0;
color: var(--detail-primary);
font-size: 14px;
font-weight: 600;
line-height: 1.4;
text-decoration: none;
}
.jarmark-product-detail .jarmark-detail-back svg {
flex-shrink: 0;
}
.jarmark-product-detail .jarmark-detail-back:hover {
color: var(--detail-primary-hover);
text-decoration: underline;
text-underline-offset: 4px;
}
/* ========================================
PRODUCT CARD
======================================== */
.jarmark-product-detail .jarmark-detail-card {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
align-items: start;
gap: 40px;
width: 100%;
min-width: 0;
padding: 32px;
background: var(--detail-surface);
border: 1px solid var(--detail-border);
border-radius: 12px;
box-sizing: border-box;
}
/* ========================================
PRODUCT IMAGE
======================================== */
.jarmark-product-detail .jarmark-detail-image {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-width: 0;
aspect-ratio: 1 / 1;
background: #edf0e9;
border: 1px solid var(--detail-border);
border-radius: 8px;
overflow: hidden;
}
.jarmark-product-detail .jarmark-detail-image img {
display: block;
width: 100%;
height: 100%;
max-width: 100%;
padding: 20px;
object-fit: contain;
object-position: center;
box-sizing: border-box;
}
/* ========================================
IMAGE PLACEHOLDER
======================================== */
.jarmark-product-detail .jarmark-detail-placeholder {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
width: 100%;
height: 100%;
padding: 24px;
background: var(--detail-secondary);
color: #64815d;
text-align: center;
}
.jarmark-product-detail .jarmark-detail-placeholder span {
color: var(--detail-muted);
font-size: 14px;
font-weight: 500;
}
/* ========================================
PRODUCT INFORMATION
======================================== */
.jarmark-product-detail .jarmark-detail-info {
display: flex;
flex-direction: column;
gap: 16px;
width: 100%;
min-width: 0;
padding: 12px 0;
}
.jarmark-product-detail .jarmark-detail-category {
display: block;
color: var(--detail-muted);
font-size: 14px;
font-weight: 500;
line-height: 1.5;
letter-spacing: normal;
text-transform: none;
overflow-wrap: anywhere;
}
.jarmark-product-detail .jarmark-detail-title {
margin: 0;
color: var(--detail-text);
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 44px);
font-weight: 700;
line-height: 1.2;
letter-spacing: normal;
overflow-wrap: anywhere;
}
.jarmark-product-detail .jarmark-detail-description {
margin: 0;
color: var(--detail-muted);
font-size: 16px;
line-height: 1.8;
white-space: pre-line;
overflow-wrap: anywhere;
}
/* ========================================
STOCK AVAILABILITY
======================================== */
.jarmark-product-detail .jarmark-detail-stock {
display: inline-flex;
align-items: center;
gap: 8px;
align-self: flex-start;
margin-top: 8px;
font-size: 14px;
font-weight: 600;
line-height: 1.5;
}
.jarmark-product-detail .jarmark-detail-stock-dot {
display: inline-block;
flex-shrink: 0;
width: 8px;
height: 8px;
background: currentColor;
border-radius: 50%;
}
.jarmark-product-detail .is-available {
color: #34754b;
}
.jarmark-product-detail .is-unavailable {
color: #93483e;
}
/* ========================================
PURCHASE SECTION
======================================== */
.jarmark-product-detail .jarmark-detail-purchase {
display: flex;
flex-direction: column;
gap: 24px;
width: 100%;
margin-top: 12px;
padding-top: 24px;
border-top: 1px solid var(--detail-border);
}
.jarmark-product-detail .jarmark-detail-price-area {
display: flex;
flex-direction: column;
gap: 4px;
}
.jarmark-product-detail .jarmark-detail-price-label {
color: var(--detail-muted);
font-size: 14px;
font-weight: 500;
}
.jarmark-product-detail .jarmark-detail-price {
color: var(--detail-primary);
font-size: clamp(32px, 4vw, 44px);
font-weight: 750;
line-height: 1.2;
font-variant-numeric: tabular-nums;
overflow-wrap: anywhere;
}
/* ========================================
ADD TO CART BUTTON
======================================== */
.jarmark-product-detail .jarmark-detail-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 12px;
width: 100%;
min-height: 52px;
margin: 0;
padding: 12px 24px;
background: var(--detail-primary);
color: #ffffff;
border: 1px solid var(--detail-primary);
border-radius: 6px;
font-family: inherit;
font-size: 15px;
font-weight: 650;
line-height: 1.5;
text-align: center;
text-decoration: none;
cursor: pointer;
transition: background-color 150ms ease, border-color 150ms ease;
}
.jarmark-product-detail .jarmark-detail-button svg {
flex-shrink: 0;
}
.jarmark-product-detail .jarmark-detail-button:not(:disabled):hover {
background: var(--detail-primary-hover);
border-color: var(--detail-primary-hover);
color: #ffffff;
text-decoration: none;
}
.jarmark-product-detail .jarmark-detail-button:disabled {
background: #e9ece7;
color: #59665b;
border-color: var(--detail-border);
opacity: 1;
cursor: not-allowed;
}
/* ========================================
EMPTY AND LOADING STATES
======================================== */
.jarmark-product-detail .jarmark-detail-empty {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 16px;
min-height: 220px;
padding: 32px;
background: var(--detail-surface);
border: 1px solid var(--detail-border);
border-radius: 8px;
}
.jarmark-product-detail .jarmark-detail-empty svg {
color: #64815d;
}
.jarmark-product-detail .jarmark-detail-empty h2 {
margin: 0;
color: var(--detail-text);
font-size: 28px;
line-height: 1.3;
}
.jarmark-product-detail .jarmark-detail-empty p {
margin: 0;
color: var(--detail-muted);
font-size: 15px;
line-height: 1.6;
}
.jarmark-product-detail .jarmark-detail-empty .jarmark-detail-button {
width: auto;
margin-top: 8px;
}
/* ========================================
CART NOTIFICATION
======================================== */
.jarmark-product-detail .jarmark-detail-notification {
position: fixed;
top: 96px;
right: 24px;
z-index: 500;
display: flex;
align-items: center;
gap: 12px;
max-width: 420px;
padding: 16px 20px;
background: var(--detail-surface);
color: var(--detail-text);
border: 1px solid #c7d6c2;
border-left: 4px solid var(--detail-primary);
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
font-size: 14px;
font-weight: 500;
line-height: 1.5;
overflow-wrap: anywhere;
}
.jarmark-product-detail .jarmark-detail-notification svg {
flex-shrink: 0;
color: var(--detail-primary);
}
/* ========================================
KEYBOARD ACCESSIBILITY
======================================== */
.jarmark-product-detail .jarmark-detail-back:focus-visible,
.jarmark-product-detail .jarmark-detail-button:focus-visible {
outline: 3px solid #527b49;
outline-offset: 4px;
}
/* ========================================
TABLET
======================================== */
@@media (max-width: 1024px) {
.jarmark-product-detail .jarmark-detail-card {
gap: 24px;
padding: 24px;
}
.jarmark-product-detail .jarmark-detail-title {
font-size: 32px;
}
.jarmark-product-detail .jarmark-detail-info {
padding: 4px 0;
}
.jarmark-product-detail .jarmark-detail-description {
font-size: 15px;
}
.jarmark-product-detail .jarmark-detail-image img {
padding: 16px;
} }
} }
/* ========================================
MOBILE
======================================== */
@@media (max-width: 768px) {
.jarmark-product-detail .jarmark-detail-card {
grid-template-columns: minmax(0, 1fr);
gap: 24px;
padding: 16px;
border-radius: 8px;
}
.jarmark-product-detail .jarmark-detail-back {
margin-bottom: 12px;
}
.jarmark-product-detail .jarmark-detail-image {
aspect-ratio: 4 / 3;
}
.jarmark-product-detail .jarmark-detail-info {
gap: 12px;
padding: 0;
}
.jarmark-product-detail .jarmark-detail-title {
font-size: 30px;
}
.jarmark-product-detail .jarmark-detail-description {
font-size: 15px;
line-height: 1.7;
}
.jarmark-product-detail .jarmark-detail-purchase {
gap: 16px;
margin-top: 8px;
padding-top: 20px;
}
.jarmark-product-detail .jarmark-detail-price {
font-size: 34px;
}
.jarmark-product-detail .jarmark-detail-button {
min-height: 52px;
padding: 12px 16px;
font-size: 15px;
}
.jarmark-product-detail .jarmark-detail-notification {
top: auto;
right: 12px;
bottom: 16px;
left: 12px;
max-width: none;
padding: 16px;
}
}
/* ========================================
SMALL MOBILE
======================================== */
@@media (max-width: 480px) {
.jarmark-product-detail .jarmark-detail-card {
gap: 20px;
padding: 12px;
}
.jarmark-product-detail .jarmark-detail-image {
aspect-ratio: 1 / 1;
}
.jarmark-product-detail .jarmark-detail-image img {
padding: 12px;
}
.jarmark-product-detail .jarmark-detail-title {
font-size: 28px;
}
.jarmark-product-detail .jarmark-detail-category {
font-size: 13px;
}
.jarmark-product-detail .jarmark-detail-empty {
padding: 20px;
}
.jarmark-product-detail .jarmark-detail-empty h2 {
font-size: 24px;
}
.jarmark-product-detail .jarmark-detail-empty .jarmark-detail-button {
width: 100%;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@@media (prefers-reduced-motion: reduce) {
.jarmark-product-detail,
.jarmark-product-detail * {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
</style>
@code { @code {
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
private Product? product; private Product? product;
private bool loading = true; private bool loading = true;
protected override async Task OnParametersSetAsync()
{
loading = true;
product = await DbContext.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == Id);
loading = false;
}
private string? cartToken; private string? cartToken;
private bool showNotification;
private string notificationMessage = "";
private CancellationTokenSource? notificationCts;
private bool imageFailed;
private void HandleImageError()
{
imageFailed = true;
}
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
if (!ApplicationState.TryTakeFromJson<string>( if (!ApplicationState.TryTakeFromJson<string>(
@@ -102,6 +837,18 @@ protected override async Task OnInitializedAsync()
} }
} }
protected override async Task OnParametersSetAsync()
{
loading = true;
imageFailed = false;
product = await DbContext.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == Id);
loading = false;
}
private async Task HandleAddToCart(Product product) private async Task HandleAddToCart(Product product)
{ {
if (string.IsNullOrWhiteSpace(cartToken)) if (string.IsNullOrWhiteSpace(cartToken))
@@ -147,5 +894,49 @@ private async Task HandleAddToCart(Product product)
cart.UpdatedAt = DateTime.UtcNow; cart.UpdatedAt = DateTime.UtcNow;
await DbContext.SaveChangesAsync(); await DbContext.SaveChangesAsync();
await ShowCartNotification(product.Name);
}
private async Task ShowCartNotification(string productName)
{
notificationCts?.Cancel();
var currentCts = new CancellationTokenSource();
notificationCts = currentCts;
notificationMessage = $"{productName} byl přidán do košíku.";
showNotification = true;
await InvokeAsync(StateHasChanged);
try
{
await Task.Delay(3500, currentCts.Token);
if (!currentCts.Token.IsCancellationRequested)
{
showNotification = false;
await InvokeAsync(StateHasChanged);
}
}
catch (OperationCanceledException)
{
// Nové přidání produktu restartovalo čas notifikace.
}
finally
{
if (ReferenceEquals(notificationCts, currentCts))
{
notificationCts = null;
currentCts.Dispose();
}
}
}
public void Dispose()
{
notificationCts?.Cancel();
notificationCts?.Dispose();
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,41 +1,75 @@
@using Web_Jarmark.Data.Models @using Web_Jarmark.Data.Models
@using Microsoft.AspNetCore.Components.Web
@inject NavigationManager NavigationManager
<article class="jarmark-product-card">
<!-- FOTOGRAFIE PRODUKTU -->
<div class="jarmark-card-picture">
<article class="market-card">
<div class="market-product-picture">
@if (!string.IsNullOrWhiteSpace(Product.ImageUrl) && !imageFailed) @if (!string.IsNullOrWhiteSpace(Product.ImageUrl) && !imageFailed)
{ {
<img src="@Product.ImageUrl.Trim()" <img src="@Product.ImageUrl.Trim()"
alt="@Product.Name" alt="@Product.Name"
loading="lazy" loading="lazy"
decoding="async"
@onerror="HandleImageError" /> @onerror="HandleImageError" />
} }
else else
{ {
<span class="product-icon">@ProductIcon</span> <div class="jarmark-card-placeholder"
aria-hidden="true">
<span>@ProductIcon</span>
</div>
} }
</div>
<!-- INFORMACE O PRODUKTU -->
<div class="jarmark-card-body">
@if (Product.Category is not null) @if (Product.Category is not null)
{ {
<span class="market-product-tag"> <div class="jarmark-card-category">
@Product.Category.Name
</span> @Product.Category.Name
}
</div> </div>
}
<h3 class="jarmark-card-title">
<a href="@($"/produkt/{Product.Id}")"
class="jarmark-card-detail">
@Product.Name
<div class="market-card-content">
<a href="@($"/produkt/{Product.Id}")" class="product-detail-link">
<h3>@Product.Name</h3>
</a> </a>
</h3>
@if (!string.IsNullOrWhiteSpace(Product.Description)) @if (!string.IsNullOrWhiteSpace(Product.Description))
{ {
<p class="market-description"> <p class="jarmark-card-description">
@Product.Description @Product.Description
</p> </p>
} }
<div class="market-stock">
<span class="market-stock-dot @(Product.StockQuantity <= 0 ? "out-of-stock" : "")"></span> <!-- DOSTUPNOST -->
<div class="jarmark-card-stock @(Product.StockQuantity <= 0 ? "is-unavailable" : "is-available")">
<span class="jarmark-stock-indicator"
aria-hidden="true">
</span>
@if (Product.StockQuantity > 0) @if (Product.StockQuantity > 0)
{ {
@@ -45,25 +79,488 @@
{ {
<span>Není skladem</span> <span>Není skladem</span>
} }
</div> </div>
<div class="market-card-bottom">
<!-- CENA A AKCE -->
<div class="jarmark-card-actions">
<div class="jarmark-card-price">
<strong>@Product.Price.ToString("N0") Kč</strong> <strong>@Product.Price.ToString("N0") Kč</strong>
</div> </div>
@if (OnAddToCart.HasDelegate) @if (OnAddToCart.HasDelegate)
{ {
<button type="button" <button type="button"
class="product-cart-button" class="jarmark-card-cart"
disabled="@(Product.StockQuantity <= 0)" disabled="@(Product.StockQuantity <= 0)"
@onclick="AddToCart"> aria-label="@($"Přidat do košíku: {Product.Name}")"
🛒 Do košíku @onclick="AddToCart"
@onclick:stopPropagation="true">
@if (Product.StockQuantity > 0)
{
<svg width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M3 3h2l3.5 13h10l3-10H6" />
<circle cx="10"
cy="20"
r="1" />
<circle cx="18"
cy="20"
r="1" />
</svg>
<span>Do košíku</span>
}
else
{
<span>Vyprodáno</span>
}
</button> </button>
} }
</div> </div>
</div>
</article> </article>
<style>
/* ========================================
PUBLIC PRODUCT CARD
======================================== */
.jarmark-product-card {
--card-primary: #244b36;
--card-primary-hover: #193b29;
--card-surface: #ffffff;
--card-text: #26372b;
--card-muted: #59665b;
--card-border: #dce3d9;
position: relative;
isolation: isolate;
display: flex;
flex-direction: column;
width: 100%;
min-width: 0;
height: 100%;
margin: 0;
padding: 0;
background: var(--card-surface);
color: var(--card-text);
border: 1px solid var(--card-border);
border-radius: 8px;
overflow: hidden;
box-sizing: border-box;
font-family: inherit;
transition: border-color 150ms ease;
}
.jarmark-product-card:hover {
border-color: #9aad96;
}
/* ========================================
PRODUCT IMAGE
======================================== */
.jarmark-product-card .jarmark-card-picture {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
aspect-ratio: 4 / 3;
overflow: hidden;
background: #edf0e9;
border-bottom: 1px solid var(--card-border);
}
.jarmark-product-card .jarmark-card-picture img {
display: block;
width: 100%;
height: 100%;
max-width: 100%;
object-fit: contain;
object-position: center;
margin: 0;
padding: 12px;
box-sizing: border-box;
}
/* ========================================
IMAGE FALLBACK
======================================== */
.jarmark-product-card .jarmark-card-placeholder {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
min-height: 120px;
background: #e6eddf;
color: var(--card-primary);
}
.jarmark-product-card .jarmark-card-placeholder span {
display: block;
font-size: 48px;
line-height: 1;
}
/* ========================================
CARD CONTENT
======================================== */
.jarmark-product-card .jarmark-card-body {
display: flex;
flex: 1;
flex-direction: column;
gap: 12px;
min-width: 0;
padding: 20px;
}
/* ========================================
CATEGORY
======================================== */
.jarmark-product-card .jarmark-card-category {
margin: 0;
color: var(--card-muted);
font-size: 13px;
font-weight: 500;
line-height: 1.4;
letter-spacing: normal;
text-transform: none;
overflow-wrap: anywhere;
}
/* ========================================
PRODUCT NAME AND DETAIL LINK
======================================== */
.jarmark-product-card .jarmark-card-title {
margin: 0;
color: var(--card-text);
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 700;
line-height: 1.3;
letter-spacing: normal;
overflow-wrap: anywhere;
}
.jarmark-product-card .jarmark-card-detail {
color: inherit;
text-decoration: none;
}
.jarmark-product-card .jarmark-card-detail:hover {
color: var(--card-primary);
text-decoration: underline;
text-underline-offset: 4px;
}
/*
Celá karta zůstává kliknutelná.
Tlačítko košíku má vlastní vrstvu.
*/
.jarmark-product-card .jarmark-card-detail::after {
content: "";
position: absolute;
inset: 0;
z-index: 1;
border-radius: 8px;
}
.jarmark-product-card .jarmark-card-detail:focus-visible::after {
outline: 3px solid #527b49;
outline-offset: -3px;
}
/* ========================================
DESCRIPTION
======================================== */
.jarmark-product-card .jarmark-card-description {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
overflow-wrap: anywhere;
margin: 0;
color: var(--card-muted);
font-size: 14px;
line-height: 1.6;
}
/* ========================================
STOCK AVAILABILITY
======================================== */
.jarmark-product-card .jarmark-card-stock {
display: flex;
align-items: center;
gap: 8px;
margin: 4px 0 0;
font-size: 13px;
font-weight: 600;
line-height: 1.4;
}
.jarmark-product-card .jarmark-stock-indicator {
display: inline-block;
flex-shrink: 0;
width: 8px;
height: 8px;
background: currentColor;
border-radius: 50%;
}
.jarmark-product-card .is-available {
color: #34754b;
}
.jarmark-product-card .is-unavailable {
color: #93483e;
}
/* ========================================
PRICE AND ACTIONS
======================================== */
.jarmark-product-card .jarmark-card-actions {
display: flex;
flex-direction: column;
gap: 12px;
margin-top: auto;
padding-top: 12px;
}
.jarmark-product-card .jarmark-card-price {
display: flex;
align-items: baseline;
margin: 0;
color: var(--card-primary);
font-size: 26px;
line-height: 1.2;
font-variant-numeric: tabular-nums;
}
.jarmark-product-card .jarmark-card-price strong {
font-weight: 750;
}
/* ========================================
ADD TO CART BUTTON
======================================== */
.jarmark-product-card .jarmark-card-cart {
position: relative;
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
width: 100%;
min-height: 48px;
margin: 0;
padding: 12px 16px;
background: var(--card-primary);
color: #ffffff;
border: 1px solid var(--card-primary);
border-radius: 6px;
font-family: inherit;
font-size: 14px;
font-weight: 650;
line-height: 1.4;
text-align: center;
cursor: pointer;
transition: background-color 150ms ease, border-color 150ms ease;
}
.jarmark-product-card .jarmark-card-cart svg {
flex-shrink: 0;
}
.jarmark-product-card .jarmark-card-cart:not(:disabled):hover {
background: var(--card-primary-hover);
border-color: var(--card-primary-hover);
color: #ffffff;
}
.jarmark-product-card .jarmark-card-cart:disabled {
background: #e9ece7;
color: #59665b;
border-color: #dce3d9;
opacity: 1;
cursor: not-allowed;
}
.jarmark-product-card .jarmark-card-cart:focus-visible {
outline: 3px solid #527b49;
outline-offset: 3px;
}
/* ========================================
TABLET
======================================== */
@@media (max-width: 1024px) {
.jarmark-product-card .jarmark-card-body {
padding: 16px;
}
.jarmark-product-card .jarmark-card-title {
font-size: 20px;
}
.jarmark-product-card .jarmark-card-price {
font-size: 24px;
}
}
/* ========================================
MOBILE
======================================== */
@@media (max-width: 640px) {
.jarmark-product-card .jarmark-card-body {
gap: 8px;
padding: 12px;
}
.jarmark-product-card .jarmark-card-title {
font-size: 18px;
}
.jarmark-product-card .jarmark-card-category {
font-size: 12px;
}
.jarmark-product-card .jarmark-card-description {
font-size: 13px;
-webkit-line-clamp: 2;
}
.jarmark-product-card .jarmark-card-stock {
gap: 4px;
font-size: 12px;
}
.jarmark-product-card .jarmark-card-price {
font-size: 22px;
}
.jarmark-product-card .jarmark-card-cart {
min-height: 48px;
padding: 12px 8px;
font-size: 13px;
}
.jarmark-product-card .jarmark-card-cart svg {
width: 18px;
height: 18px;
}
.jarmark-product-card .jarmark-card-placeholder span {
font-size: 40px;
}
}
/* ========================================
SINGLE COLUMN MOBILE
======================================== */
@@media (max-width: 480px) {
.jarmark-product-card .jarmark-card-body {
gap: 12px;
padding: 16px;
}
.jarmark-product-card .jarmark-card-title {
font-size: 22px;
}
.jarmark-product-card .jarmark-card-description {
font-size: 14px;
-webkit-line-clamp: 3;
}
.jarmark-product-card .jarmark-card-category {
font-size: 13px;
}
.jarmark-product-card .jarmark-card-stock {
gap: 8px;
font-size: 13px;
}
.jarmark-product-card .jarmark-card-price {
font-size: 26px;
}
.jarmark-product-card .jarmark-card-cart {
font-size: 15px;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@@media (prefers-reduced-motion: reduce) {
.jarmark-product-card,
.jarmark-product-card * {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
</style>
@code { @code {
[Parameter, EditorRequired] [Parameter, EditorRequired]
public Product Product { get; set; } = default!; public Product Product { get; set; } = default!;
@@ -72,30 +569,38 @@
private bool imageFailed; private bool imageFailed;
protected override void OnParametersSet() protected override void OnParametersSet()
{ {
imageFailed = false; imageFailed = false;
} }
private void HandleImageError() private void HandleImageError()
{ {
imageFailed = true; imageFailed = true;
} }
private string ProductIcon => private string ProductIcon =>
Product.Category?.Name.Contains( Product.Category?.Name.Contains(
"med", "med",
StringComparison.OrdinalIgnoreCase) == true ? "🍯" : StringComparison.OrdinalIgnoreCase) == true ? "🍯" :
Product.Category?.Name.Contains( Product.Category?.Name.Contains(
"cuk", "cuk",
StringComparison.OrdinalIgnoreCase) == true ? "🍪" : StringComparison.OrdinalIgnoreCase) == true ? "🍪" :
Product.Category?.Name.Contains( Product.Category?.Name.Contains(
"dřev", "dřev",
StringComparison.OrdinalIgnoreCase) == true ? "🪵" : StringComparison.OrdinalIgnoreCase) == true ? "🪵" :
"🎁"; "🎁";
private async Task AddToCart() private async Task AddToCart()
{ {
await OnAddToCart.InvokeAsync(Product); await OnAddToCart.InvokeAsync(Product);
} }
} }

View File

@@ -1,39 +1,45 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Web_Jarmark.Data;
using Web_Jarmark.Data.Models; using Web_Jarmark.Data.Models;
namespace Web_Jarmark.Data namespace Web_Jarmark.Data
{ {
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : IdentityDbContext<ApplicationUser>(options) public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: IdentityDbContext<ApplicationUser>(options)
{ {
public DbSet<Category> Categories { get; set; } public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; } public DbSet<Product> Products { get; set; }
public DbSet<Cart> Carts { get; set; } public DbSet<Cart> Carts { get; set; }
public DbSet<CartItem> CartItems { get; set; } public DbSet<CartItem> CartItems { get; set; }
// Objednávky
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
// Nastavení vazby 1:N mezi Category a Product // Kategorie a produkty
modelBuilder.Entity<Category>() modelBuilder.Entity<Category>()
.HasMany(c => c.Products) // Jedna kategorie obsahuje mnoho produktů .HasMany(c => c.Products)
.WithOne(p => p.Category) // Každý produkt patří ke jedné kategorii .WithOne(p => p.Category)
.HasForeignKey(p => p.CategoryId); // Cizí klíč v tabulce Product .HasForeignKey(p => p.CategoryId);
// Jeden košík obsahuje více položek // Košík a položky košíku
modelBuilder.Entity<Cart>() modelBuilder.Entity<Cart>()
.HasMany(c => c.CartItems) .HasMany(c => c.CartItems)
.WithOne(ci => ci.Cart) .WithOne(ci => ci.Cart)
.HasForeignKey(ci => ci.CartId); .HasForeignKey(ci => ci.CartId);
// Každá položka odkazuje na jeden produkt // Položka košíku odkazuje na produkt
modelBuilder.Entity<CartItem>() modelBuilder.Entity<CartItem>()
.HasOne(ci => ci.Product) .HasOne(ci => ci.Product)
.WithMany() .WithMany()
.HasForeignKey(ci => ci.ProductId); .HasForeignKey(ci => ci.ProductId);
// Jeden produkt může být v košíku pouze jednou // Produkt může být v košíku pouze jednou
modelBuilder.Entity<CartItem>() modelBuilder.Entity<CartItem>()
.HasIndex(ci => new { ci.CartId, ci.ProductId }) .HasIndex(ci => new { ci.CartId, ci.ProductId })
.IsUnique(); .IsUnique();
@@ -42,7 +48,25 @@ namespace Web_Jarmark.Data
modelBuilder.Entity<Cart>() modelBuilder.Entity<Cart>()
.HasIndex(c => c.Token) .HasIndex(c => c.Token)
.IsUnique(); .IsUnique();
}
}
// Zachování původních názvů tabulek objednávek
modelBuilder.Entity<Order>()
.ToTable("Order");
modelBuilder.Entity<OrderItem>()
.ToTable("OrderItem");
// Objednávka a její položky
modelBuilder.Entity<Order>()
.HasMany(o => o.OrderItems)
.WithOne(oi => oi.Order)
.HasForeignKey(oi => oi.OrderId);
// Položka objednávky odkazuje na produkt
modelBuilder.Entity<OrderItem>()
.HasOne(oi => oi.Product)
.WithMany(p => p.OrderItems)
.HasForeignKey(oi => oi.ProductId);
}
}
} }

View File

@@ -1,10 +1,17 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
namespace Web_Jarmark.Data namespace Web_Jarmark.Data
{ {
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser public class ApplicationUser : IdentityUser
{ {
} // Jméno uživatele
public string? FirstName { get; set; }
// Příjmení uživatele
public string? LastName { get; set; }
// Datum registrace
public DateTime? CreatedAt { get; set; }
}
} }

View File

@@ -1,4 +1,5 @@
namespace Web_Jarmark.Data.Models
namespace Web_Jarmark.Data.Models
{ {
public enum OrderStatus public enum OrderStatus
{ {
@@ -8,6 +9,7 @@
Delivered, Delivered,
Cancelled Cancelled
} }
public enum PaymentMethod public enum PaymentMethod
{ {
CreditCard, CreditCard,
@@ -19,23 +21,36 @@
public class Order public class Order
{ {
public int Id { get; set; } public int Id { get; set; }
public string Code { get; set; }
public OrderStatus Status { get; set; } public string Code { get; set; } =
public string CustomerName { get; set; } Guid.NewGuid().ToString("N")[..8].ToUpper();
public string Email { get; set; }
public string Phone { get; set; } // Bezpečný přístup k detailu objednávky
public string Note { get; set; } public string AccessTokenHash { get; set; } = string.Empty;
public OrderStatus Status { get; set; } = OrderStatus.Pending;
// Původní údaje zachované kvůli databázi
public string CustomerName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Note { get; set; } = string.Empty;
public PaymentMethod PreferredPayment { get; set; } public PaymentMethod PreferredPayment { get; set; }
public string PaymentReference { get; set; }
public string PaymentReference { get; set; } = string.Empty;
public decimal TotalAmount { get; set; } public decimal TotalAmount { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? ExpiresAt { get; set; } public DateTime? ExpiresAt { get; set; }
public DateTime? PaidAt { get; set; } public DateTime? PaidAt { get; set; }
public DateTime? IssuedAt { get; set; } public DateTime? IssuedAt { get; set; }
public string IssuedByUserId { get; set; } public string IssuedByUserId { get; set; } = string.Empty;
public DateTime? CancelledAt { get; set; } public DateTime? CancelledAt { get; set; }
// Navigační vlastnost pro objednávací položky public ICollection<OrderItem> OrderItems { get; set; }
public ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>(); = new List<OrderItem>();
} }
} }

View File

@@ -0,0 +1,624 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Web_Jarmark.Data;
#nullable disable
namespace Web_Jarmark.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20261104173931_AddCreatedAtToUsers")]
partial class AddCreatedAtToUsers
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.13");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.Property<byte[]>("CredentialId")
.HasMaxLength(1024)
.HasColumnType("BLOB");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("CredentialId");
b.HasIndex("UserId");
b.ToTable("AspNetUserPasskeys", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Carts");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CartId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("CartId", "ProductId")
.IsUnique();
b.ToTable("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CustomerName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<DateTime?>("IssuedAt")
.HasColumnType("TEXT");
b.Property<string>("IssuedByUserId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Note")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("PaidAt")
.HasColumnType("TEXT");
b.Property<string>("PaymentReference")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferredPayment")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<decimal>("TotalAmount")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Order");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OrderId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<decimal>("UnitPrice")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderItem");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CategoryId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageUrl")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsVisible")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("Price")
.HasColumnType("TEXT");
b.Property<int>("StockQuantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Products");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsOne("Microsoft.AspNetCore.Identity.IdentityPasskeyData", "Data", b1 =>
{
b1.Property<byte[]>("IdentityUserPasskeyCredentialId");
b1.Property<byte[]>("AttestationObject")
.IsRequired();
b1.Property<byte[]>("ClientDataJson")
.IsRequired();
b1.Property<DateTimeOffset>("CreatedAt");
b1.Property<bool>("IsBackedUp");
b1.Property<bool>("IsBackupEligible");
b1.Property<bool>("IsUserVerified");
b1.Property<string>("Name");
b1.Property<byte[]>("PublicKey")
.IsRequired();
b1.Property<uint>("SignCount");
b1.PrimitiveCollection<string>("Transports");
b1.HasKey("IdentityUserPasskeyCredentialId");
b1.ToTable("AspNetUserPasskeys");
b1
.ToJson("Data")
.HasColumnType("TEXT");
b1.WithOwner()
.HasForeignKey("IdentityUserPasskeyCredentialId");
});
b.Navigation("Data")
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Cart", "Cart")
.WithMany("CartItems")
.HasForeignKey("CartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cart");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Order", "Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany("OrderItems")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Category", "Category")
.WithMany("Products")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Navigation("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Navigation("OrderItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Navigation("OrderItems");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Web_Jarmark.Migrations
{
/// <inheritdoc />
public partial class AddCreatedAtToUsers : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "FirstName",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LastName",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "FirstName",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "LastName",
table: "AspNetUsers");
}
}
}

View File

@@ -0,0 +1,628 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Web_Jarmark.Data;
#nullable disable
namespace Web_Jarmark.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20261106180726_AddOrderAccessTokenHash")]
partial class AddOrderAccessTokenHash
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.13");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.Property<byte[]>("CredentialId")
.HasMaxLength(1024)
.HasColumnType("BLOB");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("CredentialId");
b.HasIndex("UserId");
b.ToTable("AspNetUserPasskeys", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Carts");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CartId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("CartId", "ProductId")
.IsUnique();
b.ToTable("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AccessTokenHash")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CustomerName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<DateTime?>("IssuedAt")
.HasColumnType("TEXT");
b.Property<string>("IssuedByUserId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Note")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("PaidAt")
.HasColumnType("TEXT");
b.Property<string>("PaymentReference")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferredPayment")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<decimal>("TotalAmount")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Order", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OrderId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<decimal>("UnitPrice")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderItem", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CategoryId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageUrl")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsVisible")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("Price")
.HasColumnType("TEXT");
b.Property<int>("StockQuantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Products");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsOne("Microsoft.AspNetCore.Identity.IdentityPasskeyData", "Data", b1 =>
{
b1.Property<byte[]>("IdentityUserPasskeyCredentialId");
b1.Property<byte[]>("AttestationObject")
.IsRequired();
b1.Property<byte[]>("ClientDataJson")
.IsRequired();
b1.Property<DateTimeOffset>("CreatedAt");
b1.Property<bool>("IsBackedUp");
b1.Property<bool>("IsBackupEligible");
b1.Property<bool>("IsUserVerified");
b1.Property<string>("Name");
b1.Property<byte[]>("PublicKey")
.IsRequired();
b1.Property<uint>("SignCount");
b1.PrimitiveCollection<string>("Transports");
b1.HasKey("IdentityUserPasskeyCredentialId");
b1.ToTable("AspNetUserPasskeys");
b1
.ToJson("Data")
.HasColumnType("TEXT");
b1.WithOwner()
.HasForeignKey("IdentityUserPasskeyCredentialId");
});
b.Navigation("Data")
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Cart", "Cart")
.WithMany("CartItems")
.HasForeignKey("CartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cart");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Order", "Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany("OrderItems")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Category", "Category")
.WithMany("Products")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Navigation("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Navigation("OrderItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Navigation("OrderItems");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Web_Jarmark.Migrations
{
/// <inheritdoc />
public partial class AddOrderAccessTokenHash : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "AccessTokenHash",
table: "Order",
type: "TEXT",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AccessTokenHash",
table: "Order");
}
}
}

View File

@@ -178,6 +178,9 @@ namespace Web_Jarmark.Migrations
.IsConcurrencyToken() .IsConcurrencyToken()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Email") b.Property<string>("Email")
.HasMaxLength(256) .HasMaxLength(256)
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -185,6 +188,12 @@ namespace Web_Jarmark.Migrations
b.Property<bool>("EmailConfirmed") b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<bool>("LockoutEnabled") b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
@@ -308,6 +317,10 @@ namespace Web_Jarmark.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("AccessTokenHash")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("CancelledAt") b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -362,7 +375,7 @@ namespace Web_Jarmark.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Order"); b.ToTable("Order", (string)null);
}); });
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b => modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
@@ -393,7 +406,7 @@ namespace Web_Jarmark.Migrations
b.HasIndex("ProductId"); b.HasIndex("ProductId");
b.ToTable("OrderItem"); b.ToTable("OrderItem", (string)null);
}); });
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b => modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>

View File

@@ -1,3 +1,4 @@
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@@ -7,11 +8,12 @@ using Web_Jarmark.Data;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents() builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(); .AddInteractiveServerComponents();
builder.Services.AddAuthorization();
builder.Services.AddCascadingAuthenticationState(); builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped<IdentityRedirectManager>(); builder.Services.AddScoped<IdentityRedirectManager>();
builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>(); builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();
@@ -22,9 +24,12 @@ builder.Services.AddAuthentication(options =>
}) })
.AddIdentityCookies(); .AddIdentityCookies();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options => builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString)); options.UseSqlite(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentityCore<ApplicationUser>(options => builder.Services.AddIdentityCore<ApplicationUser>(options =>
@@ -32,15 +37,35 @@ builder.Services.AddIdentityCore<ApplicationUser>(options =>
options.SignIn.RequireConfirmedAccount = true; options.SignIn.RequireConfirmedAccount = true;
options.Stores.SchemaVersion = IdentitySchemaVersions.Version3; options.Stores.SchemaVersion = IdentitySchemaVersions.Version3;
}) })
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>() .AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager() .AddSignInManager()
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>(); builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpContextAccessor();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Vytvoření role Admin, pokud ještě neexistuje
using (var scope = app.Services.CreateScope())
{
var roleManager = scope.ServiceProvider
.GetRequiredService<RoleManager<IdentityRole>>();
if (!await roleManager.RoleExistsAsync("Admin"))
{
var result = await roleManager.CreateAsync(new IdentityRole("Admin"));
if (!result.Succeeded)
{
throw new InvalidOperationException(
"Nepodařilo se vytvořit roli Admin: "
+ string.Join(", ", result.Errors.Select(e => e.Description)));
}
}
}
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {
app.UseMigrationsEndPoint(); app.UseMigrationsEndPoint();
@@ -48,12 +73,15 @@ if (app.Environment.IsDevelopment())
else else
{ {
app.UseExceptionHandler("/Error", createScopeForErrors: true); app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.Use(async (context, next) => app.Use(async (context, next) =>
{ {
const string cookieName = "CartToken"; const string cookieName = "CartToken";
@@ -73,16 +101,18 @@ app.Use(async (context, next) =>
}); });
} }
context.Items["CartToken"] = token;
await next(); await next();
}); });
app.UseAntiforgery(); app.UseAntiforgery();
app.MapStaticAssets(); app.MapStaticAssets();
app.MapRazorComponents<App>() app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode(); .AddInteractiveServerRenderMode();
// Add additional endpoints required by the Identity /Account Razor components.
app.MapAdditionalIdentityEndpoints(); app.MapAdditionalIdentityEndpoints();
app.Run(); app.Run();

Binary file not shown.

File diff suppressed because it is too large Load Diff