Getting Orchard.Blogs on the new UI composition model (for display)

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-10-15 14:40:35 -07:00
parent 4fa953c150
commit 262f4a4559
19 changed files with 143 additions and 104 deletions

View File

@@ -6,7 +6,7 @@ using System.Xml.Linq;
using Orchard.Blogs.Models;
using Orchard.Blogs.Routing;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.ContentManagement;
using Orchard.DisplayManagement;
using Orchard.Logging;
using Orchard.Themes;
@@ -53,25 +53,27 @@ namespace Orchard.Blogs.Controllers {
if (correctedSlug == null)
return HttpNotFound();
BlogPart blog = _blogService.Get(correctedSlug);
if (blog == null)
var blogPart = _blogService.Get(correctedSlug);
if (blogPart == null)
return HttpNotFound();
var blogPosts = _blogPostService.Get(blog, (page - 1)*pageSize, pageSize).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
var blogPosts = _blogPostService.Get(blogPart, (page - 1) * pageSize, pageSize)
.Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
blogPart.As<BlogPagerPart>().Page = page;
blogPart.As<BlogPagerPart>().PageSize = pageSize;
blogPart.As<BlogPagerPart>().BlogSlug = correctedSlug;
blogPart.As<BlogPagerPart>().ThereIsANextPage = _blogPostService.Get(blogPart, (page) * pageSize, pageSize).Any();
var blog = _services.ContentManager.BuildDisplay(blogPart);
var list = Shape.List();
list.AddRange(blogPosts);
var blogShape = _services.ContentManager.BuildDisplay(blog);
var model = new DisplayBlogViewModel {
Blog = blogShape,
BlogPostList = list,
Page = page,
PageSize = pageSize
};
return View(model);
blog.ContentItem = blogPart;
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
return View("Display", blog);
}
public ActionResult LiveWriterManifest(string blogSlug) {

View File

@@ -1,6 +1,5 @@
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.ContentsLocation.Models;
@@ -16,16 +15,17 @@ namespace Orchard.Blogs.Drivers {
}
protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) {
BlogPart blog = null;
if (!string.IsNullOrWhiteSpace(part.ForBlog))
blog = _blogService.Get(part.ForBlog);
return ContentShape("Parts_Blogs_BlogArchives",
() => {
BlogPart blog = null;
if (!string.IsNullOrWhiteSpace(part.ForBlog))
blog = _blogService.Get(part.ForBlog);
if ( blog != null ) {
var model = new BlogPostArchiveViewModel {BlogPart = blog, Archives = _blogPostService.GetArchives(blog)};
return ContentPartTemplate(model, "Parts/Blogs.BlogArchives");
}
if (blog == null)
return null;
return null;
return shapeHelper.Parts_Blogs_BlogArchives(ContentItem: part, Blog: blog, Archives: _blogPostService.GetArchives(blog));
}).Location("Content");
}
protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) {

View File

@@ -0,0 +1,11 @@
using Orchard.Blogs.Models;
using Orchard.ContentManagement.Drivers;
namespace Orchard.Blogs.Drivers {
public class BlogPagerPartDriver : ContentPartDriver<BlogPagerPart> {
protected override DriverResult Display(BlogPagerPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Blogs_Blog_Pager",
() => shapeHelper.Parts_Blogs_Blog_Pager(ContentPart: part, Page: part.Page, PageSize: part.PageSize, BlogSlug: part.BlogSlug, ThereIsANextPage: part.ThereIsANextPage));
}
}
}

View File

