refactor: make exporting consistent
This commit is contained in:
@@ -122,7 +122,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
#region Export
|
||||
|
||||
[DiscoAuthorizeAny(Claims.Config.DeviceFlag.Export), HttpGet]
|
||||
public virtual ActionResult Export(string DownloadId, int? DeviceFlagId, bool? CurrentOnly)
|
||||
public virtual ActionResult Export(Guid? exportId, int? deviceFlagId, bool? currentOnly)
|
||||
{
|
||||
var m = new ExportModel()
|
||||
{
|
||||
@@ -130,26 +130,20 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
DeviceFlags = DeviceFlagService.GetDeviceFlags(),
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(DownloadId))
|
||||
if (ExportTask.TryFromCache(exportId, out var context))
|
||||
{
|
||||
string key = string.Format(API.Controllers.DeviceFlagController.ExportSessionCacheKey, DownloadId);
|
||||
var context = HttpRuntime.Cache.Get(key) as ExportTaskContext<DeviceFlagExportOptions>;
|
||||
|
||||
if (context != null)
|
||||
{
|
||||
m.ExportSessionResult = context.Result;
|
||||
m.ExportSessionId = DownloadId;
|
||||
}
|
||||
m.ExportId = context.Id;
|
||||
m.ExportResult = context.Result;
|
||||
}
|
||||
|
||||
if (DeviceFlagId.HasValue && CurrentOnly.HasValue)
|
||||
if (deviceFlagId.HasValue && currentOnly.HasValue)
|
||||
{
|
||||
m.Options.DeviceFlagIds = new List<int>() { DeviceFlagId.Value };
|
||||
m.Options.CurrentOnly = CurrentOnly.Value;
|
||||
m.Options.DeviceFlagIds = new List<int>() { deviceFlagId.Value };
|
||||
m.Options.CurrentOnly = currentOnly.Value;
|
||||
}
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<ConfigDeviceFlagExportModel>(this.ControllerContext, m);
|
||||
UIExtensions.ExecuteExtensions<ConfigDeviceFlagExportModel>(ControllerContext, m);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
#region Export
|
||||
|
||||
[DiscoAuthorizeAny(Claims.Config.UserFlag.Export), HttpGet]
|
||||
public virtual ActionResult Export(string DownloadId, int? UserFlagId, bool? CurrentOnly)
|
||||
public virtual ActionResult Export(Guid? exportId, int? userFlagId, bool? currentOnly)
|
||||
{
|
||||
var m = new ExportModel()
|
||||
{
|
||||
@@ -132,26 +132,20 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
UserFlags = UserFlagService.GetUserFlags(),
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(DownloadId))
|
||||
if (ExportTask.TryFromCache(exportId, out var context))
|
||||
{
|
||||
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;
|
||||
}
|
||||
m.ExportId = exportId;
|
||||
m.ExportResult = context.Result;
|
||||
}
|
||||
|
||||
if (UserFlagId.HasValue && CurrentOnly.HasValue)
|
||||
if (userFlagId.HasValue && currentOnly.HasValue)
|
||||
{
|
||||
m.Options.UserFlagIds = new List<int>() { UserFlagId.Value };
|
||||
m.Options.CurrentOnly = CurrentOnly.Value;
|
||||
m.Options.UserFlagIds = new List<int>() { userFlagId.Value };
|
||||
m.Options.CurrentOnly = currentOnly.Value;
|
||||
}
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<ConfigUserFlagExportModel>(this.ControllerContext, m);
|
||||
UIExtensions.ExecuteExtensions<ConfigUserFlagExportModel>(ControllerContext, m);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Disco.Models.Areas.Config.UI.DeviceFlag;
|
||||
using Disco.Models.Services.Devices.DeviceFlag;
|
||||
using Disco.Models.Services.Exporting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Disco.Web.Areas.Config.Models.DeviceFlag
|
||||
@@ -9,8 +10,8 @@ namespace Disco.Web.Areas.Config.Models.DeviceFlag
|
||||
{
|
||||
public DeviceFlagExportOptions Options { get; set; }
|
||||
|
||||
public string ExportSessionId { get; set; }
|
||||
public ExportResult ExportSessionResult { get; set; }
|
||||
public Guid? ExportId { get; set; }
|
||||
public ExportResult ExportResult { get; set; }
|
||||
|
||||
public List<Disco.Models.Repository.DeviceFlag> DeviceFlags { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Disco.Models.Areas.Config.UI.UserFlag;
|
||||
using Disco.Models.Services.Exporting;
|
||||
using Disco.Models.Services.Users.UserFlags;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Disco.Web.Areas.Config.Models.UserFlag
|
||||
@@ -9,8 +10,8 @@ namespace Disco.Web.Areas.Config.Models.UserFlag
|
||||
{
|
||||
public UserFlagExportOptions Options { get; set; }
|
||||
|
||||
public string ExportSessionId { get; set; }
|
||||
public ExportResult ExportSessionResult { get; set; }
|
||||
public Guid? ExportId { get; set; }
|
||||
public ExportResult ExportResult { get; set; }
|
||||
|
||||
public List<Disco.Models.Repository.UserFlag> UserFlags { get; set; }
|
||||
}
|
||||
|
||||
@@ -1017,7 +1017,7 @@
|
||||
{
|
||||
if (Authorization.Has(Claims.Device.Actions.Export))
|
||||
{
|
||||
@Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.Exporting.DeviceExportTypes.Batch, Model.DeviceBatch.Id))
|
||||
@Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.DeviceExportTypes.Batch, Model.DeviceBatch.Id))
|
||||
}
|
||||
if (Authorization.Has(Claims.Device.Search) && Model.DeviceCount > 0)
|
||||
{
|
||||
|
||||
@@ -2778,14 +2778,14 @@ WriteLiteral(" ");
|
||||
#line hidden
|
||||
|
||||
#line 1020 "..\..\Areas\Config\Views\DeviceBatch\Show.cshtml"
|
||||
Write(Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.Exporting.DeviceExportTypes.Batch, Model.DeviceBatch.Id)));
|
||||
Write(Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.DeviceExportTypes.Batch, Model.DeviceBatch.Id)));
|
||||
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 1020 "..\..\Areas\Config\Views\DeviceBatch\Show.cshtml"
|
||||
|
||||
|
||||
}
|
||||
if (Authorization.Has(Claims.Device.Search) && Model.DeviceCount > 0)
|
||||
{
|
||||
|
||||
@@ -161,17 +161,17 @@
|
||||
</script>
|
||||
}
|
||||
</div>
|
||||
@if (Model.ExportSessionId != null)
|
||||
@if (Model.ExportId.HasValue)
|
||||
{
|
||||
<div id="DeviceFlag_Export_Download_Dialog" class="dialog" title="Export Device Flags">
|
||||
@if (Model.ExportSessionResult.RecordCount == 0)
|
||||
@if (Model.ExportResult.RecordCount == 0)
|
||||
{
|
||||
<h4>No records matched the filter criteria</h4>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h4>@Model.ExportSessionResult.RecordCount record@(Model.ExportSessionResult.RecordCount != 1 ? "s" : null) were successfully exported.</h4>
|
||||
<a href="@Url.Action(MVC.API.DeviceFlag.ExportRetrieve(Model.ExportSessionId))" class="button"><i class="fa fa-download fa-lg"></i>Download Device Flag Export</a>
|
||||
<h4>@Model.ExportResult.RecordCount record@(Model.ExportResult.RecordCount != 1 ? "s" : null) were successfully exported.</h4>
|
||||
<a href="@Url.Action(MVC.API.DeviceFlag.ExportRetrieve(Model.ExportId.Value))" class="button"><i class="fa fa-download fa-lg"></i>Download Device Flag Export</a>
|
||||
}
|
||||
</div>
|
||||
<script>
|
||||
|
||||
@@ -601,7 +601,7 @@ WriteLiteral("</div>\r\n");
|
||||
|
||||
|
||||
#line 164 "..\..\Areas\Config\Views\DeviceFlag\Export.cshtml"
|
||||
if (Model.ExportSessionId != null)
|
||||
if (Model.ExportId.HasValue)
|
||||
{
|
||||
|
||||
|
||||
@@ -625,7 +625,7 @@ WriteLiteral(">\r\n");
|
||||
#line hidden
|
||||
|
||||
#line 167 "..\..\Areas\Config\Views\DeviceFlag\Export.cshtml"
|
||||
if (Model.ExportSessionResult.RecordCount == 0)
|
||||
if (Model.ExportResult.RecordCount == 0)
|
||||
{
|
||||
|
||||
|
||||
@@ -646,7 +646,7 @@ WriteLiteral(" <h4>");
|
||||
|
||||
|
||||
#line 173 "..\..\Areas\Config\Views\DeviceFlag\Export.cshtml"
|
||||
Write(Model.ExportSessionResult.RecordCount);
|
||||
Write(Model.ExportResult.RecordCount);
|
||||
|
||||
|
||||
#line default
|
||||
@@ -655,7 +655,7 @@ WriteLiteral(" record");
|
||||
|
||||
|
||||
#line 173 "..\..\Areas\Config\Views\DeviceFlag\Export.cshtml"
|
||||
Write(Model.ExportSessionResult.RecordCount != 1 ? "s" : null);
|
||||
Write(Model.ExportResult.RecordCount != 1 ? "s" : null);
|
||||
|
||||
|
||||
#line default
|
||||
@@ -664,14 +664,14 @@ WriteLiteral(" were successfully exported.</h4>\r\n");
|
||||
|
||||
WriteLiteral(" <a");
|
||||
|
||||
WriteAttribute("href", Tuple.Create(" href=\"", 8524), Tuple.Create("\"", 8600)
|
||||
WriteAttribute("href", Tuple.Create(" href=\"", 8497), Tuple.Create("\"", 8572)
|
||||
|
||||
#line 174 "..\..\Areas\Config\Views\DeviceFlag\Export.cshtml"
|
||||
, Tuple.Create(Tuple.Create("", 8531), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.DeviceFlag.ExportRetrieve(Model.ExportSessionId))
|
||||
, Tuple.Create(Tuple.Create("", 8504), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.DeviceFlag.ExportRetrieve(Model.ExportId.Value))
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
, 8531), false)
|
||||
, 8504), false)
|
||||
);
|
||||
|
||||
WriteLiteral(" class=\"button\"");
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
{
|
||||
if (Authorization.Has(Claims.Device.Actions.Export))
|
||||
{
|
||||
@Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.Exporting.DeviceExportTypes.Model, Model.DeviceModel.Id))
|
||||
@Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.DeviceExportTypes.Model, Model.DeviceModel.Id))
|
||||
}
|
||||
if (Authorization.Has(Claims.Device.Search) && Model.DeviceCount > 0)
|
||||
{
|
||||
|
||||
@@ -859,14 +859,14 @@ WriteLiteral(" ");
|
||||
#line hidden
|
||||
|
||||
#line 258 "..\..\Areas\Config\Views\DeviceModel\Show.cshtml"
|
||||
Write(Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.Exporting.DeviceExportTypes.Model, Model.DeviceModel.Id)));
|
||||
Write(Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.DeviceExportTypes.Model, Model.DeviceModel.Id)));
|
||||
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 258 "..\..\Areas\Config\Views\DeviceModel\Show.cshtml"
|
||||
|
||||
|
||||
}
|
||||
if (Authorization.Has(Claims.Device.Search) && Model.DeviceCount > 0)
|
||||
{
|
||||
|
||||
@@ -1012,7 +1012,7 @@
|
||||
}
|
||||
@if (Authorization.Has(Claims.Device.Actions.Export))
|
||||
{
|
||||
@Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.Exporting.DeviceExportTypes.Profile, Model.DeviceProfile.Id))
|
||||
@Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.DeviceExportTypes.Profile, Model.DeviceProfile.Id))
|
||||
}
|
||||
@if (Authorization.Has(Claims.Device.Search) && Model.DeviceCount > 0)
|
||||
{
|
||||
|
||||
@@ -3022,14 +3022,14 @@ WriteLiteral(" ");
|
||||
#line hidden
|
||||
|
||||
#line 1015 "..\..\Areas\Config\Views\DeviceProfile\Show.cshtml"
|
||||
Write(Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.Exporting.DeviceExportTypes.Profile, Model.DeviceProfile.Id)));
|
||||
Write(Html.ActionLinkButton("Export Devices", MVC.Device.Export(null, Disco.Models.Services.Devices.DeviceExportTypes.Profile, Model.DeviceProfile.Id)));
|
||||
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 1015 "..\..\Areas\Config\Views\DeviceProfile\Show.cshtml"
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -161,17 +161,17 @@
|
||||
</script>
|
||||
}
|
||||
</div>
|
||||
@if (Model.ExportSessionId != null)
|
||||
@if (Model.ExportId.HasValue)
|
||||
{
|
||||
<div id="UserFlag_Export_Download_Dialog" class="dialog" title="Export User Flags">
|
||||
@if (Model.ExportSessionResult.RecordCount == 0)
|
||||
@if (Model.ExportResult.RecordCount == 0)
|
||||
{
|
||||
<h4>No records matched the filter criteria</h4>
|
||||
}
|
||||
else
|
||||
{
|
||||
<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>
|
||||
<h4>@Model.ExportResult.RecordCount record@(Model.ExportResult.RecordCount != 1 ? "s" : null) were successfully exported.</h4>
|
||||
<a href="@Url.Action(MVC.API.UserFlag.ExportRetrieve(Model.ExportId.Value))" class="button"><i class="fa fa-download fa-lg"></i>Download User Flag Export</a>
|
||||
}
|
||||
</div>
|
||||
<script>
|
||||
|
||||
@@ -601,7 +601,7 @@ WriteLiteral("</div>\r\n");
|
||||
|
||||
|
||||
#line 164 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
|
||||
if (Model.ExportSessionId != null)
|
||||
if (Model.ExportId.HasValue)
|
||||
{
|
||||
|
||||
|
||||
@@ -625,7 +625,7 @@ WriteLiteral(">\r\n");
|
||||
#line hidden
|
||||
|
||||
#line 167 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
|
||||
if (Model.ExportSessionResult.RecordCount == 0)
|
||||
if (Model.ExportResult.RecordCount == 0)
|
||||
{
|
||||
|
||||
|
||||
@@ -646,7 +646,7 @@ WriteLiteral(" <h4>");
|
||||
|
||||
|
||||
#line 173 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
|
||||
Write(Model.ExportSessionResult.RecordCount);
|
||||
Write(Model.ExportResult.RecordCount);
|
||||
|
||||
|
||||
#line default
|
||||
@@ -655,7 +655,7 @@ WriteLiteral(" record");
|
||||
|
||||
|
||||
#line 173 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
|
||||
Write(Model.ExportSessionResult.RecordCount != 1 ? "s" : null);
|
||||
Write(Model.ExportResult.RecordCount != 1 ? "s" : null);
|
||||
|
||||
|
||||
#line default
|
||||
@@ -664,14 +664,14 @@ WriteLiteral(" were successfully exported.</h4>\r\n");
|
||||
|
||||
WriteLiteral(" <a");
|
||||
|
||||
WriteAttribute("href", Tuple.Create(" href=\"", 8500), Tuple.Create("\"", 8574)
|
||||
WriteAttribute("href", Tuple.Create(" href=\"", 8473), Tuple.Create("\"", 8546)
|
||||
|
||||
#line 174 "..\..\Areas\Config\Views\UserFlag\Export.cshtml"
|
||||
, Tuple.Create(Tuple.Create("", 8507), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.UserFlag.ExportRetrieve(Model.ExportSessionId))
|
||||
, Tuple.Create(Tuple.Create("", 8480), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.UserFlag.ExportRetrieve(Model.ExportId.Value))
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
, 8507), false)
|
||||
, 8480), false)
|
||||
);
|
||||
|
||||
WriteLiteral(" class=\"button\"");
|
||||
|
||||
Reference in New Issue
Block a user