Merge pull request #5311 from sbwalker/dev
allow filename to be provided during module export
This commit is contained in:
commit
a25b706c7b
@ -27,6 +27,12 @@
|
||||
<FileManager ShowFiles="false" ShowUpload="false" @ref="_filemanager" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="filename" HelpText="Specify a name for the file (without an extension)" ResourceKey="Filename">Filename: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="content" type="text" class="form-control" @bind="@_filename" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<button type="button" class="btn btn-success" @onclick="ExportFile">@Localizer["Export"]</button>
|
||||
@ -39,6 +45,7 @@
|
||||
@code {
|
||||
private string _content = string.Empty;
|
||||
private FileManager _filemanager;
|
||||
private string _filename = string.Empty;
|
||||
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
||||
public override string Title => "Export Content";
|
||||
@ -62,12 +69,12 @@
|
||||
try
|
||||
{
|
||||
var folderid = _filemanager.GetFolderId();
|
||||
if (folderid != -1)
|
||||
if (folderid != -1 && !string.IsNullOrEmpty(_filename))
|
||||
{
|
||||
var result = await ModuleService.ExportModuleAsync(ModuleState.ModuleId, PageState.Page.PageId, folderid);
|
||||
var result = await ModuleService.ExportModuleAsync(ModuleState.ModuleId, PageState.Page.PageId, folderid, _filename);
|
||||
if (result.Success)
|
||||
{
|
||||
AddModuleMessage(string.Format(Localizer["Success.Export.File"], result.Message), MessageType.Success);
|
||||
AddModuleMessage(Localizer["Success.Content.Export"], MessageType.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -148,9 +148,12 @@
|
||||
<value>Select a folder where you wish to save the exported content</value>
|
||||
</data>
|
||||
<data name="Message.Content.Export" xml:space="preserve">
|
||||
<value>Please Select A Folder Before Choosing Export</value>
|
||||
<value>Please Select A Folder And Provide A Filename Before Choosing Export</value>
|
||||
</data>
|
||||
<data name="Success.Export.File" xml:space="preserve">
|
||||
<value>Content Was Successfully Exported To Specified Folder With Filename {0}</value>
|
||||
<data name="Filename.Text" xml:space="preserve">
|
||||
<value>Filename:</value>
|
||||
</data>
|
||||
<data name="Filename.HelpText" xml:space="preserve">
|
||||
<value>Specify a name for the file (without an extension)</value>
|
||||
</data>
|
||||
</root>
|
@ -66,7 +66,8 @@ namespace Oqtane.Services
|
||||
/// <param name="moduleId"></param>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="folderId"></param>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns>success/failure</returns>
|
||||
Task<Result> ExportModuleAsync(int moduleId, int pageId, int folderId);
|
||||
Task<Result> ExportModuleAsync(int moduleId, int pageId, int folderId, string filename);
|
||||
}
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ namespace Oqtane.Services
|
||||
return await GetStringAsync($"{Apiurl}/export?moduleid={moduleId}&pageid={pageId}");
|
||||
}
|
||||
|
||||
public async Task<Result> ExportModuleAsync(int moduleId, int pageId, int folderId)
|
||||
public async Task<Result> ExportModuleAsync(int moduleId, int pageId, int folderId, string filename)
|
||||
{
|
||||
return await PostJsonAsync<Result>($"{Apiurl}/export?moduleid={moduleId}&pageid={pageId}&folderid={folderId}", null);
|
||||
return await PostJsonAsync<Result>($"{Apiurl}/export?moduleid={moduleId}&pageid={pageId}&folderid={folderId}&filename={filename}", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,15 +256,15 @@ namespace Oqtane.Controllers
|
||||
return content;
|
||||
}
|
||||
|
||||
// POST api/<controller>/export?moduleid=x&pageid=y&folderid=z
|
||||
// POST api/<controller>/export?moduleid=x&pageid=y&folderid=z&filename=a
|
||||
[HttpPost("export")]
|
||||
[Authorize(Roles = RoleNames.Registered)]
|
||||
public Result Export(int moduleid, int pageid, int folderid)
|
||||
public Result Export(int moduleid, int pageid, int folderid, string filename)
|
||||
{
|
||||
var result = new Result(false);
|
||||
var module = _modules.GetModule(moduleid);
|
||||
if (module != null && module.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Page, pageid, PermissionNames.Edit) &&
|
||||
_userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Folder, folderid, PermissionNames.Edit))
|
||||
_userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Folder, folderid, PermissionNames.Edit) && !string.IsNullOrEmpty(filename))
|
||||
{
|
||||
// get content
|
||||
var content = _modules.ExportModule(moduleid);
|
||||
@ -277,8 +277,8 @@ namespace Oqtane.Controllers
|
||||
Directory.CreateDirectory(folderPath);
|
||||
}
|
||||
|
||||
// create text file
|
||||
var filename = Utilities.GetTypeNameLastSegment(module.ModuleDefinitionName, 0) + moduleid.ToString() + ".json";
|
||||
// create json file
|
||||
filename = Path.GetFileNameWithoutExtension(filename) + ".json";
|
||||
string filepath = Path.Combine(folderPath, filename);
|
||||
if (System.IO.File.Exists(filepath))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user