feature: user details are individually exported; shared export field renderer
This commit is contained in:
@@ -171,21 +171,37 @@ namespace Disco.Services.Devices
|
||||
if (Options.DetailBatteries)
|
||||
r.DeviceDetailBatteries = r.DeviceDetails.Batteries();
|
||||
|
||||
if (Options.AssignedUserDetailCustom && r.AssignedUser != null)
|
||||
{
|
||||
var detailsService = new DetailsProviderService(database);
|
||||
r.AssignedUserCustomDetails = detailsService.GetDetails(r.AssignedUser);
|
||||
}
|
||||
});
|
||||
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
AddUserCustomDetails(database, records, taskStatus);
|
||||
|
||||
return records;
|
||||
}
|
||||
|
||||
private static void AddUserCustomDetails(DiscoDataContext database, List<DeviceExportRecord> records, IScheduledTaskStatus status)
|
||||
{
|
||||
if (!records.Any(r => r.AssignedUser != null))
|
||||
return;
|
||||
status.UpdateStatus(50, "Extracting custom user detail records");
|
||||
var detailsService = new DetailsProviderService(database);
|
||||
var cache = new Dictionary<string, Dictionary<string, string>>(StringComparer.Ordinal);
|
||||
foreach (var record in records)
|
||||
{
|
||||
var userId = record.AssignedUser?.UserId;
|
||||
if (string.IsNullOrWhiteSpace(userId))
|
||||
continue;
|
||||
if (!cache.TryGetValue(userId, out var details))
|
||||
details = detailsService.GetDetails(record.AssignedUser);
|
||||
record.AssignedUserCustomDetails = details;
|
||||
}
|
||||
}
|
||||
|
||||
public ExportMetadata<DeviceExportOptions, DeviceExportRecord> BuildMetadata(DiscoDataContext database, List<DeviceExportRecord> records, IScheduledTaskStatus taskStatus)
|
||||
{
|
||||
var metadata = new ExportMetadata<DeviceExportOptions, DeviceExportRecord>(Options);
|
||||
metadata.IgnoreShortNames.Add("Device");
|
||||
metadata.IgnoreShortNames.Add("Details");
|
||||
metadata.IgnoreGroupNames.Add("Device");
|
||||
metadata.IgnoreGroupNames.Add("Details");
|
||||
|
||||
// Device
|
||||
metadata.Add(o => o.DeviceSerialNumber, r => r.Device.SerialNumber);
|
||||
@@ -233,13 +249,10 @@ namespace Disco.Services.Devices
|
||||
metadata.Add(o => o.AssignedUserEmailAddress, r => r.AssignedUser?.EmailAddress);
|
||||
|
||||
// User Custom Details
|
||||
if (Options.AssignedUserDetailCustom)
|
||||
if (Options.UserDetailCustom.Any())
|
||||
{
|
||||
var keys = records.Where(r => r.AssignedUserCustomDetails != null).SelectMany(r => r.AssignedUserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
foreach (var key in keys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
metadata.Add(key, r => r.AssignedUserCustomDetails != null && r.AssignedUserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
foreach (var key in Options.UserDetailCustom.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
metadata.Add($"Assigned User Detail {key.TrimEnd('*', '&')}", r => r.AssignedUserCustomDetails != null && r.AssignedUserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
|
||||
// Jobs
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Disco.Services.Devices.DeviceFlags
|
||||
query = query.Include(a => a.Device.DeviceProfile);
|
||||
if (Options.HasAssignedUserOptions())
|
||||
query = query.Include(a => a.Device.AssignedUser);
|
||||
if (Options.AssignedUserDetailCustom)
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
query = query.Include(a => a.Device.AssignedUser.UserDetails);
|
||||
|
||||
query = query.Where(a => Options.DeviceFlagIds.Contains(a.DeviceFlagId));
|
||||
@@ -86,7 +86,7 @@ namespace Disco.Services.Devices.DeviceFlags
|
||||
Assignment = a
|
||||
}).ToList();
|
||||
|
||||
if (Options.AssignedUserDetailCustom)
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
{
|
||||
status.UpdateStatus(50, "Extracting custom user detail records");
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Disco.Services.Devices.DeviceFlags
|
||||
public ExportMetadata<DeviceFlagExportOptions, DeviceFlagExportRecord> BuildMetadata(DiscoDataContext database, List<DeviceFlagExportRecord> records, IScheduledTaskStatus status)
|
||||
{
|
||||
var metadata = new ExportMetadata<DeviceFlagExportOptions, DeviceFlagExportRecord>(Options);
|
||||
metadata.IgnoreShortNames.Add("Device Flag");
|
||||
metadata.IgnoreGroupNames.Add("Device Flag");
|
||||
|
||||
// Device Flag
|
||||
metadata.Add(o => o.Id, r => r.Assignment.DeviceFlagId);
|
||||
@@ -171,13 +171,10 @@ namespace Disco.Services.Devices.DeviceFlags
|
||||
metadata.Add(o => o.AssignedUserEmailAddress, r => r.Assignment.Device?.AssignedUser?.EmailAddress);
|
||||
|
||||
// User Custom Details
|
||||
if (Options.AssignedUserDetailCustom)
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
{
|
||||
var keys = records.Where(r => r.AssignedUserCustomDetails != null).SelectMany(r => r.AssignedUserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
foreach (var key in keys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
metadata.Add(key, r => r.AssignedUserCustomDetails != null && r.AssignedUserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
foreach (var key in Options.UserDetailCustom.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
metadata.Add($"Assigned User Detail {key.TrimEnd('*', '&')}", r => r.AssignedUserCustomDetails != null && r.AssignedUserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
|
||||
Reference in New Issue
Block a user