exporting: remember last options for documents/user flags/device flags
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Services.Devices.DeviceFlag;
|
||||
|
||||
namespace Disco.Data.Configuration.Modules
|
||||
{
|
||||
public class DeviceFlagsConfiguration : ConfigurationBase
|
||||
{
|
||||
public DeviceFlagsConfiguration(DiscoDataContext database) : base(database) { }
|
||||
|
||||
public override string Scope { get; } = "DeviceFlags";
|
||||
|
||||
public DeviceFlagExportOptions LastExportOptions
|
||||
{
|
||||
get => Get(DeviceFlagExportOptions.DefaultOptions());
|
||||
set => Set(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,11 @@ namespace Disco.Data.Configuration.Modules
|
||||
get { return Get<List<DocumentTemplatePackage>>(null); }
|
||||
set { Set(value); }
|
||||
}
|
||||
|
||||
public DocumentExportOptions LastExportOptions
|
||||
{
|
||||
get => Get(DocumentExportOptions.DefaultOptions());
|
||||
set => Set(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Services.Users.UserFlags;
|
||||
|
||||
namespace Disco.Data.Configuration.Modules
|
||||
{
|
||||
public class UserFlagsConfiguration : ConfigurationBase
|
||||
{
|
||||
public UserFlagsConfiguration(DiscoDataContext database) : base(database) { }
|
||||
|
||||
public override string Scope { get; } = "UserFlags";
|
||||
|
||||
public UserFlagExportOptions LastExportOptions
|
||||
{
|
||||
get => Get(UserFlagExportOptions.DefaultOptions());
|
||||
set => Set(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ namespace Disco.Data.Configuration
|
||||
moduleActiveDirectoryConfiguration = new Lazy<Modules.ActiveDirectoryConfiguration>(() => new Modules.ActiveDirectoryConfiguration(Database));
|
||||
moduleDevicesConfiguration = new Lazy<Modules.DevicesConfiguration>(() => new Modules.DevicesConfiguration(Database));
|
||||
moduleDocumentsConfiguration = new Lazy<Modules.DocumentsConfiguration>(() => new Modules.DocumentsConfiguration(Database));
|
||||
moduleUserFlagsConfiguration = new Lazy<Modules.UserFlagsConfiguration>(() => new Modules.UserFlagsConfiguration(Database));
|
||||
moduleDeviceFlagsConfiguration = new Lazy<Modules.DeviceFlagsConfiguration>(() => new Modules.DeviceFlagsConfiguration(Database));
|
||||
}
|
||||
|
||||
#region Configuration Modules
|
||||
@@ -31,57 +33,18 @@ namespace Disco.Data.Configuration
|
||||
private Lazy<Modules.ActiveDirectoryConfiguration> moduleActiveDirectoryConfiguration;
|
||||
private Lazy<Modules.DevicesConfiguration> moduleDevicesConfiguration;
|
||||
private Lazy<Modules.DocumentsConfiguration> moduleDocumentsConfiguration;
|
||||
private Lazy<Modules.UserFlagsConfiguration> moduleUserFlagsConfiguration;
|
||||
private Lazy<Modules.DeviceFlagsConfiguration> moduleDeviceFlagsConfiguration;
|
||||
|
||||
public Modules.BootstrapperConfiguration Bootstrapper
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleBootstrapperConfiguration.Value;
|
||||
}
|
||||
}
|
||||
public Modules.DeviceProfilesConfiguration DeviceProfiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleDeviceProfilesConfiguration.Value;
|
||||
}
|
||||
}
|
||||
public Modules.OrganisationAddressesConfiguration OrganisationAddresses
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleOrganisationAddressesConfiguration.Value;
|
||||
}
|
||||
}
|
||||
public Modules.JobPreferencesConfiguration JobPreferences
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleJobPreferencesConfiguration.Value;
|
||||
}
|
||||
}
|
||||
public Modules.ActiveDirectoryConfiguration ActiveDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleActiveDirectoryConfiguration.Value;
|
||||
}
|
||||
}
|
||||
public Modules.DevicesConfiguration Devices
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleDevicesConfiguration.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public Modules.DocumentsConfiguration Documents
|
||||
{
|
||||
get
|
||||
{
|
||||
return moduleDocumentsConfiguration.Value;
|
||||
}
|
||||
}
|
||||
public Modules.BootstrapperConfiguration Bootstrapper => moduleBootstrapperConfiguration.Value;
|
||||
public Modules.DeviceProfilesConfiguration DeviceProfiles => moduleDeviceProfilesConfiguration.Value;
|
||||
public Modules.OrganisationAddressesConfiguration OrganisationAddresses => moduleOrganisationAddressesConfiguration.Value;
|
||||
public Modules.JobPreferencesConfiguration JobPreferences => moduleJobPreferencesConfiguration.Value;
|
||||
public Modules.ActiveDirectoryConfiguration ActiveDirectory => moduleActiveDirectoryConfiguration.Value;
|
||||
public Modules.DevicesConfiguration Devices => moduleDevicesConfiguration.Value;
|
||||
public Modules.DocumentsConfiguration Documents => moduleDocumentsConfiguration.Value;
|
||||
public Modules.UserFlagsConfiguration UserFlags => moduleUserFlagsConfiguration.Value;
|
||||
public Modules.DeviceFlagsConfiguration DeviceFlags => moduleDeviceFlagsConfiguration.Value;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -95,26 +58,27 @@ namespace Disco.Data.Configuration
|
||||
if (result == null)
|
||||
{
|
||||
var appDataPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data");
|
||||
if (appDataPath.EndsWith("\\"))
|
||||
return appDataPath;
|
||||
else
|
||||
return string.Concat(appDataPath, '\\');
|
||||
|
||||
if (!appDataPath.EndsWith(@"\"))
|
||||
appDataPath += @"\";
|
||||
|
||||
return appDataPath;
|
||||
}
|
||||
else
|
||||
return result;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
if (!System.IO.Directory.Exists(value))
|
||||
throw new System.IO.DirectoryNotFoundException(string.Format("DataStoreLocation: '{0}' could not be found", value));
|
||||
string storePath;
|
||||
if (value.EndsWith("\\"))
|
||||
storePath = value;
|
||||
else
|
||||
storePath = string.Concat(value, '\\');
|
||||
Set(storePath);
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
|
||||
if (!Directory.Exists(value))
|
||||
throw new DirectoryNotFoundException($"DataStoreLocation: '{value}' could not be found");
|
||||
|
||||
if (!value.EndsWith(@"\"))
|
||||
value += @"\";
|
||||
|
||||
Set(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,30 +95,10 @@ namespace Disco.Data.Configuration
|
||||
}
|
||||
|
||||
#region Plugin Locations
|
||||
public string PluginsLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return System.IO.Path.Combine(DataStoreLocation, @"Plugins\");
|
||||
}
|
||||
}
|
||||
public string PluginStorageLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return System.IO.Path.Combine(DataStoreLocation, @"PluginStorage\");
|
||||
}
|
||||
}
|
||||
public string PluginPackagesLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return System.IO.Path.Combine(DataStoreLocation, @"PluginPackages\");
|
||||
}
|
||||
}
|
||||
|
||||
public string PluginUserPhotosLocation
|
||||
=> Path.Combine(DataStoreLocation, @"PluginUserPhotos\");
|
||||
public string PluginsLocation => Path.Combine(DataStoreLocation, @"Plugins\");
|
||||
public string PluginStorageLocation => Path.Combine(DataStoreLocation, @"PluginStorage\");
|
||||
public string PluginPackagesLocation => Path.Combine(DataStoreLocation, @"PluginPackages\");
|
||||
public string PluginUserPhotosLocation => Path.Combine(DataStoreLocation, @"PluginUserPhotos\");
|
||||
|
||||
public DateTime PluginDetailsCacheExpiration
|
||||
{
|
||||
|
||||
@@ -77,6 +77,8 @@
|
||||
<Compile Include="Configuration\ConfigurationCache.cs" />
|
||||
<Compile Include="Configuration\Modules\ActiveDirectoryConfiguration.cs" />
|
||||
<Compile Include="Configuration\Modules\DevicesConfiguration.cs" />
|
||||
<Compile Include="Configuration\Modules\DeviceFlagsConfiguration.cs" />
|
||||
<Compile Include="Configuration\Modules\UserFlagsConfiguration.cs" />
|
||||
<Compile Include="Configuration\Modules\DocumentsConfiguration.cs" />
|
||||
<Compile Include="Configuration\Modules\JobPreferencesConfiguration.cs" />
|
||||
<Compile Include="Configuration\SystemConfiguration.cs" />
|
||||
|
||||
@@ -409,6 +409,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
if (Model == null || Model.Options == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
Database.DiscoConfiguration.DeviceFlags.LastExportOptions = Model.Options;
|
||||
Database.SaveChanges();
|
||||
|
||||
// Start Export
|
||||
var exportContext = new DeviceFlagExport(Model.Options);
|
||||
var taskContext = ExportTask.ScheduleNowCacheResult(exportContext, id => Url.Action(MVC.Config.DeviceFlag.Export(id, null, null)));
|
||||
@@ -444,6 +447,8 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[HttpPost, ValidateAntiForgeryToken]
|
||||
public virtual ActionResult SaveExport(ExportModel Model)
|
||||
{
|
||||
Database.DiscoConfiguration.DeviceFlags.LastExportOptions = Model.Options;
|
||||
|
||||
var export = new DeviceFlagExport(Model.Options);
|
||||
var savedExport = SavedExports.SaveExport(export, Database, CurrentUser);
|
||||
|
||||
|
||||
@@ -1462,6 +1462,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
if (Model.Options.DocumentTemplateIds.Count == 1)
|
||||
templateId = Model.Options.DocumentTemplateIds.First();
|
||||
|
||||
Database.DiscoConfiguration.Documents.LastExportOptions = Model.Options;
|
||||
Database.SaveChanges();
|
||||
|
||||
// Start Export
|
||||
var exportContext = new DocumentExport(Model.Options);
|
||||
var taskContext = ExportTask.ScheduleNowCacheResult(exportContext, id => Url.Action(MVC.Config.DocumentTemplate.Export(templateId, id)));
|
||||
@@ -1494,6 +1497,8 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[HttpPost, ValidateAntiForgeryToken]
|
||||
public virtual ActionResult SaveExport(ExportModel Model)
|
||||
{
|
||||
Database.DiscoConfiguration.Documents.LastExportOptions = Model.Options;
|
||||
|
||||
var export = new DocumentExport(Model.Options);
|
||||
var savedExport = SavedExports.SaveExport(export, Database, CurrentUser);
|
||||
|
||||
|
||||
@@ -414,6 +414,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
if (Model == null || Model.Options == null)
|
||||
throw new ArgumentNullException(nameof(Model));
|
||||
|
||||
Database.DiscoConfiguration.UserFlags.LastExportOptions = Model.Options;
|
||||
Database.SaveChanges();
|
||||
|
||||
// Start Export
|
||||
var exportContext = new UserFlagExport(Model.Options);
|
||||
var taskContext = ExportTask.ScheduleNowCacheResult(exportContext, id => Url.Action(MVC.Config.UserFlag.Export(id, null, null)));
|
||||
@@ -446,6 +449,8 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[HttpPost, ValidateAntiForgeryToken]
|
||||
public virtual ActionResult SaveExport(ExportModel Model)
|
||||
{
|
||||
Database.DiscoConfiguration.UserFlags.LastExportOptions = Model.Options;
|
||||
|
||||
var export = new UserFlagExport(Model.Options);
|
||||
var savedExport = SavedExports.SaveExport(export, Database, CurrentUser);
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
{
|
||||
var m = new ExportModel()
|
||||
{
|
||||
Options = DeviceFlagExportOptions.DefaultOptions(),
|
||||
Options = Database.DiscoConfiguration.DeviceFlags.LastExportOptions,
|
||||
DeviceFlags = DeviceFlagService.GetDeviceFlags(),
|
||||
};
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
{
|
||||
var m = new ExportModel()
|
||||
{
|
||||
Options = DocumentExportOptions.DefaultOptions(),
|
||||
Options = Database.DiscoConfiguration.Documents.LastExportOptions,
|
||||
DocumentTemplates = Database.DocumentTemplates.OrderBy(d => d.Id).ToList(),
|
||||
};
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
{
|
||||
var m = new ExportModel()
|
||||
{
|
||||
Options = UserFlagExportOptions.DefaultOptions(),
|
||||
Options = Database.DiscoConfiguration.UserFlags.LastExportOptions,
|
||||
UserFlags = UserFlagService.GetUserFlags(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user