From 1cc1d7518d5c35f75e1d85f2dc617c237b31170b Mon Sep 17 00:00:00 2001 From: Erik Porter Date: Tue, 2 Mar 2010 21:54:43 -0800 Subject: [PATCH 1/2] A little page list cleanup --HG-- branch : dev --- .../Orchard.Pages/Views/Admin/List.aspx | 134 +++++++----------- 1 file changed, 53 insertions(+), 81 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx b/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx index 692ee6faa..27e350b68 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx +++ b/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx @@ -3,9 +3,8 @@ <%@ Import Namespace="Orchard.Pages.ViewModels"%>

<%=Html.TitleForPage(T("Manage Pages").ToString())%>

<%-- todo: Add helper text here when ready.

<%=_Encoded("Possible text about setting up a page goes here.")%>

--%> -
<%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%>
-<% using (Html.BeginFormAntiForgeryPost()) - { %> +
<%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%>
<% +using (Html.BeginFormAntiForgeryPost()) { %> <%=Html.ValidationSummary()%>
@@ -27,85 +26,58 @@ "/>
- - -
<% } %> - - -<% } %> -
<%=Html.ActionLink(T("Add a page").ToString(), "Create", new { }, new { @class = "button primaryAction" })%>
From 7bf03123c070ea587b0776511df93c7ce5c41020 Mon Sep 17 00:00:00 2001 From: Erik Porter Date: Wed, 3 Mar 2010 00:51:48 -0800 Subject: [PATCH 2/2] Changed page management to match functionality with blog post management --HG-- branch : dev --- .../Extensions/HtmlHelperExtensions.cs | 6 ++- .../Modules/Orchard.Blogs/Models/BlogPost.cs | 4 -- .../Items/Blogs.BlogPost.SummaryAdmin.ascx | 11 ++--- .../Controllers/AdminController.cs | 40 ++++++++++++++++-- .../Modules/Orchard.Pages/Models/Page.cs | 1 + .../Orchard.Pages/Views/Admin/List.aspx | 41 +++++++++++++------ 6 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/HtmlHelperExtensions.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/HtmlHelperExtensions.cs index 9dd4b2df2..30724ae32 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/HtmlHelperExtensions.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/HtmlHelperExtensions.cs @@ -1,5 +1,7 @@ using System.Web.Mvc; using Orchard.Blogs.Models; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Mvc.Html; namespace Orchard.Blogs.Extensions { @@ -9,7 +11,7 @@ namespace Orchard.Blogs.Extensions { } public static string PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost) { - return htmlHelper.DateTime(blogPost.PublishedUtc, "Draft"); + return htmlHelper.DateTime(blogPost.As().VersionPublishedUtc, "Draft"); } public static string PublishedWhen(this HtmlHelper htmlHelper) { @@ -17,7 +19,7 @@ namespace Orchard.Blogs.Extensions { } public static string PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost) { - return htmlHelper.DateTimeRelative(blogPost.PublishedUtc, "as a Draft"); + return htmlHelper.DateTimeRelative(blogPost.As().VersionPublishedUtc, "as a Draft"); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPost.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPost.cs index 5f53fb84e..addb28127 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPost.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPost.cs @@ -60,10 +60,6 @@ namespace Orchard.Blogs.Models { get { return this.As().CreatedUtc; } } - public DateTime? PublishedUtc { - get { return this.As().VersionPublishedUtc; } - } - public DateTime? ScheduledPublishUtc { get; set; } private string _scheduledPublishUtcDate; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/DisplayTemplates/Items/Blogs.BlogPost.SummaryAdmin.ascx b/src/Orchard.Web/Modules/Orchard.Blogs/Views/DisplayTemplates/Items/Blogs.BlogPost.SummaryAdmin.ascx index ff39a50b6..17b5b16b2 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/DisplayTemplates/Items/Blogs.BlogPost.SummaryAdmin.ascx +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/DisplayTemplates/Items/Blogs.BlogPost.SummaryAdmin.ascx @@ -1,4 +1,5 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl>" %> +<%@ Import Namespace="Orchard.ContentManagement.Aspects"%> <%@ Import Namespace="Orchard.ContentManagement"%> <%@ Import Namespace="Orchard.Core.Common.Models"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%> @@ -30,20 +31,20 @@ <%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><% } else if (Model.Item.IsPublished) { %> - <%=_Encoded("Published: ") + Html.PublishedWhen(Model.Item) %><% + <%=_Encoded("Published: ") + Html.DateTimeRelative(Model.Item.As().VersionPublishedUtc.Value)%><% } else { %> - <%=_Encoded("Last modified: ") + Html.DateTimeRelative(Model.Item.As().ModifiedUtc.Value) %><% + <%=_Encoded("Last modified: ") + Html.DateTimeRelative(Model.Item.As().ModifiedUtc.Value) %><% } %> |  -
  • <%=_Encoded("By {0}", Model.Item.Creator == null ? String.Empty : Model.Item.Creator.UserName)%>
  • +
  • <%=_Encoded("By {0}", Model.Item.Creator.UserName)%>
  • diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Pages/Controllers/AdminController.cs index b693610d9..af560d976 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Controllers/AdminController.cs @@ -6,6 +6,7 @@ using System.Web.Mvc; using JetBrains.Annotations; using Orchard.Localization; using Orchard.ContentManagement; +using Orchard.Mvc.AntiForgery; using Orchard.Mvc.Results; using Orchard.Pages.Models; using Orchard.Pages.Services; @@ -210,7 +211,6 @@ namespace Orchard.Pages.Controllers { return RedirectToAction("Edit", "Admin", new { id = model.Page.Item.ContentItem.Id }); } - public ActionResult DiscardDraft(int id) { // get the current draft version var draft = Services.ContentManager.Get(id, VersionOptions.Draft); @@ -239,9 +239,41 @@ namespace Orchard.Pages.Controllers { return RedirectToAction("Edit", new { draft.Id }); } - [HttpPost] + [ValidateAntiForgeryTokenOrchard] + public ActionResult Publish(int id) { + if (!Services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't publish page"))) + return new HttpUnauthorizedResult(); + + var page = _pageService.GetLatest(id); + if (page == null) + return new NotFoundResult(); + + _pageService.Publish(page); + Services.ContentManager.Flush(); + Services.Notifier.Information(T("Page successfully published.")); + + return RedirectToAction("List"); + } + + [ValidateAntiForgeryTokenOrchard] + public ActionResult Unpublish(int id) { + if (!Services.Authorizer.Authorize(Permissions.PublishPages, T("Couldn't unpublish page"))) + return new HttpUnauthorizedResult(); + + var page = _pageService.GetLatest(id); + if (page == null) + return new NotFoundResult(); + + _pageService.Unpublish(page); + Services.ContentManager.Flush(); + Services.Notifier.Information(T("Page successfully unpublished.")); + + return RedirectToAction("List"); + } + + [ValidateAntiForgeryTokenOrchard] public ActionResult Delete(int id) { - Page page = _pageService.Get(id); + var page = _pageService.GetLatest(id); if (page == null) return new NotFoundResult(); @@ -249,7 +281,7 @@ namespace Orchard.Pages.Controllers { return new HttpUnauthorizedResult(); _pageService.Delete(page); - Services.Notifier.Information(T("Page was successfully deleted")); + Services.Notifier.Information(T("Page successfully deleted")); return RedirectToAction("List"); } diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Models/Page.cs b/src/Orchard.Web/Modules/Orchard.Pages/Models/Page.cs index 178bccf7c..e65129069 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Models/Page.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Models/Page.cs @@ -1,6 +1,7 @@ using System; using System.Web.Mvc; using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Core.Common.Models; using Orchard.Security; diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx b/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx index 27e350b68..d9626c7ba 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx +++ b/src/Orchard.Web/Modules/Orchard.Pages/Views/Admin/List.aspx @@ -1,4 +1,7 @@ <%@ Page Language="C#" Inherits="Orchard.Mvc.ViewPage" %> +<%@ Import Namespace="Orchard.ContentManagement.Aspects"%> +<%@ Import Namespace="Orchard.ContentManagement"%> +<%@ Import Namespace="Orchard.Core.Common.Models"%> <%@ Import Namespace="Orchard.Mvc.Html"%> <%@ Import Namespace="Orchard.Pages.ViewModels"%>

    <%=Html.TitleForPage(T("Manage Pages").ToString())%>

    @@ -53,24 +56,36 @@ using (Html.BeginFormAntiForgeryPost()) { %> } else { %> <%=_Encoded("No Draft")%> | <% + } %> + +
  • <% + if (pageEntry.Page.ScheduledPublishUtc.HasValue && pageEntry.Page.ScheduledPublishUtc.Value > DateTime.UtcNow) { %> + " alt="<%=_Encoded("Scheduled") %>" title="<%=_Encoded("The page is scheduled for publishing") %>" /><%=_Encoded("Scheduled")%> + <%=Html.DateTime(pageEntry.Page.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><% } - // Scheduled - if (!pageEntry.Page.IsPublished) { - if (pageEntry.Page.ScheduledPublishUtc != null) { %> - " alt="<%=_Encoded("Scheduled") %>" title="<%=_Encoded("The page is scheduled for publishing") %>" /><%=string.Format("Scheduled: {0:d}", pageEntry.Page.ScheduledPublishUtc.Value) %> | <% - } - } %> -
  • -
  • <%--Author--%> - <%=_Encoded("By {0}", pageEntry.Page.Creator.UserName)%> + else if (pageEntry.Page.IsPublished) { %> + <%=_Encoded("Published: ") + Html.DateTimeRelative(pageEntry.Page.As().VersionPublishedUtc.Value) %><% + } + else { %> + <%=_Encoded("Last modified: ") + Html.DateTimeRelative(pageEntry.Page.As().ModifiedUtc.Value) %><% + } %> | 
  • +
  • <%=_Encoded("By {0}", pageEntry.Page.Creator.UserName)%>