mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
WIP on scrolling
This commit is contained in:
parent
ea54dfa3bf
commit
227ec0a6f8
6 changed files with 155 additions and 34 deletions
75
src/Ombi.Helpers/PagnationHelper.cs
Normal file
75
src/Ombi.Helpers/PagnationHelper.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Ombi.Helpers
|
||||
{
|
||||
public static class PaginationHelper
|
||||
{
|
||||
public static List<PagesToLoad> GetNextPages(int currentlyLoaded, int toLoad, int maxItemsPerPage)
|
||||
{
|
||||
var pagesToLoad = new List<PagesToLoad>();
|
||||
|
||||
if (currentlyLoaded == maxItemsPerPage)
|
||||
{
|
||||
currentlyLoaded++;
|
||||
}
|
||||
|
||||
var a = currentlyLoaded / maxItemsPerPage;
|
||||
//var currentPage = Convert.ToInt32(Math.Round((decimal)((decimal)currentlyLoaded / (decimal)maxItemsPerPage), 2, MidpointRounding.AwayFromZero));
|
||||
var currentPage = Convert.ToInt32(Math.Ceiling((decimal)((decimal)currentlyLoaded / (decimal)maxItemsPerPage)));
|
||||
if (currentlyLoaded < maxItemsPerPage)
|
||||
{
|
||||
currentPage = 1;
|
||||
}
|
||||
|
||||
|
||||
var toBeLoaded = (currentlyLoaded + toLoad)+1;
|
||||
//var toBeLoadedPage = Convert.ToInt32(Math.Round((decimal)((decimal)toBeLoaded / (decimal)maxItemsPerPage), 2, MidpointRounding.AwayFromZero));
|
||||
var toBeLoadedPage = Convert.ToInt32(Math.Ceiling((decimal)((decimal)toBeLoaded / (decimal)maxItemsPerPage)));
|
||||
|
||||
|
||||
if (currentlyLoaded == 0)
|
||||
{
|
||||
// If we have not loaded any yet, then we should only load
|
||||
// the first page
|
||||
currentPage = toBeLoadedPage;
|
||||
}
|
||||
var extraPageNeeded = (toBeLoadedPage != currentPage);
|
||||
if(extraPageNeeded)
|
||||
{
|
||||
// Add the first page
|
||||
pagesToLoad.Add(new PagesToLoad
|
||||
{
|
||||
Page = currentPage,
|
||||
Skip = currentlyLoaded
|
||||
});
|
||||
// Add extra page
|
||||
pagesToLoad.Add(new PagesToLoad
|
||||
{
|
||||
Page = toBeLoadedPage,
|
||||
Skip = (currentlyLoaded + toLoad) - maxItemsPerPage,
|
||||
Take = toLoad
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
pagesToLoad.Add(new PagesToLoad
|
||||
{
|
||||
Page = currentPage,
|
||||
Skip = currentlyLoaded,
|
||||
Take = toLoad
|
||||
});
|
||||
}
|
||||
|
||||
return pagesToLoad;
|
||||
}
|
||||
}
|
||||
|
||||
public class PagesToLoad
|
||||
{
|
||||
public int Page { get; set; }
|
||||
public int Take { get; set; }
|
||||
public int Skip { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue