Skip to content

Commit

Permalink
Merged changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Feb 25, 2024
2 parents d0e708c + 9979644 commit ea78f4a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace DotVVM.Framework.Controls;

/// <summary> Provides an extension point to the <see cref="GridViewDataSetExtensions.LoadFromQueryable{T}(DotVVM.Framework.Controls.IGridViewDataSet{T}, IQueryable{T})" /> method, which is invoked after the items are loaded from database. </summary>
public interface IPagingOptionsLoadingPostProcessor
{
void ProcessLoadedItems<T>(IQueryable<T> filteredQueryable, IList<T> items);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@

namespace DotVVM.Framework.Controls
{
// TODO: comments
/// <summary>
/// Token-based paging options that can navigate to next and all previous pages.
/// </summary>
public class NextTokenHistoryPagingOptions : IPagingFirstPageCapability, IPagingPreviousPageCapability, IPagingPageIndexCapability, IPagingNextPageCapability
{
/// <summary> List of all known pages, including the current page. First page has a <c>null</c> token. </summary>
public List<string?> TokenHistory { get; set; } = new();

/// <summary> Zero-based index of the current page in the <see cref="TokenHistory"/> </summary>
public int PageIndex { get; set; } = 0;

/// <summary> Gets if we are on the first page (<c>null</c> token, zero page index). </summary>
public bool IsFirstPage => PageIndex == 0;

/// <summary> Navigates to the first page, resets the <see cref="PageIndex"/> to zero. </summary>
public void GoToFirstPage() => PageIndex = 0;

/// <summary> Gets whether the <see cref="PageIndex" /> represents the last page. </summary>
public bool IsLastPage => PageIndex == TokenHistory.Count - 1;

public void GoToNextPage() => PageIndex++;
/// <summary> Navigates to the next page, if possible </summary>
public void GoToNextPage() =>
PageIndex = Math.Min(PageIndex + 1, TokenHistory.Count - 1);

public void GoToPreviousPage() => PageIndex--;
/// <summary> Navigates to the previous page, if possible </summary>
public void GoToPreviousPage() =>
PageIndex = Math.Max(PageIndex - 1, 0);

/// <summary> Navigates to the page specified using a zero-based index. </summary>
public void GoToPage(int pageIndex)
{
if (TokenHistory.Count <= pageIndex)
Expand Down
18 changes: 16 additions & 2 deletions src/Framework/Core/Controls/Options/NextTokenPagingOptions.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
namespace DotVVM.Framework.Controls
{
// TODO: comments, mention that null in NextPageToken means there is no next page
/// <summary>
/// Simple token-based paging options that can navigate to the next page.
/// Paging back is not supported by this class, you can use <see cref="NextTokenHistoryPagingOptions" />
/// </summary>
public class NextTokenPagingOptions : IPagingFirstPageCapability, IPagingNextPageCapability
{
/// <summary> The paging token of the next page. If this property is <c>null</c>, then this is the last known page. </summary>
public string? NextPageToken { get; set; }

/// <summary> The paging token of the currently displayed page. Equal to <c>null</c>, if this is the first page. </summary>
public string? CurrentToken { get; set; }

/// <summary> Gets if we are on the first page — if the <see cref="CurrentToken" /> is null. </summary>
public bool IsFirstPage => CurrentToken == null;

public void GoToFirstPage() => CurrentToken = null;
/// <summary> Navigates to the first page, resets both the current and next token to <c>null</c> </summary>
public void GoToFirstPage()
{
CurrentToken = null;
NextPageToken = null;
}

/// <summary> Gets if it is on the last known page — if the <see cref="NextPageToken" /> is null. </summary>
public bool IsLastPage => NextPageToken == null;

/// <summary> Navigates to the next page, sets the <see cref="CurrentToken" /> to the <see cref="NextPageToken" /> and resets the next token. </summary>
public void GoToNextPage()
{
if (NextPageToken != null)
{
CurrentToken = NextPageToken;
NextPageToken = null;
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/Framework/Framework/Binding/BindingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,21 @@ public static ParametrizedCode GetParametrizedCommandJavascript(this ICommandBin
/// </summary>
public static CodeParameterAssignment? GetParametrizedCommandArgs(DotvvmControl control, IEnumerable<object?>? argumentsCollection)
{
if (argumentsCollection is null) return null;
var builder = new ParametrizedCode.Builder();
var isFirst = true;

builder.Add("[");
if (argumentsCollection is not null)
foreach (var arg in argumentsCollection)
{
foreach (var arg in argumentsCollection)
if (!isFirst)
{
if (!isFirst)
{
builder.Add(",");
}
builder.Add(",");
}

isFirst = false;
isFirst = false;

builder.Add(ValueOrBinding<object>.FromBoxedValue(arg).GetParametrizedJsExpression(control));
}
builder.Add(ValueOrBinding<object>.FromBoxedValue(arg).GetParametrizedJsExpression(control));
}

builder.Add("]");
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/Framework/Controls/GridViewColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public virtual void CreateHeaderControls(IDotvvmRequestContext context, GridView
}

var sortExpression = GetSortExpression();

var linkButton = new LinkButton();
linkButton.SetValue(ButtonBase.TextProperty, GetValueRaw(HeaderTextProperty));
linkButton.ClickArguments = new object?[] { sortExpression };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using DotVVM.Framework.Compilation.Javascript;
using DotVVM.Framework.Compilation.Javascript.Ast;
using DotVVM.Framework.Utils;
using FastExpressionCompiler;

namespace DotVVM.Framework.Controls;

Expand Down Expand Up @@ -245,7 +246,7 @@ private ICommandBinding CreateDefaultCommandBinding<TDataSetInterface>(Expressio
new object[]
{
new ParsedExpressionBindingProperty(expression),
new OriginalStringBindingProperty($"DataPager: _dataSet.{methodName}({string.Join(", ", arguments.AsEnumerable())})"), // For ID generation
new OriginalStringBindingProperty($"DataPager({dataSet.Type.ToCode()}): {dataSet.ToCSharpString().TrimEnd(';')}.{methodName}({string.Join(", ", arguments.AsEnumerable())})"), // For ID generation
dataContextStack
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ export const translations = {
NextTokenPagingOptions: {
goToFirstPage(options: NextTokenPagingOptions) {
options.CurrentToken = null;
options.NextPageToken = null;
},
goToNextPage(options: NextTokenPagingOptions) {
if (options.NextPageToken) {
if (options.NextPageToken != null) {
options.CurrentToken = options.NextPageToken;
options.NextPageToken = null;
}
}
},
Expand Down

0 comments on commit ea78f4a

Please sign in to comment.