Platz.SqlForms Inline Edit programming reference - ProCodersPtyLtd/MasterDetailsDataEntry GitHub Wiki
Platz.SqlForms framework is supposed to be installed using the NuGet package that can be found in Visual Studio Package Manager, the official link is: https://www.nuget.org/packages/Platz.SqlForms
To use Platz.SqlForms framework you will need to do these steps:
- Create a Dynamic Form definition - a class that is inherited from
DetailsForm<TContext>
- Use one of the available Platz.SqlForms razor components on Blazor page to render the created Dynamic Form definition
using Platz.SqlForms;
public abstract class DetailsForm< TContext > : IModelDefinitionForm
where TContext : DbContext
Base class to create a Dynamic Form definition.
DetailsForm accepts TContext
template parameter, it should be a class that based on Entity Framework DbContext
protected abstract void Define(FormBuilder builder);
This method should be implemented in the Dynamic Form class that is inherited from DetailsForm<TContext>
. The method accepts only one parameter FormBuilder builder
. The following example shows how to use it:
protected override void Define(FormBuilder builder)
{
builder.Entity<Department>(e =>
{
e.Property(p => p.DepartmentId).IsFilter().IsUnique();
});
}
using Platz.SqlForms;
public class FormBuilder
FormBuilder class is used to organize the fluent flow definition of a Dynamic Form.
public virtual FormBuilder Entity<TEntity>([NotNullAttribute] Action<FormEntityTypeBuilder<TEntity>> buildAction) where TEntity : class
This method should be used to supply the Entity Framework entity and its property definitions. The method accepts the TEntity
template parameter. The method accepts buildAction
parameter (not null). It is supposed to be a lambda expression (see example).
The return type is FormBuilder
, and you can add execution of other FormBuilder
methods to the chain, for example:
protected override void Define(FormBuilder builder)
{
builder.Entity<Department>(
// lambda expression
e =>
{
e.Property(p => p.DepartmentId).IsFilter().IsUnique();
})
// another method in the chain
.IsMaster();
}
public virtual FormBuilder IsMaster()
This method tells Platz.SqlForms framework that the last defined entity is a Master entity, the framework will recognize it as Master when rendering FormMasterDetailsComponent
razor control.
This method is supposed to be used only after the Entity<TEntity>
method in one chain, see the example above.
using Platz.SqlForms;
public class FormEntityTypeBuilder<TEntity> : FormEntityTypeBuilder where TEntity : class
FormEntityTypeBuilder is used for defining particular properties in the Entity.
public virtual FieldBuilder<TProperty> Property<TProperty>([NotNullAttribute] Expression<Func<TEntity, TProperty>> propertyExpression)
This method is used to specify an entity property that is being defined.
It accepts a lambda expression parameter, specifying a property in the entity (p => p.DepartmentId).
This method is used in the entity lambda expression (e =>):
builder.Entity<Department>(
// lambda expression
e =>
{
e.Property(p => p.DepartmentId).IsFilter().IsUnique();
})
Thus DepartmentId
property is specified in Department
entity.
The returned value is FieldBuilder<TProperty>
that allows adding a field attribute chain.
public virtual void InlineButton(string buttonText, string hint = null)
This method lets adding a custom button to the Entity is being defined. The custom button will be rendered in the Action buttons section on the right of the dynamic table.
This method accepts two string
parameters: buttonText and hint. The second parameter is optional,
It doesn't return value and should be used like that:
protected override void Define(FormBuilder builder)
{
builder.Entity<Department>(
// lambda expression
e =>
{
...
e.InlineButton("Details", "Details...");
});
}
using Platz.SqlForms;
Base class:
public class FieldBuilder
and the template class:
public class FieldBuilder<TProperty> : FieldBuilder
FieldBuilder<TProperty>
class lets specifying a chain of simple attributes that programmer adds to the entity property to define the property behavior in the Dynamic Form.
The simple attributes added as a chain of methods, that is possible because all of them return FieldBuilder<TProperty>
. The available methods are:
Method | Declaration | Description |
---|---|---|
IsPrimaryKey | IsPrimaryKey(bool pk = true) |
marks property as a Primary Key if it cannot be retrieved from Entity Framework |
IsRequired | IsRequired(bool required = true) |
marks property that required validation rule will be checked |
IsHidden | IsHidden(bool hidden = true) |
marks property that it should not be shown in the dynamic form |
IsReadOnly | IsReadOnly(bool readOnly = true) |
marks property that it is not editable |
IsFilter | IsFilter(bool filter = true) |
marks property that it can be used by filtering values by ID and prepopulated from Master record |
IsUnique | IsUnique(bool unique = true) |
marks property that unique validation rule will be checked |
Label | Label(string label) |
specifies label or column name for the property |
Format | Format(string format) |
specifies string format, very useful for DateTime |
Control | Control(Type controlType) |
specifies Dynamic Form UI component that should be used in the dynamic form |
ControlReadOnly | ControlReadOnly(Type controlType) |
specifies Dynamic Form UI component that should be used in the dynamic form in ReadOnly mode |
The simple attributes are used in the definition chain:
e.Property(p => p.DepartmentId).IsFilter().IsUnique().IsRequired().Label("Id").Format("d");
public virtual DropdownFieldBuilder<TEntity> Dropdown<TEntity>()
This method allows defining a selector UI behavior (a dropdown control) when the User should choose a value from a list. It accepts the TEntity
template parameter that is Entity Framework entity that linked to a SQL table containing all values that should be shown in the list for selection.
It returns DropdownFieldBuilder<TEntity>
embedded class with a single method Set
that allows specifying TEntity
properties for Id and Name to render in the dropdown control, see example below:
e.Property(p => p.Administrator).Dropdown<Person>().Set(c => c.PersonId, c => c.FullName).IsRequired();
These methods Dropdown
and Set
should be always used together, and after them, the chain of simple attributes can follow.
To define Master-Details form the two entities should be defined and one of them must be marked as Master:
public class DepartmentCourseForm : DetailsForm<SchoolContext>
{
protected override void Define(FormBuilder builder)
{
builder.Entity<Department>(e =>
{
e.Property(p => p.DepartmentId).IsFilter().IsUnique();
e.Property(p => p.Name).IsRequired();
e.Property(p => p.StartDate).IsRequired();
e.Property(p => p.Budget).IsRequired();
e.Property(p => p.Administrator).Dropdown<Person>().Set(c => c.PersonId, c => c.FullName).IsRequired();
}).IsMaster();
builder.Entity<Course>(e =>
{
e.Property(p => p.DepartmentId).IsFilter();
e.Property(p => p.CourseId).IsRequired().IsUnique();
e.Property(p => p.Title).IsRequired();
e.Property(p => p.Credits).IsRequired();
});
}
}
A public interface that defines methods that Dynamic Form should realize. All methods are realized in abstract class DetailsForm< TContext >
that should be used as a base class for all Dynamic Form definitions. Interface IModelDefinitionForm
is not supposed to be used directly.
Embedded to FieldBuilder<TProperty>
class it helps to define dropdown UI control for the property, accepting Entity Framework entity and Id and Name entity properties.
Parameter | Declaration | Description |
---|---|---|
FormType | public Type FormType { get; set; } |
Type of form definition class |
FilterValue | public int? FilterValue { get; set; } |
Value (if not null) by which framework filters records |
ItemButtonClicked | public EventCallback<ItemButtonClickedArgs> ItemButtonClicked { get; set; } |
Event that fired when User clicks a custom button |
Parameter | Declaration | Description |
---|---|---|
FormType | public Type FormType { get; set; } |
Type of form definition class |
FilterValue | public int? FilterValue { get; set; } |
Value (if not null) by which framework filters records |
ItemButtonClicked | public EventCallback<ItemButtonClickedArgs> ItemButtonClicked { get; set; } |
Event that fired when User clicks a custom button |
EditingNow | public bool EditingNow { get; set; } |
Shows form with empty master record in editing mode |