From 6df312ef2bdaddcee32d5576838e87a970cb2dd5 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Wed, 2 Aug 2023 17:49:47 -0500 Subject: [PATCH] Use display name for type column in scripts table --- LANCommander/Data/Enums/ScriptType.cs | 8 +++++++- LANCommander/Extensions/EnumExtensions.cs | 18 ++++++++++++++++++ .../Pages/Games/Components/ScriptEditor.razor | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 LANCommander/Extensions/EnumExtensions.cs diff --git a/LANCommander/Data/Enums/ScriptType.cs b/LANCommander/Data/Enums/ScriptType.cs index e183dfe..095d348 100644 --- a/LANCommander/Data/Enums/ScriptType.cs +++ b/LANCommander/Data/Enums/ScriptType.cs @@ -1,12 +1,18 @@ -namespace LANCommander.Data.Enums +using System.ComponentModel.DataAnnotations; + +namespace LANCommander.Data.Enums { public enum ScriptType { Install, Uninstall, + [Display(Name = "Name Change")] NameChange, + [Display(Name = "Key Change")] KeyChange, + [Display(Name = "Save Upload")] SaveUpload, + [Display(Name = "Save Download")] SaveDownload } } diff --git a/LANCommander/Extensions/EnumExtensions.cs b/LANCommander/Extensions/EnumExtensions.cs new file mode 100644 index 0000000..213ffb4 --- /dev/null +++ b/LANCommander/Extensions/EnumExtensions.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using System.Reflection; + +namespace LANCommander.Extensions +{ + public static class EnumExtensions + { + public static string GetDisplayName(this Enum value) + { + return value + .GetType() + .GetMember(value.ToString()) + .First() + .GetCustomAttribute()? + .GetName() ?? value.ToString(); + } + } +} diff --git a/LANCommander/Pages/Games/Components/ScriptEditor.razor b/LANCommander/Pages/Games/Components/ScriptEditor.razor index b935d02..ea7e28a 100644 --- a/LANCommander/Pages/Games/Components/ScriptEditor.razor +++ b/LANCommander/Pages/Games/Components/ScriptEditor.razor @@ -1,4 +1,5 @@ @using LANCommander.Data.Enums; +@using LANCommander.Extensions; @using LANCommander.Models @using LANCommander.Services @using System.IO.Compression; @@ -68,7 +69,7 @@ - + @context.Type.GetDisplayName() @context.CreatedBy?.UserName