-
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.
dynamic data: support DynamicColumns virtual column
- Loading branch information
Showing
11 changed files
with
169 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Linq; | ||
using DotVVM.Framework.Binding; | ||
using DotVVM.Framework.Binding.Expressions; | ||
using DotVVM.Framework.Compilation.Styles; | ||
using DotVVM.Framework.Controls.DynamicData.Metadata; | ||
using DotVVM.Framework.Hosting; | ||
using DotVVM.Framework.Utils; | ||
|
||
namespace DotVVM.Framework.Controls.DynamicData | ||
{ | ||
// TODO: replace this with something else | ||
public class DummyColumnThatDoesNothing : GridViewColumn | ||
{ | ||
public DummyColumnThatDoesNothing() | ||
{ | ||
Visible = false; | ||
} | ||
|
||
public override void CreateControls(IDotvvmRequestContext context, DotvvmControl container) { } | ||
public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container) { } | ||
} | ||
public class DynamicColumns: GridViewColumn | ||
{ | ||
public static DotvvmCapabilityProperty PropsProperty = | ||
DotvvmCapabilityProperty.RegisterCapability<Props, DynamicColumns>(); | ||
|
||
public static GridViewColumn[] Replace(IStyleMatchContext<DynamicColumns> col) | ||
{ | ||
if (col.HasProperty(c => c.EditTemplate)) | ||
throw new NotSupportedException("EditTemplate is not supported in DynamicGridColumnGroup."); | ||
|
||
var props = col.PropertyValue<Props>(PropsProperty).NotNull(); | ||
|
||
var context = new DynamicDataContext(col.Control.DataContextTypeStack, col.Configuration.ServiceProvider) | ||
{ | ||
ViewName = props.ViewName, | ||
GroupName = props.GroupName | ||
}; | ||
|
||
var properties = DynamicEntityBase.GetPropertiesToDisplay(context); | ||
|
||
var columns = properties.Select(p => CreateColumn(p, context, props)).ToArray(); | ||
return columns; | ||
} | ||
|
||
protected static DynamicGridColumn CreateColumn(PropertyDisplayMetadata property, DynamicDataContext context, Props props) | ||
{ | ||
return | ||
new DynamicGridColumn() | ||
.SetProperty(p => p.Property, context.CreateValueBinding(property)); | ||
// .SetProperty("Changed", props.Changed.GetValueOrDefault(property.PropertyInfo.Name)) | ||
// .SetProperty("Enabled", props.Enabled.GetValueOrDefault(property.PropertyInfo.Name, true)); | ||
} | ||
|
||
public override void CreateControls(IDotvvmRequestContext context, DotvvmControl container) => throw new NotImplementedException("DynamicGridColumn must be replaced using server-side styles. It cannot be used at runtime"); | ||
public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container) => throw new NotImplementedException("DynamicGridColumn must be replaced using server-side styles. It cannot be used at runtime"); | ||
|
||
[DotvvmControlCapability] | ||
public sealed record Props | ||
{ | ||
/// <summary> | ||
/// Gets or sets the view name (e.g. Insert, Edit, ReadOnly). Some fields may have different metadata for each view. | ||
/// </summary> | ||
public string? ViewName { get; init; } | ||
|
||
|
||
/// <summary> | ||
/// Gets or sets the group of fields that should be rendered. If not set, fields from all groups will be rendered. | ||
/// </summary> | ||
public string? GroupName { get; init; } | ||
|
||
public IValueBinding? Property { get; init; } | ||
public ValueOrBinding<bool> IsEditable { get; init; } = new(true); | ||
} | ||
} | ||
} |
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
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
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
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
46 changes: 46 additions & 0 deletions
46
src/Tests/ControlTests/testoutputs/DynamicDataTests.BasicDynamicGrid.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,46 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
|
||
<!-- ko if: List()?.length --> | ||
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':List()}"> | ||
<thead> | ||
<tr> | ||
<th> | ||
<span></span> | ||
</th> | ||
<th class=""> | ||
<span>Id</span> | ||
</th> | ||
<th class=""> | ||
<span>Name</span> | ||
</th> | ||
<th class=""> | ||
<span>Email</span> | ||
</th> | ||
<th class=""> | ||
<span>Sometime</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody data-bind="foreach: List"> | ||
<tr> | ||
<td></td> | ||
<td> | ||
<span data-bind="text: Id"></span> | ||
</td> | ||
<td> | ||
<span data-bind="text: Name"></span> | ||
</td> | ||
<td> | ||
<span data-bind="text: Email"></span> | ||
</td> | ||
<td> | ||
<span data-bind="text: dotvvm.globalize.formatString("", Sometime)"></span> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<!-- /ko --> | ||
</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