web: seznam Moje hlášení
Závady nahlášené přihlášeným uživatelem od nejnovějších: filtr podle stavu, stránkování, štítky stavů, kategorie a místo z číselníků a čas v českém pásmu. Položka v menu a site.js pro automatické odeslání filtru (bez inline skriptů kvůli CSP). Refs #22
This commit is contained in:
1 parent
6208fd3baf
commit
2fe939ba5c
10 files changed
+217
No files matched your search
@@ -45,3 +45,21 @@ public sealed record ForgotPasswordRequest(string Email);
|
||||
public sealed record ResetPasswordRequest(string Token, string NewPassword);
|
||||
|
||||
public sealed record UpdateProfileRequest(string FirstName, string LastName, string? Phone, bool EmailNotificationsEnabled);
|
||||
|
||||
/// <summary>Stránkovaný seznam z API: <c>{ items, totalCount, page, pageSize }</c>.</summary>
|
||||
public sealed record PagedResult<T>(IReadOnlyList<T> Items, int TotalCount, int Page, int PageSize)
|
||||
{
|
||||
public int PageCount => PageSize <= 0 ? 0 : (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
}
|
||||
|
||||
public sealed record CategoryDto(int Id, string Name, string? Description, bool IsActive);
|
||||
|
||||
public sealed record BuildingDto(int Id, string Code, string Name, string? Address, bool IsActive);
|
||||
|
||||
/// <summary>Závada v seznamu. Kategorie a budova jsou jen ID – názvy doplňuje web z číselníků.</summary>
|
||||
public sealed record IssueSummary(
|
||||
int Id, string Title, int CategoryId, int? BuildingId, string? LocationDetail, string Status,
|
||||
string Priority, int ReporterId, int? AssigneeId, DateTimeOffset CreatedAt);
|
||||
|
||||
/// <summary>Filtry <c>GET /api/v1/issues</c>; prázdné hodnoty se do dotazu neposílají.</summary>
|
||||
public sealed record IssueListQuery(string? Status = null, bool Mine = false, string Sort = "newest", int Page = 1, int PageSize = 20);
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Globalization;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
namespace Helpdesk.Web.Api;
|
||||
|
||||
@@ -17,6 +19,32 @@ public sealed class HelpdeskApiClient(HttpClient http)
|
||||
return await ApiResponse.ReadAsync<UserDto>(response, ct);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IssueSummary>> GetIssuesAsync(IssueListQuery query, CancellationToken ct)
|
||||
{
|
||||
var parameters = new Dictionary<string, string?>
|
||||
{
|
||||
["status"] = query.Status,
|
||||
["mine"] = query.Mine ? "true" : null,
|
||||
["sort"] = query.Sort,
|
||||
["page"] = query.Page.ToString(CultureInfo.InvariantCulture),
|
||||
["pageSize"] = query.PageSize.ToString(CultureInfo.InvariantCulture),
|
||||
};
|
||||
using var response = await http.GetAsync(QueryHelpers.AddQueryString("api/v1/issues", parameters.Where(p => !string.IsNullOrEmpty(p.Value))), ct);
|
||||
return await ApiResponse.ReadAsync<PagedResult<IssueSummary>>(response, ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<CategoryDto>> GetIssueCategoriesAsync(CancellationToken ct)
|
||||
{
|
||||
using var response = await http.GetAsync("api/v1/issue-categories", ct);
|
||||
return await ApiResponse.ReadAsync<List<CategoryDto>>(response, ct);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<BuildingDto>> GetBuildingsAsync(CancellationToken ct)
|
||||
{
|
||||
using var response = await http.GetAsync("api/v1/buildings", ct);
|
||||
return await ApiResponse.ReadAsync<List<BuildingDto>>(response, ct);
|
||||
}
|
||||
|
||||
/// <summary>Odhlásí ze všech zařízení – API zneplatní všechny tokeny uživatele.</summary>
|
||||
public async Task LogoutAllAsync(CancellationToken ct)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Helpdesk.Web.Api;
|
||||
using Helpdesk.Web.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Helpdesk.Web.Controllers;
|
||||
|
||||
/// <summary>Hlášení závad (FR-10 – FR-17).</summary>
|
||||
[Route("issues")]
|
||||
public sealed class IssuesController(HelpdeskApiClient api) : Controller
|
||||
{
|
||||
/// <summary>Moje hlášení – závady, které uživatel nahlásil, od nejnovějších.</summary>
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> Index(string? status, int page = 1, CancellationToken ct = default)
|
||||
{
|
||||
if (status is not null && !IssueListViewModel.Statuses.Contains(status))
|
||||
status = null;
|
||||
|
||||
var issues = await api.GetIssuesAsync(new IssueListQuery(status, Mine: true, Page: Math.Max(page, 1)), ct);
|
||||
// API vrací u závady jen ID kategorie a budovy – názvy doplníme z číselníků.
|
||||
var categories = await api.GetIssueCategoriesAsync(ct);
|
||||
var buildings = await api.GetBuildingsAsync(ct);
|
||||
|
||||
return View(new IssueListViewModel
|
||||
{
|
||||
Issues = issues,
|
||||
CategoryNames = categories.ToDictionary(c => c.Id, c => c.Name),
|
||||
BuildingNames = buildings.ToDictionary(b => b.Id, b => b.Name),
|
||||
Status = status,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Helpdesk.Web.Infrastructure;
|
||||
|
||||
/// <summary>API vrací časy v UTC; uživatelům je zobrazujeme v českém čase (kap. 12.6 návrhu).</summary>
|
||||
public static class DisplayTime
|
||||
{
|
||||
private static readonly TimeZoneInfo Prague = TimeZoneInfo.FindSystemTimeZoneById("Europe/Prague");
|
||||
private static readonly CultureInfo Czech = CultureInfo.GetCultureInfo("cs-CZ");
|
||||
|
||||
public static DateTimeOffset ToLocal(DateTimeOffset utc) => TimeZoneInfo.ConvertTime(utc, Prague);
|
||||
|
||||
/// <summary>Např. „3. 10. 2026 14:05“.</summary>
|
||||
public static string Format(DateTimeOffset utc) => ToLocal(utc).ToString("d. M. yyyy H:mm", Czech);
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public static class Navigation
|
||||
public static readonly IReadOnlyList<NavItem> Items =
|
||||
[
|
||||
new("Nástěnka", "Home", "Index"),
|
||||
new("Moje hlášení", "Issues", "Index"),
|
||||
];
|
||||
|
||||
public static IEnumerable<NavItem> For(ClaimsPrincipal user) => Items.Where(i => i.IsVisibleTo(user));
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Helpdesk.Web.Api;
|
||||
|
||||
namespace Helpdesk.Web.Models;
|
||||
|
||||
public sealed class IssueListViewModel
|
||||
{
|
||||
/// <summary>Stavy závady v pořadí životního cyklu (kap. 6 návrhu) pro filtr.</summary>
|
||||
public static readonly IReadOnlyList<string> Statuses =
|
||||
["RECEIVED", "ASSIGNED", "IN_PROGRESS", "PENDING_VERIFICATION", "RESOLVED", "REJECTED"];
|
||||
|
||||
public required PagedResult<IssueSummary> Issues { get; init; }
|
||||
public required IReadOnlyDictionary<int, string> CategoryNames { get; init; }
|
||||
public required IReadOnlyDictionary<int, string> BuildingNames { get; init; }
|
||||
public string? Status { get; init; }
|
||||
|
||||
public string CategoryName(int id) => CategoryNames.GetValueOrDefault(id, "Neznámá kategorie");
|
||||
|
||||
/// <summary>Budova a upřesnění místa, např. „Budova B – učebna B-205“.</summary>
|
||||
public string? Location(IssueSummary issue)
|
||||
{
|
||||
var building = issue.BuildingId is { } id ? BuildingNames.GetValueOrDefault(id) : null;
|
||||
return (building, issue.LocationDetail) switch
|
||||
{
|
||||
(null, null or "") => null,
|
||||
(null, var detail) => detail,
|
||||
(var b, null or "") => b,
|
||||
var (b, detail) => $"{b} – {detail}",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
@model IssueListViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Moje hlášení";
|
||||
var result = Model.Issues;
|
||||
}
|
||||
|
||||
<section class="app-page-head d-flex flex-wrap align-items-end justify-content-between gap-3">
|
||||
<div>
|
||||
<h1>Moje hlášení</h1>
|
||||
<p class="text-body-secondary mb-0">Závady, které jste nahlásili, a v jakém stavu je jejich řešení.</p>
|
||||
</div>
|
||||
<form method="get" asp-action="Index" class="d-flex gap-2 align-items-center">
|
||||
<label for="status" class="form-label mb-0 text-nowrap">Stav</label>
|
||||
<select id="status" name="status" class="form-select" data-autosubmit>
|
||||
<option value="">Všechny</option>
|
||||
@foreach (var status in IssueListViewModel.Statuses)
|
||||
{
|
||||
<option value="@status" selected="@(status == Model.Status)">@StatusLabels.For(status)</option>
|
||||
}
|
||||
</select>
|
||||
<noscript><button type="submit" class="btn btn-outline-primary">Filtrovat</button></noscript>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
@if (result.Items.Count == 0)
|
||||
{
|
||||
<div class="app-card app-empty-card">
|
||||
<h2 class="h6 fw-bold">@(Model.Status is null ? "Zatím jste nic nenahlásili" : "V tomto stavu nemáte žádné hlášení")</h2>
|
||||
<p class="text-body-secondary mb-0">
|
||||
@(Model.Status is null
|
||||
? "Až nahlásíte závadu, uvidíte ji tady i s tím, jak se řeší."
|
||||
: "Zkuste vybrat jiný stav, nebo zobrazit všechna hlášení.")
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="app-issue-list">
|
||||
@foreach (var issue in result.Items)
|
||||
{
|
||||
var location = Model.Location(issue);
|
||||
<li class="app-card app-issue">
|
||||
<div class="app-issue-main">
|
||||
<span class="app-issue-id">#@issue.Id</span>
|
||||
<h2 class="app-issue-title">@issue.Title</h2>
|
||||
<p class="app-issue-meta">
|
||||
@Model.CategoryName(issue.CategoryId)
|
||||
@if (location is not null)
|
||||
{
|
||||
<span aria-hidden="true">·</span> @location
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
<div class="app-issue-side">
|
||||
<partial name="_StatusBadge" model="new StatusBadgeModel(issue.Status)" />
|
||||
<time datetime="@issue.CreatedAt.ToString("O")">@DisplayTime.Format(issue.CreatedAt)</time>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
@if (result.PageCount > 1)
|
||||
{
|
||||
<nav aria-label="Stránkování" class="mt-4">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item @(result.Page <= 1 ? "disabled" : "")">
|
||||
<a class="page-link" asp-action="Index" asp-route-status="@Model.Status" asp-route-page="@(result.Page - 1)">Předchozí</a>
|
||||
</li>
|
||||
<li class="page-item disabled"><span class="page-link">Strana @result.Page z @result.PageCount</span></li>
|
||||
<li class="page-item @(result.Page >= result.PageCount ? "disabled" : "")">
|
||||
<a class="page-link" asp-action="Index" asp-route-status="@Model.Status" asp-route-page="@(result.Page + 1)">Další</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@
|
||||
</footer>
|
||||
|
||||
<script src="~/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -107,6 +107,17 @@ body { min-height: 100vh; display: flex; flex-direction: column; }
|
||||
|
||||
.app-footer { padding-block: 1.25rem; color: var(--app-muted); font-size: .875rem; border-top: 1px solid var(--app-line); }
|
||||
|
||||
/* seznam závad – karta jako IssueCard v mobilu */
|
||||
.app-issue-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
|
||||
.app-issue { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem 1.5rem; padding: 1.1rem 1.4rem; }
|
||||
.app-issue-main { min-width: 0; flex: 1 1 20rem; }
|
||||
.app-issue-id { font-size: .8rem; font-weight: 600; color: var(--app-muted); font-variant-numeric: tabular-nums; }
|
||||
.app-issue-title { font-size: 1.05rem; font-weight: 700; margin: .1rem 0 .25rem; overflow-wrap: anywhere; }
|
||||
.app-issue-meta { margin: 0; color: var(--app-muted); font-size: .925rem; }
|
||||
.app-issue-side { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; font-size: .85rem; color: var(--app-muted); font-variant-numeric: tabular-nums; }
|
||||
@media (max-width: 575.98px) { .app-issue-side { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; } }
|
||||
.app-empty-card { text-align: center; padding-block: 2.5rem; }
|
||||
|
||||
/* Štítek stavu jako StatusBadge v mobilu: tečka a text v barvě stavu na pozadí s 11 % té barvy. */
|
||||
.status-badge {
|
||||
--status-color: var(--status-neutral);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Drobné chování stránek. CSP nepovoluje inline skripty ani atributy onchange, proto vše tady.
|
||||
|
||||
// <select data-autosubmit> odešle svůj formulář hned po změně (filtry seznamů).
|
||||
document.querySelectorAll("[data-autosubmit]").forEach((element) => {
|
||||
element.addEventListener("change", () => element.form?.requestSubmit());
|
||||
});
|
||||
Reference in new issue
Block a user