Skip to content

Commit

Permalink
Merge pull request #45 from BryanSoltis/main
Browse files Browse the repository at this point in the history
v3.2.0 Updates

### FEATURES
- Added ability to add custom locations
- Added guidance to Configuration page for locations
- Added Generate Random Value functionality for custom components
- Added Custom Component API functions for retrieving/deleting by parent component id
- Added new Azure regions to Locations

### BUG FIXES
- Updated Configuration to properly close Working modal
- Updated Global Export/Import to include ReadOnlyAPI key
- Fixed #29. Updated Azure regions
- Fixed #39. Updated Generate page to properly handle optional free text components
- Updated text on Add / Edit modals
- Updated GitHub Action to remove Azure Credentials requirement (This is included in the App Service Publish Profile)

### CONTRIBUTORS
- [wipash](https://github.com/wipash)
  • Loading branch information
BryanSoltis authored Nov 17, 2023
2 parents eef10fe + a8b1397 commit ff98584
Show file tree
Hide file tree
Showing 20 changed files with 911 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ jobs:
env:
azure-webapp-name: ${{ secrets.AZURE_WEBAPP_NAME }}
azure-webapp-publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
if: (env.azure-webapp-name != null && env.azure-webapp-publish-profile != null && env.azure-credentials != null)
if: (env.azure-webapp-name != null && env.azure-webapp-publish-profile != null)
run: echo 'isvalid=true' >> $GITHUB_OUTPUT

build:
Expand Down Expand Up @@ -104,11 +103,6 @@ jobs:
uses: actions/download-artifact@v3
with:
name: .net-app

- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Deploy to Azure Web App
id: deploy-to-webapp
Expand Down
2 changes: 1 addition & 1 deletion src/AzureNamingTool.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Version>3.1.1</Version>
<Version>3.2.0</Version>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
75 changes: 73 additions & 2 deletions src/Controllers/CustomComponentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,38 @@ public async Task<IActionResult> Get()

// GET api/<CustomComponentsController>/sample
/// <summary>
/// This function will return the custom components data for the specifc parent component type.
/// This function will return the custom components data for the specifc parent component id.
/// </summary>
/// <param name="parentcomponentid">int - Parent Component Id</param>
/// <returns>json - Current custom components data</returns>
[Route("[action]/{parentcomponentid}")]
[HttpGet]
public async Task<IActionResult> GetByParentComponentId(int parentcomponentid)
{
ServiceResponse serviceResponse = new();
try
{
// Get list of items
serviceResponse = await CustomComponentService.GetItemsByParentComponentId(parentcomponentid);
if (serviceResponse.Success)
{
return Ok(serviceResponse.ResponseObject);
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
catch (Exception ex)
{
AdminLogService.PostItem(new AdminLogMessage() { Title = "ERROR", Message = ex.Message });
return BadRequest(ex);
}
}

// GET api/<CustomComponentsController>/sample
/// <summary>
/// This function will return the custom components data for the specifc parent component type (name).
/// </summary>
/// <param name="parenttype">string - Parent Component Type Name</param>
/// <returns>json - Current custom components data</returns>
Expand Down Expand Up @@ -284,7 +315,7 @@ public async Task<IActionResult> Delete(int id)
if (serviceResponse.Success)
{
AdminLogService.PostItem(new AdminLogMessage() { Source = "API", Title = "INFORMATION", Message = "Custom Component (" + item.Name + ") deleted." });
CacheHelper.InvalidateCacheObject("GeneratedName");
CacheHelper.InvalidateCacheObject("CustomComponent");
return Ok("Custom Component (" + item.Name + ") deleted.");
}
else
Expand All @@ -303,5 +334,45 @@ public async Task<IActionResult> Delete(int id)
return BadRequest(ex);
}
}
// DELETE api/<CustomComponentsController>/5
/// <summary>
/// This function will delete the custom component data for the specifed parent component id.
/// </summary>
/// <param name="parentcomponentid">int - Parent component id</param>
/// <returns>bool - PASS/FAIL</returns>
[HttpDelete("[action]/{parentcomponentid}")]
public async Task<IActionResult> DeleteByParentComponentId(int parentcomponentid)
{
ServiceResponse serviceResponse = new();
try
{
// Get the item details
serviceResponse = await ResourceComponentService.GetItem(parentcomponentid);
if (serviceResponse.Success)
{
var component = (ResourceComponent)serviceResponse.ResponseObject!;
serviceResponse = await CustomComponentService.DeleteByParentComponentId(parentcomponentid);
if (serviceResponse.Success)
{
AdminLogService.PostItem(new AdminLogMessage() { Source = "API", Title = "INFORMATION", Message = "Custom Component data for component (" + component.Name + ") deleted." });
CacheHelper.InvalidateCacheObject("CustomComponent");
return Ok("Custom Component data for component (" + component.Name + ") deleted.");
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
catch (Exception ex)
{
AdminLogService.PostItem(new AdminLogMessage() { Title = "ERROR", Message = ex.Message });
return BadRequest(ex);
}
}
}
}
29 changes: 27 additions & 2 deletions src/Helpers/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,31 @@ public static void ResetState(StateContainer state)
state.SetAppTheme("bg-default text-dark");
}

public static string GetAssemblyVersion()
{
string result = String.Empty;
try
{
string data = (string)CacheHelper.GetCacheObject("assemblyversion")!;
if (String.IsNullOrEmpty(data))
{
Version version = Assembly.GetExecutingAssembly().GetName().Version!;
result = version.Major + "." + version.Minor + "." + version.Revision;
CacheHelper.SetCacheObject("assemblyversion", result);
}
else
{
result = data;
}
return result;
}
catch (Exception ex)
{
AdminLogService.PostItem(new AdminLogMessage() { Title = "ERROR", Message = ex.Message });
}
return result;
}

public static async Task<string?> GetToolVersion()
{
try
Expand All @@ -588,7 +613,7 @@ public static async Task<string> GetVersionAlert(bool forceDisplay = false)
{
VersionAlert versionalert = new();
bool dismissed = false;
string appversion = Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
string appversion = GetAssemblyVersion();

// Check if version alert has been dismissed
var dismissedalerts = GetAppSetting("DismissedAlerts").Split(',');
Expand Down Expand Up @@ -645,7 +670,7 @@ public static void DismissVersionAlert()
{
try
{
string appversion = Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
string appversion = GetAssemblyVersion();
List<string> dismissedalerts = new(GetAppSetting("DismissedAlerts").Split(','));
if (!dismissedalerts.Contains(appversion))
{
Expand Down
23 changes: 22 additions & 1 deletion src/Helpers/GeneralHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AzureNamingTool.Shared;
using Blazored.Modal;
using Blazored.Modal.Services;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Security.Cryptography;
Expand Down Expand Up @@ -121,7 +122,6 @@ public static string SetTextEnabledClass(bool enabled)

public static bool IsNotNull([NotNullWhen(true)] object? obj) => obj != null;


public static string[] FormatResoureType(string type)
{
String[] returntype = new String[4];
Expand Down Expand Up @@ -161,5 +161,26 @@ public static string[] FormatResoureType(string type)
}
return returntype;
}

public static string GenerateRandomString(int maxLength, bool alphanumeric)
{
var chars = "abcdefghijklmnopqrstuvwxyz";
if (alphanumeric)
{
chars = "abcdefghijklmnopqrstuvwxyz0123456789";
}

var Charsarr = new char[maxLength];
var random = new Random();

for (int i = 0; i < Charsarr.Length; i++)
{
Charsarr[i] = chars[random.Next(chars.Length)];
}

var result = new String(Charsarr);

return result;
}
}
}
2 changes: 2 additions & 0 deletions src/Models/ResourceComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public class ResourceComponent
public bool IsFreeText { get; set; } = false;
public string MinLength { get; set; } = "1";
public string MaxLength { get; set; } = "10";
public bool EnforceRandom { get; set; } = false;
public bool Alphanumeric { get; set; } = true;
}
}
10 changes: 3 additions & 7 deletions src/Pages/Admin.razor
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,8 @@
currentuser = await IdentityHelper.GetCurrentUser(session);
if (firstRender)
{
// Get the version
if (GeneralHelper.IsNotNull(Assembly.GetEntryAssembly()))
{
appversion = Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
releasenotesurl = "https://github.com/mspnp/AzureNamingTool/wiki/v" + appversion;
}
appversion = ConfigurationHelper.GetAssemblyVersion();
releasenotesurl = "https://github.com/mspnp/AzureNamingTool/wiki/v" + appversion;

servicesData = await ServicesHelper.LoadServicesData(servicesData, true);
var result = await session.GetAsync<bool>("admin");
Expand Down Expand Up @@ -1031,4 +1027,4 @@
await JsRuntime.InvokeVoidAsync("open", issueURL, "_blank");
}
}
}
}
73 changes: 37 additions & 36 deletions src/Pages/Configuration.razor
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,14 @@
</div>
<div class="card card-body @theme.ThemeStyle">
<p>The current Locations.</p>
@if (admin)
{
<p>
<button type="button" class="btn btn-success" @onclick="@(e => FormAction("ResourceLocation",0,"add"))" title="Add Location">
<span class="oi oi-plus" aria-hidden="true"></span> Add Location
</button>
</p>
}
<div class="table-responsive">
<table class="table @theme.ThemeStyle">
<thead>
Expand Down Expand Up @@ -943,6 +951,10 @@
<span class="oi oi-plus" aria-hidden="true"></span>
</button>
}
<span> </span>
<button type="button" class="btn btn-danger" @onclick="@(e => FormAction("ResourceLocation",item.Id,"delete"))" title="Delete">
<span class="oi oi-x" aria-hidden="true"></span>
</button>
}
</td>
}
Expand All @@ -955,37 +967,6 @@
</div>
@if (admin)
{
@* <div class="card">
<div class="card card-header bg-default" style="font-weight:bold;">
New Location
</div>
<div class="card card-body">
<p>Add a new Location.</p>
<table class="table table-striped">
<tbody>
<tr>
<td>Name</td>
<td>
<input class="form-control" type="text" value="@newLocationName" @onchange="@((ui) => { SetFormValue("newLocationName",(string)ui.Value);})" />
</td>
</tr>
<tr>
<td>Short Name</td>
<td>
<input class="form-control" type="text" value="@newLocationShortName" @onchange="@((ui) => { SetFormValue("newLocationShortName",(string)ui.Value);})" />
</td>
</tr>
<tr>
<td colspan="2">
<button type="button" class="btn btn-success" @onclick="@(e => FormAction("ResourceLocation",0,"add"))" title="Add">
<span class="oi oi-plus" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>*@
<div class="card mb-3">
<div class="card-header bg-default text-dark">
<a class="text-decoration-none text-dark" data-bs-toggle="collapse" style="display:block;font-weight:bold;" href="#locationsconfig" role="button" aria-expanded="false" aria-controls="locationsconfig">
Expand Down Expand Up @@ -1035,6 +1016,12 @@
</li>
}
</ul>
<div class="alert alert-warning" role="alert">
<div>
<span class="fw-bold">NOTE</span><br />
This action may result in duplicate locations if you have added a custom location that matches the incoming values.
</div>
</div>
</p>
<p>
<button type="button" class="btn btn-success" @onclick=@(e => FormAction("ResourceLocation",0,"refresh")) title="Refresh">
Expand Down Expand Up @@ -1895,7 +1882,7 @@
private bool versionalertshown = false;
private bool dismissalert = false;
private bool configurationfilealertshown = false;
private string appversion = Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
private string appversion = ConfigurationHelper.GetAssemblyVersion();

