mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Recipes: Code styling and simplifications for 41cdb8e852
This commit is contained in:
parent
41cdb8e852
commit
bae1bc6763
@ -2,26 +2,22 @@
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Recipes
|
||||
{
|
||||
public class AdminMenu : INavigationProvider
|
||||
{
|
||||
namespace Orchard.Recipes {
|
||||
public class AdminMenu : INavigationProvider {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public string MenuName
|
||||
{
|
||||
public string MenuName {
|
||||
get { return "admin"; }
|
||||
}
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder)
|
||||
{
|
||||
builder.AddImageSet("modules")
|
||||
.Add(T("Modules"), "9", BuildMenu);
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.AddImageSet("modules").Add(T("Modules"), "9", BuildMenu);
|
||||
}
|
||||
|
||||
private void BuildMenu(NavigationItemBuilder menu)
|
||||
{
|
||||
menu.Add(T("Recipes"), "2", item => item.Action("Index", "Admin", new { area = "Orchard.Recipes" }).Permission(StandardPermissions.SiteOwner).LocalNav());
|
||||
private void BuildMenu(NavigationItemBuilder menu) {
|
||||
menu.Add(T("Recipes"), "2", item => item
|
||||
.Action("Index", "Admin", new { area = "Orchard.Recipes" })
|
||||
.Permission(StandardPermissions.SiteOwner).LocalNav());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Configuration;
|
||||
@ -8,19 +6,15 @@ using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.Recipes.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
|
||||
namespace Orchard.Recipes.Controllers
|
||||
{
|
||||
namespace Orchard.Recipes.Controllers {
|
||||
[Admin]
|
||||
public class AdminController : Controller
|
||||
{
|
||||
public class AdminController : Controller {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IRecipeHarvester _recipeHarvester;
|
||||
private readonly IRecipeManager _recipeManager;
|
||||
@ -34,15 +28,13 @@ namespace Orchard.Recipes.Controllers
|
||||
IRecipeManager recipeManager,
|
||||
IRecipeResultAccessor recipeResultAccessor,
|
||||
ShellSettings shellSettings,
|
||||
IShapeFactory shapeFactory)
|
||||
{
|
||||
IShapeFactory shapeFactory) {
|
||||
Services = services;
|
||||
_extensionManager = extensionManager;
|
||||
_recipeHarvester = recipeHarvester;
|
||||
_recipeManager = recipeManager;
|
||||
_recipeResultAccessor = recipeResultAccessor;
|
||||
_shellSettings = shellSettings;
|
||||
Shape = shapeFactory;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
@ -51,83 +43,70 @@ namespace Orchard.Recipes.Controllers
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
public dynamic Shape { get; set; }
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
public ActionResult Index() {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to execute recipe files.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
IEnumerable<ModuleEntry> modules = _extensionManager.AvailableExtensions()
|
||||
var modules = _extensionManager.AvailableExtensions()
|
||||
.Where(extensionDescriptor => ExtensionIsAllowed(extensionDescriptor))
|
||||
.OrderBy(extensionDescriptor => extensionDescriptor.Name)
|
||||
.Select(extensionDescriptor => new ModuleEntry { Descriptor = extensionDescriptor });
|
||||
.OrderBy(extensionDescriptor => extensionDescriptor.Name);
|
||||
|
||||
var viewModel = new RecipesViewModel();
|
||||
|
||||
if (_recipeHarvester != null)
|
||||
{
|
||||
viewModel.Modules = modules.Select(x => new ModuleRecipesViewModel
|
||||
{
|
||||
Module = x,
|
||||
Recipes = _recipeHarvester.HarvestRecipes(x.Descriptor.Id).Where(recipe => !recipe.IsSetupRecipe).ToList()
|
||||
})
|
||||
.Where(x => x.Recipes.Any())
|
||||
.ToList();
|
||||
}
|
||||
var viewModel = new RecipesViewModel {
|
||||
Modules = modules
|
||||
.Select(x => new ModuleRecipesViewModel {
|
||||
Descriptor = x,
|
||||
Recipes = _recipeHarvester.HarvestRecipes(x.Id).Where(recipe => !recipe.IsSetupRecipe).ToList()
|
||||
})
|
||||
.Where(x => x.Recipes.Any())
|
||||
.ToList()
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("Recipes")]
|
||||
public ActionResult RecipesPOST(string moduleId, string name)
|
||||
{
|
||||
public ActionResult RecipesPOST(string moduleId, string name) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to execute recipe files.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
ModuleEntry module = _extensionManager.AvailableExtensions()
|
||||
var module = _extensionManager.AvailableExtensions()
|
||||
.Where(extensionDescriptor => extensionDescriptor.Id == moduleId && ExtensionIsAllowed(extensionDescriptor))
|
||||
.Select(extensionDescriptor => new ModuleEntry { Descriptor = extensionDescriptor }).FirstOrDefault();
|
||||
.FirstOrDefault();
|
||||
|
||||
if (module == null)
|
||||
{
|
||||
if (module == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
Recipe recipe = _recipeHarvester.HarvestRecipes(module.Descriptor.Id).FirstOrDefault(x => !x.IsSetupRecipe && x.Name == name);
|
||||
var recipe = _recipeHarvester.HarvestRecipes(module.Id).FirstOrDefault(x => !x.IsSetupRecipe && x.Name == name);
|
||||
|
||||
if (recipe == null)
|
||||
{
|
||||
if (recipe == null) {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
var executionId = _recipeManager.Execute(recipe);
|
||||
|
||||
if (String.IsNullOrEmpty(executionId))
|
||||
{
|
||||
if (string.IsNullOrEmpty(executionId)) {
|
||||
Logger.Error("Error while executing recipe {0} in {1}.", name, moduleId);
|
||||
|
||||
Services.Notifier.Error(T("Error while executing recipe {0} in {1}.", name, moduleId));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("RecipeResult", new { executionId = executionId });
|
||||
else {
|
||||
return RedirectToAction("RecipeResult", new { executionId });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ActionResult RecipeResult(string executionId)
|
||||
{
|
||||
public ActionResult RecipeResult(string executionId) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to view recipe file execution results.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var result = _recipeResultAccessor.GetResult(executionId);
|
||||
|
||||
var viewModel = new RecipeResultViewModel()
|
||||
{
|
||||
var viewModel = new RecipeResultViewModel() {
|
||||
Result = result
|
||||
};
|
||||
|
||||
@ -136,10 +115,9 @@ namespace Orchard.Recipes.Controllers
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the module is allowed for the current tenant
|
||||
/// Checks whether the given Extension is allowed for the current Tenant.
|
||||
/// </summary>
|
||||
private bool ExtensionIsAllowed(ExtensionDescriptor extensionDescriptor)
|
||||
{
|
||||
private bool ExtensionIsAllowed(ExtensionDescriptor extensionDescriptor) {
|
||||
return _shellSettings.Modules.Length == 0 || _shellSettings.Modules.Contains(extensionDescriptor.Id);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Recipes.Models {
|
||||
/// <summary>
|
||||
/// Represents a module.
|
||||
/// </summary>
|
||||
public class ModuleEntry {
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public ModuleEntry() {
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The module's extension descriptor.
|
||||
/// </summary>
|
||||
public ExtensionDescriptor Descriptor { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -118,7 +118,6 @@
|
||||
<Compile Include="Commands\RecipesCommands.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Models\ModuleEntry.cs" />
|
||||
<Compile Include="Models\RecipeResultRecord.cs" />
|
||||
<Compile Include="Models\RecipeStepResultRecord.cs" />
|
||||
<Compile Include="Models\VersionHistoryOptions.cs" />
|
||||
|
@ -46,7 +46,7 @@ namespace Orchard.Recipes.Services {
|
||||
|
||||
private IEnumerable<Recipe> HarvestRecipes(ExtensionDescriptor extension) {
|
||||
var recipes = new List<Recipe>();
|
||||
|
||||
|
||||
var recipeLocation = Path.Combine(extension.Location, extension.Id, "Recipes");
|
||||
var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true);
|
||||
|
||||
@ -58,7 +58,7 @@ namespace Orchard.Recipes.Services {
|
||||
Logger.Error(ex, "Error while parsing recipe file '{0}'.", r);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return recipes;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Recipes.Models;
|
||||
|
||||
namespace Orchard.Recipes.ViewModels {
|
||||
@ -7,7 +8,7 @@ namespace Orchard.Recipes.ViewModels {
|
||||
}
|
||||
|
||||
public class ModuleRecipesViewModel {
|
||||
public ModuleEntry Module { get; set; }
|
||||
public IEnumerable<Recipe> Recipes { get; set; }
|
||||
public ExtensionDescriptor Descriptor { get; set; }
|
||||
public IEnumerable<Recipe> Recipes { get; set; }
|
||||
}
|
||||
}
|
@ -1,26 +1,24 @@
|
||||
@using Orchard.Utility.Extensions
|
||||
|
||||
@model Orchard.Recipes.ViewModels.RecipesViewModel
|
||||
|
||||
@{
|
||||
Layout.Title = T("Recipes");
|
||||
}
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
if (Model.Modules.Any()) {
|
||||
<ul class="contentItems">
|
||||
@foreach (var moduleEntry in Model.Modules.OrderBy(m => m.Module.Descriptor.Name)) {
|
||||
var module = moduleEntry.Module;
|
||||
var descriptor = module.Descriptor;
|
||||
|
||||
@foreach (var module in Model.Modules.OrderBy(m => m.Descriptor.Name)) {
|
||||
<li>
|
||||
<div class="summary">
|
||||
<div class="properties">
|
||||
<h2>@descriptor.Name<span> - @T("Version: {0}", !string.IsNullOrEmpty(descriptor.Version) ? descriptor.Version : T("1.0").ToString())</span></h2>
|
||||
<h2>@module.Descriptor.Name<span> - @T("Version: {0}", !string.IsNullOrEmpty(module.Descriptor.Version) ? module.Descriptor.Version : T("1.0").ToString())</span></h2>
|
||||
|
||||
|
||||
@foreach (var recipe in moduleEntry.Recipes) {
|
||||
@foreach (var recipe in module.Recipes) {
|
||||
<br />
|
||||
<div>
|
||||
<h4>@recipe.Name.CamelFriendly() - @Html.ActionLink(T("Execute").Text, "Recipes", "Admin", new { area = "Orchard.Recipes", moduleId = descriptor.Id, name = recipe.Name }, new { itemprop = "UnsafeUrl" })</h4>
|
||||
<h4>@recipe.Name.CamelFriendly() - @Html.ActionLink(T("Execute").Text, "Recipes", "Admin", new { area = "Orchard.Recipes", moduleId = module.Descriptor.Id, name = recipe.Name }, new { itemprop = "UnsafeUrl" })</h4>
|
||||
<p>@(!string.IsNullOrEmpty(recipe.Description) ? recipe.Description : T("No description").ToString())</p>
|
||||
</div>
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
@model Orchard.Recipes.ViewModels.RecipeResultViewModel
|
||||
|
||||
@{
|
||||
Layout.Title = T("Recipe File Execution Result").ToString();
|
||||
}
|
||||
|
||||
@if (Model.Result.IsSuccessful) {
|
||||
<div class="message message-Information">
|
||||
@T("The recipe file was successfully executed.")
|
||||
@ -12,6 +14,7 @@ else {
|
||||
@T("The recipe file execution failed. Check the logs (recipe execution ID <strong>{0}</strong>) for more information.", Model.Result.ExecutionId)
|
||||
</div>
|
||||
}
|
||||
|
||||
<h2>@T("Recipe steps")</h2>
|
||||
<table class="items" style="width: auto;">
|
||||
<thead>
|
||||
|
Loading…
Reference in New Issue
Block a user