@@ -38,13 +38,15 @@ namespace Orchard.Blogs.Drivers {
() => shapeHelper.Parts_Blogs_Blog_Manage(ContentPart: part)),
ContentShape("Parts_Blogs_Blog_Description",
() => shapeHelper.Parts_Blogs_Blog_Description(ContentPart: part, Description: part.Description)),
// todo: (heskew) implement a paging solution that doesn't require blog posts to be tied to the blog within the controller
ContentShape("Parts_Blogs_BlogPost_List",
() => {
_feedManager.Register(part);
var list = shapeHelper.List();
list.AddRange(_blogPostService.Get(part)
.Select(bp => _contentManager.BuildDisplay(bp, "Summary")));
return shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, ContentItems: list);
return null;
// var list = shapeHelper.List();
// list.AddRange(_blogPostService.Get(part)
// .Select(bp => _contentManager.BuildDisplay(bp, "Summary")));
// return shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, ContentItems: list);
}),
ContentShape("Parts_Blogs_BlogPost_List_Admin",
() => {

View File

@@ -18,7 +18,7 @@ namespace Orchard.Blogs.Drivers {
}
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
IEnumerable<BlogPostPart> blogPosts = null;
IEnumerable<BlogPostPart> blogPosts;
BlogPart blog = null;
if (!string.IsNullOrWhiteSpace(part.ForBlog))
@@ -32,7 +32,6 @@ namespace Orchard.Blogs.Drivers {
.Select(ci => ci.As<BlogPostPart>());
}
else {
var blogs = _blogService.Get().ToList();
blogPosts = _contentManager.Query(VersionOptions.Published, "BlogPost")
.Join<CommonPartRecord>()
.OrderByDescending(cr => cr.CreatedUtc)
@@ -41,12 +40,11 @@ namespace Orchard.Blogs.Drivers {
}
var list = shapeHelper.List();
list.AddRange(blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "Summary.BlogPost")));
list.AddRange(blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "Summary")));
var blogPostList = shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, BlogPosts: list);
blogPostList.Metadata.Type = "Parts_Blogs_BlogPost.List";
var blogPostList = shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, ContentItems: list);
return ContentShape(blogPostList).Location("Primary");
return ContentShape(shapeHelper.Parts_Blogs_RecentBlogPosts(ContentItem: part, ContentItems: blogPostList));
}
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {

View File

@@ -89,5 +89,11 @@ namespace Orchard.Blogs {
return 5;
}
public int UpdateFrom5() {
ContentDefinitionManager.AlterTypeDefinition("Blog",
cfg => cfg.WithPart("BlogPagerPart"));
return 6;
}
}
}

View File

@@ -0,0 +1,10 @@
using Orchard.ContentManagement;
namespace Orchard.Blogs.Models {
public class BlogPagerPart : ContentPart {
public int Page { get; set; }
public int PageSize { get; set; }
public string BlogSlug { get; set; }
public bool ThereIsANextPage { get; set; }
}
}

View File

