Use display name for type column in scripts table

This commit is contained in:
Pat Hartl 2023-08-02 17:49:47 -05:00
parent 7aabecb882
commit 6df312ef2b
3 changed files with 27 additions and 2 deletions

View file

@ -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
}
}

View file

@ -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<DisplayAttribute>()?
.GetName() ?? value.ToString();
}
}
}

View file

@ -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 @@
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
<SpaceItem>
<Table TItem="Script" DataSource="@Scripts" HidePagination="true">
<PropertyColumn Property="s => s.Type" />
<PropertyColumn Property="s => s.Type">@context.Type.GetDisplayName()</PropertyColumn>
<PropertyColumn Property="s => s.CreatedBy">
@context.CreatedBy?.UserName
</PropertyColumn>