mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 05:23:33 +08:00
Started hooking up appropriate aspects for Blog and BlogPost. No functionality change.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041987
This commit is contained in:
@@ -3,5 +3,7 @@ using Orchard.Models;
|
|||||||
|
|
||||||
namespace Orchard.Core.Common.Models {
|
namespace Orchard.Core.Common.Models {
|
||||||
public class RoutableAspect : ContentPart<RoutableRecord> {
|
public class RoutableAspect : ContentPart<RoutableRecord> {
|
||||||
|
public string Title { get { return Record.Title; } }
|
||||||
|
public string Slug { get { return Record.Slug; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
8
src/Orchard.Web/Core/Common/Records/BodyRecord.cs
Normal file
8
src/Orchard.Web/Core/Common/Records/BodyRecord.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Orchard.Models.Records;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Common.Records {
|
||||||
|
public class BodyRecord : ContentPartRecord {
|
||||||
|
public virtual string Body { get; set; }
|
||||||
|
public virtual string Format { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@@ -68,6 +68,7 @@
|
|||||||
<Compile Include="Common\Models\BodyAspect.cs" />
|
<Compile Include="Common\Models\BodyAspect.cs" />
|
||||||
<Compile Include="Common\Models\RoutableAspect.cs" />
|
<Compile Include="Common\Models\RoutableAspect.cs" />
|
||||||
<Compile Include="Common\Providers\RoutableAspectProvider.cs" />
|
<Compile Include="Common\Providers\RoutableAspectProvider.cs" />
|
||||||
|
<Compile Include="Common\Records\BodyRecord.cs" />
|
||||||
<Compile Include="Common\Records\CommonRecord.cs" />
|
<Compile Include="Common\Records\CommonRecord.cs" />
|
||||||
<Compile Include="Common\Records\RoutableRecord.cs" />
|
<Compile Include="Common\Records\RoutableRecord.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@@ -4,7 +4,7 @@ using Orchard.Blogs.ViewModels;
|
|||||||
namespace Orchard.Blogs.Extensions {
|
namespace Orchard.Blogs.Extensions {
|
||||||
public static class BlogCreateViewModelExtensions {
|
public static class BlogCreateViewModelExtensions {
|
||||||
public static CreateBlogParams ToCreateBlogParams(this CreateBlogViewModel viewModel) {
|
public static CreateBlogParams ToCreateBlogParams(this CreateBlogViewModel viewModel) {
|
||||||
return new CreateBlogParams() {Name = viewModel.Name, Slug = viewModel.Slug, Enabled = viewModel.Enabled};
|
return new CreateBlogParams() {Name = viewModel.Name, Description = viewModel.Description, Slug = viewModel.Slug/*, Enabled = viewModel.Enabled*/};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,10 +1,12 @@
|
|||||||
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class Blog : ContentPart<BlogRecord> {
|
public class Blog : ContentPart<BlogRecord> {
|
||||||
public int Id { get { return ContentItem.Id; } }
|
public int Id { get { return ContentItem.Id; } }
|
||||||
public string Name { get { return Record.Name; } }
|
public string Name { get { return this.As<RoutableAspect>().Title; } }
|
||||||
public string Slug { get { return Record.Slug; } }
|
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
||||||
public bool Enabled { get { return Record.Enabled; } }
|
public string Description { get { return Record.Description; } }
|
||||||
|
//public bool Enabled { get { return Record.Enabled; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,8 +2,6 @@ using Orchard.Models;
|
|||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||||
public string BlogSlug { get { return Record.Blog.Slug; } }
|
public Blog Blog { get; set; }
|
||||||
public string Title { get { return Record.Title; } }
|
|
||||||
public string Slug { get { return Record.Slug; } }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,11 +1,17 @@
|
|||||||
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
|
using Orchard.Models;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogPostProvider : ContentProvider {
|
public class BlogPostProvider : ContentProvider {
|
||||||
public BlogPostProvider(IRepository<BlogPostRecord> repository) {
|
public BlogPostProvider(IRepository<BlogPostRecord> repository, IContentManager contentManager) {
|
||||||
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
||||||
|
Filters.Add(new ActivatingFilter<CommonAspect>("blogpost"));
|
||||||
|
Filters.Add(new ActivatingFilter<RoutableAspect>("blogpost"));
|
||||||
|
Filters.Add(new ActivatingFilter<BodyAspect>("blogpost"));
|
||||||
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
||||||
|
AddOnLoaded<BlogPost>((context, bp) => bp.Blog = contentManager.Get<Blog>(context.ContentItem.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,9 +1,19 @@
|
|||||||
|
//using System;
|
||||||
|
using System;
|
||||||
using Orchard.Models.Records;
|
using Orchard.Models.Records;
|
||||||
|
using Orchard.Users.Models;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogPostRecord : ContentPartRecord {
|
public class BlogPostRecord : ContentPartRecord {
|
||||||
public virtual BlogRecord Blog { get; set; }
|
public virtual BlogRecord Blog { get; set; }
|
||||||
|
public virtual UserRecord Creator { get; set; }
|
||||||
public virtual string Title { get; set; }
|
public virtual string Title { get; set; }
|
||||||
|
public virtual string Body { get; set; }
|
||||||
|
public virtual string BodyShort { get; set; }
|
||||||
|
//TODO: (erikpo) Probably need some sort of body source type to keep track of what created the text so its available to plugins to use appropriately.
|
||||||
public virtual string Slug { get; set; }
|
public virtual string Slug { get; set; }
|
||||||
|
public virtual DateTime? Published { get; set; }
|
||||||
|
//public virtual DateTime Created { get; set; }
|
||||||
|
//public virtual DateTime Modified { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,3 +1,4 @@
|
|||||||
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models.Driver;
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
@@ -5,6 +6,8 @@ namespace Orchard.Blogs.Models {
|
|||||||
public class BlogProvider : ContentProvider {
|
public class BlogProvider : ContentProvider {
|
||||||
public BlogProvider(IRepository<BlogRecord> repository) {
|
public BlogProvider(IRepository<BlogRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<Blog>("blog"));
|
Filters.Add(new ActivatingFilter<Blog>("blog"));
|
||||||
|
Filters.Add(new ActivatingFilter<CommonAspect>("blog"));
|
||||||
|
Filters.Add(new ActivatingFilter<RoutableAspect>("blog"));
|
||||||
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,7 @@ using Orchard.Models.Records;
|
|||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class BlogRecord : ContentPartRecord {
|
public class BlogRecord : ContentPartRecord {
|
||||||
public virtual IEnumerable<BlogPostRecord> Posts { get; set; }
|
public virtual IEnumerable<BlogPostRecord> Posts { get; set; }
|
||||||
public virtual string Name { get; set; }
|
public virtual string Description { get; set; }
|
||||||
public virtual string Slug { get; set; }
|
//public virtual bool Enabled { get; set; }
|
||||||
public virtual bool Enabled { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -107,6 +107,14 @@
|
|||||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||||
<Name>Orchard</Name>
|
<Name>Orchard</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
|
||||||
|
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||||
|
<Name>Orchard.Core</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.Users\Orchard.Users.csproj">
|
||||||
|
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
|
||||||
|
<Name>Orchard.Users</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
|
@@ -15,14 +15,14 @@ namespace Orchard.Blogs.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlogPost Get(Blog blog, string slug) {
|
public BlogPost Get(Blog blog, string slug) {
|
||||||
BlogPostRecord record = _repository.Get(bpr => bpr.Blog.Id == blog.Record.Id && bpr.Blog.Enabled && bpr.Slug == slug);
|
BlogPostRecord record = _repository.Get(bpr => bpr.Blog.Id == blog.Record.Id/* && bpr.Blog.Enabled*/ && bpr.Slug == slug);
|
||||||
|
|
||||||
return _contentManager.Get<BlogPost>(record.Id);
|
return _contentManager.Get<BlogPost>(record.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<BlogPost> Get(Blog blog) {
|
public IEnumerable<BlogPost> Get(Blog blog) {
|
||||||
//TODO: (erikpo) Sort by published desc
|
//TODO: (erikpo) Sort by published desc
|
||||||
IEnumerable<BlogPostRecord> items =_repository.Fetch(bpr => bpr.Blog.Id == blog.Record.Id && bpr.Blog.Enabled/*, bpr => bpr.Asc(bpr2 => bpr2.Slug)*/);
|
IEnumerable<BlogPostRecord> items =_repository.Fetch(bpr => bpr.Blog.Id == blog.Record.Id/* && bpr.Blog.Enabled, bpr => bpr.Asc(bpr2 => bpr2.Slug)*/);
|
||||||
|
|
||||||
return items.Select(br => _contentManager.Get(br.Id).As<BlogPost>());
|
return items.Select(br => _contentManager.Get(br.Id).As<BlogPost>());
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Common.Records;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
|
|
||||||
@@ -8,29 +10,31 @@ namespace Orchard.Blogs.Services {
|
|||||||
public class BlogService : IBlogService {
|
public class BlogService : IBlogService {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly IRepository<BlogRecord> _repository;
|
private readonly IRepository<BlogRecord> _repository;
|
||||||
|
private readonly IRepository<RoutableRecord> _routableRepository;
|
||||||
|
|
||||||
public BlogService(IContentManager contentManager, IRepository<BlogRecord> repository) {
|
public BlogService(IContentManager contentManager, IRepository<BlogRecord> repository, IRepository<RoutableRecord> routableRepository) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
|
_routableRepository = routableRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blog Get(string slug) {
|
public Blog Get(string slug) {
|
||||||
BlogRecord record = _repository.Get(br => br.Slug == slug && br.Enabled);
|
RoutableRecord record = _routableRepository.Get(r => r.ContentItem.ContentType.Name == "blog" && r.Slug == slug);
|
||||||
|
|
||||||
return record != null ?_contentManager.Get<Blog>(record.Id) : null;
|
return record != null ?_contentManager.Get<Blog>(record.Id) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Blog> Get() {
|
public IEnumerable<Blog> Get() {
|
||||||
IEnumerable<BlogRecord> blogs = _repository.Fetch(br => br.Enabled, br => br.Asc(br2 => br2.Name));
|
IEnumerable<RoutableRecord> records = _routableRepository.Fetch(rr => rr.ContentItem.ContentType.Name == "blog", rr => rr.Asc(rr2 => rr2.Title));
|
||||||
|
|
||||||
return blogs.Select(br => _contentManager.Get<Blog>(br.Id));
|
return records.Select(rr => _contentManager.Get<Blog>(rr.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blog CreateBlog(CreateBlogParams parameters) {
|
public Blog CreateBlog(CreateBlogParams parameters) {
|
||||||
return _contentManager.Create<Blog>("blog", init => {
|
return _contentManager.Create<Blog>("blog", init => {
|
||||||
init.Record.Name = parameters.Name;
|
init.Record.Description = parameters.Description;
|
||||||
init.Record.Slug = parameters.Slug;
|
init.As<RoutableAspect>().Record.Title = parameters.Name;
|
||||||
init.Record.Enabled = parameters.Enabled;
|
init.As<RoutableAspect>().Record.Slug = parameters.Slug;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
namespace Orchard.Blogs.Services {
|
namespace Orchard.Blogs.Services {
|
||||||
public class CreateBlogParams {
|
public class CreateBlogParams {
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
public string Slug { get; set; }
|
public string Slug { get; set; }
|
||||||
public bool Enabled { get; set; }
|
//public bool Enabled { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
using Orchard.UI.Models;
|
using Orchard.UI.Models;
|
||||||
@@ -18,19 +19,24 @@ namespace Orchard.Blogs.ViewModels {
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Name {
|
public string Name {
|
||||||
get { return Blog.As<Blog>().Record.Name; }
|
get { return Blog.As<RoutableAspect>().Record.Title; }
|
||||||
set { Blog.As<Blog>().Record.Name = value; }
|
set { Blog.As<RoutableAspect>().Record.Title = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Slug {
|
public string Slug {
|
||||||
get { return Blog.As<Blog>().Record.Slug; }
|
get { return Blog.As<RoutableAspect>().Record.Slug; }
|
||||||
set { Blog.As<Blog>().Record.Slug = value; }
|
set { Blog.As<RoutableAspect>().Record.Slug = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Enabled {
|
public string Description {
|
||||||
get { return Blog.As<Blog>().Record.Enabled; }
|
get { return Blog.Record.Description; }
|
||||||
set { Blog.As<Blog>().Record.Enabled = value; }
|
set { Blog.Record.Description = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public bool Enabled {
|
||||||
|
// get { return Blog.As<Blog>().Record.Enabled; }
|
||||||
|
// set { Blog.As<Blog>().Record.Enabled = value; }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -10,7 +10,9 @@ namespace Orchard.Blogs.ViewModels {
|
|||||||
[Required]
|
[Required]
|
||||||
public string Slug { get; set; }
|
public string Slug { get; set; }
|
||||||
|
|
||||||
[Required]
|
public string Description { get; set; }
|
||||||
public bool Enabled { get; set; }
|
|
||||||
|
//[Required]
|
||||||
|
//public bool Enabled { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogViewModel>" %>
|
<%@ Page Language="C#" 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.Extensions"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
@@ -12,7 +14,7 @@
|
|||||||
if (Model.Posts.Count() > 0) { %>
|
if (Model.Posts.Count() > 0) { %>
|
||||||
<ul><%
|
<ul><%
|
||||||
foreach (BlogPost post in Model.Posts) { %>
|
foreach (BlogPost post in Model.Posts) { %>
|
||||||
<li><a href="<%=Url.BlogPost(post.BlogSlug, post.Slug) %>"><%=Html.Encode(post.Title) %></a></li><%
|
<li><a href="<%=Url.BlogPost(post.Blog.Slug, post.As<RoutableAspect>().Slug) %>"><%=Html.Encode(post.As<RoutableAspect>().Title) %></a></li><%
|
||||||
} %>
|
} %>
|
||||||
</ul><%
|
</ul><%
|
||||||
} %>
|
} %>
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<BlogPost>>" %>
|
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<BlogPost>>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Core.Common.Models"%>
|
||||||
|
<%@ Import Namespace="Orchard.Models"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||||
@@ -10,7 +12,7 @@
|
|||||||
if (Model.Count() > 0) { %>
|
if (Model.Count() > 0) { %>
|
||||||
<ul><%
|
<ul><%
|
||||||
foreach (BlogPost post in Model) { %>
|
foreach (BlogPost post in Model) { %>
|
||||||
<li><a href="<%=Url.BlogPost(post.BlogSlug, post.Slug) %>"><%=Html.Encode(post.Title) %></a></li><%
|
<li><a href="<%=Url.BlogPost(post.Blog.Slug, post.As<RoutableAspect>().Slug) %>"><%=Html.Encode(post.As<RoutableAspect>().Title) %></a></li><%
|
||||||
} %>
|
} %>
|
||||||
</ul><%
|
</ul><%
|
||||||
} %>
|
} %>
|
||||||
|
@@ -24,10 +24,10 @@
|
|||||||
Content Item</h3>
|
Content Item</h3>
|
||||||
<p>
|
<p>
|
||||||
Id:
|
Id:
|
||||||
<%=Model.Item.Id %></p>
|
<%=Model.Item.ContentItem.Id %></p>
|
||||||
<p>
|
<p>
|
||||||
ContentType:
|
ContentType:
|
||||||
<%=Model.Item.ContentType%> <%=Html.ItemDisplayLink(Model.Item) %> <%=Html.ItemEditLink("edit", Model.Item) %></p>
|
<%=Model.Item.ContentItem.ContentType%> <%=Html.ItemDisplayLink(Model.Item) %> <%=Html.ItemEditLink("edit", Model.Item) %></p>
|
||||||
<h3>
|
<h3>
|
||||||
Content Item Parts</h3>
|
Content Item Parts</h3>
|
||||||
<ul>
|
<ul>
|
||||||
|
Reference in New Issue
Block a user