@@ -68,11 +68,13 @@
<ItemGroup>
<Compile Include="AdminMenu.cs" />
<Compile Include="Drivers\BlogArchivesPartDriver.cs" />
<Compile Include="Drivers\BlogPagerPartDriver.cs" />
<Compile Include="Drivers\RecentBlogPostsPartDriver.cs" />
<Compile Include="Handlers\BlogArchivesPartHandler.cs" />
<Compile Include="Handlers\RecentBlogPostsPartHandler.cs" />
<Compile Include="Models\BlogArchivesPart.cs" />
<Compile Include="Models\BlogArchivesPartRecord.cs" />
<Compile Include="Models\BlogPagerPart.cs" />
<Compile Include="Models\RecentBlogPostsPart.cs" />
<Compile Include="Models\RecentBlogPostsPartRecord.cs" />
<Compile Include="ResourceManifest.cs" />
@@ -107,8 +109,7 @@
<Compile Include="Services\IBlogService.cs" />
<Compile Include="Services\XmlRpcHandler.cs" />
<Compile Include="RemoteBlogPublishingShapes.cs" />
<Compile Include="ViewModels\BlogPostArchiveViewModel.cs" />
<Compile Include="ViewModels\DisplayBlogViewModel.cs" />
<Compile Include="Shapes.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\Admin\images\draft.gif" />
@@ -161,7 +162,7 @@
<SubType>Designer</SubType>
</None>
<Content Include="Views\RemoteBlogPublishing.cshtml" />
<None Include="Views\DisplayTemplates\Parts\Blogs.BlogArchives.cshtml" />
<None Include="Views\Parts\Blogs.BlogArchives.cshtml" />
<None Include="Views\EditorTemplates\Parts\Blogs.RecentBlogPosts.cshtml" />
<None Include="Views\EditorTemplates\Parts\Blogs.BlogArchives.cshtml" />
<None Include="Views\Items\Blog.DetailAdmin.cshtml" />
@@ -169,6 +170,8 @@
<None Include="Views\Items\BlogPost.Editor.cshtml" />
<None Include="Views\Items\BlogPost.SummaryAdmin.cshtml" />
<None Include="Views\Parts\Blogs.BlogPost.List.cshtml" />
<None Include="Views\Parts\Blogs.Blog.Pager.cshtml" />
<None Include="Views\Parts\Blogs.RecentBlogPosts.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@@ -1,13 +1,23 @@
<Placement>
<Place Parts_Blogs_Blog_Manage="-"/>
<Place Parts_Blogs_Blog_Description="-"/>
<Place Parts_Blogs_BlogPost_List="-"/>
<Place Parts_Blogs_BlogPost_List_Admin="-"/>
<!-- available display shapes -->
<!--
Parts_Blogs_Blog_Manage
Parts_Blogs_Blog_Description
Parts_Blogs_Blog_Pager
Parts_Blogs_BlogPost_List -> when in the blog detail display the blog post list is currently hard-coded to Content:5 to enable the current state of blog paging
Parts_Blogs_BlogPost_List_Admin
-->
<!-- widget and edit shapes just get default placement -->
<!-- edit "shapes" -->
<Place Parts_Blogs_Blog_Fields="Primary:2"/>
<!-- widgets -->
<Place Parts_Blogs_BlogArchives="Content"/>
<Place Parts_Blogs_RecentBlogPosts="Content"/>
<Match ContentType="Blog">
<Match DisplayType="Detail">
<!-- current paging solution makes this redundant
<Place Parts_Blogs_BlogPost_List="Content:5" /> -->
<!-- blog posts currently added to the blog within the controller into Content:5 <Place Parts_Blogs_BlogPost_List="Content:5" />-->
<Place Parts_Blogs_Blog_Pager="Content:after"
Parts_Blogs_Blog_Description="Content:before" />
</Match>
<Match DisplayType="DetailAdmin">
<Place Parts_Blogs_BlogPost_List_Admin="Content:5"

View File

@@ -0,0 +1,22 @@
//using Orchard.ContentManagement;
//using Orchard.DisplayManagement.Descriptors;
//namespace Orchard.Blogs {
// public class Shapes : IShapeTableProvider {
// public void Discover(ShapeTableBuilder builder) {
// builder.Describe("Items_Content__Blog")
// .OnCreated(created => {
// var blog = created.Shape;
// blog.Content.Add(created.New.Parts_Blogs_BlogPost_List(ContentPart: blog.ContentItem, ContentItems: blog.));
// })
// .OnDisplaying(displaying => {
// ContentItem contentItem = displaying.Shape.ContentItem;
// if (contentItem != null) {
// var zoneName = contentItem.As<WidgetPart>().Zone;
// displaying.ShapeMetadata.Alternates.Add("Items_Widget__" + contentItem.ContentType);
// displaying.ShapeMetadata.Alternates.Add("Items_Widget__" + zoneName);
// }
// });
// }
// }
//}

View File

@@ -1,9 +0,0 @@
using System.Collections.Generic;
using Orchard.Blogs.Models;
namespace Orchard.Blogs.ViewModels {
public class BlogPostArchiveViewModel {
public BlogPart BlogPart { get; set; }
public IEnumerable<KeyValuePair<ArchiveData, int>> Archives { get; set; }
}
}

View File

@@ -1,8 +0,0 @@
namespace Orchard.Blogs.ViewModels {
public class DisplayBlogViewModel {
public dynamic Blog { get; set; }
public dynamic BlogPostList { get; set; }
public int Page { get; set; }
public int PageSize { get; set; }
}
}

View File

