mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Splitting the widget global management zone placement UI into zones which are
applicable to the current theme and zones which are not. --HG-- branch : dev
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Contents.Controllers;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc.Extensions;
|
||||
@@ -62,12 +63,17 @@ namespace Orchard.Widgets.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();
|
||||
IEnumerable<string> allZones = _widgetsService.GetZones();
|
||||
IEnumerable<string> currentThemesZones = _widgetsService.GetZones(currentTheme);
|
||||
|
||||
dynamic viewModel = Shape.ViewModel()
|
||||
.CurrentTheme(_siteThemeService.GetSiteTheme())
|
||||
.CurrentTheme(currentTheme)
|
||||
.CurrentLayer(currentLayer)
|
||||
.Layers(layers)
|
||||
.Widgets(_widgetsService.GetWidgets())
|
||||
.Zones(_widgetsService.GetZones());
|
||||
.Zones(currentThemesZones)
|
||||
.OrphanZones(allZones.Except(currentThemesZones));
|
||||
|
||||
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
||||
return View((object)viewModel);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Widgets.Models;
|
||||
|
||||
namespace Orchard.Widgets.Services {
|
||||
public interface IWidgetsService : IDependency {
|
||||
|
||||
IEnumerable<string> GetZones();
|
||||
IEnumerable<string> GetZones(ExtensionDescriptor theme);
|
||||
|
||||
IEnumerable<LayerPart> GetLayers();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Widgets.Models;
|
||||
@@ -13,14 +14,17 @@ namespace Orchard.Widgets.Services {
|
||||
[UsedImplicitly]
|
||||
public class WidgetsService : IWidgetsService {
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public WidgetsService(
|
||||
IContentManager contentManager,
|
||||
IFeatureManager featureManager) {
|
||||
IFeatureManager featureManager,
|
||||
IExtensionManager extensionManager) {
|
||||
|
||||
_contentManager = contentManager;
|
||||
_featureManager = featureManager;
|
||||
_extensionManager = extensionManager;
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<string, string>> GetWidgetTypes() {
|
||||
@@ -58,6 +62,27 @@ namespace Orchard.Widgets.Services {
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetZones(ExtensionDescriptor theme) {
|
||||
IEnumerable<string> zones = new List<string>();
|
||||
|
||||
// get the zones for this theme
|
||||
if (theme.Zones != null)
|
||||
zones = theme.Zones.Split(',')
|
||||
.Distinct()
|
||||
.Select(x => x.Trim())
|
||||
.ToList();
|
||||
|
||||
// add the zones for the base theme
|
||||
if (!string.IsNullOrWhiteSpace(theme.BaseTheme)) {
|
||||
string baseTheme = theme.BaseTheme;
|
||||
theme = _extensionManager.GetExtension(baseTheme);
|
||||
if (theme != null)
|
||||
zones.Concat(GetZones(theme).Where(z => !zones.Contains(z)));
|
||||
}
|
||||
|
||||
return zones;
|
||||
}
|
||||
|
||||
public IEnumerable<WidgetPart> GetWidgets(int layerId) {
|
||||
return GetWidgets().Where(widgetPart => widgetPart.As<ICommonPart>().Container.ContentItem.Id == layerId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user