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:
Suha Can
2011-03-10 16:14:41 -08:00
parent d4f8d73e9a
commit 7b54e374fd
5 changed files with 88 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement.MetaData;
using Orchard.ImportExport.Services;
using Orchard.ImportExport.ViewModels;
using Orchard.Localization;
@@ -9,9 +12,11 @@ using Orchard.UI.Notify;
namespace Orchard.ImportExport.Controllers {
public class AdminController : Controller {
private readonly IImportExportService _importExportService;
private readonly IContentDefinitionManager _contentDefinitionManager;
public AdminController(IOrchardServices services, IImportExportService importExportService) {
public AdminController(IOrchardServices services, IImportExportService importExportService, IContentDefinitionManager contentDefinitionManager) {
_importExportService = importExportService;
_contentDefinitionManager = contentDefinitionManager;
Services = services;
T = NullLocalizer.Instance;
}
@@ -46,9 +51,32 @@ namespace Orchard.ImportExport.Controllers {
}
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);
}
[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);
}
}
}
}

View File

@@ -1,6 +1,9 @@
namespace Orchard.ImportExport.Services {
using System.Collections.Generic;
namespace Orchard.ImportExport.Services {
public interface IImportExportService : IDependency {
void Import(string recipeText);
string Export(IEnumerable<string> contentTypes, bool exportMetadata, bool exportData, bool exportSettings);
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Orchard.Environment.Descriptor;
using Orchard.Localization;
@@ -31,6 +32,10 @@ namespace Orchard.ImportExport.Services {
UpdateShell();
}
public string Export(IEnumerable<string> contentTypes, bool exportMetadata, bool exportData, bool exportSettings) {
return String.Empty;
}
private void CheckRecipeSteps(Recipe recipe) {
foreach (var step in recipe.RecipeSteps) {
switch (step.Name) {

View File

@@ -1,4 +1,15 @@
namespace Orchard.ImportExport.ViewModels {
using System.Collections.Generic;
namespace Orchard.ImportExport.ViewModels {
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; }
}
}

View File

@@ -2,3 +2,38 @@
@{ 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>
}