diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/DataMigrations/WidgetsDataMigration.cs b/src/Orchard.Web/Modules/Orchard.Widgets/DataMigrations/WidgetsDataMigration.cs new file mode 100644 index 000000000..af3b88096 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Widgets/DataMigrations/WidgetsDataMigration.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.Data.Migration; +using Orchard.Environment.Configuration; +using Orchard.Environment.Descriptor.Models; +using Orchard.Environment.State; +using Orchard.Events; +using Orchard.Widgets.Models; + +namespace Orchard.Widgets.DataMigrations { + public interface IDefaultLayersInitializer : IEventHandler { + void CreateDefaultLayers(); + } + + public class DefaultLayersInitializer : IDefaultLayersInitializer { + private readonly IContentManager _contentManager; + + public DefaultLayersInitializer(IContentManager contentManager) { + _contentManager = contentManager; + } + + public void CreateDefaultLayers() { + _contentManager.Create("Layer", t => t.Record.Name = "Default"); + _contentManager.Create("Layer", t => t.Record.Name = "Authenticated"); + _contentManager.Create("Layer", t => t.Record.Name = "Anonymous"); + } + } + + public class WidgetsDataMigration : DataMigrationImpl { + private readonly IProcessingEngine _processingEngine; + private readonly ShellSettings _shellSettings; + private readonly ShellDescriptor _shellDescriptor; + + public WidgetsDataMigration(IProcessingEngine processingEngine, ShellSettings shellSettings, ShellDescriptor shellDescriptor) { + _processingEngine = processingEngine; + _shellSettings = shellSettings; + _shellDescriptor = shellDescriptor; + } + + public int Create() { + SchemaBuilder.CreateTable("LayerPartRecord", table => table + .ContentPartRecord() + .Column("Name") + .Column("Description") + .Column("Rule") + ); + + SchemaBuilder.CreateTable("WidgetPartRecord", table => table + .ContentPartRecord() + .Column("Title") + .Column("Position") + .Column("Zone") + ); + + ContentDefinitionManager.AlterTypeDefinition("Layer", + cfg => cfg + .WithPart("LayerPart") + ); + + ContentDefinitionManager.AlterTypeDefinition("HtmlWidget", + cfg => cfg + .WithPart("WidgetPart") + .WithPart("BodyPart") + ); + + CreateDefaultLayers(); + + return 1; + } + + private void CreateDefaultLayers() { + _processingEngine.AddTask( + _shellSettings, + _shellDescriptor, + "IDefaultLayersInitializer.CreateDefaultLayers", + new Dictionary()); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs index 2fcf4b879..77dbf72b1 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Filters/WidgetFilter.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.Mvc.Filters; using Orchard.UI.Admin; +using Orchard.Widgets.Models; namespace Orchard.Widgets.Filters { public class WidgetFilter : FilterProvider, IResultFilter { @@ -15,9 +18,6 @@ namespace Orchard.Widgets.Filters { } public void OnResultExecuting(ResultExecutingContext filterContext) { - } - - public void OnResultExecuted(ResultExecutedContext filterContext) { var workContext = _workContextAccessor.GetContext(filterContext); if (workContext == null || @@ -27,11 +27,20 @@ namespace Orchard.Widgets.Filters { return; } - // Get Layers - // Get LayerZones - // Get WidgetParts - // BuildDisplayModel - // Add to Zone. + // Once the Rule Engine is done: + // Get Layers and filter by zone and rule + IEnumerable widgetParts = _contentManager.Query().List(); + + // Build and add shape to zone. + var zones = workContext.Page.Zones; + foreach (var widgetPart in widgetParts) { + var widgetShape = _contentManager.BuildDisplayModel(widgetPart); + + zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position); + } + } + + public void OnResultExecuted(ResultExecutedContext filterContext) { } } } diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Models/Layer.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Models/Layer.cs deleted file mode 100644 index 21b3da5c8..000000000 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Models/Layer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; -using Orchard.ContentManagement; - -namespace Orchard.Widgets.Models { - public class Layer : ContentItem { - public IList LayerZones = new List(); - public LayerPart LayerPart = new LayerPart(); - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Models/LayerZone.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Models/LayerZone.cs deleted file mode 100644 index 84fb95a1b..000000000 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Models/LayerZone.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System.Collections.Generic; - -namespace Orchard.Widgets.Models { - public class LayerZone { - public IList WidgetParts = new List(); - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Models/WidgetPartRecord.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Models/WidgetPartRecord.cs index 1a1b29fa8..e53aa03b7 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Models/WidgetPartRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Models/WidgetPartRecord.cs @@ -4,5 +4,6 @@ namespace Orchard.Widgets.Models { public class WidgetPartRecord : ContentPartRecord { public virtual string Title { get; set; } public virtual string Position { get; set; } + public virtual string Zone { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj b/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj index 2a3ebfb45..48a9b64b4 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Orchard.Widgets.csproj @@ -59,19 +59,16 @@ + - - - - diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Services/IWidgetService.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Services/IWidgetService.cs deleted file mode 100644 index 68f9d8611..000000000 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Services/IWidgetService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; -using Orchard.Widgets.Models; - -namespace Orchard.Widgets.Services { - public interface IWidgetService : IDependency { - IEnumerable GetLayers(); - } -} diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Services/WidgetService.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Services/WidgetService.cs deleted file mode 100644 index fa2990e7f..000000000 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Services/WidgetService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using Orchard.Logging; -using Orchard.Settings; -using Orchard.Widgets.Models; - -namespace Orchard.Widgets.Services { - public class WidgetService : IWidgetService { - public WidgetService() { - Logger = NullLogger.Instance; - } - - public ILogger Logger { get; set; } - protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } - - #region IWidgetService Members - - public IEnumerable GetLayers() { - throw new NotImplementedException(); - } - - #endregion - } -} \ No newline at end of file