Skip to content

Commit

Permalink
🐛 fixed template
Browse files Browse the repository at this point in the history
🐛 fixed template
  • Loading branch information
neozhu authored Dec 23, 2023
2 parents 40e42b0 + a283bc3 commit f04028a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/CodeGeneratorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ protected async override System.Threading.Tasks.Task InitializeAsync(Cancellatio
private void ExecuteAsync(object sender, EventArgs e)
{
NewItemTarget target = NewItemTarget.Create(_dte);
NewItemTarget domain= NewItemTarget.Create(_dte, DOMAINPROJECT);
NewItemTarget infrastructure = NewItemTarget.Create(_dte, INFRASTRUCTUREPROJECT);
NewItemTarget ui = NewItemTarget.Create(_dte, UIPROJECT);
var includes = new string[] { "IEntity", "BaseEntity", "BaseAuditableEntity", "BaseAuditableSoftDeleteEntity", "AuditTrail", "OwnerPropertyEntity" };
NewItemTarget domain= NewItemTarget.Create(_dte,"Domain");
NewItemTarget infrastructure = NewItemTarget.Create(_dte, "Infrastructure");
NewItemTarget ui = NewItemTarget.Create(_dte, "Server.UI");
var includes = new string[] { "IEntity", "BaseEntity", "BaseAuditableEntity", "BaseAuditableSoftDeleteEntity", "AuditTrail", "OwnerPropertyEntity","KeyValue" };
var objectlist = ProjectHelpers.GetEntities(domain.Project)
.Where(x => includes.Contains(x.BaseName) && !includes.Contains(x.Name));
var entities = objectlist.Select(x=>x.Name).Distinct().ToArray();
Expand Down
48 changes: 24 additions & 24 deletions src/Templatemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ static TemplateMap()
_folder = Path.Combine(Path.GetDirectoryName(assembly), "Templates");
_templateFiles.AddRange(Directory.GetFiles(_folder, "*" + _defaultExt, SearchOption.AllDirectories));
}


public static async Task<string> GetTemplateFilePathAsync(Project project, IntellisenseObject classObject, string file,string itemname,string selectFolder)

public static async Task<string> GetTemplateFilePathAsync(Project project, IntellisenseObject classObject, string file, string itemname, string selectFolder)
{
var templatefolders =new string[]{
var templatefolders = new string[]{
"Commands\\AcceptChanges",
"Commands\\Create",
"Commands\\Delete",
Expand Down Expand Up @@ -70,18 +70,18 @@ public static async Task<string> GetTemplateFilePathAsync(Project project, Intel

// Look for direct file name matches
if (list.Any(f => {
var pattern = templatefolders.Where(x => relative.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0).First().Replace("\\","\\\\");
var result = Regex.IsMatch(f, pattern, RegexOptions.IgnoreCase);
return result;
}) )
var pattern = templatefolders.Where(x => relative.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0).First().Replace("\\", "\\\\");
var result = Regex.IsMatch(f, pattern, RegexOptions.IgnoreCase);
return result;

}))
{
var tmplFile = list.OrderByDescending(x=>x.Length).FirstOrDefault(f => {
var tmplFile = list.OrderByDescending(x => x.Length).FirstOrDefault(f => {
var pattern = templatefolders.Where(x => relative.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0).First().Replace("\\", "\\\\"); ;
var result = Regex.IsMatch(f, pattern, RegexOptions.IgnoreCase);
if (result)
{
return Path.GetFileNameWithoutExtension(f).Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).All(x=>name.IndexOf(x, StringComparison.OrdinalIgnoreCase)>=0);
return Path.GetFileNameWithoutExtension(f).Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).All(x => name.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0);
}
return false;
});
Expand Down Expand Up @@ -116,7 +116,7 @@ private static void AddTemplatesFromCurrentFolder(List<string> list, string dir)
list.InsertRange(0, dynaList);
}

private static async Task<string> ReplaceTokensAsync(Project project, IntellisenseObject classObject, string name, string relative,string selectRelative, string templateFile)
private static async Task<string> ReplaceTokensAsync(Project project, IntellisenseObject classObject, string name, string relative, string selectRelative, string templateFile)
{
if (string.IsNullOrEmpty(templateFile))
{
Expand Down Expand Up @@ -148,8 +148,8 @@ private static async Task<string> ReplaceTokensAsync(Project project, Intellisen
var mudFormFieldDefinition = createMudFormFieldDefinition(classObject);
var fieldAssignmentDefinition = createFieldAssignmentDefinition(classObject);
return content.Replace("{rootnamespace}", _defaultNamespace)
.Replace("{namespace}", ns)
.Replace("{selectns}", selectNs)
.Replace("{namespace}", ns)
.Replace("{selectns}", selectNs)
.Replace("{itemname}", name)
.Replace("{nameofPlural}", nameofPlural)
.Replace("{dtoFieldDefinition}", dtoFieldDefinition)
Expand Down Expand Up @@ -195,7 +195,7 @@ private static string splitCamelCase(string str)
private static string createDtoFieldDefinition(IntellisenseObject classObject)
{
var output = new StringBuilder();
foreach(var property in classObject.Properties.Where(x => x.Type.IsKnownType == true))
foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true))
{
output.Append($" [Description(\"{splitCamelCase(property.Name)}\")]\r\n");
if (property.Name == PRIMARYKEY)
Expand All @@ -208,7 +208,7 @@ private static string createDtoFieldDefinition(IntellisenseObject classObject)
{
case "string" when property.Name.Equals("Name", StringComparison.OrdinalIgnoreCase):
output.Append($" public {property.Type.CodeName} {property.Name} {{get;set;}} = String.Empty; \r\n");
break;
break;
case "string" when !property.Name.Equals("Name", StringComparison.OrdinalIgnoreCase) && !property.Type.IsArray && !property.Type.IsDictionary:
output.Append($" public {property.Type.CodeName}? {property.Name} {{get;set;}} \r\n");
break;
Expand Down Expand Up @@ -247,7 +247,7 @@ private static string createDtoFieldDefinition(IntellisenseObject classObject)
}
break;
}

}
}
return output.ToString();
Expand Down Expand Up @@ -333,10 +333,11 @@ private static string createMudTdDefinition(IntellisenseObject classObject)
output.Append(" ");
output.Append($" <MudText>@context.Name</MudText>\r\n");
}
if (classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name == defaultfieldName.Last()).Any()) {
if (classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name == defaultfieldName.Last()).Any())
{
output.Append(" ");
output.Append($" <MudText Typo=\"Typo.body2\" Class=\"mud-text-secondary\">@context.Description</MudText>\r\n");
}
}
output.Append(" ");
output.Append($" </div>\r\n");
output.Append(" ");
Expand All @@ -350,7 +351,7 @@ private static string createMudTdDefinition(IntellisenseObject classObject)
{
output.Append($" <MudTd HideSmall=\"false\" DataLabel=\"@L[_currentDto.GetMemberDescription(x=>x.{property.Name})]\" ><MudCheckBox Checked=\"@context.{property.Name}\" ReadOnly></MudCheckBox></MudTd> \r\n");
}
else if(property.Type.CodeName.Equals("System.DateTime", StringComparison.OrdinalIgnoreCase))
else if (property.Type.CodeName.Equals("System.DateTime", StringComparison.OrdinalIgnoreCase))
{
output.Append($" <MudTd HideSmall=\"false\" DataLabel=\"@L[_currentDto.GetMemberDescription(x=>x.{property.Name}))]\" >@context.{property.Name}.Date.ToString(\"d\")</MudTd> \r\n");
}
Expand All @@ -362,7 +363,7 @@ private static string createMudTdDefinition(IntellisenseObject classObject)
{
output.Append($" <MudTd HideSmall=\"false\" DataLabel=\"@L[_currentDto.GetMemberDescription(x=>.{property.Name})]\" >@context.{property.Name}</MudTd> \r\n");
}

}
return output.ToString();
}
Expand Down Expand Up @@ -421,7 +422,7 @@ private static string createMudFormFieldDefinition(IntellisenseObject classObjec
output.Append(" ");
output.Append($"</MudItem> \r\n");
break;
case "system.datetime?":
case "system.datetime?":
output.Append($"<MudItem xs=\"12\" md=\"6\"> \r\n");
output.Append(" ");
output.Append($" <MudDatePicker Label=\"@L[model.GetMemberDescription(x=>x.{property.Name})]\" @bind-Date=\"model.{property.Name}\" For=\"@(() => model.{property.Name})\" Required=\"false\" RequiredError=\"@L[\"{splitCamelCase(property.Name).ToLower()} is required!\"]\"></MudDatePicker>\r\n");
Expand All @@ -437,7 +438,7 @@ private static string createMudFormFieldDefinition(IntellisenseObject classObjec
break;

}

}
return output.ToString();
}
Expand All @@ -446,9 +447,8 @@ private static string createMudFormFieldDefinition(IntellisenseObject classObjec
private static string createFieldAssignmentDefinition(IntellisenseObject classObject)
{
var output = new StringBuilder();
foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true))
foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name != "Id"))
{
output.Append($" ");
output.Append($" {property.Name} = dto.{property.Name}, \r\n");
}
return output.ToString();
Expand Down
1 change: 0 additions & 1 deletion src/Templates/DTOs/.dto.cs.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
namespace {namespace};

