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" />
|
<FileManager ShowFiles="false" ShowUpload="false" @ref="_filemanager" />
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<button type="button" class="btn btn-success" @onclick="ExportFile">@Localizer["Export"]</button>
|
<button type="button" class="btn btn-success" @onclick="ExportFile">@Localizer["Export"]</button>
|
||||||
@ -39,6 +45,7 @@
|
|||||||
@code {
|
@code {
|
||||||
private string _content = string.Empty;
|
private string _content = string.Empty;
|
||||||
private FileManager _filemanager;
|
private FileManager _filemanager;
|
||||||
|
private string _filename = string.Empty;
|
||||||
|
|
||||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
||||||
public override string Title => "Export Content";
|
public override string Title => "Export Content";
|
||||||
@ -62,12 +69,12 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var folderid = _filemanager.GetFolderId();
|
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)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
AddModuleMessage(string.Format(Localizer["Success.Export.File"], result.Message), MessageType.Success);
|
AddModuleMessage(Localizer["Success.Content.Export"], MessageType.Success);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -148,9 +148,12 @@
|
|||||||
<value>Select a folder where you wish to save the exported content</value>
|
<value>Select a folder where you wish to save the exported content</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Message.Content.Export" xml:space="preserve">
|
<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>
|
||||||
<data name="Success.Export.File" xml:space="preserve">
|
<data name="Filename.Text" xml:space="preserve">
|
||||||
<value>Content Was Successfully Exported To Specified Folder With Filename {0}</value>
|
<value>Filename:</value>
|
||||||
|
</data>
|
||||||
|
<data name="Filename.HelpText" xml:space="preserve">
|
||||||
|
<value>Specify a name for the file (without an extension)</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
@ -66,7 +66,8 @@ namespace Oqtane.Services
|
|||||||
/// <param name="moduleId"></param>
|
/// <param name="moduleId"></param>
|
||||||
/// <param name="pageId"></param>
|
/// <param name="pageId"></param>
|
||||||
/// <param name="folderId"></param>
|
/// <param name="folderId"></param>
|
||||||
|
/// <param name="filename"></param>
|
||||||
/// <returns>success/failure</returns>
|
/// <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}");
|
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;
|
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")]
|
[HttpPost("export")]
|
||||||
[Authorize(Roles = RoleNames.Registered)]
|
[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 result = new Result(false);
|
||||||
var module = _modules.GetModule(moduleid);
|
var module = _modules.GetModule(moduleid);
|
||||||
if (module != null && module.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, module.SiteId, EntityNames.Page, pageid, PermissionNames.Edit) &&
|
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
|
// get content
|
||||||
var content = _modules.ExportModule(moduleid);
|
var content = _modules.ExportModule(moduleid);
|
||||||
@ -277,8 +277,8 @@ namespace Oqtane.Controllers
|
|||||||
Directory.CreateDirectory(folderPath);
|
Directory.CreateDirectory(folderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create text file
|
// create json file
|
||||||
var filename = Utilities.GetTypeNameLastSegment(module.ModuleDefinitionName, 0) + moduleid.ToString() + ".json";
|
filename = Path.GetFileNameWithoutExtension(filename) + ".json";
|
||||||
string filepath = Path.Combine(folderPath, filename);
|
string filepath = Path.Combine(folderPath, filename);
|
||||||
if (System.IO.File.Exists(filepath))
|
if (System.IO.File.Exists(filepath))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user