mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
Adding a rudimentary recent blog posts widget
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.Blogs.Models;
|
||||||
|
using Orchard.Blogs.Services;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.ContentsLocation.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.Drivers {
|
||||||
|
public class RecentBlogPostsPartDriver : ContentPartDriver<RecentBlogPostsPart> {
|
||||||
|
private readonly IBlogService _blogService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public RecentBlogPostsPartDriver(IBlogService blogService, IContentManager contentManager) {
|
||||||
|
_blogService = blogService;
|
||||||
|
_contentManager = contentManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
|
||||||
|
IEnumerable<BlogPostPart> blogPosts = null;
|
||||||
|
|
||||||
|
BlogPart blog = null;
|
||||||
|
if (!string.IsNullOrWhiteSpace(part.ForBlog))
|
||||||
|
blog = _blogService.Get(part.ForBlog);
|
||||||
|
|
||||||
|
if (blog != null) {
|
||||||
|
blogPosts = _contentManager.Query(VersionOptions.Published, "BlogPost")
|
||||||
|
.Join<CommonPartRecord>().Where(cr => cr.Container == blog.Record.ContentItemRecord)
|
||||||
|
.OrderByDescending(cr => cr.CreatedUtc)
|
||||||
|
.Slice(0, part.Count)
|
||||||
|
.Select(ci => ci.As<BlogPostPart>());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var blogs = _blogService.Get().ToList();
|
||||||
|
blogPosts = _contentManager.Query(VersionOptions.Published, "BlogPost")
|
||||||
|
.Join<CommonPartRecord>()
|
||||||
|
.OrderByDescending(cr => cr.CreatedUtc)
|
||||||
|
.Slice(0, part.Count)
|
||||||
|
.Select(ci => ci.As<BlogPostPart>());
|
||||||
|
}
|
||||||
|
|
||||||
|
var list = shapeHelper.List();
|
||||||
|
list.AddRange(blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "Summary.BlogPost")));
|
||||||
|
|
||||||
|
var blogPostList = shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, BlogPosts: list);
|
||||||
|
blogPostList.Metadata.Type = "Parts_Blogs_BlogPost.List";
|
||||||
|
|
||||||
|
return ContentShape(blogPostList).Location("Primary");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {
|
||||||
|
var location = part.GetLocation("Editor", "Primary", "5");
|
||||||
|
return ContentPartTemplate(part, "Parts/Blogs.RecentBlogPosts").Location(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(RecentBlogPostsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
|
updater.TryUpdateModel(part, Prefix, null, null);
|
||||||
|
return Editor(part, shapeHelper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
using Orchard.Blogs.Models;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.Data;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.Handlers {
|
||||||
|
[UsedImplicitly]
|
||||||
|
public class RecentBlogPostsPartHandler : ContentHandler {
|
||||||
|
public RecentBlogPostsPartHandler(IRepository<RecentBlogPostsPartRecord> repository) {
|
||||||
|
Filters.Add(StorageFilter.For(repository));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -55,5 +55,22 @@ namespace Orchard.Blogs {
|
|||||||
}));
|
}));
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UpdateFrom3() {
|
||||||
|
SchemaBuilder.CreateTable("RecentBlogPostsPartRecord", table => table
|
||||||
|
.ContentPartRecord()
|
||||||
|
.Column<string>("BlogSlug")
|
||||||
|
.Column<int>("Count")
|
||||||
|
);
|
||||||
|
|
||||||
|
ContentDefinitionManager.AlterTypeDefinition("RecentBlogPosts",
|
||||||
|
cfg => cfg
|
||||||
|
.WithPart("RecentBlogPostsPart")
|
||||||
|
.WithPart("CommonPart")
|
||||||
|
.WithPart("WidgetPart")
|
||||||
|
.WithSetting("Stereotype", "Widget")
|
||||||
|
);
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.Models {
|
||||||
|
public class RecentBlogPostsPart : ContentPart<RecentBlogPostsPartRecord> {
|
||||||
|
public string ForBlog {
|
||||||
|
get { return Record.BlogSlug; }
|
||||||
|
set { Record.BlogSlug = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count {
|
||||||
|
get { return Record.Count; }
|
||||||
|
set { Record.Count = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,8 @@
|
|||||||
|
using Orchard.ContentManagement.Records;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.Models {
|
||||||
|
public class RecentBlogPostsPartRecord : ContentPartRecord {
|
||||||
|
public virtual string BlogSlug { get; set; }
|
||||||
|
public virtual int Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@@ -67,6 +67,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AdminMenu.cs" />
|
<Compile Include="AdminMenu.cs" />
|
||||||
|
<Compile Include="Drivers\RecentBlogPostsPartDriver.cs" />
|
||||||
|
<Compile Include="Handlers\RecentBlogPostsPartHandler.cs" />
|
||||||
|
<Compile Include="Models\RecentBlogPostsPart.cs" />
|
||||||
|
<Compile Include="Models\RecentBlogPostsPartRecord.cs" />
|
||||||
<Compile Include="ResourceManifest.cs" />
|
<Compile Include="ResourceManifest.cs" />
|
||||||
<Compile Include="Commands\BlogCommands.cs" />
|
<Compile Include="Commands\BlogCommands.cs" />
|
||||||
<Compile Include="Controllers\BlogAdminController.cs" />
|
<Compile Include="Controllers\BlogAdminController.cs" />
|
||||||
@@ -183,6 +187,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App_Data\Localization\fr-FR\orchard.module.po" />
|
<None Include="App_Data\Localization\fr-FR\orchard.module.po" />
|
||||||
|
<None Include="Views\EditorTemplates\Parts\Blogs.RecentBlogPosts.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
|
@@ -0,0 +1,11 @@
|
|||||||
|
@model Orchard.Blogs.Models.RecentBlogPostsPart
|
||||||
|
<fieldset>
|
||||||
|
<div>
|
||||||
|
@Html.LabelFor(m => m.ForBlog)
|
||||||
|
@Html.TextBoxFor(m => m.ForBlog)
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@Html.LabelFor(m => m.Count)
|
||||||
|
@Html.TextBoxFor(m => m.Count)
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
@@ -61,7 +61,16 @@
|
|||||||
@Zone(Model.Messages)
|
@Zone(Model.Messages)
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@if(Model.Featured != null) {
|
||||||
|
<div class="zone-featured">
|
||||||
|
@Zone(Model.Featured)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if(Model.Recent != null) {
|
||||||
|
<div class="zone-recent">
|
||||||
|
@Zone(Model.Recent)
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@if(Model.Sidebar2 != null) {
|
@if(Model.Sidebar2 != null) {
|
||||||
<aside class="sidebar secondary">
|
<aside class="sidebar secondary">
|
||||||
@Zone(Model.Sidebar2)
|
@Zone(Model.Sidebar2)
|
||||||
|
Reference in New Issue
Block a user