mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +08:00
#18437: Fixing RecentBlogPosts and BlogPostsArchives widgets
Work Item: 18437 --HG-- branch : 1.x
This commit is contained in:
@@ -10,18 +10,21 @@ namespace Orchard.Blogs.Drivers {
|
||||
public class BlogArchivesPartDriver : ContentPartDriver<BlogArchivesPart> {
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public BlogArchivesPartDriver(
|
||||
IBlogService blogService,
|
||||
IBlogPostService blogPostService) {
|
||||
IBlogPostService blogPostService,
|
||||
IContentManager contentManager) {
|
||||
_blogService = blogService;
|
||||
_blogPostService = blogPostService;
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_Blogs_BlogArchives",
|
||||
() => {
|
||||
BlogPart blog = _blogService.Get(part.ForBlog);
|
||||
var blog = _blogService.Get(part.BlogId, VersionOptions.Published).As<BlogPart>();
|
||||
|
||||
if (blog == null)
|
||||
return null;
|
||||
@@ -32,7 +35,7 @@ namespace Orchard.Blogs.Drivers {
|
||||
|
||||
protected override DriverResult Editor(BlogArchivesPart part, dynamic shapeHelper) {
|
||||
var viewModel = new BlogArchivesViewModel {
|
||||
Slug = part.ForBlog,
|
||||
BlogId = part.BlogId,
|
||||
Blogs = _blogService.Get().ToList().OrderBy(b => b.Name)
|
||||
};
|
||||
|
||||
@@ -43,21 +46,23 @@ namespace Orchard.Blogs.Drivers {
|
||||
protected override DriverResult Editor(BlogArchivesPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var viewModel = new BlogArchivesViewModel();
|
||||
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||
part.ForBlog = viewModel.Slug;
|
||||
part.BlogId = viewModel.BlogId;
|
||||
}
|
||||
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
|
||||
protected override void Importing(BlogArchivesPart part, ImportContentContext context) {
|
||||
var blogSlug = context.Attribute(part.PartDefinition.Name, "BlogSlug");
|
||||
if (blogSlug != null) {
|
||||
part.ForBlog = blogSlug;
|
||||
var blog = context.Attribute(part.PartDefinition.Name, "Blog");
|
||||
if (blog != null) {
|
||||
part.BlogId = context.GetItemFromSession(blog).Id;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(BlogArchivesPart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("BlogSlug", part.ForBlog);
|
||||
var blog = _contentManager.Get(part.BlogId);
|
||||
var blogIdentity = _contentManager.GetItemMetadata(blog).Identity;
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Orchard.Blogs.Drivers {
|
||||
|
||||
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_Blogs_RecentBlogPosts", () => {
|
||||
BlogPart blog = _blogService.Get(part.ForBlog);
|
||||
var blog = _contentManager.Get<BlogPart>(part.BlogId);
|
||||
|
||||
if (blog == null) {
|
||||
return null;
|
||||
@@ -46,7 +46,7 @@ namespace Orchard.Blogs.Drivers {
|
||||
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {
|
||||
var viewModel = new RecentBlogPostsViewModel {
|
||||
Count = part.Count,
|
||||
Slug = part.ForBlog,
|
||||
BlogId = part.BlogId,
|
||||
Blogs = _blogService.Get().ToList().OrderBy(b => b.Name)
|
||||
};
|
||||
|
||||
@@ -56,8 +56,9 @@ namespace Orchard.Blogs.Drivers {
|
||||
|
||||
protected override DriverResult Editor(RecentBlogPostsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var viewModel = new RecentBlogPostsViewModel();
|
||||
|
||||
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||
part.ForBlog = viewModel.Slug;
|
||||
part.BlogId = viewModel.BlogId;
|
||||
part.Count = viewModel.Count;
|
||||
}
|
||||
|
||||
@@ -65,9 +66,9 @@ namespace Orchard.Blogs.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(RecentBlogPostsPart part, ImportContentContext context) {
|
||||
var blogSlug = context.Attribute(part.PartDefinition.Name, "BlogSlug");
|
||||
if (blogSlug != null) {
|
||||
part.ForBlog = blogSlug;
|
||||
var blog = context.Attribute(part.PartDefinition.Name, "Blog");
|
||||
if (blog != null) {
|
||||
part.BlogId = context.GetItemFromSession(blog).Id;
|
||||
}
|
||||
|
||||
var count = context.Attribute(part.PartDefinition.Name, "Count");
|
||||
@@ -77,7 +78,10 @@ namespace Orchard.Blogs.Drivers {
|
||||
}
|
||||
|
||||
protected override void Exporting(RecentBlogPostsPart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("BlogSlug", part.ForBlog);
|
||||
var blog = _contentManager.Get(part.BlogId);
|
||||
var blogIdentity = _contentManager.GetItemMetadata(blog).Identity;
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
|
||||
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace Orchard.Blogs {
|
||||
SchemaBuilder.CreateTable("RecentBlogPostsPartRecord",
|
||||
table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("BlogSlug")
|
||||
.Column<int>("BlogId")
|
||||
.Column<int>("Count")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("BlogArchivesPartRecord",
|
||||
table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("BlogSlug", c => c.WithLength(255))
|
||||
.Column<int>("BlogId")
|
||||
);
|
||||
|
||||
ContentDefinitionManager.AlterTypeDefinition("Blog",
|
||||
@@ -96,5 +96,19 @@ namespace Orchard.Blogs {
|
||||
ContentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true")));
|
||||
return 4;
|
||||
}
|
||||
|
||||
public int UpdateFrom4() {
|
||||
// adding the new fields required as Routable was removed
|
||||
// the user still needs to execute the corresponding migration
|
||||
// steps from the migration module
|
||||
|
||||
SchemaBuilder.AlterTable("RecentBlogPostsPartRecord", table => table
|
||||
.AddColumn<int>("BlogId"));
|
||||
|
||||
SchemaBuilder.AlterTable("BlogArchivesPartRecord", table => table
|
||||
.AddColumn<int>("BlogId"));
|
||||
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
/// <summary>
|
||||
/// The content part used by the BlogArchives widget
|
||||
/// </summary>
|
||||
public class BlogArchivesPart : ContentPart<BlogArchivesPartRecord> {
|
||||
[Required]
|
||||
public string ForBlog {
|
||||
get { return Record.BlogSlug; }
|
||||
set { Record.BlogSlug = value; }
|
||||
|
||||
public int BlogId {
|
||||
get { return Record.BlogId; }
|
||||
set { Record.BlogId = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ namespace Orchard.Blogs.Models {
|
||||
/// The content part used by the BlogArchives widget
|
||||
/// </summary>
|
||||
public class BlogArchivesPartRecord : ContentPartRecord {
|
||||
public virtual string BlogSlug { get; set; }
|
||||
public virtual int BlogId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ using Orchard.ContentManagement;
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class RecentBlogPostsPart : ContentPart<RecentBlogPostsPartRecord> {
|
||||
|
||||
[Required]
|
||||
public string ForBlog {
|
||||
get { return Record.BlogSlug; }
|
||||
set { Record.BlogSlug = value; }
|
||||
public int BlogId {
|
||||
get { return Record.BlogId; }
|
||||
set { Record.BlogId = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Orchard.Blogs.Models {
|
||||
Count = 5;
|
||||
}
|
||||
|
||||
public virtual string BlogSlug { get; set; }
|
||||
public virtual int BlogId { get; set; }
|
||||
public virtual int Count { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Orchard.Blogs.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogArchivesViewModel {
|
||||
public string Slug { get; set; }
|
||||
public int BlogId { get; set; }
|
||||
public IEnumerable<BlogPart> Blogs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Blogs.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class RecentBlogPostsViewModel {
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public string Slug { get; set; }
|
||||
|
||||
[Required]
|
||||
public int BlogId { get; set; }
|
||||
|
||||
public IEnumerable<BlogPart> Blogs { get; set; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user