Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates for razor pages crud and blazor crud templates #3086

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eng/Versions.DotNetScaffold.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>9.0.0</VersionPrefix>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>10</PreReleaseVersionIteration>
<VersionPrefix>10.0.0</VersionPrefix>
deepchoudhery marked this conversation as resolved.
Show resolved Hide resolved
<PreReleaseVersionLabel>alpha</PreReleaseVersionLabel>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<!--
Expand Down
6 changes: 3 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
<MicrosoftDotNetPlatformAbstractionsVersion>3.1.6</MicrosoftDotNetPlatformAbstractionsVersion>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>9.0.0</VersionPrefix>
<PreReleaseVersionLabel>rc</PreReleaseVersionLabel>
<PreReleaseVersionIteration>2</PreReleaseVersionIteration>
<VersionPrefix>10.0.0</VersionPrefix>
<PreReleaseVersionLabel>alpha</PreReleaseVersionLabel>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<!--
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-aspnet-codegenerator.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set VERSION=9.0.0-dev
set VERSION=10.0.0-dev
set DEFAULT_NUPKG_PATH=C:\Nuget
set SRC_DIR=%cd%
set NUPKG=artifacts\packages\Debug\Shipping\
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-scaffold-all.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set VERSION=9.0.0-dev
set VERSION=10.0.0-dev
set DEFAULT_NUPKG_PATH=%userprofile%/.nuget/packages
set SRC_DIR=%cd%
set NUPKG=artifacts/packages/Debug/Shipping/
Expand Down
10 changes: 7 additions & 3 deletions src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ public virtual string TransformText()
string propertyShortTypeName = property.ShortTypeName.Replace("?", string.Empty);
var inputTypeName = Model.GetInputType(propertyShortTypeName);
var inputClass = Model.GetInputClassType(propertyShortTypeName);
var requiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var ariaRequiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var divWhitespace = new string(' ', 16);
var requiredSpanAttributeHtml = property.IsRequired ? $"\r\n{divWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;

