From 7dd863624acd39395465b2134c7e189f07e401c0 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 1 Sep 2010 13:46:13 -0700 Subject: [PATCH] Some initial work towards the new rendering scheme --HG-- branch : dev --- .../DisplayManagement/IShapeMetadata.cs | 1 + .../DisplayManagement/Shapes/ShapeMetadata.cs | 1 + src/Orchard/IWorkContextAccessor.cs | 8 +++++ src/Orchard/Orchard.Framework.csproj | 3 ++ .../Admin/Notification/NotificationFilter.cs | 32 +++++++++---------- src/Orchard/UI/IPage.cs | 17 ++++++++++ src/Orchard/UI/Navigation/MenuFilter.cs | 4 ++- src/Orchard/WorkContext.cs | 20 ++++++++++++ 8 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 src/Orchard/IWorkContextAccessor.cs create mode 100644 src/Orchard/UI/IPage.cs create mode 100644 src/Orchard/WorkContext.cs diff --git a/src/Orchard/DisplayManagement/IShapeMetadata.cs b/src/Orchard/DisplayManagement/IShapeMetadata.cs index 06a4d43b2..e14fc321a 100644 --- a/src/Orchard/DisplayManagement/IShapeMetadata.cs +++ b/src/Orchard/DisplayManagement/IShapeMetadata.cs @@ -2,5 +2,6 @@ public interface IShapeMetadata { string Type { get; set; } string Position { get; set; } + bool WasExecuted { get; set; } } } diff --git a/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs b/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs index 0a70c9a67..e25072d1c 100644 --- a/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs +++ b/src/Orchard/DisplayManagement/Shapes/ShapeMetadata.cs @@ -2,5 +2,6 @@ public class ShapeMetadata : IShapeMetadata { public string Type { get; set; } public string Position { get; set; } + public bool WasExecuted { get; set; } } } \ No newline at end of file diff --git a/src/Orchard/IWorkContextAccessor.cs b/src/Orchard/IWorkContextAccessor.cs new file mode 100644 index 000000000..1f29e844c --- /dev/null +++ b/src/Orchard/IWorkContextAccessor.cs @@ -0,0 +1,8 @@ +using System.Web; + +namespace Orchard { + public interface IWorkContextAccessor : IDependency { + WorkContext GetContext(); + WorkContext GetContext(HttpContextBase httpContext); + } +} \ No newline at end of file diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 0d1925101..e9a4ba3e7 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -406,11 +406,13 @@ + + @@ -550,6 +552,7 @@ + diff --git a/src/Orchard/UI/Admin/Notification/NotificationFilter.cs b/src/Orchard/UI/Admin/Notification/NotificationFilter.cs index 9fcbd5159..d838ad92f 100644 --- a/src/Orchard/UI/Admin/Notification/NotificationFilter.cs +++ b/src/Orchard/UI/Admin/Notification/NotificationFilter.cs @@ -1,41 +1,39 @@ using System.Linq; using System.Web.Mvc; +using Orchard.DisplayManagement; using Orchard.Mvc.Filters; -using Orchard.Mvc.ViewModels; namespace Orchard.UI.Admin.Notification { public class AdminNotificationFilter : FilterProvider, IResultFilter { private readonly INotificationManager _notificationManager; + private readonly IWorkContextAccessor _workContextAccessor; + private readonly IShapeHelperFactory _shapeHelperFactory; - public AdminNotificationFilter(INotificationManager notificationManager) { + public AdminNotificationFilter(INotificationManager notificationManager, IWorkContextAccessor workContextAccessor, IShapeHelperFactory shapeHelperFactory) { _notificationManager = notificationManager; + _workContextAccessor = workContextAccessor; + _shapeHelperFactory = shapeHelperFactory; } public void OnResultExecuting(ResultExecutingContext filterContext) { - - if ( !AdminFilter.IsApplied(filterContext.RequestContext) ) { + if (!AdminFilter.IsApplied(filterContext.RequestContext)) return; - } - var viewResult = filterContext.Result as ViewResultBase; // if it's not a view result, a redirect for example - if ( viewResult == null ) - return; - - var baseViewModel = BaseViewModel.From(viewResult); - // if it's not a view model that holds messages, don't touch temp data either - if ( baseViewModel == null ) + if (filterContext.Result is ViewResultBase) return; var messageEntries = _notificationManager.GetNotifications().ToList(); + if (!messageEntries.Any()) + return; - if ( messageEntries.Any() ) { - baseViewModel.Zones.AddRenderPartial("content:before", "Messages", messageEntries); + var shape = _shapeHelperFactory.CreateHelper(); + foreach(var messageEntry in messageEntries) { + _workContextAccessor.GetContext(filterContext.RequestContext.HttpContext).CurrentPage.Zones["Messages"].Add(shape.Message(messageEntry)); + // need extension to enable -> _workContextAccessor.GetContext(filterContext).CurrentPage.Zones["Messages"].Add(shape.Message()); } } - public void OnResultExecuted(ResultExecutedContext filterContext) { - - } + public void OnResultExecuted(ResultExecutedContext filterContext) {} } } diff --git a/src/Orchard/UI/IPage.cs b/src/Orchard/UI/IPage.cs new file mode 100644 index 000000000..2e5045bbc --- /dev/null +++ b/src/Orchard/UI/IPage.cs @@ -0,0 +1,17 @@ +using Orchard.UI.Zones; + +namespace Orchard.UI { + public interface IPage { + + IZoneCollection Zones { get; } + } + + public interface IZoneCollection { + IZone this[string key] { get; } + } + + public interface IZone { + void Add(object item); + void Add(object item, string position); + } +} \ No newline at end of file diff --git a/src/Orchard/UI/Navigation/MenuFilter.cs b/src/Orchard/UI/Navigation/MenuFilter.cs index e844ac5f4..f694f9e35 100644 --- a/src/Orchard/UI/Navigation/MenuFilter.cs +++ b/src/Orchard/UI/Navigation/MenuFilter.cs @@ -6,9 +6,11 @@ using Orchard.UI.Admin; namespace Orchard.UI.Navigation { public class MenuFilter : FilterProvider, IResultFilter { private readonly INavigationManager _navigationManager; + private readonly IWorkContextAccessor _workContextAccessor; - public MenuFilter(INavigationManager navigationManager) { + public MenuFilter(INavigationManager navigationManager, IWorkContextAccessor workContextAccessor) { _navigationManager = navigationManager; + _workContextAccessor = workContextAccessor; } public void OnResultExecuting(ResultExecutingContext filterContext) { diff --git a/src/Orchard/WorkContext.cs b/src/Orchard/WorkContext.cs new file mode 100644 index 000000000..4e407d27e --- /dev/null +++ b/src/Orchard/WorkContext.cs @@ -0,0 +1,20 @@ +using Orchard.Security; +using Orchard.Settings; +using Orchard.UI; + +namespace Orchard { + public abstract class WorkContext { + public IPage CurrentPage { + get { return State(); } + } + public ISite CurrentSite { + get { return State(); } + } + public IUser CurrentUser { + get { return State(); } + } + + public abstract T Service(); + public abstract T State(); + } +} \ No newline at end of file