mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-23 21:32:14 +08:00
Hooked up publish later option for blogs and pages. Code is fairly duplicated at the moment. Added todo comments in marking the duplicated code to evaluate for pulling back into content manager.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045266
This commit is contained in:
@@ -9,7 +9,6 @@ using Orchard.Security;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class BlogController : Controller {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IBlogService _blogService;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Extensions;
|
||||
using Orchard.Blogs.Models;
|
||||
@@ -11,6 +12,7 @@ using Orchard.Mvc.Results;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class BlogPostAdminController : Controller, IUpdateModel {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IBlogService _blogService;
|
||||
@@ -59,12 +61,25 @@ namespace Orchard.Blogs.Controllers {
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||
DateTime? publishDate = null;
|
||||
bool publishNow = false;
|
||||
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||
publishNow = true;
|
||||
} else if (string.Equals(Request.Form["Publish"], "Publish")) {
|
||||
DateTime publishDateValue;
|
||||
if (DateTime.TryParse(Request.Form["Publish"], out publishDateValue)) {
|
||||
publishDate = publishDateValue;
|
||||
}
|
||||
}
|
||||
|
||||
BlogPost blogPost = _services.ContentManager.Create<BlogPost>("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft, bp => { bp.Blog = blog; });
|
||||
//TODO: (erikpo) Evaluate if publish options should be moved into create or out of create to keep it clean
|
||||
BlogPost blogPost = _services.ContentManager.Create<BlogPost>("blogpost", publishNow ? VersionOptions.Published : VersionOptions.Draft,
|
||||
bp => {
|
||||
bp.Blog = blog;
|
||||
if (!publishNow && publishDate != null)
|
||||
bp.Published = publishDate.Value;
|
||||
});
|
||||
model.BlogPost = _services.ContentManager.UpdateEditorModel(blogPost, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
@@ -117,14 +132,24 @@ namespace Orchard.Blogs.Controllers {
|
||||
|
||||
if (post == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
|
||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||
DateTime? publishDate = null;
|
||||
bool publishNow = false;
|
||||
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||
publishNow = true;
|
||||
} else if (string.Equals(Request.Form["Publish"], "Publish")) {
|
||||
DateTime publishDateValue;
|
||||
if (DateTime.TryParse(Request.Form["Publish"], out publishDateValue)) {
|
||||
publishDate = publishDateValue;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||
if (publishNow)
|
||||
_blogPostService.Publish(post);
|
||||
else if (publishDate != null)
|
||||
_blogPostService.Publish(post, publishDate.Value);
|
||||
else
|
||||
_blogPostService.Unpublish(post);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ using Orchard.ContentManagement;
|
||||
using Orchard.Mvc.Results;
|
||||
|
||||
namespace Orchard.Blogs.Controllers {
|
||||
[ValidateInput(false)]
|
||||
public class BlogPostController : Controller {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IBlogService _blogService;
|
||||
|
||||
@@ -63,11 +63,20 @@ namespace Orchard.Blogs.Services {
|
||||
|
||||
public void Publish(BlogPost blogPost) {
|
||||
_contentManager.Publish(blogPost.ContentItem);
|
||||
//TODO: (erikpo) Not sure if this is needed or not
|
||||
blogPost.Published = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void Publish(BlogPost blogPost, DateTime publishDate) {
|
||||
//TODO: (erikpo) This logic should move out of blogs and pages and into content manager
|
||||
if (blogPost.Published != null && blogPost.Published.Value >= DateTime.UtcNow)
|
||||
_contentManager.Unpublish(blogPost.ContentItem);
|
||||
blogPost.Published = publishDate;
|
||||
}
|
||||
|
||||
public void Unpublish(BlogPost blogPost) {
|
||||
_contentManager.Unpublish(blogPost.ContentItem);
|
||||
//TODO: (erikpo) Not sure if this is needed or not
|
||||
blogPost.Published = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -11,6 +12,7 @@ namespace Orchard.Blogs.Services {
|
||||
IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData);
|
||||
void Delete(BlogPost blogPost);
|
||||
void Publish(BlogPost blogPost);
|
||||
void Publish(BlogPost blogPost, DateTime publishDate);
|
||||
void Unpublish(BlogPost blogPost);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Blogs.Models.BlogPost>" %>
|
||||
<fieldset>
|
||||
<legend><%=_Encoded("Publish Settings")%></legend>
|
||||
<label for="Command_SaveDraft"><%=Html.RadioButton("Command", "SaveDraft", Model.ContentItem.VersionRecord == null || !Model.ContentItem.VersionRecord.Published, new { id = "Command_SaveDraft" }) %> <%=_Encoded("Save Draft")%></label><br />
|
||||
@@ -7,7 +6,7 @@
|
||||
<fieldset>
|
||||
<label for="Command_PublishNow"><%=Html.RadioButton("Command", "PublishNow", Model.ContentItem.VersionRecord != null && Model.ContentItem.VersionRecord.Published, new { id = "Command_PublishNow" })%> <%=_Encoded("Publish Now")%></label>
|
||||
</fieldset>
|
||||
<%--<fieldset>
|
||||
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", new { id = "Command_PublishLater" }) %> <%=_Encoded("Publish Later")%></label>
|
||||
<fieldset>
|
||||
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", Model.Published != null && Model.Published.Value > DateTime.UtcNow, new { id = "Command_PublishLater" }) %> <%=_Encoded("Publish Later")%></label>
|
||||
<%=Html.EditorFor(m => m.Published) %>
|
||||
</fieldset>--%>
|
||||
</fieldset>
|
||||
@@ -125,12 +125,19 @@ namespace Orchard.Pages.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||
DateTime? publishDate = null;
|
||||
bool publishNow = false;
|
||||
if (String.Equals(Request.Form["Command"], "PublishNow")) {
|
||||
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||
publishNow = true;
|
||||
} else if (string.Equals(Request.Form["Publish"], "Publish")) {
|
||||
DateTime publishDateValue;
|
||||
if (DateTime.TryParse(Request.Form["Publish"], out publishDateValue)) {
|
||||
publishDate = publishDateValue;
|
||||
}
|
||||
}
|
||||
|
||||
Page page = _pageService.Create(publishNow);
|
||||
Page page = _pageService.Create(publishNow, publishDate);
|
||||
model.Page = Services.ContentManager.UpdateEditorModel(page, this);
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
@@ -165,32 +172,45 @@ namespace Orchard.Pages.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
bool publishNow = false;
|
||||
if (String.Equals(Request.Form["Command"], "PublishNow")) {
|
||||
publishNow = true;
|
||||
}
|
||||
|
||||
Page page = _pageService.GetPageOrDraft(pageSlug);
|
||||
|
||||
if (page == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
if (publishNow) {
|
||||
_pageService.Publish(page);
|
||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||
DateTime? publishDate = null;
|
||||
bool publishNow = false;
|
||||
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||
publishNow = true;
|
||||
} else if (string.Equals(Request.Form["Publish"], "Publish")) {
|
||||
DateTime publishDateValue;
|
||||
if (DateTime.TryParse(Request.Form["Publish"], out publishDateValue)) {
|
||||
publishDate = publishDateValue;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||
if (publishNow)
|
||||
_pageService.Publish(page);
|
||||
else if (publishDate != null)
|
||||
_pageService.Publish(page, publishDate.Value);
|
||||
else
|
||||
_pageService.Unpublish(page);
|
||||
|
||||
var model = new PageEditViewModel {
|
||||
Page = Services.ContentManager.UpdateEditorModel(page, this)
|
||||
};
|
||||
|
||||
TryUpdateModel(model);
|
||||
|
||||
if (ModelState.IsValid == false) {
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel();
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
Services.Notifier.Information(T("Page information updated."));
|
||||
|
||||
return RedirectToAction("List");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ namespace Orchard.Pages.Models {
|
||||
}
|
||||
|
||||
public DateTime? Published {
|
||||
get { return Record.Published; }
|
||||
set { Record.Published = value; }
|
||||
get { return this.As<CommonAspect>().PublishedUtc; }
|
||||
set { this.As<CommonAspect>().PublishedUtc = value; }
|
||||
}
|
||||
|
||||
//[CascadeAllDeleteOrphan]
|
||||
|
||||
@@ -9,14 +9,14 @@ using Orchard.ContentManagement.Handlers;
|
||||
namespace Orchard.Pages.Models {
|
||||
[UsedImplicitly]
|
||||
public class PageHandler : ContentHandler {
|
||||
public PageHandler(IRepository<PageRecord> repository) {
|
||||
public PageHandler(IRepository<PageRecord> repository, IRepository<CommonVersionRecord> commonRepository) {
|
||||
Filters.Add(new ActivatingFilter<Page>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<CommonAspect>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<ContentPart<CommonVersionRecord>>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new StorageFilter<PageRecord>(repository));
|
||||
Filters.Add(new StorageFilter<CommonVersionRecord>(commonRepository));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Pages.Models;
|
||||
|
||||
namespace Orchard.Pages.Services {
|
||||
@@ -10,9 +11,10 @@ namespace Orchard.Pages.Services {
|
||||
Page GetLatest(string slug);
|
||||
Page GetLatest(int id);
|
||||
Page New();
|
||||
Page Create(bool publishNow);
|
||||
Page Create(bool publishNow, DateTime? publishDate);
|
||||
void Delete(Page page);
|
||||
void Publish(Page page);
|
||||
void Publish(Page page, DateTime publishDate);
|
||||
void Unpublish(Page page);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Pages.Models;
|
||||
using Orchard.Core.Common.Records;
|
||||
@@ -61,8 +62,13 @@ namespace Orchard.Pages.Services {
|
||||
return _contentManager.New<Page>("page");
|
||||
}
|
||||
|
||||
public Page Create(bool publishNow) {
|
||||
return _contentManager.Create<Page>("page", publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
||||
public Page Create(bool publishNow, DateTime? publishDate) {
|
||||
//TODO: (erikpo) Evaluate if publish options should be moved into create or out of create to keep it clean
|
||||
return _contentManager.Create<Page>("page", publishNow ? VersionOptions.Published : VersionOptions.Draft,
|
||||
bp => {
|
||||
if (!publishNow && publishDate != null)
|
||||
bp.Published = publishDate.Value;
|
||||
});
|
||||
}
|
||||
|
||||
public void Delete(Page page) {
|
||||
@@ -71,10 +77,21 @@ namespace Orchard.Pages.Services {
|
||||
|
||||
public void Publish(Page page) {
|
||||
_contentManager.Publish(page.ContentItem);
|
||||
//TODO: (erikpo) Not sure if this is needed or not
|
||||
page.Published = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void Publish(Page page, DateTime publishDate) {
|
||||
//TODO: (erikpo) This logic should move out of blogs and pages and into content manager
|
||||
if (page.Published != null && page.Published.Value >= DateTime.UtcNow)
|
||||
_contentManager.Unpublish(page.ContentItem);
|
||||
page.Published = publishDate;
|
||||
}
|
||||
|
||||
public void Unpublish(Page page) {
|
||||
//_contentManager.Unpublish(page.ContentItem);
|
||||
_contentManager.Unpublish(page.ContentItem);
|
||||
//TODO: (erikpo) Not sure if this is needed or not
|
||||
page.Published = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<fieldset>
|
||||
<label for="Command_PublishNow"><%=Html.RadioButton("Command", "PublishNow", Model.ContentItem.VersionRecord != null && Model.ContentItem.VersionRecord.Published, new { id = "Command_PublishNow" })%> <%=_Encoded("Publish Now")%></label>
|
||||
</fieldset>
|
||||
<%--<fieldset>
|
||||
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", new { id = "Command_PublishLater" }) %> <%=_Encoded("Publish Later")%></label>
|
||||
<fieldset>
|
||||
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", Model.Published != null && Model.Published.Value > DateTime.UtcNow, new { id = "Command_PublishLater" })%> <%=_Encoded("Publish Later")%></label>
|
||||
<%=Html.EditorFor(m => m.Published) %>
|
||||
</fieldset>--%>
|
||||
</fieldset>
|
||||
Reference in New Issue
Block a user