Refactored Dynamic Forms Submissions import/export step.

This commit is contained in:
Sipke Schoorstra
2015-07-17 13:21:34 +01:00
parent 860282bb44
commit 2507ef17d3
5 changed files with 37 additions and 49 deletions

View File

@@ -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");
}
}
}

View File

@@ -27,10 +27,10 @@ Features:
Category: Forms Category: Forms
Dependencies: Orchard.DynamicForms, Orchard.Projections Dependencies: Orchard.DynamicForms, Orchard.Projections
Orchard.DynamicForms.ImportExport: Orchard.DynamicForms.ImportExport:
Name: Dynamic Forms Import Export Name: Dynamic Forms Submissions Import Export
Description: Enables the import and export of form submissions. Description: Enables the import and export of form submissions.
Category: Forms Category: Forms
Dependencies: Orchard.DynamicForms, Orchard.ImportExport Dependencies: Orchard.DynamicForms
Orchard.DynamicForms.Activities.Validation: Orchard.DynamicForms.Activities.Validation:
Name: Dynamic Forms Validation Activities Name: Dynamic Forms Validation Activities
Description: Adds activities for form validation. Description: Adds activities for form validation.

View File

@@ -264,9 +264,8 @@
<Compile Include="Helpers\StreamExtensions.cs" /> <Compile Include="Helpers\StreamExtensions.cs" />
<Compile Include="Helpers\DataTableExtensions.cs" /> <Compile Include="Helpers\DataTableExtensions.cs" />
<Compile Include="Helpers\TokenizerExtensions.cs" /> <Compile Include="Helpers\TokenizerExtensions.cs" />
<Compile Include="ImportExport\FormsExportStep.cs" /> <Compile Include="Recipes\Builders\FormSubmissionsStep.cs" />
<Compile Include="ImportExport\FormsExportHandler.cs" /> <Compile Include="Recipes\Executors\FormSubmissionsStep.cs" />
<Compile Include="ImportExport\FormsImportHandler.cs" />
<Compile Include="Services\IDynamicFormEventHandler.cs" /> <Compile Include="Services\IDynamicFormEventHandler.cs" />
<Compile Include="Services\Models\FieldValidatorDescriptor.cs" /> <Compile Include="Services\Models\FieldValidatorDescriptor.cs" />
<Compile Include="Services\Models\FormSubmittedEventContext.cs" /> <Compile Include="Services\Models\FormSubmittedEventContext.cs" />

View File

@@ -1,32 +1,39 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Orchard.DynamicForms.Services; using Orchard.DynamicForms.Services;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
using Orchard.Events; using Orchard.Localization;
using Orchard.Recipes.Services;
namespace Orchard.DynamicForms.ImportExport {
public interface IExportEventHandler : IEventHandler {
void Exporting(dynamic context);
void Exported(dynamic context);
}
namespace Orchard.DynamicForms.Recipes.Builders {
[OrchardFeature("Orchard.DynamicForms.ImportExport")] [OrchardFeature("Orchard.DynamicForms.ImportExport")]
public class FormsExportHandler : IExportEventHandler { public class FormSubmissionsStep : RecipeBuilderStep {
private readonly IFormService _formService; private readonly IFormService _formService;
public FormsExportHandler(IFormService formService) { public FormSubmissionsStep(IFormService formService) {
_formService = 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")) { public override LocalizedString Description
return; {
} 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(); var submissions = _formService.GetSubmissions().ToArray();
if (!submissions.Any()) { if (!submissions.Any()) {
@@ -35,7 +42,7 @@ namespace Orchard.DynamicForms.ImportExport {
var forms = submissions.GroupBy(x => x.FormName); var forms = submissions.GroupBy(x => x.FormName);
var root = new XElement("Forms"); var root = new XElement("Forms");
context.Document.Element("Orchard").Add(root); context.RecipeDocument.Element("Orchard").Add(root);
foreach (var form in forms) { foreach (var form in forms) {
root.Add(new XElement("Form", root.Add(new XElement("Form",

View File

@@ -6,20 +6,20 @@ using Orchard.Environment.Extensions;
using Orchard.Recipes.Models; using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
namespace Orchard.DynamicForms.ImportExport { namespace Orchard.DynamicForms.Recipes.Executors {
[OrchardFeature("Orchard.DynamicForms.ImportExport")] [OrchardFeature("Orchard.DynamicForms.ImportExport")]
public class FormsImportHandler : Component, IRecipeHandler { public class FormSubmissionsStep : RecipeExecutionStep {
private readonly IFormService _formService; private readonly IFormService _formService;
public FormsImportHandler(IFormService formService) { public FormSubmissionsStep(IFormService formService) {
_formService = formService; _formService = formService;
} }
public void ExecuteRecipeStep(RecipeContext recipeContext) { public override string Name
if (!String.Equals(recipeContext.RecipeStep.Name, "Forms", StringComparison.OrdinalIgnoreCase)) { {
return; get { return "Forms"; }
} }
public override void Execute(RecipeExecutionContext context) {
var formsElement = recipeContext.RecipeStep.Step.Elements(); var formsElement = context.RecipeStep.Step.Elements();
foreach (var formElement in formsElement) { foreach (var formElement in formsElement) {
var formName = formElement.Attr<string>("Name"); var formName = formElement.Attr<string>("Name");
var submissionElements = formElement.Element("Submissions").Elements(); var submissionElements = formElement.Element("Submissions").Elements();
@@ -32,8 +32,6 @@ namespace Orchard.DynamicForms.ImportExport {
}); });
} }
} }
recipeContext.Executed = true;
} }
} }
} }