mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Removing the IContentDisplayInfo interface in favor of new manager method GetItemMetadata
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042888
This commit is contained in:
@@ -5,7 +5,7 @@ using Orchard.Models;
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPost : ContentPart<BlogPostRecord>, IContentDisplayInfo {
|
||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||
public readonly static ContentType ContentType = new ContentType { Name = "blogpost", DisplayName = "Blog Post" };
|
||||
|
||||
public Blog Blog { get; set; }
|
||||
@@ -16,20 +16,5 @@ namespace Orchard.Blogs.Models {
|
||||
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
|
||||
public DateTime? Published { get { return Record.Published; } }
|
||||
|
||||
#region IContentDisplayInfo Members
|
||||
|
||||
public string DisplayText {
|
||||
get { return Title; }
|
||||
}
|
||||
|
||||
public RouteValueDictionary DisplayRouteValues() {
|
||||
return new RouteValueDictionary(new { area = "Orchard.Blogs", controller = "BlogPost", action = "Item", blogSlug = Blog.Slug, postSlug = Slug });
|
||||
}
|
||||
|
||||
public RouteValueDictionary EditRouteValues() {
|
||||
return new RouteValueDictionary(new { area = "Orchard.Blogs", controller = "BlogPost", action = "Edit", blogSlug = Blog.Slug, postSlug = Slug });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
@@ -17,6 +18,28 @@ namespace Orchard.Blogs.Models {
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>("blogpost"));
|
||||
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
||||
OnLoaded<BlogPost>((context, bp) => bp.Blog = contentManager.Get<Blog>(bp.Record.Blog.Id));
|
||||
|
||||
OnGetItemMetadata<BlogPost>((context, bp) => {
|
||||
context.Metadata.DisplayText = bp.Title;
|
||||
context.Metadata.DisplayRouteValues =
|
||||
new RouteValueDictionary(
|
||||
new {
|
||||
area = "Orchard.Blogs",
|
||||
controller = "BlogPost",
|
||||
action = "Item",
|
||||
blogSlug = bp.Blog.Slug,
|
||||
postSlug = bp.Slug
|
||||
});
|
||||
context.Metadata.EditorRouteValues =
|
||||
new RouteValueDictionary(
|
||||
new {
|
||||
area = "Orchard.Blogs",
|
||||
controller = "BlogPost",
|
||||
action = "Edit",
|
||||
blogSlug = bp.Blog.Slug,
|
||||
postSlug = bp.Slug
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ namespace Orchard.Comments.Services {
|
||||
IEnumerable<Comment> GetCommentsForCommentedContent(int id);
|
||||
IEnumerable<Comment> GetCommentsForCommentedContent(int id, CommentStatus status);
|
||||
Comment GetComment(int id);
|
||||
IContentDisplayInfo GetDisplayForCommentedContent(int id);
|
||||
ContentItemMetadata GetDisplayForCommentedContent(int id);
|
||||
void CreateComment(Comment comment);
|
||||
void UpdateComment(int id, string name, string email, string siteName, string commentText, CommentStatus status);
|
||||
void MarkCommentAsSpam(int commentId);
|
||||
@@ -73,8 +73,11 @@ namespace Orchard.Comments.Services {
|
||||
return _commentRepository.Get(id);
|
||||
}
|
||||
|
||||
public IContentDisplayInfo GetDisplayForCommentedContent(int id) {
|
||||
return _contentManager.Get(id).As<IContentDisplayInfo>();
|
||||
public ContentItemMetadata GetDisplayForCommentedContent(int id) {
|
||||
var content = _contentManager.Get(id);
|
||||
if (content == null)
|
||||
return null;
|
||||
return _contentManager.GetItemMetadata(content);
|
||||
}
|
||||
|
||||
public void CreateComment(Comment comment) {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
@@ -8,11 +9,11 @@ namespace Orchard.Sandbox.Models {
|
||||
public class SandboxContentProvider : ContentProvider {
|
||||
|
||||
public override IEnumerable<ContentType> GetContentTypes() {
|
||||
return new[] {SandboxPage.ContentType};
|
||||
return new[] { SandboxPage.ContentType };
|
||||
}
|
||||
|
||||
public SandboxContentProvider(
|
||||
IRepository<SandboxPageRecord> pageRepository,
|
||||
IRepository<SandboxPageRecord> pageRepository,
|
||||
IRepository<SandboxSettingsRecord> settingsRepository) {
|
||||
|
||||
// define the "sandboxpage" content type
|
||||
@@ -22,6 +23,26 @@ namespace Orchard.Sandbox.Models {
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(SandboxPage.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<SandboxPageRecord>(pageRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
|
||||
OnGetItemMetadata<SandboxPage>((context, page) => {
|
||||
context.Metadata.DisplayText = page.Record.Name;
|
||||
context.Metadata.DisplayRouteValues =
|
||||
new RouteValueDictionary(
|
||||
new {
|
||||
area = "Orchard.Sandbox",
|
||||
controller = "Page",
|
||||
action = "Show",
|
||||
id = context.ContentItem.Id,
|
||||
});
|
||||
context.Metadata.EditorRouteValues =
|
||||
new RouteValueDictionary(
|
||||
new {
|
||||
area = "Orchard.Sandbox",
|
||||
controller = "Page",
|
||||
action = "Edit",
|
||||
id = context.ContentItem.Id,
|
||||
});
|
||||
});
|
||||
|
||||
// add settings to site, and simple record-template gui
|
||||
Filters.Add(new ActivatingFilter<ContentPart<SandboxSettingsRecord>>("site"));
|
||||
Filters.Add(new StorageFilter<SandboxSettingsRecord>(settingsRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
|
@@ -2,21 +2,9 @@ using System.Web.Routing;
|
||||
using Orchard.Models;
|
||||
|
||||
namespace Orchard.Sandbox.Models {
|
||||
public class SandboxPage : ContentPart<SandboxPageRecord>, IContentDisplayInfo {
|
||||
public class SandboxPage : ContentPart<SandboxPageRecord> {
|
||||
|
||||
public readonly static ContentType ContentType = new ContentType {Name = "sandboxpage", DisplayName = "Sandbox Page"};
|
||||
|
||||
string IContentDisplayInfo.DisplayText {
|
||||
get { return Record.Name; }
|
||||
}
|
||||
|
||||
RouteValueDictionary IContentDisplayInfo.DisplayRouteValues() {
|
||||
return new RouteValueDictionary(new { area = "Orchard.Sandbox", controller = "Page", action = "Show", id = ContentItem.Id });
|
||||
}
|
||||
|
||||
RouteValueDictionary IContentDisplayInfo.EditRouteValues() {
|
||||
return new RouteValueDictionary(new { area = "Orchard.Sandbox", controller = "Page", action = "Edit", id = ContentItem.Id });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,9 @@ namespace Orchard.Tags.Models {
|
||||
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
|
||||
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
|
||||
|
||||
OnGetDisplays<HasTags>((context, part) => {
|
||||
context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()) { Position = "2", TemplateName = "HasTagsList" });
|
||||
context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()) { Position = "5" });
|
||||
OnGetDisplays<HasTags>((context, hasTags) => {
|
||||
context.Displays.Add(new ModelTemplate(hasTags) { Position = "2", TemplateName = "HasTagsList" });
|
||||
context.Displays.Add(new ModelTemplate(hasTags) { Position = "5" });
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -21,10 +21,10 @@
|
||||
<% foreach (var contentItem in Model.Contents) { %>
|
||||
<tr>
|
||||
<td>
|
||||
<%=contentItem.As<IContentDisplayInfo>().DisplayText%>
|
||||
<%=Html.ItemDisplayText(contentItem)%>
|
||||
</td>
|
||||
<td>
|
||||
<%=Html.ItemDisplayLink(contentItem)%>
|
||||
<%=Html.ItemDisplayLink(contentItem)%>
|
||||
</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
|
@@ -19,6 +19,7 @@ namespace Orchard.Models {
|
||||
|
||||
public IEnumerable<ContentPart> Parts { get { return _parts; } }
|
||||
|
||||
public IContentManager ContentManager { get; set; }
|
||||
|
||||
public bool Has(Type partType) {
|
||||
return partType==typeof(ContentItem) || _parts.Any(part => partType.IsAssignableFrom(part.GetType()));
|
||||
|
13
src/Orchard/Models/ContentItemMetadata.cs
Normal file
13
src/Orchard/Models/ContentItemMetadata.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Orchard.Models {
|
||||
public class ContentItemMetadata {
|
||||
public string DisplayText { get; set; }
|
||||
public RouteValueDictionary DisplayRouteValues { get; set; }
|
||||
public RouteValueDictionary EditorRouteValues { get; set; }
|
||||
|
||||
public IEnumerable<string> DisplayTabs { get; set; }
|
||||
public IEnumerable<string> EditorTabs { get; set; }
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ namespace Orchard.Models {
|
||||
if (_drivers == null)
|
||||
_drivers = _context.Resolve<IEnumerable<IContentProvider>>();
|
||||
return _drivers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ContentType> GetContentTypes() {
|
||||
@@ -54,6 +54,10 @@ namespace Orchard.Models {
|
||||
ContentType = contentType,
|
||||
ContentItem = context.Builder.Build()
|
||||
};
|
||||
|
||||
// back-reference for convenience (e.g. getting metadata when in a view)
|
||||
context2.ContentItem.ContentManager = this;
|
||||
|
||||
foreach (var driver in Drivers) {
|
||||
driver.Activated(context2);
|
||||
}
|
||||
@@ -121,6 +125,16 @@ namespace Orchard.Models {
|
||||
}
|
||||
}
|
||||
|
||||
public ContentItemMetadata GetItemMetadata(IContent content) {
|
||||
var context = new GetItemMetadataContext {
|
||||
ContentItem = content.ContentItem,
|
||||
Metadata = new ContentItemMetadata()
|
||||
};
|
||||
foreach (var driver in Drivers) {
|
||||
driver.GetItemMetadata(context);
|
||||
}
|
||||
return context.Metadata;
|
||||
}
|
||||
|
||||
public IEnumerable<ModelTemplate> GetDisplays(IContent content) {
|
||||
var context = new GetDisplaysContext(content);
|
||||
@@ -149,7 +163,7 @@ namespace Orchard.Models {
|
||||
private static IEnumerable<ModelTemplate> OrderTemplates(IEnumerable<ModelTemplate> templates) {
|
||||
var comparer = new PositionComparer();
|
||||
return templates.OrderBy(x => x.Position ?? "6", comparer);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public IContentQuery<ContentItem> Query() {
|
||||
|
@@ -33,6 +33,9 @@ namespace Orchard.Models.Driver {
|
||||
Filters.Add(new InlineStorageFilter<TPart> { OnLoaded = handler });
|
||||
}
|
||||
|
||||
protected void OnGetItemMetadata<TPart>(Action<GetItemMetadataContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetItemMetadata = handler });
|
||||
}
|
||||
protected void OnGetDisplays<TPart>(Action<GetDisplaysContext, TPart> handler) where TPart : class, IContent {
|
||||
Filters.Add(new InlineTemplateFilter<TPart> { OnGetDisplays = handler });
|
||||
}
|
||||
@@ -69,9 +72,13 @@ namespace Orchard.Models.Driver {
|
||||
}
|
||||
|
||||
class InlineTemplateFilter<TPart> : TemplateFilterBase<TPart> where TPart : class, IContent {
|
||||
public Action<GetItemMetadataContext, TPart> OnGetItemMetadata { get; set; }
|
||||
public Action<GetDisplaysContext, TPart> OnGetDisplays { get; set; }
|
||||
public Action<GetEditorsContext, TPart> OnGetEditors { get; set; }
|
||||
public Action<UpdateContentContext, TPart> OnUpdateEditors { get; set; }
|
||||
protected override void GetItemMetadata(GetItemMetadataContext context, TPart instance) {
|
||||
if (OnGetItemMetadata != null) OnGetItemMetadata(context, instance);
|
||||
}
|
||||
protected override void GetDisplays(GetDisplaysContext context, TPart instance) {
|
||||
if (OnGetDisplays != null) OnGetDisplays(context, instance);
|
||||
}
|
||||
@@ -124,6 +131,11 @@ namespace Orchard.Models.Driver {
|
||||
}
|
||||
|
||||
|
||||
void IContentProvider.GetItemMetadata(GetItemMetadataContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.GetItemMetadata(context);
|
||||
GetItemMetadata(context);
|
||||
}
|
||||
void IContentProvider.GetDisplays(GetDisplaysContext context) {
|
||||
foreach (var filter in Filters.OfType<IContentTemplateFilter>())
|
||||
filter.GetDisplays(context);
|
||||
@@ -149,6 +161,7 @@ namespace Orchard.Models.Driver {
|
||||
protected virtual void Creating(CreateContentContext context) { }
|
||||
protected virtual void Created(CreateContentContext context) { }
|
||||
|
||||
protected virtual void GetItemMetadata(GetItemMetadataContext context) { }
|
||||
protected virtual void GetDisplays(GetDisplaysContext context) { }
|
||||
protected virtual void GetEditors(GetEditorsContext context) { }
|
||||
protected virtual void UpdateEditors(UpdateContentContext context) {}
|
||||
|
13
src/Orchard/Models/Driver/GetDisplaysContext.cs
Normal file
13
src/Orchard/Models/Driver/GetDisplaysContext.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetDisplaysContext {
|
||||
public GetDisplaysContext(IContent content) {
|
||||
ContentItem = content.ContentItem;
|
||||
Displays = new List<ModelTemplate>();
|
||||
}
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public IList<ModelTemplate> Displays { get; set; }
|
||||
}
|
||||
}
|
@@ -10,13 +10,4 @@ namespace Orchard.Models.Driver {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public IList<ModelTemplate> Editors { get; set; }
|
||||
}
|
||||
|
||||
public class GetDisplaysContext {
|
||||
public GetDisplaysContext(IContent content) {
|
||||
ContentItem = content.ContentItem;
|
||||
Displays = new List<ModelTemplate>();
|
||||
}
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public IList<ModelTemplate> Displays { get; set; }
|
||||
}
|
||||
}
|
6
src/Orchard/Models/Driver/GetItemMetadataContext.cs
Normal file
6
src/Orchard/Models/Driver/GetItemMetadataContext.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Orchard.Models.Driver {
|
||||
public class GetItemMetadataContext {
|
||||
public ContentItem ContentItem { get; set; }
|
||||
public ContentItemMetadata Metadata { get; set; }
|
||||
}
|
||||
}
|
@@ -11,8 +11,9 @@ namespace Orchard.Models.Driver {
|
||||
void Loading(LoadContentContext context);
|
||||
void Loaded(LoadContentContext context);
|
||||
|
||||
void GetItemMetadata(GetItemMetadataContext context);
|
||||
void GetDisplays(GetDisplaysContext context);
|
||||
void GetEditors(GetEditorsContext context);
|
||||
void UpdateEditors(UpdateContentContext context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ using System.Text;
|
||||
|
||||
namespace Orchard.Models.Driver {
|
||||
interface IContentTemplateFilter : IContentFilter {
|
||||
void GetItemMetadata(GetItemMetadataContext context);
|
||||
void GetDisplays(GetDisplaysContext context);
|
||||
void GetEditors(GetEditorsContext context);
|
||||
void UpdateEditors(UpdateContentContext context);
|
||||
|
@@ -6,10 +6,15 @@ using System.Text;
|
||||
namespace Orchard.Models.Driver {
|
||||
public abstract class TemplateFilterBase<TPart> : IContentTemplateFilter where TPart : class, IContent {
|
||||
|
||||
protected virtual void GetItemMetadata(GetItemMetadataContext context, TPart instance) { }
|
||||
protected virtual void GetDisplays(GetDisplaysContext context, TPart instance) { }
|
||||
protected virtual void GetEditors(GetEditorsContext context, TPart instance) { }
|
||||
protected virtual void UpdateEditors(UpdateContentContext context, TPart instance) { }
|
||||
|
||||
void IContentTemplateFilter.GetItemMetadata(GetItemMetadataContext context) {
|
||||
if (context.ContentItem.Is<TPart>())
|
||||
GetItemMetadata(context, context.ContentItem.As<TPart>());
|
||||
}
|
||||
|
||||
void IContentTemplateFilter.GetDisplays(GetDisplaysContext context) {
|
||||
if (context.ContentItem.Is<TPart>())
|
||||
|
@@ -1,9 +1,9 @@
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Orchard.Models {
|
||||
public interface IContentDisplayInfo : IContent {
|
||||
string DisplayText { get; }
|
||||
RouteValueDictionary DisplayRouteValues();
|
||||
RouteValueDictionary EditRouteValues();
|
||||
}
|
||||
//public interface IContentDisplayInfo : IContent {
|
||||
// string DisplayText { get; }
|
||||
// RouteValueDictionary DisplayRouteValues();
|
||||
// RouteValueDictionary EditRouteValues();
|
||||
//}
|
||||
}
|
@@ -14,6 +14,7 @@ namespace Orchard.Models {
|
||||
|
||||
IContentQuery<ContentItem> Query();
|
||||
|
||||
ContentItemMetadata GetItemMetadata(IContent contentItem);
|
||||
IEnumerable<ModelTemplate> GetDisplays(IContent contentItem);
|
||||
IEnumerable<ModelTemplate> GetEditors(IContent contentItem);
|
||||
IEnumerable<ModelTemplate> UpdateEditors(IContent contentItem, IUpdateModel updater);
|
||||
|
@@ -5,13 +5,23 @@ using Orchard.Models;
|
||||
|
||||
namespace Orchard.Mvc.Html {
|
||||
public static class ContentItemExtensions {
|
||||
public static string ItemDisplayText(this HtmlHelper html, IContent content) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayText == null)
|
||||
return null;
|
||||
return html.Encode(metadata.DisplayText);
|
||||
}
|
||||
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
var display = content.As<IContentDisplayInfo>();
|
||||
if (display == null)
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
var values = display.DisplayRouteValues();
|
||||
return html.ActionLink(linkText ?? display.DisplayText, Convert.ToString(values["action"]), values);
|
||||
return html.ActionLink(
|
||||
linkText ?? metadata.DisplayText,
|
||||
Convert.ToString(metadata.DisplayRouteValues["action"]),
|
||||
metadata.DisplayRouteValues);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemDisplayLink(this HtmlHelper html, IContent content) {
|
||||
@@ -19,12 +29,14 @@ namespace Orchard.Mvc.Html {
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, string linkText, IContent content) {
|
||||
var display = content.As<IContentDisplayInfo>();
|
||||
if (display == null)
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.EditorRouteValues == null)
|
||||
return null;
|
||||
|
||||
var values = display.EditRouteValues();
|
||||
return html.ActionLink(linkText ?? display.DisplayText, Convert.ToString(values["action"]), values);
|
||||
return html.ActionLink(
|
||||
linkText ?? metadata.DisplayText,
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues);
|
||||
}
|
||||
|
||||
public static MvcHtmlString ItemEditLink(this HtmlHelper html, IContent content) {
|
||||
|
@@ -128,11 +128,14 @@
|
||||
<Compile Include="Localization\NullLocalizer.cs" />
|
||||
<Compile Include="Models\Aspects\ICommonAspect.cs" />
|
||||
<Compile Include="Models\ContentItem.cs" />
|
||||
<Compile Include="Models\ContentItemMetadata.cs" />
|
||||
<Compile Include="Models\ContentModule.cs" />
|
||||
<Compile Include="Models\ContentType.cs" />
|
||||
<Compile Include="Models\DefaultContentQuery.cs" />
|
||||
<Compile Include="Models\Driver\ActivatedContentContext.cs" />
|
||||
<Compile Include="Models\Driver\ActivatingFilter.cs" />
|
||||
<Compile Include="Models\Driver\GetDisplaysContext.cs" />
|
||||
<Compile Include="Models\Driver\GetItemMetadataContext.cs" />
|
||||
<Compile Include="Models\Driver\IContentActivatingFilter.cs" />
|
||||
<Compile Include="Models\Driver\IContentFilter.cs" />
|
||||
<Compile Include="Models\Driver\IContentStorageFilter.cs" />
|
||||
|
Reference in New Issue
Block a user