@@ -1,26 +1,2 @@
@model Orchard.Blogs.ViewModels.DisplayBlogViewModel
@using Orchard.Blogs.Extensions;
@{
Style.Include("pagination.css");
}
@Display(Model.Blog)
@if (Model.BlogPostList.Items.Count > 0) {
@Display(Model.BlogPostList)
<ul class="pagination">
@if(Model.BlogPostList.Items.Count == Model.PageSize) {
<li class="older">
@Html.ActionLink(T("Older Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.Blog.Slug, page = Model.Page + 1 })
</li>
}
@if(Model.Page > 1) {
<li class="newer">
@Html.ActionLink(T("Newer Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.Blog.Slug, page = Model.Page - 1 })
</li>
}
</ul>
}
else {
<p>@T("There are no posts for this blog.")</p>
}
@Display(Model.Meta)
@Display(Model.Content)

View File

@@ -3,6 +3,6 @@
<div>
@Html.LabelFor(m => m.ForBlog)
@Html.TextBoxFor(m => m.ForBlog)
<span class="hint">@T("The blog's slug to display the archives for.")</span>
<span class="hint">@T("Show the archives for which blog? Note: specify the blog's slug.")</span>
</div>
</fieldset>

View File

@@ -0,0 +1,18 @@
@using Orchard.Blogs.Extensions;
@{
Style.Include("pagination.css");
}
@if (Model.ThereIsANextPage || Model.Page > 1) {
<ul class="blog-pagination">
@if(Model.ThereIsANextPage) {
<li class="older">
@Html.ActionLink(T("Older Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.BlogSlug, page = Model.Page + 1 })
</li>
}
@if(Model.Page > 1) {
<li class="newer">
@Html.ActionLink(T("Newer Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.BlogSlug, page = Model.Page - 1 })
</li>
}
</ul>
}

View File

@@ -1,23 +1,20 @@
@model Orchard.Blogs.ViewModels.BlogPostArchiveViewModel
@using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models;
@{
Style.Require("BlogsArchives");
Script.Require("BlogsArchives");
IEnumerable<KeyValuePair<ArchiveData, int>> archives = Model.Archives;
}
<div class="archives">
<h3>@T("Archives")</h3>
@if (Model.Archives.Count() > 20) {
@if (archives.Count() > 20) {
<ul class="years">
@{
int lastYear = Model.Archives.First().Key.Year;
int firstYear = Model.Archives.Last().Key.Year;
int lastYear = archives.First().Key.Year;
int firstYear = archives.Last().Key.Year;
}
@for (int year = lastYear; year >= firstYear; year--) {
var yearMonths = Model.Archives.Where(m => m.Key.Year == year);
var yearMonths = archives.Where(m => m.Key.Year == year);
if (year == lastYear) {
<li>
@@ -28,15 +25,14 @@
if (year != lastYear) {
<li class="previous">
<h4>@year <span>(@yearMonths.Sum(ym => ym.Value))</span></h4>
@Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0:MMMM} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.BlogPart.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList")
@Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0:MMMM} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth((string)Model.BlogPart.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList")
</li>
}
}
</ul>
}
else if (Model.Archives.Count() > 0) {
@Html.UnorderedList(Model.Archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.BlogPart.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList")
else if (archives.Count() > 0) {
@Html.UnorderedList(archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth((string)Model.BlogPart.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList")
}
else {
<div class="message info">@T("None found")</div>

View File

@@ -1,9 +1,7 @@
@{
IEnumerable<object> blogPosts = Model.BlogPosts;
IEnumerable<object> blogPosts = Model.ContentItems;
}
@Display(ContentItems)
@Display(Model.ContentItems)
@if (blogPosts == null || blogPosts.Count() < 1) {
<p>@T("There are no posts for this blog.")</p>
}
hi
}

View File

@@ -0,0 +1 @@
@Display(Model.ContentItems)

View File

@@ -44,6 +44,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Tests", "Tools\Orchard.Tests\Orchard.Tests.csproj", "{0DFA2E10-96C8-4E05-BC10-B710B97ECCDE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Notes", "_Notes", "{8A49DB66-40B2-4B6A-BFF0-D4839A240D00}"
ProjectSection(SolutionItems) = preProject
Shapes.txt = Shapes.txt
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orchard.Modules", "Orchard.Web\Modules\Orchard.Modules\Orchard.Modules.csproj", "{17F86780-9A1F-4AA1-86F1-875EEC2730C7}"
EndProject