refactor: simplify export metadata construction

This commit is contained in:
Gary Sharp
2025-02-07 16:10:15 +11:00
parent 67f1c2a5d1
commit 2fce645066
30 changed files with 1432 additions and 1484 deletions
+2 -1
View File
@@ -49,8 +49,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BI\Config\OrganisationAddress.cs" />
<Compile Include="Exporting\ExportFieldMetadata.cs" />
<Compile Include="Exporting\ExportMetadataField.cs" />
<Compile Include="Exporting\ExportFormat.cs" />
<Compile Include="Exporting\ExportMetadata.cs" />
<Compile Include="Exporting\IExportRecord.cs" />
<Compile Include="Repository\Device\Flag\DeviceFlag.cs" />
<Compile Include="Repository\Device\Flag\DeviceFlagAssignment.cs" />
@@ -1,27 +0,0 @@
using System;
namespace Disco.Models.Exporting
{
public class ExportFieldMetadata<T> where T : IExportRecord
{
public string Name { get; set; }
public string ColumnName { get; set; }
public Type ValueType { get; set; }
public Func<T, object> Accessor { get; set; }
public Func<object, string> CsvEncoder { get; set; }
public ExportFieldMetadata(string name, Type valueType, Func<T, object> accessor, Func<object, string> csvEncoder)
{
Name = name;
ValueType = valueType;
Accessor = accessor;
CsvEncoder = csvEncoder;
}
public ExportFieldMetadata(string name, string columnName, Type valueType, Func<T, object> accessor, Func<object, string> csvEncoder)
: this(name, valueType, accessor, csvEncoder)
{
ColumnName = columnName;
}
}
}
+10
View File
@@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace Disco.Models.Exporting
{
public class ExportMetadata<T>
: List<ExportMetadataField<T>> where T : IExportRecord
{
public List<string> IgnoreShortNames { get; } = new List<string>();
}
}
@@ -0,0 +1,20 @@
using System;
namespace Disco.Models.Exporting
{
public class ExportMetadataField<T> where T : IExportRecord
{
public string ColumnName { get; }
public Type ValueType { get; }
public Func<T, object> Accessor { get; }
public Func<object, string> CsvEncoder { get; }
public ExportMetadataField(string columnName, Type valueType, Func<T, object> accessor, Func<object, string> csvEncoder)
{
ColumnName = columnName;
ValueType = valueType;
Accessor = accessor;
CsvEncoder = csvEncoder;
}
}
}
@@ -56,6 +56,8 @@ namespace Disco.Models.Services.Users.UserFlags
public bool UserEmailAddress { get; set; }
[Display(ShortName = "User", Name = "Custom Details", Description = "The custom details provided by plugins for the user assigned to the user flag")]
public bool UserDetailCustom { get; set; }
public bool HasAssignedUserDetails()
=> UserDisplayName || UserSurname || UserGivenName || UserPhoneNumber || UserEmailAddress || UserDetailCustom;
public static UserFlagExportOptions DefaultOptions()
{