public string filterData { get; set; } = String.Empty;

Expand Down Expand Up @@ -2813,6 +2800,22 @@
generalerror = true;
}
break;
case "add":
if (GeneralHelper.IsNotNull(thisresourceComponent))
{
response = await ModalHelper.ShowAddModal(Modal!, servicesData, theme, "bg-navcolor", "Add Location", "<p>Add a Location.</p><p><span class=\"fw-bold\">NOTES</span></p><ul><li>Short Name value will be converted to lower case.</li><li>Short Name must be " + thisresourceComponent.MinLength + "-" + thisresourceComponent.MaxLength + " characters.</li></ul>", (int)id, "ResourceLocation", admin, "");
if (response)
{
servicesData = await ServicesHelper.LoadServicesData(servicesData, admin);
state.SetNavReload(true);
StateHasChanged();
}
}
else
{
generalerror = true;
}
break;
case "delete":
confirm = await ModalHelper.ShowConfirmationModal(Modal!, "ATTENTION", "<div class=\"my-4\">This will delete the Location and cannot be undone!</div><div class=\"my-4\">Are you sure?</div>", "bg-danger", theme);
if (confirm)
Expand Down Expand Up @@ -3974,10 +3977,8 @@
message.Type = MessageTypesEnum.ERROR;
message.Message = "There was a problem with the request.";
}
finally
{
workingmodal.Close();
}

workingmodal.Close();
}

if (!generalerror)
Expand Down
Loading

0 comments on commit ff98584

Please sign in to comment.