feature: user flag assignment exporting

This commit is contained in:
Gary Sharp
2023-11-11 20:04:52 +11:00
parent 143dc1b3e6
commit 53e57d4017
25 changed files with 1790 additions and 183 deletions
+3
View File
@@ -158,6 +158,8 @@
<Compile Include="Services\Searching\ISearchResultItem.cs" />
<Compile Include="Services\Searching\JobSearchResultItem.cs" />
<Compile Include="Services\Searching\UserSearchResultItem.cs" />
<Compile Include="Services\Users\UserFlags\UserFlagExportOptions.cs" />
<Compile Include="Services\Users\UserFlags\UserFlagExportRecord.cs" />
<Compile Include="UI\BaseUIModel.cs" />
<Compile Include="UI\Config\AuthorizationRole\ConfigAuthorizationRoleCreateModel.cs" />
<Compile Include="UI\Config\AuthorizationRole\ConfigAuthorizationRoleIndexModel.cs" />
@@ -199,6 +201,7 @@
<Compile Include="UI\Config\UserFlag\ConfigUserFlagCreateModel.cs" />
<Compile Include="UI\Config\UserFlag\ConfigUserFlagIndexModel.cs" />
<Compile Include="UI\Config\UserFlag\ConfigUserFlagShowModel.cs" />
<Compile Include="UI\Config\UserFlag\ConfigUserFlagExportModel.cs" />
<Compile Include="UI\Device\DeviceAddOfflineModel.cs" />
<Compile Include="UI\Device\DeviceExportModel.cs" />
<Compile Include="UI\Device\DeviceImportHeadersModel.cs" />
@@ -0,0 +1,77 @@
using Disco.Models.Exporting;
using Disco.Models.Services.Devices.Exporting;
using Disco.Models.Services.Exporting;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Disco.Models.Services.Users.UserFlags
{
public class UserFlagExportOptions : IExportOptions
{
public ExportFormat Format { get; set; }
public string FilenamePrefix { get; } = "DiscoUserFlagExport";
public string ExcelWorksheetName { get; } = "UserFlagExport";
public string ExcelTableName { get; } = "UserFlags";
[Required]
public List<int> UserFlagIds { get; set; } = new List<int>();
[DisplayAttribute(Name = "Current Only")]
public bool CurrentOnly { get; set; }
// User Flag
[Display(ShortName = "User Flag", Name = "Identifier", Description = "The identifier of the user flag")]
public bool Id { get; set; }
[Display(ShortName = "User Flag", Name = "Name", Description = "The name of the user flag")]
public bool Name { get; set; }
[Display(ShortName = "User Flag", Name = "Description", Description = "The description of the user flag")]
public bool Description { get; set; }
[Display(ShortName = "User Flag", Name = "Icon", Description = "The icon assigned to the user flag")]
public bool Icon { get; set; }
[Display(ShortName = "User Flag", Name = "Icon Colour", Description = "The icon colour assigned to the user flag")]
public bool IconColour { get; set; }
[Display(ShortName = "User Flag", Name = "Assignment Identifier", Description = "The identifier of the user flag assignment")]
public bool AssignmentId { get; set; }
[Display(ShortName = "User Flag", Name = "Added Date", Description = "The date the user flag was assigned to the user")]
public bool AddedDate { get; set; }
[Display(ShortName = "User Flag", Name = "Added User Identifier", Description = "The identifier of the user who assigned the user flag")]
public bool AddedUserId { get; set; }
[Display(ShortName = "User Flag", Name = "Removed Date", Description = "The date the user flag was unassigned from the user")]
public bool RemovedDate { get; set; }
[Display(ShortName = "User Flag", Name = "Removed User Identifier", Description = "The identifier of the user who unassigned the user flag")]
public bool RemovedUserId { get; set; }
[Display(ShortName = "User Flag", Name = "Comments", Description = "The comments associated with the user flag assignment")]
public bool Comments { get; set; }
// User
[Display(ShortName = "User", Name = "Identifier", Description = "The identifier of the user assigned to the user flag")]
public bool UserId { get; set; }
[Display(ShortName = "User", Name = "Display Name", Description = "The display name of the user assigned to the user flag")]
public bool UserDisplayName { get; set; }
[Display(ShortName = "User", Name = "Surname", Description = "The surname of the user assigned to the user flag")]
public bool UserSurname { get; set; }
[Display(ShortName = "User", Name = "Given Name", Description = "The given name of the user assigned to the user flag")]
public bool UserGivenName { get; set; }
[Display(ShortName = "User", Name = "Phone Number", Description = "The phone number of the user assigned to the user flag")]
public bool UserPhoneNumber { get; set; }
[Display(ShortName = "User", Name = "Email Address", Description = "The email address of the user assigned to the user flag")]
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 static UserFlagExportOptions DefaultOptions()
{
return new UserFlagExportOptions()
{
Format = ExportFormat.Xlsx,
CurrentOnly = true,
Name = true,
AddedDate = true,
UserId = true,
UserDisplayName = true,
Comments = true,
};
}
}
}
@@ -0,0 +1,12 @@
using Disco.Models.Exporting;
using Disco.Models.Repository;
using System.Collections.Generic;
namespace Disco.Models.Services.Users.UserFlags
{
public class UserFlagExportRecord : IExportRecord
{
public UserFlagAssignment Assignment { get; set; }
public Dictionary<string, string> UserCustomDetails { get; set; }
}
}
@@ -0,0 +1,17 @@
using Disco.Models.Services.Exporting;
using Disco.Models.Services.Users.UserFlags;
using Disco.Models.UI;
using System.Collections.Generic;
namespace Disco.Models.Areas.Config.UI.UserFlag
{
public interface ConfigUserFlagExportModel : BaseUIModel
{
UserFlagExportOptions Options { get; set; }
string ExportSessionId { get; set; }
ExportResult ExportSessionResult { get; set; }
List<Repository.UserFlag> UserFlags { get; set; }
}
}
+8
View File
@@ -77,6 +77,7 @@ namespace Disco.Services.Authorization
{ "Config.UserFlag.Configure", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Configure, (c, v) => c.Config.UserFlag.Configure = v, "Configure User Flags", "Can configure user flags", false) },
{ "Config.UserFlag.Create", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Create, (c, v) => c.Config.UserFlag.Create = v, "Create User Flags", "Can create user flags", false) },
{ "Config.UserFlag.Delete", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Delete, (c, v) => c.Config.UserFlag.Delete = v, "Delete User Flags", "Can delete user flags", false) },
{ "Config.UserFlag.Export", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Export, (c, v) => c.Config.UserFlag.Export = v, "Export User Flag Assignments", "Can export user flag assignments", false) },
{ "Config.UserFlag.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.UserFlag.Show, (c, v) => c.Config.UserFlag.Show = v, "Show User Flags", "Can show user flags", false) },
{ "Config.Show", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Config.Show, (c, v) => c.Config.Show = v, "Show Configuration", "Can show the configuration menu", false) },
{ "Job.Lists.AllOpen", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.AllOpen, (c, v) => c.Job.Lists.AllOpen = v, "All Open List", "Can show list", false) },
@@ -306,6 +307,7 @@ namespace Disco.Services.Authorization
new ClaimNavigatorItem("Config.UserFlag.Configure", false),
new ClaimNavigatorItem("Config.UserFlag.Create", false),
new ClaimNavigatorItem("Config.UserFlag.Delete", false),
new ClaimNavigatorItem("Config.UserFlag.Export", false),
new ClaimNavigatorItem("Config.UserFlag.Show", false)
}),
new ClaimNavigatorItem("Config.Show", false)
@@ -593,6 +595,7 @@ namespace Disco.Services.Authorization
c.Config.UserFlag.Configure = true;
c.Config.UserFlag.Create = true;
c.Config.UserFlag.Delete = true;
c.Config.UserFlag.Export = true;
c.Config.UserFlag.Show = true;
c.Config.Show = true;
c.Job.Lists.AllOpen = true;
@@ -1109,6 +1112,11 @@ namespace Disco.Services.Authorization
/// </summary>
public const string Delete = "Config.UserFlag.Delete";
/// <summary>Export User Flag Assignments
/// <para>Can export user flag assignments</para>
/// </summary>
public const string Export = "Config.UserFlag.Export";
/// <summary>Show User Flags
/// <para>Can show user flags</para>
/// </summary>
@@ -11,6 +11,8 @@
[ClaimDetails("Delete User Flags", "Can delete user flags")]
public bool Delete { get; set; }
[ClaimDetails("Export User Flag Assignments", "Can export user flag assignments")]
public bool Export { get; set; }
[ClaimDetails("Show User Flags", "Can show user flags")]
public bool Show { get; set; }
+2
View File
@@ -461,6 +461,8 @@
<Compile Include="Users\Contact\UserContactService.cs" />
<Compile Include="Users\UserExtensions.cs" />
<Compile Include="Users\UserFlags\Cache.cs" />
<Compile Include="Users\UserFlags\UserFlagExport.cs" />
<Compile Include="Users\UserFlags\UserFlagExportTask.cs" />
<Compile Include="Users\UserFlags\UserFlagExtensions.cs" />
<Compile Include="Users\UserFlags\UserFlagUserDevicesManagedGroup.cs" />
<Compile Include="Users\UserFlags\UserFlagUsersManagedGroup.cs" />
@@ -0,0 +1,176 @@
using Disco.Data.Repository;
using Disco.Models.Exporting;
using Disco.Models.Services.Exporting;
using Disco.Models.Services.Users.UserFlags;
using Disco.Services.Plugins.Features.DetailsProvider;
using Disco.Services.Tasks;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
namespace Disco.Services.Users.UserFlags
{
using Metadata = ExportFieldMetadata<UserFlagExportRecord>;
public class UserFlagExport
{
private readonly DiscoDataContext database;
private readonly UserFlagExportOptions options;
public UserFlagExport(DiscoDataContext database, UserFlagExportOptions options)
{
this.database = database;
this.options = options;
}
public ExportResult Generate(IScheduledTaskStatus status)
{
var records = BuildRecords(status);
var metadata = BuildMetadata(records, status);
if (metadata.Count == 0)
throw new ArgumentException("At least one export field must be specified", nameof(options));
status.UpdateStatus(90, $"Formatting {records.Count} records for export");
return ExportHelpers.WriteExport(options, status, metadata, records);
}
private List<UserFlagExportRecord> BuildRecords(IScheduledTaskStatus status)
{
var query = database.UserFlagAssignments
.Include(a => a.User.UserDetails)
.Include(a => a.UserFlag)
.Where(a => options.UserFlagIds.Contains(a.UserFlagId));
if (options.CurrentOnly)
{
query = query.Where(a => !a.RemovedDate.HasValue);
}
// Update Users
if (options.UserDisplayName ||
options.UserSurname ||
options.UserGivenName ||
options.UserPhoneNumber ||
options.UserEmailAddress)
{
status.UpdateStatus(5, "Refreshing user details from Active Directory");
var userIds = query.Select(d => d.UserId).Distinct().ToList();
foreach (var userId in userIds)
{
try
{
UserService.GetUser(userId, database);
}
catch (Exception) { } // Ignore Errors
}
}
status.UpdateStatus(15, "Extracting records from the database");
var records = query.Select(a => new UserFlagExportRecord()
{
Assignment = a
}).ToList();
if (options.UserDetailCustom)
{
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)
{
if (!cache.TryGetValue(record.Assignment.UserId, out var details))
details = detailsService.GetDetails(record.Assignment.User);
record.UserCustomDetails = details;
}
}
return records;
}
private List<Metadata> BuildMetadata(List<UserFlagExportRecord> records, IScheduledTaskStatus status)
{
status.UpdateStatus(80, "Building metadata");
IEnumerable<string> userDetailCustomKeys = null;
if (options.UserDetailCustom)
userDetailCustomKeys = records.Where(r => r.UserCustomDetails != null).SelectMany(r => r.UserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
var accessors = BuildAccessors(userDetailCustomKeys);
return typeof(UserFlagExportOptions).GetProperties()
.Where(p => p.PropertyType == typeof(bool))
.Select(p => new
{
property = p,
details = (DisplayAttribute)p.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()
})
.Where(p => p.details != null && p.property.Name != nameof(options.CurrentOnly) && (bool)p.property.GetValue(options))
.SelectMany(p =>
{
var fieldMetadata = accessors[p.property.Name];
fieldMetadata.ForEach(f =>
{
if (f.ColumnName == null)
f.ColumnName = (p.details.ShortName == "User Flag") ? p.details.Name : $"{p.details.ShortName} {p.details.Name}";
});
return fieldMetadata;
}).ToList();
}
private static Dictionary<string, List<Metadata>> BuildAccessors(IEnumerable<string> userDetailsCustomKeys)
{
const string DateFormat = "yyyy-MM-dd";
const string DateTimeFormat = DateFormat + " HH:mm:ss";
Func<object, string> csvStringEncoded = (o) => o == null ? null : $"\"{((string)o).Replace("\"", "\"\"")}\"";
Func<object, string> csvToStringEncoded = (o) => o == null ? null : o.ToString();
Func<object, string> csvCurrencyEncoded = (o) => ((decimal?)o).HasValue ? ((decimal?)o).Value.ToString("C") : null;
Func<object, string> csvDateEncoded = (o) => ((DateTime)o).ToString(DateFormat);
Func<object, string> csvDateTimeEncoded = (o) => ((DateTime)o).ToString(DateTimeFormat);
Func<object, string> csvNullableDateEncoded = (o) => ((DateTime?)o).HasValue ? csvDateEncoded(o) : null;
Func<object, string> csvNullableDateTimeEncoded = (o) => ((DateTime?)o).HasValue ? csvDateTimeEncoded(o) : null;
var metadata = new Dictionary<string, List<Metadata>>();
// User Flag
metadata.Add(nameof(UserFlagExportOptions.Id), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.Id), typeof(string), r => r.Assignment.UserFlagId, csvToStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.Name), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.Name), typeof(string), r => r.Assignment.UserFlag.Name, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.Description), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.Description), typeof(string), r => r.Assignment.UserFlag.Description, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.Icon), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.Icon), typeof(string), r => r.Assignment.UserFlag.Icon, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.IconColour), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.IconColour), typeof(string), r => r.Assignment.UserFlag.IconColour, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.AssignmentId), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.AssignmentId), typeof(string), r => r.Assignment.Id, csvToStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.AddedDate), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.AddedDate), typeof(string), r => r.Assignment.AddedDate, csvDateTimeEncoded) });
metadata.Add(nameof(UserFlagExportOptions.AddedUserId), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.AddedUserId), typeof(string), r => r.Assignment.AddedUserId, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.RemovedUserId), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.RemovedUserId), typeof(string), r => r.Assignment.RemovedUserId, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.RemovedDate), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.RemovedDate), typeof(string), r => r.Assignment.RemovedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(UserFlagExportOptions.Comments), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.Comments), typeof(string), r => r.Assignment.Comments, csvStringEncoded) });
// User
metadata.Add(nameof(UserFlagExportOptions.UserId), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.UserId), typeof(string), r => r.Assignment.User?.UserId, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.UserDisplayName), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.UserDisplayName), typeof(string), r => r.Assignment.User?.DisplayName, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.UserSurname), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.UserSurname), typeof(string), r => r.Assignment.User?.Surname, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.UserGivenName), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.UserGivenName), typeof(string), r => r.Assignment.User?.GivenName, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.UserPhoneNumber), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.UserPhoneNumber), typeof(string), r => r.Assignment.User?.PhoneNumber, csvStringEncoded) });
metadata.Add(nameof(UserFlagExportOptions.UserEmailAddress), new List<Metadata>() { new Metadata(nameof(UserFlagExportOptions.UserEmailAddress), typeof(string), r => r.Assignment.User?.EmailAddress, csvStringEncoded) });
if (userDetailsCustomKeys != null)
{
var userDetailCustomFields = new List<Metadata>();
foreach (var detailKey in userDetailsCustomKeys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
{
var key = detailKey;
userDetailCustomFields.Add(new Metadata(detailKey, detailKey, typeof(string), r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null, csvStringEncoded));
}
metadata.Add(nameof(UserFlagExportOptions.UserDetailCustom), userDetailCustomFields);
}
return metadata;
}
}
}
@@ -0,0 +1,46 @@
using Disco.Data.Repository;
using Disco.Models.Services.Users.UserFlags;
using Disco.Services.Exporting;
using Disco.Services.Tasks;
using Quartz;
namespace Disco.Services.Users.UserFlags
{
public class UserFlagExportTask : ScheduledTask
{
private const string JobDataMapContext = "Context";
public override string TaskName { get; } = "Export User Flags";
public override bool SingleInstanceTask { get { return false; } }
public override bool CancelInitiallySupported { get { return false; } }
public static ExportTaskContext<UserFlagExportOptions> ScheduleNow(UserFlagExportOptions options)
{
// Build Context
var context = new ExportTaskContext<UserFlagExportOptions>(options);
// Build Data Map
var task = new UserFlagExportTask();
JobDataMap taskData = new JobDataMap() { { JobDataMapContext, context } };
// Schedule Task
context.TaskStatus = task.ScheduleTask(taskData);
return context;
}
protected override void ExecuteTask()
{
var context = (ExportTaskContext<UserFlagExportOptions>)ExecutionContext.JobDetail.JobDataMap[JobDataMapContext];
Status.UpdateStatus(10, "Exporting User Flag Records", "Starting...");
using (DiscoDataContext Database = new DiscoDataContext())
{
var export = new UserFlagExport(Database, context.Options);
context.Result = export.Generate(Status);
}
}
}
}
@@ -1,12 +1,18 @@
using Disco.Models.Repository;
using Disco.Models.Services.Users.UserFlags;
using Disco.Services;
using Disco.Services.Authorization;
using Disco.Services.Exporting;
using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Tasks;
using Disco.Services.Users.UserFlags;
using Disco.Services.Web;
using Disco.Web.Areas.Config.Models.UserFlag;
using Disco.Web.Extensions;
using System;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.Web.Mvc;
namespace Disco.Web.Areas.API.Controllers
@@ -401,5 +407,53 @@ namespace Disco.Web.Areas.API.Controllers
return Json(assignedUsers, JsonRequestBehavior.AllowGet);
}
#endregion
#region Exporting
internal const string ExportSessionCacheKey = "UserFlagExportContext_{0}";
[DiscoAuthorize(Claims.Config.UserFlag.Export)]
public virtual ActionResult Export(ExportModel Model)
{
if (Model == null || Model.Options == null)
throw new ArgumentNullException(nameof(Model));
// Start Export
var exportContext = UserFlagExportTask.ScheduleNow(Model.Options);
// Store Export Context in Web Cache
string key = string.Format(ExportSessionCacheKey, exportContext.TaskStatus.SessionId);
HttpRuntime.Cache.Insert(key, exportContext, null, DateTime.Now.AddMinutes(60), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
// Set Task Finished Url
var finishedActionResult = MVC.Config.UserFlag.Export(exportContext.TaskStatus.SessionId, null, null);
exportContext.TaskStatus.SetFinishedUrl(Url.Action(finishedActionResult));
// Try waiting for completion
if (exportContext.TaskStatus.WaitUntilFinished(TimeSpan.FromSeconds(2)))
return RedirectToAction(finishedActionResult);
else
return RedirectToAction(MVC.Config.Logging.TaskStatus(exportContext.TaskStatus.SessionId));
}
[DiscoAuthorize(Claims.Config.UserFlag.Export)]
public virtual ActionResult ExportRetrieve(string Id)
{
if (string.IsNullOrWhiteSpace(Id))
throw new ArgumentNullException("Id");
string key = string.Format(ExportSessionCacheKey, Id);
var context = HttpRuntime.Cache.Get(key) as ExportTaskContext<UserFlagExportOptions>;
if (context == null)
throw new ArgumentException("The Id specified is invalid, or the export data expired (60 minutes)", nameof(Id));
if (context.Result == null || context.Result.Result == null)
throw new ArgumentException("The export session is still running, or failed to complete successfully", nameof(Id));
var fileStream = context.Result.Result;
return this.File(fileStream.GetBuffer(), 0, (int)fileStream.Length, context.Result.MimeType, context.Result.Filename);
}
#endregion
}
}
@@ -129,6 +129,11 @@ namespace Disco.Web.Areas.Config
"Config/UserFlag/Create",
new { controller = "UserFlag", action = "Create", id = UrlParameter.Optional }
);
context.MapRoute(
"Config_UserFlag_Export",
"Config/UserFlag/Export",
new { controller = "UserFlag", action = "Export", id = UrlParameter.Optional }
);
context.MapRoute(
"Config_UserFlag",
"Config/UserFlag/{id}",
@@ -1,12 +1,19 @@
using Disco.Models.Repository;
using Disco.Models.Areas.Config.UI.UserFlag;
using Disco.Models.Repository;
using Disco.Models.Services.Devices.Exporting;
using Disco.Models.Services.Users.UserFlags;
using Disco.Models.UI.Config.UserFlag;
using Disco.Services.Authorization;
using Disco.Services.Exporting;
using Disco.Services.Extensions;
using Disco.Services.Plugins.Features.UIExtension;
using Disco.Services.Users.UserFlags;
using Disco.Services.Web;
using Disco.Web.Areas.Config.Models.UserFlag;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Disco.Web.Areas.Config.Controllers
@@ -114,5 +121,42 @@ namespace Disco.Web.Areas.Config.Controllers
return View(model);
}
#region Export
[DiscoAuthorizeAny(Claims.Config.UserFlag.Export), HttpGet]
public virtual ActionResult Export(string DownloadId, int? UserFlagId, bool? CurrentOnly)
{
var m = new ExportModel()
{
Options = UserFlagExportOptions.DefaultOptions(),
UserFlags = UserFlagService.GetUserFlags(),
};
if (!string.IsNullOrWhiteSpace(DownloadId))
{
string key = string.Format(API.Controllers.UserFlagController.ExportSessionCacheKey, DownloadId);
var context = HttpRuntime.Cache.Get(key) as ExportTaskContext<UserFlagExportOptions>;
if (context != null)
{
m.ExportSessionResult = context.Result;
m.ExportSessionId = DownloadId;
}
}
if (UserFlagId.HasValue && CurrentOnly.HasValue)
{
m.Options.UserFlagIds = new List<int>() { UserFlagId.Value };
m.Options.CurrentOnly = CurrentOnly.Value;
}
// UI Extensions
UIExtensions.ExecuteExtensions<ConfigUserFlagExportModel>(this.ControllerContext, m);
return View(m);
}
#endregion
}
}
@@ -0,0 +1,17 @@
using Disco.Models.Areas.Config.UI.UserFlag;
using Disco.Models.Services.Exporting;
using Disco.Models.Services.Users.UserFlags;
using System.Collections.Generic;
namespace Disco.Web.Areas.Config.Models.UserFlag
{
public class ExportModel : ConfigUserFlagExportModel
{
public UserFlagExportOptions Options { get; set; }
public string ExportSessionId { get; set; }
public ExportResult ExportSessionResult { get; set; }
public List<Disco.Models.Repository.UserFlag> UserFlags { get; set; }
}
}
@@ -0,0 +1,185 @@
@using Disco.Web.Areas.Config.Models.UserFlag;
@model ExportModel
@{
Authorization.RequireAny(Claims.Config.UserFlag.Export);
ViewBag.Title = Html.ToBreadcrumb("Configuration", MVC.Config.Config.Index(), "User Flags", MVC.Config.UserFlag.Index(null), "Export");
var optionsMetadata = ModelMetadata.FromLambdaExpression(m => m.Options, ViewData);
var optionGroups = optionsMetadata.Properties.Where(p => p.ShortDisplayName != null && p.ModelType == typeof(bool) && p.PropertyName != "CurrentOnly")
.GroupBy(m => m.ShortDisplayName);
}
<div id="UserFlag_Export">
@using (Html.BeginForm(MVC.API.UserFlag.Export()))
{
<div id="UserFlag_Export_Scope" class="form" style="width: 570px">
<h2>Export Scope</h2>
<table>
<tr>
<th style="width: 150px">
User Flags:
</th>
<td>
@foreach (var userFlag in Model.UserFlags)
{
<div>
<label>
<input type="checkbox" id="Options_UserFlagIds" name="Options.UserFlagIds" value="@userFlag.Id" @(((bool)Model.Options.UserFlagIds.Contains(userFlag.Id)) ? "checked " : null) />
<i class="fa fa-@(userFlag.Icon) fa-lg d-@(userFlag.IconColour)"></i>
<span>@userFlag.Name</span>
</label>
</div>
}
</td>
</tr>
<tr>
<th>@Html.LabelFor(m => m.Options.CurrentOnly)</th>
<td>
@Html.CheckBoxFor(m => m.Options.CurrentOnly)
<p>Uncheck to include all historical user flag assignments.</p>
</td>
</tr>
<tr>
<th>@Html.LabelFor(m => m.Options.Format)</th>
<td>
@Html.DropDownListFor(m => m.Options.Format, Enum.GetNames(typeof(Disco.Models.Exporting.ExportFormat)).Select(v => new SelectListItem() { Value = v, Text = v }))
</td>
</tr>
</table>
</div>
<div id="UserFlag_Export_Fields" class="form" style="width: 570px; margin-top: 15px;">
<h2>Export Fields <a id="UserFlag_Export_Fields_Defaults" href="#">(Defaults)</a></h2>
<table>
@foreach (var optionGroup in optionGroups)
{
var optionFields = optionGroup.ToList();
var itemsPerColumn = (int)Math.Ceiling((double)optionFields.Count / 2);
<tr>
<th style="width: 120px;">
@optionGroup.Key
@if (optionFields.Count > 2)
{
<span style="display: block;" class="select"><a class="selectAll" href="#">ALL</a> | <a class="selectNone" href="#">NONE</a></span>
}
</th>
<td>
<div class="UserFlag_Export_Fields_Group">
<table class="none">
<tr>
<td style="width: 50%">
<ul class="none">
@foreach (var optionItem in optionFields.Take(itemsPerColumn))
{
<li title="@optionItem.Description">
<input type="checkbox" id="Options_@optionItem.PropertyName" name="Options.@optionItem.PropertyName" value="true" @(((bool)optionItem.Model) ? "checked " : null)/><label for="Options_@optionItem.PropertyName">@optionItem.DisplayName</label></li>
}
</ul>
</td>
<td style="width: 50%">
<ul class="none">
@foreach (var optionItem in optionFields.Skip(itemsPerColumn))
{
<li title="@optionItem.Description">
<input type="checkbox" id="Options_@optionItem.PropertyName" name="Options.@optionItem.PropertyName" value="true" @(((bool)optionItem.Model) ? "checked " : null)/><label for="Options_@optionItem.PropertyName">@optionItem.DisplayName</label></li>
}
</ul>
</td>
</tr>
</table>
</div>
</td>
</tr>
}
</table>
</div>
<script>
$(function () {
var exportDefaultFields = ['Name', 'AddedDate', 'UserId', 'UserDisplayName', 'Comments'];
var $exportFields = $('#UserFlag_Export_Fields');
var $exportScope = $('#UserFlag_Export_Scope');
var $form = $exportScope.closest('form');
var $exportingDialog = null;
$exportFields.on('click', 'a.selectAll,a.selectNone', function () {
var $this = $(this);
$this.closest('tr').find('input').prop('checked', $this.is('.selectAll'));
return false;
});
$('#UserFlag_Export_Fields_Defaults').click(function () {
$exportFields.find('input').prop('checked', false);
$.each(exportDefaultFields, function (index, value) {
$('#Options_' + value).prop('checked', true);
});
return false;
});
// Submit Validation
function submitHandler() {
var exportFieldCount = $exportFields.find('input:checked').length;
if (exportFieldCount > 0) {
if ($exportingDialog == null) {
$exportingDialog = $('#UserFlag_Export_Exporting').dialog({
width: 400,
height: 164,
resizable: false,
modal: true,
autoOpen: false
});
}
$exportingDialog.dialog('open');
$form[0].submit();
}
else
alert('Select at least one field to export.');
}
$.validator.unobtrusive.parse($form);
$form.data("validator").settings.submitHandler = submitHandler;
$('#UserFlag_Export_Download_Dialog').dialog({
width: 400,
height: 164,
resizable: false,
modal: true,
autoOpen: true
});
$('#UserFlag_Export_Button').click(function () {
$form.submit();
});
});
</script>
}
</div>
@if (Model.ExportSessionId != null)
{
<div id="UserFlag_Export_Download_Dialog" class="dialog" title="Export User Flags">
<h4>@Model.ExportSessionResult.RecordCount record@(Model.ExportSessionResult.RecordCount != 1 ? "s" : null) were successfully exported.</h4>
<a href="@Url.Action(MVC.API.UserFlag.ExportRetrieve(Model.ExportSessionId))" class="button"><i class="fa fa-download fa-lg"></i>Download User Flag Export</a>
</div>
<script>
$(function () {
$('#UserFlag_Export_Download_Dialog')
.dialog({
width: 400,
height: 164,
resizable: false,
modal: true,
autoOpen: true
});
});
</script>
}
<div id="UserFlag_Export_Exporting" class="dialog" title="Exporting User Flags...">
<h4><i class="fa fa-lg fa-cog fa-spin" title="Please Wait"></i>Exporting user flags...</h4>
</div>
<div class="actionBar">
<a id="UserFlag_Export_Button" href="#" class="button">Export User Flags</a>
</div>
@@ -0,0 +1,707 @@
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Disco.Web.Areas.Config.Views.UserFlag
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebPages;
using Disco;
using Disco.Models.Repository;
using Disco.Services;
using Disco.Services.Authorization;
using Disco.Services.Web;
using Disco.Web;
#line 1 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
using Disco.Web.Areas.Config.Models.UserFlag;
#line default
#line hidden
using Disco.Web.Extensions;
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
[System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Config/Views/UserFlag/Export.cshtml")]
public partial class Export : Disco.Services.Web.WebViewPage<ExportModel>
{
public Export()
{
}
public override void Execute()
{
#line 3 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Authorization.RequireAny(Claims.Config.UserFlag.Export);
ViewBag.Title = Html.ToBreadcrumb("Configuration", MVC.Config.Config.Index(), "User Flags", MVC.Config.UserFlag.Index(null), "Export");
var optionsMetadata = ModelMetadata.FromLambdaExpression(m => m.Options, ViewData);
var optionGroups = optionsMetadata.Properties.Where(p => p.ShortDisplayName != null && p.ModelType == typeof(bool) && p.PropertyName != "CurrentOnly")
.GroupBy(m => m.ShortDisplayName);
#line default
#line hidden
WriteLiteral("\r\n<div");
WriteLiteral(" id=\"UserFlag_Export\"");
WriteLiteral(">\r\n");
#line 13 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
#line default
#line hidden
#line 13 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
using (Html.BeginForm(MVC.API.UserFlag.Export()))
{
#line default
#line hidden
WriteLiteral(" <div");
WriteLiteral(" id=\"UserFlag_Export_Scope\"");
WriteLiteral(" class=\"form\"");
WriteLiteral(" style=\"width: 570px\"");
WriteLiteral(">\r\n <h2>Export Scope</h2>\r\n <table>\r\n <tr>\r\n" +
" <th");
WriteLiteral(" style=\"width: 150px\"");
WriteLiteral(">\r\n User Flags:\r\n </th>\r\n " +
" <td>\r\n");
#line 23 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
#line default
#line hidden
#line 23 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
foreach (var userFlag in Model.UserFlags)
{
#line default
#line hidden
WriteLiteral(" <div>\r\n <label>\r\n " +
" <input");
WriteLiteral(" type=\"checkbox\"");
WriteLiteral(" id=\"Options_UserFlagIds\"");
WriteLiteral(" name=\"Options.UserFlagIds\"");
WriteAttribute("value", Tuple.Create(" value=\"", 1234), Tuple.Create("\"", 1254)
#line 27 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 1242), Tuple.Create<System.Object, System.Int32>(userFlag.Id
#line default
#line hidden
, 1242), false)
);
WriteLiteral(" ");
#line 27 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(((bool)Model.Options.UserFlagIds.Contains(userFlag.Id)) ? "checked " : null);
#line default
#line hidden
WriteLiteral(" />\r\n <i");
WriteAttribute("class", Tuple.Create(" class=\"", 1377), Tuple.Create("\"", 1438)
, Tuple.Create(Tuple.Create("", 1385), Tuple.Create("fa", 1385), true)
, Tuple.Create(Tuple.Create(" ", 1387), Tuple.Create("fa-", 1388), true)
#line 28 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 1391), Tuple.Create<System.Object, System.Int32>(userFlag.Icon
#line default
#line hidden
, 1391), false)
, Tuple.Create(Tuple.Create(" ", 1407), Tuple.Create("fa-lg", 1408), true)
, Tuple.Create(Tuple.Create(" ", 1413), Tuple.Create("d-", 1414), true)
#line 28 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 1416), Tuple.Create<System.Object, System.Int32>(userFlag.IconColour
#line default
#line hidden
, 1416), false)
);
WriteLiteral("></i>\r\n <span>");
#line 29 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(userFlag.Name);
#line default
#line hidden
WriteLiteral("</span>\r\n </label>\r\n </" +
"div>\r\n");
#line 32 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral(" </td>\r\n </tr>\r\n <tr>\r\n " +
" <th>");
#line 36 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(Html.LabelFor(m => m.Options.CurrentOnly));
#line default
#line hidden
WriteLiteral("</th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 38 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(Html.CheckBoxFor(m => m.Options.CurrentOnly));
#line default
#line hidden
WriteLiteral("\r\n <p>Uncheck to include all historical user flag assignme" +
"nts.</p>\r\n </td>\r\n </tr>\r\n <tr>" +
"\r\n <th>");
#line 43 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(Html.LabelFor(m => m.Options.Format));
#line default
#line hidden
WriteLiteral("</th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 45 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(Html.DropDownListFor(m => m.Options.Format, Enum.GetNames(typeof(Disco.Models.Exporting.ExportFormat)).Select(v => new SelectListItem() { Value = v, Text = v })));
#line default
#line hidden
WriteLiteral("\r\n </td>\r\n </tr>\r\n </table>\r\n " +
" </div>\r\n");
WriteLiteral(" <div");
WriteLiteral(" id=\"UserFlag_Export_Fields\"");
WriteLiteral(" class=\"form\"");
WriteLiteral(" style=\"width: 570px; margin-top: 15px;\"");
WriteLiteral(">\r\n <h2>Export Fields <a");
WriteLiteral(" id=\"UserFlag_Export_Fields_Defaults\"");
WriteLiteral(" href=\"#\"");
WriteLiteral(">(Defaults)</a></h2>\r\n <table>\r\n");
#line 53 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
#line default
#line hidden
#line 53 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
foreach (var optionGroup in optionGroups)
{
var optionFields = optionGroup.ToList();
var itemsPerColumn = (int)Math.Ceiling((double)optionFields.Count / 2);
#line default
#line hidden
WriteLiteral(" <tr>\r\n <th");
WriteLiteral(" style=\"width: 120px;\"");
WriteLiteral(">\r\n");
WriteLiteral(" ");
#line 59 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(optionGroup.Key);
#line default
#line hidden
WriteLiteral("\r\n");
#line 60 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
#line default
#line hidden
#line 60 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
if (optionFields.Count > 2)
{
#line default
#line hidden
WriteLiteral(" <span");
WriteLiteral(" style=\"display: block;\"");
WriteLiteral(" class=\"select\"");
WriteLiteral("><a");
WriteLiteral(" class=\"selectAll\"");
WriteLiteral(" href=\"#\"");
WriteLiteral(">ALL</a> | <a");
WriteLiteral(" class=\"selectNone\"");
WriteLiteral(" href=\"#\"");
WriteLiteral(">NONE</a></span>\r\n");
#line 63 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral(" </th>\r\n <td>\r\n " +
" <div");
WriteLiteral(" class=\"UserFlag_Export_Fields_Group\"");
WriteLiteral(">\r\n <table");
WriteLiteral(" class=\"none\"");
WriteLiteral(">\r\n <tr>\r\n " +
" <td");
WriteLiteral(" style=\"width: 50%\"");
WriteLiteral(">\r\n <ul");
WriteLiteral(" class=\"none\"");
WriteLiteral(">\r\n");
#line 71 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
#line default
#line hidden
#line 71 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
foreach (var optionItem in optionFields.Take(itemsPerColumn))
{
#line default
#line hidden
WriteLiteral(" <li");
WriteAttribute("title", Tuple.Create(" title=\"", 3824), Tuple.Create("\"", 3855)
#line 73 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 3832), Tuple.Create<System.Object, System.Int32>(optionItem.Description
#line default
#line hidden
, 3832), false)
);
WriteLiteral(">\r\n <input");
WriteLiteral(" type=\"checkbox\"");
WriteAttribute("id", Tuple.Create(" id=\"", 3937), Tuple.Create("\"", 3974)
, Tuple.Create(Tuple.Create("", 3942), Tuple.Create("Options_", 3942), true)
#line 74 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 3950), Tuple.Create<System.Object, System.Int32>(optionItem.PropertyName
#line default
#line hidden
, 3950), false)
);
WriteAttribute("name", Tuple.Create(" name=\"", 3975), Tuple.Create("\"", 4014)
, Tuple.Create(Tuple.Create("", 3982), Tuple.Create("Options.", 3982), true)
#line 74 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 3990), Tuple.Create<System.Object, System.Int32>(optionItem.PropertyName
#line default
#line hidden
, 3990), false)
);
WriteLiteral(" value=\"true\"");
WriteLiteral(" ");
#line 74 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(((bool)optionItem.Model) ? "checked " : null);
#line default
#line hidden
WriteLiteral("/><label");
WriteAttribute("for", Tuple.Create(" for=\"", 4084), Tuple.Create("\"", 4122)
, Tuple.Create(Tuple.Create("", 4090), Tuple.Create("Options_", 4090), true)
#line 74 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 4098), Tuple.Create<System.Object, System.Int32>(optionItem.PropertyName
#line default
#line hidden
, 4098), false)
);
WriteLiteral(">");
#line 74 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(optionItem.DisplayName);
#line default
#line hidden
WriteLiteral("</label></li>\r\n");
#line 75 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ul>\r\n " +
" </td>\r\n <td");
WriteLiteral(" style=\"width: 50%\"");
WriteLiteral(">\r\n <ul");
WriteLiteral(" class=\"none\"");
WriteLiteral(">\r\n");
#line 80 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
#line default
#line hidden
#line 80 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
foreach (var optionItem in optionFields.Skip(itemsPerColumn))
{
#line default
#line hidden
WriteLiteral(" <li");
WriteAttribute("title", Tuple.Create(" title=\"", 4657), Tuple.Create("\"", 4688)
#line 82 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 4665), Tuple.Create<System.Object, System.Int32>(optionItem.Description
#line default
#line hidden
, 4665), false)
);
WriteLiteral(">\r\n <input");
WriteLiteral(" type=\"checkbox\"");
WriteAttribute("id", Tuple.Create(" id=\"", 4770), Tuple.Create("\"", 4807)
, Tuple.Create(Tuple.Create("", 4775), Tuple.Create("Options_", 4775), true)
#line 83 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 4783), Tuple.Create<System.Object, System.Int32>(optionItem.PropertyName
#line default
#line hidden
, 4783), false)
);
WriteAttribute("name", Tuple.Create(" name=\"", 4808), Tuple.Create("\"", 4847)
, Tuple.Create(Tuple.Create("", 4815), Tuple.Create("Options.", 4815), true)
#line 83 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 4823), Tuple.Create<System.Object, System.Int32>(optionItem.PropertyName
#line default
#line hidden
, 4823), false)
);
WriteLiteral(" value=\"true\"");
WriteLiteral(" ");
#line 83 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(((bool)optionItem.Model) ? "checked " : null);
#line default
#line hidden
WriteLiteral("/><label");
WriteAttribute("for", Tuple.Create(" for=\"", 4917), Tuple.Create("\"", 4955)
, Tuple.Create(Tuple.Create("", 4923), Tuple.Create("Options_", 4923), true)
#line 83 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 4931), Tuple.Create<System.Object, System.Int32>(optionItem.PropertyName
#line default
#line hidden
, 4931), false)
);
WriteLiteral(">");
#line 83 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(optionItem.DisplayName);
#line default
#line hidden
WriteLiteral("</label></li>\r\n");
#line 84 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral(@" </ul>
</td>
</tr>
</table>
</div>
</td>
</tr>
");
#line 92 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral(" </table>\r\n </div>\r\n");
WriteLiteral(" <script>\r\n $(function () {\r\n var exportDefaultF" +
"ields = [\'Name\', \'AddedDate\', \'UserId\', \'UserDisplayName\', \'Comments\'];\r\n " +
" var $exportFields = $(\'#UserFlag_Export_Fields\');\r\n var " +
"$exportScope = $(\'#UserFlag_Export_Scope\');\r\n var $form = $export" +
"Scope.closest(\'form\');\r\n var $exportingDialog = null;\r\n\r\n " +
" $exportFields.on(\'click\', \'a.selectAll,a.selectNone\', function () {\r\n " +
" var $this = $(this);\r\n\r\n $this.closest(\'tr\')" +
".find(\'input\').prop(\'checked\', $this.is(\'.selectAll\'));\r\n\r\n r" +
"eturn false;\r\n });\r\n\r\n $(\'#UserFlag_Export_Fields_" +
"Defaults\').click(function () {\r\n\r\n $exportFields.find(\'input\'" +
").prop(\'checked\', false);\r\n\r\n $.each(exportDefaultFields, fun" +
"ction (index, value) {\r\n $(\'#Options_\' + value).prop(\'che" +
"cked\', true);\r\n });\r\n\r\n return false;\r\n " +
" });\r\n\r\n // Submit Validation\r\n functi" +
"on submitHandler() {\r\n var exportFieldCount = $exportFields.f" +
"ind(\'input:checked\').length;\r\n\r\n if (exportFieldCount > 0) {\r" +
"\n\r\n if ($exportingDialog == null) {\r\n " +
" $exportingDialog = $(\'#UserFlag_Export_Exporting\').dialog({\r\n " +
" width: 400,\r\n height: 164,\r\n" +
" resizable: false,\r\n " +
" modal: true,\r\n autoOpen: false\r\n " +
" });\r\n }\r\n $exporting" +
"Dialog.dialog(\'open\');\r\n\r\n $form[0].submit();\r\n " +
" }\r\n else\r\n alert(\'Select at " +
"least one field to export.\');\r\n }\r\n $.validator.un" +
"obtrusive.parse($form);\r\n $form.data(\"validator\").settings.submit" +
"Handler = submitHandler;\r\n\r\n $(\'#UserFlag_Export_Download_Dialog\'" +
").dialog({\r\n width: 400,\r\n height: 164,\r\n " +
" resizable: false,\r\n modal: true,\r\n " +
" autoOpen: true\r\n });\r\n $(\'#UserFlag_Ex" +
"port_Button\').click(function () {\r\n $form.submit();\r\n " +
" });\r\n });\r\n </script>\r\n");
#line 159 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral("</div>\r\n");
#line 161 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
if (Model.ExportSessionId != null)
{
#line default
#line hidden
WriteLiteral(" <div");
WriteLiteral(" id=\"UserFlag_Export_Download_Dialog\"");
WriteLiteral(" class=\"dialog\"");
WriteLiteral(" title=\"Export User Flags\"");
WriteLiteral(">\r\n <h4>");
#line 164 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(Model.ExportSessionResult.RecordCount);
#line default
#line hidden
WriteLiteral(" record");
#line 164 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
Write(Model.ExportSessionResult.RecordCount != 1 ? "s" : null);
#line default
#line hidden
WriteLiteral(" were successfully exported.</h4>\r\n <a");
WriteAttribute("href", Tuple.Create(" href=\"", 8226), Tuple.Create("\"", 8300)
#line 165 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
, Tuple.Create(Tuple.Create("", 8233), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.UserFlag.ExportRetrieve(Model.ExportSessionId))
#line default
#line hidden
, 8233), false)
);
WriteLiteral(" class=\"button\"");
WriteLiteral("><i");
WriteLiteral(" class=\"fa fa-download fa-lg\"");
WriteLiteral("></i>Download User Flag Export</a>\r\n </div>\r\n");
WriteLiteral(@" <script>
$(function () {
$('#UserFlag_Export_Download_Dialog')
.dialog({
width: 400,
height: 164,
resizable: false,
modal: true,
autoOpen: true
});
});
</script>
");
#line 179 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
}
#line default
#line hidden
WriteLiteral("<div");
WriteLiteral(" id=\"UserFlag_Export_Exporting\"");
WriteLiteral(" class=\"dialog\"");
WriteLiteral(" title=\"Exporting User Flags...\"");
WriteLiteral(">\r\n <h4><i");
WriteLiteral(" class=\"fa fa-lg fa-cog fa-spin\"");
WriteLiteral(" title=\"Please Wait\"");
WriteLiteral("></i>Exporting user flags...</h4>\r\n</div>\r\n<div");
WriteLiteral(" class=\"actionBar\"");
WriteLiteral(">\r\n <a");
WriteLiteral(" id=\"UserFlag_Export_Button\"");
WriteLiteral(" href=\"#\"");
WriteLiteral(" class=\"button\"");
WriteLiteral(">Export User Flags</a>\r\n</div>\r\n");
}
}
}
#pragma warning restore 1591
@@ -65,10 +65,14 @@
}
</table>
}
<div class="actionBar">
@if (Authorization.Has(Claims.Config.UserFlag.Export) && Model.UserFlags.Count > 0)
{
@Html.ActionLinkButton("Export", MVC.Config.UserFlag.Export())
}
@if (Authorization.Has(Claims.Config.UserFlag.Create))
{
<div class="actionBar">
@Html.ActionLinkButton("Create User Flag", MVC.Config.UserFlag.Create())
</div>
}
</div>
</div>
@@ -340,43 +340,69 @@ WriteLiteral(" </table>\r\n");
}
#line default
#line hidden
WriteLiteral("<div");
WriteLiteral(" class=\"actionBar\"");
WriteLiteral(">\r\n");
#line 69 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
#line default
#line hidden
#line 69 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
if (Authorization.Has(Claims.Config.UserFlag.Export) && Model.UserFlags.Count > 0)
{
#line default
#line hidden
#line 71 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
Write(Html.ActionLinkButton("Export", MVC.Config.UserFlag.Export()));
#line default
#line hidden
#line 71 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
}
#line default
#line hidden
WriteLiteral(" ");
#line 68 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
#line 73 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
if (Authorization.Has(Claims.Config.UserFlag.Create))
{
#line default
#line hidden
WriteLiteral(" <div");
WriteLiteral(" class=\"actionBar\"");
WriteLiteral(">\r\n");
WriteLiteral(" ");
#line 71 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
#line 75 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
Write(Html.ActionLinkButton("Create User Flag", MVC.Config.UserFlag.Create()));
#line default
#line hidden
WriteLiteral("\r\n </div>\r\n");
#line 75 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
#line 73 "..\..\Areas\Config\Views\UserFlag\Index.cshtml"
}
#line default
#line hidden
WriteLiteral("</div>");
WriteLiteral("</div>\r\n</div>");
}
}
@@ -11,6 +11,8 @@
var canDelete = Authorization.Has(Claims.Config.UserFlag.Delete);
var canBulkAssignment = Authorization.HasAll(Claims.User.Actions.AddFlags, Claims.User.Actions.RemoveFlags, Claims.User.ShowFlagAssignments);
var canShowUsers = Model.CurrentAssignmentCount > 0 && Authorization.HasAll(Claims.User.Search, Claims.User.ShowFlagAssignments);
var canExportCurrent = Model.CurrentAssignmentCount > 0 && Authorization.Has(Claims.Config.UserFlag.Export);
var canExportAll = Model.TotalAssignmentCount > 0 && Authorization.Has(Claims.Config.UserFlag.Export);
var hideAdvanced =
Model.UserFlag.UserDevicesLinkedGroup == null &&
@@ -398,9 +400,17 @@
</tr>
</table>
</div>
@if (canBulkAssignment || canDelete || canShowUsers)
@if (canBulkAssignment || canDelete || canShowUsers || canExportCurrent || canExportAll)
{
<div class="actionBar">
@if (canExportCurrent)
{
@Html.ActionLinkButton("Export Current Assignments", MVC.Config.UserFlag.Export(null, Model.UserFlag.Id, true), "Config_UserFlags_Actions_ExportCurrent_Button")
}
@if (canExportAll)
{
@Html.ActionLinkButton("Export All Assignments", MVC.Config.UserFlag.Export(null, Model.UserFlag.Id, false), "Config_UserFlags_Actions_ExportAll_Button")
}
@if (canBulkAssignment)
{
<a href="#" id="Config_UserFlags_BulkAssign_Button" class="button">Bulk Assign Users</a>
@@ -537,9 +547,6 @@
});
</script>
}
@if (canDelete)
{
@Html.ActionLinkButton("Delete", MVC.API.UserFlag.Delete(Model.UserFlag.Id, true), "Config_UserFlags_Actions_Delete_Button")
File diff suppressed because it is too large Load Diff
+28
View File
@@ -1800,6 +1800,34 @@ h1.Config_DocumentTemplates {
#Config_UserFlags_BulkAssign_AssignDialog.loading > form {
display: none;
}
#UserFlag_Export #UserFlag_Export_Fields #UserFlag_Export_Fields_Defaults {
font-size: 0.75em;
}
#UserFlag_Export #UserFlag_Export_Fields th {
font-size: 1.05em;
}
#UserFlag_Export #UserFlag_Export_Fields th span {
margin-top: 4px;
font-size: 0.8em;
}
#UserFlag_Export_Download_Dialog {
padding-top: 20px;
text-align: center;
}
#UserFlag_Export_Download_Dialog h4 {
margin-bottom: 30px;
}
#UserFlag_Export_Download_Dialog a {
margin-bottom: 20px;
}
#UserFlag_Export_Exporting {
padding-top: 50px;
text-align: center;
}
#UserFlag_Export_Exporting i {
margin-right: 10px;
color: #1e6dab;
}
#DocumentTemplate_BulkGenerate .actions {
padding-bottom: 0.5em;
text-align: right;
+40
View File
@@ -2121,6 +2121,46 @@ h1.Config_DocumentTemplates {
}
}
#UserFlag_Export {
#UserFlag_Export_Fields {
#UserFlag_Export_Fields_Defaults {
font-size: .75em;
}
th {
font-size: 1.05em;
span {
margin-top: 4px;
font-size: .8em;
}
}
}
}
#UserFlag_Export_Download_Dialog {
padding-top: 20px;
text-align: center;
h4 {
margin-bottom: 30px;
}
a {
margin-bottom: 20px;
}
}
#UserFlag_Export_Exporting {
padding-top: 50px;
text-align: center;
i {
margin-right: 10px;
color: @StatusInformation;
}
}
#DocumentTemplate_BulkGenerate {
.actions {
padding-bottom: .5em;
File diff suppressed because one or more lines are too long
+11
View File
@@ -234,6 +234,7 @@
<Compile Include="Areas\Config\Models\Shared\DeviceGroupDocumentTemplateBulkGenerateModel.cs" />
<Compile Include="Areas\Config\Models\Shared\LinkedGroupModel.cs" />
<Compile Include="Areas\Config\Models\UserFlag\CreateModel.cs" />
<Compile Include="Areas\Config\Models\UserFlag\ExportModel.cs" />
<Compile Include="Areas\Config\Models\UserFlag\IndexModel.cs" />
<Compile Include="Areas\Config\Models\UserFlag\ShowModel.cs" />
<Compile Include="Areas\Config\Models\DeviceBatch\CreateModel.cs" />
@@ -347,6 +348,11 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Areas\Config\Views\UserFlag\Export.generated.cs">
<DependentUpon>Export.cshtml</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Areas\Config\Views\UserFlag\Index.generated.cs">
<DependentUpon>Index.cshtml</DependentUpon>
<AutoGen>True</AutoGen>
@@ -1295,6 +1301,10 @@
<Generator>RazorGenerator</Generator>
<LastGenOutput>Create.generated.cs</LastGenOutput>
</None>
<Content Include="Areas\Config\Views\UserFlag\Export.cshtml">
<Generator>RazorGenerator</Generator>
<LastGenOutput>Export.generated.cs</LastGenOutput>
</Content>
<None Include="Areas\Config\Views\UserFlag\Index.cshtml">
<Generator>RazorGenerator</Generator>
<LastGenOutput>Index.generated.cs</LastGenOutput>
@@ -2393,6 +2403,7 @@
<Folder Include="Areas\API\Models\AuthorizationRole\" />
<Folder Include="Areas\API\Models\JobQueue\" />
<Folder Include="Areas\API\Models\Search\" />
<Folder Include="Areas\API\Models\UserFlag\" />
<Folder Include="Areas\API\Models\WirelessCertificate\" />
<Folder Include="Areas\Services\Models\" />
</ItemGroup>
@@ -137,6 +137,18 @@ namespace Disco.Web.Areas.API.Controllers
{
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.AssignedUsers);
}
[NonAction]
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public virtual System.Web.Mvc.ActionResult Export()
{
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Export);
}
[NonAction]
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public virtual System.Web.Mvc.ActionResult ExportRetrieve()
{
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.ExportRetrieve);
}
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public UserFlagController Actions { get { return MVC.API.UserFlag; } }
@@ -166,6 +178,8 @@ namespace Disco.Web.Areas.API.Controllers
public readonly string Delete = "Delete";
public readonly string BulkAssignUsers = "BulkAssignUsers";
public readonly string AssignedUsers = "AssignedUsers";
public readonly string Export = "Export";
public readonly string ExportRetrieve = "ExportRetrieve";
}
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
@@ -184,6 +198,8 @@ namespace Disco.Web.Areas.API.Controllers
public const string Delete = "Delete";
public const string BulkAssignUsers = "BulkAssignUsers";
public const string AssignedUsers = "AssignedUsers";
public const string Export = "Export";
public const string ExportRetrieve = "ExportRetrieve";
}
@@ -319,6 +335,22 @@ namespace Disco.Web.Areas.API.Controllers
{
public readonly string id = "id";
}
static readonly ActionParamsClass_Export s_params_Export = new ActionParamsClass_Export();
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public ActionParamsClass_Export ExportParams { get { return s_params_Export; } }
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public class ActionParamsClass_Export
{
public readonly string Model = "Model";
}
static readonly ActionParamsClass_ExportRetrieve s_params_ExportRetrieve = new ActionParamsClass_ExportRetrieve();
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public ActionParamsClass_ExportRetrieve ExportRetrieveParams { get { return s_params_ExportRetrieve; } }
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public class ActionParamsClass_ExportRetrieve
{
public readonly string Id = "Id";
}
static readonly ViewsClass s_views = new ViewsClass();
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public ViewsClass Views { get { return s_views; } }
@@ -522,6 +554,30 @@ namespace Disco.Web.Areas.API.Controllers
return callInfo;
}
[NonAction]
partial void ExportOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, Disco.Web.Areas.Config.Models.UserFlag.ExportModel Model);
[NonAction]
public override System.Web.Mvc.ActionResult Export(Disco.Web.Areas.Config.Models.UserFlag.ExportModel Model)
{
var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Export);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "Model", Model);
ExportOverride(callInfo, Model);
return callInfo;
}
[NonAction]
partial void ExportRetrieveOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, string Id);
[NonAction]
public override System.Web.Mvc.ActionResult ExportRetrieve(string Id)
{
var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.ExportRetrieve);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "Id", Id);
ExportRetrieveOverride(callInfo, Id);
return callInfo;
}
}
}
@@ -65,6 +65,12 @@ namespace Disco.Web.Areas.Config.Controllers
{
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Index);
}
[NonAction]
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public virtual System.Web.Mvc.ActionResult Export()
{
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Export);
}
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public UserFlagController Actions { get { return MVC.Config.UserFlag; } }
@@ -83,6 +89,7 @@ namespace Disco.Web.Areas.Config.Controllers
{
public readonly string Index = "Index";
public readonly string Create = "Create";
public readonly string Export = "Export";
}
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
@@ -90,6 +97,7 @@ namespace Disco.Web.Areas.Config.Controllers
{
public const string Index = "Index";
public const string Create = "Create";
public const string Export = "Export";
}
@@ -109,6 +117,16 @@ namespace Disco.Web.Areas.Config.Controllers
{
public readonly string model = "model";
}
static readonly ActionParamsClass_Export s_params_Export = new ActionParamsClass_Export();
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public ActionParamsClass_Export ExportParams { get { return s_params_Export; } }
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public class ActionParamsClass_Export
{
public readonly string DownloadId = "DownloadId";
public readonly string UserFlagId = "UserFlagId";
public readonly string CurrentOnly = "CurrentOnly";
}
static readonly ViewsClass s_views = new ViewsClass();
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public ViewsClass Views { get { return s_views; } }
@@ -120,10 +138,12 @@ namespace Disco.Web.Areas.Config.Controllers
public class _ViewNamesClass
{
public readonly string Create = "Create";
public readonly string Export = "Export";
public readonly string Index = "Index";
public readonly string Show = "Show";
}
public readonly string Create = "~/Areas/Config/Views/UserFlag/Create.cshtml";
public readonly string Export = "~/Areas/Config/Views/UserFlag/Export.cshtml";
public readonly string Index = "~/Areas/Config/Views/UserFlag/Index.cshtml";
public readonly string Show = "~/Areas/Config/Views/UserFlag/Show.cshtml";
}
@@ -169,6 +189,20 @@ namespace Disco.Web.Areas.Config.Controllers
return callInfo;
}
[NonAction]
partial void ExportOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, string DownloadId, int? UserFlagId, bool? CurrentOnly);
[NonAction]
public override System.Web.Mvc.ActionResult Export(string DownloadId, int? UserFlagId, bool? CurrentOnly)
{
var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Export);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "DownloadId", DownloadId);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "UserFlagId", UserFlagId);
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "CurrentOnly", CurrentOnly);
ExportOverride(callInfo, DownloadId, UserFlagId, CurrentOnly);
return callInfo;
}
}
}