Hooked up dependeny checks and messages for unsatisified feature dependencies on enable/disable

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-05-18 10:04:14 -07:00
parent e00dd3d34c
commit 0f5d492333
4 changed files with 56 additions and 17 deletions

View File

@@ -59,7 +59,6 @@ namespace Orchard.Modules.Controllers {
return new NotFoundResult();
_moduleService.EnableFeatures(new [] {id});
Services.Notifier.Information(T("{0} was enabled", id));
return RedirectToAction("Features");
}
@@ -73,7 +72,6 @@ namespace Orchard.Modules.Controllers {
return new NotFoundResult();
_moduleService.DisableFeatures(new[] { id });
//Services.Notifier.Information(T("{0} was disabled", featureName));
return RedirectToAction("Features");
}

View File

@@ -6,7 +6,9 @@ using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Topology;
using Orchard.Environment.Topology.Models;
using Orchard.Localization;
using Orchard.Modules.Models;
using Orchard.UI.Notify;
namespace Orchard.Modules.Services {
public class ModuleService : IModuleService {
@@ -14,11 +16,16 @@ namespace Orchard.Modules.Services {
private readonly IExtensionManager _extensionManager;
private readonly IShellDescriptorManager _shellDescriptorManager;
public ModuleService(IExtensionManager extensionManager, IShellDescriptorManager shellDescriptorManager) {
public ModuleService(IOrchardServices orchardServices,IExtensionManager extensionManager, IShellDescriptorManager shellDescriptorManager) {
Services = orchardServices;
_extensionManager = extensionManager;
_shellDescriptorManager = shellDescriptorManager;
T = NullLocalizer.Instance;
}
private Localizer T { get; set; }
public IOrchardServices Services { get; set; }
public IModule GetModuleByName(string moduleName) {
return _extensionManager.AvailableExtensions().Where(e => string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase) && string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase)).Select(
descriptor => AssembleModuleFromDescriptor(descriptor)).FirstOrDefault();
@@ -60,9 +67,32 @@ namespace Orchard.Modules.Services {
public void EnableFeatures(IEnumerable<string> featureNames) {
var shellDescriptor = _shellDescriptorManager.GetShellDescriptor();
var enabledFeatures = shellDescriptor.EnabledFeatures.ToList();
var features = GetAvailableFeatures().ToList();
var enabledFeatures = shellDescriptor.EnabledFeatures
.Union(featureNames.Select(s => new ShellFeature {Name = s}));
foreach (var name in featureNames) {
var featureName = name;
var feature = features.Single(f => f.Descriptor.Name == featureName);
var sleepingDependencies =
feature.Descriptor.Dependencies.Where(s => enabledFeatures.FirstOrDefault(sf => sf.Name == s) == null);
if (sleepingDependencies.Count() != 0) {
Services.Notifier.Warning(T(
"If you want to enable {0}, then you'll also need {1} (and I won't let you flip everything on in one go yet).",
featureName,
sleepingDependencies.Count() > 1
? string.Join("",
sleepingDependencies.Select(
(s, i) =>
i == sleepingDependencies.Count() - 2
? T("{0} and ", s).ToString()
: T("{0}, ", s).ToString()).ToArray())
: sleepingDependencies.First()));
} else if (enabledFeatures.FirstOrDefault(f => f.Name == featureName) == null) {
enabledFeatures.Add(new ShellFeature {Name = featureName});
Services.Notifier.Information(T("{0} was enabled", featureName));
}
}
_shellDescriptorManager.UpdateShellDescriptor(shellDescriptor.SerialNumber, enabledFeatures, shellDescriptor.Parameters);
}
@@ -72,15 +102,26 @@ namespace Orchard.Modules.Services {
var enabledFeatures = shellDescriptor.EnabledFeatures.ToList();
var features = GetAvailableFeatures().ToList();
foreach (var featureName in featureNames) {
var feature = featureName;
var dependants = features.Where(f => f.IsEnabled && f.Descriptor.Dependencies != null && f.Descriptor.Dependencies.Contains(feature));
foreach (var name in featureNames) {
var featureName = name;
var dependants = features.Where(f => f.IsEnabled && f.Descriptor.Dependencies != null && f.Descriptor.Dependencies.Contains(featureName));
if (dependants.Count() == 0) {
enabledFeatures.RemoveAll(f => f.Name == feature);
if (dependants.Count() != 0) {
Services.Notifier.Warning(T(
"If you want to disable {0}, then you'll also lose {1} (and I won't let you do that yet).",
featureName,
dependants.Count() > 0
? string.Join("",
dependants.Select(
(f, i) =>
i == dependants.Count() - 2
? T("{0} and ", f.Descriptor.Name).ToString()
: T("{0}, ", f.Descriptor.Name).ToString()).ToArray())
: dependants.First().Descriptor.Name));
}
else {
// list what else will be disabled with ok/cancel
enabledFeatures.RemoveAll(f => f.Name == featureName);
Services.Notifier.Information(T("{0} was disabled", featureName));
}
}

View File

@@ -45,12 +45,12 @@
</div>
<div class="actions"><%
if (feature.IsEnabled) {
using (Html.BeginFormAntiForgeryPost(string.Format("{0}#{1}", Url.Action("Disable", new { area = "Orchard.Modules" }), featureId), FormMethod.Post, new {@class = "inline link"})) { %>
using (Html.BeginFormAntiForgeryPost(string.Format("{0}", Url.Action("Disable", new { area = "Orchard.Modules" })), FormMethod.Post, new {@class = "inline link"})) { %>
<%=Html.Hidden("id", feature.Descriptor.Name, new { id = "" })%>
<button type="submit"><%=_Encoded("Disable") %></button><%
}
} else {
using (Html.BeginFormAntiForgeryPost(string.Format("{0}#{1}", Url.Action("Enable", new { area = "Orchard.Modules" }), featureId), FormMethod.Post, new {@class = "inline link"})) { %>
using (Html.BeginFormAntiForgeryPost(string.Format("{0}", Url.Action("Enable", new { area = "Orchard.Modules" })), FormMethod.Post, new {@class = "inline link"})) { %>
<%=Html.Hidden("id", feature.Descriptor.Name, new { id = "" })%>
<button type="submit"><%=_Encoded("Enable") %></button><%
}

View File

@@ -320,8 +320,8 @@ span.message {
}
.confirmation.message {
background:#e6f1c9; /* green */
border:1px solid #cfe493;
background:#D1F2A5; /* green */
border:1px solid #BCD994;
}
.warning.message {
background:#fdf5bc; /* yellow */
@@ -337,8 +337,8 @@ span.message {
color:#fff;
}
.info.message {
background:#e6f1c9; /* green*/
border:1px solid #d4deb9;
background:#D1F2A5; /* green*/
border:1px solid #BCD994;
color:#062232;
}
.debug.message {