Minor changes
This commit is contained in:
@@ -28,6 +28,8 @@ public static class Constants
|
||||
public const string HeaderActionLabel = "HeaderActionLabel";
|
||||
public const string HeaderActionTarget = "HeaderActionTarget";
|
||||
public const string CreatePersonModel = "CreatePersonModel";
|
||||
public const string PeopleCountryOptions = "PeopleCountryOptions";
|
||||
public const string PeopleCountryFilter = "PeopleCountryFilter";
|
||||
public const string Prefix = "Prefix";
|
||||
public const string CanRemoveRows = "CanRemoveRows";
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CountriesController : Controller
|
||||
private readonly ISieveProcessor sieveProcessor;
|
||||
private readonly PagingSettings pagingSettings;
|
||||
|
||||
public CountriesController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptions<PagingSettings> pagingSettings)
|
||||
public CountriesController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptionsSnapshot<PagingSettings> pagingSettings)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
this.sieveProcessor = sieveProcessor;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class EventsController : Controller
|
||||
private readonly ISieveProcessor sieveProcessor;
|
||||
private readonly PagingSettings pagingSettings;
|
||||
|
||||
public EventsController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptions<PagingSettings> pagingSettings)
|
||||
public EventsController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptionsSnapshot<PagingSettings> pagingSettings)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
this.sieveProcessor = sieveProcessor;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PeopleController : Controller
|
||||
private readonly ISieveProcessor sieveProcessor;
|
||||
private readonly PagingSettings pagingSettings;
|
||||
|
||||
public PeopleController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptions<PagingSettings> pagingSettings)
|
||||
public PeopleController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptionsSnapshot<PagingSettings> pagingSettings)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
this.sieveProcessor = sieveProcessor;
|
||||
@@ -40,6 +40,7 @@ public class PeopleController : Controller
|
||||
return RedirectToAction("Index", "Countries");
|
||||
}
|
||||
|
||||
await PopulatePeopleCountryFilterViewDataAsync(sieveModel.Filters);
|
||||
var viewModel = await BuildPeopleListAsync(sieveModel);
|
||||
if (Request.Headers.ContainsKey(Constants.HtmxHeaders.Request))
|
||||
{
|
||||
@@ -155,6 +156,7 @@ public class PeopleController : Controller
|
||||
}
|
||||
});
|
||||
|
||||
await PopulatePeopleCountryFilterViewDataAsync(sieveModel.Filters);
|
||||
var viewModel = await BuildPeopleListAsync(sieveModel);
|
||||
return PartialView("_PeopleList", viewModel);
|
||||
}
|
||||
@@ -248,16 +250,16 @@ public class PeopleController : Controller
|
||||
}
|
||||
});
|
||||
|
||||
await PopulatePeopleCountryFilterViewDataAsync(sieveModel.Filters);
|
||||
var viewModel = await BuildPeopleListAsync(sieveModel);
|
||||
return PartialView("_PeopleList", viewModel);
|
||||
}
|
||||
|
||||
private async Task<PeoplePageViewModel> BuildPeopleListAsync(SieveModel sieveModel)
|
||||
private async Task<PagedList<PersonViewModel>> BuildPeopleListAsync(SieveModel sieveModel)
|
||||
{
|
||||
sieveModel.SetDefaultPagingAndSorting(pagingSettings.PageSize, "LastNameTranscription");
|
||||
var normalizedFilters = sieveModel.Filters?.Trim() ?? string.Empty;
|
||||
var nameFilter = SieveModelExtensions.ExtractFilterValue(normalizedFilters, "FullNameTranscription");
|
||||
var countryFilter = SieveModelExtensions.ExtractFilterValue(normalizedFilters, "CountryCode", "==");
|
||||
|
||||
var baseQuery = ctx.People
|
||||
.Select(p => new PersonViewModel
|
||||
@@ -308,12 +310,7 @@ public class PeopleController : Controller
|
||||
.Apply(sieveModel, baseQuery)
|
||||
.ToListAsync();
|
||||
|
||||
return new PeoplePageViewModel
|
||||
{
|
||||
People = new PagedList<PersonViewModel>(people, pagingInfo),
|
||||
CountryOptions = await GetCountryOptionsAsync(countryFilter),
|
||||
CountryFilter = countryFilter
|
||||
};
|
||||
return new PagedList<PersonViewModel>(people, pagingInfo);
|
||||
}
|
||||
|
||||
private async Task<List<SelectListItem>> GetCountryOptionsAsync(string? selectedCode = null)
|
||||
@@ -329,4 +326,11 @@ public class PeopleController : Controller
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task PopulatePeopleCountryFilterViewDataAsync(string? filters)
|
||||
{
|
||||
var countryFilter = SieveModelExtensions.ExtractFilterValue(filters?.Trim() ?? string.Empty, "CountryCode", "==");
|
||||
ViewData[Constants.ViewDataKeys.PeopleCountryOptions] = await GetCountryOptionsAsync(countryFilter);
|
||||
ViewData[Constants.ViewDataKeys.PeopleCountryFilter] = countryFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class RegistrationsController : Controller
|
||||
private readonly ISieveProcessor sieveProcessor;
|
||||
private readonly PagingSettings pagingSettings;
|
||||
|
||||
public RegistrationsController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptions<PagingSettings> pagingSettings)
|
||||
public RegistrationsController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptionsSnapshot<PagingSettings> pagingSettings)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
this.sieveProcessor = sieveProcessor;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SportsController : Controller
|
||||
private readonly ISieveProcessor sieveProcessor;
|
||||
private readonly PagingSettings pagingSettings;
|
||||
|
||||
public SportsController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptions<PagingSettings> pagingSettings)
|
||||
public SportsController(EventsContext ctx, ISieveProcessor sieveProcessor, IOptionsSnapshot<PagingSettings> pagingSettings)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
this.sieveProcessor = sieveProcessor;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
namespace Events.MVC.Models.People;
|
||||
|
||||
public class PeoplePageViewModel
|
||||
{
|
||||
public PagedList<PersonViewModel> People { get; set; } = new([], new PagingInfo());
|
||||
|
||||
public List<SelectListItem> CountryOptions { get; set; } = [];
|
||||
|
||||
public string CountryFilter { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public class PagerTagHelper : TagHelper
|
||||
private readonly IUrlHelperFactory urlHelperFactory;
|
||||
private readonly PagingSettings pagingSettings;
|
||||
|
||||
public PagerTagHelper(IUrlHelperFactory urlHelperFactory, IOptions<PagingSettings> pagingSettings)
|
||||
public PagerTagHelper(IUrlHelperFactory urlHelperFactory, IOptionsSnapshot<PagingSettings> pagingSettings)
|
||||
{
|
||||
this.urlHelperFactory = urlHelperFactory;
|
||||
this.pagingSettings = pagingSettings.Value;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@model Events.MVC.Models.People.PeoplePageViewModel
|
||||
@model PagedList<Events.MVC.Models.People.PersonViewModel>
|
||||
|
||||
@{
|
||||
ViewData[Constants.ViewDataKeys.Title] = "People";
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
@model Events.MVC.Models.People.PeoplePageViewModel
|
||||
@model PagedList<Events.MVC.Models.People.PersonViewModel>
|
||||
@{
|
||||
var countryFilter = ViewData[Constants.ViewDataKeys.PeopleCountryFilter] as string ?? string.Empty;
|
||||
var countryOptions = ViewData[Constants.ViewDataKeys.PeopleCountryOptions] as IEnumerable<SelectListItem>
|
||||
?? Enumerable.Empty<SelectListItem>();
|
||||
}
|
||||
|
||||
<section class="card border-0 shadow-sm" id="people-list">
|
||||
<div class="card-body">
|
||||
<div id="people-state" class="d-none">
|
||||
<input type="hidden" name="page" value="@Model.People.PagingInfo.CurrentPage" />
|
||||
<input type="hidden" name="pageSize" value="@Model.People.PagingInfo.ItemsPerPage" />
|
||||
<input type="hidden" name="sorts" value="@Model.People.PagingInfo.Sorts" />
|
||||
<input type="hidden" name="filters" value="@Model.People.PagingInfo.Filters" />
|
||||
<input type="hidden" name="countryFilter" value="@Model.CountryFilter" />
|
||||
<input type="hidden" name="page" value="@Model.PagingInfo.CurrentPage" />
|
||||
<input type="hidden" name="pageSize" value="@Model.PagingInfo.ItemsPerPage" />
|
||||
<input type="hidden" name="sorts" value="@Model.PagingInfo.Sorts" />
|
||||
<input type="hidden" name="filters" value="@Model.PagingInfo.Filters" />
|
||||
<input type="hidden" name="countryFilter" value="@countryFilter" />
|
||||
</div>
|
||||
|
||||
<form
|
||||
@@ -20,40 +25,40 @@
|
||||
hx-push-url="true"
|
||||
onsubmit="var input=this.querySelector('[data-name-filter-input]'); var country=this.querySelector('[name=countryFilter]'); var filters=this.querySelector('[name=filters]'); var values=[]; if (input && input.value.trim()) { values.push('FullNameTranscription' + String.fromCharCode(64) + '=*' + input.value.trim()); } if (country && country.value) { values.push('CountryCode==' + country.value); } filters.value=values.join(','); this.querySelector('[name=page]').value='1';">
|
||||
<input type="hidden" name="page" value="1" />
|
||||
<input type="hidden" name="pageSize" value="@Model.People.PagingInfo.ItemsPerPage" />
|
||||
<input type="hidden" name="sorts" value="@Model.People.PagingInfo.Sorts" />
|
||||
<input type="hidden" name="filters" value="@Model.People.PagingInfo.Filters" />
|
||||
<input type="hidden" name="pageSize" value="@Model.PagingInfo.ItemsPerPage" />
|
||||
<input type="hidden" name="sorts" value="@Model.PagingInfo.Sorts" />
|
||||
<input type="hidden" name="filters" value="@Model.PagingInfo.Filters" />
|
||||
|
||||
<div class="d-flex align-items-center gap-3 pt-2">
|
||||
<h2 class="h5 mb-0">People list</h2>
|
||||
<span class="badge text-bg-light">@(Model.People.PagingInfo.IsFiltered ? $"{Model.People.PagingInfo.FilteredItemsCount} / {Model.People.PagingInfo.TotalItemsCount}" : Model.People.PagingInfo.TotalItemsCount.ToString())</span>
|
||||
<span class="badge text-bg-light">@(Model.PagingInfo.IsFiltered ? $"{Model.PagingInfo.FilteredItemsCount} / {Model.PagingInfo.TotalItemsCount}" : Model.PagingInfo.TotalItemsCount.ToString())</span>
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-items-center gap-2 flex-nowrap ms-auto">
|
||||
<input
|
||||
id="personNameFilter"
|
||||
value="@Model.People.PagingInfo.NameFilter"
|
||||
value="@Model.PagingInfo.NameFilter"
|
||||
data-name-filter-input
|
||||
class="form-control"
|
||||
style="max-width: 18rem;"
|
||||
placeholder="Search by transcribed full name"
|
||||
aria-label="Filter by transcribed full name" />
|
||||
|
||||
<select name="countryFilter" asp-items="Model.CountryOptions" class="form-select" style="max-width: 14rem;" aria-label="Filter by country">
|
||||
<select name="countryFilter" asp-items="countryOptions" class="form-select" style="max-width: 14rem;" aria-label="Filter by country">
|
||||
<option value="">All countries</option>
|
||||
</select>
|
||||
|
||||
<button type="submit" class="btn btn-outline-primary">Filter</button>
|
||||
@if (Model.People.PagingInfo.IsFiltered)
|
||||
@if (Model.PagingInfo.IsFiltered)
|
||||
{
|
||||
<a
|
||||
asp-action="Index"
|
||||
asp-route-page="1"
|
||||
asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage"
|
||||
asp-route-sorts="@Model.People.PagingInfo.Sorts"
|
||||
asp-route-pageSize="@Model.PagingInfo.ItemsPerPage"
|
||||
asp-route-sorts="@Model.PagingInfo.Sorts"
|
||||
asp-route-filters=""
|
||||
class="btn btn-outline-secondary"
|
||||
hx-get="@Url.Action("Index", "People", new { page = 1, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.Sorts, filters = string.Empty })"
|
||||
hx-get="@Url.Action("Index", "People", new { page = 1, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.Sorts, filters = string.Empty })"
|
||||
hx-target="#people-list"
|
||||
hx-swap="outerHTML"
|
||||
hx-push-url="true">
|
||||
@@ -68,41 +73,41 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<a asp-action="Index" asp-route-page="@Model.People.PagingInfo.CurrentPage" asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.People.PagingInfo.ToggleSort("Id")" asp-route-filters="@Model.People.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.People.PagingInfo.CurrentPage, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.ToggleSort("Id"), filters = Model.People.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
ID@(Model.People.PagingInfo.IsSortedBy("Id") ? (Model.People.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
<a asp-action="Index" asp-route-page="@Model.PagingInfo.CurrentPage" asp-route-pageSize="@Model.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.PagingInfo.ToggleSort("Id")" asp-route-filters="@Model.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.PagingInfo.CurrentPage, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.ToggleSort("Id"), filters = Model.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
ID@(Model.PagingInfo.IsSortedBy("Id") ? (Model.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a asp-action="Index" asp-route-page="@Model.People.PagingInfo.CurrentPage" asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.People.PagingInfo.ToggleSort("FirstNameTranscription")" asp-route-filters="@Model.People.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.People.PagingInfo.CurrentPage, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.ToggleSort("FirstNameTranscription"), filters = Model.People.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
First name@(Model.People.PagingInfo.IsSortedBy("FirstNameTranscription") ? (Model.People.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
<a asp-action="Index" asp-route-page="@Model.PagingInfo.CurrentPage" asp-route-pageSize="@Model.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.PagingInfo.ToggleSort("FirstNameTranscription")" asp-route-filters="@Model.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.PagingInfo.CurrentPage, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.ToggleSort("FirstNameTranscription"), filters = Model.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
First name@(Model.PagingInfo.IsSortedBy("FirstNameTranscription") ? (Model.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a asp-action="Index" asp-route-page="@Model.People.PagingInfo.CurrentPage" asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.People.PagingInfo.ToggleSort("LastNameTranscription")" asp-route-filters="@Model.People.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.People.PagingInfo.CurrentPage, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.ToggleSort("LastNameTranscription"), filters = Model.People.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Last name@(Model.People.PagingInfo.IsSortedBy("LastNameTranscription") ? (Model.People.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
<a asp-action="Index" asp-route-page="@Model.PagingInfo.CurrentPage" asp-route-pageSize="@Model.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.PagingInfo.ToggleSort("LastNameTranscription")" asp-route-filters="@Model.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.PagingInfo.CurrentPage, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.ToggleSort("LastNameTranscription"), filters = Model.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Last name@(Model.PagingInfo.IsSortedBy("LastNameTranscription") ? (Model.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
</a>
|
||||
</th>
|
||||
<th></th>
|
||||
<th>
|
||||
<a asp-action="Index" asp-route-page="@Model.People.PagingInfo.CurrentPage" asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.People.PagingInfo.ToggleSort("BirthDate")" asp-route-filters="@Model.People.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.People.PagingInfo.CurrentPage, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.ToggleSort("BirthDate"), filters = Model.People.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Birth date@(Model.People.PagingInfo.IsSortedBy("BirthDate") ? (Model.People.PagingInfo.IsDescending() ? " v" : " ^") : "")
|
||||
<a asp-action="Index" asp-route-page="@Model.PagingInfo.CurrentPage" asp-route-pageSize="@Model.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.PagingInfo.ToggleSort("BirthDate")" asp-route-filters="@Model.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.PagingInfo.CurrentPage, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.ToggleSort("BirthDate"), filters = Model.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Birth date@(Model.PagingInfo.IsSortedBy("BirthDate") ? (Model.PagingInfo.IsDescending() ? " v" : " ^") : "")
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a asp-action="Index" asp-route-page="@Model.People.PagingInfo.CurrentPage" asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.People.PagingInfo.ToggleSort("CountryName")" asp-route-filters="@Model.People.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.People.PagingInfo.CurrentPage, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.ToggleSort("CountryName"), filters = Model.People.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Country@(Model.People.PagingInfo.IsSortedBy("CountryName") ? (Model.People.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
<a asp-action="Index" asp-route-page="@Model.PagingInfo.CurrentPage" asp-route-pageSize="@Model.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.PagingInfo.ToggleSort("CountryName")" asp-route-filters="@Model.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.PagingInfo.CurrentPage, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.ToggleSort("CountryName"), filters = Model.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Country@(Model.PagingInfo.IsSortedBy("CountryName") ? (Model.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a asp-action="Index" asp-route-page="@Model.People.PagingInfo.CurrentPage" asp-route-pageSize="@Model.People.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.People.PagingInfo.ToggleSort("RegistrationsCount")" asp-route-filters="@Model.People.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.People.PagingInfo.CurrentPage, pageSize = Model.People.PagingInfo.ItemsPerPage, sorts = Model.People.PagingInfo.ToggleSort("RegistrationsCount"), filters = Model.People.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Registrations@(Model.People.PagingInfo.IsSortedBy("RegistrationsCount") ? (Model.People.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
<a asp-action="Index" asp-route-page="@Model.PagingInfo.CurrentPage" asp-route-pageSize="@Model.PagingInfo.ItemsPerPage" asp-route-sorts="@Model.PagingInfo.ToggleSort("RegistrationsCount")" asp-route-filters="@Model.PagingInfo.Filters" class="link-dark link-underline-opacity-0" hx-get="@Url.Action("Index", "People", new { page = Model.PagingInfo.CurrentPage, pageSize = Model.PagingInfo.ItemsPerPage, sorts = Model.PagingInfo.ToggleSort("RegistrationsCount"), filters = Model.PagingInfo.Filters })" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
Registrations@(Model.PagingInfo.IsSortedBy("RegistrationsCount") ? (Model.PagingInfo.IsDescending() ? " ↓" : " ↑") : "")
|
||||
</a>
|
||||
</th>
|
||||
<th class="text-end"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (Model.People.Data.Count == 0)
|
||||
@if (Model.Data.Count == 0)
|
||||
{
|
||||
<tr>
|
||||
<td colspan="8" class="text-body-secondary">No people to display.</td>
|
||||
@@ -110,7 +115,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var person in Model.People.Data)
|
||||
@foreach (var person in Model.Data)
|
||||
{
|
||||
<partial name="_PersonRow" model="person" />
|
||||
}
|
||||
@@ -121,24 +126,24 @@
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mt-4 gap-3 flex-wrap">
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<small class="text-body-secondary">Page @Model.People.PagingInfo.CurrentPage of @Model.People.PagingInfo.TotalPages</small>
|
||||
<small class="text-body-secondary">Page @Model.PagingInfo.CurrentPage of @Model.PagingInfo.TotalPages</small>
|
||||
<form asp-action="Index" method="get" class="d-inline-flex align-items-center gap-2" hx-get="@Url.Action("Index", "People")" hx-target="#people-list" hx-swap="outerHTML" hx-push-url="true">
|
||||
<input type="hidden" name="page" value="1" />
|
||||
<input type="hidden" name="sorts" value="@Model.People.PagingInfo.Sorts" />
|
||||
<input type="hidden" name="filters" value="@Model.People.PagingInfo.Filters" />
|
||||
<input type="hidden" name="sorts" value="@Model.PagingInfo.Sorts" />
|
||||
<input type="hidden" name="filters" value="@Model.PagingInfo.Filters" />
|
||||
<select name="pageSize" class="form-select form-select-sm" style="width: auto;" aria-label="Items per page" onchange="this.form.requestSubmit()">
|
||||
@{
|
||||
int[] pageSizeOptions = [10, 20, 50, 100];
|
||||
}
|
||||
@foreach (var option in pageSizeOptions)
|
||||
{
|
||||
<option value="@option" selected="@(Model.People.PagingInfo.ItemsPerPage == option)">@option</option>
|
||||
<option value="@option" selected="@(Model.PagingInfo.ItemsPerPage == option)">@option</option>
|
||||
}
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<pager
|
||||
page-info="@Model.People.PagingInfo"
|
||||
page-info="@Model.PagingInfo"
|
||||
page-action="Index"
|
||||
page-title="Enter a page number and press Enter"
|
||||
page-target="#people-list"
|
||||
|
||||
@@ -9,6 +9,7 @@ using Events.MVC.Models;
|
||||
using Events.MVC.Models.People;
|
||||
using Events.Tests.UnitTests.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sieve.Models;
|
||||
|
||||
@@ -59,8 +60,8 @@ public class PeopleControllerShould
|
||||
|
||||
var partial = Assert.IsType<PartialViewResult>(result);
|
||||
Assert.Equal("_PeopleList", partial.ViewName);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(partial.Model);
|
||||
Assert.Contains(model.People.Data, p => p.FullName == "Ana Kovac" && p.CountryName == "Croatia");
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(partial.Model);
|
||||
Assert.Contains(model.Data, p => p.FullName == "Ana Kovac" && p.CountryName == "Croatia");
|
||||
Assert.Contains("was added successfully", controller.Response.Headers[Events.MVC.Constants.HtmxHeaders.Trigger].ToString());
|
||||
}
|
||||
|
||||
@@ -100,8 +101,8 @@ public class PeopleControllerShould
|
||||
|
||||
var partial = Assert.IsType<PartialViewResult>(result);
|
||||
Assert.Equal("_PeopleList", partial.ViewName);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(partial.Model);
|
||||
var person = Assert.Single(model.People.Data);
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(partial.Model);
|
||||
var person = Assert.Single(model.Data);
|
||||
Assert.Equal("Ana Kovac", person.FullName);
|
||||
Assert.Equal("Croatia", person.CountryName);
|
||||
}
|
||||
@@ -178,8 +179,8 @@ public class PeopleControllerShould
|
||||
});
|
||||
|
||||
var view = Assert.IsType<ViewResult>(result);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(view.Model);
|
||||
var people = Assert.Single(model.People.Data);
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(view.Model);
|
||||
var people = Assert.Single(model.Data);
|
||||
Assert.Equal(1, people.Id);
|
||||
Assert.Equal("Ђорђе Петровић", people.FullName);
|
||||
}
|
||||
@@ -203,11 +204,12 @@ public class PeopleControllerShould
|
||||
});
|
||||
|
||||
var view = Assert.IsType<ViewResult>(result);
|
||||
var model = Assert.IsType<PeoplePageViewModel>(view.Model);
|
||||
var person = Assert.Single(model.People.Data);
|
||||
var model = Assert.IsType<PagedList<PersonViewModel>>(view.Model);
|
||||
var person = Assert.Single(model.Data);
|
||||
Assert.Equal("Ana Novak", person.FullName);
|
||||
Assert.Equal("SI", model.CountryFilter);
|
||||
Assert.Contains(model.CountryOptions, option => option.Value == "SI" && option.Selected);
|
||||
Assert.Equal("SI", Assert.IsType<string>(view.ViewData[Events.MVC.Constants.ViewDataKeys.PeopleCountryFilter]));
|
||||
var countryOptions = Assert.IsAssignableFrom<IEnumerable<SelectListItem>>(view.ViewData[Events.MVC.Constants.ViewDataKeys.PeopleCountryOptions]);
|
||||
Assert.Contains(countryOptions, option => option.Value == "SI" && option.Selected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SportsControllerShould
|
||||
new Sport { Id = 3, Name = "Cycling" });
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
var optionsMock = new Mock<IOptions<PagingSettings>>();
|
||||
var optionsMock = new Mock<IOptionsSnapshot<PagingSettings>>();
|
||||
optionsMock
|
||||
.SetupGet(options => options.Value)
|
||||
.Returns(new PagingSettings { PageSize = 2 });
|
||||
|
||||
@@ -24,9 +24,9 @@ internal static class ControllerTestContext
|
||||
return new EventsContext(options);
|
||||
}
|
||||
|
||||
public static IOptions<PagingSettings> CreatePagingOptions(int pageSize = 10)
|
||||
public static IOptionsSnapshot<PagingSettings> CreatePagingOptions(int pageSize = 10)
|
||||
{
|
||||
return Options.Create(new PagingSettings { PageSize = pageSize });
|
||||
return new TestOptionsSnapshot<PagingSettings>(new PagingSettings { PageSize = pageSize });
|
||||
}
|
||||
|
||||
public static SieveModel EmptySieveModel()
|
||||
@@ -95,4 +95,12 @@ internal static class ControllerTestContext
|
||||
Name = name
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class TestOptionsSnapshot<TOptions>(TOptions value) : IOptionsSnapshot<TOptions>
|
||||
where TOptions : class
|
||||
{
|
||||
public TOptions Value => value;
|
||||
|
||||
public TOptions Get(string? name) => value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ public class ProviderSpecificQueryShould
|
||||
ctx.People.Add(ControllerTestContext.CreatePerson());
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
var people = await ctx.People
|
||||
.Where(person => person.FirstName != null && Microsoft.EntityFrameworkCore.EF.Functions.ILike(person.FirstName, "%iv%"))
|
||||
.ToListAsync();
|
||||
var people = await ctx.People
|
||||
.Where(person => person.FirstName != null && Microsoft.EntityFrameworkCore.EF.Functions.ILike(person.FirstName, "%iv%"))
|
||||
.ToListAsync();
|
||||
|
||||
Assert.Single(people);
|
||||
Assert.Equal("Ivan", people[0].FirstName);
|
||||
}
|
||||
Assert.Single(people);
|
||||
Assert.Equal("Ivan", people[0].FirstName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ThrowInvalidOperationExceptionWhenUsingILikeWithInMemoryProvider()
|
||||
|
||||
Reference in New Issue
Block a user