mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Modifying the blog show template
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043450
This commit is contained in:
@@ -24,8 +24,8 @@ namespace Orchard.Blogs.Controllers {
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
|
||||
public BlogController(ISessionLocator sessionLocator, IContentManager contentManager,
|
||||
IAuthorizer authorizer, INotifier notifier,
|
||||
public BlogController(ISessionLocator sessionLocator, IContentManager contentManager,
|
||||
IAuthorizer authorizer, INotifier notifier,
|
||||
IBlogService blogService, IBlogPostService blogPostService) {
|
||||
_sessionLocator = sessionLocator;
|
||||
_contentManager = contentManager;
|
||||
@@ -50,17 +50,19 @@ namespace Orchard.Blogs.Controllers {
|
||||
public ActionResult Item(string blogSlug) {
|
||||
Blog blog = _blogService.Get(blogSlug);
|
||||
|
||||
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var posts = _blogPostService.Get(blog).Select(bp => _contentManager.GetDisplayViewModel(bp, null, "Summary"));
|
||||
// var posts = _blogPostService.Get(blog).Select(bp => _contentManager.GetDisplayViewModel(bp, null, "Summary"));
|
||||
|
||||
return View(new BlogViewModel { Blog = blog, Posts = posts });
|
||||
return View(new BlogViewModel {
|
||||
Blog = _contentManager.GetDisplayViewModel(blog, null, "Detail")
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
||||
public ActionResult ItemForAdmin(string blogSlug)
|
||||
{
|
||||
public ActionResult ItemForAdmin(string blogSlug) {
|
||||
Blog blog = _blogService.Get(blogSlug);
|
||||
|
||||
if (blog == null)
|
||||
@@ -116,7 +118,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogEditViewModel { Blog = blog };
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(model.Blog.ContentItem, "",this);
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(model.Blog.ContentItem, "", this);
|
||||
|
||||
IValueProvider values = input.ToValueProvider();
|
||||
if (!TryUpdateModel(model, values))
|
||||
|
@@ -1,9 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPostProvider : ContentProvider {
|
||||
@@ -11,7 +14,11 @@ namespace Orchard.Blogs.Models {
|
||||
return new[] { BlogPost.ContentType };
|
||||
}
|
||||
|
||||
public BlogPostProvider(IRepository<BlogPostRecord> repository, IContentManager contentManager) {
|
||||
public BlogPostProvider(
|
||||
IRepository<BlogPostRecord> repository,
|
||||
IContentManager contentManager,
|
||||
IBlogPostService blogPostService) {
|
||||
|
||||
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blogpost"));
|
||||
@@ -42,6 +49,19 @@ namespace Orchard.Blogs.Models {
|
||||
postSlug = bp.Slug
|
||||
});
|
||||
});
|
||||
|
||||
OnGetDisplayViewModel<Blog>((context, blog) => {
|
||||
if (context.DisplayType != "Detail") {
|
||||
return;
|
||||
}
|
||||
|
||||
var posts = blogPostService.Get(blog);
|
||||
var viewModels = posts.Select(
|
||||
bp => contentManager.GetDisplayViewModel(bp, null, "Summary"));
|
||||
context.AddDisplay(new TemplateViewModel(viewModels) { TemplateName = "BlogPostList", ZoneName = "body" });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ namespace Orchard.Blogs.Models {
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>("blog"));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>("blog"));
|
||||
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
||||
Filters.Add(new ContentItemTemplates<Blog>("Blog"));
|
||||
}
|
||||
}
|
||||
}
|
@@ -111,11 +111,13 @@
|
||||
<Content Include="Views\Blog\List.aspx" />
|
||||
<Content Include="Views\Blog\ListForAdmin.aspx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogPostSummary.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\Blog.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogPostList.ascx" />
|
||||
<Content Include="Views\Shared\BlogPostPreview.ascx" />
|
||||
<Content Include="Views\BlogPost\EditorTemplates\CreateBlogPostViewModel.ascx" />
|
||||
<Content Include="Views\BlogPost\Item.aspx" />
|
||||
<Content Include="Views\Blog\Create.aspx" />
|
||||
<Content Include="Views\Blog\DisplayTemplates\Blog.ascx" />
|
||||
<Content Include="Views\Blog\DisplayTemplates\_Blog.ascx" />
|
||||
<Content Include="Views\Blog\Edit.aspx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\BlogEditViewModel.ascx" />
|
||||
<Content Include="Views\Blog\EditorTemplates\BlogPermalink.ascx" />
|
||||
|
@@ -5,7 +5,9 @@ using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogViewModel : BaseViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public IEnumerable<ItemDisplayViewModel<BlogPost>> Posts { get; set; }
|
||||
public ItemDisplayViewModel<Blog> Blog { get; set; }
|
||||
|
||||
//public Blog Blog { get; set; }
|
||||
//public IEnumerable<ItemDisplayViewModel<BlogPost>> Posts { get; set; }
|
||||
}
|
||||
}
|
@@ -1,15 +1,18 @@
|
||||
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BlogViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models"%>
|
||||
<%@ Import Namespace="Orchard.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels" %>
|
||||
<%-- todo: (heskew) make master-less when we get into theming --%>
|
||||
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
|
||||
<div class="manage"><a href="<%=Url.BlogEdit(Model.Blog.Slug) %>" class="ibutton edit">edit</a></div>
|
||||
<%=Html.DisplayForItem(m=>m.Blog) %>
|
||||
<%-- <div class="manage"><a href="<%=Url.BlogEdit(Model.Blog.Slug) %>" class="ibutton edit">edit</a></div>
|
||||
<h2><%=Html.Encode(Model.Blog.Name) %></h2>
|
||||
<div><%=Html.Encode(Model.Blog.Description) %></div>
|
||||
<%=Html.UnorderedList(Model.Posts, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "posts contentItems") %>
|
||||
</asp:Content>
|
||||
--%>
|
||||
</asp:Content>
|
||||
|
@@ -0,0 +1,17 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemDisplayViewModel<Blog>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
|
||||
<h2><%=Html.Encode(Model.Item.Name) %></h2>
|
||||
<div><%=Html.Encode(Model.Item.Description) %></div>
|
||||
<%=Html.DisplayZonesAny() %>
|
||||
|
||||
<%-- <div class="manage"><a href="<%=Url.BlogEdit(Model.Blog.Slug) %>" class="ibutton edit">edit</a></div>
|
||||
<h2><%=Html.Encode(Model.Blog.Name) %></h2>
|
||||
<div><%=Html.Encode(Model.Blog.Description) %></div>
|
||||
<%=Html.UnorderedList(Model.Posts, (bp, i) => Html.DisplayForItem(bp).ToHtmlString(), "posts contentItems") %>
|
||||
--%>
|
@@ -0,0 +1,14 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<ItemDisplayViewModel<BlogPost>>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Models" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models" %>
|
||||
<ul class="posts contentItems">
|
||||
<%foreach (var item in Model) { %>
|
||||
<li>
|
||||
<%= Html.DisplayForItem(item)%>
|
||||
</li>
|
||||
<%} %>
|
||||
</ul>
|
Reference in New Issue
Block a user