mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Some initial work towards the new rendering scheme
--HG-- branch : dev
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
public interface IShapeMetadata {
|
||||
string Type { get; set; }
|
||||
string Position { get; set; }
|
||||
bool WasExecuted { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -2,5 +2,6 @@
|
||||
public class ShapeMetadata : IShapeMetadata {
|
||||
public string Type { get; set; }
|
||||
public string Position { get; set; }
|
||||
public bool WasExecuted { get; set; }
|
||||
}
|
||||
}
|
8
src/Orchard/IWorkContextAccessor.cs
Normal file
8
src/Orchard/IWorkContextAccessor.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard {
|
||||
public interface IWorkContextAccessor : IDependency {
|
||||
WorkContext GetContext();
|
||||
WorkContext GetContext(HttpContextBase httpContext);
|
||||
}
|
||||
}
|
@@ -406,11 +406,13 @@
|
||||
<Compile Include="Environment\IHostLocalRestart.cs" />
|
||||
<Compile Include="Environment\IShellContainerRegistrations.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\DynamicModuleVirtualPathProvider.cs" />
|
||||
<Compile Include="IWorkContextAccessor.cs" />
|
||||
<Compile Include="Mvc\Html\Shapes.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\Razor\RazorCompilationEventsShim.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\Razor\RazorViewEngineProvider.cs" />
|
||||
<Compile Include="Mvc\ViewEngines\Razor\WebViewPage.cs" />
|
||||
<Compile Include="Services\IHtmlFilter.cs" />
|
||||
<Compile Include="UI\IPage.cs" />
|
||||
<Compile Include="Utility\Hash.cs" />
|
||||
<Compile Include="Data\ISessionConfigurationCache.cs" />
|
||||
<Compile Include="Data\Migration\Generator\ISchemaCommandGenerator.cs" />
|
||||
@@ -550,6 +552,7 @@
|
||||
<Compile Include="Tasks\Indexing\IIndexingTask.cs" />
|
||||
<Compile Include="Tasks\Indexing\IIndexingTaskManager.cs" />
|
||||
<Compile Include="Validation\Argument.cs" />
|
||||
<Compile Include="WorkContext.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Caching\AcquireContext.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) {}
|
||||
}
|
||||
}
|
||||
|
17
src/Orchard/UI/IPage.cs
Normal file
17
src/Orchard/UI/IPage.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
@@ -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) {
|
||||
|
20
src/Orchard/WorkContext.cs
Normal file
20
src/Orchard/WorkContext.cs
Normal file
@@ -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<IPage>(); }
|
||||
}
|
||||
public ISite CurrentSite {
|
||||
get { return State<ISite>(); }
|
||||
}
|
||||
public IUser CurrentUser {
|
||||
get { return State<IUser>(); }
|
||||
}
|
||||
|
||||
public abstract T Service<T>();
|
||||
public abstract T State<T>();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user