diff --git a/web/Helpdesk.Web/Api/ApiModels.cs b/web/Helpdesk.Web/Api/ApiModels.cs index b09772b..96751ce 100644 --- a/web/Helpdesk.Web/Api/ApiModels.cs +++ b/web/Helpdesk.Web/Api/ApiModels.cs @@ -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); + +/// Stránkovaný seznam z API: { items, totalCount, page, pageSize }. +public sealed record PagedResult(IReadOnlyList 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); + +/// Závada v seznamu. Kategorie a budova jsou jen ID – názvy doplňuje web z číselníků. +public sealed record IssueSummary( + int Id, string Title, int CategoryId, int? BuildingId, string? LocationDetail, string Status, + string Priority, int ReporterId, int? AssigneeId, DateTimeOffset CreatedAt); + +/// Filtry GET /api/v1/issues; prázdné hodnoty se do dotazu neposílají. +public sealed record IssueListQuery(string? Status = null, bool Mine = false, string Sort = "newest", int Page = 1, int PageSize = 20); diff --git a/web/Helpdesk.Web/Api/HelpdeskApiClient.cs b/web/Helpdesk.Web/Api/HelpdeskApiClient.cs index 2ac3395..35ea6cc 100644 --- a/web/Helpdesk.Web/Api/HelpdeskApiClient.cs +++ b/web/Helpdesk.Web/Api/HelpdeskApiClient.cs @@ -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(response, ct); } + public async Task> GetIssuesAsync(IssueListQuery query, CancellationToken ct) + { + var parameters = new Dictionary + { + ["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>(response, ct); + } + + public async Task> GetIssueCategoriesAsync(CancellationToken ct) + { + using var response = await http.GetAsync("api/v1/issue-categories", ct); + return await ApiResponse.ReadAsync>(response, ct); + } + + public async Task> GetBuildingsAsync(CancellationToken ct) + { + using var response = await http.GetAsync("api/v1/buildings", ct); + return await ApiResponse.ReadAsync>(response, ct); + } + /// Odhlásí ze všech zařízení – API zneplatní všechny tokeny uživatele. public async Task LogoutAllAsync(CancellationToken ct) { diff --git a/web/Helpdesk.Web/Controllers/IssuesController.cs b/web/Helpdesk.Web/Controllers/IssuesController.cs new file mode 100644 index 0000000..f62c033 --- /dev/null +++ b/web/Helpdesk.Web/Controllers/IssuesController.cs @@ -0,0 +1,31 @@ +using Helpdesk.Web.Api; +using Helpdesk.Web.Models; +using Microsoft.AspNetCore.Mvc; + +namespace Helpdesk.Web.Controllers; + +/// Hlášení závad (FR-10 – FR-17). +[Route("issues")] +public sealed class IssuesController(HelpdeskApiClient api) : Controller +{ + /// Moje hlášení – závady, které uživatel nahlásil, od nejnovějších. + [HttpGet("")] + public async Task 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, + }); + } +} diff --git a/web/Helpdesk.Web/Infrastructure/DisplayTime.cs b/web/Helpdesk.Web/Infrastructure/DisplayTime.cs new file mode 100644 index 0000000..9db6087 --- /dev/null +++ b/web/Helpdesk.Web/Infrastructure/DisplayTime.cs @@ -0,0 +1,15 @@ +using System.Globalization; + +namespace Helpdesk.Web.Infrastructure; + +/// API vrací časy v UTC; uživatelům je zobrazujeme v českém čase (kap. 12.6 návrhu). +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); + + /// Např. „3. 10. 2026 14:05“. + public static string Format(DateTimeOffset utc) => ToLocal(utc).ToString("d. M. yyyy H:mm", Czech); +} diff --git a/web/Helpdesk.Web/Infrastructure/Navigation.cs b/web/Helpdesk.Web/Infrastructure/Navigation.cs index 988a928..386b998 100644 --- a/web/Helpdesk.Web/Infrastructure/Navigation.cs +++ b/web/Helpdesk.Web/Infrastructure/Navigation.cs @@ -19,6 +19,7 @@ public static class Navigation public static readonly IReadOnlyList Items = [ new("Nástěnka", "Home", "Index"), + new("Moje hlášení", "Issues", "Index"), ]; public static IEnumerable For(ClaimsPrincipal user) => Items.Where(i => i.IsVisibleTo(user)); diff --git a/web/Helpdesk.Web/Models/IssueListViewModel.cs b/web/Helpdesk.Web/Models/IssueListViewModel.cs new file mode 100644 index 0000000..2df3c55 --- /dev/null +++ b/web/Helpdesk.Web/Models/IssueListViewModel.cs @@ -0,0 +1,30 @@ +using Helpdesk.Web.Api; + +namespace Helpdesk.Web.Models; + +public sealed class IssueListViewModel +{ + /// Stavy závady v pořadí životního cyklu (kap. 6 návrhu) pro filtr. + public static readonly IReadOnlyList Statuses = + ["RECEIVED", "ASSIGNED", "IN_PROGRESS", "PENDING_VERIFICATION", "RESOLVED", "REJECTED"]; + + public required PagedResult Issues { get; init; } + public required IReadOnlyDictionary CategoryNames { get; init; } + public required IReadOnlyDictionary BuildingNames { get; init; } + public string? Status { get; init; } + + public string CategoryName(int id) => CategoryNames.GetValueOrDefault(id, "Neznámá kategorie"); + + /// Budova a upřesnění místa, např. „Budova B – učebna B-205“. + 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}", + }; + } +} diff --git a/web/Helpdesk.Web/Views/Issues/Index.cshtml b/web/Helpdesk.Web/Views/Issues/Index.cshtml new file mode 100644 index 0000000..6f1849e --- /dev/null +++ b/web/Helpdesk.Web/Views/Issues/Index.cshtml @@ -0,0 +1,76 @@ +@model IssueListViewModel +@{ + ViewData["Title"] = "Moje hlášení"; + var result = Model.Issues; +} + +
+
+

