Skip to content

Commit

Permalink
DataPager commands refactored and added support for static commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg authored and exyi committed Oct 7, 2023
1 parent 6531b96 commit 2ca439b
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 55 deletions.
17 changes: 0 additions & 17 deletions src/Framework/Framework/Binding/CommonBindings.cs

This file was deleted.

Expand Up @@ -110,6 +110,12 @@ public void AddPropertyTranslator<T>(Expression<Func<T>> propertyAccess, IJavasc
}
}

public void AddMethodTranslator(Expression<Action> methodCall, IJavascriptMethodTranslator translator)

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (ubuntu-latest)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (ubuntu-latest)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (macOS-latest)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (macOS-latest)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (windows-2022)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (windows-2022)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types

Check failure on line 113 in src/Framework/Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs

View workflow job for this annotation

GitHub Actions / UI tests (chrome, windows-2022, Development, Default)

Type 'JavascriptTranslatableMethodCollection' already defines a member called 'AddMethodTranslator' with the same parameter types
{
var method = (MethodInfo)MethodFindingHelper.GetMethodFromExpression(methodCall);
AddMethodTranslator(method, translator);
}

public void AddMethodTranslator(Type declaringType, string methodName, IJavascriptMethodTranslator translator, int parameterCount, bool allowMultipleMethods = false, Func<ParameterInfo[], bool>? parameterFilter = null)
{
var methods = declaringType.GetMethods()
Expand Down Expand Up @@ -243,8 +249,9 @@ public void AddDefaultMethodTranslators()
AddDefaultMathTranslations();
AddDefaultDateTimeTranslations();
AddDefaultConvertTranslations();
AddDataSetOptionsTranslations();
}

private void AddDefaultToStringTranslations()
{
AddMethodTranslator(typeof(object).GetMethod("ToString", Type.EmptyTypes), new PrimitiveToStringTranslator());
Expand Down Expand Up @@ -777,6 +784,58 @@ private void AddDefaultConvertTranslations()
}
}
}

private void AddDataSetOptionsTranslations()
{
// GridViewDataSetBindingProvider
AddMethodTranslator(typeof(GridViewDataSetBindingProvider), "DataSetClientSideLoad", new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("loadDataSet").Invoke(args[1], args[2])));

