Skip to content

Commit

Permalink
- Fixed Issue #2
Browse files Browse the repository at this point in the history
- Updated Generate page to properly set selected resource type
- Updated Generate Name logging to include full resource type name
  • Loading branch information
BryanSoltis committed Aug 16, 2023
1 parent 71feeb6 commit 2cc2fe1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 18 deletions.
32 changes: 22 additions & 10 deletions src/Helpers/GeneralHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
53 changes: 45 additions & 8 deletions src/Pages/Generate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<span class="input-group-text" id="addon-wrapping">
<span class="oi oi-magnifying-glass" id="addon-wrapping"></span>
</span>
<input @bind-value="@selectedResourceType" @oninput="(EventArgs) => { OnTypeChanged(EventArgs.Value!.ToString()!);}" class="@GetControlStyle()" list="typeslist" id="generatetypes" placeholder="Type to search resource types..." autocomplete="off">
<input @bind-value="@selectedResourceTypeDisplayName" @oninput="(EventArgs) => { OnTypeChanged(EventArgs.Value!.ToString()!);}" class="@GetControlStyle()" list="typeslist" id="generatetypes" placeholder="Type to search resource types..." autocomplete="off">
<datalist id="typeslist">
@foreach (var type in @ResourceTypeService.GetFilteredResourceTypes(servicesData.ResourceTypes, selectedResourceTypeCategory))
{
Expand Down Expand Up @@ -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<string, string> selectedCustomComponents = new();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/Services/ResourceNamingRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ public static async Task<ResourceNameResponse> 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)
{
Expand Down

0 comments on commit 2cc2fe1

Please sign in to comment.