[Fixes #7486] Possibility of exporting individual Form Submissions (#7495)

This commit is contained in:
Hannan Azam Khan
2017-02-03 01:24:13 +05:00
committed by Sébastien Ros
parent 5a0fe4e105
commit 8c1ffe2564
5 changed files with 92 additions and 18 deletions

View File

@@ -118,6 +118,7 @@
<Content Include="Styles\DynamicForms.min.css" />
<Content Include="Styles\menu.dynamicforms-admin.css" />
<Content Include="Styles\menu.dynamicforms.png" />
<Content Include="Styles\recipebuilderstep-forms.css" />
<Content Include="Styles\workflows-activity-add-model-error.css" />
<Content Include="Styles\workflows-activity-dynamic-form-submitted.css" />
<Content Include="Styles\workflows-activity-dynamic-form-validating.css" />
@@ -304,6 +305,7 @@
<Compile Include="Validators\TextAreaValidator.cs" />
<Compile Include="Validators\TextFieldValidator.cs" />
<Compile Include="Validators\UrlFieldValidator.cs" />
<Compile Include="ViewModels\FormExportEntry.cs" />
<Compile Include="ViewModels\FieldValidationSettings.cs" />
<Compile Include="ViewModels\FormBindingSettings.cs" />
<Compile Include="Helpers\ContentTypeDefinitionExtensions.cs" />
@@ -549,6 +551,9 @@
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\BuilderSteps\FormSubmissions.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@@ -3,12 +3,17 @@ using System.Xml.Linq;
using Orchard.DynamicForms.Services;
using Orchard.Localization;
using Orchard.Recipes.Services;
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.DynamicForms.ViewModels;
namespace Orchard.DynamicForms.Recipes.Builders {
public class FormSubmissionsStep : RecipeBuilderStep {
private readonly IFormService _formService;
public FormSubmissionsStep(IFormService formService) {
_formService = formService;
SelectedForms = new List<string>();
}
public override string Name {
@@ -23,29 +28,43 @@ namespace Orchard.DynamicForms.Recipes.Builders {
get { return T("Exports submitted forms."); }
}
public IList<string> SelectedForms { get; set; }
public override dynamic BuildEditor(dynamic shapeFactory) {
// TODO: Implement an editor that enables the user to select which forms to export.
return null;
return UpdateEditor(shapeFactory, null);
}
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
List<FormExportEntry> forms = new List<FormExportEntry>();
if (updater != null && updater.TryUpdateModel(forms, Prefix, null, null)) {
SelectedForms = forms.Where(x => x.Export).Select(x => x.FormName).ToList();
}
else {
forms = _formService.GetSubmissions().OrderBy(x => x.FormName).GroupBy(y => y.FormName)
.Select(x => new FormExportEntry { FormName = x.FirstOrDefault().FormName })
.ToList();
}
return shapeFactory.EditorTemplate(TemplateName: "BuilderSteps/FormSubmissions", Model: forms, Prefix: Prefix);
}
public override void Build(BuildContext context) {
var submissions = _formService.GetSubmissions().ToArray();
if (SelectedForms.Count() > 0) {
var root = new XElement("Forms");
context.RecipeDocument.Element("Orchard").Add(root);
if (!submissions.Any()) {
return;
}
var forms = submissions.GroupBy(x => x.FormName);
var root = new XElement("Forms");
context.RecipeDocument.Element("Orchard").Add(root);
foreach (var form in forms) {
root.Add(new XElement("Form",
new XAttribute("Name", form.Key),
new XElement("Submissions", form.Select(submission =>
new XElement("Submission",
new XAttribute("CreatedUtc", submission.CreatedUtc),
new XCData(submission.FormData))))));
foreach (var form in SelectedForms) {
var submissions = _formService.GetSubmissions(form);
if (submissions.Count() > 0) {
root.Add(new XElement("Form",
new XAttribute("Name", form),
new XElement("Submissions", submissions.Select(submission =>
new XElement("Submission",
new XAttribute("CreatedUtc", submission.CreatedUtc),
new XCData(submission.FormData))))));
}
}
}
}
}

View File

@@ -0,0 +1,9 @@
fieldset.recipe-builder-step-form-submissions table.items {
width: 500px;
margin: 0;
}
fieldset.recipe-builder-step-form-submissions table.items td,
fieldset.recipe-builder-step-form-submissions table.items thead tr.sub th {
padding: 0 12px;
}

View File

@@ -0,0 +1,6 @@
namespace Orchard.DynamicForms.ViewModels {
public class FormExportEntry {
public string FormName { get; set; }
public bool Export { get; set; }
}
}

View File

@@ -0,0 +1,35 @@
@model List<FormExportEntry>
@using Orchard.DynamicForms.ViewModels;
@{
Style.Include("recipebuilderstep-forms.css");
}
<div>
<table class="items">
<thead>
<tr>
<th>@T("Form")</th>
<th>
<input type="checkbox" class="check-all-in-column" />
@T("Select All")
</th>
</tr>
</thead>
<tbody>
@for (int index = 0; index < Model.Count(); index++) {
var entry = Model.ElementAt(index);
<tr>
<td>@entry.FormName</td>
<td>
<input type="hidden" name="@Html.NameFor(m => m[index].FormName)" value="@entry.FormName" />
<input type="checkbox" class="check-data" name="@Html.NameFor(m => m[index].Export)" value="true" />
</td>
</tr>
}
</tbody>
</table>
@Html.Hint(T("Choose the forms to include in the export file"))
</div>