mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 13:33:34 +08:00
Shifting more work out of framework
Framework ThemeManager now for getting request theme from selectors Module interfaces entirely moved - now exist as orchard.modules implementation --HG-- branch : perf rename : src/Orchard.Web/Modules/Orchard.Modules/Models/ModuleFeature.cs => src/Orchard.Web/Modules/Orchard.Modules/ViewModels/ModuleFeature.cs
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Commands;
|
using Orchard.Commands;
|
||||||
|
using Orchard.Environment.Descriptor.Models;
|
||||||
using Orchard.Environment.Features;
|
using Orchard.Environment.Features;
|
||||||
|
using Orchard.Modules.Services;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
@@ -10,11 +12,13 @@ namespace Orchard.Modules.Commands {
|
|||||||
private readonly IModuleService _moduleService;
|
private readonly IModuleService _moduleService;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
private readonly IFeatureManager _featureManager;
|
private readonly IFeatureManager _featureManager;
|
||||||
|
private readonly ShellDescriptor _shellDescriptor;
|
||||||
|
|
||||||
public FeatureCommands(IModuleService moduleService, INotifier notifier, IFeatureManager featureManager) {
|
public FeatureCommands(IModuleService moduleService, INotifier notifier, IFeatureManager featureManager, ShellDescriptor shellDescriptor) {
|
||||||
_moduleService = moduleService;
|
_moduleService = moduleService;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
|
_shellDescriptor = shellDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardSwitch]
|
[OrchardSwitch]
|
||||||
@@ -24,25 +28,26 @@ namespace Orchard.Modules.Commands {
|
|||||||
[CommandName("feature list")]
|
[CommandName("feature list")]
|
||||||
[OrchardSwitches("Summary")]
|
[OrchardSwitches("Summary")]
|
||||||
public void List() {
|
public void List() {
|
||||||
|
var enabled = _shellDescriptor.Features.Select(x => x.Name);
|
||||||
if (Summary) {
|
if (Summary) {
|
||||||
foreach (var feature in _featureManager.GetAvailableFeatures().OrderBy(f => f.Name)) {
|
foreach (var feature in _featureManager.GetAvailableFeatures().OrderBy(f => f.Name)) {
|
||||||
Context.Output.WriteLine(T("{0}, {1}", feature.Name, feature.IsEnabled ? T("Enabled") : T("Disabled")));
|
Context.Output.WriteLine(T("{0}, {1}", feature.Name, enabled.Contains(feature.Name) ? T("Enabled") : T("Disabled")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Context.Output.WriteLine(T("List of available features"));
|
Context.Output.WriteLine(T("List of available features"));
|
||||||
Context.Output.WriteLine(T("--------------------------"));
|
Context.Output.WriteLine(T("--------------------------"));
|
||||||
|
|
||||||
var categories = _moduleService.GetAvailableFeatures().ToList().GroupBy(f => f.Descriptor.Category);
|
var categories = _featureManager.GetAvailableFeatures().ToList().GroupBy(f => f.Category);
|
||||||
foreach (var category in categories) {
|
foreach (var category in categories) {
|
||||||
Context.Output.WriteLine(T("Category: {0}", category.Key.OrDefault(T("General"))));
|
Context.Output.WriteLine(T("Category: {0}", category.Key.OrDefault(T("General"))));
|
||||||
foreach (var feature in category.OrderBy(f => f.Descriptor.Name)) {
|
foreach (var feature in category.OrderBy(f => f.Name)) {
|
||||||
Context.Output.WriteLine(T(" Name: {0}", feature.Descriptor.Name));
|
Context.Output.WriteLine(T(" Name: {0}", feature.Name));
|
||||||
Context.Output.WriteLine(T(" State: {0}", feature.IsEnabled ? T("Enabled") : T("Disabled")));
|
Context.Output.WriteLine(T(" State: {0}", enabled.Contains(feature.Name) ? T("Enabled") : T("Disabled")));
|
||||||
Context.Output.WriteLine(T(" Description: {0}", feature.Descriptor.Description.OrDefault(T("<none>"))));
|
Context.Output.WriteLine(T(" Description: {0}", feature.Description.OrDefault(T("<none>"))));
|
||||||
Context.Output.WriteLine(T(" Category: {0}", feature.Descriptor.Category.OrDefault(T("<none>"))));
|
Context.Output.WriteLine(T(" Category: {0}", feature.Category.OrDefault(T("<none>"))));
|
||||||
Context.Output.WriteLine(T(" Module: {0}", feature.Descriptor.Extension.Name.OrDefault(T("<none>"))));
|
Context.Output.WriteLine(T(" Module: {0}", feature.Extension.Name.OrDefault(T("<none>"))));
|
||||||
Context.Output.WriteLine(T(" Dependencies: {0}", string.Join(", ", feature.Descriptor.Dependencies).OrDefault(T("<none>"))));
|
Context.Output.WriteLine(T(" Dependencies: {0}", string.Join(", ", feature.Dependencies).OrDefault(T("<none>"))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,7 +59,7 @@ namespace Orchard.Modules.Commands {
|
|||||||
Context.Output.WriteLine(T("Enabling features {0}", string.Join(",", featureNames)));
|
Context.Output.WriteLine(T("Enabling features {0}", string.Join(",", featureNames)));
|
||||||
bool listAvailableFeatures = false;
|
bool listAvailableFeatures = false;
|
||||||
List<string> featuresToEnable = new List<string>();
|
List<string> featuresToEnable = new List<string>();
|
||||||
string[] availableFeatures = _moduleService.GetAvailableFeatures().Select(x => x.Descriptor.Name).ToArray();
|
string[] availableFeatures = _featureManager.GetAvailableFeatures().Select(x => x.Name).ToArray();
|
||||||
foreach (var featureName in featureNames) {
|
foreach (var featureName in featureNames) {
|
||||||
if (availableFeatures.Contains(featureName)) {
|
if (availableFeatures.Contains(featureName)) {
|
||||||
featuresToEnable.Add(featureName);
|
featuresToEnable.Add(featureName);
|
||||||
|
@@ -2,7 +2,11 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
|
using Orchard.Environment.Descriptor.Models;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Environment.Features;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
using Orchard.Modules.Services;
|
||||||
using Orchard.Modules.ViewModels;
|
using Orchard.Modules.ViewModels;
|
||||||
using Orchard.Packaging.Services;
|
using Orchard.Packaging.Services;
|
||||||
using Orchard.Reports.Services;
|
using Orchard.Reports.Services;
|
||||||
@@ -14,18 +18,27 @@ namespace Orchard.Modules.Controllers {
|
|||||||
private readonly IDataMigrationManager _dataMigrationManager;
|
private readonly IDataMigrationManager _dataMigrationManager;
|
||||||
private readonly IPackageManager _packageManager;
|
private readonly IPackageManager _packageManager;
|
||||||
private readonly IReportsCoordinator _reportsCoordinator;
|
private readonly IReportsCoordinator _reportsCoordinator;
|
||||||
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
private readonly IFeatureManager _featureManager;
|
||||||
|
private readonly ShellDescriptor _shellDescriptor;
|
||||||
|
|
||||||
public AdminController(IOrchardServices services,
|
public AdminController(IOrchardServices services,
|
||||||
IModuleService moduleService,
|
IModuleService moduleService,
|
||||||
IDataMigrationManager dataMigrationManager,
|
IDataMigrationManager dataMigrationManager,
|
||||||
IPackageManager packageManager,
|
IPackageManager packageManager,
|
||||||
IReportsCoordinator reportsCoordinator) {
|
IReportsCoordinator reportsCoordinator,
|
||||||
|
IExtensionManager extensionManager,
|
||||||
|
IFeatureManager featureManager,
|
||||||
|
ShellDescriptor shellDescriptor) {
|
||||||
|
|
||||||
Services = services;
|
Services = services;
|
||||||
_moduleService = moduleService;
|
_moduleService = moduleService;
|
||||||
_dataMigrationManager = dataMigrationManager;
|
_dataMigrationManager = dataMigrationManager;
|
||||||
_packageManager = packageManager;
|
_packageManager = packageManager;
|
||||||
_reportsCoordinator = reportsCoordinator;
|
_reportsCoordinator = reportsCoordinator;
|
||||||
|
_extensionManager = extensionManager;
|
||||||
|
_featureManager = featureManager;
|
||||||
|
_shellDescriptor = shellDescriptor;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
@@ -37,7 +50,7 @@ namespace Orchard.Modules.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Not allowed to manage modules")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Not allowed to manage modules")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var modules = _moduleService.GetInstalledModules().ToList();
|
var modules = _extensionManager.AvailableExtensions().Where(x => x.ExtensionType == "Module");
|
||||||
return View(new ModulesIndexViewModel { Modules = modules });
|
return View(new ModulesIndexViewModel { Modules = modules });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,10 +96,16 @@ namespace Orchard.Modules.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
|
if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var features = _moduleService.GetAvailableFeatures().Where(f => !f.Descriptor.Extension.ExtensionType.Equals("Theme", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
||||||
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
|
||||||
|
|
||||||
return View(new FeaturesViewModel { Features = features, FeaturesThatNeedUpdate = featuresThatNeedUpdate });
|
var features = _featureManager.GetAvailableFeatures()
|
||||||
|
.Where(f => !f.Extension.ExtensionType.Equals("Theme", StringComparison.OrdinalIgnoreCase))
|
||||||
|
.Select(f=>new ModuleFeature{Descriptor=f,
|
||||||
|
IsEnabled=_shellDescriptor.Features.Any(sf=>sf.Name==f.Name),
|
||||||
|
NeedsUpdate=featuresThatNeedUpdate.Contains(f.Name)})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return View(new FeaturesViewModel { Features = features });
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
namespace Orchard.Modules.Models {
|
|
||||||
public class Module : IModule {}
|
|
||||||
}
|
|
@@ -75,9 +75,8 @@
|
|||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
<Compile Include="Extensions\StringExtensions.cs" />
|
<Compile Include="Extensions\StringExtensions.cs" />
|
||||||
<Compile Include="Models\DoghouseComparer.cs" />
|
<Compile Include="Models\DoghouseComparer.cs" />
|
||||||
<Compile Include="Models\ModuleFeature.cs" />
|
<Compile Include="ViewModels\ModuleFeature.cs" />
|
||||||
<Compile Include="ViewModels\FeaturesViewModel.cs" />
|
<Compile Include="ViewModels\FeaturesViewModel.cs" />
|
||||||
<Compile Include="Models\Module.cs" />
|
|
||||||
<Compile Include="Permissions.cs" />
|
<Compile Include="Permissions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Services\ModuleService.cs" />
|
<Compile Include="Services\ModuleService.cs" />
|
||||||
|
@@ -7,9 +7,22 @@ using Orchard.Environment.Descriptor;
|
|||||||
using Orchard.Environment.Descriptor.Models;
|
using Orchard.Environment.Descriptor.Models;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Modules.Models;
|
using Orchard.Modules.Models;
|
||||||
|
using Orchard.Modules.ViewModels;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
namespace Orchard.Modules.Services {
|
namespace Orchard.Modules.Services {
|
||||||
|
[Obsolete]
|
||||||
|
public interface IModuleService : IDependency {
|
||||||
|
[Obsolete]
|
||||||
|
void EnableFeatures(IEnumerable<string> featureNames);
|
||||||
|
[Obsolete]
|
||||||
|
void EnableFeatures(IEnumerable<string> featureNames, bool force);
|
||||||
|
[Obsolete]
|
||||||
|
void DisableFeatures(IEnumerable<string> featureNames);
|
||||||
|
[Obsolete]
|
||||||
|
void DisableFeatures(IEnumerable<string> featureNames, bool force);
|
||||||
|
}
|
||||||
|
|
||||||
public class ModuleService : IModuleService {
|
public class ModuleService : IModuleService {
|
||||||
private const string ModuleExtensionType = "module";
|
private const string ModuleExtensionType = "module";
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
@@ -31,23 +44,16 @@ namespace Orchard.Modules.Services {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
|
|
||||||
public IModule GetModuleByName(string moduleName) {
|
//public IModule GetModuleByName(string moduleName) {
|
||||||
return _extensionManager
|
// return _extensionManager
|
||||||
.AvailableExtensions()
|
// .AvailableExtensions()
|
||||||
.Where(e => string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase))
|
// .Where(e => string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase))
|
||||||
.Where(e => string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
// .Where(e => string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
||||||
.Select(descriptor => AssembleModuleFromDescriptor(descriptor))
|
// .Select(descriptor => AssembleModuleFromDescriptor(descriptor))
|
||||||
.FirstOrDefault();
|
// .FirstOrDefault();
|
||||||
}
|
//}
|
||||||
|
|
||||||
public IEnumerable<IModule> GetInstalledModules() {
|
public IEnumerable<ModuleFeature> GetAvailableFeatures() {
|
||||||
return _extensionManager
|
|
||||||
.AvailableExtensions()
|
|
||||||
.Where(e => String.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
|
||||||
.Select(descriptor => AssembleModuleFromDescriptor(descriptor));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<IModuleFeature> GetAvailableFeatures() {
|
|
||||||
var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features;
|
var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features;
|
||||||
return _extensionManager.AvailableExtensions()
|
return _extensionManager.AvailableExtensions()
|
||||||
.SelectMany(m => _extensionManager.LoadFeatures(m.Features))
|
.SelectMany(m => _extensionManager.LoadFeatures(m.Features))
|
||||||
@@ -105,16 +111,16 @@ namespace Orchard.Modules.Services {
|
|||||||
shellDescriptor.Parameters);
|
shellDescriptor.Parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> EnableFeature(string featureName, IEnumerable<IModuleFeature> features, bool force) {
|
private IEnumerable<string> EnableFeature(string featureName, IEnumerable<ModuleFeature> features, bool force) {
|
||||||
var featuresList = features.ToList();
|
var featuresList = features.ToList();
|
||||||
var getDisabledDependencies =
|
var getDisabledDependencies =
|
||||||
new Func<string, IEnumerable<IModuleFeature>, IEnumerable<IModuleFeature>>(
|
new Func<string, IEnumerable<ModuleFeature>, IEnumerable<ModuleFeature>>(
|
||||||
(n, fs) => {
|
(n, fs) => {
|
||||||
var feature = fs.Single(f => f.Descriptor.Name == n);
|
var feature = fs.Single(f => f.Descriptor.Name == n);
|
||||||
return feature.Descriptor.Dependencies != null
|
return feature.Descriptor.Dependencies != null
|
||||||
? feature.Descriptor.Dependencies.Select(
|
? feature.Descriptor.Dependencies.Select(
|
||||||
fn => fs.Single(f => f.Descriptor.Name == fn)).Where(f => !f.IsEnabled)
|
fn => fs.Single(f => f.Descriptor.Name == fn)).Where(f => !f.IsEnabled)
|
||||||
: Enumerable.Empty<IModuleFeature>();
|
: Enumerable.Empty<ModuleFeature>();
|
||||||
});
|
});
|
||||||
|
|
||||||
var featuresToEnable = GetAffectedFeatures(featureName, featuresList, getDisabledDependencies);
|
var featuresToEnable = GetAffectedFeatures(featureName, featuresList, getDisabledDependencies);
|
||||||
@@ -129,10 +135,10 @@ namespace Orchard.Modules.Services {
|
|||||||
return featuresToEnable;
|
return featuresToEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> DisableFeature(string featureName, IEnumerable<IModuleFeature> features, bool force) {
|
private IEnumerable<string> DisableFeature(string featureName, IEnumerable<ModuleFeature> features, bool force) {
|
||||||
var featuresList = features.ToList();
|
var featuresList = features.ToList();
|
||||||
var getEnabledDependants =
|
var getEnabledDependants =
|
||||||
new Func<string, IEnumerable<IModuleFeature>, IEnumerable<IModuleFeature>>(
|
new Func<string, IEnumerable<ModuleFeature>, IEnumerable<ModuleFeature>>(
|
||||||
(n, fs) => fs.Where(f => f.IsEnabled && f.Descriptor.Dependencies != null && f.Descriptor.Dependencies.Contains(n)));
|
(n, fs) => fs.Where(f => f.IsEnabled && f.Descriptor.Dependencies != null && f.Descriptor.Dependencies.Contains(n)));
|
||||||
|
|
||||||
var featuresToDisable = GetAffectedFeatures(featureName, featuresList, getEnabledDependants);
|
var featuresToDisable = GetAffectedFeatures(featureName, featuresList, getEnabledDependants);
|
||||||
@@ -147,7 +153,7 @@ namespace Orchard.Modules.Services {
|
|||||||
return featuresToDisable;
|
return featuresToDisable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> GetAffectedFeatures(string featureName, IEnumerable<IModuleFeature> features, Func<string, IEnumerable<IModuleFeature>, IEnumerable<IModuleFeature>> getAffectedDependencies) {
|
private static IEnumerable<string> GetAffectedFeatures(string featureName, IEnumerable<ModuleFeature> features, Func<string, IEnumerable<ModuleFeature>, IEnumerable<ModuleFeature>> getAffectedDependencies) {
|
||||||
var dependencies = new List<string> {featureName};
|
var dependencies = new List<string> {featureName};
|
||||||
|
|
||||||
foreach (var dependency in getAffectedDependencies(featureName, features))
|
foreach (var dependency in getAffectedDependencies(featureName, features))
|
||||||
@@ -186,30 +192,30 @@ namespace Orchard.Modules.Services {
|
|||||||
return localized;
|
return localized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IModule AssembleModuleFromDescriptor(ExtensionDescriptor extensionDescriptor) {
|
//private IModule AssembleModuleFromDescriptor(ExtensionDescriptor extensionDescriptor) {
|
||||||
|
|
||||||
var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(extensionDescriptor.Location, "/", extensionDescriptor.Name, "/Module.txt"));
|
// var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(extensionDescriptor.Location, "/", extensionDescriptor.Name, "/Module.txt"));
|
||||||
|
|
||||||
return new Module {
|
// return new Module {
|
||||||
//ModuleName = extensionDescriptor.Name,
|
// //ModuleName = extensionDescriptor.Name,
|
||||||
//DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
|
// //DisplayName = TryLocalize("Name", extensionDescriptor.DisplayName, localizer),
|
||||||
//Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
|
// //Description = TryLocalize("Description", extensionDescriptor.Description, localizer),
|
||||||
//Version = extensionDescriptor.Version,
|
// //Version = extensionDescriptor.Version,
|
||||||
//Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
|
// //Author = TryLocalize("Author", extensionDescriptor.Author, localizer),
|
||||||
//HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
|
// //HomePage = TryLocalize("Website", extensionDescriptor.WebSite, localizer),
|
||||||
//Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
|
// //Tags = TryLocalize("Tags", extensionDescriptor.Tags, localizer),
|
||||||
//Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
|
// //Features = extensionDescriptor.Features.Select(f => new FeatureDescriptor {
|
||||||
// Category = TryLocalize(f.Name + " Category", f.Category, localizer),
|
// // Category = TryLocalize(f.Name + " Category", f.Category, localizer),
|
||||||
// Dependencies = f.Dependencies,
|
// // Dependencies = f.Dependencies,
|
||||||
// Description = TryLocalize(f.Name + " Description", f.Description, localizer),
|
// // Description = TryLocalize(f.Name + " Description", f.Description, localizer),
|
||||||
// DisplayName = TryLocalize(f.Name + " Name", f.DisplayName, localizer),
|
// // DisplayName = TryLocalize(f.Name + " Name", f.DisplayName, localizer),
|
||||||
// Extension = f.Extension,
|
// // Extension = f.Extension,
|
||||||
// Name = f.Name,
|
// // Name = f.Name,
|
||||||
//})
|
// //})
|
||||||
};
|
// };
|
||||||
}
|
//}
|
||||||
|
|
||||||
private static IModuleFeature AssembleModuleFromDescriptor(Feature feature, bool isEnabled) {
|
private static ModuleFeature AssembleModuleFromDescriptor(Feature feature, bool isEnabled) {
|
||||||
return new ModuleFeature {
|
return new ModuleFeature {
|
||||||
Descriptor = feature.Descriptor,
|
Descriptor = feature.Descriptor,
|
||||||
IsEnabled = isEnabled
|
IsEnabled = isEnabled
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
namespace Orchard.Modules.ViewModels {
|
namespace Orchard.Modules.ViewModels {
|
||||||
public class FeaturesViewModel {
|
public class FeaturesViewModel {
|
||||||
public IEnumerable<IModuleFeature> Features { get; set; }
|
public IEnumerable<ModuleFeature> Features { get; set; }
|
||||||
public IEnumerable<string> FeaturesThatNeedUpdate { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
namespace Orchard.Modules.Models {
|
namespace Orchard.Modules.ViewModels {
|
||||||
public class ModuleFeature : IModuleFeature {
|
public class ModuleFeature {
|
||||||
public FeatureDescriptor Descriptor { get; set; }
|
public FeatureDescriptor Descriptor { get; set; }
|
||||||
public bool IsEnabled { get; set; }
|
public bool IsEnabled { get; set; }
|
||||||
|
public bool NeedsUpdate { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
namespace Orchard.Modules.ViewModels {
|
namespace Orchard.Modules.ViewModels {
|
||||||
public class ModulesIndexViewModel {
|
public class ModulesIndexViewModel {
|
||||||
public IEnumerable<IModule> Modules { get; set; }
|
public IEnumerable<ExtensionDescriptor> Modules { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -34,7 +34,7 @@
|
|||||||
var featureId = feature.Descriptor.Name.AsFeatureId(n => T(n));
|
var featureId = feature.Descriptor.Name.AsFeatureId(n => T(n));
|
||||||
var featureName = string.IsNullOrEmpty(feature.Descriptor.DisplayName) ? feature.Descriptor.Name : feature.Descriptor.DisplayName;
|
var featureName = string.IsNullOrEmpty(feature.Descriptor.DisplayName) ? feature.Descriptor.Name : feature.Descriptor.DisplayName;
|
||||||
var featureState = feature.IsEnabled ? "enabled" : "disabled";
|
var featureState = feature.IsEnabled ? "enabled" : "disabled";
|
||||||
var featureClassName = string.Format("feature {0}", featureState + (Model.FeaturesThatNeedUpdate.Contains(feature.Descriptor.Name) ? " update" : String.Empty));
|
var featureClassName = string.Format("feature {0}", featureState + (feature.NeedsUpdate ? " update" : String.Empty));
|
||||||
if (feature == features.First()) {
|
if (feature == features.First()) {
|
||||||
featureClassName += " first";
|
featureClassName += " first";
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@if(Model.FeaturesThatNeedUpdate.Contains(feature.Descriptor.Name)){
|
@if(feature.NeedsUpdate){
|
||||||
using (Html.BeginFormAntiForgeryPost(string.Format("{0}", Url.Action("Update", new { area = "Orchard.Modules" })), FormMethod.Post, new {@class = "inline link"})) {
|
using (Html.BeginFormAntiForgeryPost(string.Format("{0}", Url.Action("Update", new { area = "Orchard.Modules" })), FormMethod.Post, new {@class = "inline link"})) {
|
||||||
@Html.Hidden("id", feature.Descriptor.Name, new { id = "" })
|
@Html.Hidden("id", feature.Descriptor.Name, new { id = "" })
|
||||||
<button type="submit" class="update">@T("Update")</button>
|
<button type="submit" class="update">@T("Update")</button>
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
<ul class="pageStatus" style="color:#666; margin:.6em 0 0 0;">
|
<ul class="pageStatus" style="color:#666; margin:.6em 0 0 0;">
|
||||||
<li>@T("Features: {0}", MvcHtmlString.Create(string.Join(", ", module.Features.Select(f => Html.Link(f.Name, string.Format("{0}#{1}", Url.Action("features", new { area = "Orchard.Modules" }), f.Name.AsFeatureId(n => T(n)))).ToString()).OrderBy(s => s).ToArray())))</li>
|
<li>@T("Features: {0}", MvcHtmlString.Create(string.Join(", ", module.Features.Select(f => Html.Link(f.Name, string.Format("{0}#{1}", Url.Action("features", new { area = "Orchard.Modules" }), f.Name.AsFeatureId(n => T(n)))).ToString()).OrderBy(s => s).ToArray())))</li>
|
||||||
<li> | @T("Author: {0}", !string.IsNullOrEmpty(module.Author) ? module.Author : (new []{"Bradley", "Bertrand", "Renaud", "Suha", "Sebastien", "Jon", "Nathan", "Erik", "Andre"})[(module.DisplayName.Length + (new Random()).Next()) % 7])</li>
|
<li> | @T("Author: {0}", !string.IsNullOrEmpty(module.Author) ? module.Author : (new []{"Bradley", "Bertrand", "Renaud", "Suha", "Sebastien", "Jon", "Nathan", "Erik", "Andre"})[(module.DisplayName.Length + (new Random()).Next()) % 7])</li>
|
||||||
<li> | @T("Website: {0}", !string.IsNullOrEmpty(module.HomePage) ? module.HomePage : "http://orchardproject.net")</li>
|
<li> | @T("Website: {0}", !string.IsNullOrEmpty(module.WebSite) ? module.WebSite : "http://orchardproject.net")</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -64,7 +64,7 @@ namespace Orchard.Setup {
|
|||||||
builder.RegisterType<ResourceFilter>().As<IFilterProvider>().InstancePerLifetimeScope();
|
builder.RegisterType<ResourceFilter>().As<IFilterProvider>().InstancePerLifetimeScope();
|
||||||
|
|
||||||
// setup mode specific implementations of needed service interfaces
|
// setup mode specific implementations of needed service interfaces
|
||||||
builder.RegisterType<SafeModeThemeService>().As<IThemeService>().InstancePerLifetimeScope();
|
builder.RegisterType<SafeModeThemeService>().As<IThemeManager>().InstancePerLifetimeScope();
|
||||||
builder.RegisterType<SafeModeText>().As<IText>().InstancePerLifetimeScope();
|
builder.RegisterType<SafeModeText>().As<IText>().InstancePerLifetimeScope();
|
||||||
builder.RegisterType<SafeModeSiteService>().As<ISiteService>().InstancePerLifetimeScope();
|
builder.RegisterType<SafeModeSiteService>().As<ISiteService>().InstancePerLifetimeScope();
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ namespace Orchard.Setup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
class SafeModeThemeService : IThemeService {
|
class SafeModeThemeService : IThemeManager {
|
||||||
class SafeModeTheme : FeatureDescriptor {
|
class SafeModeTheme : FeatureDescriptor {
|
||||||
public ContentItem ContentItem { get; set; }
|
public ContentItem ContentItem { get; set; }
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
|
@@ -18,7 +18,7 @@ using Orchard.UI.Notify;
|
|||||||
namespace Orchard.Themes.Controllers {
|
namespace Orchard.Themes.Controllers {
|
||||||
[ValidateInput(false)]
|
[ValidateInput(false)]
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
private readonly IThemeService _themeService;
|
private readonly IThemeManager _themeManager;
|
||||||
private readonly IFeatureManager _featureManager;
|
private readonly IFeatureManager _featureManager;
|
||||||
private readonly ISiteThemeService _siteThemeService;
|
private readonly ISiteThemeService _siteThemeService;
|
||||||
private readonly IPreviewTheme _previewTheme;
|
private readonly IPreviewTheme _previewTheme;
|
||||||
@@ -30,7 +30,7 @@ namespace Orchard.Themes.Controllers {
|
|||||||
IDataMigrationManager dataMigraitonManager,
|
IDataMigrationManager dataMigraitonManager,
|
||||||
IReportsCoordinator reportsCoordinator,
|
IReportsCoordinator reportsCoordinator,
|
||||||
IOrchardServices services,
|
IOrchardServices services,
|
||||||
IThemeService themeService,
|
IThemeManager themeManager,
|
||||||
IFeatureManager featureManager,
|
IFeatureManager featureManager,
|
||||||
ISiteThemeService siteThemeService,
|
ISiteThemeService siteThemeService,
|
||||||
IPreviewTheme previewTheme,
|
IPreviewTheme previewTheme,
|
||||||
@@ -40,7 +40,7 @@ namespace Orchard.Themes.Controllers {
|
|||||||
Services = services;
|
Services = services;
|
||||||
_dataMigrationManager = dataMigraitonManager;
|
_dataMigrationManager = dataMigraitonManager;
|
||||||
_reportsCoordinator = reportsCoordinator;
|
_reportsCoordinator = reportsCoordinator;
|
||||||
_themeService = themeService;
|
_themeManager = themeManager;
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
_siteThemeService = siteThemeService;
|
_siteThemeService = siteThemeService;
|
||||||
_previewTheme = previewTheme;
|
_previewTheme = previewTheme;
|
||||||
|
@@ -86,7 +86,7 @@
|
|||||||
<Compile Include="Services\SafeModeThemeSelector.cs" />
|
<Compile Include="Services\SafeModeThemeSelector.cs" />
|
||||||
<Compile Include="Services\SiteThemeSelector.cs" />
|
<Compile Include="Services\SiteThemeSelector.cs" />
|
||||||
<Compile Include="Services\SiteThemeService.cs" />
|
<Compile Include="Services\SiteThemeService.cs" />
|
||||||
<Compile Include="Services\ThemeService.cs" />
|
<Compile Include="Services\ThemeManager.cs" />
|
||||||
<Compile Include="ViewModels\ThemesIndexViewModel.cs" />
|
<Compile Include="ViewModels\ThemesIndexViewModel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -7,19 +7,19 @@ using Orchard.Themes.ViewModels;
|
|||||||
|
|
||||||
namespace Orchard.Themes.Preview {
|
namespace Orchard.Themes.Preview {
|
||||||
public class PreviewThemeFilter : FilterProvider, IResultFilter {
|
public class PreviewThemeFilter : FilterProvider, IResultFilter {
|
||||||
private readonly IThemeService _themeService;
|
private readonly IThemeManager _themeManager;
|
||||||
private readonly IPreviewTheme _previewTheme;
|
private readonly IPreviewTheme _previewTheme;
|
||||||
private readonly IWorkContextAccessor _workContextAccessor;
|
private readonly IWorkContextAccessor _workContextAccessor;
|
||||||
private readonly dynamic _shapeFactory;
|
private readonly dynamic _shapeFactory;
|
||||||
private readonly IFeatureManager _featureManager;
|
private readonly IFeatureManager _featureManager;
|
||||||
|
|
||||||
public PreviewThemeFilter(
|
public PreviewThemeFilter(
|
||||||
IThemeService themeService,
|
IThemeManager themeManager,
|
||||||
IPreviewTheme previewTheme,
|
IPreviewTheme previewTheme,
|
||||||
IWorkContextAccessor workContextAccessor,
|
IWorkContextAccessor workContextAccessor,
|
||||||
IShapeFactory shapeFactory,
|
IShapeFactory shapeFactory,
|
||||||
IFeatureManager featureManager) {
|
IFeatureManager featureManager) {
|
||||||
_themeService = themeService;
|
_themeManager = themeManager;
|
||||||
_previewTheme = previewTheme;
|
_previewTheme = previewTheme;
|
||||||
_workContextAccessor = workContextAccessor;
|
_workContextAccessor = workContextAccessor;
|
||||||
_shapeFactory = shapeFactory;
|
_shapeFactory = shapeFactory;
|
||||||
|
@@ -1,200 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Web.Routing;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Orchard.Environment.Descriptor;
|
|
||||||
using Orchard.Environment.Descriptor.Models;
|
|
||||||
using Orchard.Environment.Extensions;
|
|
||||||
using Orchard.Environment.Extensions.Models;
|
|
||||||
using Orchard.Localization;
|
|
||||||
using Orchard.Logging;
|
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.Modules;
|
|
||||||
using Orchard.Themes.Models;
|
|
||||||
|
|
||||||
namespace Orchard.Themes.Services {
|
|
||||||
[UsedImplicitly]
|
|
||||||
public class ThemeService : IThemeService {
|
|
||||||
private readonly IExtensionManager _extensionManager;
|
|
||||||
private readonly IEnumerable<IThemeSelector> _themeSelectors;
|
|
||||||
private readonly IModuleService _moduleService;
|
|
||||||
private readonly IWorkContextAccessor _workContextAccessor;
|
|
||||||
private readonly ShellDescriptor _shellDescriptor;
|
|
||||||
private readonly IOrchardServices _orchardServices;
|
|
||||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
|
||||||
|
|
||||||
public ThemeService(
|
|
||||||
IShellDescriptorManager shellDescriptorManager,
|
|
||||||
IExtensionManager extensionManager,
|
|
||||||
IEnumerable<IThemeSelector> themeSelectors,
|
|
||||||
IModuleService moduleService,
|
|
||||||
IWorkContextAccessor workContextAccessor,
|
|
||||||
ShellDescriptor shellDescriptor,
|
|
||||||
IOrchardServices orchardServices) {
|
|
||||||
_shellDescriptorManager = shellDescriptorManager;
|
|
||||||
_extensionManager = extensionManager;
|
|
||||||
_themeSelectors = themeSelectors;
|
|
||||||
_moduleService = moduleService;
|
|
||||||
_workContextAccessor = workContextAccessor;
|
|
||||||
_shellDescriptor = shellDescriptor;
|
|
||||||
_orchardServices = orchardServices;
|
|
||||||
Logger = NullLogger.Instance;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
|
||||||
public ILogger Logger { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private bool AllBaseThemesAreInstalled(string baseThemeName) {
|
|
||||||
var themesSeen = new List<string>();
|
|
||||||
while (!string.IsNullOrWhiteSpace(baseThemeName)) {
|
|
||||||
//todo: (heskew) need a better way to protect from recursive references
|
|
||||||
if (themesSeen.Contains(baseThemeName))
|
|
||||||
throw new InvalidOperationException(T("The theme \"{0}\" was already seen - looks like we're going around in circles.", baseThemeName).Text);
|
|
||||||
themesSeen.Add(baseThemeName);
|
|
||||||
|
|
||||||
var baseTheme = _extensionManager.GetExtension(baseThemeName);
|
|
||||||
if (baseTheme == null)
|
|
||||||
return false;
|
|
||||||
baseThemeName = baseTheme.BaseTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DisableThemeFeatures(string themeName) {
|
|
||||||
var themes = new Queue<string>();
|
|
||||||
while (themeName != null) {
|
|
||||||
if (themes.Contains(themeName))
|
|
||||||
throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text);
|
|
||||||
var theme = _extensionManager.GetExtension(themeName);
|
|
||||||
if (theme == null)
|
|
||||||
break;
|
|
||||||
themes.Enqueue(themeName);
|
|
||||||
|
|
||||||
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
|
||||||
? theme.BaseTheme
|
|
||||||
: null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
while (themes.Count > 0)
|
|
||||||
_moduleService.DisableFeatures(new[] { themes.Dequeue() });
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EnableThemeFeatures(string themeName) {
|
|
||||||
var themes = new Stack<string>();
|
|
||||||
while(themeName != null) {
|
|
||||||
if (themes.Contains(themeName))
|
|
||||||
throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features enabled.", themeName).Text);
|
|
||||||
themes.Push(themeName);
|
|
||||||
|
|
||||||
var theme = _extensionManager.GetExtension(themeName);
|
|
||||||
themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme)
|
|
||||||
? theme.BaseTheme
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (themes.Count > 0)
|
|
||||||
_moduleService.EnableFeatures(new[] {themes.Pop()});
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool DoEnableTheme(string themeName) {
|
|
||||||
if (string.IsNullOrWhiteSpace(themeName))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//todo: (heskew) need messages given in addition to all of these early returns so something meaningful can be presented to the user
|
|
||||||
var themeToEnable = _extensionManager.GetExtension(themeName);
|
|
||||||
if (themeToEnable == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// ensure all base themes down the line are present and accounted for
|
|
||||||
//todo: (heskew) dito on the need of a meaningful message
|
|
||||||
if (!AllBaseThemesAreInstalled(themeToEnable.BaseTheme))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// enable all theme features
|
|
||||||
EnableThemeFeatures(themeToEnable.Name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) {
|
|
||||||
var requestTheme = _themeSelectors
|
|
||||||
.Select(x => x.GetTheme(requestContext))
|
|
||||||
.Where(x => x != null)
|
|
||||||
.OrderByDescending(x => x.Priority);
|
|
||||||
|
|
||||||
if (requestTheme.Count() < 1)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
foreach (var theme in requestTheme) {
|
|
||||||
var t = _extensionManager.GetExtension(theme.ThemeName);
|
|
||||||
if (t != null)
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _extensionManager.GetExtension("SafeMode");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Loads only installed themes
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<ExtensionDescriptor> GetInstalledThemes() {
|
|
||||||
return GetThemes(_extensionManager.AvailableExtensions());
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerable<ExtensionDescriptor> GetThemes(IEnumerable<ExtensionDescriptor> extensions) {
|
|
||||||
var themes = new List<ExtensionDescriptor>();
|
|
||||||
foreach (var descriptor in extensions) {
|
|
||||||
|
|
||||||
if (!string.Equals(descriptor.ExtensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionDescriptor theme = descriptor;
|
|
||||||
|
|
||||||
if (!theme.Tags.Contains("hidden")) {
|
|
||||||
themes.Add(theme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return themes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string TryLocalize(string key, string original, Localizer localizer) {
|
|
||||||
var localized = localizer(key).Text;
|
|
||||||
|
|
||||||
if ( key == localized ) {
|
|
||||||
// no specific localization available
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
|
|
||||||
return localized;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsThemeEnabled(ExtensionDescriptor descriptor) {
|
|
||||||
return (descriptor.Name == "TheAdmin" || descriptor.Name == "SafeMode") ||
|
|
||||||
_shellDescriptorManager.GetShellDescriptor().Features.Any(sf => sf.Name == descriptor.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
//private ITheme CreateTheme(ExtensionDescriptor descriptor) {
|
|
||||||
|
|
||||||
// var localizer = LocalizationUtilities.Resolve(_workContextAccessor.GetContext(), String.Concat(descriptor.Location, "/", descriptor.Name, "/Theme.txt"));
|
|
||||||
|
|
||||||
// return new Theme {
|
|
||||||
// //Author = TryLocalize("Author", descriptor.Author, localizer) ?? "",
|
|
||||||
// //Description = TryLocalize("Description", descriptor.Description, localizer) ?? "",
|
|
||||||
// DisplayName = TryLocalize("Name", descriptor.DisplayName, localizer) ?? "",
|
|
||||||
// //HomePage = TryLocalize("Website", descriptor.WebSite, localizer) ?? "",
|
|
||||||
// ThemeName = descriptor.Name,
|
|
||||||
// //Version = descriptor.Version ?? "",
|
|
||||||
// Tags = TryLocalize("Tags", descriptor.Tags, localizer) ?? "",
|
|
||||||
// Zones = descriptor.Zones ?? "",
|
|
||||||
// BaseTheme = descriptor.BaseTheme ?? "",
|
|
||||||
// Enabled = IsThemeEnabled(descriptor)
|
|
||||||
// };
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -12,17 +12,17 @@ namespace Orchard.Widgets.Services {
|
|||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class WidgetsService : IWidgetsService {
|
public class WidgetsService : IWidgetsService {
|
||||||
private readonly IThemeService _themeService;
|
private readonly IThemeManager _themeManager;
|
||||||
private readonly IFeatureManager _featureManager;
|
private readonly IFeatureManager _featureManager;
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
public WidgetsService(
|
public WidgetsService(
|
||||||
IContentManager contentManager,
|
IContentManager contentManager,
|
||||||
IThemeService themeService,
|
IThemeManager themeManager,
|
||||||
IFeatureManager featureManager) {
|
IFeatureManager featureManager) {
|
||||||
|
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_themeService = themeService;
|
_themeManager = themeManager;
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@
|
|||||||
affects performance, set this value to true only
|
affects performance, set this value to true only
|
||||||
during development.
|
during development.
|
||||||
-->
|
-->
|
||||||
<compilation debug="true" targetFramework="4.0">
|
<compilation debug="false" targetFramework="4.0">
|
||||||
<buildProviders>
|
<buildProviders>
|
||||||
<add extension=".csproj" type="Orchard.Environment.Extensions.Compilers.CSharpExtensionBuildProviderShim"/>
|
<add extension=".csproj" type="Orchard.Environment.Extensions.Compilers.CSharpExtensionBuildProviderShim"/>
|
||||||
</buildProviders>
|
</buildProviders>
|
||||||
|
@@ -21,7 +21,7 @@ namespace Orchard.ContentManagement {
|
|||||||
private readonly IShapeTableManager _shapeTableManager;
|
private readonly IShapeTableManager _shapeTableManager;
|
||||||
private readonly IWorkContextAccessor _workContextAccessor;
|
private readonly IWorkContextAccessor _workContextAccessor;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly Lazy<IThemeService> _themeService;
|
private readonly Lazy<IThemeManager> _themeService;
|
||||||
private readonly RequestContext _requestContext;
|
private readonly RequestContext _requestContext;
|
||||||
|
|
||||||
public DefaultContentDisplay(
|
public DefaultContentDisplay(
|
||||||
@@ -30,7 +30,7 @@ namespace Orchard.ContentManagement {
|
|||||||
IShapeTableManager shapeTableManager,
|
IShapeTableManager shapeTableManager,
|
||||||
IWorkContextAccessor workContextAccessor,
|
IWorkContextAccessor workContextAccessor,
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
Lazy<IThemeService> themeService,
|
Lazy<IThemeManager> themeService,
|
||||||
RequestContext requestContext) {
|
RequestContext requestContext) {
|
||||||
_handlers = handlers;
|
_handlers = handlers;
|
||||||
_shapeFactory = shapeFactory;
|
_shapeFactory = shapeFactory;
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
namespace Orchard.Environment.Extensions.Models {
|
|
||||||
public class Extension {
|
|
||||||
}
|
|
||||||
}
|
|
@@ -31,8 +31,5 @@ namespace Orchard.Environment.Extensions.Models {
|
|||||||
public string BaseTheme { get; set; }
|
public string BaseTheme { get; set; }
|
||||||
|
|
||||||
public IEnumerable<FeatureDescriptor> Features { get; set; }
|
public IEnumerable<FeatureDescriptor> Features { get; set; }
|
||||||
|
|
||||||
[Obsolete("Temporary property - added for theme transition")]
|
|
||||||
public bool Enabled { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -15,7 +15,5 @@ namespace Orchard.Environment.Extensions.Models {
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string Category { get; set; }
|
public string Category { get; set; }
|
||||||
public IEnumerable<string> Dependencies { get; set; }
|
public IEnumerable<string> Dependencies { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
namespace Orchard.Environment.Features {
|
namespace Orchard.Environment.Features {
|
||||||
public interface IFeatureManager : IDependency {
|
public interface IFeatureManager : IDependency {
|
||||||
IEnumerable<FeatureInfo> GetFeatures();
|
|
||||||
IEnumerable<FeatureDescriptor> GetAvailableFeatures();
|
IEnumerable<FeatureDescriptor> GetAvailableFeatures();
|
||||||
IEnumerable<FeatureDescriptor> GetEnabledFeatures();
|
IEnumerable<FeatureDescriptor> GetEnabledFeatures();
|
||||||
|
|
||||||
@@ -12,15 +12,16 @@ namespace Orchard.Environment.Features {
|
|||||||
void DisableFeature(string name);
|
void DisableFeature(string name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FeatureInfo {
|
|
||||||
ExtensionDescriptor Extension { get; set; }
|
|
||||||
FeatureDescriptor Descriptor { get; set; }
|
|
||||||
bool IsEnabled { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class FeatureManager : IFeatureManager {
|
public class FeatureManager : IFeatureManager {
|
||||||
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
|
||||||
|
public FeatureManager(IExtensionManager extensionManager) {
|
||||||
|
_extensionManager = extensionManager;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<FeatureDescriptor> GetAvailableFeatures() {
|
public IEnumerable<FeatureDescriptor> GetAvailableFeatures() {
|
||||||
throw new NotImplementedException();
|
return _extensionManager.AvailableFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<FeatureDescriptor> GetEnabledFeatures() {
|
public IEnumerable<FeatureDescriptor> GetEnabledFeatures() {
|
||||||
|
@@ -1,6 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Orchard.Modules {
|
|
||||||
[Obsolete]
|
|
||||||
public interface IModule { }
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Orchard.Environment.Extensions.Models;
|
|
||||||
|
|
||||||
namespace Orchard.Modules {
|
|
||||||
[Obsolete]
|
|
||||||
public interface IModuleFeature {
|
|
||||||
[Obsolete]
|
|
||||||
FeatureDescriptor Descriptor { get; set; }
|
|
||||||
[Obsolete]
|
|
||||||
bool IsEnabled { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Orchard.Modules {
|
|
||||||
[Obsolete]
|
|
||||||
public interface IModuleService : IDependency {
|
|
||||||
[Obsolete]
|
|
||||||
IEnumerable<IModule> GetInstalledModules();
|
|
||||||
[Obsolete("",true)]
|
|
||||||
IEnumerable<IModuleFeature> GetAvailableFeatures();
|
|
||||||
[Obsolete]
|
|
||||||
void EnableFeatures(IEnumerable<string> featureNames);
|
|
||||||
[Obsolete]
|
|
||||||
void EnableFeatures(IEnumerable<string> featureNames, bool force);
|
|
||||||
[Obsolete]
|
|
||||||
void DisableFeatures(IEnumerable<string> featureNames);
|
|
||||||
[Obsolete]
|
|
||||||
void DisableFeatures(IEnumerable<string> featureNames, bool force);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -19,7 +19,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
|
|
||||||
[Obsolete("How do you know the request theme is the same as the place the theme template is rendering from?")]
|
[Obsolete("How do you know the request theme is the same as the place the theme template is rendering from?")]
|
||||||
public static string ThemePath(this HtmlHelper helper, string path) {
|
public static string ThemePath(this HtmlHelper helper, string path) {
|
||||||
return helper.ThemePath(helper.Resolve<IThemeService>().GetRequestTheme(helper.ViewContext.RequestContext), path);
|
return helper.ThemePath(helper.Resolve<IThemeManager>().GetRequestTheme(helper.ViewContext.RequestContext), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ThemePath(this HtmlHelper helper, ExtensionDescriptor theme, string path) {
|
public static string ThemePath(this HtmlHelper helper, ExtensionDescriptor theme, string path) {
|
||||||
|
@@ -6,12 +6,12 @@ using Orchard.Themes;
|
|||||||
namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
||||||
|
|
||||||
public class ThemedViewResultFilter : FilterProvider, IResultFilter {
|
public class ThemedViewResultFilter : FilterProvider, IResultFilter {
|
||||||
private readonly IThemeService _themeService;
|
private readonly IThemeManager _themeManager;
|
||||||
private readonly WorkContext _workContext;
|
private readonly WorkContext _workContext;
|
||||||
private readonly ILayoutAwareViewEngine _layoutAwareViewEngine;
|
private readonly ILayoutAwareViewEngine _layoutAwareViewEngine;
|
||||||
|
|
||||||
public ThemedViewResultFilter(IThemeService themeService, WorkContext workContext, ILayoutAwareViewEngine layoutAwareViewEngine) {
|
public ThemedViewResultFilter(IThemeManager themeManager, WorkContext workContext, ILayoutAwareViewEngine layoutAwareViewEngine) {
|
||||||
_themeService = themeService;
|
_themeManager = themeManager;
|
||||||
_workContext = workContext;
|
_workContext = workContext;
|
||||||
_layoutAwareViewEngine = layoutAwareViewEngine;
|
_layoutAwareViewEngine = layoutAwareViewEngine;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
@@ -26,7 +26,7 @@ namespace Orchard.Mvc.ViewEngines.ThemeAwareness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_workContext.CurrentTheme == null) {
|
if (_workContext.CurrentTheme == null) {
|
||||||
_workContext.CurrentTheme = _themeService.GetRequestTheme(filterContext.RequestContext);
|
_workContext.CurrentTheme = _themeManager.GetRequestTheme(filterContext.RequestContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
viewResultBase.ViewEngineCollection = new ViewEngineCollection(new[] { _layoutAwareViewEngine });
|
viewResultBase.ViewEngineCollection = new ViewEngineCollection(new[] { _layoutAwareViewEngine });
|
||||||
|
@@ -661,15 +661,11 @@
|
|||||||
<Compile Include="Events\IEventBusHandler.cs" />
|
<Compile Include="Events\IEventBusHandler.cs" />
|
||||||
<Compile Include="Environment\Extensions\Folders\AreaFolders.cs" />
|
<Compile Include="Environment\Extensions\Folders\AreaFolders.cs" />
|
||||||
<Compile Include="Environment\Extensions\Folders\ExtensionFolders.cs" />
|
<Compile Include="Environment\Extensions\Folders\ExtensionFolders.cs" />
|
||||||
<Compile Include="Environment\Extensions\Models\Extension.cs" />
|
|
||||||
<Compile Include="Environment\Extensions\Loaders\AreaExtensionLoader.cs" />
|
<Compile Include="Environment\Extensions\Loaders\AreaExtensionLoader.cs" />
|
||||||
<Compile Include="Environment\Extensions\Models\Feature.cs" />
|
<Compile Include="Environment\Extensions\Models\Feature.cs" />
|
||||||
<Compile Include="Environment\Extensions\Models\FeatureDescriptor.cs" />
|
<Compile Include="Environment\Extensions\Models\FeatureDescriptor.cs" />
|
||||||
<Compile Include="Environment\Extensions\OrchardFeatureAttribute.cs" />
|
<Compile Include="Environment\Extensions\OrchardFeatureAttribute.cs" />
|
||||||
<Compile Include="Events\IEventHandler.cs" />
|
<Compile Include="Events\IEventHandler.cs" />
|
||||||
<Compile Include="Modules\IModule.cs" />
|
|
||||||
<Compile Include="Modules\IModuleFeature.cs" />
|
|
||||||
<Compile Include="Modules\IModuleService.cs" />
|
|
||||||
<Compile Include="Mvc\AntiForgery\ValidateAntiForgeryTokenOrchardAttribute.cs" />
|
<Compile Include="Mvc\AntiForgery\ValidateAntiForgeryTokenOrchardAttribute.cs" />
|
||||||
<Compile Include="Mvc\Extensions\ModelStateDictionaryExtensions.cs" />
|
<Compile Include="Mvc\Extensions\ModelStateDictionaryExtensions.cs" />
|
||||||
<Compile Include="Mvc\Html\FileRegistrationContextExtensions.cs" />
|
<Compile Include="Mvc\Html\FileRegistrationContextExtensions.cs" />
|
||||||
@@ -779,7 +775,7 @@
|
|||||||
<Compile Include="Tasks\IBackgroundTask.cs" />
|
<Compile Include="Tasks\IBackgroundTask.cs" />
|
||||||
<Compile Include="Tasks\SweepGenerator.cs" />
|
<Compile Include="Tasks\SweepGenerator.cs" />
|
||||||
<Compile Include="Themes\IThemeSelector.cs" />
|
<Compile Include="Themes\IThemeSelector.cs" />
|
||||||
<Compile Include="Themes\IThemeService.cs" />
|
<Compile Include="Themes\IThemeManager.cs" />
|
||||||
<Compile Include="UI\Navigation\MenuFilter.cs" />
|
<Compile Include="UI\Navigation\MenuFilter.cs" />
|
||||||
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
||||||
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
||||||
|
42
src/Orchard/Themes/IThemeManager.cs
Normal file
42
src/Orchard/Themes/IThemeManager.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Routing;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Themes {
|
||||||
|
public interface IThemeManager : IDependency {
|
||||||
|
[Obsolete]
|
||||||
|
ExtensionDescriptor GetRequestTheme(RequestContext requestContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ThemeManager : IThemeManager {
|
||||||
|
private readonly IEnumerable<IThemeSelector> _themeSelectors;
|
||||||
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
|
||||||
|
public ThemeManager(IEnumerable<IThemeSelector> themeSelectors,
|
||||||
|
IExtensionManager extensionManager) {
|
||||||
|
_themeSelectors = themeSelectors;
|
||||||
|
_extensionManager = extensionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) {
|
||||||
|
var requestTheme = _themeSelectors
|
||||||
|
.Select(x => x.GetTheme(requestContext))
|
||||||
|
.Where(x => x != null)
|
||||||
|
.OrderByDescending(x => x.Priority);
|
||||||
|
|
||||||
|
if (requestTheme.Count() < 1)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
foreach (var theme in requestTheme) {
|
||||||
|
var t = _extensionManager.GetExtension(theme.ThemeName);
|
||||||
|
if (t != null)
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _extensionManager.GetExtension("SafeMode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Web.Routing;
|
|
||||||
using Orchard.Environment.Extensions.Models;
|
|
||||||
|
|
||||||
namespace Orchard.Themes {
|
|
||||||
public interface IThemeService : IDependency {
|
|
||||||
[Obsolete]
|
|
||||||
ExtensionDescriptor GetRequestTheme(RequestContext requestContext);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user