Showing allowed modules with dependencies

This commit is contained in:
Sebastien Ros
2014-05-12 15:30:56 -07:00
parent 4525650ffa
commit f327a32895
3 changed files with 66 additions and 49 deletions

View File

@@ -81,7 +81,7 @@ namespace Orchard.Modules.Controllers {
IEnumerable<ModuleEntry> modules = _extensionManager.AvailableExtensions()
.Where(extensionDescriptor => DefaultExtensionTypes.IsModule(extensionDescriptor.ExtensionType) &&
ModuleIsAllowed(extensionDescriptor) &&
(string.IsNullOrEmpty(options.SearchText) || extensionDescriptor.Name.ToLowerInvariant().Contains(options.SearchText.ToLowerInvariant())))
.OrderBy(extensionDescriptor => extensionDescriptor.Name)
.Select(extensionDescriptor => new ModuleEntry { Descriptor = extensionDescriptor });
@@ -174,7 +174,7 @@ namespace Orchard.Modules.Controllers {
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
IEnumerable<ModuleFeature> features = _featureManager.GetAvailableFeatures()
.Where(f => !DefaultExtensionTypes.IsTheme(f.Extension.ExtensionType) && ModuleIsAllowed(f.Extension))
.Where(f => !DefaultExtensionTypes.IsTheme(f.Extension.ExtensionType))
.Select(f => new ModuleFeature {
Descriptor = f,
IsEnabled = _shellDescriptor.Features.Any(sf => sf.Name == f.Id),
@@ -184,7 +184,10 @@ namespace Orchard.Modules.Controllers {
})
.ToList();
return View(new FeaturesViewModel { Features = features });
return View(new FeaturesViewModel {
Features = features,
IsAllowed = ModuleIsAllowed
});
}
[HttpPost, ActionName("Features")]

View File

@@ -1,10 +1,14 @@
using System;
using System.Collections.Generic;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions.Models;
using Orchard.Modules.Models;
namespace Orchard.Modules.ViewModels {
public class FeaturesViewModel {
public IEnumerable<ModuleFeature> Features { get; set; }
public FeaturesBulkAction BulkAction { get; set; }
public Func<ExtensionDescriptor, bool> IsAllowed { get; set; }
}
public enum FeaturesBulkAction {

View File

@@ -36,9 +36,13 @@
</fieldset>
</div>
<ul class="features summary-view switchable">@{
<ul class="features summary-view switchable">
@{
var featureGroups = Model.Features.OrderBy(f => f.Descriptor.Category, new DoghouseComparer("Core")).GroupBy(f => f.Descriptor.Category).ToList();
foreach (var featureGroup in featureGroups) {
if (!featureGroup.Any(x => Model.IsAllowed(x.Descriptor.Extension))) {
continue;
}
var categoryName = LocalizedString.TextOrDefault(featureGroup.First().Descriptor.Category, T("Uncategorized"));
var categoryClassName = string.Format("category {0}", Html.Encode(categoryName.ToString().HtmlClassify()));
if (featureGroup == featureGroups.First()) {
@@ -50,9 +54,13 @@
<li class="@categoryClassName">
<h2>@categoryName</h2>
<ul>@{
<ul>
@{
var features = featureGroup.OrderBy(f => f.Descriptor.Name);
foreach (var feature in features) {
if (!Model.IsAllowed(feature.Descriptor.Extension)) {
continue;
}
//hmmm...I feel like I've done this before...
var featureId = feature.Descriptor.Id.AsFeatureId(n => T(n));
var featureName = string.IsNullOrEmpty(feature.Descriptor.Name) ? feature.Descriptor.Id : feature.Descriptor.Name;
@@ -74,7 +82,7 @@
var missingDependencies = feature.Descriptor.Dependencies
.Where(d => !Model.Features.Any(f => f.Descriptor.Id.Equals(d, StringComparison.OrdinalIgnoreCase)));
var showDisable = categoryName.ToString() != "Core";
var showEnable = !missingDependencies.Any() && feature.Descriptor.Id != "Orchard.Setup";
var showEnable = Model.IsAllowed(feature.Descriptor.Extension) && !missingDependencies.Any() && feature.Descriptor.Id != "Orchard.Setup";
<li class="@featureClassName" id="@featureId" title="@T("{0} is {1}", Html.AttributeEncode(featureName), featureState)">
<div class="summary">
@@ -122,9 +130,11 @@
</div>
</div>
</li>}
}</ul>
}
</ul>
</li>}
}</ul>}
}
</ul>}
using (Script.Foot()) {
<script type="text/javascript">