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;
|
||||
|
||||
@@ -4,14 +4,14 @@ using Disco.Models.Repository;
|
||||
using Disco.Models.Services.Documents;
|
||||
using Disco.Models.Services.Exporting;
|
||||
using Disco.Services.Exporting;
|
||||
using Disco.Services.Plugins.Features.DetailsProvider;
|
||||
using Disco.Services.Tasks;
|
||||
using Disco.Services.Users;
|
||||
using Newtonsoft.Json;
|
||||
using System.Data.Entity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using Disco.Services.Users;
|
||||
using Disco.Services.Plugins.Features.DetailsProvider;
|
||||
|
||||
namespace Disco.Services.Documents
|
||||
{
|
||||
@@ -110,12 +110,10 @@ namespace Disco.Services.Documents
|
||||
metadata.Add(o => o.UserEmailAddress, r => r.User?.EmailAddress);
|
||||
|
||||
// User Custom Details
|
||||
if (Options.UserDetailCustom.Any())
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
{
|
||||
foreach (var key in Options.UserDetailCustom.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
metadata.Add(key, r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
metadata.Add($"User Detail {key.TrimEnd('*', '&')}", r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
|
||||
@@ -139,10 +139,10 @@ namespace Disco.Services.Exporting
|
||||
var member = ((MemberExpression)optionAccessor.Body).Member;
|
||||
var attribute = (DisplayAttribute)member.GetCustomAttributes(typeof(DisplayAttribute), false).Single();
|
||||
|
||||
if (metadata.IgnoreShortNames.Contains(attribute.ShortName))
|
||||
if (metadata.IgnoreGroupNames.Contains(attribute.GroupName))
|
||||
columnName = attribute.Name;
|
||||
else
|
||||
columnName = $"{attribute.ShortName} {attribute.Name}";
|
||||
columnName = $"{attribute.GroupName} {attribute.Name}";
|
||||
}
|
||||
|
||||
metadata.Add(columnName, valueAccessor, csvValueEncoder);
|
||||
@@ -190,6 +190,8 @@ namespace Disco.Services.Exporting
|
||||
{ typeof(ushort?), ToStringEncoder },
|
||||
{ typeof(bool), ToStringEncoder },
|
||||
{ typeof(bool?), ToStringEncoder },
|
||||
{ typeof(Guid), ToStringEncoder },
|
||||
{ typeof(Guid?), ToStringEncoder },
|
||||
{ typeof(DateTime), DateTimeEncoder },
|
||||
{ typeof(DateTime?), NullableDateTimeEncoder },
|
||||
};
|
||||
|
||||
@@ -219,8 +219,8 @@ namespace Disco.Services.Jobs
|
||||
public ExportMetadata<JobExportOptions, JobExportRecord> BuildMetadata(DiscoDataContext database, List<JobExportRecord> records, IScheduledTaskStatus status)
|
||||
{
|
||||
var metadata = new ExportMetadata<JobExportOptions, JobExportRecord>(Options);
|
||||
metadata.IgnoreShortNames.Add("Job");
|
||||
metadata.IgnoreShortNames.Add("Job Details");
|
||||
metadata.IgnoreGroupNames.Add("Job");
|
||||
metadata.IgnoreGroupNames.Add("Job Details");
|
||||
|
||||
// Job
|
||||
metadata.Add(o => o.JobId, r => r.Job.Id);
|
||||
|
||||
@@ -7,12 +7,12 @@ namespace Disco.Services.Plugins.Features.ExportProvider
|
||||
[PluginFeatureCategory(DisplayName = "Exporter")]
|
||||
public class ExportProviderFeature : PluginFeature
|
||||
{
|
||||
public void RegisterExportType<T, E, R>()
|
||||
where T : IExport<E, R>, new()
|
||||
where E : IExportOptions, new()
|
||||
public void RegisterExportType<T, O, R>()
|
||||
where T : IExport<O, R>, new()
|
||||
where O : IExportOptions, new()
|
||||
where R : IExportRecord
|
||||
{
|
||||
SavedExports.RegisterExportType<T, E, R>();
|
||||
SavedExports.RegisterExportType<T, O, R>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Disco.Services.Users.UserFlags
|
||||
Assignment = a
|
||||
}).ToList();
|
||||
|
||||
if (Options.UserDetailCustom)
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
{
|
||||
status.UpdateStatus(50, "Extracting custom user detail records");
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace Disco.Services.Users.UserFlags
|
||||
status.UpdateStatus(80, "Building metadata");
|
||||
|
||||
var metadata = new ExportMetadata<UserFlagExportOptions, UserFlagExportRecord>(Options);
|
||||
metadata.IgnoreShortNames.Add("User Flag");
|
||||
metadata.IgnoreGroupNames.Add("User Flag");
|
||||
|
||||
// User Flag
|
||||
metadata.Add(o => o.Id, r => r.Assignment.UserFlagId);
|
||||
@@ -120,13 +120,10 @@ namespace Disco.Services.Users.UserFlags
|
||||
metadata.Add(o => o.UserEmailAddress, r => r.Assignment.User?.EmailAddress);
|
||||
|
||||
// User Custom Details
|
||||
if (Options.UserDetailCustom)
|
||||
if (Options.UserDetailCustom?.Any() ?? false)
|
||||
{
|
||||
var keys = records.Where(r => r.UserCustomDetails != null).SelectMany(r => r.UserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
foreach (var key in keys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
metadata.Add(key, r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
foreach (var key in Options.UserDetailCustom.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
metadata.Add($"User Detail {key.TrimEnd('*', '&')}", r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
|
||||
Reference in New Issue
Block a user