mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +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;
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
[ValidateInput(false)]
|
|
||||||
public class BlogController : Controller {
|
public class BlogController : Controller {
|
||||||
private readonly IOrchardServices _services;
|
private readonly IOrchardServices _services;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Blogs.Extensions;
|
using Orchard.Blogs.Extensions;
|
||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
@@ -11,6 +12,7 @@ using Orchard.Mvc.Results;
|
|||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
|
[ValidateInput(false)]
|
||||||
public class BlogPostAdminController : Controller, IUpdateModel {
|
public class BlogPostAdminController : Controller, IUpdateModel {
|
||||||
private readonly IOrchardServices _services;
|
private readonly IOrchardServices _services;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
@@ -59,12 +61,25 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (blog == null)
|
if (blog == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
|
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||||
|
DateTime? publishDate = null;
|
||||||
bool publishNow = false;
|
bool publishNow = false;
|
||||||
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||||
publishNow = true;
|
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);
|
model.BlogPost = _services.ContentManager.UpdateEditorModel(blogPost, this);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
@@ -118,13 +133,23 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
if (post == null)
|
if (post == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
|
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||||
|
DateTime? publishDate = null;
|
||||||
bool publishNow = false;
|
bool publishNow = false;
|
||||||
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||||
publishNow = true;
|
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)
|
if (publishNow)
|
||||||
_blogPostService.Publish(post);
|
_blogPostService.Publish(post);
|
||||||
|
else if (publishDate != null)
|
||||||
|
_blogPostService.Publish(post, publishDate.Value);
|
||||||
else
|
else
|
||||||
_blogPostService.Unpublish(post);
|
_blogPostService.Unpublish(post);
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Controllers {
|
namespace Orchard.Blogs.Controllers {
|
||||||
[ValidateInput(false)]
|
|
||||||
public class BlogPostController : Controller {
|
public class BlogPostController : Controller {
|
||||||
private readonly IOrchardServices _services;
|
private readonly IOrchardServices _services;
|
||||||
private readonly IBlogService _blogService;
|
private readonly IBlogService _blogService;
|
||||||
|
|||||||
@@ -63,11 +63,20 @@ namespace Orchard.Blogs.Services {
|
|||||||
|
|
||||||
public void Publish(BlogPost blogPost) {
|
public void Publish(BlogPost blogPost) {
|
||||||
_contentManager.Publish(blogPost.ContentItem);
|
_contentManager.Publish(blogPost.ContentItem);
|
||||||
|
//TODO: (erikpo) Not sure if this is needed or not
|
||||||
blogPost.Published = DateTime.UtcNow;
|
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) {
|
public void Unpublish(BlogPost blogPost) {
|
||||||
_contentManager.Unpublish(blogPost.ContentItem);
|
_contentManager.Unpublish(blogPost.ContentItem);
|
||||||
|
//TODO: (erikpo) Not sure if this is needed or not
|
||||||
blogPost.Published = null;
|
blogPost.Published = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
@@ -11,6 +12,7 @@ namespace Orchard.Blogs.Services {
|
|||||||
IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData);
|
IEnumerable<BlogPost> Get(Blog blog, ArchiveData archiveData);
|
||||||
void Delete(BlogPost blogPost);
|
void Delete(BlogPost blogPost);
|
||||||
void Publish(BlogPost blogPost);
|
void Publish(BlogPost blogPost);
|
||||||
|
void Publish(BlogPost blogPost, DateTime publishDate);
|
||||||
void Unpublish(BlogPost blogPost);
|
void Unpublish(BlogPost blogPost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-5
@@ -1,5 +1,4 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Blogs.Models.BlogPost>" %>
|
||||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%=_Encoded("Publish Settings")%></legend>
|
<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 />
|
<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>
|
<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>
|
<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>
|
||||||
<%--<fieldset>
|
<fieldset>
|
||||||
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", new { id = "Command_PublishLater" }) %> <%=_Encoded("Publish Later")%></label>
|
<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) %>
|
<%=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")))
|
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||||
|
DateTime? publishDate = null;
|
||||||
bool publishNow = false;
|
bool publishNow = false;
|
||||||
if (String.Equals(Request.Form["Command"], "PublishNow")) {
|
if (string.Equals(Request.Form["Command"], "PublishNow")) {
|
||||||
publishNow = true;
|
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);
|
model.Page = Services.ContentManager.UpdateEditorModel(page, this);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
@@ -165,32 +172,45 @@ namespace Orchard.Pages.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
if (!Services.Authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
bool publishNow = false;
|
|
||||||
if (String.Equals(Request.Form["Command"], "PublishNow")) {
|
|
||||||
publishNow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Page page = _pageService.GetPageOrDraft(pageSlug);
|
Page page = _pageService.GetPageOrDraft(pageSlug);
|
||||||
|
|
||||||
if (page == null)
|
if (page == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
if (publishNow) {
|
//TODO: (erikpo) Move this duplicate code somewhere else
|
||||||
_pageService.Publish(page);
|
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 {
|
var model = new PageEditViewModel {
|
||||||
Page = Services.ContentManager.UpdateEditorModel(page, this)
|
Page = Services.ContentManager.UpdateEditorModel(page, this)
|
||||||
};
|
};
|
||||||
|
|
||||||
TryUpdateModel(model);
|
TryUpdateModel(model);
|
||||||
|
|
||||||
if (ModelState.IsValid == false) {
|
if (!ModelState.IsValid) {
|
||||||
Services.TransactionManager.Cancel();
|
Services.TransactionManager.Cancel();
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.Notifier.Information(T("Page information updated."));
|
Services.Notifier.Information(T("Page information updated."));
|
||||||
|
|
||||||
return RedirectToAction("List");
|
return RedirectToAction("List");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ namespace Orchard.Pages.Models {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DateTime? Published {
|
public DateTime? Published {
|
||||||
get { return Record.Published; }
|
get { return this.As<CommonAspect>().PublishedUtc; }
|
||||||
set { Record.Published = value; }
|
set { this.As<CommonAspect>().PublishedUtc = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//[CascadeAllDeleteOrphan]
|
//[CascadeAllDeleteOrphan]
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ using Orchard.ContentManagement.Handlers;
|
|||||||
namespace Orchard.Pages.Models {
|
namespace Orchard.Pages.Models {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class PageHandler : ContentHandler {
|
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<Page>(PageDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<CommonAspect>(PageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<CommonAspect>(PageDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<ContentPart<CommonVersionRecord>>(PageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<ContentPart<CommonVersionRecord>>(PageDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<RoutableAspect>(PageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<RoutableAspect>(PageDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<BodyAspect>(PageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<BodyAspect>(PageDriver.ContentType.Name));
|
||||||
Filters.Add(new StorageFilter<PageRecord>(repository));
|
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;
|
using Orchard.Pages.Models;
|
||||||
|
|
||||||
namespace Orchard.Pages.Services {
|
namespace Orchard.Pages.Services {
|
||||||
@@ -10,9 +11,10 @@ namespace Orchard.Pages.Services {
|
|||||||
Page GetLatest(string slug);
|
Page GetLatest(string slug);
|
||||||
Page GetLatest(int id);
|
Page GetLatest(int id);
|
||||||
Page New();
|
Page New();
|
||||||
Page Create(bool publishNow);
|
Page Create(bool publishNow, DateTime? publishDate);
|
||||||
void Delete(Page page);
|
void Delete(Page page);
|
||||||
void Publish(Page page);
|
void Publish(Page page);
|
||||||
|
void Publish(Page page, DateTime publishDate);
|
||||||
void Unpublish(Page page);
|
void Unpublish(Page page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Pages.Models;
|
using Orchard.Pages.Models;
|
||||||
using Orchard.Core.Common.Records;
|
using Orchard.Core.Common.Records;
|
||||||
@@ -61,8 +62,13 @@ namespace Orchard.Pages.Services {
|
|||||||
return _contentManager.New<Page>("page");
|
return _contentManager.New<Page>("page");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page Create(bool publishNow) {
|
public Page Create(bool publishNow, DateTime? publishDate) {
|
||||||
return _contentManager.Create<Page>("page", publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
//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) {
|
public void Delete(Page page) {
|
||||||
@@ -71,10 +77,21 @@ namespace Orchard.Pages.Services {
|
|||||||
|
|
||||||
public void Publish(Page page) {
|
public void Publish(Page page) {
|
||||||
_contentManager.Publish(page.ContentItem);
|
_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) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
<fieldset>
|
<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>
|
<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>
|
||||||
<%--<fieldset>
|
<fieldset>
|
||||||
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", new { id = "Command_PublishLater" }) %> <%=_Encoded("Publish Later")%></label>
|
<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) %>
|
<%=Html.EditorFor(m => m.Published) %>
|
||||||
</fieldset>--%>
|
</fieldset>
|
||||||
Reference in New Issue
Block a user