[Description("{nameofPlural}")]
Expand Down
9 changes: 4 additions & 5 deletions src/Templates/Pages/.razor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,9 @@
}
private async Task OnClone()
{
var copyitem = _selectedItems.First();
var dto = _selectedItems.First();
var command = new AddEdit{itemname}Command(){
Name = copyitem.Name,
Description = copyitem.Description,
{fieldAssignmentDefinition}
};
var parameters = new DialogParameters<{itemname}FormDialog>
{
Expand All @@ -311,7 +310,7 @@
if (!state.Canceled)
{
await _table.ReloadServerData();
_selectedItems.Remove(copyitem);
_selectedItems=new HashSet<{itemname}Dto>();
}
}
private async Task OnEdit({itemname}Dto dto)
Expand All @@ -337,7 +336,7 @@
var parameters = new DialogParameters<DeleteConfirmation>
{
{ x=>x.Command, command },
{ x=>x.ContentText, string.Format(ConstantString.DeleteConfirmation, dto.Name) }
{ x=>x.ContentText, string.Format(ConstantString.DeleteConfirmation, dto.Id) }
};
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Small, FullWidth = true, DisableBackdropClick = true };
var dialog = DialogService.Show<DeleteConfirmation>(ConstantString.DeleteConfirmationTitle, parameters, options);
Expand Down

0 comments on commit f04028a

Please sign in to comment.