// PagingOptions
AddMethodTranslator(() => default(PagingOptions)!.GoToFirstPage(),new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("PagingOptions").Member("goToFirstPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(PagingOptions)!.GoToLastPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("PagingOptions").Member("goToLastPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(PagingOptions)!.GoToPreviousPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("PagingOptions").Member("goToPreviousPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(PagingOptions)!.GoToNextPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("PagingOptions").Member("goToNextPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(PagingOptions)!.GoToPage(default(int)), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("PagingOptions").Member("goToPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance), args[1])));

// NextTokenPagingOptions
AddMethodTranslator(() => default(NextTokenPagingOptions)!.GoToFirstPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("NextTokenPagingOptions").Member("goToFirstPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(NextTokenPagingOptions)!.GoToNextPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("NextTokenPagingOptions").Member("goToNextPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));

// NextTokenHistoryPagingOptions
AddMethodTranslator(() => default(NextTokenHistoryPagingOptions)!.GoToFirstPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("NextTokenHistoryPagingOptions").Member("goToFirstPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(NextTokenHistoryPagingOptions)!.GoToPreviousPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("NextTokenHistoryPagingOptions").Member("goToPreviousPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(NextTokenHistoryPagingOptions)!.GoToNextPage(), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("NextTokenHistoryPagingOptions").Member("goToNextPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance))));
AddMethodTranslator(() => default(NextTokenHistoryPagingOptions)!.GoToPage(default(int)), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("NextTokenHistoryPagingOptions").Member("goToPage")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance), args[1])));

// SortingOptions
AddMethodTranslator(() => default(SortingOptions)!.SetSortExpression(default(string?)), new GenericMethodCompiler(args =>
new JsIdentifierExpression("dotvvm").Member("dataSet").Member("translations").Member("SortingOptions").Member("setSortExpression")
.Invoke(args[0].WithAnnotation(ShouldBeObservableAnnotation.Instance), args[1])));
}

public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] args, MethodInfo method)
{
{
Expand Down
Expand Up @@ -31,6 +31,12 @@ static Expression UnwrapConversions(Expression e)
e = unary.Operand;
return e;
}

public static MethodBase GetMethodFromExpression(Expression<Action> expression)

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (ubuntu-latest)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (ubuntu-latest)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Debug)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build published projects without warnings (Release)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (macOS-latest)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (macOS-latest)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (windows-2022)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / .NET unit tests (windows-2022)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types

Check failure on line 35 in src/Framework/Framework/Compilation/Javascript/MemberInfoHelper.cs

View workflow job for this annotation

GitHub Actions / UI tests (chrome, windows-2022, Development, Default)

Type 'MethodFindingHelper' already defines a member called 'GetMethodFromExpression' with the same parameter types
{
return GetMethodFromExpression((Expression)expression);
}

static MethodBase GetMethodFromExpression(Expression expression)
{
var originalExpression = expression;
Expand Down
49 changes: 16 additions & 33 deletions src/Framework/Framework/Controls/DataPager.cs
Expand Up @@ -20,32 +20,17 @@ namespace DotVVM.Framework.Controls
[ControlMarkupOptions(AllowContent = false)]
public class DataPager : HtmlGenericControl
{
public class CommonBindings
{
public readonly CommandBindingExpression GoToNextPageCommand;
public readonly CommandBindingExpression GoToThisPageCommand;
public readonly CommandBindingExpression GoToPrevPageCommand;
public readonly CommandBindingExpression GoToFirstPageCommand;
public readonly CommandBindingExpression GoToLastPageCommand;
private readonly GridViewDataSetBindingProvider gridViewDataSetBindingProvider;
private readonly BindingCompilationService bindingCompilationService;

public CommonBindings(BindingCompilationService service)
{
GoToNextPageCommand = new CommandBindingExpression(service, h => ((IPageableGridViewDataSet<IPagingNextPageCapability>)h[0]).GoToNextPageAndRefresh(), "__$DataPager_GoToNextPage");
GoToThisPageCommand = new CommandBindingExpression(service, h => ((IPageableGridViewDataSet<IPagingPageIndexCapability>)h[1]).GoToPageAndRefresh((int)h[0]), "__$DataPager_GoToThisPage");
GoToPrevPageCommand = new CommandBindingExpression(service, h => ((IPageableGridViewDataSet<IPagingPreviousPageCapability>)h[0]).GoToPreviousPageAndRefresh(), "__$DataPager_GoToPrevPage");
GoToFirstPageCommand = new CommandBindingExpression(service, h => ((IPageableGridViewDataSet<IPagingFirstPageCapability>)h[0]).GoToFirstPageAndRefresh(), "__$DataPager_GoToFirstPage");
GoToLastPageCommand = new CommandBindingExpression(service, h => ((IPageableGridViewDataSet<IPagingLastPageCapability>)h[0]).GoToLastPageAndRefresh(), "__$DataPager_GoToLastPage");
}
}
private DataPagerCommands? pagerCommands;

private readonly CommonBindings commonBindings;
private readonly BindingCompilationService bindingService;

public DataPager(CommonBindings commonBindings, BindingCompilationService bindingService)
public DataPager(GridViewDataSetBindingProvider gridViewDataSetBindingProvider, BindingCompilationService bindingCompilationService)
: base("div", false)
{
this.commonBindings = commonBindings;
this.bindingService = bindingService;
this.gridViewDataSetBindingProvider = gridViewDataSetBindingProvider;
this.bindingCompilationService = bindingCompilationService;
}

/// <summary>
Expand Down Expand Up @@ -171,19 +156,18 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context)
ContentWrapper = CreateWrapperList(dataContextType);
Children.Add(ContentWrapper);

var bindings = context.Services.GetRequiredService<CommonBindings>();

pagerCommands = gridViewDataSetBindingProvider.GetDataPagerCommands(dataContextType, GridViewDataSetCommandType.Command);
object enabledValue = GetValueRaw(EnabledProperty)!;

if (typeof(IPageableGridViewDataSet<IPagingFirstPageCapability>).IsAssignableFrom(dataContextType.DataContextType))
{
GoToFirstPageButton = CreateNavigationButton("««", FirstPageTemplate, enabledValue, bindings.GoToFirstPageCommand, context);
GoToFirstPageButton = CreateNavigationButton("««", FirstPageTemplate, enabledValue, pagerCommands.GoToFirstPage!, context);
ContentWrapper.Children.Add(GoToFirstPageButton);
}

if (typeof(IPageableGridViewDataSet<IPagingPreviousPageCapability>).IsAssignableFrom(dataContextType.DataContextType))
{
GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, enabledValue, bindings.GoToPrevPageCommand, context);
GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, enabledValue, pagerCommands.GoToPreviousPage!, context);
ContentWrapper.Children.Add(GoToPreviousPageButton);
}

