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:
ErikPorter
2010-01-14 22:00:11 +00:00
parent f683210de8
commit 6d59754258
7 changed files with 130 additions and 20 deletions

View File

@@ -6,13 +6,18 @@ Model.Zones.AddRenderPartial("header:after", "user", Model);
Model.Zones.AddRenderPartial("menu", "menu", Model);
Model.Zones.AddRenderPartial("content:before", "messages", Model.Messages);
%>
<div class="page">
<div id="page">
<div id="header"><%
Html.Zone("header");
Html.Zone("menu"); %>
</div>
<div id="main"><%
Html.ZoneBody("content"); %>
<div id="main">
<div id=”content”><%
Html.ZoneBody("primary");
%></div>
<div id=”sidebar”><%
Html.Zone("secondary");
%></div>
<div id="footer"><%
Html.Zone("footer");
%></div>

View File

@@ -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) {
}
}
}

View File

@@ -82,6 +82,7 @@
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
<Compile Include="Extensions\UriExtensions.cs" />
<Compile Include="Extensions\UrlHelperExtensions.cs" />
<Compile Include="Filters\ArchivesFilter.cs" />
<Compile Include="Models\ArchiveData.cs" />
<Compile Include="Permissions.cs" />
<Compile Include="Routing\IsArchiveConstraint.cs" />
@@ -99,6 +100,7 @@
<Compile Include="Services\IBlogPostService.cs" />
<Compile Include="Services\IBlogService.cs" />
<Compile Include="ViewModels\AdminBlogsViewModel.cs" />
<Compile Include="ViewModels\BlogArchivesViewModel.cs" />
<Compile Include="ViewModels\BlogPostArchiveViewModel.cs" />
<Compile Include="ViewModels\BlogViewModel.cs" />
<Compile Include="ViewModels\BlogPostViewModel.cs" />
@@ -113,6 +115,7 @@
<Content Include="Package.txt" />
<Content Include="Views\BlogPostAdmin\Create.ascx" />
<Content Include="Views\BlogPostAdmin\Edit.ascx" />
<Content Include="Views\Blog\Archives.ascx" />
<Content Include="Views\BlogPost\ListByArchive.ascx" />
<Content Include="Views\DisplayTemplates\Items\Blogs.Blog.DetailAdmin.ascx" />
<Content Include="Views\BlogAdmin\Item.ascx" />

View File

@@ -35,28 +35,52 @@ namespace Orchard.Blogs.Services {
public IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData) {
var query = GetBlogQuery(blog, VersionOptions.Published);
if (archiveData.Day > 0)
query =
query.Where(
cr =>
cr.CreatedUtc >= new DateTime(archiveData.Year, archiveData.Month, archiveData.Day) &&
cr.CreatedUtc < new DateTime(archiveData.Year, archiveData.Month, archiveData.Day + 1));
if (archiveData.Day > 0) {
var dayDate = new DateTime(archiveData.Year, archiveData.Month, archiveData.Day);
query = query.Where(cr => cr.CreatedUtc >= dayDate && cr.CreatedUtc < dayDate.AddDays(1));
}
else if (archiveData.Month > 0)
query =
query.Where(
cr =>
cr.CreatedUtc >= new DateTime(archiveData.Year, archiveData.Month, 1) &&
cr.CreatedUtc < new DateTime(archiveData.Year, archiveData.Month + 1, 1));
else
query =
query.Where(
cr =>
cr.CreatedUtc >= new DateTime(archiveData.Year, 1, 1) &&
cr.CreatedUtc < new DateTime(archiveData.Year + 1, 1, 1));
{
var monthDate = new DateTime(archiveData.Year, archiveData.Month, 1);
query = query.Where(cr => cr.CreatedUtc >= monthDate && cr.CreatedUtc < monthDate.AddMonths(1));
}
else {
var yearDate = new DateTime(archiveData.Year, 1, 1);
query = query.Where(cr => cr.CreatedUtc >= yearDate && cr.CreatedUtc < yearDate.AddYears(1));
}
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) {
_contentManager.Remove(blogPost.ContentItem);
}

View File

@@ -10,6 +10,7 @@ namespace Orchard.Blogs.Services {
IEnumerable<BlogPost> Get(Blog blog);
IEnumerable<BlogPost> Get(Blog blog, VersionOptions versionOptions);
IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData);
IEnumerable<KeyValuePair<ArchiveData, int>> GetArchives(Blog blog);
void Delete(BlogPost blogPost);
void Publish(BlogPost blogPost);
void Publish(BlogPost blogPost, DateTime publishDate);

View File

@@ -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; }
}
}

View 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>