Moje hlášení

+

Závady, které jste nahlásili, a v jakém stavu je jejich řešení.

+
+
+ + + +
+
+ +@if (result.Items.Count == 0) +{ +
+

@(Model.Status is null ? "Zatím jste nic nenahlásili" : "V tomto stavu nemáte žádné hlášení")

+

+ @(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í.") +

+
+} +else +{ +
    + @foreach (var issue in result.Items) + { + var location = Model.Location(issue); +
  • +
    + #@issue.Id +

    @issue.Title

    +

    + @Model.CategoryName(issue.CategoryId) + @if (location is not null) + { + @location + } +

    +
    +
    + + +
    +
  • + } +
+ + @if (result.PageCount > 1) + { + + } +} diff --git a/web/Helpdesk.Web/Views/Shared/_Layout.cshtml b/web/Helpdesk.Web/Views/Shared/_Layout.cshtml index 36409d0..30eee60 100644 --- a/web/Helpdesk.Web/Views/Shared/_Layout.cshtml +++ b/web/Helpdesk.Web/Views/Shared/_Layout.cshtml @@ -54,6 +54,7 @@ + @await RenderSectionAsync("Scripts", required: false) diff --git a/web/Helpdesk.Web/wwwroot/css/site.css b/web/Helpdesk.Web/wwwroot/css/site.css index 6a513a9..c1b90ba 100644 --- a/web/Helpdesk.Web/wwwroot/css/site.css +++ b/web/Helpdesk.Web/wwwroot/css/site.css @@ -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); diff --git a/web/Helpdesk.Web/wwwroot/js/site.js b/web/Helpdesk.Web/wwwroot/js/site.js new file mode 100644 index 0000000..9711aeb --- /dev/null +++ b/web/Helpdesk.Web/wwwroot/js/site.js @@ -0,0 +1,6 @@ +// Drobné chování stránek. CSP nepovoluje inline skripty ani atributy onchange, proto vše tady. + +//