Skip to content

Commit

Permalink
Format knockout binding group as multiline expression when some expre…
Browse files Browse the repository at this point in the history
…ssion is multiline
  • Loading branch information
exyi committed Nov 19, 2023
1 parent 5ed8388 commit 65fe97f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 12 deletions.
12 changes: 11 additions & 1 deletion src/Framework/Framework/Controls/KnockoutBindingGroup.cs
Expand Up @@ -85,7 +85,17 @@ protected virtual string GetKnockoutBindingExpression(DotvvmBindableObject obj,
public override string ToString()
{
if (entries.Count == 0) return "{}";
return "{ " + string.Join(", ", entries) + " }";
bool multiline = false;
foreach (var entry in entries)
if (entry.Expression.Contains('\n'))

Check failure on line 90 in src/Framework/Framework/Controls/KnockoutBindingGroup.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Argument 1: cannot convert from 'char' to 'string'

Check failure on line 90 in src/Framework/Framework/Controls/KnockoutBindingGroup.cs

View workflow job for this annotation

GitHub Actions / Build all projects without errors

Argument 1: cannot convert from 'char' to 'string'

Check failure on line 90 in src/Framework/Framework/Controls/KnockoutBindingGroup.cs

View workflow job for this annotation

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

Argument 1: cannot convert from 'char' to 'string'
{
multiline = true;
break;
}
if (multiline)
return "{\n" + string.Join(",\n", entries) + "\n}";
else
return "{ " + string.Join(", ", entries) + " }";
}

IEnumerator<KnockoutBindingInfo> IEnumerable<KnockoutBindingInfo>.GetEnumerator() => GetEnumerator();
Expand Down
Expand Up @@ -3,7 +3,7 @@
<body>

<!-- ko if: List()?.Items()?.length -->
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':List()}">
<table data-bind="dotvvm-gridviewdataset: { dataSet: List(), mapping: {} }">
<thead>
<tr>
<th class="">
Expand Down
Expand Up @@ -3,7 +3,7 @@
<body>

<!-- ko if: List()?.Items()?.length -->
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':List()}">
<table data-bind="dotvvm-gridviewdataset: { dataSet: List(), mapping: {} }">
<thead>
<tr>
<th class="">
Expand Down
@@ -1,7 +1,7 @@
<html>
<head></head>
<body>
<ul data-bind="dotvvm-gridviewdataset: { dataSet: Customers() }, visible: (Customers()).PagingOptions().PagesCount() > 1">
<ul data-bind="visible: Customers()?.PagingOptions()?.PagesCount() > 1">
<li class="disabled" data-bind="css: { disabled: Customers()?.PagingOptions()?.IsFirstPage }">
<a href="javascript:;" onclick="dotvvm.postBack(this,[],&quot;XV5Ciz2t6C9bIsEQ&quot;,&quot;&quot;,null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;">««</a>
</li>
Expand Down
Expand Up @@ -3,7 +3,7 @@
<body>

<!-- ko if: EmptyCustomers()?.Items()?.length -->
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':EmptyCustomers()}">
<table data-bind="dotvvm-gridviewdataset: { dataSet: EmptyCustomers(), mapping: {} }">
<thead>
<tr>
<th>
Expand Down
Expand Up @@ -3,19 +3,23 @@
<body>

<!-- ko with: int -->
<div data-bind="dotvvm-with-control-properties: { Click: (...args)=>(dotvvm.applyPostbackHandlers(async (options) => {
<div data-bind="dotvvm-with-control-properties: {
Click: (...args)=>(dotvvm.applyPostbackHandlers(async (options) => {
await dotvvm.staticCommandPostback(&quot;WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuVGVzdFNlcnZpY2UsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMiLCJTYXZlIixbXSwxLG51bGwsIkFRQT0iXQ==&quot;, [$context.$parent.int.state], options);
},$element,[],args,$context)) }">
},$element,[],args,$context))
}">
<input onclick="dotvvm.applyPostbackHandlers(async (options) => {
let a;
return await((a = options.knockoutContext.$control.Click.state) &amp;&amp; a());
},this).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;" type="button" value="Button with number = 10000000">
</div>
<!-- /ko -->
<div data-bind="foreach: { data: Collection }">
<div data-bind="dotvvm-with-control-properties: { Click: (...args)=>(dotvvm.applyPostbackHandlers(async (options) => {
<div data-bind="dotvvm-with-control-properties: {
Click: (...args)=>(dotvvm.applyPostbackHandlers(async (options) => {
await dotvvm.staticCommandPostback(&quot;WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuVGVzdFNlcnZpY2UsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMiLCJTYXZlIixbXSwxLG51bGwsIkFRQT0iXQ==&quot;, [$context.$rawData.state], options);
},$element,[],args,$context)) }">
},$element,[],args,$context))
}">
<input onclick="dotvvm.applyPostbackHandlers(async (options) => {
let a;
return await((a = options.knockoutContext.$control.Click.state) &amp;&amp; a());
Expand Down
Expand Up @@ -4,7 +4,7 @@

