Skip to content

Commit

Permalink
Merge pull request #30 from Geta/bugfix/HTS-1404-pagination-not-working
Browse files Browse the repository at this point in the history
HTS-1404: remove unnecessary ?page= from link
  • Loading branch information
ivanmarkovic1402 authored Jan 14, 2025
2 parents 2bcdff8 + 4b2b3c5 commit b88526e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<li class="page-item"><a class="page-link" href="@Model.PageUrl(i)">@i</a></li>
}
<li class="page-item @(Model.HasNextPage ? string.Empty : "disabled")">
<a class="page-link" href="?page=@Model.PageUrl(Model.PageNumber+1)" aria-label="Next">
<a class="page-link" href="@Model.PageUrl(Model.PageNumber+1)" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</td>
<td>
<button type="submit" class="btn btn-primary"
asp-page-handler="update" asp-route-id="@item.Id.ToString()">
asp-page-handler="update" asp-route-pageNumber="@item.ItemPageNumber" asp-route-id="@item.Id.ToString()">
<span data-feather="plus"></span> update
</button>
</td>
Expand All @@ -60,7 +60,7 @@
<td>@item.GroupKey</td>
<td colspan="2" class="text-end">
<button type="submit" class="btn btn-secondary"
asp-page-handler="edit" asp-route-id="@item.Id.ToString()">
asp-page-handler="edit" asp-route-pageNumber="@item.ItemPageNumber" asp-route-id="@item.Id.ToString()">
<span data-feather="edit"></span> edit
</button>
<button type="submit" class="btn btn-danger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using EPiServer;
using EPiServer.Core;
using EPiServer.Data;
Expand Down Expand Up @@ -103,9 +104,18 @@ public IActionResult OnPostDelete(string id)

private void Load()
{
SetPageNumberFromQueryString();

var items = FindTags().ToPagedList(Paging.PageNumber, Paging.PageSize);
Items = items;
}
private void SetPageNumberFromQueryString()
{
if (HttpContext.Request.Query.TryGetValue("pageNumber", out var value) && int.TryParse(value, out var pageNumber))
{
Paging.PageNumber = pageNumber == 0 ? 1 : pageNumber;
}
}

private IEnumerable<Tag> FindTags()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using Microsoft.AspNetCore.Mvc;

namespace Geta.Optimizely.Tags.Pages.Geta.Optimizely.Tags.Models
{
public class Paging
{
public const int DefaultPageSize = 50;
namespace Geta.Optimizely.Tags.Pages.Geta.Optimizely.Tags.Models;

[FromQuery(Name = "page")]
public int PageNumber { get; set; } = 1;
public class Paging
{
[FromQuery(Name = "page")]
public int PageNumber { get; set; } = 1;

[FromQuery(Name = "page-size")]
public int PageSize { get; set; } = DefaultPageSize;
}
public static int PageSize { get => 50; }
}
4 changes: 3 additions & 1 deletion src/Geta.Optimizely.Tags/Core/Tag.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Geta Digital. All rights reserved.
// Copyright (c) Geta Digital. All rights reserved.
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information

using System;
Expand Down Expand Up @@ -31,6 +31,8 @@ public class Tag

public bool CheckedEditContentTags { get; set; }

public int ItemPageNumber { get; set; }

public override int GetHashCode()
{
return Name == null ? base.GetHashCode() : Name.GetHashCode();
Expand Down
16 changes: 15 additions & 1 deletion src/Geta.Optimizely.Tags/TagsScheduledJob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Geta Digital. All rights reserved.
// Copyright (c) Geta Digital. All rights reserved.
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information

using System;
Expand All @@ -10,6 +10,8 @@
using EPiServer.PlugIn;
using EPiServer.Scheduler;
using Geta.Optimizely.Tags.Core;
using Geta.Optimizely.Tags.Pages.Geta.Optimizely.Tags.Models;
using X.PagedList;

namespace Geta.Optimizely.Tags
{
Expand All @@ -36,6 +38,7 @@ public TagsScheduledJob(
public override string Execute()
{
var tags = _tagService.GetAllTags().ToList();
SetTagPageNumber(tags.ToPagedList());
var contentGuids = GetTaggedContentGuids(tags);

foreach (var contentGuid in contentGuids)
Expand Down Expand Up @@ -165,6 +168,17 @@ private void RemoveFromAllTags(Guid guid, IEnumerable<Tag> tags)
}
}

private void SetTagPageNumber(IPagedList<Tag> items)
{
for (var i = 0; i < items.Count; i++)
{
var itemPageNumber = (i / Paging.PageSize) + 1;
var tag = _tagService.GetTagById(items[i].Id);
tag.ItemPageNumber = itemPageNumber;
_tagService.Save(tag);
}
}

public override void Stop()
{
_stop = true;
Expand Down

0 comments on commit b88526e

Please sign in to comment.