mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 21:02:08 +08:00
Added archives UI to show up on blog and blog post pages in the secondary zone. The current archives data shown is hardcoded and temporary.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045424
This commit is contained in:
@@ -6,13 +6,18 @@ Model.Zones.AddRenderPartial("header:after", "user", Model);
|
|||||||
Model.Zones.AddRenderPartial("menu", "menu", Model);
|
Model.Zones.AddRenderPartial("menu", "menu", Model);
|
||||||
Model.Zones.AddRenderPartial("content:before", "messages", Model.Messages);
|
Model.Zones.AddRenderPartial("content:before", "messages", Model.Messages);
|
||||||
%>
|
%>
|
||||||
<div class="page">
|
<div id="page">
|
||||||
<div id="header"><%
|
<div id="header"><%
|
||||||
Html.Zone("header");
|
Html.Zone("header");
|
||||||
Html.Zone("menu"); %>
|
Html.Zone("menu"); %>
|
||||||
</div>
|
</div>
|
||||||
<div id="main"><%
|
<div id="main">
|
||||||
Html.ZoneBody("content"); %>
|
<div id=”content”><%
|
||||||
|
Html.ZoneBody("primary");
|
||||||
|
%></div>
|
||||||
|
<div id=”sidebar”><%
|
||||||
|
Html.Zone("secondary");
|
||||||
|
%></div>
|
||||||
<div id="footer"><%
|
<div id="footer"><%
|
||||||
Html.Zone("footer");
|
Html.Zone("footer");
|
||||||
%></div>
|
%></div>
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Blogs.Services;
|
||||||
|
using Orchard.Blogs.ViewModels;
|
||||||
|
using Orchard.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.Filters {
|
||||||
|
public class ArchivesFilter : FilterProvider, IResultFilter {
|
||||||
|
private readonly IBlogPostService _blogPostService;
|
||||||
|
|
||||||
|
public ArchivesFilter(IBlogPostService blogPostService) {
|
||||||
|
_blogPostService = blogPostService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||||
|
|
||||||
|
var blogViewModel = filterContext.Controller.ViewData.Model as BlogViewModel;
|
||||||
|
if (blogViewModel != null) {
|
||||||
|
blogViewModel.Zones.AddRenderPartial("secondary", "Archives", new BlogArchivesViewModel { Blog = blogViewModel.Blog.Item, Archives = _blogPostService.GetArchives(blogViewModel.Blog.Item) });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var blogPostViewModel = filterContext.Controller.ViewData.Model as BlogPostViewModel;
|
||||||
|
if (blogPostViewModel != null) {
|
||||||
|
blogPostViewModel.Zones.AddRenderPartial("secondary", "Archives", new BlogArchivesViewModel { Blog = blogPostViewModel.Blog, Archives = _blogPostService.GetArchives(blogPostViewModel.Blog) });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnResultExecuted(ResultExecutedContext filterContext) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,7 @@
|
|||||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||||
<Compile Include="Extensions\UriExtensions.cs" />
|
<Compile Include="Extensions\UriExtensions.cs" />
|
||||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||||
|
<Compile Include="Filters\ArchivesFilter.cs" />
|
||||||
<Compile Include="Models\ArchiveData.cs" />
|
<Compile Include="Models\ArchiveData.cs" />
|
||||||
<Compile Include="Permissions.cs" />
|
<Compile Include="Permissions.cs" />
|
||||||
<Compile Include="Routing\IsArchiveConstraint.cs" />
|
<Compile Include="Routing\IsArchiveConstraint.cs" />
|
||||||
@@ -99,6 +100,7 @@
|
|||||||
<Compile Include="Services\IBlogPostService.cs" />
|
<Compile Include="Services\IBlogPostService.cs" />
|
||||||
<Compile Include="Services\IBlogService.cs" />
|
<Compile Include="Services\IBlogService.cs" />
|
||||||
<Compile Include="ViewModels\AdminBlogsViewModel.cs" />
|
<Compile Include="ViewModels\AdminBlogsViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\BlogArchivesViewModel.cs" />
|
||||||
<Compile Include="ViewModels\BlogPostArchiveViewModel.cs" />
|
<Compile Include="ViewModels\BlogPostArchiveViewModel.cs" />
|
||||||
<Compile Include="ViewModels\BlogViewModel.cs" />
|
<Compile Include="ViewModels\BlogViewModel.cs" />
|
||||||
<Compile Include="ViewModels\BlogPostViewModel.cs" />
|
<Compile Include="ViewModels\BlogPostViewModel.cs" />
|
||||||
@@ -113,6 +115,7 @@
|
|||||||
<Content Include="Package.txt" />
|
<Content Include="Package.txt" />
|
||||||
<Content Include="Views\BlogPostAdmin\Create.ascx" />
|
<Content Include="Views\BlogPostAdmin\Create.ascx" />
|
||||||
<Content Include="Views\BlogPostAdmin\Edit.ascx" />
|
<Content Include="Views\BlogPostAdmin\Edit.ascx" />
|
||||||
|
<Content Include="Views\Blog\Archives.ascx" />
|
||||||
<Content Include="Views\BlogPost\ListByArchive.ascx" />
|
<Content Include="Views\BlogPost\ListByArchive.ascx" />
|
||||||
<Content Include="Views\DisplayTemplates\Items\Blogs.Blog.DetailAdmin.ascx" />
|
<Content Include="Views\DisplayTemplates\Items\Blogs.Blog.DetailAdmin.ascx" />
|
||||||
<Content Include="Views\BlogAdmin\Item.ascx" />
|
<Content Include="Views\BlogAdmin\Item.ascx" />
|
||||||
|
|||||||
@@ -35,28 +35,52 @@ namespace Orchard.Blogs.Services {
|
|||||||
public IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData) {
|
public IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData) {
|
||||||
var query = GetBlogQuery(blog, VersionOptions.Published);
|
var query = GetBlogQuery(blog, VersionOptions.Published);
|
||||||
|
|
||||||
if (archiveData.Day > 0)
|
if (archiveData.Day > 0) {
|
||||||
query =
|
var dayDate = new DateTime(archiveData.Year, archiveData.Month, archiveData.Day);
|
||||||
query.Where(
|
|
||||||
cr =>
|
query = query.Where(cr => cr.CreatedUtc >= dayDate && cr.CreatedUtc < dayDate.AddDays(1));
|
||||||
cr.CreatedUtc >= new DateTime(archiveData.Year, archiveData.Month, archiveData.Day) &&
|
}
|
||||||
cr.CreatedUtc < new DateTime(archiveData.Year, archiveData.Month, archiveData.Day + 1));
|
|
||||||
else if (archiveData.Month > 0)
|
else if (archiveData.Month > 0)
|
||||||
query =
|
{
|
||||||
query.Where(
|
var monthDate = new DateTime(archiveData.Year, archiveData.Month, 1);
|
||||||
cr =>
|
|
||||||
cr.CreatedUtc >= new DateTime(archiveData.Year, archiveData.Month, 1) &&
|
query = query.Where(cr => cr.CreatedUtc >= monthDate && cr.CreatedUtc < monthDate.AddMonths(1));
|
||||||
cr.CreatedUtc < new DateTime(archiveData.Year, archiveData.Month + 1, 1));
|
}
|
||||||
else
|
else {
|
||||||
query =
|
var yearDate = new DateTime(archiveData.Year, 1, 1);
|
||||||
query.Where(
|
|
||||||
cr =>
|
query = query.Where(cr => cr.CreatedUtc >= yearDate && cr.CreatedUtc < yearDate.AddYears(1));
|
||||||
cr.CreatedUtc >= new DateTime(archiveData.Year, 1, 1) &&
|
}
|
||||||
cr.CreatedUtc < new DateTime(archiveData.Year + 1, 1, 1));
|
|
||||||
|
|
||||||
return query.List().Select(ci => ci.As<BlogPost>());
|
return query.List().Select(ci => ci.As<BlogPost>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<KeyValuePair<ArchiveData, int>> GetArchives(Blog blog) {
|
||||||
|
return new List<KeyValuePair<ArchiveData, int>> {
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2010/1"), 5),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/12"), 23),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/11"), 4),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/9"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/8"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/7"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/6"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/5"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/4"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/3"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/2"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2009/1"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/12"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/11"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/10"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/9"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/7"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/6"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/5"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/4"), 1),
|
||||||
|
new KeyValuePair<ArchiveData, int>(new ArchiveData("2008/3"), 1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void Delete(BlogPost blogPost) {
|
public void Delete(BlogPost blogPost) {
|
||||||
_contentManager.Remove(blogPost.ContentItem);
|
_contentManager.Remove(blogPost.ContentItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace Orchard.Blogs.Services {
|
|||||||
IEnumerable<BlogPost> Get(Blog blog);
|
IEnumerable<BlogPost> Get(Blog blog);
|
||||||
IEnumerable<BlogPost> Get(Blog blog, VersionOptions versionOptions);
|
IEnumerable<BlogPost> Get(Blog blog, VersionOptions versionOptions);
|
||||||
IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData);
|
IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData);
|
||||||
|
IEnumerable<KeyValuePair<ArchiveData, int>> GetArchives(Blog blog);
|
||||||
void Delete(BlogPost blogPost);
|
void Delete(BlogPost blogPost);
|
||||||
void Publish(BlogPost blogPost);
|
void Publish(BlogPost blogPost);
|
||||||
void Publish(BlogPost blogPost, DateTime publishDate);
|
void Publish(BlogPost blogPost, DateTime publishDate);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Blogs.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Blogs.ViewModels {
|
||||||
|
public class BlogArchivesViewModel {
|
||||||
|
public Blog Blog { get; set; }
|
||||||
|
public IEnumerable<KeyValuePair<ArchiveData, int>> Archives { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/Orchard.Web/Packages/Orchard.Blogs/Views/Archives.ascx
Normal file
36
src/Orchard.Web/Packages/Orchard.Blogs/Views/Archives.ascx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Orchard.Mvc.ViewUserControl<BlogArchivesViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||||
|
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||||
|
<div class="sub archives">
|
||||||
|
<h3><%=_Encoded("Archives") %></h3><%
|
||||||
|
if (Model.Archives.Count() > 0) {
|
||||||
|
if (Model.Archives.Count() > 20) { %>
|
||||||
|
<ul class="yearList"><%
|
||||||
|
int lastYear = Model.Archives.First().Key.Year;
|
||||||
|
int firstYear = Model.Archives.Last().Key.Year;
|
||||||
|
|
||||||
|
for (int year = lastYear; year >= firstYear; year--) {
|
||||||
|
var yearMonths = Model.Archives.Where(m => m.Key.Year == year);
|
||||||
|
|
||||||
|
if (year == lastYear) { %>
|
||||||
|
<li>
|
||||||
|
<h4><%=year %></h4><%
|
||||||
|
}
|
||||||
|
else { %>
|
||||||
|
<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.Blog.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList") %>
|
||||||
|
</li><%
|
||||||
|
} %>
|
||||||
|
</ul><%
|
||||||
|
}
|
||||||
|
else { %>
|
||||||
|
<%=Html.UnorderedList(Model.Archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth(Model.Blog.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList") %><%
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { %>
|
||||||
|
<div class="message info"><%=_Encoded("None found")%></div><%
|
||||||
|
} %>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user