More clean up for blogs and added blog list page on the front end and added a menu item.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043003
This commit is contained in:
ErikPorter
2009-12-03 01:37:45 +00:00
parent 4f34920dbb
commit 3a3c34bf90
20 changed files with 90 additions and 20 deletions

View File

@@ -4,7 +4,6 @@ using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels;
using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.Localization;
using Orchard.Models;
@@ -32,10 +31,14 @@ namespace Orchard.Blogs.Controllers {
public Localizer T { get; set; }
public ActionResult ListForAdmin() {
public ActionResult List() {
return View(new BlogsViewModel { Blogs = _blogService.Get() });
}
public ActionResult ListForAdmin() {
return View(new BlogsForAdminViewModel { Blogs = _blogService.Get() });
}
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
public ActionResult Item(string blogSlug) {
Blog blog = _blogService.Get(blogSlug);
@@ -63,7 +66,8 @@ namespace Orchard.Blogs.Controllers {
var session = _sessionLocator.For(typeof(BlogRecord));
session.Flush();
return Redirect(Url.BlogEdit(blog.As<RoutableAspect>().Slug));
//TODO: (erikpo) This should redirect to the blog homepage in the admin once that page is created
return Redirect(Url.BlogsForAdmin());
}
public ActionResult Edit(string blogSlug) {
@@ -96,7 +100,7 @@ namespace Orchard.Blogs.Controllers {
_notifier.Information(T("Blog information updated"));
//TODO: (erikpo) This should redirect to the blog homepage in the admin once that page is created
return Redirect(Url.Blogs());
return Redirect(Url.BlogsForAdmin());
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {

View File

@@ -3,6 +3,10 @@ using System.Web.Mvc;
namespace Orchard.Blogs.Extensions {
public static class UrlHelperExtensions {
public static string Blogs(this UrlHelper urlHelper) {
return urlHelper.Action("List", "Blog", new {area = "Orchard.Blogs"});
}
public static string BlogsForAdmin(this UrlHelper urlHelper) {
return urlHelper.Action("ListForAdmin", "Blog", new {area = "Orchard.Blogs"});
}

View File

@@ -10,5 +10,6 @@ namespace Orchard.Blogs.Models {
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
public string Description { get { return Record.Description; } }
//public bool Enabled { get { return Record.Enabled; } }
public int PostCount { get { return Record.PostCount; } }
}
}

View File

@@ -6,5 +6,6 @@ namespace Orchard.Blogs.Models {
public virtual IEnumerable<BlogPostRecord> Posts { get; set; }
public virtual string Description { get; set; }
//public virtual bool Enabled { get; set; }
public virtual int PostCount { get; set; }
}
}

View File

@@ -88,10 +88,11 @@
<Compile Include="Services\IBlogPostService.cs" />
<Compile Include="Services\CreateBlogParams.cs" />
<Compile Include="Services\IBlogService.cs" />
<Compile Include="ViewModels\BlogsViewModel.cs" />
<Compile Include="ViewModels\BlogsForAdminViewModel.cs" />
<Compile Include="ViewModels\BlogViewModel.cs" />
<Compile Include="ViewModels\BlogPostViewModel.cs" />
<Compile Include="ViewModels\BlogPostEditViewModel.cs" />
<Compile Include="ViewModels\BlogsViewModel.cs" />
<Compile Include="ViewModels\CreateBlogPostViewModel.cs" />
<Compile Include="ViewModels\CreateBlogViewModel.cs" />
<Compile Include="ViewModels\BlogEditViewModel.cs" />
@@ -101,6 +102,9 @@
<Content Include="Views\BlogPost\Create.aspx" />
<Content Include="Views\BlogPost\Edit.aspx" />
<Content Include="Views\BlogPost\EditorTemplates\BlogPostEditViewModel.ascx" />
<Content Include="Views\Blog\DisplayTemplates\BlogsForAdminViewModel.ascx" />
<Content Include="Views\Blog\DisplayTemplates\BlogForAdmin.ascx" />
<Content Include="Views\Blog\List.aspx" />
<Content Include="Views\Blog\ListForAdmin.aspx" />
<Content Include="Views\Shared\BlogPostPreview.ascx" />
<Content Include="Views\BlogPost\EditorTemplates\CreateBlogPostViewModel.ascx" />

View File

@@ -113,6 +113,20 @@ namespace Orchard.Blogs {
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"Blogs",
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "Blog"},
{"action", "List"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "Orchard.Blogs"}
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"{blogSlug}/{postSlug}",

View File

@@ -45,6 +45,7 @@ namespace Orchard.Blogs.Services {
bp.Record.Published = parameters.Published;
bp.As<RoutableAspect>().Record.Title = parameters.Title;
bp.As<RoutableAspect>().Record.Slug = parameters.Slug;
bp.Record.Blog.PostCount++;
});
}
}

View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
using Orchard.Blogs.Models;
using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels {
public class BlogsForAdminViewModel : AdminViewModel {
public IEnumerable<Blog> Blogs { get; set; }
}
}

View File

@@ -3,7 +3,7 @@ using Orchard.Blogs.Models;
using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels {
public class BlogsViewModel : AdminViewModel {
public class BlogsViewModel : BaseViewModel {
public IEnumerable<Blog> Blogs { get; set; }
}
}

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<% Html.Include("AdminHead"); %>
<h2>Create New Blog</h2>
<p><a href="<%=Url.Blogs() %>">Manage Blogs</a> &gt; Create Blog</p>
<p><a href="<%=Url.BlogsForAdmin() %>">Manage Blogs</a> &gt; Create Blog</p>
<% using (Html.BeginForm()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorForModel() %>

View File

@@ -1,10 +1,8 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Blog>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h3>
<a href="<%=Url.BlogEdit(Model.Slug) %>"><%=Html.Encode(Model.Name) %></a>
<span>(<a href="<%=Url.Blog(Model.Slug) %>">view</a>)</span>
<span>(<a href="<%=Url.BlogPostCreate(Model.Slug) %>">create post</a>)</span>
</h3>
<p>[list of authors] [modify blog access]</p>
<h2>
<a href="<%=Url.Blog(Model.Slug) %>"><%=Html.Encode(Model.Name) %></a>
<span>(<%=Model.PostCount %> post<%=Model.PostCount == 1 ? "" : "s" %>)</span>
</h2>
<p><%=Model.Description %></p>

View File

@@ -0,0 +1,10 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Blog>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h3>
<a href="<%=Url.BlogEdit(Model.Slug) %>"><%=Html.Encode(Model.Name) %></a>
<span>(<a href="<%=Url.Blog(Model.Slug) %>">view</a>)</span>
<span>(<a href="<%=Url.BlogPostCreate(Model.Slug) %>">create post</a>)</span>
</h3>
<p>[list of authors] [modify blog access]</p>
<p><%=Model.Description %></p>

View File

@@ -0,0 +1,10 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BlogsForAdminViewModel>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Blogs.ViewModels"
%><div class="actions"><a class="add button" href="<%=Url.BlogCreate() %>">Create a New Blog</a></div><%
if (Model.Blogs.Count() > 0) { %>
<%=Html.UnorderedList(Model.Blogs, (b, i) => Html.DisplayFor(blog => b, "BlogForAdmin").ToHtmlString(), "blogs") %>
<div class="actions"><a class="add button" href="<%=Url.BlogCreate() %>">Create a New Blog</a></div><%
} %>

View File

@@ -3,8 +3,10 @@
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Blogs.ViewModels"
%><div class="actions"><a class="add button" href="<%=Url.BlogCreate() %>">Create a New Blog</a></div><%
%><%
if (Model.Blogs.Count() > 0) { %>
<%=Html.UnorderedList(Model.Blogs, (b, i) => Html.DisplayFor(blog => b).ToHtmlString(), "blogs") %>
<div class="actions"><a class="add button" href="<%=Url.BlogCreate() %>">Create a New Blog</a></div><%
<%=Html.UnorderedList(Model.Blogs, (b, i) => Html.DisplayFor(blog => b).ToHtmlString(), "blogs") %><%
}
else { %>
<p>No blogs found.</p><%
} %>

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
<% Html.Include("AdminHead"); %>
<h2>Edit Blog</h2>
<p><a href="<%=Url.Blogs() %>">Manage Blogs</a> &gt; Editing <strong><%=Html.Encode(Model.Name)%></strong></p>
<p><a href="<%=Url.BlogsForAdmin() %>">Manage Blogs</a> &gt; Editing <strong><%=Html.Encode(Model.Name)%></strong></p>
<% using (Html.BeginForm()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorForModel() %>

View File

@@ -0,0 +1,11 @@
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<BlogsViewModel>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%-- todo: (heskew) make master-less when we get into theming --%>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<h1>Blogs</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<%=Html.DisplayForModel() %>
</asp:Content>

View File

@@ -1,4 +1,4 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogsViewModel>" %>
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<BlogsForAdminViewModel>" %>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>

View File

@@ -5,7 +5,7 @@
<%@ Import Namespace="Orchard.Mvc.Html" %>
<% Html.Include("AdminHead"); %>
<h2>Create a New Blog Post</h2>
<p><a href="<%=Url.Blogs() %>">Manage Blogs</a> &gt; <a href="<%=Url.BlogEdit(Model.Blog.Slug) %>"><%=Html.Encode(Model.Blog.Name) %></a> &gt; Create Blog Post</p>
<p><a href="<%=Url.BlogsForAdmin() %>">Manage Blogs</a> &gt; <a href="<%=Url.BlogEdit(Model.Blog.Slug) %>"><%=Html.Encode(Model.Blog.Name) %></a> &gt; Create Blog Post</p>
<%using (Html.BeginForm()) { %>
<%= Html.ValidationSummary() %>
<%= Html.EditorForModel() %>

View File

@@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
<% Html.Include("AdminHead"); %>
<h2>Edit Blog Post</h2>
<p><a href="<%=Url.Blogs() %>">Manage Blogs</a> &gt; <a href="<%=Url.BlogEdit(Model.Blog.Slug) %>"><%=Html.Encode(Model.Blog.Name)%></a> &gt; <a href="<%=Url.BlogPostEdit(Model.Blog.Slug, Model.Post.Slug) %>"><%=Model.Title %></a></p>
<p><a href="<%=Url.BlogsForAdmin() %>">Manage Blogs</a> &gt; <a href="<%=Url.BlogEdit(Model.Blog.Slug) %>"><%=Html.Encode(Model.Blog.Name)%></a> &gt; <a href="<%=Url.BlogPostEdit(Model.Blog.Slug, Model.Post.Slug) %>"><%=Model.Title %></a></p>
<% using (Html.BeginForm()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorForModel() %>

View File

@@ -4,6 +4,7 @@
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home", new {Area = ""}, new {})%></li>
<li><%= Html.ActionLink("About", "About", "Home", new {Area = ""}, new {})%></li>
<li><%= Html.ActionLink("Blogs", "List", "Blog", new {Area = "Orchard.Blogs"}, new {})%></li>
<li><%= Html.ActionLink("Admin", "Index", new {Area = "Orchard.CMSPages", Controller = "Admin"})%></li>
</ul>
</div>