mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
- Adding DataMigrations for Widgets.
- Creating Layer and HtmlWidget content types. - Adding 3 default Layers using the IProcessingEngine interface. - Injection of widget shapes into zones from a resultfilter. - Some refactoring/cleanup in the Widgets module. --HG-- branch : dev
This commit is contained in:
@@ -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<LayerPart>("Layer", t => t.Record.Name = "Default");
|
||||
_contentManager.Create<LayerPart>("Layer", t => t.Record.Name = "Authenticated");
|
||||
_contentManager.Create<LayerPart>("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<string>("Name")
|
||||
.Column<string>("Description")
|
||||
.Column<string>("Rule")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("WidgetPartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("Title")
|
||||
.Column<string>("Position")
|
||||
.Column<string>("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<string, object>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -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<WidgetPart> widgetParts = _contentManager.Query<WidgetPart, WidgetPartRecord>().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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Widgets.Models {
|
||||
public class Layer : ContentItem {
|
||||
public IList<LayerZone> LayerZones = new List<LayerZone>();
|
||||
public LayerPart LayerPart = new LayerPart();
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Widgets.Models {
|
||||
public class LayerZone {
|
||||
public IList<WidgetPart> WidgetParts = new List<WidgetPart>();
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
@@ -59,19 +59,16 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="DataMigrations\WidgetsDataMigration.cs" />
|
||||
<Compile Include="Handlers\LayerPartHandler.cs" />
|
||||
<Compile Include="Handlers\WidgetPartHandler.cs" />
|
||||
<Compile Include="Models\Layer.cs" />
|
||||
<Compile Include="Models\LayerPart.cs" />
|
||||
<Compile Include="Models\LayerPartRecord.cs" />
|
||||
<Compile Include="Models\LayerZone.cs" />
|
||||
<Compile Include="Models\WidgetPart.cs" />
|
||||
<Compile Include="Models\WidgetPartRecord.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Filters\WidgetFilter.cs" />
|
||||
<Compile Include="Services\IWidgetService.cs" />
|
||||
<Compile Include="Services\WidgetService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
|
@@ -1,8 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Widgets.Models;
|
||||
|
||||
namespace Orchard.Widgets.Services {
|
||||
public interface IWidgetService : IDependency {
|
||||
IEnumerable<Layer> GetLayers();
|
||||
}
|
||||
}
|
@@ -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<Layer> GetLayers() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user