mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Export controller action and UI with content type selections and metadata,data,settings options.
Adding an export method to IImportExportService. --HG-- branch : dev
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ImportExport.Services;
|
using Orchard.ImportExport.Services;
|
||||||
using Orchard.ImportExport.ViewModels;
|
using Orchard.ImportExport.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -9,9 +12,11 @@ using Orchard.UI.Notify;
|
|||||||
namespace Orchard.ImportExport.Controllers {
|
namespace Orchard.ImportExport.Controllers {
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
private readonly IImportExportService _importExportService;
|
private readonly IImportExportService _importExportService;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public AdminController(IOrchardServices services, IImportExportService importExportService) {
|
public AdminController(IOrchardServices services, IImportExportService importExportService, IContentDefinitionManager contentDefinitionManager) {
|
||||||
_importExportService = importExportService;
|
_importExportService = importExportService;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
Services = services;
|
Services = services;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
@@ -46,9 +51,32 @@ namespace Orchard.ImportExport.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Export() {
|
public ActionResult Export() {
|
||||||
var viewModel = new ExportViewModel();
|
var viewModel = new ExportViewModel { ContentTypes = new List<ContentTypeEntry>() };
|
||||||
|
foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions()) {
|
||||||
|
viewModel.ContentTypes.Add(new ContentTypeEntry { ContentTypeName = contentType.Name });
|
||||||
|
}
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost, ActionName("Export")]
|
||||||
|
public ActionResult ExportPOST() {
|
||||||
|
if (!Services.Authorizer.Authorize(Permissions.Export, T("Not allowed to export.")))
|
||||||
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
var viewModel = new ExportViewModel { ContentTypes = new List<ContentTypeEntry>() };
|
||||||
|
|
||||||
|
try {
|
||||||
|
UpdateModel(viewModel);
|
||||||
|
var contentTypesToExport = viewModel.ContentTypes.Where(c => c.IsChecked).Select(c => c.ContentTypeName);
|
||||||
|
var exportFile = _importExportService.Export(contentTypesToExport, viewModel.Metadata, viewModel.Data, viewModel.SiteSettings);
|
||||||
|
Services.Notifier.Information(T("Your export file has been created at <a href=\"{0}\" />", exportFile));
|
||||||
|
|
||||||
|
return RedirectToAction("Export");
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
Services.Notifier.Error(T("Export failed: {0}", exception.Message));
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
namespace Orchard.ImportExport.Services {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.ImportExport.Services {
|
||||||
public interface IImportExportService : IDependency {
|
public interface IImportExportService : IDependency {
|
||||||
void Import(string recipeText);
|
void Import(string recipeText);
|
||||||
|
string Export(IEnumerable<string> contentTypes, bool exportMetadata, bool exportData, bool exportSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Environment.Descriptor;
|
using Orchard.Environment.Descriptor;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -31,6 +32,10 @@ namespace Orchard.ImportExport.Services {
|
|||||||
UpdateShell();
|
UpdateShell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Export(IEnumerable<string> contentTypes, bool exportMetadata, bool exportData, bool exportSettings) {
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckRecipeSteps(Recipe recipe) {
|
private void CheckRecipeSteps(Recipe recipe) {
|
||||||
foreach (var step in recipe.RecipeSteps) {
|
foreach (var step in recipe.RecipeSteps) {
|
||||||
switch (step.Name) {
|
switch (step.Name) {
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
namespace Orchard.ImportExport.ViewModels {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.ImportExport.ViewModels {
|
||||||
public class ExportViewModel {
|
public class ExportViewModel {
|
||||||
|
public IList<ContentTypeEntry> ContentTypes { get; set; }
|
||||||
|
public virtual bool Metadata { get; set; }
|
||||||
|
public virtual bool Data { get; set; }
|
||||||
|
public virtual bool SiteSettings { get; set; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public class ContentTypeEntry {
|
||||||
|
public string ContentTypeName { get; set; }
|
||||||
|
public bool IsChecked { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,3 +2,38 @@
|
|||||||
|
|
||||||
@{ Layout.Title = T("Export").ToString(); }
|
@{ Layout.Title = T("Export").ToString(); }
|
||||||
|
|
||||||
|
@using(Html.BeginFormAntiForgeryPost()) {
|
||||||
|
Html.ValidationSummary();
|
||||||
|
<fieldset>
|
||||||
|
<legend>@T("Choose the types to include in the export file:")</legend><br />
|
||||||
|
<div>
|
||||||
|
@T("Content Types")
|
||||||
|
@{var contentTypeIndex = 0;}
|
||||||
|
@foreach (var contentTypeEntry in Model.ContentTypes) {
|
||||||
|
<br />
|
||||||
|
<input type="hidden" value="@Model.ContentTypes[contentTypeIndex].ContentTypeName" name="@Html.NameOf(m => m.ContentTypes[contentTypeIndex].ContentTypeName)"/>
|
||||||
|
<input type="checkbox" value="true" name="@Html.NameOf(m => m.ContentTypes[contentTypeIndex].IsChecked)"/>
|
||||||
|
<label class="forcheckbox">@Model.ContentTypes[contentTypeIndex].ContentTypeName</label>
|
||||||
|
contentTypeIndex = contentTypeIndex + 1;
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<br /><hr /><br />
|
||||||
|
<legend>@T("Choose what to save for these types:")</legend><br />
|
||||||
|
<div>
|
||||||
|
@Html.EditorFor(m => m.Metadata)
|
||||||
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.Metadata)">@T("Metadata")</label>
|
||||||
|
<p>@T("Metadata is the definition of your content types: what parts and fields they have, with what settings.")</p><br />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@Html.EditorFor(m => m.Data)
|
||||||
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.Data)">@T("Data")</label>
|
||||||
|
<p>@T("Data is the actual content of your site.")</p><br />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@Html.EditorFor(m => m.SiteSettings)
|
||||||
|
<label class="forcheckbox" for="@Html.FieldIdFor( m => m.SiteSettings)">@T("Site Settings")</label><br />
|
||||||
|
<p>@T("Please verify that you are not exporting confidential information, such as passwords or application keys.")</p><br />
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<button type="submit" class="primaryAction">@T("Export")</button>
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user