mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Some work on getting BlogPosts to use the new editor templating
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043628
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Extensions;
|
||||
@@ -9,7 +8,6 @@ using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -34,7 +32,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
private Localizer T { get; set; }
|
||||
|
||||
public ActionResult List() {
|
||||
var model = new BlogsViewModel {
|
||||
|
@@ -35,7 +35,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
private Localizer T { get; set; }
|
||||
|
||||
//TODO: (erikpo) Should think about moving the slug parameters and get calls and null checks up into a model binder or action filter
|
||||
public ActionResult Item(string blogSlug, string postSlug) {
|
||||
@@ -83,16 +83,23 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult Create(string blogSlug) {
|
||||
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
|
||||
if (!_authorizer.Authorize(Permissions.CreatePost, T("Not allowed to create blog post")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
|
||||
Blog blog = _blogService.Get(blogSlug);
|
||||
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var blogPost = _contentManager.GetEditorViewModel(_contentManager.New<BlogPost>("blogpost"), null);
|
||||
blogPost.Item.Blog = blog;
|
||||
|
||||
var model = new CreateBlogPostViewModel {
|
||||
Blog = blog,
|
||||
ItemView = _contentManager.GetEditorViewModel(_contentManager.New("blogpost"), null)
|
||||
BlogPost = blogPost
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -107,20 +114,19 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
if (ModelState.IsValid == false) {
|
||||
model.Blog = blog;
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(_contentManager.New<BlogPost>("blogpost"), null, this);
|
||||
return View(model);
|
||||
}
|
||||
model.BlogPost = _contentManager.UpdateEditorViewModel(_contentManager.New<BlogPost>("blogpost"), null, this);
|
||||
model.BlogPost.Item.Blog = blog;
|
||||
|
||||
BlogPost blogPost = _blogPostService.Create(model.ToCreateBlogPostParams(blog));
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(blogPost, null, this);
|
||||
if (!ModelState.IsValid)
|
||||
return View(model);
|
||||
|
||||
_contentManager.Create(model.BlogPost.Item.ContentItem);
|
||||
|
||||
//TEMP: (erikpo) ensure information has committed for this record
|
||||
var session = _sessionLocator.For(typeof(BlogPostRecord));
|
||||
session.Flush();
|
||||
|
||||
return Redirect(Url.BlogPost(blogSlug, blogPost.As<RoutableAspect>().Slug));
|
||||
return Redirect(Url.BlogPost(blogSlug, model.BlogPost.Item.Slug));
|
||||
}
|
||||
|
||||
public ActionResult Edit(string blogSlug, string postSlug) {
|
||||
@@ -138,8 +144,8 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (post == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogPostEditViewModel { Blog = blog, Post = post };
|
||||
model.ItemView = _contentManager.GetEditorViewModel(model.Post.ContentItem, null);
|
||||
var model = new BlogPostEditViewModel { Blog = blog, BlogPost = null };
|
||||
//model.ItemView = _contentManager.GetEditorViewModel(model.Post.ContentItem, null);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -159,8 +165,8 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (post == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var model = new BlogPostEditViewModel { Blog = blog, Post = post };
|
||||
model.ItemView = _contentManager.UpdateEditorViewModel(model.Post, null, this);
|
||||
var model = new BlogPostEditViewModel { Blog = blog, BlogPost = null };
|
||||
//model.ItemView = _contentManager.UpdateEditorViewModel(model.Post, null, this);
|
||||
|
||||
IValueProvider values = input.ToValueProvider();
|
||||
TryUpdateModel(model, values);
|
||||
|
@@ -1,11 +0,0 @@
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Blogs.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.Extensions {
|
||||
public static class BlogPostCreateViewModelExtensions {
|
||||
public static CreateBlogPostParams ToCreateBlogPostParams(this CreateBlogPostViewModel viewModel, Blog blog) {
|
||||
return new CreateBlogPostParams() {Blog = blog, Title = viewModel.Title, Body = viewModel.Body, Slug = viewModel.Slug, Published = viewModel.Published};
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Security;
|
||||
@@ -8,12 +10,26 @@ namespace Orchard.Blogs.Models {
|
||||
public readonly static ContentType ContentType = new ContentType { Name = "blogpost", DisplayName = "Blog Post" };
|
||||
|
||||
public Blog Blog { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
|
||||
[Required]
|
||||
public string Title { get { return this.As<RoutableAspect>().Title; } }
|
||||
public string Body { get { return this.As<BodyAspect>().Record.Text; } }
|
||||
|
||||
[Required]
|
||||
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
|
||||
|
||||
[Required]
|
||||
public string Body { get { return this.As<BodyAspect>().Record.Text; } }
|
||||
|
||||
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
|
||||
public DateTime? Published { get { return Record.Published; } }
|
||||
|
||||
public DateTime? Published
|
||||
{
|
||||
get { return Record.Published; }
|
||||
set { Record.Published = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -73,8 +73,16 @@ namespace Orchard.Blogs.Models {
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
OnGetEditorViewModel<BlogPost>((context, blogPost) =>
|
||||
context.AddEditor(new TemplateViewModel(blogPost) {TemplateName = "BlogPostFields"})
|
||||
);
|
||||
|
||||
OnUpdateEditorViewModel<BlogPost>((context, blogPost) => {
|
||||
context.AddEditor(new TemplateViewModel(blogPost) { TemplateName = "BlogPostFields" });
|
||||
context.Updater.TryUpdateModel(blogPost, "", null, null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -67,7 +67,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Controllers\BlogPostController.cs" />
|
||||
<Compile Include="Extensions\BlogPostCreateViewModelExtensions.cs" />
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||
@@ -113,7 +112,7 @@
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogDetail.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogPostList.ascx" />
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogSummary.ascx" />
|
||||
<Content Include="Views\BlogPost\EditorTemplates\CreateBlogPostViewModel.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\BlogPostFields.ascx" />
|
||||
<Content Include="Views\BlogPost\Item.aspx" />
|
||||
<Content Include="Views\Blog\Create.aspx" />
|
||||
<Content Include="Views\Blog\Edit.aspx" />
|
||||
@@ -123,6 +122,7 @@
|
||||
<Content Include="Views\Models\DisplayTemplates\BlogPostListAdmin.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\BlogFields.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\Blog.ascx" />
|
||||
<Content Include="Views\Models\EditorTemplates\BlogPost.ascx" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.Records;
|
||||
using Orchard.Data;
|
||||
using Orchard.Models;
|
||||
@@ -38,19 +37,6 @@ namespace Orchard.Blogs.Services {
|
||||
bp => bp.Record.Blog.Id == blog.ContentItem.Id);
|
||||
}
|
||||
|
||||
public BlogPost Create(CreateBlogPostParams parameters) {
|
||||
return _contentManager.Create<BlogPost>("blogpost", bp =>
|
||||
{
|
||||
bp.Record.Blog = parameters.Blog.Record;
|
||||
bp.As<BodyAspect>().Record.Text = parameters.Body;
|
||||
bp.As<BodyAspect>().Record.Format = "html";
|
||||
bp.Record.Published = parameters.Published;
|
||||
bp.As<RoutableAspect>().Record.Title = parameters.Title;
|
||||
bp.As<RoutableAspect>().Record.Slug = parameters.Slug;
|
||||
bp.Record.Blog.PostCount++;
|
||||
});
|
||||
}
|
||||
|
||||
public void Delete(BlogPost blogPost) {
|
||||
_blogPostRepository.Delete(blogPost.Record);
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ namespace Orchard.Blogs.Services {
|
||||
public interface IBlogPostService : IDependency {
|
||||
BlogPost Get(Blog blog, string slug);
|
||||
IEnumerable<BlogPost> Get(Blog blog);
|
||||
BlogPost Create(CreateBlogPostParams parameters);
|
||||
void Delete(BlogPost blogPost);
|
||||
}
|
||||
}
|
@@ -1,6 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
@@ -1,45 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class BlogPostEditViewModel : AdminViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
public BlogPost Post { get; set; }
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id {
|
||||
get { return Post.Id; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Title {
|
||||
get { return Post.As<RoutableAspect>().Record.Title; }
|
||||
set { Post.As<RoutableAspect>().Record.Title = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Body {
|
||||
get { return Post.As<BodyAspect>().Record.Text; }
|
||||
set { Post.As<BodyAspect>().Record.Text = value; }
|
||||
}
|
||||
|
||||
[Required]
|
||||
public string Slug {
|
||||
get { return Post.As<RoutableAspect>().Record.Slug; }
|
||||
set { Post.As<RoutableAspect>().Record.Slug = value; }
|
||||
}
|
||||
|
||||
public DateTime? Published {
|
||||
get { return Post.Record.Published; }
|
||||
set { Post.Record.Published = value; }
|
||||
}
|
||||
public ItemEditorViewModel<BlogPost> BlogPost { get; set; }
|
||||
}
|
||||
}
|
@@ -1,25 +1,9 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class CreateBlogPostViewModel : AdminViewModel {
|
||||
public Blog Blog { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Body { get; set; }
|
||||
|
||||
//TODO: (erikpo) Need a data type for slug
|
||||
[Required]
|
||||
public string Slug { get; set; }
|
||||
|
||||
public DateTime? Published { get; set; }
|
||||
|
||||
public ItemEditorViewModel ItemView { get; set; }
|
||||
public ItemEditorViewModel<BlogPost> BlogPost { get; set; }
|
||||
}
|
||||
}
|
@@ -7,6 +7,6 @@
|
||||
<h2>Add Post</h2>
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<%= Html.ValidationSummary() %>
|
||||
<%= Html.EditorForModel() %>
|
||||
<%= Html.EditorForItem(m => m.BlogPost) %>
|
||||
<% } %>
|
||||
<% Html.Include("AdminFoot"); %>
|
@@ -0,0 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ItemEditorViewModel<BlogPost>>" %>
|
||||
<%@ Import Namespace="Orchard.Models.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%=Html.EditorZonesAny() %>
|
@@ -1,4 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CreateBlogPostViewModel>" %>
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
|
||||
<div class="sections">
|
||||
@@ -18,15 +19,6 @@
|
||||
<label for="body">Body</label>
|
||||
<span><%=Html.TextAreaFor(m => m.Body, new { id = "body", @class = "html" })%></span>
|
||||
</fieldset>
|
||||
<% foreach (var e in Model.ItemView.Editors) {
|
||||
var editor = e;
|
||||
// TODO: why is Body in editors?
|
||||
// TODO: because any content type using the body editor doesn't need
|
||||
// to re-implement the rich editor, media extensions, format filter chain selection, etc
|
||||
if (!String.Equals(editor.Prefix, "Body")) {
|
||||
%><%=Html.EditorFor(m=>editor.Model, editor.TemplateName, editor.Prefix) %>
|
||||
<% }
|
||||
} %>
|
||||
</div>
|
||||
<div class="secondary">
|
||||
<fieldset>
|
Reference in New Issue
Block a user