mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
- Pages: Publish/Draft support for the new pages package using the new ContentItemVersion model.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045117
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -7,7 +8,6 @@ using Orchard.Mvc.Results;
|
|||||||
using Orchard.Pages.Models;
|
using Orchard.Pages.Models;
|
||||||
using Orchard.Pages.Services;
|
using Orchard.Pages.Services;
|
||||||
using Orchard.Pages.ViewModels;
|
using Orchard.Pages.ViewModels;
|
||||||
using Orchard.Security;
|
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
namespace Orchard.Pages.Controllers {
|
namespace Orchard.Pages.Controllers {
|
||||||
@@ -45,7 +45,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
|
if (!Services.Authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var page = Services.ContentManager.BuildEditorModel(Services.ContentManager.New<Page>("page"));
|
var page = Services.ContentManager.BuildEditorModel(_pageService.New());
|
||||||
|
|
||||||
var model = new PageCreateViewModel {
|
var model = new PageCreateViewModel {
|
||||||
Page = page
|
Page = page
|
||||||
@@ -59,7 +59,12 @@ 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();
|
||||||
|
|
||||||
Page page = Services.ContentManager.Create<Page>("page");
|
bool publishNow = false;
|
||||||
|
if (String.Equals(Request.Form["Command"], "PublishNow")) {
|
||||||
|
publishNow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Page page = _pageService.Create(publishNow);
|
||||||
model.Page = Services.ContentManager.UpdateEditorModel(page, this);
|
model.Page = Services.ContentManager.UpdateEditorModel(page, this);
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
@@ -68,14 +73,14 @@ namespace Orchard.Pages.Controllers {
|
|||||||
var session = _sessionLocator.For(typeof(Page));
|
var session = _sessionLocator.For(typeof(Page));
|
||||||
session.Flush();
|
session.Flush();
|
||||||
|
|
||||||
return RedirectToAction("Edit", new { pageSlug = model.Page.Item.Slug });
|
return RedirectToAction("List");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Edit(string pageSlug) {
|
public ActionResult Edit(string pageSlug) {
|
||||||
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();
|
||||||
|
|
||||||
Page page = _pageService.Get(pageSlug);
|
Page page = _pageService.GetPageOrDraft(pageSlug);
|
||||||
|
|
||||||
if (page == null)
|
if (page == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
@@ -92,11 +97,20 @@ 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();
|
||||||
|
|
||||||
Page page = _pageService.Get(pageSlug);
|
bool publishNow = false;
|
||||||
|
if (String.Equals(Request.Form["Command"], "PublishNow")) {
|
||||||
|
publishNow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Page page = _pageService.GetPageOrDraft(pageSlug);
|
||||||
|
|
||||||
if (page == null)
|
if (page == null)
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
|
if (publishNow) {
|
||||||
|
_pageService.Publish(page);
|
||||||
|
}
|
||||||
|
|
||||||
var model = new PageEditViewModel {
|
var model = new PageEditViewModel {
|
||||||
Page = Services.ContentManager.UpdateEditorModel(page, this)
|
Page = Services.ContentManager.UpdateEditorModel(page, this)
|
||||||
};
|
};
|
||||||
@@ -109,7 +123,7 @@ namespace Orchard.Pages.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Services.Notifier.Information(T("Page information updated."));
|
Services.Notifier.Information(T("Page information updated."));
|
||||||
return RedirectToAction("Edit", new { pageSlug = page.Slug });
|
return RedirectToAction("List");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
@@ -27,6 +27,39 @@ namespace Orchard.Pages.Models {
|
|||||||
set { this.As<CommonAspect>().Owner = value; }
|
set { this.As<CommonAspect>().Owner = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsPublished {
|
||||||
|
get { return ContentItem.VersionRecord.Published; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasDraft {
|
||||||
|
get {
|
||||||
|
return (
|
||||||
|
(ContentItem.VersionRecord.Published == false) ||
|
||||||
|
(ContentItem.VersionRecord.Published && ContentItem.VersionRecord.Latest == false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasPublished {
|
||||||
|
get {
|
||||||
|
if (IsPublished)
|
||||||
|
return true;
|
||||||
|
if (ContentItem.ContentManager.Get(Id, VersionOptions.Published) != null)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PublishedSlug {
|
||||||
|
get {
|
||||||
|
if (IsPublished)
|
||||||
|
return Slug;
|
||||||
|
Page publishedPage = ContentItem.ContentManager.Get<Page>(Id, VersionOptions.Published);
|
||||||
|
if (publishedPage == null)
|
||||||
|
return String.Empty;
|
||||||
|
return publishedPage.Slug;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime? Published {
|
public DateTime? Published {
|
||||||
get { return Record.Published; }
|
get { return Record.Published; }
|
||||||
set { Record.Published = value; }
|
set { Record.Published = value; }
|
||||||
@@ -44,9 +77,4 @@ namespace Orchard.Pages.Models {
|
|||||||
|
|
||||||
//public virtual Published Published { get; set; }
|
//public virtual Published Published { get; set; }
|
||||||
}
|
}
|
||||||
//public class PageOverride : IAutoMappingOverride<Page> {
|
|
||||||
// public void Override(AutoMapping<Page> mapping) {
|
|
||||||
// mapping.HasOne(p => p.Published).PropertyRef(p => p.Page).Cascade.All();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,10 @@ namespace Orchard.Pages.Services {
|
|||||||
public interface IPageService : IDependency {
|
public interface IPageService : IDependency {
|
||||||
IEnumerable<Page> Get();
|
IEnumerable<Page> Get();
|
||||||
Page Get(string slug);
|
Page Get(string slug);
|
||||||
|
Page GetPageOrDraft(string slug);
|
||||||
|
Page New();
|
||||||
|
Page Create(bool publishNow);
|
||||||
void Delete(Page page);
|
void Delete(Page page);
|
||||||
|
void Publish(Page page);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,23 +1,19 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
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;
|
||||||
using Orchard.Data;
|
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
namespace Orchard.Pages.Services {
|
namespace Orchard.Pages.Services {
|
||||||
public class PageService : IPageService {
|
public class PageService : IPageService {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly IRepository<PageRecord> _pageRepository;
|
|
||||||
|
|
||||||
public PageService(IContentManager contentManager, IRepository<PageRecord> pageRepository) {
|
public PageService(IContentManager contentManager) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_pageRepository = pageRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Page> Get() {
|
public IEnumerable<Page> Get() {
|
||||||
return _contentManager.Query<Page, PageRecord>().List();
|
return _contentManager.Query<Page, PageRecord>(VersionOptions.Latest).List();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page Get(string slug) {
|
public Page Get(string slug) {
|
||||||
@@ -26,8 +22,27 @@ namespace Orchard.Pages.Services {
|
|||||||
.List().FirstOrDefault();
|
.List().FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Page GetPageOrDraft(string slug) {
|
||||||
|
Page page = _contentManager.Query<Page, PageRecord>(VersionOptions.Latest)
|
||||||
|
.Join<RoutableRecord>().Where(rr => rr.Slug == slug)
|
||||||
|
.List().FirstOrDefault();
|
||||||
|
return _contentManager.GetDraftRequired<Page>(page.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page New() {
|
||||||
|
return _contentManager.New<Page>("page");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page Create(bool publishNow) {
|
||||||
|
return _contentManager.Create<Page>("page", publishNow ? VersionOptions.Published : VersionOptions.Draft);
|
||||||
|
}
|
||||||
|
|
||||||
public void Delete(Page page) {
|
public void Delete(Page page) {
|
||||||
_pageRepository.Delete(page.Record);
|
_contentManager.Remove(page.ContentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Publish(Page page) {
|
||||||
|
_contentManager.Publish(page.ContentItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -38,14 +38,25 @@
|
|||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="Online" title="The page is currently online" />
|
<% if (page.HasPublished) {%>
|
||||||
|
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/online.gif")%>" alt="Online" title="The page is currently online" />
|
||||||
|
<% } else { %>
|
||||||
|
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/offline.gif")%>" alt="Offline" title="The page is currently offline" />
|
||||||
|
<% } %>
|
||||||
</td>
|
</td>
|
||||||
<td><%=page.Title ?? "(no title)" %></td>
|
<td><%=page.Title ?? "(no title)" %></td>
|
||||||
<td><%=Html.ActionLink(page.Slug ?? "(no slug)", "Item", new { controller = "Page", slug = page.Slug }) %></td>
|
<td><% if (page.HasPublished) {%>
|
||||||
|
<%=Html.ActionLink(page.Slug ?? "(no slug)", "Item", new {controller = "Page", slug = page.PublishedSlug})%>
|
||||||
|
<% } else {%>
|
||||||
|
<%= page.Slug ?? "(no slug)" %>
|
||||||
|
<% } %>
|
||||||
|
</td>
|
||||||
<td>By <%= page.Creator.UserName %></td>
|
<td>By <%= page.Creator.UserName %></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>
|
<td>
|
||||||
|
<% if (page.HasDraft) { %>
|
||||||
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/draft.gif") %>" alt="Draft" title="The page has a draft" />
|
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/draft.gif") %>" alt="Draft" title="The page has a draft" />
|
||||||
|
<% } %>
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><%=Html.ActionLink("Edit", "Edit", new { pageSlug = page.Slug }) %></td>
|
<td><%=Html.ActionLink("Edit", "Edit", new { pageSlug = page.Slug }) %></td>
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
<% if (Model.Item.Creator != null)
|
<% if (Model.Item.Creator != null)
|
||||||
{
|
{
|
||||||
%><div class="posted">Posted by <%=Html.Encode(Model.Item.Creator.UserName)%> at <%=Model.Item.Published%></div><%
|
%><div class="posted">Published by <%=Html.Encode(Model.Item.Creator.UserName)%> </div><%
|
||||||
} %>
|
} %>
|
||||||
</div>
|
</div>
|
||||||
<% Html.Zone("primary"); %>
|
<% Html.Zone("primary"); %>
|
||||||
|
@@ -2,4 +2,11 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Publish Settings</legend>
|
<legend>Publish Settings</legend>
|
||||||
<label for="Command_SaveDraft"><%=Html.RadioButton("Command", "SaveDraft", true, new { id = "Command_SaveDraft" }) %> Save Draft</label><br />
|
<label for="Command_SaveDraft"><%=Html.RadioButton("Command", "SaveDraft", true, new { id = "Command_SaveDraft" }) %> Save Draft</label><br />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<label for="Command_PublishNow"><%=Html.RadioButton("Command", "PublishNow", new { id = "Command_PublishNow" }) %> Publish Now</label>
|
||||||
|
</fieldset>
|
||||||
|
<%--<fieldset>
|
||||||
|
<label for="Command_PublishLater"><%=Html.RadioButton("Command", "PublishLater", new { id = "Command_PublishLater" }) %> Publish Later</label>
|
||||||
|
<%=Html.EditorFor(m => m.Published) %>
|
||||||
|
</fieldset>--%>
|
@@ -1,13 +1,10 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Mvc.ViewModels;
|
using Orchard.Mvc.ViewModels;
|
||||||
using Orchard.UI.Navigation;
|
|
||||||
|
|
||||||
namespace Orchard.ContentManagement {
|
namespace Orchard.ContentManagement {
|
||||||
public class DefaultContentManager : IContentManager {
|
public class DefaultContentManager : IContentManager {
|
||||||
|
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
using JetBrains.Annotations;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
|
Reference in New Issue
Block a user