-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #928 from riganti/feature/staticCommand-in-markupC…
…ontrol Static Commands in MarkupControl
- Loading branch information
Showing
24 changed files
with
701 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/DotVVM.Framework.Tests.Common/ControlTests/MarkupControlTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Threading.Tasks; | ||
using CheckTestOutput; | ||
using DotVVM.Framework.Binding; | ||
using DotVVM.Framework.Binding.Expressions; | ||
using DotVVM.Framework.Controls; | ||
using DotVVM.Framework.Tests.Binding; | ||
using DotVVM.Framework.ViewModel; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DotVVM.Framework.Tests.Common.ControlTests | ||
{ | ||
[TestClass] | ||
public class MarkupControlTests | ||
{ | ||
ControlTestHelper cth = new ControlTestHelper(config: config => { | ||
config.Markup.AddMarkupControl("cc", "CustomControlWithCommand", "CustomControlWithCommand.dotcontrol"); | ||
}, services: s => { | ||
s.AddSingleton<TestService>(); | ||
}); | ||
OutputChecker check = new OutputChecker( | ||
"testoutputs"); | ||
|
||
[TestMethod] | ||
public async Task MarkupControl_PassingStaticCommand() | ||
{ | ||
var r = await cth.RunPage(typeof(BasicTestViewModel), @" | ||
<cc:CustomControlWithCommand DataContext={value: Integer} Click={staticCommand: s.Save(_parent.Integer)} /> | ||
<dot:Repeater DataSource={value: Collection}> | ||
<cc:CustomControlWithCommand Click={staticCommand: s.Save(_this)} /> | ||
</dot:Repeater> | ||
", | ||
directives: $"@service s = {typeof(TestService)}", | ||
markupFiles: new Dictionary<string, string> { | ||
["CustomControlWithCommand.dotcontrol"] = @" | ||
@viewModel int | ||
@baseType DotVVM.Framework.Tests.Common.ControlTests.CustomControlWithCommand | ||
@wrapperTag div | ||
<dot:Button Click={staticCommand: _control.Click()} />" | ||
} | ||
); | ||
|
||
check.CheckString(r.FormattedHtml, fileExtension: "html"); | ||
} | ||
|
||
public class BasicTestViewModel : DotvvmViewModelBase | ||
{ | ||
[Bind(Name = "int")] | ||
public int Integer { get; set; } = 10000000; | ||
|
||
public List<int> Collection { get; set; } = new List<int> { 10, -20 }; | ||
} | ||
} | ||
|
||
public class CustomControlWithCommand : DotvvmMarkupControl | ||
{ | ||
public static readonly DotvvmProperty ClickProperty = | ||
DotvvmProperty.Register<Command, CustomControlWithCommand>("Click"); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ommon/ControlTests/testoutputs/MarkupControlTests.MarkupControl_PassingStaticCommand.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
|
||
<!-- ko with: int --> | ||
<div> | ||
<!-- ko dotvvm-with-control-properties: { "Click": function(){return dotvvm.applyPostbackHandlers(function(options){return (function(a, b) { | ||
return new Promise(function(resolve, reject) { | ||
dotvvm.staticCommandPostback(a, "WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuVGVzdFNlcnZpY2UsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMuQ29tbW9uIiwiU2F2ZSIsW10sIkFRQT0iXQ==", [b.$parent.int()], options).then(function(r_0) { | ||
resolve(r_0); | ||
}, reject); | ||
}); | ||
}($element, ko.contextFor($element)))}.bind(this),$element,[])} } --> | ||
<input type="button" value="" onclick="dotvvm.applyPostbackHandlers(function(options){return (function(a, b) { | ||
return new Promise(function(resolve, reject) { | ||
Promise.resolve((b = a.$control.Click()) && b()).then(function(r_0) { | ||
resolve(r_0); | ||
}, reject); | ||
}); | ||
}(ko.contextFor(this)))}.bind(this),this,[]).catch(function(){});event.stopPropagation();return false;"> | ||
<!-- /ko --> | ||
</div> | ||
<!-- /ko --> | ||
<div data-bind="foreach: { "data": Collection }"> | ||
<div> | ||
<!-- ko dotvvm-with-control-properties: { "Click": function(){return dotvvm.applyPostbackHandlers(function(options){return (function(a, b) { | ||
return new Promise(function(resolve, reject) { | ||
dotvvm.staticCommandPostback(a, "WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuVGVzdFNlcnZpY2UsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMuQ29tbW9uIiwiU2F2ZSIsW10sIkFRQT0iXQ==", [b.$data], options).then(function(r_0) { | ||
resolve(r_0); | ||
}, reject); | ||
}); | ||
}($element, ko.contextFor($element)))}.bind(this),$element,[])} } --> | ||
<input type="button" value="" onclick="dotvvm.applyPostbackHandlers(function(options){return (function(a, b) { | ||
return new Promise(function(resolve, reject) { | ||
Promise.resolve((b = a.$control.Click()) && b()).then(function(r_0) { | ||
resolve(r_0); | ||
}, reject); | ||
}); | ||
}(ko.contextFor(this)))}.bind(this),this,[]).catch(function(){});event.stopPropagation();return false;"> | ||
<!-- /ko --> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/DotVVM.Framework/Compilation/Javascript/InvocationRewriterExpressionVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace DotVVM.Framework.Compilation.Javascript | ||
{ | ||
public class InvocationRewriterExpressionVisitor : ExpressionVisitor | ||
{ | ||
protected override Expression VisitInvocation(InvocationExpression node) | ||
{ | ||
var invokeMethod = node.Expression.Type.GetMethod("Invoke"); | ||
|
||
return Expression.Call(node.Expression, invokeMethod, node.Arguments); ; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.