diff --git a/src/Helpers/GeneralHelper.cs b/src/Helpers/GeneralHelper.cs index b8962c1..5fe8932 100644 --- a/src/Helpers/GeneralHelper.cs +++ b/src/Helpers/GeneralHelper.cs @@ -121,27 +121,39 @@ public static string SetTextEnabledClass(bool enabled) public static bool IsNotNull([NotNullWhen(true)] object? obj) => obj != null; - public static string FormatResoureType(string type) + public static string[] FormatResoureType(string type) { + String[] returntype = new String[3]; + // Make sure it is a full resource type name + if (type.Contains("(")) + { + returntype[0] = type.Substring(0, type.IndexOf("(")).Trim(); + } try { - // trim any details out of the value - if (type.Contains("-")) + if ((GeneralHelper.IsNotNull(type)) && (GeneralHelper.IsNotNull(returntype[0]))) { - type = type.Substring(0, type.IndexOf("-")).Trim(); - } + // trim any details out of the value + if (returntype[0].Contains(" -")) + { + returntype[1] = returntype[0].Substring(0, returntype[0].IndexOf(" -")).Trim(); + } - // trim any details out of the value - if (type.Contains("(")) - { - type = type.Substring(0, type.IndexOf("(")).Trim(); + // trim any details out of the value + if ((type.Contains("(")) && (type.Contains(")"))) + { + { + int intstart = type.IndexOf("(") + 1; + returntype[2] = String.Concat(type.Substring(intstart).TakeWhile(x => x != ')')); + } + } } } catch (Exception ex) { AdminLogService.PostItem(new AdminLogMessage() { Title = "ERROR", Message = ex.Message }); } - return type; + return returntype; } } } diff --git a/src/Pages/Generate.razor b/src/Pages/Generate.razor index a68376f..5f84095 100644 --- a/src/Pages/Generate.razor +++ b/src/Pages/Generate.razor @@ -107,7 +107,7 @@ - + @foreach (var type in @ResourceTypeService.GetFilteredResourceTypes(servicesData.ResourceTypes, selectedResourceTypeCategory)) { @@ -492,8 +492,11 @@ private string selectedResourceLocation = String.Empty; private string selectedResourceOrg = String.Empty; private string selectedResourceProjAppSvc = String.Empty; + private String[] selectedResourceTypeFull = new String[2]; private string selectedResourceTypeCategory = String.Empty; private string selectedResourceType = String.Empty; + private string selectedResourceTypeShortName = String.Empty; + private string selectedResourceTypeDisplayName = String.Empty; private string selectedResourceTypeExclude = String.Empty; private string selectedResourceTypeOptional = String.Empty; private Dictionary selectedCustomComponents = new(); @@ -607,8 +610,24 @@ { // Single type generation StringBuilder sbName = new(); - selectedResourceType = GeneralHelper.FormatResoureType(selectedResourceType); - resourceType = servicesData.ResourceTypes!.Find(x => x.Resource == selectedResourceType)!; + selectedResourceTypeFull = GeneralHelper.FormatResoureType(selectedResourceTypeDisplayName); + if (GeneralHelper.IsNotNull(selectedResourceTypeFull[1])) + { + selectedResourceType = selectedResourceTypeFull[1]; + } + else + { + selectedResourceType = selectedResourceTypeFull[0]; + } + selectedResourceTypeShortName = selectedResourceTypeFull[2]; + if (GeneralHelper.IsNotNull(selectedResourceTypeShortName)) + { + resourceType = servicesData.ResourceTypes!.Find(x => x.Resource == selectedResourceType && x.ShortName == selectedResourceTypeShortName)!; + } + else + { + resourceType = servicesData.ResourceTypes!.Find(x => x.Resource == selectedResourceType)!; + } if (GeneralHelper.IsNotNull(resourceType)) { resourceNameRequest.ResourceType = resourceType.ShortName; @@ -805,14 +824,29 @@ } resourceNameRequestResponse = new(); // Assign the selected value to the Model - selectedResourceType = value; + selectedResourceTypeDisplayName = value; - if (!String.IsNullOrEmpty(selectedResourceType)) + if (!String.IsNullOrEmpty(selectedResourceTypeDisplayName)) { - selectedResourceType = GeneralHelper.FormatResoureType(selectedResourceType); + selectedResourceTypeFull = GeneralHelper.FormatResoureType(selectedResourceTypeDisplayName); + if(GeneralHelper.IsNotNull(selectedResourceTypeFull[1])) + { + selectedResourceType = selectedResourceTypeFull[1]; + } + else + { + selectedResourceType = selectedResourceTypeFull[0]; + } + selectedResourceTypeShortName = selectedResourceTypeFull[2]; + if (GeneralHelper.IsNotNull(selectedResourceTypeShortName)) + { + currentResourceType = servicesData.ResourceTypes!.Find(x => x.Resource == selectedResourceType && x.ShortName == selectedResourceTypeShortName)!; + } + else + { + currentResourceType = servicesData.ResourceTypes!.Find(x => x.Resource == selectedResourceType)!; + } - // Find the selected resoruce type - currentResourceType = servicesData.ResourceTypes!.Find((t) => t.Resource == selectedResourceType); if (GeneralHelper.IsNotNull(currentResourceType)) { // Set the optional components @@ -1107,6 +1141,9 @@ private void ResetForm(bool clearselection) { selectedResourceTypeCategory = String.Empty; + Array.Clear(selectedResourceTypeFull); + selectedResourceTypeShortName = String.Empty; + selectedResourceTypeDisplayName = String.Empty; selectedResourceType = String.Empty; componentsVisible = "collapse show"; currentResourceType = null; diff --git a/src/Services/ResourceNamingRequestService.cs b/src/Services/ResourceNamingRequestService.cs index 6b5405e..0ad35d3 100644 --- a/src/Services/ResourceNamingRequestService.cs +++ b/src/Services/ResourceNamingRequestService.cs @@ -747,6 +747,13 @@ public static async Task RequestName(ResourceNameRequest r ResourceTypeName = resourceType.Resource, User = request.CreatedBy }; + + // Check if the property should be appended to name + if(!String.IsNullOrEmpty(resourceType.Property)) + { + generatedName.ResourceTypeName += " - " + resourceType.Property; + } + ServiceResponse responseGenerateName = await GeneratedNamesService.PostItem(generatedName); if (responseGenerateName.Success) {