├── src ├── Tools │ ├── NuGet.exe │ ├── transform │ │ ├── Microsoft.Web.XmlTransform.dll │ │ └── WebConfigTransformRunner.exe │ ├── CI │ │ └── restore.cmd │ └── build │ │ ├── CopyPackageBetweenNugetFeeds.ps1 │ │ └── publish.ps1 ├── DotVVM.Framework.Controls.DynamicData │ ├── ColumnPlacement.cs │ ├── Builders │ │ ├── IFormBuilder.cs │ │ ├── FormBuilderBase.cs │ │ ├── BootstrapFormGroupBuilder.cs │ │ └── TableDynamicFormBuilder.cs │ ├── Utils │ │ ├── PropertyMatch.cs │ │ ├── PropertyDelegateMatch.cs │ │ ├── PropertyNameMatch.cs │ │ └── PropertyExactMatch.cs │ ├── PropertyHandlers │ │ ├── IDynamicDataPropertyHandler.cs │ │ ├── GridColumns │ │ │ ├── IGridColumnProvider.cs │ │ │ ├── CheckBoxGridColumnProvider.cs │ │ │ ├── GridColumnProviderBase.cs │ │ │ └── TextGridColumnProvider.cs │ │ ├── FormEditors │ │ │ ├── IFormEditorProvider.cs │ │ │ ├── FormEditorProviderBase.cs │ │ │ ├── CheckBoxEditorProvider.cs │ │ │ ├── TextBoxEditorProvider.cs │ │ │ ├── ComboBoxConventionFormEditorProvider.cs │ │ │ └── ComboBoxFormEditorProviderBase.cs │ │ ├── DynamicDataPropertyHandlerBase.cs │ │ └── TextBoxHelper.cs │ ├── ViewContext.cs │ ├── Configuration │ │ ├── ComboBoxConvention.cs │ │ ├── ComboBoxConventions.cs │ │ └── DynamicDataConfiguration.cs │ ├── StateBagKey.cs │ ├── Metadata │ │ ├── IPropertyDisplayMetadataProvider.cs │ │ ├── IEntityPropertyListProvider.cs │ │ ├── PropertyDisplayMetadata.cs │ │ ├── ResourcePropertyDisplayMetadataProvider.cs │ │ ├── DataAnnotationsPropertyDisplayMetadataProvider.cs │ │ ├── DefaultEntityPropertyListProvider.cs │ │ └── ResourceViewModelValidationMetadataProvider.cs │ ├── ControlHelpers.cs │ ├── DynamicEditor.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── DataContextStackHelper.cs │ ├── DotVVM.Framework.Controls.DynamicData.csproj │ ├── ServiceCollectionExtensions.cs │ ├── DynamicDataExtensions.cs │ ├── DynamicEntity.cs │ ├── DynamicDataGridViewDecorator.cs │ └── DynamicDataContext.cs ├── DotVVM.Framework.Controls.DynamicData.Annotations │ ├── VisibilityMode.cs │ ├── IVisibilityFilter.cs │ ├── IViewContext.cs │ ├── ComboBoxSettingsAttribute.cs │ ├── UnmatchedFilterAttribute.cs │ ├── AuthenticatedFilterAttribute.cs │ ├── StyleAttribute.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ViewFilterAttribute.cs │ ├── RoleFilterAttribute.cs │ └── DotVVM.Framework.Controls.DynamicData.Annotations.csproj ├── .config │ └── dotnet-tools.json └── DotVVM.Framework.DynamicData.sln ├── .gitignore ├── README.md └── LICENSE /src/Tools/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riganti/dotvvm-dynamic-data/HEAD/src/Tools/NuGet.exe -------------------------------------------------------------------------------- /src/Tools/transform/Microsoft.Web.XmlTransform.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riganti/dotvvm-dynamic-data/HEAD/src/Tools/transform/Microsoft.Web.XmlTransform.dll -------------------------------------------------------------------------------- /src/Tools/transform/WebConfigTransformRunner.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riganti/dotvvm-dynamic-data/HEAD/src/Tools/transform/WebConfigTransformRunner.exe -------------------------------------------------------------------------------- /src/Tools/CI/restore.cmd: -------------------------------------------------------------------------------- 1 | @echo restoring dot net core packages 2 | 3 | cd DotVVM.Framework.Controls.DynamicData 4 | dotnet restore --source http://nuget.riganti.cz:8080/nuget --source https://nuget.org/api/v2/ -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/ColumnPlacement.cs: -------------------------------------------------------------------------------- 1 | namespace DotVVM.Framework.Controls.DynamicData 2 | { 3 | public enum ColumnPlacement 4 | { 5 | Left = 0, 6 | Right = 1 7 | } 8 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/VisibilityMode.cs: -------------------------------------------------------------------------------- 1 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 2 | { 3 | public enum VisibilityMode 4 | { 5 | Show, 6 | Hide 7 | } 8 | } -------------------------------------------------------------------------------- /src/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "signclient": { 6 | "version": "1.2.33", 7 | "commands": [ 8 | "SignClient" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Builders/IFormBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace DotVVM.Framework.Controls.DynamicData.Builders 2 | { 3 | public interface IFormBuilder 4 | { 5 | void BuildForm(DotvvmControl hostControl, DynamicDataContext dynamicDataContext); 6 | } 7 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Utils/PropertyMatch.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.Utils 4 | { 5 | public abstract class PropertyMatch 6 | { 7 | 8 | public abstract bool IsMatch(PropertyInfo property); 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/IDynamicDataPropertyHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers 4 | { 5 | public interface IDynamicDataPropertyHandler 6 | { 7 | bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context); 8 | } 9 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/ViewContext.cs: -------------------------------------------------------------------------------- 1 | using DotVVM.Framework.Controls.DynamicData.Annotations; 2 | using System.Security.Principal; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData 5 | { 6 | public class ViewContext : IViewContext 7 | { 8 | public string ViewName { get; set; } 9 | public string GroupName { get; set; } 10 | public IPrincipal CurrentUser { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Configuration/ComboBoxConvention.cs: -------------------------------------------------------------------------------- 1 | using DotVVM.Framework.Controls.DynamicData.Annotations; 2 | using DotVVM.Framework.Controls.DynamicData.Utils; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.Configuration 5 | { 6 | public class ComboBoxConvention 7 | { 8 | public PropertyMatch Match { get; set; } 9 | 10 | public ComboBoxSettingsAttribute Settings { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Utils/PropertyDelegateMatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.Utils 5 | { 6 | public class PropertyDelegateMatch : PropertyMatch 7 | { 8 | 9 | public Func Delegate { get; set; } 10 | 11 | public override bool IsMatch(PropertyInfo property) 12 | { 13 | return Delegate(property); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/GridColumns/IGridColumnProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using DotVVM.Framework.Controls.DynamicData.Metadata; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.GridColumns 5 | { 6 | public interface IGridColumnProvider : IDynamicDataPropertyHandler 7 | { 8 | 9 | GridViewColumn CreateColumn(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/StateBagKey.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData 4 | { 5 | public struct StateBagKey 6 | { 7 | 8 | public object Provider { get; private set; } 9 | 10 | public PropertyInfo Property { get; private set; } 11 | 12 | public StateBagKey(object provider, PropertyInfo property) : this() 13 | { 14 | Provider = provider; 15 | Property = property; 16 | } 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Utils/PropertyNameMatch.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.Utils 4 | { 5 | public class PropertyNameMatch : PropertyMatch 6 | { 7 | 8 | public string PropertyName { get; } 9 | 10 | public PropertyNameMatch(string propertyName) 11 | { 12 | PropertyName = propertyName; 13 | } 14 | 15 | 16 | public override bool IsMatch(PropertyInfo property) 17 | { 18 | return property.Name == PropertyName; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Utils/PropertyExactMatch.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.Utils 4 | { 5 | public class PropertyExactMatch : PropertyMatch 6 | { 7 | public PropertyInfo PropertyInfo { get; set; } 8 | 9 | public PropertyExactMatch(PropertyInfo property) 10 | { 11 | PropertyInfo = property; 12 | } 13 | 14 | 15 | public override bool IsMatch(PropertyInfo property) 16 | { 17 | return property.Equals(PropertyInfo); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/IVisibilityFilter.cs: -------------------------------------------------------------------------------- 1 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 2 | { 3 | /// 4 | /// Represents an attribute that defines conditions for a field to be shown or hidden. 5 | /// 6 | public interface IVisibilityFilter 7 | { 8 | /// 9 | /// Evaluates whether the field should be shown or hidden. If this method returns null, the next filter attribute will be evaluated. 10 | /// 11 | VisibilityMode? CanShow(IViewContext viewContext); 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/IPropertyDisplayMetadataProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 4 | { 5 | /// 6 | /// Provides information about how the property is displayed in the user interface. 7 | /// 8 | public interface IPropertyDisplayMetadataProvider 9 | { 10 | 11 | /// 12 | /// Get the metadata about how the property is displayed. 13 | /// 14 | PropertyDisplayMetadata GetPropertyMetadata(PropertyInfo property); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/IEntityPropertyListProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DotVVM.Framework.Controls.DynamicData.Annotations; 4 | 5 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 6 | { 7 | /// 8 | /// Provides a list of properties for the specified entity. 9 | /// 10 | public interface IEntityPropertyListProvider 11 | { 12 | 13 | 14 | /// 15 | /// Gets a list of properties for the specified entity and view name. 16 | /// 17 | IList GetProperties(Type entityType, IViewContext viewContext); 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/IFormEditorProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using DotVVM.Framework.Binding.Expressions; 3 | using DotVVM.Framework.Controls.DynamicData.Metadata; 4 | 5 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors 6 | { 7 | public interface IFormEditorProvider : IDynamicDataPropertyHandler 8 | { 9 | 10 | bool RenderDefaultLabel { get; } 11 | 12 | bool CanValidate { get; } 13 | 14 | ValueBindingExpression GetValidationValueBinding(PropertyDisplayMetadata property, DynamicDataContext context); 15 | 16 | void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context); 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/DynamicDataPropertyHandlerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers 5 | { 6 | public abstract class DynamicDataPropertyHandlerBase : IDynamicDataPropertyHandler 7 | { 8 | 9 | public abstract bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context); 10 | 11 | public static Type UnwrapNullableType(Type type) 12 | { 13 | if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) 14 | { 15 | type = type.GetGenericArguments()[0]; 16 | } 17 | return type; 18 | } 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /src/Tools/build/CopyPackageBetweenNugetFeeds.ps1: -------------------------------------------------------------------------------- 1 | Param( 2 | [string]$version, 3 | [string]$server, 4 | [string]$internalServer, 5 | [string]$apiKey, 6 | [string]$packageId 7 | ) 8 | 9 | # get package 10 | & .\tools\nuget.exe install $packageId -OutputDirectory .\tools\packages -version $version -DirectDownload -NoCache -DependencyVersion Ignore -source $internalServer 11 | $nupkgFile = dir -s ./tools/packages/$packageId.$version.nupkg | Select -First 1 12 | Write-Host "Downloaded package located on '$nupkgFile'" 13 | 14 | if ($nupkgFile) { 15 | # upload 16 | Write-Host "Uploading package..." 17 | & .\tools\nuget.exe push $nupkgFile -source $server -apiKey $apiKey 18 | Write-Host "Package uploaded to $server." 19 | } 20 | if ( Test-Path -Path ./tools/packages ) { 21 | Remove-Item -Recurse -Force ./tools/packages 22 | } 23 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/IViewContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Principal; 4 | using System.Text; 5 | 6 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 7 | { 8 | /// 9 | /// Provides information about the context in which the field is being rendered. 10 | /// 11 | public interface IViewContext 12 | { 13 | 14 | /// 15 | /// Gets the name of the current view. 16 | /// 17 | string ViewName { get; } 18 | 19 | /// 20 | /// Gets the name of the current field group. 21 | /// 22 | string GroupName { get; } 23 | 24 | /// 25 | /// Gets the current principal. 26 | /// 27 | IPrincipal CurrentUser { get; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/GridColumns/CheckBoxGridColumnProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using DotVVM.Framework.Controls.DynamicData.Metadata; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.GridColumns 5 | { 6 | public class CheckBoxGridColumnProvider : GridColumnProviderBase 7 | { 8 | public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 9 | { 10 | return UnwrapNullableType(propertyInfo.PropertyType) == typeof(bool); 11 | } 12 | 13 | protected override GridViewColumn CreateColumnCore(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context) 14 | { 15 | var column = new GridViewCheckBoxColumn(); 16 | column.SetBinding(GridViewCheckBoxColumn.ValueBindingProperty, context.CreateValueBinding(property.PropertyInfo.Name)); 17 | return column; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/PropertyDisplayMetadata.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.Reflection; 3 | using DotVVM.Framework.Controls.DynamicData.Annotations; 4 | 5 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 6 | { 7 | public class PropertyDisplayMetadata 8 | { 9 | 10 | public PropertyInfo PropertyInfo { get; set; } 11 | 12 | public string DisplayName { get; set; } 13 | 14 | public string GroupName { get; set; } 15 | 16 | public int? Order { get; set; } 17 | 18 | public string FormatString { get; set; } 19 | 20 | public string NullDisplayText { get; set; } 21 | 22 | public bool AutoGenerateField { get; set; } 23 | 24 | public DataType? DataType { get; set; } 25 | 26 | public IVisibilityFilter[] VisibilityFilters { get; set; } 27 | 28 | public StyleAttribute Styles { get; set; } 29 | public bool IsEditAllowed { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/GridColumns/GridColumnProviderBase.cs: -------------------------------------------------------------------------------- 1 | using DotVVM.Framework.Controls.DynamicData.Metadata; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.GridColumns 4 | { 5 | public abstract class GridColumnProviderBase : DynamicDataPropertyHandlerBase, IGridColumnProvider 6 | { 7 | public GridViewColumn CreateColumn(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context) 8 | { 9 | var column = CreateColumnCore(gridView, property, context); 10 | 11 | column.CssClass = ControlHelpers.ConcatCssClasses(column.CssClass, property.Styles?.GridCellCssClass); 12 | column.HeaderCssClass = ControlHelpers.ConcatCssClasses(column.HeaderCssClass, property.Styles?.GridHeaderCellCssClass); 13 | 14 | return column; 15 | } 16 | 17 | protected abstract GridViewColumn CreateColumnCore(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context); 18 | } 19 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/ControlHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using DotVVM.Framework.Binding; 6 | 7 | namespace DotVVM.Framework.Controls.DynamicData 8 | { 9 | public static class ControlHelpers 10 | { 11 | 12 | public static void CopyProperty(DotvvmBindableObject source, DotvvmProperty sourceProperty, DotvvmBindableObject target, DotvvmProperty targetProperty) 13 | { 14 | var binding = source.GetValueBinding(sourceProperty); 15 | if (binding != null) 16 | { 17 | target.SetBinding(targetProperty, binding); 18 | } 19 | else 20 | { 21 | target.SetValue(targetProperty, source.GetValue(sourceProperty)); 22 | } 23 | } 24 | 25 | public static string ConcatCssClasses(params string[] fragments) 26 | { 27 | return string.Join(" ", fragments.Select(f => f?.Trim() ?? "").Where(f => !string.IsNullOrEmpty(f))); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/GridColumns/TextGridColumnProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using DotVVM.Framework.Controls.DynamicData.Metadata; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.GridColumns 5 | { 6 | public class TextGridColumnProvider : GridColumnProviderBase 7 | { 8 | public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 9 | { 10 | return TextBoxHelper.CanHandleProperty(propertyInfo, context); 11 | } 12 | 13 | protected override GridViewColumn CreateColumnCore(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context) 14 | { 15 | var column = new GridViewTextColumn(); 16 | column.ValueType = TextBoxHelper.GetValueTypeOrDefault(property.PropertyInfo); 17 | column.FormatString = property.FormatString; 18 | column.SetBinding(GridViewTextColumn.ValueBindingProperty, context.CreateValueBinding(property.PropertyInfo.Name)); 19 | column.IsEditable = property.IsEditAllowed; 20 | return column; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/ComboBoxSettingsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 6 | { 7 | /// 8 | /// Defines the settings for the ComboBox form editor provider. 9 | /// 10 | [AttributeUsage(AttributeTargets.Property)] 11 | public class ComboBoxSettingsAttribute : Attribute 12 | { 13 | 14 | /// 15 | /// Gets or sets the name of the property to be displayed. 16 | /// 17 | public string DisplayMember { get; set; } 18 | 19 | /// 20 | /// Gets or sets the name of the property to be used as selected value. 21 | /// 22 | public string ValueMember { get; set; } 23 | 24 | /// 25 | /// Gets or sets the binding expression for the list of items. 26 | /// 27 | public string DataSourceBinding { get; set; } 28 | 29 | /// 30 | /// Gets or sets the text on the empty item. If null or empty, the empty item will not be included. 31 | /// 32 | public string EmptyItemText { get; set; } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/UnmatchedFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 4 | { 5 | /// 6 | /// Specifies whether the field should be shown or hidden if none of the filter attributes is matched. 7 | /// 8 | public class UnmatchedFilterAttribute : Attribute, IVisibilityFilter 9 | { 10 | /// 11 | /// Gets or sets whether the field will be shown or hidden. 12 | /// 13 | public VisibilityMode Mode { get; } 14 | 15 | /// 16 | /// Initializes a new instance of class. 17 | /// 18 | /// Specified whether the field should be shown or hidden. 19 | public UnmatchedFilterAttribute(VisibilityMode mode) 20 | { 21 | Mode = mode; 22 | } 23 | 24 | /// 25 | /// Evaluates whether the field should be shown or hidden. If this method returns null, the next filter attribute will be evaluated. 26 | /// 27 | public VisibilityMode? CanShow(IViewContext viewContext) 28 | { 29 | return Mode; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/FormEditorProviderBase.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using DotVVM.Framework.Binding.Expressions; 3 | using DotVVM.Framework.Controls.DynamicData.Metadata; 4 | 5 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors 6 | { 7 | public abstract class FormEditorProviderBase : DynamicDataPropertyHandlerBase, IFormEditorProvider 8 | { 9 | public string ControlCssClass { get; set; } 10 | 11 | public virtual bool RenderDefaultLabel => true; 12 | 13 | public virtual bool CanValidate => false; 14 | 15 | public ValueBindingExpression GetValidationValueBinding(PropertyDisplayMetadata property, DynamicDataContext context) 16 | { 17 | return context.CreateValueBinding(property.PropertyInfo.Name); 18 | } 19 | 20 | public abstract void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context); 21 | 22 | protected virtual void SetValidatorValueBinding(DotvvmBindableObject textBox, BindingExpression valueBindingExpression) 23 | { 24 | if (CanValidate) 25 | { 26 | textBox.SetBinding(Validator.ValueProperty, valueBindingExpression); 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DynamicEditor.cs: -------------------------------------------------------------------------------- 1 | using DotVVM.Framework.Binding; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using DotVVM.Framework.Binding.Expressions; 8 | using DotVVM.Framework.Hosting; 9 | 10 | namespace DotVVM.Framework.Controls.DynamicData 11 | { 12 | /// 13 | /// Creates the editor for the specified property using the metadata information. 14 | /// 15 | public class DynamicEditor : HtmlGenericControl 16 | { 17 | 18 | /// 19 | /// Gets or sets the property that should be edited. 20 | /// 21 | public IValueBinding Property 22 | { 23 | get { return (IValueBinding)GetValue(PropertyProperty); } 24 | set { SetValue(PropertyProperty, value); } 25 | } 26 | public static readonly DotvvmProperty PropertyProperty 27 | = DotvvmProperty.Register(c => c.Property, null); 28 | 29 | 30 | public DynamicEditor() : base("div") 31 | { 32 | } 33 | 34 | protected override void OnInit(IDotvvmRequestContext context) 35 | { 36 | 37 | 38 | 39 | base.OnInit(context); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Configuration/ComboBoxConventions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using DotVVM.Framework.Controls.DynamicData.Annotations; 5 | using DotVVM.Framework.Controls.DynamicData.Utils; 6 | 7 | namespace DotVVM.Framework.Controls.DynamicData.Configuration 8 | { 9 | public class ComboBoxConventions 10 | { 11 | 12 | public List Conventions { get; } = new List(); 13 | 14 | 15 | public void Register(string propertyName, ComboBoxSettingsAttribute settings) 16 | { 17 | Conventions.Add(new ComboBoxConvention() 18 | { 19 | Match = new PropertyNameMatch(propertyName), 20 | Settings = settings 21 | }); 22 | } 23 | 24 | public void Register(PropertyInfo property, ComboBoxSettingsAttribute settings) 25 | { 26 | Conventions.Add(new ComboBoxConvention() 27 | { 28 | Match = new PropertyExactMatch(property), 29 | Settings = settings 30 | }); 31 | } 32 | 33 | public void Register(Func predicate, ComboBoxSettingsAttribute settings) 34 | { 35 | Conventions.Add(new ComboBoxConvention() 36 | { 37 | Match = new PropertyDelegateMatch() { Delegate = predicate }, 38 | Settings = settings 39 | }); 40 | } 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/AuthenticatedFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Security.Claims; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 5 | { 6 | /// 7 | /// Show or hides the field based on current user authentication status. 8 | /// 9 | [AttributeUsage(AttributeTargets.Property)] 10 | public class AuthenticatedFilterAttribute : Attribute, IVisibilityFilter 11 | { 12 | /// 13 | /// Gets or sets whether the field will be shown or hidden. 14 | /// 15 | public VisibilityMode Mode { get; } 16 | 17 | /// 18 | /// Initializes a new instance of class. 19 | /// 20 | /// Specified whether the field should be shown or hidden when the user is authenticated. 21 | public AuthenticatedFilterAttribute(VisibilityMode mode = VisibilityMode.Show) 22 | { 23 | Mode = mode; 24 | } 25 | 26 | /// 27 | /// Evaluates whether the field should be shown or hidden. If this method returns null, the next filter attribute will be evaluated. 28 | /// 29 | public VisibilityMode? CanShow(IViewContext viewContext) 30 | { 31 | if (viewContext.CurrentUser?.Identity?.IsAuthenticated == true) 32 | { 33 | return Mode; 34 | } 35 | return null; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/StyleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 4 | { 5 | /// 6 | /// Defines the CSS classes applied to the field. 7 | /// 8 | [AttributeUsage(AttributeTargets.Property)] 9 | public class StyleAttribute : Attribute 10 | { 11 | 12 | /// 13 | /// Gets or sets the CSS class applied to the container of the form control (e.g. table cell which contains the TextBox control) for this field. 14 | /// 15 | public string FormControlContainerCssClass { get; set; } 16 | 17 | /// 18 | /// Gets or sets the CSS class applied to the row in the form (e.g. table row which contains the label and the TextBox control) for this field. 19 | /// 20 | public string FormRowCssClass { get; set; } 21 | 22 | /// 23 | /// Gets or sets the CSS class applied to the control in the form. 24 | /// 25 | public string FormControlCssClass { get; set; } 26 | 27 | /// 28 | /// Gets or sets the CSS class applied to the GridView table cell for this field. 29 | /// 30 | public string GridCellCssClass { get; set; } 31 | 32 | /// 33 | /// Gets or sets the CSS class applied to the GridView table header cell for this field. 34 | /// 35 | public string GridHeaderCellCssClass { get; set; } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotVVM.Framework.Controls.DynamicData")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotVVM.Framework.Controls.DynamicData")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("442c940c-47c5-422d-a676-e3e51200fc6a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("3.1.0")] 35 | [assembly: AssemblyVersion("3.1.0")] 36 | [assembly: AssemblyFileVersion("3.1.0")] 37 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("DotVVM.Framework.Controls.DynamicData.Annotations")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DotVVM.Framework.Controls.DynamicData.Annotations")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("442c940c-47c5-422d-a676-e3e51200fc6a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("3.1.0")] 35 | [assembly: AssemblyVersion("3.1.0")] 36 | [assembly: AssemblyFileVersion("3.1.0")] 37 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/CheckBoxEditorProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using DotVVM.Framework.Controls.DynamicData.Metadata; 4 | 5 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors 6 | { 7 | /// 8 | /// Renders a CheckBox control for properties of boolean type. 9 | /// 10 | public class CheckBoxEditorProvider : FormEditorProviderBase 11 | { 12 | public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 13 | { 14 | return UnwrapNullableType(propertyInfo.PropertyType) == typeof(bool); 15 | } 16 | 17 | public override bool CanValidate => true; 18 | 19 | public override bool RenderDefaultLabel => false; 20 | 21 | public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context) 22 | { 23 | var checkBox = new CheckBox(); 24 | container.Children.Add(checkBox); 25 | 26 | var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass); 27 | if (!string.IsNullOrEmpty(cssClass)) 28 | { 29 | checkBox.Attributes["class"] = cssClass; 30 | } 31 | 32 | checkBox.Text = property.DisplayName; 33 | checkBox.SetBinding(CheckBox.CheckedProperty, context.CreateValueBinding(property.PropertyInfo.Name)); 34 | 35 | if (checkBox.IsPropertySet(DynamicEntity.EnabledProperty)) 36 | { 37 | ControlHelpers.CopyProperty(checkBox, DynamicEntity.EnabledProperty, checkBox, CheckableControlBase.EnabledProperty); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DataContextStackHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using DotVVM.Framework.Binding; 5 | using DotVVM.Framework.Binding.Expressions; 6 | using DotVVM.Framework.Binding.Properties; 7 | using DotVVM.Framework.Compilation; 8 | using DotVVM.Framework.Compilation.ControlTree; 9 | using DotVVM.Framework.Utils; 10 | 11 | namespace DotVVM.Framework.Controls.DynamicData 12 | { 13 | public static class DataContextStackHelper 14 | { 15 | public static DataContextStack GetItemDataContextStack(this DotvvmBindableObject bindableObject, DotvvmProperty dataSourceProperty) 16 | { 17 | return bindableObject.GetValueBinding(dataSourceProperty) 18 | ?.GetProperty()?.DataContext; 19 | } 20 | 21 | public static DataContextStack CreateChildStack(this DotvvmBindableObject bindableObject, Type viewModelType) 22 | { 23 | var dataContextTypeStack = bindableObject.GetDataContextType(); 24 | 25 | return DataContextStack.Create( 26 | viewModelType, 27 | dataContextTypeStack, 28 | dataContextTypeStack.NamespaceImports, 29 | dataContextTypeStack.ExtensionParameters, 30 | dataContextTypeStack.BindingPropertyResolvers); 31 | } 32 | 33 | public static DataContextStack CreateChildStack(this DataContextStack dataContextStack, Type viewModelType) 34 | { 35 | return DataContextStack.Create( 36 | viewModelType, 37 | dataContextStack, 38 | dataContextStack.NamespaceImports, 39 | dataContextStack.ExtensionParameters, 40 | dataContextStack.BindingPropertyResolvers); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Builders/FormBuilderBase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using DotVVM.Framework.Controls.DynamicData.Metadata; 4 | using DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors; 5 | 6 | namespace DotVVM.Framework.Controls.DynamicData.Builders 7 | { 8 | /// 9 | /// A base implementation for the form builder control. 10 | /// 11 | public abstract class FormBuilderBase : IFormBuilder 12 | { 13 | /// 14 | /// Gets the list of properties that should be displayed. 15 | /// 16 | protected virtual IEnumerable GetPropertiesToDisplay(DynamicDataContext dynamicDataContext, IEntityPropertyListProvider entityPropertyListProvider) 17 | { 18 | var viewContext = dynamicDataContext.CreateViewContext(dynamicDataContext.RequestContext); 19 | var properties = entityPropertyListProvider.GetProperties(dynamicDataContext.EntityType, viewContext); 20 | if (!string.IsNullOrEmpty(dynamicDataContext.GroupName)) 21 | { 22 | return properties.Where(p => p.GroupName == dynamicDataContext.GroupName); 23 | } 24 | return properties; 25 | } 26 | 27 | /// 28 | /// Finds the editor provider for the specified property. 29 | /// 30 | protected virtual IFormEditorProvider FindEditorProvider(PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 31 | { 32 | return dynamicDataContext.DynamicDataConfiguration.FormEditorProviders 33 | .FirstOrDefault(e => e.CanHandleProperty(property.PropertyInfo, dynamicDataContext)); 34 | } 35 | 36 | public abstract void BuildForm(DotvvmControl hostControl, DynamicDataContext dynamicDataContext); 37 | } 38 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/ViewFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 5 | { 6 | /// 7 | /// Show or hides the field based on the current view. 8 | /// 9 | [AttributeUsage(AttributeTargets.Property)] 10 | public class ViewFilterAttribute : Attribute, IVisibilityFilter 11 | { 12 | /// 13 | /// Gets or sets the names of the views that this attribute applies to. 14 | /// 15 | public string[] ViewNames { get; } 16 | 17 | /// 18 | /// Gets or sets whether the field will be shown or hidden. 19 | /// 20 | public VisibilityMode Mode { get; } 21 | 22 | 23 | /// 24 | /// Initializes a new instance of class. 25 | /// 26 | /// Comma-separated list of views. The rule is matched if the current view is one of the values of this parameter. 27 | /// Specified whether the field should be shown or hidden when the rule is matched. 28 | public ViewFilterAttribute(string viewNames, VisibilityMode mode = VisibilityMode.Show) 29 | { 30 | ViewNames = viewNames.Split(',', ';').Select(v => v.Trim()).ToArray(); 31 | Mode = mode; 32 | } 33 | 34 | /// 35 | /// Evaluates whether the field should be shown or hidden. If this method returns null, the next filter attribute will be evaluated. 36 | /// 37 | public VisibilityMode? CanShow(IViewContext viewContext) 38 | { 39 | if (ViewNames.Contains(viewContext.ViewName, StringComparer.CurrentCultureIgnoreCase)) 40 | { 41 | return Mode; 42 | } 43 | return null; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/TextBoxHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers 9 | { 10 | public static class TextBoxHelper 11 | { 12 | private static readonly HashSet stringTypes = new HashSet() { typeof(string), typeof(Guid) }; 13 | private static readonly HashSet numericTypes = new HashSet() { typeof(float), typeof(double), typeof(decimal), typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong) }; 14 | private static readonly HashSet dateTypes = new HashSet() { typeof(DateTime) }; 15 | 16 | public static bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 17 | { 18 | var type = DynamicDataPropertyHandlerBase.UnwrapNullableType(propertyInfo.PropertyType); 19 | return stringTypes.Contains(type) || numericTypes.Contains(type) || dateTypes.Contains(type); 20 | } 21 | 22 | public static FormatValueType? GetValueType(PropertyInfo propertyInfo) 23 | { 24 | var type = DynamicDataPropertyHandlerBase.UnwrapNullableType(propertyInfo.PropertyType); 25 | if (numericTypes.Contains(type)) 26 | { 27 | return FormatValueType.Number; 28 | } 29 | else if (dateTypes.Contains(type)) 30 | { 31 | return FormatValueType.DateTime; 32 | } 33 | if (stringTypes.Contains(type)) 34 | { 35 | return FormatValueType.Text; 36 | } 37 | 38 | return null; 39 | } 40 | 41 | public static FormatValueType GetValueTypeOrDefault(PropertyInfo propertyPropertyInfo) 42 | { 43 | return GetValueType(propertyPropertyInfo) ?? FormatValueType.Text; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/RoleFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | 7 | namespace DotVVM.Framework.Controls.DynamicData.Annotations 8 | { 9 | /// 10 | /// Show or hides the field based on current user role memebership. 11 | /// 12 | [AttributeUsage(AttributeTargets.Property)] 13 | public class RoleFilterAttribute : Attribute, IVisibilityFilter 14 | { 15 | /// 16 | /// Gets or sets the names of the roles that this attribute applies to. 17 | /// 18 | public string[] RoleNames { get; } 19 | 20 | /// 21 | /// Gets or sets whether the field will be shown or hidden. 22 | /// 23 | public VisibilityMode Mode { get; } 24 | 25 | 26 | /// 27 | /// Initializes a new instance of class. 28 | /// 29 | /// Comma-separated list of roles. The rule is matched if the user is in any of the roles. 30 | /// Specified whether the field should be shown or hidden when the user is in any of the roles. 31 | public RoleFilterAttribute(string roleNames, VisibilityMode mode = VisibilityMode.Show) 32 | { 33 | Mode = mode; 34 | RoleNames = roleNames.Split(',', ';').Select(s => s.Trim()).ToArray(); 35 | } 36 | 37 | /// 38 | /// Evaluates whether the field should be shown or hidden. If this method returns null, the next filter attribute will be evaluated. 39 | /// 40 | public VisibilityMode? CanShow(IViewContext viewContext) 41 | { 42 | if (viewContext.CurrentUser != null && RoleNames.Any(viewContext.CurrentUser.IsInRole)) 43 | { 44 | return Mode; 45 | } 46 | return null; 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData.Annotations/DotVVM.Framework.Controls.DynamicData.Annotations.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0;net451;netcoreapp2.0 4 | win7-x64;win7-x86 5 | DotVVM.DynamicData.Annotations 6 | 3.1.0 7 | 3.1.0 8 | RIGANTI 9 | 10 | Annotation attributes for DotVVM Dynamic Data that provide additional features. 11 | 12 | false 13 | dotvvm;asp.net;mvvm;owin;dotnetcore;dnx;dynamic data;annotations;metadata;ui generation 14 | https://dotvvm.com/Content/images/icons/icon-blue-64x64.png 15 | Apache-2.0 16 | https://github.com/riganti/dotvvm-dynamic-data 17 | false 18 | false 19 | false 20 | false 21 | false 22 | false 23 | false 24 | false 25 | true 26 | 27 | 28 | 1701;1702;1591 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/TextBoxEditorProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Reflection; 5 | using DotVVM.Framework.Controls.DynamicData.Metadata; 6 | 7 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors 8 | { 9 | /// 10 | /// Renders a TextBox control for properties of string, numeric or date type. 11 | /// 12 | public class TextBoxEditorProvider : FormEditorProviderBase 13 | { 14 | public override bool CanValidate => true; 15 | 16 | public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 17 | { 18 | return TextBoxHelper.CanHandleProperty(propertyInfo, context); 19 | } 20 | 21 | public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context) 22 | { 23 | if (!property.IsEditAllowed) 24 | { 25 | var literal = new Literal(); 26 | container.Children.Add(literal); 27 | literal.SetBinding(Literal.TextProperty, context.CreateValueBinding(property.PropertyInfo.Name)); 28 | 29 | return; 30 | } 31 | 32 | var textBox = new TextBox(); 33 | container.Children.Add(textBox); 34 | 35 | var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass); 36 | if (!string.IsNullOrEmpty(cssClass)) 37 | { 38 | textBox.Attributes["class"] = cssClass; 39 | } 40 | 41 | textBox.ValueType = TextBoxHelper.GetValueTypeOrDefault(property.PropertyInfo); 42 | textBox.FormatString = property.FormatString; 43 | textBox.SetBinding(TextBox.TextProperty, context.CreateValueBinding(property.PropertyInfo.Name)); 44 | 45 | if (property.DataType == DataType.Password) 46 | { 47 | textBox.Type = TextBoxType.Password; 48 | } 49 | else if (property.DataType == DataType.MultilineText) 50 | { 51 | textBox.Type = TextBoxType.MultiLine; 52 | } 53 | 54 | if (textBox.IsPropertySet(DynamicEntity.EnabledProperty)) 55 | { 56 | ControlHelpers.CopyProperty(textBox, DynamicEntity.EnabledProperty, textBox, TextBox.EnabledProperty); 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DotVVM.Framework.Controls.DynamicData.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0;net451;netcoreapp2.0 4 | DotVVM.DynamicData 5 | 3.1.0 6 | 3.1.0 7 | RIGANTI 8 | Dynamic Data implementation for DotVVM. 9 | DotVVM is an open source ASP.NET-based framework which allows to build modern web apps without writing any JavaScript code. 10 | false 11 | dotvvm;asp.net;mvvm;owin;dotnetcore;dnx;dynamic data;annotations;metadata;ui generation 12 | https://dotvvm.com/Content/images/icons/icon-blue-64x64.png 13 | https://github.com/riganti/dotvvm-dynamic-data/blob/master/LICENSE 14 | https://github.com/riganti/dotvvm-dynamic-data 15 | false 16 | false 17 | false 18 | false 19 | false 20 | false 21 | false 22 | false 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | $(DefineConstants);DotNetCore 41 | 42 | 43 | $(DefineConstants);RELEASE 44 | 45 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/ComboBoxConventionFormEditorProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using DotVVM.Framework.Controls.DynamicData.Configuration; 7 | using DotVVM.Framework.Controls.DynamicData.Metadata; 8 | 9 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors 10 | { 11 | /// 12 | /// Convention-based ComboBox form editor provider. 13 | /// 14 | public class ComboBoxConventionFormEditorProvider : ComboBoxFormEditorProvider 15 | { 16 | private readonly ComboBoxConventions comboBoxConventions; 17 | 18 | public ComboBoxConventionFormEditorProvider(ComboBoxConventions comboBoxConventions) 19 | { 20 | this.comboBoxConventions = comboBoxConventions; 21 | } 22 | 23 | public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 24 | { 25 | var matchedConvention = comboBoxConventions.Conventions.FirstOrDefault(c => c.Match.IsMatch(propertyInfo)); 26 | if (matchedConvention == null) 27 | { 28 | return false; 29 | } 30 | 31 | // store the convention in the context 32 | context.StateBag[new StateBagKey(this, propertyInfo)] = matchedConvention; 33 | return true; 34 | } 35 | 36 | protected override string GetDisplayMember(PropertyDisplayMetadata property, DynamicDataContext context) 37 | { 38 | return base.GetDisplayMember(property, context) ?? GetConvention(property, context).Settings.DisplayMember; 39 | } 40 | 41 | protected override string GetValueMember(PropertyDisplayMetadata property, DynamicDataContext context) 42 | { 43 | return base.GetValueMember(property, context) ?? GetConvention(property, context).Settings.ValueMember; 44 | } 45 | 46 | protected override string GetEmptyItemText(PropertyDisplayMetadata property, DynamicDataContext context) 47 | { 48 | return base.GetEmptyItemText(property, context) ?? GetConvention(property, context).Settings.EmptyItemText; 49 | } 50 | 51 | protected override string GetDataSourceBindingExpression(PropertyDisplayMetadata property, DynamicDataContext context) 52 | { 53 | return base.GetDataSourceBindingExpression(property, context) ?? GetConvention(property, context).Settings.DataSourceBinding; 54 | } 55 | 56 | private ComboBoxConvention GetConvention(PropertyDisplayMetadata property, DynamicDataContext context) 57 | { 58 | return (ComboBoxConvention)context.StateBag[new StateBagKey(this, property.PropertyInfo)]; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/ResourcePropertyDisplayMetadataProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Globalization; 4 | using System.Reflection; 5 | using System.Resources; 6 | using System.Threading; 7 | 8 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 9 | { 10 | /// 11 | /// Property display metadata provider which loads missing property names from the RESX file. 12 | /// 13 | public class ResourcePropertyDisplayMetadataProvider : IPropertyDisplayMetadataProvider 14 | { 15 | private readonly IPropertyDisplayMetadataProvider basePropertyDisplayMetadataProvider; 16 | private readonly ResourceManager propertyDisplayNames; 17 | 18 | private readonly ConcurrentDictionary cache = new ConcurrentDictionary(); 19 | 20 | /// 21 | /// Gets the type of the resource file that contains the property names. 22 | /// The resource key is in the "TypeName_PropertyName" or "PropertyName". 23 | /// 24 | public Type PropertyDisplayNameResourceFile { get; } 25 | 26 | 27 | public ResourcePropertyDisplayMetadataProvider(Type propertyDisplayNameResourceFile, IPropertyDisplayMetadataProvider basePropertyDisplayMetadataProvider) 28 | { 29 | this.basePropertyDisplayMetadataProvider = basePropertyDisplayMetadataProvider; 30 | 31 | PropertyDisplayNameResourceFile = propertyDisplayNameResourceFile; 32 | propertyDisplayNames = new ResourceManager(propertyDisplayNameResourceFile); 33 | } 34 | 35 | 36 | /// 37 | /// Get the metadata about how the property is displayed. 38 | /// 39 | public PropertyDisplayMetadata GetPropertyMetadata(PropertyInfo property) 40 | { 41 | return cache.GetOrAdd(new PropertyCulturePair(property, CultureInfo.CurrentUICulture), GetPropertyMetadataCore); 42 | } 43 | 44 | 45 | private PropertyDisplayMetadata GetPropertyMetadataCore(PropertyCulturePair pair) 46 | { 47 | var metadata = basePropertyDisplayMetadataProvider.GetPropertyMetadata(pair.PropertyInfo); 48 | 49 | if (string.IsNullOrEmpty(metadata.DisplayName)) 50 | { 51 | metadata.DisplayName = propertyDisplayNames.GetString(pair.PropertyInfo.DeclaringType.Name + "_" + pair.PropertyInfo.Name) 52 | ?? propertyDisplayNames.GetString(pair.PropertyInfo.Name); 53 | } 54 | 55 | return metadata; 56 | } 57 | 58 | 59 | private struct PropertyCulturePair 60 | { 61 | public CultureInfo Culture; 62 | public PropertyInfo PropertyInfo; 63 | 64 | public PropertyCulturePair(PropertyInfo propertyInfo, CultureInfo culture) 65 | { 66 | Culture = culture; 67 | PropertyInfo = propertyInfo; 68 | } 69 | } 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/DataAnnotationsPropertyDisplayMetadataProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Threading; 7 | using DotVVM.Framework.Controls.DynamicData.Annotations; 8 | 9 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 10 | { 11 | /// 12 | /// Provides information about how the property is displayed in the user interface. 13 | /// 14 | public class DataAnnotationsPropertyDisplayMetadataProvider : IPropertyDisplayMetadataProvider 15 | { 16 | 17 | private readonly ConcurrentDictionary cache = new ConcurrentDictionary(); 18 | 19 | /// 20 | /// Get the metadata about how the property is displayed. 21 | /// 22 | public PropertyDisplayMetadata GetPropertyMetadata(PropertyInfo property) 23 | { 24 | return cache.GetOrAdd(new PropertyCulturePair(property, CultureInfo.CurrentUICulture), GetPropertyMetadataCore); 25 | } 26 | 27 | private PropertyDisplayMetadata GetPropertyMetadataCore(PropertyCulturePair pair) 28 | { 29 | var displayAttribute = pair.PropertyInfo.GetCustomAttribute(); 30 | var displayFormatAttribute = pair.PropertyInfo.GetCustomAttribute(); 31 | var dataTypeAttribute = pair.PropertyInfo.GetCustomAttribute(); 32 | var styleAttribute = pair.PropertyInfo.GetCustomAttribute(); 33 | var visibilityFilters = pair.PropertyInfo.GetCustomAttributes().OfType().ToArray(); 34 | var editableFilter = pair.PropertyInfo.GetCustomAttribute(); 35 | 36 | return new PropertyDisplayMetadata() 37 | { 38 | PropertyInfo = pair.PropertyInfo, 39 | DisplayName = displayAttribute?.GetName(), 40 | Order = displayAttribute?.GetOrder(), 41 | GroupName = displayAttribute?.GetGroupName(), 42 | FormatString = displayFormatAttribute?.DataFormatString, 43 | NullDisplayText = displayFormatAttribute?.NullDisplayText, 44 | AutoGenerateField = displayAttribute?.GetAutoGenerateField() ?? true, 45 | DataType = dataTypeAttribute?.DataType, 46 | VisibilityFilters = visibilityFilters, 47 | Styles = styleAttribute, 48 | IsEditAllowed = editableFilter?.AllowEdit != false 49 | }; 50 | } 51 | 52 | 53 | private struct PropertyCulturePair 54 | { 55 | public CultureInfo Culture; 56 | public PropertyInfo PropertyInfo; 57 | 58 | public PropertyCulturePair(PropertyInfo propertyInfo, CultureInfo culture) 59 | { 60 | Culture = culture; 61 | PropertyInfo = propertyInfo; 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.DynamicData.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2006 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotVVM.Framework.Controls.DynamicData", "DotVVM.Framework.Controls.DynamicData\DotVVM.Framework.Controls.DynamicData.csproj", "{6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotVVM.Framework.Controls.DynamicData.Annotations", "DotVVM.Framework.Controls.DynamicData.Annotations\DotVVM.Framework.Controls.DynamicData.Annotations.csproj", "{7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Debug|x64.Build.0 = Debug|Any CPU 24 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Debug|x86.ActiveCfg = Debug|Any CPU 25 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Debug|x86.Build.0 = Debug|Any CPU 26 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Release|x64.ActiveCfg = Release|Any CPU 29 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Release|x64.Build.0 = Release|Any CPU 30 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Release|x86.ActiveCfg = Release|Any CPU 31 | {6EF7B1F8-56C1-4D6C-A2A2-CBA2B032FA25}.Release|x86.Build.0 = Release|Any CPU 32 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Debug|x64.Build.0 = Debug|Any CPU 36 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Debug|x86.Build.0 = Debug|Any CPU 38 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Release|x64.ActiveCfg = Release|Any CPU 41 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Release|x64.Build.0 = Release|Any CPU 42 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Release|x86.ActiveCfg = Release|Any CPU 43 | {7BD8A6DD-242D-4E7C-AF70-842CB4F5562E}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {7CABA741-5363-4D38-8D48-83007592C79A} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.DependencyInjection.Extensions; 5 | 6 | namespace DotVVM.Framework.Controls.DynamicData 7 | { 8 | // Many thanks to https://gist.github.com/khellang/c9d39444f713eab04c26dc09d5687196 9 | 10 | public static class ServiceCollectionExtensions 11 | { 12 | public static IServiceCollection Decorate(this IServiceCollection services, Func decorator) 13 | { 14 | var descriptors = services.GetDescriptors(); 15 | 16 | foreach (var descriptor in descriptors) 17 | { 18 | services.Replace(descriptor.Decorate(decorator)); 19 | } 20 | 21 | return services; 22 | } 23 | 24 | public static IServiceCollection Decorate(this IServiceCollection services, Func decorator) 25 | { 26 | var descriptors = services.GetDescriptors(); 27 | 28 | foreach (var descriptor in descriptors) 29 | { 30 | services.Replace(descriptor.Decorate(decorator)); 31 | } 32 | 33 | return services; 34 | } 35 | 36 | private static List GetDescriptors(this IServiceCollection services) 37 | { 38 | var descriptors = new List(); 39 | 40 | foreach (var service in services) 41 | { 42 | if (service.ServiceType == typeof(TService)) 43 | { 44 | descriptors.Add(service); 45 | } 46 | } 47 | 48 | if (descriptors.Count == 0) 49 | { 50 | throw new InvalidOperationException($"Could not find any registered services for type '{typeof(TService).FullName}'."); 51 | } 52 | 53 | return descriptors; 54 | } 55 | 56 | private static ServiceDescriptor Decorate(this ServiceDescriptor descriptor, Func decorator) 57 | { 58 | return descriptor.WithFactory(provider => decorator((TService)descriptor.GetInstance(provider), provider)); 59 | } 60 | 61 | private static ServiceDescriptor Decorate(this ServiceDescriptor descriptor, Func decorator) 62 | { 63 | return descriptor.WithFactory(provider => decorator((TService)descriptor.GetInstance(provider))); 64 | } 65 | 66 | private static ServiceDescriptor WithFactory(this ServiceDescriptor descriptor, Func factory) 67 | { 68 | return ServiceDescriptor.Describe(descriptor.ServiceType, factory, descriptor.Lifetime); 69 | } 70 | 71 | private static object GetInstance(this ServiceDescriptor descriptor, IServiceProvider provider) 72 | { 73 | if (descriptor.ImplementationInstance != null) 74 | { 75 | return descriptor.ImplementationInstance; 76 | } 77 | 78 | if (descriptor.ImplementationType != null) 79 | { 80 | return provider.GetServiceOrCreateInstance(descriptor.ImplementationType); 81 | } 82 | 83 | return descriptor.ImplementationFactory(provider); 84 | } 85 | 86 | private static object GetServiceOrCreateInstance(this IServiceProvider provider, Type type) 87 | { 88 | return ActivatorUtilities.GetServiceOrCreateInstance(provider, type); 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/DefaultEntityPropertyListProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Threading; 8 | using DotVVM.Framework.Controls.DynamicData.Annotations; 9 | 10 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 11 | { 12 | /// 13 | /// Provides a list of properties for the specified entity. 14 | /// 15 | public class DefaultEntityPropertyListProvider : IEntityPropertyListProvider 16 | { 17 | private readonly IPropertyDisplayMetadataProvider propertyDisplayMetadataProvider; 18 | private readonly ConcurrentDictionary> cache = new ConcurrentDictionary>(); 19 | 20 | 21 | public DefaultEntityPropertyListProvider(IPropertyDisplayMetadataProvider propertyDisplayMetadataProvider) 22 | { 23 | this.propertyDisplayMetadataProvider = propertyDisplayMetadataProvider; 24 | } 25 | 26 | /// 27 | /// Gets a list of properties for the specified entity and view name. 28 | /// 29 | public IList GetProperties(Type entityType, IViewContext viewContext) 30 | { 31 | var allProperties = cache.GetOrAdd(new TypeCulturePair(entityType, CultureInfo.CurrentUICulture), GetPropertiesCore); 32 | return FilterProperties(allProperties, viewContext); 33 | } 34 | 35 | private List GetPropertiesCore(TypeCulturePair pair) 36 | { 37 | var metadata = pair.EntityType.GetTypeInfo().GetProperties() 38 | .Select(propertyDisplayMetadataProvider.GetPropertyMetadata) 39 | .OrderBy(p => p.Order) 40 | .Where(p => p.AutoGenerateField) 41 | .ToList(); 42 | 43 | foreach (var property in metadata) 44 | { 45 | if (string.IsNullOrEmpty(property.DisplayName)) 46 | { 47 | property.DisplayName = property.PropertyInfo.Name; 48 | } 49 | } 50 | 51 | return metadata; 52 | } 53 | 54 | 55 | private IList FilterProperties(List allProperties, IViewContext viewContext) 56 | { 57 | return allProperties.Where(p => EvaluatePropertyVisibility(p, viewContext)).ToList(); 58 | } 59 | 60 | private bool EvaluatePropertyVisibility(PropertyDisplayMetadata property, IViewContext viewContext) 61 | { 62 | if (property.VisibilityFilters.Length == 0) 63 | { 64 | return true; 65 | } 66 | 67 | foreach (var filter in property.VisibilityFilters) 68 | { 69 | var mode = filter.CanShow(viewContext); 70 | if (mode == VisibilityMode.Show) 71 | { 72 | return true; 73 | } 74 | else if (mode == VisibilityMode.Hide) 75 | { 76 | return false; 77 | } 78 | } 79 | return false; 80 | } 81 | 82 | 83 | private struct TypeCulturePair 84 | { 85 | public Type EntityType; 86 | public CultureInfo Culture; 87 | 88 | public TypeCulturePair(Type entityType, CultureInfo culture) 89 | { 90 | EntityType = entityType; 91 | Culture = culture; 92 | } 93 | } 94 | 95 | } 96 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DynamicDataExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using DotVVM.Framework.Configuration; 7 | using DotVVM.Framework.Controls.DynamicData.Configuration; 8 | using DotVVM.Framework.Controls.DynamicData.Metadata; 9 | using DotVVM.Framework.ViewModel.Validation; 10 | using Microsoft.Extensions.DependencyInjection; 11 | 12 | namespace DotVVM.Framework.Controls.DynamicData 13 | { 14 | public static class DynamicDataExtensions 15 | { 16 | /// 17 | /// Registers all services required by DotVVM Dynamic Data. 18 | /// 19 | public static IDotvvmServiceCollection AddDynamicData(this IDotvvmServiceCollection services, DynamicDataConfiguration dynamicDataConfiguration = null) 20 | { 21 | if (dynamicDataConfiguration == null) 22 | { 23 | dynamicDataConfiguration = new DynamicDataConfiguration(); 24 | } 25 | 26 | // add the configuration of Dynamic Data to the service collection 27 | services.Services.AddSingleton(serviceProvider => dynamicDataConfiguration); 28 | 29 | RegisterDefaultProviders(services.Services, dynamicDataConfiguration); 30 | if (dynamicDataConfiguration.UseLocalizationResourceFiles) 31 | { 32 | RegisterResourceFileProviders(services.Services, dynamicDataConfiguration); 33 | } 34 | 35 | return services; 36 | } 37 | 38 | private static void RegisterDefaultProviders(IServiceCollection services, DynamicDataConfiguration dynamicDataConfiguration) 39 | { 40 | services.AddSingleton( 41 | serviceProvider => new DataAnnotationsPropertyDisplayMetadataProvider() 42 | ); 43 | 44 | services.AddSingleton( 45 | serviceProvider => new DefaultEntityPropertyListProvider(serviceProvider.GetService()) 46 | ); 47 | } 48 | 49 | private static void RegisterResourceFileProviders(IServiceCollection services, DynamicDataConfiguration dynamicDataConfiguration) 50 | { 51 | if (dynamicDataConfiguration.PropertyDisplayNamesResourceFile == null) 52 | { 53 | throw new ArgumentException($"The {nameof(DynamicDataConfiguration)} must specify the {nameof(DynamicDataConfiguration.PropertyDisplayNamesResourceFile)} resource class!"); 54 | } 55 | if (dynamicDataConfiguration.ErrorMessagesResourceFile == null) 56 | { 57 | throw new ArgumentException($"The {nameof(DynamicDataConfiguration)} must specify the {nameof(DynamicDataConfiguration.ErrorMessagesResourceFile)} resource class!"); 58 | } 59 | 60 | services.Decorate( 61 | baseService => new ResourcePropertyDisplayMetadataProvider( 62 | dynamicDataConfiguration.PropertyDisplayNamesResourceFile, baseService) 63 | ); 64 | 65 | services.Decorate( 66 | (baseService, serviceProvider) => new ResourceViewModelValidationMetadataProvider( 67 | dynamicDataConfiguration.ErrorMessagesResourceFile, 68 | serviceProvider.GetService(), 69 | baseService) 70 | ); 71 | } 72 | 73 | 74 | /// 75 | /// Registers the Dynamic Data controls and return the Dynamic Data configuration. 76 | /// 77 | public static DynamicDataConfiguration AddDynamicDataConfiguration(this DotvvmConfiguration config) 78 | { 79 | config.Markup.AddCodeControls("dd", typeof(DynamicDataExtensions).Namespace, typeof(DynamicDataExtensions).GetTypeInfo().Assembly.GetName().Name); 80 | return config.ServiceProvider.GetService(); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DynamicEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DotVVM.Framework.Binding; 3 | using DotVVM.Framework.Controls.DynamicData.Builders; 4 | using DotVVM.Framework.Controls.DynamicData.Configuration; 5 | using DotVVM.Framework.Hosting; 6 | 7 | namespace DotVVM.Framework.Controls.DynamicData 8 | { 9 | public class DynamicEntity : HtmlGenericControl 10 | { 11 | /// 12 | /// Gets or sets the custom layout of the form. 13 | /// 14 | [MarkupOptions(AllowBinding = false, MappingMode = MappingMode.InnerElement)] 15 | public ITemplate ContentTemplate 16 | { 17 | get { return (ITemplate)GetValue(ContentTemplateProperty); } 18 | set { SetValue(ContentTemplateProperty, value); } 19 | } 20 | public static readonly DotvvmProperty ContentTemplateProperty 21 | = DotvvmProperty.Register(c => c.ContentTemplate, null); 22 | 23 | 24 | /// 25 | /// Gets or sets the view name (e.g. Insert, Edit, ReadOnly). Some fields may have different metadata for each view. 26 | /// 27 | public string ViewName 28 | { 29 | get { return (string)GetValue(ViewNameProperty); } 30 | set { SetValue(ViewNameProperty, value); } 31 | } 32 | public static readonly DotvvmProperty ViewNameProperty 33 | = DotvvmProperty.Register(c => c.ViewName, null); 34 | 35 | 36 | /// 37 | /// Gets or sets the group of fields that should be rendered. If not set, fields from all groups will be rendered. 38 | /// 39 | public string GroupName 40 | { 41 | get { return (string)GetValue(GroupNameProperty); } 42 | set { SetValue(GroupNameProperty, value); } 43 | } 44 | public static readonly DotvvmProperty GroupNameProperty 45 | = DotvvmProperty.Register(c => c.GroupName, null); 46 | 47 | 48 | /// 49 | /// Gets or sets the name of the form builder to be used. If not set, the default form builder is used. 50 | /// 51 | public string FormBuilderName 52 | { 53 | get { return (string)GetValue(FormBuilderNameProperty); } 54 | set { SetValue(FormBuilderNameProperty, value); } 55 | } 56 | public static readonly DotvvmProperty FormBuilderNameProperty 57 | = DotvvmProperty.Register(c => c.FormBuilderName, ""); 58 | 59 | 60 | /// 61 | /// Gets or sets whether the controls in the form are enabled or disabled. 62 | /// 63 | public bool Enabled 64 | { 65 | get { return (bool)GetValue(EnabledProperty); } 66 | set { SetValue(EnabledProperty, value); } 67 | } 68 | public static readonly DotvvmProperty EnabledProperty 69 | = DotvvmProperty.Register(c => c.Enabled, true, isValueInherited: true); 70 | 71 | 72 | 73 | 74 | 75 | internal static readonly DotvvmProperty DynamicDataContextProperty 76 | = DotvvmProperty.Register("DynamicDataContext", null); 77 | 78 | 79 | public DynamicEntity() : base("div") 80 | { 81 | } 82 | 83 | protected override void OnInit(IDotvvmRequestContext context) 84 | { 85 | var dynamicDataContext = CreateDynamicDataContext(context); 86 | SetValue(DynamicDataContextProperty, dynamicDataContext); 87 | 88 | if (ContentTemplate != null) 89 | { 90 | ContentTemplate.BuildContent(context, this); 91 | } 92 | else 93 | { 94 | BuildForm(dynamicDataContext); 95 | } 96 | 97 | base.OnInit(context); 98 | } 99 | 100 | protected virtual void BuildForm(DynamicDataContext dynamicDataContext) 101 | { 102 | var builder = dynamicDataContext.DynamicDataConfiguration.GetFormBuilder(FormBuilderName); 103 | builder.BuildForm(this, dynamicDataContext); 104 | } 105 | 106 | private DynamicDataContext CreateDynamicDataContext(IDotvvmRequestContext context) 107 | { 108 | return new DynamicDataContext(this.GetDataContextType(), context) 109 | { 110 | ViewName = ViewName, 111 | GroupName = GroupName 112 | }; 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Configuration/DynamicDataConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using DotVVM.Framework.Controls.DynamicData.Builders; 8 | using DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors; 9 | using DotVVM.Framework.Controls.DynamicData.PropertyHandlers.GridColumns; 10 | 11 | namespace DotVVM.Framework.Controls.DynamicData.Configuration 12 | { 13 | /// 14 | /// Represents the configuration of DotVVM Dynamic Data library. 15 | /// 16 | public class DynamicDataConfiguration 17 | { 18 | public Dictionary Properties { get; } = new Dictionary(); 19 | 20 | /// 21 | /// Gets a list of registered providers that render form fields. 22 | /// 23 | public List FormEditorProviders { get; private set; } = new List(); 24 | 25 | /// 26 | /// Gets a list of registered providers that render GridView columns. 27 | /// 28 | public List GridColumnProviders { get; private set; } = new List(); 29 | 30 | /// 31 | /// Gets a list of registered IFormBuilders. 32 | /// 33 | public Dictionary FormBuilders { get; private set; } = new Dictionary() 34 | { 35 | { "", new TableDynamicFormBuilder() }, 36 | { "bootstrap", new BootstrapFormGroupBuilder() } 37 | }; 38 | 39 | /// 40 | /// Gets or sets whether the localization resource files for field display names and error messages will be used. 41 | /// 42 | public bool UseLocalizationResourceFiles { get; set; } 43 | 44 | /// 45 | /// Gets or sets the RESX file class with display names of the fields. 46 | /// 47 | public Type PropertyDisplayNamesResourceFile { get; set; } 48 | 49 | /// 50 | /// Gets or sets the RESX file class with localized error messages. 51 | /// 52 | public Type ErrorMessagesResourceFile { get; set; } 53 | 54 | public DynamicDataConfiguration() 55 | { 56 | FormEditorProviders.Add(new CheckBoxEditorProvider()); 57 | FormEditorProviders.Add(new TextBoxEditorProvider()); 58 | 59 | GridColumnProviders.Add(new CheckBoxGridColumnProvider()); 60 | GridColumnProviders.Add(new TextGridColumnProvider()); 61 | } 62 | 63 | public IFormBuilder GetFormBuilder(string formBuilderName = "") 64 | { 65 | IFormBuilder builder; 66 | if (!FormBuilders.TryGetValue(formBuilderName, out builder)) 67 | { 68 | throw new ArgumentException($"The {nameof(IFormBuilder)} with name '{formBuilderName}' was not found! Make sure it is registered in the {nameof(DynamicDataExtensions.AddDynamicData)} method."); 69 | } 70 | return builder; 71 | } 72 | 73 | /// 74 | /// Browses the specified assembly and auto-registers all form editor providers. 75 | /// 76 | public void AutoDiscoverFormEditorProviders(Assembly assembly) 77 | { 78 | AutoDiscoverProviders(assembly, FormEditorProviders); 79 | } 80 | 81 | /// 82 | /// Browses the specified assembly and auto-registers all grid column providers. 83 | /// 84 | public void AutoDiscoverGridColumnProviders(Assembly assembly) 85 | { 86 | AutoDiscoverProviders(assembly, GridColumnProviders); 87 | } 88 | 89 | private void AutoDiscoverProviders(Assembly assembly, IList targetCollection) 90 | { 91 | var types = assembly.GetTypes() 92 | .Where(t => typeof(T).IsAssignableFrom(t)) 93 | .Where(t => !t.GetTypeInfo().IsAbstract) 94 | .Where(t => t.GetTypeInfo().DeclaredConstructors.Any(c => c.GetParameters().Length == 0)); 95 | 96 | foreach (var type in types) 97 | { 98 | try 99 | { 100 | var instance = Activator.CreateInstance(type); 101 | targetCollection.Insert(0, (T)instance); 102 | } 103 | catch (TargetInvocationException ex) 104 | { 105 | throw new Exception($"Could not invoke the default constructor of {type.FullName}!", ex); 106 | } 107 | } 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/ComboBoxFormEditorProviderBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using DotVVM.Framework.Binding.Expressions; 4 | using DotVVM.Framework.Controls.DynamicData.Annotations; 5 | using DotVVM.Framework.Controls.DynamicData.Metadata; 6 | 7 | namespace DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors 8 | { 9 | /// 10 | /// A base class for ComboBox form editor providers. 11 | /// 12 | public abstract class ComboBoxFormEditorProvider : FormEditorProviderBase 13 | { 14 | public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context) 15 | { 16 | return GetSettings(propertyInfo) != null; 17 | } 18 | 19 | public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context) 20 | { 21 | var comboBox = new ComboBox() 22 | { 23 | EmptyItemText = GetEmptyItemText(property, context) 24 | }; 25 | container.Children.Add(comboBox); 26 | 27 | comboBox.SetBinding(SelectorBase.ItemTextBindingProperty, context.CreateValueBinding(GetDisplayMember(property, context))); 28 | comboBox.SetBinding(SelectorBase.ItemValueBindingProperty, context.CreateValueBinding(GetValueMember(property, context))); 29 | 30 | comboBox.SetBinding(SelectorBase.ItemTextBindingProperty, context.CreateValueBinding(GetDisplayMember(property, context))); 31 | comboBox.SetBinding(SelectorBase.ItemValueBindingProperty, context.CreateValueBinding(GetValueMember(property, context))); 32 | comboBox.SetBinding(Selector.SelectedValueProperty, context.CreateValueBinding(property.PropertyInfo.Name)); 33 | comboBox.SetBinding(ItemsControl.DataSourceProperty, GetDataSourceBinding(property, context, comboBox)); 34 | 35 | var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass); 36 | if (!string.IsNullOrEmpty(cssClass)) 37 | { 38 | comboBox.Attributes["class"] = cssClass; 39 | } 40 | 41 | if (container.IsPropertySet(DynamicEntity.EnabledProperty)) 42 | { 43 | ControlHelpers.CopyProperty(container, DynamicEntity.EnabledProperty, comboBox, SelectorBase.EnabledProperty); 44 | } 45 | } 46 | 47 | /// 48 | /// Compiles the DataSource binding expression to a value binding. 49 | /// 50 | protected virtual ValueBindingExpression GetDataSourceBinding(PropertyDisplayMetadata property, DynamicDataContext context, ComboBox comboBox) 51 | { 52 | var dataSourceBindingExpression = GetDataSourceBindingExpression(property, context); 53 | if (string.IsNullOrEmpty(dataSourceBindingExpression)) 54 | { 55 | throw new Exception($"The DataSource binding expression for property {property.PropertyInfo} must be specified!"); 56 | } 57 | 58 | return context.CreateValueBinding(dataSourceBindingExpression); 59 | } 60 | 61 | /// 62 | /// Gets the DataSource binding expression for the ComboBox control from the ComboBoxSettingsAttribute. 63 | /// 64 | protected virtual string GetDataSourceBindingExpression(PropertyDisplayMetadata property, DynamicDataContext context) 65 | { 66 | return GetSettings(property.PropertyInfo)?.DataSourceBinding; 67 | } 68 | 69 | /// 70 | /// Gets the EmptyItemText for the ComboBox control from the ComboBoxSettingsAttribute. 71 | /// 72 | protected virtual string GetEmptyItemText(PropertyDisplayMetadata property, DynamicDataContext context) 73 | { 74 | return GetSettings(property.PropertyInfo)?.EmptyItemText; 75 | } 76 | 77 | /// 78 | /// Gets the ValueMember for the ComboBox control from the ComboBoxSettingsAttribute. 79 | /// 80 | protected virtual string GetValueMember(PropertyDisplayMetadata property, DynamicDataContext context) 81 | { 82 | return GetSettings(property.PropertyInfo)?.ValueMember; 83 | } 84 | 85 | /// 86 | /// Gets the DisplayMember for the ComboBox control from the ComboBoxSettingsAttribute. 87 | /// 88 | protected virtual string GetDisplayMember(PropertyDisplayMetadata property, DynamicDataContext context) 89 | { 90 | return GetSettings(property.PropertyInfo)?.DisplayMember; 91 | } 92 | 93 | private ComboBoxSettingsAttribute GetSettings(PropertyInfo propertyInfo) 94 | { 95 | return propertyInfo.GetCustomAttribute(); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Builders/BootstrapFormGroupBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using DotVVM.Framework.Controls.DynamicData.Metadata; 7 | using DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors; 8 | 9 | namespace DotVVM.Framework.Controls.DynamicData.Builders 10 | { 11 | public class BootstrapFormGroupBuilder : FormBuilderBase 12 | { 13 | 14 | public string FormGroupCssClass { get; set; } = "form-group"; 15 | 16 | public string LabelCssClass { get; set; } = "control-label"; 17 | 18 | 19 | public override void BuildForm(DotvvmControl hostControl, DynamicDataContext dynamicDataContext) 20 | { 21 | var entityPropertyListProvider = dynamicDataContext.RequestContext.Configuration.ServiceProvider.GetService(); 22 | 23 | // create the rows 24 | var properties = GetPropertiesToDisplay(dynamicDataContext, entityPropertyListProvider); 25 | foreach (var property in properties) 26 | { 27 | // find the editorProvider for cell 28 | var editorProvider = FindEditorProvider(property, dynamicDataContext); 29 | if (editorProvider == null) continue; 30 | 31 | // create the row 32 | HtmlGenericControl labelElement, controlElement; 33 | var formGroup = InitializeFormGroup(hostControl, property, dynamicDataContext, out labelElement, out controlElement); 34 | 35 | // create the label 36 | InitializeControlLabel(formGroup, labelElement, editorProvider, property, dynamicDataContext); 37 | 38 | // create the editorProvider 39 | InitializeControlEditor(formGroup, controlElement, editorProvider, property, dynamicDataContext); 40 | 41 | // create the validator 42 | InitializeValidation(formGroup, labelElement, controlElement, editorProvider, property, dynamicDataContext); 43 | } 44 | } 45 | 46 | 47 | 48 | protected virtual HtmlGenericControl InitializeFormGroup(DotvvmControl hostControl, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext, out HtmlGenericControl labelElement, out HtmlGenericControl controlElement) 49 | { 50 | var formGroup = new HtmlGenericControl("div"); 51 | formGroup.Attributes["class"] = ControlHelpers.ConcatCssClasses(FormGroupCssClass, property.Styles?.FormRowCssClass); 52 | hostControl.Children.Add(formGroup); 53 | 54 | labelElement = new HtmlGenericControl("label"); 55 | labelElement.Attributes["class"] = LabelCssClass; 56 | formGroup.Children.Add(labelElement); 57 | 58 | controlElement = new HtmlGenericControl("div"); 59 | controlElement.Attributes["class"] = ControlHelpers.ConcatCssClasses(property.Styles?.FormControlContainerCssClass); 60 | formGroup.Children.Add(controlElement); 61 | 62 | return formGroup; 63 | } 64 | 65 | protected virtual void InitializeControlLabel(HtmlGenericControl formGroup, HtmlGenericControl labelElement, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 66 | { 67 | if (editorProvider.RenderDefaultLabel) 68 | { 69 | labelElement.Children.Add(new Literal(property.DisplayName)); 70 | } 71 | } 72 | 73 | protected virtual void InitializeControlEditor(HtmlGenericControl formGroup, HtmlGenericControl controlElement, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 74 | { 75 | editorProvider.CreateControl(controlElement, property, dynamicDataContext); 76 | 77 | // set CSS classes 78 | foreach (var control in controlElement.GetAllDescendants()) 79 | { 80 | if (control is TextBox || control is ComboBox) 81 | { 82 | ((HtmlGenericControl) control).Attributes["class"] = "form-control"; 83 | } 84 | } 85 | } 86 | 87 | protected virtual void InitializeValidation(HtmlGenericControl formGroup, HtmlGenericControl labelElement, HtmlGenericControl controlElement, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 88 | { 89 | if (dynamicDataContext.ValidationMetadataProvider.GetAttributesForProperty(property.PropertyInfo).OfType().Any()) 90 | { 91 | labelElement.Attributes["class"] = ControlHelpers.ConcatCssClasses(labelElement.Attributes["class"] as string, "dynamicdata-required"); 92 | } 93 | 94 | if (editorProvider.CanValidate) 95 | { 96 | controlElement.SetValue(Validator.ValueProperty, editorProvider.GetValidationValueBinding(property, dynamicDataContext)); 97 | } 98 | } 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DynamicDataGridViewDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using DotVVM.Framework.Binding; 7 | using DotVVM.Framework.Binding.Expressions; 8 | using DotVVM.Framework.Controls.DynamicData.Metadata; 9 | using DotVVM.Framework.Controls.DynamicData.PropertyHandlers.GridColumns; 10 | using DotVVM.Framework.Hosting; 11 | 12 | namespace DotVVM.Framework.Controls.DynamicData 13 | { 14 | public class DynamicDataGridViewDecorator : Decorator 15 | { 16 | /// 17 | /// Gets or sets the view name (e.g. Insert, Edit, ReadOnly). Some fields may have different metadata for each view. 18 | /// 19 | public string ViewName 20 | { 21 | get { return (string)GetValue(ViewNameProperty); } 22 | set { SetValue(ViewNameProperty, value); } 23 | } 24 | 25 | public static readonly DotvvmProperty ViewNameProperty 26 | = DotvvmProperty.Register(c => c.ViewName, null); 27 | 28 | /// 29 | /// Gets or sets whether the columns are generated on the left side or on the right side of the grid. 30 | /// 31 | public ColumnPlacement ColumnPlacement 32 | { 33 | get { return (ColumnPlacement)GetValue(ColumnPlacementProperty); } 34 | set { SetValue(ColumnPlacementProperty, value); } 35 | } 36 | 37 | public static readonly DotvvmProperty ColumnPlacementProperty 38 | = DotvvmProperty.Register(c => c.ColumnPlacement, ColumnPlacement.Left); 39 | 40 | protected override void OnInit(IDotvvmRequestContext context) 41 | { 42 | base.OnInit(context); 43 | 44 | GenerateGridViewColumns(context); 45 | } 46 | 47 | /// 48 | /// Generates the GridView columns. 49 | /// 50 | private void GenerateGridViewColumns(IDotvvmRequestContext context) 51 | { 52 | var grid = FindGridView(); 53 | 54 | var itemDataContextStack = grid.GetItemDataContextStack(ItemsControl.DataSourceProperty); 55 | var dynamicDataContext = new DynamicDataContext(itemDataContextStack, context) 56 | { 57 | ViewName = ViewName 58 | }; 59 | 60 | // generate columns 61 | var entityPropertyListProvider = context.Configuration.ServiceProvider.GetService(); 62 | var viewContext = dynamicDataContext.CreateViewContext(context); 63 | var entityProperties = entityPropertyListProvider.GetProperties(itemDataContextStack.DataContextType, viewContext); 64 | 65 | // create columns 66 | var newColumns = new List(); 67 | foreach (var property in entityProperties) 68 | { 69 | // get the column provider 70 | var columnProvider = FindGridColumnProvider(dynamicDataContext, property); 71 | if (columnProvider == null) continue; 72 | 73 | // create the column 74 | var column = columnProvider.CreateColumn(grid, property, dynamicDataContext); 75 | SetColumnCommonProperties(grid, property, column, dynamicDataContext); 76 | 77 | // add the column to the GridView 78 | newColumns.Add(column); 79 | } 80 | AddColumns(grid, newColumns); 81 | } 82 | 83 | protected virtual void AddColumns(GridView grid, List newColumns) 84 | { 85 | if (ColumnPlacement == ColumnPlacement.Left) 86 | { 87 | grid.Columns.InsertRange(0, newColumns); 88 | } 89 | else 90 | { 91 | grid.Columns.AddRange(newColumns); 92 | } 93 | } 94 | 95 | protected virtual GridView FindGridView() 96 | { 97 | try 98 | { 99 | return Children.OfType().Single(); 100 | } 101 | catch (InvalidOperationException) 102 | { 103 | throw new DotvvmControlException(this, $"The {nameof(DynamicDataGridViewDecorator)} control must have exactly one {nameof(GridView)} control inside!"); 104 | } 105 | } 106 | 107 | /// 108 | /// Sets the common properties of the grid view column. 109 | /// 110 | protected virtual void SetColumnCommonProperties(GridView grid, PropertyDisplayMetadata property, GridViewColumn column, DynamicDataContext dynamicDataContext) 111 | { 112 | column.HeaderText = property.DisplayName; 113 | } 114 | 115 | /// 116 | /// Finds the grid column provider. 117 | /// 118 | protected virtual IGridColumnProvider FindGridColumnProvider(DynamicDataContext dynamicDataContext, PropertyDisplayMetadata property) 119 | { 120 | return dynamicDataContext.DynamicDataConfiguration.GridColumnProviders.FirstOrDefault(p => p.CanHandleProperty(property.PropertyInfo, dynamicDataContext)); 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Builders/TableDynamicFormBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Linq; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using DotVVM.Framework.Controls.DynamicData.Metadata; 6 | using DotVVM.Framework.Controls.DynamicData.PropertyHandlers.FormEditors; 7 | 8 | namespace DotVVM.Framework.Controls.DynamicData.Builders 9 | { 10 | /// 11 | /// Builds the dynamic form using a HTML table - the first column contain the field labels, the second column contains the form fields. 12 | /// 13 | public class TableDynamicFormBuilder : FormBuilderBase 14 | { 15 | 16 | public string LabelCellCssClass { get; set; } 17 | 18 | public string EditorCellCssClass { get; set; } 19 | 20 | 21 | public override void BuildForm(DotvvmControl hostControl, DynamicDataContext dynamicDataContext) 22 | { 23 | var entityPropertyListProvider = dynamicDataContext.RequestContext.Configuration.ServiceProvider.GetService(); 24 | 25 | // create the table 26 | var table = InitializeTable(hostControl, dynamicDataContext); 27 | 28 | // create the rows 29 | var properties = GetPropertiesToDisplay(dynamicDataContext, entityPropertyListProvider); 30 | foreach (var property in properties) 31 | { 32 | // find the editorProvider for cell 33 | var editorProvider = FindEditorProvider(property, dynamicDataContext); 34 | if (editorProvider == null) continue; 35 | 36 | // create the row 37 | HtmlGenericControl labelCell, editorCell; 38 | var row = InitializeTableRow(table, property, dynamicDataContext, out labelCell, out editorCell); 39 | 40 | // create the label 41 | InitializeControlLabel(row, labelCell, editorProvider, property, dynamicDataContext); 42 | 43 | // create the editorProvider 44 | InitializeControlEditor(row, editorCell, editorProvider, property, dynamicDataContext); 45 | 46 | // create the validator 47 | InitializeValidation(row, labelCell, editorCell, editorProvider, property, dynamicDataContext); 48 | } 49 | } 50 | 51 | /// 52 | /// Initializes the validation on the row. 53 | /// 54 | protected virtual void InitializeValidation(HtmlGenericControl row, HtmlGenericControl labelCell, HtmlGenericControl editorCell, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 55 | { 56 | if (dynamicDataContext.ValidationMetadataProvider.GetAttributesForProperty(property.PropertyInfo).OfType().Any()) 57 | { 58 | labelCell.Attributes["class"] += " dynamicdata-required"; 59 | } 60 | 61 | if (editorProvider.CanValidate) 62 | { 63 | row.SetValue(Validator.ValueProperty, editorProvider.GetValidationValueBinding(property, dynamicDataContext)); 64 | } 65 | } 66 | 67 | /// 68 | /// Creates the table element for the form. 69 | /// 70 | protected virtual HtmlGenericControl InitializeTable(DotvvmControl hostControl, DynamicDataContext dynamicDataContext) 71 | { 72 | var table = new HtmlGenericControl("table"); 73 | table.Attributes["class"] = "dotvvm-dynamicdata-form-table"; 74 | 75 | hostControl.Children.Add(table); 76 | return table; 77 | } 78 | 79 | /// 80 | /// Creates the table row for the specified property. 81 | /// 82 | protected virtual HtmlGenericControl InitializeTableRow(HtmlGenericControl table, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext, out HtmlGenericControl labelCell, out HtmlGenericControl editorCell) 83 | { 84 | var row = new HtmlGenericControl("tr"); 85 | row.Attributes["class"] = property.Styles?.FormRowCssClass; 86 | table.Children.Add(row); 87 | 88 | labelCell = new HtmlGenericControl("td"); 89 | labelCell.Attributes["class"] = ControlHelpers.ConcatCssClasses("dynamicdata-label", LabelCellCssClass); 90 | row.Children.Add(labelCell); 91 | 92 | editorCell = new HtmlGenericControl("td"); 93 | editorCell.Attributes["class"] = ControlHelpers.ConcatCssClasses("dynamicdata-editor", EditorCellCssClass, property.Styles?.FormControlContainerCssClass); 94 | row.Children.Add(editorCell); 95 | 96 | return row; 97 | } 98 | 99 | /// 100 | /// Creates the contents of the label cell for the specified property. 101 | /// 102 | protected virtual void InitializeControlLabel(HtmlGenericControl row, HtmlGenericControl labelCell, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 103 | { 104 | if (editorProvider.RenderDefaultLabel) 105 | { 106 | labelCell.Children.Add(new Literal(property.DisplayName)); 107 | } 108 | } 109 | 110 | /// 111 | /// Creates the contents of the editor cell for the specified property. 112 | /// 113 | protected virtual void InitializeControlEditor(HtmlGenericControl row, HtmlGenericControl editorCell, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext) 114 | { 115 | editorProvider.CreateControl(editorCell, property, dynamicDataContext); 116 | } 117 | 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/Metadata/ResourceViewModelValidationMetadataProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Globalization; 6 | using System.Reflection; 7 | using System.Resources; 8 | using System.Threading; 9 | using DotVVM.Framework.ViewModel.Validation; 10 | 11 | namespace DotVVM.Framework.Controls.DynamicData.Metadata 12 | { 13 | /// 14 | /// Validation attribmetadata provider which loads missing error messages from the RESX file. 15 | /// 16 | public class ResourceViewModelValidationMetadataProvider : IViewModelValidationMetadataProvider 17 | { 18 | private readonly IPropertyDisplayMetadataProvider propertyDisplayMetadataProvider; 19 | private readonly IViewModelValidationMetadataProvider baseValidationMetadataProvider; 20 | private ConcurrentDictionary> cache = new ConcurrentDictionary>(); 21 | 22 | private ResourceManager errorMessages; 23 | 24 | /// 25 | /// Gets the type of the resource file that contains the default error message patterns. 26 | /// The resource key is the name of the attribute without the trailing Attribute (e.g. Required for RequiredAttribute etc.). 27 | /// 28 | public Type ErrorMessagesResourceFileType { get; } 29 | 30 | 31 | public ResourceViewModelValidationMetadataProvider(Type errorMessagesResourceFileType, IPropertyDisplayMetadataProvider propertyDisplayMetadataProvider, IViewModelValidationMetadataProvider baseValidationMetadataProvider) 32 | { 33 | ErrorMessagesResourceFileType = errorMessagesResourceFileType; 34 | errorMessages = new ResourceManager(errorMessagesResourceFileType); 35 | 36 | this.propertyDisplayMetadataProvider = propertyDisplayMetadataProvider; 37 | this.baseValidationMetadataProvider = baseValidationMetadataProvider; 38 | } 39 | 40 | /// 41 | /// Gets validation attributes for the specified property. 42 | /// 43 | public IEnumerable GetAttributesForProperty(PropertyInfo property) 44 | { 45 | return cache.GetOrAdd(new PropertyInfoCulturePair(CultureInfo.CurrentUICulture, property), GetAttributesForPropertyCore); 46 | } 47 | 48 | /// 49 | /// Determines validation attributes for the specified property and loads missing error messages from the resource file. 50 | /// 51 | private List GetAttributesForPropertyCore(PropertyInfoCulturePair pair) 52 | { 53 | // determine property name 54 | var propertyDisplayName = propertyDisplayMetadataProvider.GetPropertyMetadata(pair.PropertyInfo).DisplayName; 55 | 56 | // process all validation attributes 57 | var results = new List(); 58 | foreach (var attribute in baseValidationMetadataProvider.GetAttributesForProperty(pair.PropertyInfo)) 59 | { 60 | if (string.IsNullOrEmpty(attribute.ErrorMessage) && string.IsNullOrEmpty(attribute.ErrorMessageResourceName)) 61 | { 62 | // the error message has not been set, determine new error message 63 | var clone = CloneAttribute(attribute); 64 | 65 | // determine error message 66 | var errorMessage = GetErrorMessage(attribute, propertyDisplayName); 67 | 68 | // add the clone to the list 69 | clone.ErrorMessage = errorMessage; 70 | results.Add(clone); 71 | } 72 | else 73 | { 74 | results.Add(attribute); 75 | } 76 | } 77 | 78 | return results; 79 | } 80 | 81 | /// 82 | /// Creates a copy of the specified validation attribute instance. 83 | /// 84 | protected virtual ValidationAttribute CloneAttribute(ValidationAttribute attribute) 85 | { 86 | return (ValidationAttribute)attribute.GetType() 87 | .GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance) 88 | .Invoke(attribute, null); 89 | } 90 | 91 | /// 92 | /// Gets the error message for the specified attribute. 93 | /// 94 | public virtual string GetErrorMessage(ValidationAttribute attribute, string propertyDisplayName) 95 | { 96 | var attributeName = attribute.GetType().Name; 97 | if (attributeName.EndsWith("Attribute", StringComparison.CurrentCultureIgnoreCase)) 98 | { 99 | attributeName = attributeName.Substring(0, attributeName.Length - "Attribute".Length); 100 | } 101 | 102 | return string.Format(GetDefaultErrorMessagePattern(attributeName), propertyDisplayName); 103 | } 104 | 105 | /// 106 | /// Gets the default error message pattern for the specified attribute. 107 | /// 108 | protected virtual string GetDefaultErrorMessagePattern(string attributeName) 109 | { 110 | return errorMessages.GetString(attributeName) ?? errorMessages.GetString("Unknown") ?? "Error"; 111 | } 112 | 113 | 114 | private struct PropertyInfoCulturePair 115 | { 116 | public readonly CultureInfo Culture; 117 | public readonly PropertyInfo PropertyInfo; 118 | 119 | public PropertyInfoCulturePair(CultureInfo culture, PropertyInfo propertyInfo) 120 | { 121 | Culture = culture; 122 | PropertyInfo = propertyInfo; 123 | } 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Tools/build/publish.ps1: -------------------------------------------------------------------------------- 1 | param([String]$version, [String]$apiKey, [String]$server, [String]$branchName, [String]$repoUrl, [String]$nugetRestoreAltSource = "", [bool]$pushTag, [String]$configuration, [String]$apiKeyInternal, [String]$internalServer, [String]$signUser = "", [String]$signSecret = "", $signConfigPath = "") 2 | $currentDirectory = $PWD 3 | 4 | ### Helper Functions 5 | 6 | function Invoke-Git { 7 | <# 8 | .Synopsis 9 | Wrapper function that deals with Powershell's peculiar error output when Git uses the error stream. 10 | .Example 11 | Invoke-Git ThrowError 12 | $LASTEXITCODE 13 | #> 14 | [CmdletBinding()] 15 | param( 16 | [parameter(ValueFromRemainingArguments=$true)] 17 | [string[]]$Arguments 18 | ) 19 | 20 | & { 21 | [CmdletBinding()] 22 | param( 23 | [parameter(ValueFromRemainingArguments=$true)] 24 | [string[]]$InnerArgs 25 | ) 26 | git.exe $InnerArgs 2>&1 27 | } -ErrorAction SilentlyContinue -ErrorVariable fail @Arguments 28 | 29 | if ($fail) { 30 | $fail.Exception 31 | } 32 | } 33 | 34 | function CleanOldGeneratedPackages() { 35 | Write-Host "Cleaning old versions of nupkg ..." 36 | foreach ($package in $packages) { 37 | del .\$($package.Directory)\bin\$configuration\*.nupkg -ErrorAction SilentlyContinue 38 | } 39 | } 40 | 41 | function RestoreSignClient() { 42 | & dotnet tool restore | Out-Host 43 | } 44 | 45 | function SetVersion() { 46 | Write-Host "Setting version: $version ..." 47 | Write-Host "Current directory: $currentDirectory" 48 | foreach ($package in $packages) { 49 | 50 | Write-Host -------------------------------- 51 | 52 | $filePath = Join-Path $currentDirectory ".\$($package.Directory)\$($package.Directory).csproj" -Resolve 53 | Write-Host "Updating $filePath" 54 | 55 | 56 | $file = [System.IO.File]::ReadAllText($filePath, [System.Text.Encoding]::UTF8) 57 | $file = [System.Text.RegularExpressions.Regex]::Replace($file, "\([^<]+)\", "" + $version + "") 58 | $file = [System.Text.RegularExpressions.Regex]::Replace($file, "\([^<]+)\", "" + $version + "") 59 | [System.IO.File]::WriteAllText($filePath, $file, [System.Text.Encoding]::UTF8) 60 | 61 | $filePath = Join-Path $currentDirectory ".\$($package.Directory)\Properties\AssemblyInfo.cs" 62 | if(Test-Path $filePath) { 63 | Write-Host "Updating $filePath" 64 | $file = [System.IO.File]::ReadAllText($filePath, [System.Text.Encoding]::UTF8) 65 | $file = [System.Text.RegularExpressions.Regex]::Replace($file, "\[assembly: AssemblyVersion\(""([^""]+)""\)\]", "[assembly: AssemblyVersion(""" + $versionWithoutPre + """)]") 66 | $file = [System.Text.RegularExpressions.Regex]::Replace($file, "\[assembly: AssemblyFileVersion\(""([^""]+)""\)]", "[assembly: AssemblyFileVersion(""" + $versionWithoutPre + """)]") 67 | [System.IO.File]::WriteAllText($filePath, $file, [System.Text.Encoding]::UTF8) 68 | } 69 | } 70 | } 71 | 72 | function BuildPackages() { 73 | Write-Host "Build started" 74 | foreach ($package in $packages) { 75 | cd .\$($package.Directory) 76 | Write-Host "Building in directory $PWD" 77 | 78 | if ($nugetRestoreAltSource -eq "") { 79 | & dotnet restore | Out-Host 80 | } 81 | else { 82 | & dotnet restore --source $nugetRestoreAltSource --source https://nuget.org/api/v2/ | Out-Host 83 | } 84 | Write-Host "Packing project in directory $PWD" 85 | 86 | & dotnet pack -c $configuration --include-symbols | Out-Host 87 | cd .. 88 | } 89 | } 90 | 91 | function SignPackages() { 92 | if ($signUser -ne "") { 93 | Write-Host "Signing packages ..." 94 | foreach ($package in $packages) { 95 | $baseDir = Join-Path $currentDirectory ".\$($package.Directory)\bin\$configuration\" 96 | & dotnet signclient sign --baseDirectory "$baseDir" --input *.nupkg --config "$signConfigPath" --user "$signUser" --secret "$signSecret" --name "$($package.Package)" --description "$($package.Package + " " + $version)" --descriptionUrl "https://github.com/riganti/dotvvm" | Out-Host 97 | } 98 | } 99 | } 100 | 101 | function PushPackages() { 102 | Write-Host "Pushing packages ..." 103 | foreach ($package in $packages) { 104 | & .\Tools\nuget.exe push .\$($package.Directory)\bin\$configuration\$($package.Package).$version.symbols.nupkg -source $server -apiKey $apiKey | Out-Host 105 | } 106 | } 107 | 108 | function GitCheckout() { 109 | invoke-git checkout $branchName 110 | invoke-git -c http.sslVerify=false pull $repoUrl $branchName 111 | } 112 | 113 | function GitPush() { 114 | 115 | invoke-git config --global user.email "rigantiteamcity" 116 | invoke-git config --global user.name "Riganti Team City" 117 | if ($pushTag) { 118 | invoke-git tag "v$($version)" HEAD 119 | } 120 | invoke-git commit -am "NuGet package version $version" 121 | invoke-git rebase HEAD $branchName 122 | invoke-git push --follow-tags $repoUrl $branchName 123 | } 124 | 125 | 126 | 127 | ### Configuration 128 | 129 | $packages = @( 130 | [pscustomobject]@{ Package = "DotVVM.DynamicData"; Directory = "DotVVM.Framework.Controls.DynamicData" }, 131 | [pscustomobject]@{ Package = "DotVVM.DynamicData.Annotations"; Directory = "DotVVM.Framework.Controls.DynamicData.Annotations" } 132 | ) 133 | 134 | 135 | 136 | ### Publish Workflow 137 | 138 | $versionWithoutPre = $version 139 | if ($versionWithoutPre.Contains("-")) { 140 | $versionWithoutPre = $versionWithoutPre.Substring(0, $versionWithoutPre.IndexOf("-")) 141 | } 142 | 143 | CleanOldGeneratedPackages; 144 | RestoreSignClient; 145 | GitCheckout; 146 | SetVersion; 147 | BuildPackages; 148 | SignPackages; 149 | PushPackages; 150 | GitPush; -------------------------------------------------------------------------------- /src/DotVVM.Framework.Controls.DynamicData/DynamicDataContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Claims; 5 | using System.Text; 6 | using DotVVM.Framework.Binding.Expressions; 7 | using DotVVM.Framework.Compilation; 8 | using DotVVM.Framework.Compilation.Binding; 9 | using DotVVM.Framework.Compilation.ControlTree; 10 | using DotVVM.Framework.Compilation.ControlTree.Resolved; 11 | using DotVVM.Framework.Controls.DynamicData.Annotations; 12 | using DotVVM.Framework.Controls.DynamicData.Configuration; 13 | using DotVVM.Framework.Controls.DynamicData.Metadata; 14 | using DotVVM.Framework.Hosting; 15 | using DotVVM.Framework.ViewModel.Validation; 16 | using Microsoft.Extensions.DependencyInjection; 17 | using DotVVM.Framework.Binding; 18 | using DotVVM.Framework.Utils; 19 | using DotVVM.Framework.Binding.Properties; 20 | using System.Collections.Concurrent; 21 | 22 | namespace DotVVM.Framework.Controls.DynamicData 23 | { 24 | public class DynamicDataContext 25 | { 26 | private static ConcurrentDictionary bindingCache = new ConcurrentDictionary(); 27 | 28 | public DataContextStack DataContextStack { get; } 29 | 30 | public IDotvvmRequestContext RequestContext { get; } 31 | 32 | public IViewModelValidationMetadataProvider ValidationMetadataProvider { get; } 33 | 34 | public IPropertyDisplayMetadataProvider PropertyDisplayMetadataProvider { get; } 35 | public DynamicDataConfiguration DynamicDataConfiguration { get; } 36 | 37 | public Type EntityType => DataContextStack.DataContextType; 38 | 39 | public string ViewName { get; set; } 40 | 41 | public string GroupName { get; set; } 42 | 43 | public Dictionary StateBag { get; } = new Dictionary(); 44 | public BindingCompilationService BindingCompilationService { get; } 45 | 46 | public DynamicDataContext(DataContextStack dataContextStack, IDotvvmRequestContext requestContext) 47 | { 48 | DataContextStack = dataContextStack; 49 | RequestContext = requestContext; 50 | 51 | ValidationMetadataProvider = requestContext.Services.GetRequiredService(); 52 | PropertyDisplayMetadataProvider = requestContext.Services.GetRequiredService(); 53 | DynamicDataConfiguration = requestContext.Services.GetRequiredService(); 54 | BindingCompilationService = requestContext.Services.GetRequiredService(); 55 | } 56 | 57 | public ValueBindingExpression CreateValueBinding(string expression, params Type[] nestedDataContextTypes) 58 | { 59 | var dataContextStack = CreateDataContextStack(DataContextStack, nestedDataContextTypes); 60 | 61 | var descriptor = new BindingDescriptor(expression, typeof(ValueBindingExpression), dataContextStack); 62 | 63 | return (ValueBindingExpression)bindingCache.GetOrAdd(descriptor, bd => CompileValueBindingExpression(descriptor)); 64 | } 65 | 66 | public ValueBindingExpression CreateValueBinding(string expression, params Type[] nestedDataContextTypes) 67 | { 68 | var dataContextStack = CreateDataContextStack(DataContextStack, nestedDataContextTypes); 69 | 70 | var descriptor = new BindingDescriptor(expression, typeof(ValueBindingExpression), dataContextStack); 71 | 72 | return (ValueBindingExpression)bindingCache.GetOrAdd(descriptor, bd => CompileValueBindingExpression(descriptor)); 73 | } 74 | 75 | public CommandBindingExpression CreateCommandBinding(string expression, params Type[] nestedDataContextTypes) 76 | { 77 | var dataContextStack = CreateDataContextStack(DataContextStack, nestedDataContextTypes); 78 | 79 | var descriptor = new BindingDescriptor(expression, typeof(CommandBindingExpression), dataContextStack); 80 | 81 | return (CommandBindingExpression)bindingCache.GetOrAdd(descriptor, bd => CompileCommandBindingExpression(descriptor)); 82 | } 83 | 84 | private IBinding CompileCommandBindingExpression(BindingDescriptor descriptor) 85 | { 86 | var bindingId = Convert.ToBase64String(Encoding.ASCII.GetBytes(descriptor.DataContextStack.DataContextType.Name + "." + descriptor.Expression)); 87 | 88 | var properties = new object[]{ 89 | descriptor.DataContextStack, 90 | new OriginalStringBindingProperty(descriptor.Expression), 91 | new IdBindingProperty(bindingId) 92 | }; 93 | 94 | return BindingCompilationService.CreateBinding(descriptor.BindingType, properties); 95 | } 96 | 97 | private IBinding CompileValueBindingExpression(BindingDescriptor bindingDescriptor) 98 | { 99 | var properties = new object[] 100 | { 101 | bindingDescriptor.DataContextStack, 102 | new OriginalStringBindingProperty(bindingDescriptor.Expression) 103 | }; 104 | 105 | return BindingCompilationService.CreateBinding(bindingDescriptor.BindingType, properties); 106 | } 107 | 108 | private DataContextStack CreateDataContextStack(DataContextStack dataContextStack, Type[] nestedDataContextTypes) 109 | { 110 | foreach (var type in nestedDataContextTypes) 111 | { 112 | dataContextStack = DataContextStack.Create(type, dataContextStack, dataContextStack.NamespaceImports, dataContextStack.ExtensionParameters); 113 | } 114 | return dataContextStack; 115 | } 116 | 117 | public IViewContext CreateViewContext(IDotvvmRequestContext context) 118 | { 119 | return new ViewContext() 120 | { 121 | ViewName = ViewName, 122 | GroupName = GroupName, 123 | CurrentUser = context.HttpContext.User 124 | }; 125 | } 126 | 127 | private class BindingDescriptor 128 | { 129 | public DataContextStack DataContextStack { get; } 130 | public string Expression { get; } 131 | 132 | public Type BindingType { get; } 133 | 134 | public BindingDescriptor(string expression, Type bindingType, DataContextStack dataContextStack) 135 | { 136 | Expression = expression ?? throw new ArgumentNullException(nameof(expression)); 137 | BindingType = bindingType ?? throw new ArgumentNullException(nameof(bindingType)); 138 | DataContextStack = dataContextStack ?? throw new ArgumentNullException(nameof(dataContextStack)); ; 139 | } 140 | 141 | public override bool Equals(object obj) 142 | { 143 | var descriptor = obj as BindingDescriptor; 144 | 145 | if (descriptor == null) 146 | { 147 | return false; 148 | } 149 | 150 | return DataContextStack.Equals(descriptor.DataContextStack) 151 | && Expression.Equals(descriptor.Expression) 152 | && BindingType.Equals(descriptor.BindingType); 153 | } 154 | 155 | public override int GetHashCode() 156 | { 157 | unchecked 158 | { 159 | var hashCode = 0; 160 | hashCode = (hashCode * 397) ^ (DataContextStack?.GetHashCode() ?? 0); 161 | hashCode = (hashCode * 13) ^ (Expression?.GetHashCode() ?? 0); 162 | hashCode = (hashCode * 49) ^ (BindingType?.GetHashCode() ?? 0); 163 | 164 | return hashCode; 165 | } 166 | } 167 | } 168 | } 169 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DotVVM Dynamic Data 2 | 3 | Reimplementation of **ASP.NET Dynamic Data** for [DotVVM](https://github.com/riganti/dotvvm). 4 | 5 | 6 | ## Data Annotations 7 | 8 | The main goal of this library is to generate user interface from metadata. Currently, there are two interfaces: 9 | 10 | * `IPropertyDisplayMetadataProvider` provides basic information about properties - the display name, format string, order, group name (you can split the fields into multiple groups and render each group separately). 11 | 12 | * `IViewModelValidationMetadataProvider` allows to retrieve all validation attributes for each property. 13 | 14 | 15 | ## Initialization 16 | 17 | First, install the `DotVVM.DynamicData` NuGet package in your project. 18 | 19 | ``` 20 | Install-Package DotVVM.DynamicData 21 | ``` 22 | 23 | To use Dynamic Data, add the following line to the `Startup.cs` file. 24 | 25 | ``` 26 | // ASP.NET Core (place this snippet in the ConfigureServices method) 27 | services.AddDotVVM(options => 28 | { 29 | var dynamicDataConfig = new DynamicDataConfiguration(); 30 | // set up config 31 | options.AddDynamicData(dynamicDataConfig); 32 | }); 33 | 34 | // OWIN 35 | app.UseDotVVM(applicationPhysicalPath, options: options => 36 | { 37 | var dynamicDataConfig = new DynamicDataConfiguration(); 38 | // set up config 39 | options.AddDynamicData(dynamicDataConfig); 40 | }); 41 | ``` 42 | 43 | This will allow to provide UI metadata using the standard .NET Data Annotations attributes. 44 | 45 | ``` 46 | public class EmployeeDTO 47 | { 48 | [Display(AutoGenerateField = false)] // this field will be hidden 49 | public int Id { get; set; } 50 | 51 | 52 | 53 | // first group of fields 54 | 55 | [Required] 56 | [EmailAddress] 57 | [Display(Name = "User Name", Order = 1, GroupName = "Basic Info")] 58 | public string UserName { get; set; } 59 | 60 | [Required] 61 | [Display(Name = "First Name", Order = 2, GroupName = "Basic Info")] 62 | public string FirstName { get; set; } 63 | 64 | [Required] 65 | [Display(Name = "Last Name", Order = 3, GroupName = "Basic Info")] 66 | public string LastName { get; set; } 67 | 68 | [DisplayFormat(DataFormatString = "d")] 69 | [Display(Name = "Birth Date", Order = 4, GroupName = "Basic Info")] 70 | public DateTime BirthDate { get; set; } 71 | 72 | 73 | // second group of fields 74 | 75 | [Display(Name = "E-mail", Order = 11, GroupName = "Contact Info")] 76 | public string PersonalEmail { get; set; } 77 | 78 | [Display(Name = "Phone", Order = 12, GroupName = "Contact Info")] 79 | public string PersonalPhone { get; set; } 80 | 81 | } 82 | ``` 83 | 84 |
85 | 86 | ## GridView 87 | 88 | Now, when you have your DTO class decorated with data annotation attributes, you can auto-generate GridView columns. 89 | 90 | DotVVM Dynamic Data brings the `DynamicDataGridViewDecorator` control. Use this decorator on `GridView` to initialize the `Columns` collection. 91 | 92 | ``` 93 | 94 | 95 | 96 | ``` 97 | 98 | If you want to add your own columns (e.g. the edit button) to the auto-generated ones, you can use the `ColumnPlacement` to specify, whether 99 | the generated columns should appear on the left side or the right side from your own columns. 100 | 101 | ``` 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | ``` 117 | 118 |
119 | 120 | ## Generating Forms 121 | 122 | DotVVM Dynamic Data also contains the `DynamicEntity` control - you can use it to generate forms. 123 | 124 | ``` 125 | 126 | ``` 127 | 128 | The control takes its `DataContext` and generates form fields for all properties of the object using the metadata from data annotation attributes. 129 | 130 | If you want the form to have a custom layout, you need to use the group names and render each group separately. If you specify the `GroupName` property, the `DynamicEntity` will render 131 | only fields from this group. 132 | 133 | ``` 134 | 135 |
136 |
137 | 138 |
139 |
140 | 141 |
142 |
143 | ``` 144 | 145 | By default, the form is rendered using the [TableDynamicFormBuilder](./src/DotVVM.Framework.DynamicData/DotVVM.Framework.Controls.DynamicData/Builders/TableDynamicFormBuilder.cs) class. 146 | This class renders HTML table with rows for each of the form fields. 147 | 148 | You can write your own form builder and register it in the `DotvvmStartup.cs` class. The builder must implement the `IFormBuilder` interface. 149 | 150 | ``` 151 | config.ServiceLocator.RegisterSingleton(() => new YourOwnFormBuilder()); 152 | ``` 153 | 154 | If you have implemented your own form builder and there is a chance that it might be useful for other people, please send us PR and we'll be happy to include as part of the library. 155 | 156 |
157 | 158 | ## Custom Editors 159 | 160 | Currently, the framework supports `TextBox` and `CheckBox` editors, which can edit string, numeric, date-time and boolean values. 161 | If you want to support any other data type, you can implement your own editor and grid column. 162 | 163 | You need to derive from the [FormEditorProviderBase](./src/DotVVM.Framework.DynamicData/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/FormEditors/FormEditorProviderBase.cs) to implement a custom editor 164 | in the form, and to derive from the [GridColumnProviderBase](./src/DotVVM.Framework.DynamicData/DotVVM.Framework.Controls.DynamicData/PropertyHandlers/GridColumns/GridColumnProviderBase.cs) to implement about 165 | custom GridView column. 166 | 167 | Then, you have to register the editor in the `DotvvmStartup.cs` file. Please note that the order of editor providers and grid columns matters. The Dynamic Data will use the first provider which returns `CanHandleProperty = true` 168 | for the property. 169 | 170 | ``` 171 | dynamicDataConfig.FormEditorProviders.Add(new YourEditorProvider()); 172 | dynamicDataConfig.GridColumnProviders.Add(new YourGridColumnProvider()); 173 | ``` 174 | 175 |
176 | 177 | ## Loading Metadata from Resource Files 178 | 179 | Decorating every field with the `[Display(Name = "Whatever")]` is not very effective when it comes to localization - you need to specify the resource file type and resource key. 180 | Also, if you have multiple entities with the `FirstName` property, you'll probably want to use the same field name for all of them. 181 | 182 | That's why DotVVM Dynamic Data comes with the resource-based metadata providers. They can be registered in the `DotvvmStartup.cs` like this: 183 | 184 | ``` 185 | config.RegisterResourceMetadataProvider(typeof(Resources.ErrorMessages), typeof(Resources.PropertyDisplayNames)); 186 | ``` 187 | 188 | The `ErrorMessages` and `PropertyDisplayNames` are RESX files in the `Resources` folder and they contain the default error messages and display names of the properties. 189 | 190 | ### Localizing Error Messages 191 | 192 | If you use the `[Required]` attribute and you don't specify the `ErrorMessage` or `ErrorMessageResourceName` on it, the resource provider will look in the `ErrorMessages.resx` file 193 | and if it finds the `Required` key there, it'll use this resource item to provide the error message. 194 | 195 | Your `ErrorMessages.resx` file may look like this: 196 | 197 | ``` 198 | Resource Key Value 199 | ------------------------------------------------------------------------------------- 200 | Required {0} is required! 201 | EmailAddress {0} is not a valid e-mail address! 202 | ... 203 | ``` 204 | 205 | ### Localizing Property Display Names 206 | 207 | The second resource file `PropertyDisplayNames.resx` contains the display names. If the property doesn't have the `[Display(Name = "Something")]` attribute, the provider will look in the 208 | resource file for the following values (in this order). If it finds an item with that key, it'll use the value as a display name of the field 209 | 210 | * `TypeName_PropertyName` 211 | * `PropertyName` 212 | 213 | So if you want to use the text "Given Name" for the `FirstName` property in all classes, with the exception of the `ManagerDTO` class where you need to use the "First Name" text, your resource file 214 | should look like this: 215 | 216 | ``` 217 | Resource Key Value 218 | ------------------------------------------------------------------------------------- 219 | FirstName Given Name 220 | ManagerDTO_FirstName First Name 221 | ... 222 | ``` 223 | 224 |
225 | 226 | ## Roadmap 227 | 228 | Here is a brief list of features that are already done, and features that are planned for the future releases. 229 | 230 | ### Implemented 231 | 232 | * `DisplayAttribute` (`Name`, `Order`, `GroupName`, `AutoGenerateField`) 233 | * `DisplayFormatAttribute` (`DataFormatString`) 234 | * Validation Attributes 235 | * Resource lookup for validation error messages and property display names 236 | * HTML table layout for Forms 237 | * TextBox and CheckBox editors 238 | * ComboBox editor with support of conventions 239 | 240 | ### In Progress 241 | 242 | * `DisplayFormatAttribute` (`NullDisplayText`) 243 | * `DynamicEditor` control for editing individual field 244 | * DateTimePicker and UserControl editor 245 | * More form layouts 246 | 247 | ### Future 248 | 249 | * `UIHint` attribute support 250 | * Auto-generating filters on top of the GridView 251 | * Entity Relationship support 252 | * Collection editors 253 | * Page templates 254 | 255 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------