mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-09 11:21:04 +08:00
Refactored Dynamic Forms Submissions import/export step.
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.DynamicForms.ImportExport {
|
||||
public interface ICustomExportStep : IEventHandler {
|
||||
void Register(IList<string> steps);
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.DynamicForms.ImportExport")]
|
||||
public class FormsExportStep : ICustomExportStep {
|
||||
public void Register(IList<string> steps) {
|
||||
steps.Add("Forms");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,10 @@ Features:
|
||||
Category: Forms
|
||||
Dependencies: Orchard.DynamicForms, Orchard.Projections
|
||||
Orchard.DynamicForms.ImportExport:
|
||||
Name: Dynamic Forms Import Export
|
||||
Name: Dynamic Forms Submissions Import Export
|
||||
Description: Enables the import and export of form submissions.
|
||||
Category: Forms
|
||||
Dependencies: Orchard.DynamicForms, Orchard.ImportExport
|
||||
Dependencies: Orchard.DynamicForms
|
||||
Orchard.DynamicForms.Activities.Validation:
|
||||
Name: Dynamic Forms Validation Activities
|
||||
Description: Adds activities for form validation.
|
||||
|
||||
@@ -264,9 +264,8 @@
|
||||
<Compile Include="Helpers\StreamExtensions.cs" />
|
||||
<Compile Include="Helpers\DataTableExtensions.cs" />
|
||||
<Compile Include="Helpers\TokenizerExtensions.cs" />
|
||||
<Compile Include="ImportExport\FormsExportStep.cs" />
|
||||
<Compile Include="ImportExport\FormsExportHandler.cs" />
|
||||
<Compile Include="ImportExport\FormsImportHandler.cs" />
|
||||
<Compile Include="Recipes\Builders\FormSubmissionsStep.cs" />
|
||||
<Compile Include="Recipes\Executors\FormSubmissionsStep.cs" />
|
||||
<Compile Include="Services\IDynamicFormEventHandler.cs" />
|
||||
<Compile Include="Services\Models\FieldValidatorDescriptor.cs" />
|
||||
<Compile Include="Services\Models\FormSubmittedEventContext.cs" />
|
||||
|
||||
@@ -1,32 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.DynamicForms.Services;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.DynamicForms.ImportExport {
|
||||
public interface IExportEventHandler : IEventHandler {
|
||||
void Exporting(dynamic context);
|
||||
void Exported(dynamic context);
|
||||
}
|
||||
using Orchard.Localization;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.DynamicForms.Recipes.Builders {
|
||||
[OrchardFeature("Orchard.DynamicForms.ImportExport")]
|
||||
public class FormsExportHandler : IExportEventHandler {
|
||||
public class FormSubmissionsStep : RecipeBuilderStep {
|
||||
private readonly IFormService _formService;
|
||||
public FormsExportHandler(IFormService formService) {
|
||||
public FormSubmissionsStep(IFormService formService) {
|
||||
_formService = formService;
|
||||
}
|
||||
|
||||
public void Exporting(dynamic context) {
|
||||
public override string Name
|
||||
{
|
||||
get { return "FormSubmissions"; }
|
||||
}
|
||||
|
||||
public void Exported(dynamic context) {
|
||||
public override LocalizedString DisplayName
|
||||
{
|
||||
get { return T("Form Submissions"); }
|
||||
}
|
||||
|
||||
if (!((IEnumerable<string>)context.ExportOptions.CustomSteps).Contains("Forms")) {
|
||||
return;
|
||||
}
|
||||
public override LocalizedString Description
|
||||
{
|
||||
get { return T("Exports submitted forms."); }
|
||||
}
|
||||
|
||||
public override dynamic BuildEditor(dynamic shapeFactory) {
|
||||
// TODO: Implement an editor that enables the user to select which forms to export.
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Build(BuildContext context) {
|
||||
var submissions = _formService.GetSubmissions().ToArray();
|
||||
|
||||
if (!submissions.Any()) {
|
||||
@@ -35,7 +42,7 @@ namespace Orchard.DynamicForms.ImportExport {
|
||||
|
||||
var forms = submissions.GroupBy(x => x.FormName);
|
||||
var root = new XElement("Forms");
|
||||
context.Document.Element("Orchard").Add(root);
|
||||
context.RecipeDocument.Element("Orchard").Add(root);
|
||||
|
||||
foreach (var form in forms) {
|
||||
root.Add(new XElement("Form",
|
||||
@@ -6,20 +6,20 @@ using Orchard.Environment.Extensions;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.DynamicForms.ImportExport {
|
||||
namespace Orchard.DynamicForms.Recipes.Executors {
|
||||
[OrchardFeature("Orchard.DynamicForms.ImportExport")]
|
||||
public class FormsImportHandler : Component, IRecipeHandler {
|
||||
public class FormSubmissionsStep : RecipeExecutionStep {
|
||||
private readonly IFormService _formService;
|
||||
public FormsImportHandler(IFormService formService) {
|
||||
public FormSubmissionsStep(IFormService formService) {
|
||||
_formService = formService;
|
||||
}
|
||||
|
||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Forms", StringComparison.OrdinalIgnoreCase)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var formsElement = recipeContext.RecipeStep.Step.Elements();
|
||||
public override string Name
|
||||
{
|
||||
get { return "Forms"; }
|
||||
}
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
var formsElement = context.RecipeStep.Step.Elements();
|
||||
foreach (var formElement in formsElement) {
|
||||
var formName = formElement.Attr<string>("Name");
|
||||
var submissionElements = formElement.Element("Submissions").Elements();
|
||||
@@ -32,8 +32,6 @@ namespace Orchard.DynamicForms.ImportExport {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
recipeContext.Executed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user