Added configuration upload to Export screen.

This commit is contained in:
Sipke Schoorstra
2015-07-20 17:13:28 +01:00
parent 4c962b2f66
commit b0177ab7b8
5 changed files with 84 additions and 38 deletions

View File

@@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Xml.Linq;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ImportExport.Models; using Orchard.ImportExport.Models;
using Orchard.ImportExport.Services; using Orchard.ImportExport.Services;
@@ -13,10 +15,12 @@ namespace Orchard.ImportExport.Providers.ExportActions {
public class BuildRecipeAction : ExportAction { public class BuildRecipeAction : ExportAction {
private readonly IEnumerable<IRecipeBuilderStep> _recipeBuilderSteps; private readonly IEnumerable<IRecipeBuilderStep> _recipeBuilderSteps;
private readonly IRecipeBuilder _recipeBuilder; private readonly IRecipeBuilder _recipeBuilder;
private readonly IOrchardServices _orchardServices;
public BuildRecipeAction(IEnumerable<IRecipeBuilderStep> recipeBuilderSteps, IRecipeBuilder recipeBuilder) { public BuildRecipeAction(IEnumerable<IRecipeBuilderStep> recipeBuilderSteps, IRecipeBuilder recipeBuilder, IOrchardServices orchardServices) {
_recipeBuilderSteps = recipeBuilderSteps; _recipeBuilderSteps = recipeBuilderSteps;
_recipeBuilder = recipeBuilder; _recipeBuilder = recipeBuilder;
_orchardServices = orchardServices;
RecipeBuilderSteps = new List<IRecipeBuilderStep>(); RecipeBuilderSteps = new List<IRecipeBuilderStep>();
} }
@@ -44,18 +48,30 @@ namespace Orchard.ImportExport.Providers.ExportActions {
if (updater != null) { if (updater != null) {
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) { if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
var exportStepNames = viewModel.Steps.Where(x => x.IsSelected).Select(x => x.Name); if (viewModel.UploadConfigurationFile) {
var stepsQuery = from name in exportStepNames var configurationFile = _orchardServices.WorkContext.HttpContext.Request.Files["ConfigurationFile"];
let provider = _recipeBuilderSteps.SingleOrDefault(x => x.Name == name)
where provider != null
select provider;
var steps = stepsQuery.ToArray();
var stepUpdater = new Updater(updater, secondHalf => String.Format("{0}.{1}", Prefix, secondHalf));
foreach (var exportStep in steps) {
exportStep.UpdateEditor(shapeFactory, stepUpdater);
}
RecipeBuilderSteps = steps; if (configurationFile.ContentLength == 0)
updater.AddModelError("ConfigurationFile", T("No configuration file was specified."));
else {
var configurationDocument = XDocument.Parse(new StreamReader(configurationFile.InputStream).ReadToEnd());
Configure(new ExportActionConfigurationContext(configurationDocument.Root.Element(Name)));
}
}
else {
var exportStepNames = viewModel.Steps.Where(x => x.IsSelected).Select(x => x.Name);
var stepsQuery = from name in exportStepNames
let provider = _recipeBuilderSteps.SingleOrDefault(x => x.Name == name)
where provider != null
select provider;
var steps = stepsQuery.ToArray();
var stepUpdater = new Updater(updater, secondHalf => String.Format("{0}.{1}", Prefix, secondHalf));
foreach (var exportStep in steps) {
exportStep.UpdateEditor(shapeFactory, stepUpdater);
}
RecipeBuilderSteps = steps;
}
} }
} }

View File

@@ -2,6 +2,7 @@
namespace Orchard.ImportExport.ViewModels { namespace Orchard.ImportExport.ViewModels {
public class RecipeBuilderViewModel { public class RecipeBuilderViewModel {
public bool UploadConfigurationFile { get; set; }
public IList<ExportStepViewModel> Steps { get; set; } public IList<ExportStepViewModel> Steps { get; set; }
} }
} }

View File

@@ -1,9 +1,9 @@
@model Orchard.ImportExport.ViewModels.ExportViewModel @model Orchard.ImportExport.ViewModels.ExportViewModel
@{ Layout.Title = T("Export").ToString(); } @{ Layout.Title = T("Export").ToString(); }
@using (Html.BeginFormAntiForgeryPost()) { @using (Html.BeginFormAntiForgeryPost(Url.Action("Export", new { area = "Orchard.ImportExport" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
Html.ValidationSummary(); Html.ValidationSummary();
foreach(var action in Model.Actions) { foreach (var action in Model.Actions) {
<div class="export-action"> <div class="export-action">
@Display(action.Editor) @Display(action.Editor)
</div> </div>

View File

@@ -4,28 +4,57 @@
Script.Require("ShapesBase"); Script.Require("ShapesBase");
} }
@{ @{
var stepIndex = 0; var exportOptions = new[] {
var steps = Model.Steps.Where(x => x.IsVisible).ToArray(); new SelectListItem { Text = T("Select the recipe steps to execute").ToString(), Value = "false", Selected = !Model.UploadConfigurationFile},
foreach (var step in steps) { new SelectListItem { Text = T("Upload a configuration file with recipe steps to execute").ToString(), Value = "true", Selected = Model.UploadConfigurationFile},
var stepName = Html.NameFor(m => m.Steps[stepIndex].IsSelected).ToString(); };
var stepId = stepName.HtmlClassify(); }
<div>
<fieldset class="recipe-builder-step recipe-builder-step-@step.Name.HtmlClassify()"> <fieldset>
<legend> <legend>
<input type="hidden" name="@Html.NameFor(m => m.Steps[stepIndex].Name)" value="@steps[stepIndex].Name" /> @T("Export Options")
<input type="checkbox" id="@stepId" name="@stepName" value="true" /> </legend>
<label for="@stepId" class="forcheckbox">@step.DisplayName</label> <ul>
</legend> @foreach (var option in exportOptions) {
@Html.Hint(step.Description) var exportOptionId = String.Format("{0}_{1}", Html.FieldIdFor(m => m.UploadConfigurationFile), option.Value);
@if (step.Editor != null) { <li>
<div data-controllerid="@stepId"> <input type="radio" id="@exportOptionId" name="@Html.FieldNameFor(m => m.UploadConfigurationFile)" value="@option.Value" @if (option.Selected) { <text> checked="checked" </text> }/>
@Display(step.Editor) <label for="@exportOptionId" class="forradiobutton">@option.Text</label>
</div> </li>
} }
</fieldset> </ul>
stepIndex++; </fieldset>
if (stepIndex < steps.Count()) { </div>
<hr /> <div data-controllerid="@String.Format("{0}_{1}", Html.FieldIdFor(m => m.UploadConfigurationFile), "false")">
@{
var stepIndex = 0;
var steps = Model.Steps.Where(x => x.IsVisible).ToArray();
foreach (var step in steps) {
var stepName = Html.NameFor(m => m.Steps[stepIndex].IsSelected).ToString();
var stepId = stepName.HtmlClassify();
if (stepIndex <= steps.Count()) {
<hr />
}
<fieldset class="recipe-builder-step recipe-builder-step-@step.Name.HtmlClassify()">
<legend>
<input type="hidden" name="@Html.NameFor(m => m.Steps[stepIndex].Name)" value="@steps[stepIndex].Name"/>
<input type="checkbox" id="@stepId" name="@stepName" value="true"/>
<label for="@stepId" class="forcheckbox">@step.DisplayName</label>
</legend>
@Html.Hint(step.Description)
@if (step.Editor != null) {
<div data-controllerid="@stepId">
@Display(step.Editor)
</div>
}
</fieldset>
stepIndex++;
} }
} }
} </div>
<div data-controllerid="@String.Format("{0}_{1}", Html.FieldIdFor(m => m.UploadConfigurationFile), "true")" style="display: none;">
<fieldset>
<label for="ConfigurationFile">@T("Configuration File")</label>
<input type="file" id="ConfigurationFile" size="64" name="ConfigurationFile" value="@T("Browse...")" />
</fieldset>
</div>

View File

@@ -4,7 +4,7 @@
Script.Require("ShapesBase"); Script.Require("ShapesBase");
} }
@{ @{
var importOptions = new SelectListItem[] { var importOptions = new[] {
new SelectListItem { Text = T("Import the uploaded recipe").ToString(), Value = "false", Selected = !Model.ResetSite}, new SelectListItem { Text = T("Import the uploaded recipe").ToString(), Value = "false", Selected = !Model.ResetSite},
new SelectListItem { Text = T("Reset the site and run setup using the uploaded recipe").ToString(), Value = "true", Selected = Model.ResetSite}, new SelectListItem { Text = T("Reset the site and run setup using the uploaded recipe").ToString(), Value = "true", Selected = Model.ResetSite},
}; };
@@ -13,7 +13,7 @@
@T("Choose a recipe file to import. Please consider {0} or backing up your data first.", @Html.Link(T("exporting").Text, Url.Action("Export", "Admin", new { area = "Orchard.ImportExport" }))) @T("Choose a recipe file to import. Please consider {0} or backing up your data first.", @Html.Link(T("exporting").Text, Url.Action("Export", "Admin", new { area = "Orchard.ImportExport" })))
</p> </p>
<fieldset> <fieldset>
<label for="RecipeFile">@T("Recipe File:")</label> <label for="RecipeFile">@T("Recipe File")</label>
<input type="file" id="RecipeFile" size="64" name="RecipeFile" value="@T("Browse...")"/> <input type="file" id="RecipeFile" size="64" name="RecipeFile" value="@T("Browse...")"/>
</fieldset> </fieldset>
<fieldset> <fieldset>