mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Converting ItemDisplayModel's Displays collection into a Zones collection. Changing display item templates to use Zone helpers.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044547
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
|
|
||||||
OnGetDisplayViewModel<BodyAspect>((context, body) => {
|
OnGetDisplayViewModel<BodyAspect>((context, body) => {
|
||||||
var model = new BodyDisplayViewModel { BodyAspect = body };
|
var model = new BodyDisplayViewModel { BodyAspect = body };
|
||||||
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName });
|
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "body" });
|
||||||
});
|
});
|
||||||
|
|
||||||
OnGetEditorViewModel<BodyAspect>((context, body) => {
|
OnGetEditorViewModel<BodyAspect>((context, body) => {
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@
|
|||||||
<p><%=Model.Item.Description%></p>
|
<p><%=Model.Item.Description%></p>
|
||||||
<div class="actions"><a href="<%=Url.BlogPostCreate(Model.Item.Slug) %>" class="add button">New Post</a></div>
|
<div class="actions"><a href="<%=Url.BlogPostCreate(Model.Item.Slug) %>" class="add button">New Post</a></div>
|
||||||
<%--TODO: (erikpo) Need to figure out which zones should be displayed in this template--%>
|
<%--TODO: (erikpo) Need to figure out which zones should be displayed in this template--%>
|
||||||
<%=Html.DisplayZonesAny() %>
|
<% Html.ZonesAny(); %>
|
||||||
|
|
||||||
<%--<%
|
<%--<%
|
||||||
if (Model.Posts.Count() > 0) { %>
|
if (Model.Posts.Count() > 0) { %>
|
||||||
|
|||||||
@@ -6,4 +6,4 @@
|
|||||||
<h1><%=Html.TitleForPage(Model.Item.Name) %></h1>
|
<h1><%=Html.TitleForPage(Model.Item.Name) %></h1>
|
||||||
<div><%=Html.Encode(Model.Item.Description) %></div>
|
<div><%=Html.Encode(Model.Item.Description) %></div>
|
||||||
<%--TODO: (erikpo) Need to figure out which zones should be displayed in this template--%>
|
<%--TODO: (erikpo) Need to figure out which zones should be displayed in this template--%>
|
||||||
<%=Html.DisplayZonesAny() %>
|
<% Html.ZonesAny(); %>
|
||||||
+1
-1
@@ -10,4 +10,4 @@
|
|||||||
%><div class="posted">Posted by <%=Html.Encode(Model.Item.Creator.UserName)%> <%=Html.PublishedWhen(Model.Item)%></div><%
|
%><div class="posted">Posted by <%=Html.Encode(Model.Item.Creator.UserName)%> <%=Html.PublishedWhen(Model.Item)%></div><%
|
||||||
} %>
|
} %>
|
||||||
</div>
|
</div>
|
||||||
<%=Html.DisplayZonesAny() %>
|
<% Html.ZonesAny(); %>
|
||||||
@@ -15,7 +15,7 @@ namespace Orchard.Comments.Controllers {
|
|||||||
PartTemplate(part, "Parts/Comments.HasComments").Location("body", "below.5"));
|
PartTemplate(part, "Parts/Comments.HasComments").Location("body", "below.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return PartTemplate(part, "Parts/Comments.HasComments").Location("body", "below.5");
|
return PartTemplate(part, "Parts/Comments.Count").Location("body", "above.5");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(HasComments part) {
|
protected override DriverResult Editor(HasComments part) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.ContentManagement.ViewModels;
|
using Orchard.ContentManagement.ViewModels;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.DevTools.ViewModels {
|
namespace Orchard.DevTools.ViewModels {
|
||||||
public class ContentDetailsViewModel : BaseViewModel {
|
public class ContentDetailsViewModel : BaseViewModel {
|
||||||
@@ -17,7 +18,20 @@ namespace Orchard.DevTools.ViewModels {
|
|||||||
|
|
||||||
public ItemEditorModel EditorModel { get; set; }
|
public ItemEditorModel EditorModel { get; set; }
|
||||||
|
|
||||||
public IEnumerable<TemplateViewModel> Displays { get { return DisplayModel.Displays; } }
|
public IEnumerable<TemplateViewModel> Displays {
|
||||||
|
get {
|
||||||
|
return DisplayModel.Zones
|
||||||
|
.SelectMany(z => z.Value.Items
|
||||||
|
.OfType<PartDisplayZoneItem>()
|
||||||
|
.Select(x=>new{ZoneName=z.Key,Item=x}))
|
||||||
|
.Select(x => new TemplateViewModel(x.Item.Model,x.Item.Prefix) {
|
||||||
|
Model = x.Item.Model,
|
||||||
|
TemplateName=x.Item.TemplateName,
|
||||||
|
WasUsed=x.Item.WasExecuted,
|
||||||
|
ZoneName=x.ZoneName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<TemplateViewModel> Editors { get { return EditorModel.Editors; } }
|
public IEnumerable<TemplateViewModel> Editors { get { return EditorModel.Editors; } }
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -3,7 +3,7 @@
|
|||||||
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
||||||
|
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<%=Html.DisplayZone("title") %>
|
<% Html.Zone("title"); %>
|
||||||
<%=Html.DisplayZone("metatop")%>
|
<% Html.Zone("metatop"); %>
|
||||||
<%=Html.DisplayZone("body") %>
|
<% Html.Zone("body"); %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+8
-8
@@ -2,22 +2,22 @@
|
|||||||
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
<%@ Import Namespace="Orchard.Sandbox.Models" %>
|
||||||
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
<%@ Import Namespace="Orchard.ContentManagement.ViewModels" %>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<%=Html.DisplayZone("first")%>
|
<% Html.Zone("first"); %>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<%=Html.DisplayZone("title")%>
|
<% Html.Zone("title"); %>
|
||||||
</div>
|
</div>
|
||||||
<%=Html.DisplayZone("metatop")%>
|
<% Html.Zone("metatop"); %>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%=Html.ItemEditLink("Edit this page", Model.Item) %>
|
<%=Html.ItemEditLink("Edit this page", Model.Item) %>
|
||||||
<%=Html.ActionLink("Return to list", "index") %>
|
<%=Html.ActionLink("Return to list", "index") %>
|
||||||
<%=Html.DisplayZone("actions") %>
|
<% Html.Zone("actions"); %>
|
||||||
</div>
|
</div>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<%=Html.DisplayZone("body")%>
|
<% Html.Zone("body"); %>
|
||||||
</div>
|
</div>
|
||||||
<%=Html.DisplayZone("metabottom")%>
|
<% Html.Zone("metabottom"); %>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<%=Html.DisplayZonesExcept("last") %>
|
<% Html.ZonesExcept("last"); %>
|
||||||
<%=Html.DisplayZone("last")%>
|
<% Html.Zone("last"); %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -137,12 +137,11 @@ namespace Orchard.ContentManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemDisplayModel<TContentPart> BuildDisplayModel<TContentPart>(TContentPart content, string displayType) where TContentPart : IContent {
|
public ItemDisplayModel<TContentPart> BuildDisplayModel<TContentPart>(TContentPart content, string displayType) where TContentPart : IContent {
|
||||||
var itemView = new ItemDisplayModel<TContentPart> {Item = content, Displays = Enumerable.Empty<TemplateViewModel>()};
|
var itemView = new ItemDisplayModel<TContentPart> {Item = content};
|
||||||
var context = new BuildDisplayModelContext(itemView, displayType);
|
var context = new BuildDisplayModelContext(itemView, displayType);
|
||||||
foreach (var handler in Handlers) {
|
foreach (var handler in Handlers) {
|
||||||
handler.BuildDisplayModel(context);
|
handler.BuildDisplayModel(context);
|
||||||
}
|
}
|
||||||
context.DisplayModel.Displays = OrderTemplates(context.DisplayModel.Displays);
|
|
||||||
return itemView;
|
return itemView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,12 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
public ItemDisplayModel DisplayModel { get; private set; }
|
public ItemDisplayModel DisplayModel { get; private set; }
|
||||||
|
|
||||||
public void AddDisplay(TemplateViewModel display) {
|
public void AddDisplay(TemplateViewModel display) {
|
||||||
DisplayModel.Displays = DisplayModel.Displays.Concat(new[] { display });
|
//TEMP: (loudej) transition code - from TemplateViewMode to ZoneItem
|
||||||
|
DisplayModel.Zones.AddDisplayPart(
|
||||||
|
display.ZoneName+":"+display.Position,
|
||||||
|
display.Model,
|
||||||
|
display.TemplateName,
|
||||||
|
display.Prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,26 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.ViewModels {
|
namespace Orchard.ContentManagement.ViewModels {
|
||||||
public class ItemDisplayModel {
|
public class ItemDisplayModel : IZoneContainer {
|
||||||
private ContentItem _item;
|
private ContentItem _item;
|
||||||
|
|
||||||
protected ItemDisplayModel() {
|
protected ItemDisplayModel() {
|
||||||
|
Zones = new ZoneCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ItemDisplayModel(ItemDisplayModel displayModel) {
|
protected ItemDisplayModel(ItemDisplayModel displayModel) {
|
||||||
TemplateName = displayModel.TemplateName;
|
TemplateName = displayModel.TemplateName;
|
||||||
Prefix = displayModel.Prefix;
|
Prefix = displayModel.Prefix;
|
||||||
Displays = displayModel.Displays.ToArray();
|
Zones = displayModel.Zones;
|
||||||
Item = displayModel.Item;
|
Item = displayModel.Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemDisplayModel(ContentItem item) {
|
public ItemDisplayModel(ContentItem item) {
|
||||||
Item = item;
|
Item = item;
|
||||||
Displays = Enumerable.Empty<TemplateViewModel>();
|
Zones = new ZoneCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentItem Item {
|
public ContentItem Item {
|
||||||
@@ -34,7 +36,24 @@ namespace Orchard.ContentManagement.ViewModels {
|
|||||||
public Func<HtmlHelper, ItemDisplayModel, HtmlHelper> Adaptor { get; set; }
|
public Func<HtmlHelper, ItemDisplayModel, HtmlHelper> Adaptor { get; set; }
|
||||||
public string TemplateName { get; set; }
|
public string TemplateName { get; set; }
|
||||||
public string Prefix { get; set; }
|
public string Prefix { get; set; }
|
||||||
public IEnumerable<TemplateViewModel> Displays { get; set; }
|
|
||||||
|
|
||||||
|
public IEnumerable<TemplateViewModel> Displays {
|
||||||
|
get {
|
||||||
|
return Zones
|
||||||
|
.SelectMany(z => z.Value.Items
|
||||||
|
.OfType<PartDisplayZoneItem>()
|
||||||
|
.Select(x=>new{ZoneName=z.Key,Item=x}))
|
||||||
|
.Select(x => new TemplateViewModel(x.Item.Model,x.Item.Prefix) {
|
||||||
|
Model = x.Item.Model,
|
||||||
|
TemplateName=x.Item.TemplateName,
|
||||||
|
WasUsed=x.Item.WasExecuted,
|
||||||
|
ZoneName=x.ZoneName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZoneCollection Zones { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ItemDisplayModel<TPart> : ItemDisplayModel where TPart : IContent {
|
public class ItemDisplayModel<TPart> : ItemDisplayModel where TPart : IContent {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Mvc.Html;
|
using System.Web.Mvc.Html;
|
||||||
@@ -11,6 +9,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
public static MvcHtmlString DisplayForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, TItemModel item) where TItemModel : ItemDisplayModel {
|
public static MvcHtmlString DisplayForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, TItemModel item) where TItemModel : ItemDisplayModel {
|
||||||
return html.DisplayForItem(x => item);
|
return html.DisplayForItem(x => item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MvcHtmlString DisplayForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, Expression<Func<TModel, TItemModel>> expression) where TItemModel : ItemDisplayModel {
|
public static MvcHtmlString DisplayForItem<TModel, TItemModel>(this HtmlHelper<TModel> html, Expression<Func<TModel, TItemModel>> expression) where TItemModel : ItemDisplayModel {
|
||||||
|
|
||||||
var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
|
var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
|
||||||
@@ -19,49 +18,13 @@ namespace Orchard.Mvc.Html {
|
|||||||
if (model.Adaptor != null) {
|
if (model.Adaptor != null) {
|
||||||
return model.Adaptor(html, model).DisplayForModel(model.TemplateName, model.Prefix ?? "");
|
return model.Adaptor(html, model).DisplayForModel(model.TemplateName, model.Prefix ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
|
return html.DisplayFor(expression, model.TemplateName, model.Prefix ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static MvcHtmlString DisplayZone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : ItemDisplayModel {
|
public static void DisplayZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : ItemDisplayModel {
|
||||||
var templates = html.ViewData.Model.Displays.Where(x => x.ZoneName == zoneName && x.WasUsed == false);
|
html.ZonesAny();
|
||||||
return DisplayZoneImplementation(html, templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MvcHtmlString DisplayZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : ItemDisplayModel {
|
|
||||||
var templates = html.ViewData.Model.Displays.Where(x => x.WasUsed == false);
|
|
||||||
return DisplayZoneImplementation(html, templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MvcHtmlString DisplayZones<TModel>(this HtmlHelper<TModel> html, params string[] include) where TModel : ItemDisplayModel {
|
|
||||||
var templates = html.ViewData.Model.Displays.Where(x => include.Contains(x.ZoneName) && x.WasUsed == false);
|
|
||||||
return DisplayZoneImplementation(html, templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MvcHtmlString DisplayZonesExcept<TModel>(this HtmlHelper<TModel> html, params string[] exclude) where TModel : ItemDisplayModel {
|
|
||||||
var templates = html.ViewData.Model.Displays.Where(x => !exclude.Contains(x.ZoneName) && x.WasUsed == false);
|
|
||||||
return DisplayZoneImplementation(html, templates);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MvcHtmlString DisplayZoneImplementation<TModel>(HtmlHelper<TModel> html, IEnumerable<TemplateViewModel> templates) {
|
|
||||||
var count = templates.Count();
|
|
||||||
if (count == 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (count == 1) {
|
|
||||||
var t = templates.Single();
|
|
||||||
t.WasUsed = true;
|
|
||||||
return html.DisplayFor(m => t.Model, t.TemplateName, t.Prefix ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
var strings = new List<MvcHtmlString>();
|
|
||||||
foreach (var template in templates) {
|
|
||||||
var t = template;
|
|
||||||
t.WasUsed = true;
|
|
||||||
strings.Add(html.DisplayFor(m => t.Model, t.TemplateName, t.Prefix ?? ""));
|
|
||||||
}
|
|
||||||
return MvcHtmlString.Create(string.Concat(strings.ToArray()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,22 +46,31 @@ namespace Orchard.Mvc.Html {
|
|||||||
return MvcHtmlString.Create(html.Encode(titleParts[0]));
|
return MvcHtmlString.Create(html.Encode(titleParts[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : BaseViewModel {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, string partitions) where TModel : IZoneContainer {
|
||||||
IZoneManager manager = html.Resolve<IZoneManager>();
|
var manager = html.Resolve<IZoneManager>();
|
||||||
|
|
||||||
manager.Render(html, html.ViewData.Model.Zones, zoneName, partitions);
|
manager.Render(html, html.ViewData.Model.Zones, zoneName, partitions, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : IZoneContainer {
|
||||||
html.Zone(zoneName, string.Empty);
|
html.Zone(zoneName, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, Action action) where TModel : BaseViewModel {
|
public static void Zone<TModel>(this HtmlHelper<TModel> html, string zoneName, Action action) where TModel : IZoneContainer {
|
||||||
//TODO: again, IoC could move this AddAction (or similar) method out of the data-bearing object
|
//TODO: again, IoC could move this AddAction (or similar) method out of the data-bearing object
|
||||||
html.ViewData.Model.Zones.AddAction(zoneName, x => action());
|
html.ViewData.Model.Zones.AddAction(zoneName, x => action());
|
||||||
html.Zone(zoneName, string.Empty);
|
html.Zone(zoneName, string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ZonesAny<TModel>(this HtmlHelper<TModel> html) where TModel : IZoneContainer {
|
||||||
|
html.ZonesExcept();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ZonesExcept<TModel>(this HtmlHelper<TModel> html, params string[] except) where TModel : IZoneContainer {
|
||||||
|
var manager = html.Resolve<IZoneManager>();
|
||||||
|
manager.Render(html, html.ViewData.Model.Zones, null, null, except);
|
||||||
|
}
|
||||||
|
|
||||||
public static void ZoneBody<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
public static void ZoneBody<TModel>(this HtmlHelper<TModel> html, string zoneName) where TModel : BaseViewModel {
|
||||||
html.Zone(zoneName, () => html.RenderBody());
|
html.Zone(zoneName, () => html.RenderBody());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Orchard.UI.Notify;
|
|||||||
using Orchard.UI.Zones;
|
using Orchard.UI.Zones;
|
||||||
|
|
||||||
namespace Orchard.Mvc.ViewModels {
|
namespace Orchard.Mvc.ViewModels {
|
||||||
public class BaseViewModel {
|
public class BaseViewModel : IZoneContainer {
|
||||||
public BaseViewModel() {
|
public BaseViewModel() {
|
||||||
Messages = new List<NotifyEntry>();
|
Messages = new List<NotifyEntry>();
|
||||||
Zones = new ZoneCollection();
|
Zones = new ZoneCollection();
|
||||||
|
|||||||
@@ -251,6 +251,7 @@
|
|||||||
<Compile Include="UI\Zones\DelegateZoneItem.cs" />
|
<Compile Include="UI\Zones\DelegateZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
<Compile Include="UI\Zones\ItemDisplayZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\IZoneManager.cs" />
|
<Compile Include="UI\Zones\IZoneManager.cs" />
|
||||||
|
<Compile Include="UI\Zones\PartDisplayZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
|
||||||
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
<Compile Include="UI\Zones\ZoneCollection.cs" />
|
||||||
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
<Compile Include="UI\Zones\ZoneEntry.cs" />
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ using System.Web.Mvc;
|
|||||||
|
|
||||||
namespace Orchard.UI.Zones {
|
namespace Orchard.UI.Zones {
|
||||||
public interface IZoneManager : IDependency {
|
public interface IZoneManager : IDependency {
|
||||||
void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions);
|
void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions, string[] except);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Mvc.Html;
|
||||||
|
|
||||||
|
namespace Orchard.UI.Zones {
|
||||||
|
public class PartDisplayZoneItem : ZoneItem {
|
||||||
|
public object Model { get; set; }
|
||||||
|
public string TemplateName { get; set; }
|
||||||
|
public string Prefix { get; set; }
|
||||||
|
|
||||||
|
public override void Execute<TModel>(HtmlHelper<TModel> html) {
|
||||||
|
html.ViewContext.Writer.Write(
|
||||||
|
html.DisplayFor(m => Model, TemplateName, Prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,19 @@ using System.Web.Mvc;
|
|||||||
using Orchard.ContentManagement.ViewModels;
|
using Orchard.ContentManagement.ViewModels;
|
||||||
|
|
||||||
namespace Orchard.UI.Zones {
|
namespace Orchard.UI.Zones {
|
||||||
|
public interface IZoneContainer {
|
||||||
|
ZoneCollection Zones { get; }
|
||||||
|
}
|
||||||
|
|
||||||
public class ZoneCollection : Dictionary<string, ZoneEntry> {
|
public class ZoneCollection : Dictionary<string, ZoneEntry> {
|
||||||
public void AddRenderPartial(string location, string templateName, object model) {
|
public void AddRenderPartial(string location, string templateName, object model) {
|
||||||
AddZoneItem(location, new RenderPartialZoneItem() { Model = model, TemplateName = templateName });
|
AddZoneItem(location, new RenderPartialZoneItem { Model = model, TemplateName = templateName });
|
||||||
}
|
}
|
||||||
public void AddDisplayItem(string location, ItemDisplayModel displayModel) {
|
public void AddDisplayItem(string location, ItemDisplayModel displayModel) {
|
||||||
AddZoneItem(location, new ItemDisplayZoneItem { DisplayModel = displayModel });
|
AddZoneItem(location, new ItemDisplayZoneItem() { DisplayModel = displayModel });
|
||||||
|
}
|
||||||
|
public void AddDisplayPart(string location, object model, string templateName, string prefix) {
|
||||||
|
AddZoneItem(location, new PartDisplayZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
|
||||||
}
|
}
|
||||||
public void AddAction(string location, Action<HtmlHelper> action) {
|
public void AddAction(string location, Action<HtmlHelper> action) {
|
||||||
AddZoneItem(location, new DelegateZoneItem { Action = action });
|
AddZoneItem(location, new DelegateZoneItem { Action = action });
|
||||||
|
|||||||
@@ -2,16 +2,22 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.UI.Navigation;
|
||||||
|
|
||||||
namespace Orchard.UI.Zones {
|
namespace Orchard.UI.Zones {
|
||||||
public class ZoneManager : IZoneManager {
|
public class ZoneManager : IZoneManager {
|
||||||
public void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions) {
|
public void Render<TModel>(HtmlHelper<TModel> html, ZoneCollection zones, string zoneName, string partitions, string[] exclude) {
|
||||||
|
IEnumerable<Group> groups;
|
||||||
ZoneEntry zone;
|
if (string.IsNullOrEmpty(zoneName)) {
|
||||||
if (!zones.TryGetValue(zoneName, out zone))
|
var entries = zones.Values.Where(z => !exclude.Contains(z.ZoneName));
|
||||||
return;
|
groups = BuildGroups(partitions, entries);
|
||||||
|
}
|
||||||
var groups = BuildGroups(partitions, zone);
|
else {
|
||||||
|
ZoneEntry entry;
|
||||||
|
if (!zones.TryGetValue(zoneName, out entry))
|
||||||
|
return;
|
||||||
|
groups = BuildGroups(partitions, new[] { entry });
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var item in groups.SelectMany(x => x.Items)) {
|
foreach (var item in groups.SelectMany(x => x.Items)) {
|
||||||
item.WasExecuted = true;
|
item.WasExecuted = true;
|
||||||
@@ -20,14 +26,15 @@ namespace Orchard.UI.Zones {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<Group> BuildGroups(string partitions, ZoneEntry zone) {
|
private IEnumerable<Group> BuildGroups(string partitions, IEnumerable<ZoneEntry> zones) {
|
||||||
|
|
||||||
var partitionCodes = (":before " + partitions + " :* :after").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
var partitionCodes = (":before " + partitions + " :* :after").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
var itemsRemaining = zone.Items.Where(x => x.WasExecuted == false);
|
var itemsRemaining = zones.SelectMany(zone => zone.Items.Where(x => x.WasExecuted == false));
|
||||||
|
|
||||||
Group catchAllItem = null;
|
Group catchAllItem = null;
|
||||||
|
|
||||||
|
var positionComparer = new PositionComparer();
|
||||||
var results = new List<Group>();
|
var results = new List<Group>();
|
||||||
foreach (var code in partitionCodes) {
|
foreach (var code in partitionCodes) {
|
||||||
if (code == ":*") {
|
if (code == ":*") {
|
||||||
@@ -36,13 +43,17 @@ namespace Orchard.UI.Zones {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var value = code;
|
var value = code;
|
||||||
var items = itemsRemaining.Where(x => (":" + x.Position).StartsWith(value));
|
var items = itemsRemaining
|
||||||
|
.Where(x => (":" + x.Position).StartsWith(value))
|
||||||
|
.OrderBy(x => x.Position, positionComparer);
|
||||||
results.Add(new Group { Items = items.ToArray() });
|
results.Add(new Group { Items = items.ToArray() });
|
||||||
itemsRemaining = itemsRemaining.Except(items).ToArray();
|
itemsRemaining = itemsRemaining.Except(items).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (catchAllItem != null) {
|
if (catchAllItem != null) {
|
||||||
catchAllItem.Items = itemsRemaining;
|
catchAllItem.Items = itemsRemaining
|
||||||
|
.OrderBy(x => x.Position, positionComparer)
|
||||||
|
.ToArray();
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user