<!-- no header attribute -->
<!-- ko if: Collection()?.length -->
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':Collection()}">
<table data-bind="dotvvm-gridviewdataset: { dataSet: Collection(), mapping: {} }">
<thead>
<tr>
<th>
Expand All @@ -23,7 +23,7 @@
<!-- /ko -->
<!-- has header attribute -->
<!-- ko if: Collection()?.length -->
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':Collection()}" data-headers="RealValue ; Test">
<table data-bind="dotvvm-gridviewdataset: { dataSet: Collection(), mapping: {} }" data-headers="RealValue ; Test">
<thead>
<tr>
<th>
Expand Down
Expand Up @@ -348,6 +348,35 @@
"isCompileTimeOnly": true
}
},
"DotVVM.Framework.Controls.AppendableDataPager": {
"DataSet": {
"type": "DotVVM.Framework.Controls.IPageableGridViewDataSet, DotVVM.Core",
"required": true,
"onlyBindings": true
},
"EndTemplate": {
"type": "DotVVM.Framework.Controls.ITemplate, DotVVM.Framework",
"mappingMode": "InnerElement",
"onlyHardcoded": true
},
"LoadData": {
"type": "DotVVM.Framework.Binding.Expressions.ICommandBinding, DotVVM.Framework",
"required": true,
"onlyBindings": true
},
"LoadTemplate": {
"type": "DotVVM.Framework.Controls.ITemplate, DotVVM.Framework",
"dataContextChange": [
{
"$type": "DotVVM.Framework.Binding.HelperNamespace.DataPagerApi+AddParameterDataContextChangeAttribute, DotVVM.Framework",
"Name": "_dataPager",
"TypeId": "DotVVM.Framework.Binding.HelperNamespace.DataPagerApi+AddParameterDataContextChangeAttribute, DotVVM.Framework"
}
],
"mappingMode": "InnerElement",
"onlyHardcoded": true
}
},
"DotVVM.Framework.Controls.AuthenticatedView": {
"AuthenticatedTemplate": {
"type": "DotVVM.Framework.Controls.ITemplate, DotVVM.Framework",
Expand Down Expand Up @@ -375,6 +404,10 @@
"type": "DotVVM.Framework.Binding.Expressions.Command, DotVVM.Framework",
"isCommand": true
},
"ClickArguments": {
"type": "System.Collections.Generic.List`1[[System.Object, CoreLibrary]]",
"mappingMode": "Exclude"
},
"Enabled": {
"type": "System.Boolean",
"defaultValue": true
Expand Down Expand Up @@ -731,6 +764,10 @@
"defaultValue": false,
"onlyHardcoded": true
},
"LoadData": {
"type": "DotVVM.Framework.Binding.Expressions.ICommandBinding, DotVVM.Framework",
"onlyBindings": true
},
"RowDecorators": {
"type": "System.Collections.Generic.List`1[[DotVVM.Framework.Controls.Decorator, DotVVM.Framework, Version=***, Culture=neutral, PublicKeyToken=23f3607db32275da]]",
"dataContextChange": [
Expand Down Expand Up @@ -1974,6 +2011,12 @@
"assembly": "DotVVM.Framework",
"baseType": "DotVVM.Framework.Controls.DotvvmControl, DotVVM.Framework"
},
"DotVVM.Framework.Controls.AppendableDataPager": {
"assembly": "DotVVM.Framework",
"baseType": "DotVVM.Framework.Controls.HtmlGenericControl, DotVVM.Framework",
"defaultContentProperty": "LoadTemplate",
"withoutContent": true
},
"DotVVM.Framework.Controls.AuthenticatedView": {
"assembly": "DotVVM.Framework",
"baseType": "DotVVM.Framework.Controls.ConfigurableHtmlControl, DotVVM.Framework",
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/ViewModel/GridViewDataSetTests.cs
Expand Up @@ -128,7 +128,7 @@ public void GridViewDataSet_DataPagerCommands_StaticCommand()

var goToFirstPage = CompileBinding(commands.GoToFirstPage);
Console.WriteLine(goToFirstPage);
XAssert.Equal("dotvvm.applyPostbackHandlers(async (options)=>{let vm=options.viewModel;dotvvm.dataSet.translations.PagingOptions.goToFirstPage(vm.PagingOptions);return await dotvvm.dataSet.loadDataSet(vm,options.knockoutContext.$gridViewDataSetHelper.loadDataSet);},this)", goToFirstPage);
XAssert.Equal("dotvvm.applyPostbackHandlers(async (options)=>{let cx=options.knockoutContext;return await dotvvm.dataSet.loadDataSet(options.viewModel,(options)=>dotvvm.dataSet.translations.PagingOptions.goToFirstPage(ko.unwrap(options).PagingOptions),cx.$gridViewDataSetHelper.loadDataSet,cx.$gridViewDataSetHelper.postProcessor);},this)", goToFirstPage);
}

private string CompileBinding(ICommandBinding staticCommand)
Expand Down

0 comments on commit 65fe97f

Please sign in to comment.