this.Write("<div class=\"mb-3\">\r\n <label for=\"");
this.Write("<div class=\"mb-3\">");
this.Write(this.ToStringHelper.ToStringWithCulture(requiredSpanAttributeHtml));
this.Write("\r\n <label for=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(modelPropertyNameLowercase));
this.Write("\" class=\"form-label\">");
this.Write(this.ToStringHelper.ToStringWithCulture(modelPropertyName));
Expand All @@ -85,7 +89,7 @@ public virtual string TransformText()
this.Write("\" class=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(inputClass));
this.Write("\" ");
this.Write(this.ToStringHelper.ToStringWithCulture(requiredAttributeHtml));
this.Write(this.ToStringHelper.ToStringWithCulture(ariaRequiredAttributeHtml));
this.Write("/> \r\n <ValidationMessage For=\"() => ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelName));
this.Write(".");
Expand Down
8 changes: 5 additions & 3 deletions src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Create.tt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
string propertyShortTypeName = property.ShortTypeName.Replace("?", string.Empty);
var inputTypeName = Model.GetInputType(propertyShortTypeName);
var inputClass = Model.GetInputClassType(propertyShortTypeName);
var requiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var ariaRequiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var divWhitespace = new string(' ', 16);
var requiredSpanAttributeHtml = property.IsRequired ? $"\r\n{divWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;
#>
<div class="mb-3">
<div class="mb-3"><#= requiredSpanAttributeHtml #>
<label for="<#= modelPropertyNameLowercase #>" class="form-label"><#= modelPropertyName #>:</label>
<<#= inputTypeName #> id="<#= modelPropertyNameLowercase #>" @bind-Value="<#= modelName #>.<#= modelPropertyName #>" class="<#= inputClass #>" <#= requiredAttributeHtml #>/>
<<#= inputTypeName #> id="<#= modelPropertyNameLowercase #>" @bind-Value="<#= modelName #>.<#= modelPropertyName #>" class="<#= inputClass #>" <#= ariaRequiredAttributeHtml #>/>
<ValidationMessage For="() => <#= modelName #>.<#= modelPropertyName #>" class="text-danger" />
</div>
<# } #>
Expand Down
10 changes: 7 additions & 3 deletions src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ public virtual string TransformText()
string propertyShortTypeName = property.ShortTypeName.Replace("?", string.Empty);
var inputTypeName = Model.GetInputType(propertyShortTypeName);
var inputClass = Model.GetInputClassType(propertyShortTypeName);
var requiredHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var ariaRequiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var divWhitespace = new string(' ', 16);
var requiredSpanAttributeHtml = property.IsRequired ? $"\r\n{divWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;

this.Write(" <div class=\"mb-3\">\r\n <label for=\"");
this.Write(" <div class=\"mb-3\">");
this.Write(this.ToStringHelper.ToStringWithCulture(requiredSpanAttributeHtml));
this.Write("\r\n <label for=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(modelPropertyNameLowercase));
this.Write("\" class=\"form-label\">");
this.Write(this.ToStringHelper.ToStringWithCulture(modelPropertyName));
Expand All @@ -100,7 +104,7 @@ public virtual string TransformText()
this.Write("\" class=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(inputClass));
this.Write("\" ");
this.Write(this.ToStringHelper.ToStringWithCulture(requiredHtml));
this.Write(this.ToStringHelper.ToStringWithCulture(ariaRequiredAttributeHtml));
this.Write("/>\r\n <ValidationMessage For=\"() => ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelName));
this.Write(".");
Expand Down
8 changes: 5 additions & 3 deletions src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ else
string propertyShortTypeName = property.ShortTypeName.Replace("?", string.Empty);
var inputTypeName = Model.GetInputType(propertyShortTypeName);
var inputClass = Model.GetInputClassType(propertyShortTypeName);
var requiredHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var ariaRequiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty;
var divWhitespace = new string(' ', 16);
var requiredSpanAttributeHtml = property.IsRequired ? $"\r\n{divWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;
#>
<div class="mb-3">
<div class="mb-3"><#= requiredSpanAttributeHtml #>
<label for="<#= modelPropertyNameLowercase #>" class="form-label"><#= modelPropertyName #>:</label>
<<#= inputTypeName #> id="<#= modelPropertyNameLowercase #>" @bind-Value="<#= modelName #>.<#= modelPropertyName #>" class="<#= inputClass #>" <#= requiredHtml #>/>
<<#= inputTypeName #> id="<#= modelPropertyNameLowercase #>" @bind-Value="<#= modelName #>.<#= modelPropertyName #>" class="<#= inputClass #>" <#= ariaRequiredAttributeHtml #>/>
<ValidationMessage For="() => <#= modelName #>.<#= modelPropertyName #>" class="text-danger" />
</div>
<# } #>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
foreach (var property in Model.ModelMetadata.Properties)
{
var sixteenWhitespace = new string(' ', 16);
var propertyRequiredText = property.IsRequired ? $"\n{sixteenWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;
var propertyRequiredText = property.IsRequired ? $"\r\n{sixteenWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;
var ariaRequiredAttributeHtml = property.IsRequired ? "required aria-required=\"true\"" : string.Empty;
if (property.Scaffold && !property.IsAutoGenerated && !property.IsReadOnly)
{
if (property.IsForeignKey)
{
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class ="form-control" asp-items="[email protected]"></select>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class ="form-control" asp-items="[email protected]" @ariaRequiredAttributeHtml></select>
@:</div>
continue;
}
Expand All @@ -65,31 +66,31 @@
{
@:<div class="form-group form-check">@propertyRequiredText
@:<label class="form-check-label">
@:<input class="form-check-input" asp-for="@(Model.ModelTypeName)[email protected]" /> @@Html.DisplayNameFor(model => model.@(Model.ModelTypeName).@GetValueExpression(property))
@:<input class="form-check-input" asp-for="@(Model.ModelTypeName)[email protected]" @ariaRequiredAttributeHtml/> @@Html.DisplayNameFor(model => model.@(Model.ModelTypeName).@GetValueExpression(property))
@:</label>
@:</div>
}
else if (property.IsEnum && !property.IsEnumFlags)
{
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class="form-control"></select>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" @ariaRequiredAttributeHtml></select>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
}
else if (property.IsMultilineText)
{
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<textarea asp-for="@(Model.ModelTypeName)[email protected]" class="form-control"></textarea>
@:<textarea asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" @ariaRequiredAttributeHtml></textarea>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
}
else
{
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<input asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" />
@:<input asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" @ariaRequiredAttributeHtml/>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
@:<div asp-validation-summary="ModelOnly" class="text-danger"></div>
foreach (PropertyMetadata property in Model.ModelMetadata.Properties)
{
var propertyRequiredText = property.IsRequired ? "<span class=\"text-danger\">*</span>" : string.Empty;
var propertyRequiredText = property.IsRequired ? "\r\n<span class=\"text-danger\">*</span>" : string.Empty;
var ariaRequiredAttributeHtml = property.IsRequired ? "required aria-required=\"true\"" : string.Empty;
deepchoudhery marked this conversation as resolved.
Show resolved Hide resolved
if (property.IsPrimaryKey)
{
@:<input type="hidden" asp-for="@(Model.ModelTypeName)[email protected]" />
Expand All @@ -63,10 +64,9 @@

if (property.IsForeignKey)
{
@:<div class="form-group">
@:@propertyRequiredText
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" asp-items="[email protected]"></select>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" asp-items="[email protected]" @ariaRequiredAttributeHtml></select>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
continue;
Expand All @@ -75,37 +75,33 @@
bool isCheckbox = property.TypeName.Equals("System.Boolean");
if (isCheckbox)
{
@:<div class="form-group form-check">
@:@propertyRequiredText
@:<div class="form-group form-check">@propertyRequiredText
@:<label class="form-check-label">
@:<input class="form-check-input" asp-for="@(Model.ModelTypeName)[email protected]" /> @@Html.DisplayNameFor(model => model.@(Model.ModelTypeName).@GetValueExpression(property))
@:<input class="form-check-input" asp-for="@(Model.ModelTypeName)[email protected]" @ariaRequiredAttributeHtml/> @@Html.DisplayNameFor(model => model.@(Model.ModelTypeName).@GetValueExpression(property))
@:</label>
@:</div>
}
else if (property.IsEnum && !property.IsEnumFlags)
{
@:<div class="form-group">
@:@propertyRequiredText
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class="form-control"></select>
@:<select asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" @ariaRequiredAttributeHtml></select>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
}
else if (property.IsMultilineText)
{
@:<div class="form-group">
@:@propertyRequiredText
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<textarea asp-for="@(Model.ModelTypeName)[email protected]" class="form-control"></textarea>
@:<textarea asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" @ariaRequiredAttributeHtml></textarea>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
}
else
{
@:<div class="form-group">
@:@propertyRequiredText
@:<div class="form-group">@propertyRequiredText
@:<label asp-for="@(Model.ModelTypeName)[email protected]" class="control-label"></label>
@:<input asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" />
@:<input asp-for="@(Model.ModelTypeName)[email protected]" class="form-control" @ariaRequiredAttributeHtml/>
@:<span asp-validation-for="@(Model.ModelTypeName)[email protected]" class="text-danger"></span>
@:</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public virtual string TransformText()
string propertyShortTypeName = property.Type.ToDisplayString().Replace("?", string.Empty);
var inputTypeName = Model.GetInputType(propertyShortTypeName);
var inputClass = Model.GetInputClassType(propertyShortTypeName);
var requiredAttributeHtml = property.HasRequiredAttribute() ? "aria-required=\"true\"" : string.Empty;
var ariaRequiredAttributeHtml = property.HasRequiredAttribute() ? "aria-required=\"true\"" : string.Empty;
var divWhitespace = new string(' ', 16);
var requiredSpanAttributeHtml = property.HasRequiredAttribute() ? $"\r\n{divWhitespace}<span class=\"text-danger\">*</span>" : string.Empty;

this.Write("<div class=\"mb-3\">\r\n <label for=\"");
this.Write("<div class=\"mb-3\">");
this.Write(this.ToStringHelper.ToStringWithCulture(requiredSpanAttributeHtml));
this.Write("\r\n <label for=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(modelPropertyNameLowercase));
this.Write("\" class=\"form-label\">");
this.Write(this.ToStringHelper.ToStringWithCulture(modelPropertyName));
Expand All @@ -87,7 +91,7 @@ public virtual string TransformText()
this.Write("\" class=\"");
this.Write(this.ToStringHelper.ToStringWithCulture(inputClass));
this.Write("\" ");
this.Write(this.ToStringHelper.ToStringWithCulture(requiredAttributeHtml));
this.Write(this.ToStringHelper.ToStringWithCulture(ariaRequiredAttributeHtml));
this.Write("/> \r\n <ValidationMessage For=\"() => ");
this.Write(this.ToStringHelper.ToStringWithCulture(modelName));
this.Write(".");
Expand Down
Loading