- Page content type is introduced and Pages module was moved to the ContentManager architecture. Basic cms functionality was achieved (create/edit/view cms pages). Next will be history management.

- Refactoring the pages controller into a separate admin and a front end controller.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045089
This commit is contained in:
suhacan
2010-01-07 01:56:16 +00:00
parent 194ddc1034
commit 4bdd7de389
11 changed files with 161 additions and 116 deletions

View File

@@ -7,8 +7,8 @@ namespace Orchard.Pages {
public void GetNavigation(NavigationBuilder builder) {
builder.Add("Pages", "1",
menu => menu
.Add("Manage Pages", "1.0", item => item.Action("List", "Page", new { area = "Orchard.Pages" }))
.Add("Add New Page", "1.1", item => item.Action("Create", "Page", new { area = "Orchard.Pages" })));
.Add("Manage Pages", "1.0", item => item.Action("List", "Admin", new { area = "Orchard.Pages" }))
.Add("Add New Page", "1.1", item => item.Action("Create", "Admin", new { area = "Orchard.Pages" })));
}
}
}

View File

@@ -0,0 +1,147 @@
using System.Collections.Generic;
using System.Web.Mvc;
using Orchard.Data;
using Orchard.Localization;
using Orchard.ContentManagement;
using Orchard.Mvc.Results;
using Orchard.Pages.Models;
using Orchard.Pages.Services;
using Orchard.Pages.ViewModels;
using Orchard.Security;
using Orchard.UI.Notify;
namespace Orchard.Pages.Controllers {
[ValidateInput(false)]
public class AdminController : Controller, IUpdateModel {
private readonly ISessionLocator _sessionLocator;
private readonly IContentManager _contentManager;
private readonly IAuthorizer _authorizer;
private readonly INotifier _notifier;
private readonly IPageService _pageService;
private readonly ISlugConstraint _slugConstraint;
public AdminController(
IOrchardServices services,
ISessionLocator sessionLocator, IContentManager contentManager,
IAuthorizer authorizer,
INotifier notifier,
IPageService pageService,
ISlugConstraint slugConstraint) {
Services = services;
_sessionLocator = sessionLocator;
_contentManager = contentManager;
_authorizer = authorizer;
_notifier = notifier;
_pageService = pageService;
_slugConstraint = slugConstraint;
T = NullLocalizer.Instance;
}
public IOrchardServices Services { get; set; }
private Localizer T { get; set; }
public ActionResult List() {
IEnumerable<Page> pages = _pageService.Get();
var model = new PagesViewModel {
Pages = pages
};
return View(model);
}
public ActionResult Create() {
if (!_authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
return new HttpUnauthorizedResult();
var page = _contentManager.BuildEditorModel(_contentManager.New<Page>("page"));
var model = new PageCreateViewModel {
Page = page
};
return View(model);
}
[HttpPost, ActionName("Create")]
public ActionResult CreatePOST(PageCreateViewModel model) {
if (!_authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
return new HttpUnauthorizedResult();
Page page = _contentManager.Create<Page>("page");
model.Page = _contentManager.UpdateEditorModel(page, this);
if (!ModelState.IsValid)
return View(model);
var session = _sessionLocator.For(typeof(Page));
session.Flush();
return RedirectToAction("Edit", new { pageSlug = model.Page.Item.Slug });
}
public ActionResult Edit(string pageSlug) {
if (!_authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug);
if (page == null)
return new NotFoundResult();
var model = new PageEditViewModel {
Page = _contentManager.BuildEditorModel(page)
};
return View(model);
}
[HttpPost, ActionName("Edit")]
public ActionResult EditPOST(string pageSlug) {
if (!_authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug);
if (page == null)
return new NotFoundResult();
var model = new PageEditViewModel {
Page = _contentManager.UpdateEditorModel(page, this)
};
TryUpdateModel(model);
if (ModelState.IsValid == false) {
Services.TransactionManager.Cancel();
return View(model);
}
_notifier.Information(T("Page information updated."));
return RedirectToAction("Edit", new { pageSlug = page.Slug });
}
[HttpPost]
public ActionResult Delete(string pageSlug) {
if (!_authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug);
if (page == null)
return new NotFoundResult();
_pageService.Delete(page);
_notifier.Information(T("Page was successfully deleted"));
return RedirectToAction("List");
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}
void IUpdateModel.AddModelError(string key, LocalizedString errorMessage) {
ModelState.AddModelError(key, errorMessage.ToString());
}
}
}

View File

@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Orchard.Data;
using Orchard.Localization;
using Orchard.ContentManagement;
using Orchard.Mvc.Results;
using Orchard.Pages.Models;
using Orchard.Pages.Services;
using Orchard.Pages.ViewModels;
using Orchard.Security;
@@ -14,7 +10,6 @@ using Orchard.UI.Notify;
namespace Orchard.Pages.Controllers {
[ValidateInput(false)]
public class PageController : Controller, IUpdateModel {
private readonly ISessionLocator _sessionLocator;
private readonly IContentManager _contentManager;
private readonly IAuthorizer _authorizer;
private readonly INotifier _notifier;
@@ -23,13 +18,12 @@ namespace Orchard.Pages.Controllers {
public PageController(
IOrchardServices services,
ISessionLocator sessionLocator, IContentManager contentManager,
IContentManager contentManager,
IAuthorizer authorizer,
INotifier notifier,
IPageService pageService,
ISlugConstraint slugConstraint) {
Services = services;
_sessionLocator = sessionLocator;
_contentManager = contentManager;
_authorizer = authorizer;
_notifier = notifier;
@@ -41,15 +35,6 @@ namespace Orchard.Pages.Controllers {
public IOrchardServices Services { get; set; }
private Localizer T { get; set; }
public ActionResult List() {
IEnumerable<Page> pages = _pageService.Get();
var model = new PagesViewModel {
Pages = pages
};
return View(model);
}
public ActionResult Item(string slug) {
if (!_authorizer.Authorize(Permissions.ViewPages, T("Couldn't view page")))
return new HttpUnauthorizedResult();
@@ -68,94 +53,6 @@ namespace Orchard.Pages.Controllers {
return View(model);
}
public ActionResult Create() {
if (!_authorizer.Authorize(Permissions.CreatePages, T("Not allowed to create a page")))
return new HttpUnauthorizedResult();
var page = _contentManager.BuildEditorModel(_contentManager.New<Page>("page"));
var model = new PageCreateViewModel {
Page = page
};
return View(model);
}
[HttpPost, ActionName("Create")]
public ActionResult CreatePOST(PageCreateViewModel model) {
if (!_authorizer.Authorize(Permissions.CreatePages, T("Couldn't create page")))
return new HttpUnauthorizedResult();
Page page = _contentManager.Create<Page>("page");
model.Page = _contentManager.UpdateEditorModel(page, this);
if (!ModelState.IsValid)
return View(model);
var session = _sessionLocator.For(typeof(Page));
session.Flush();
return RedirectToAction("Edit", new { model.Page.Item.Slug });
}
public ActionResult Edit(string pageSlug) {
if (!_authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug);
if (page == null)
return new NotFoundResult();
var model = new PageEditViewModel {
Page = _contentManager.BuildEditorModel(page)
};
return View(model);
}
[HttpPost, ActionName("Edit")]
public ActionResult EditPOST(string pageSlug) {
if (!_authorizer.Authorize(Permissions.ModifyPages, T("Couldn't edit page")))
return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug);
if (page == null)
return new NotFoundResult();
var model = new PageEditViewModel {
Page = _contentManager.UpdateEditorModel(page, this)
};
TryUpdateModel(model);
if (ModelState.IsValid == false) {
Services.TransactionManager.Cancel();
return View(model);
}
_notifier.Information(T("Page information updated."));
return RedirectToAction("Edit", new { page.Slug });
}
[HttpPost]
public ActionResult Delete(string pageSlug) {
if (!_authorizer.Authorize(Permissions.DeletePages, T("Couldn't delete page")))
return new HttpUnauthorizedResult();
Page page = _pageService.Get(pageSlug);
if (page == null)
return new NotFoundResult();
_pageService.Delete(page);
_notifier.Information(T("Page was successfully deleted"));
return RedirectToAction("List");
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
}

View File

@@ -34,7 +34,7 @@ namespace Orchard.Pages.Controllers {
protected override RouteValueDictionary GetEditorRouteValues(Page page) {
return new RouteValueDictionary {
{"Area", "Orchard.Pages"},
{"Controller", "Page"},
{"Controller", "Admin"},
{"Action", "Edit"},
{"pageSlug", page.Slug},
};

View File

@@ -74,6 +74,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AdminMenu.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Controllers\PageController.cs" />
<Compile Include="Controllers\PageDriver.cs" />
<Compile Include="Extensions\UriExtensions.cs" />
@@ -106,10 +107,10 @@
<Content Include="Views\EditorTemplates\Items\Pages.Page.ascx" />
<Content Include="Views\EditorTemplates\Parts\Pages.Page.Fields.ascx" />
<Content Include="Views\EditorTemplates\Parts\Pages.Page.Publish.ascx" />
<Content Include="Views\Page\Create.ascx" />
<Content Include="Views\Page\Edit.ascx" />
<Content Include="Views\Admin\Create.ascx" />
<Content Include="Views\Admin\Edit.ascx" />
<Content Include="Views\Page\Item.ascx" />
<Content Include="Views\Page\List.aspx" />
<Content Include="Views\Admin\List.aspx" />
<Content Include="Web.config" />
<Content Include="Views\Web.config" />
</ItemGroup>

View File

@@ -3,7 +3,7 @@ using Orchard.Mvc.ViewModels;
using Orchard.Pages.Models;
namespace Orchard.Pages.ViewModels {
public class PagesViewModel : BaseViewModel {
public class PagesViewModel : AdminViewModel {
public IEnumerable<Page> Pages { get; set; }
}
}

View File

@@ -41,14 +41,14 @@
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/online.gif") %>" alt="Online" title="The page is currently online" />
</td>
<td><%=page.Title ?? "(no title)" %></td>
<td><%=Html.ActionLink(page.Slug ?? "(no slug)", "Show", new { page.Slug }) %></td>
<td>By <%= page.Creator %></td>
<td><%=Html.ActionLink(page.Slug ?? "(no slug)", "Item", new { controller = "Page", slug = page.Slug }) %></td>
<td>By <%= page.Creator.UserName %></td>
<td></td>
<td>
<img src="<%=ResolveUrl("~/Packages/Orchard.Pages/Content/Admin/images/draft.gif") %>" alt="Draft" title="The page has a draft" />
</td>
<td></td>
<td><%=Html.ActionLink("Edit", "Edit", new { page.Slug }) %></td>
<td><%=Html.ActionLink("Edit", "Edit", new { pageSlug = page.Slug }) %></td>
</tr>
<% }%>
</table>

View File

@@ -2,5 +2,5 @@
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<h3><a href="<%=Url.Action("Item", "Page", new { pageSlug = Model.Item.Slug }) %>"><%=Html.Encode(Model.Item.Title) %></a></h3>
<h3><a href="<%=Url.Action("Item", "Page", new { slug = Model.Item.Slug }) %>"><%=Html.Encode(Model.Item.Title) %></a></h3>
<div class="content"><%=Model.Item.As<BodyAspect>().Text ?? "<p><em>there's no content for this blog post</em></p>" %></div>

View File

@@ -1,7 +1,7 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ContentItemViewModel<Orchard.Pages.Models.Page>>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<div class="manage"><a href="<%=Url.Action("Edit", "Page", new {pageSlug = Model.Item.Slug}) %>" class="ibutton edit">edit</a></div>
<div class="manage"><a href="<%=Url.Action("Edit", "Admin", new {pageSlug = Model.Item.Slug}) %>" class="ibutton edit">edit</a></div>
<h1><%=Html.TitleForPage(Model.Item.Title)%></h1>
<div class="metadata">
<% if (Model.Item.Creator != null)