Expand All @@ -205,7 +189,7 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context)
li.Attributes.Set("class", ActiveItemCssClass);
}
var link = new LinkButton() { Text = (number + 1).ToString() };
link.SetBinding(ButtonBase.ClickProperty, bindings.GoToThisPageCommand);
link.SetBinding(ButtonBase.ClickProperty, pagerCommands.GoToPage!);
if (!true.Equals(enabledValue)) link.SetValue(LinkButton.EnabledProperty, enabledValue);
li.Children.Add(link);
NumberButtonsPlaceHolder.Children.Add(li);
Expand All @@ -217,13 +201,13 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context)

if (typeof(IPageableGridViewDataSet<IPagingNextPageCapability>).IsAssignableFrom(dataContextType.DataContextType))
{
GoToNextPageButton = CreateNavigationButton("»", NextPageTemplate, enabledValue, bindings.GoToNextPageCommand, context);
GoToNextPageButton = CreateNavigationButton("»", NextPageTemplate, enabledValue, pagerCommands.GoToNextPage!, context);
ContentWrapper.Children.Add(GoToNextPageButton);
}

if (typeof(IPageableGridViewDataSet<IPagingLastPageCapability>).IsAssignableFrom(dataContextType.DataContextType))
{
GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, enabledValue, bindings.GoToLastPageCommand, context);
GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, enabledValue, pagerCommands.GoToLastPage!, context);
ContentWrapper.Children.Add(GoToLastPageButton);
}
}
Expand Down Expand Up @@ -269,7 +253,7 @@ private ValueBindingExpression GetNearIndexesBinding(IDotvvmRequestContext conte
_nearIndexesBindingCache.GetOrCreateValue(context.Configuration)
.GetOrAdd(i, _ =>
ValueBindingExpression.CreateBinding(
bindingService.WithoutInitialization(),
bindingCompilationService.WithoutInitialization(),
h => ((IPageableGridViewDataSet<IPagingPageIndexCapability>)h[0]!).PagingOptions.NearPageIndexes[i],
dataContext));
}
Expand Down Expand Up @@ -358,7 +342,7 @@ protected virtual void RenderPageNumberButton(IHtmlWriter writer, IDotvvmRequest
var currentPageTextContext = DataContextStack.Create(typeof(int), NumberButtonsPlaceHolder!.GetDataContextType());
li.SetDataContextType(currentPageTextContext);
li.DataContext = null;
var currentPageTextBinding = ValueBindingExpression.CreateBinding(bindingService.WithoutInitialization(),
var currentPageTextBinding = ValueBindingExpression.CreateBinding(bindingCompilationService.WithoutInitialization(),
vm => ((int) vm[0]! + 1).ToString(),
currentPageTextJs,
currentPageTextContext);
Expand Down Expand Up @@ -394,7 +378,7 @@ protected virtual void RenderPageNumberButton(IHtmlWriter writer, IDotvvmRequest
li.Children.Add(link);
link.SetDataContextType(currentPageTextContext);
link.SetBinding(ButtonBase.TextProperty, currentPageTextBinding);
link.SetBinding(ButtonBase.ClickProperty, commonBindings.GoToThisPageCommand);
link.SetBinding(ButtonBase.ClickProperty, pagerCommands.GoToPage!);
object enabledValue = GetValueRaw(EnabledProperty)!;
if (!true.Equals(enabledValue)) link.SetValue(LinkButton.EnabledProperty, enabledValue);

Expand All @@ -409,5 +393,4 @@ protected override void RenderEndTag(IHtmlWriter writer, IDotvvmRequestContext c
private IValueBinding GetDataSetBinding()
=> GetValueBinding(DataSetProperty) ?? throw new DotvvmControlException(this, "The DataSet property of the dot:DataPager control must be set!");
}

}
13 changes: 13 additions & 0 deletions src/Framework/Framework/Controls/DataPagerCommands.cs
@@ -0,0 +1,13 @@
using DotVVM.Framework.Binding.Expressions;

namespace DotVVM.Framework.Controls
{
public class DataPagerCommands
{
public ICommandBinding? GoToFirstPage { get; init; }
public ICommandBinding? GoToPreviousPage { get; init; }
public ICommandBinding? GoToNextPage { get; init; }
public ICommandBinding? GoToLastPage { get; init; }
public ICommandBinding? GoToPage { get; init; }
}
}
9 changes: 9 additions & 0 deletions src/Framework/Framework/Controls/GridViewCommands.cs
@@ -0,0 +1,9 @@
using DotVVM.Framework.Binding.Expressions;

namespace DotVVM.Framework.Controls
{
public class GridViewCommands
{
public ICommandBinding? SetSortExpression { get; init; }
}
}

0 comments on commit 2ca439b

Please sign in to comment.