- Ability to promote cms pages to be homepage.

- New homepage core package with a home controller and routes. Home->Index action calls homepage provider, implemented by pages package.
- New site setting (invisible), which is the currently active homepage provider + a parameter identifies the "item" within the provider.
- Add checkbox to Edit Page form to set the page being edited to be homepage.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-02-12 15:32:30 -08:00
parent 1b6df7a085
commit c070e8fd20
17 changed files with 183 additions and 4 deletions

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Logging;
using Orchard.Mvc.ViewModels;
using Orchard.Services;
using Orchard.Settings;
namespace Orchard.Core.HomePage.Controllers {
[HandleError]
public class HomeController : Controller {
private readonly IEnumerable<IHomePageProvider> _homePageProviders;
public HomeController(IEnumerable<IHomePageProvider> homePageProviders) {
_homePageProviders = homePageProviders;
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ActionResult Index() {
try {
string homepage = CurrentSite.HomePage;
if (String.IsNullOrEmpty(homepage)) {
return View(new BaseViewModel());
}
string[] homePageParameters = homepage.Split(';');
if (homePageParameters.Length != 2) {
return View(new BaseViewModel());
}
string providerName = homePageParameters[0];
int item = Int32.Parse(homePageParameters[1]);
foreach (var provider in _homePageProviders) {
if (String.Equals(provider.GetProviderName(), providerName)) {
ActionResult result = provider.GetHomePage(item);
if (result is ViewResultBase) {
ViewResultBase resultBase = result as ViewResultBase;
ViewData = resultBase.ViewData;
}
return result;
}
}
return View(new BaseViewModel());
}
catch {
return View(new BaseViewModel());
}
}
}
}

View File

@@ -0,0 +1 @@
name: HomePage

View File

@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;
namespace Orchard.Core.HomePage {
public class Routes : IRouteProvider {
public void GetRoutes(ICollection<RouteDescriptor> routes) {
foreach (var routeDescriptor in GetRoutes())
routes.Add(routeDescriptor);
}
public IEnumerable<RouteDescriptor> GetRoutes() {
return new[] {
new RouteDescriptor {
Priority = 20,
Route = new Route(
"",
new RouteValueDictionary {
{"area", "HomePage"},
{"controller", "Home"},
{"action", "Index"}
},
new RouteValueDictionary {
{"area", "HomePage"},
{"controller", "Home"},
},
new RouteValueDictionary {
{"area", "HomePage"}
},
new MvcRouteHandler())
}
};
}
}
}

View File

@@ -102,6 +102,8 @@
<Compile Include="Feeds\Models\FeedResponse.cs" />
<Compile Include="Feeds\Rss\RssFeedBuilder.cs" />
<Compile Include="Feeds\Rss\RssResult.cs" />
<Compile Include="HomePage\Controllers\HomeController.cs" />
<Compile Include="HomePage\Routes.cs" />
<Compile Include="Navigation\AdminMenu.cs" />
<Compile Include="Navigation\Controllers\AdminController.cs" />
<Compile Include="Navigation\Models\MenuItem.cs" />
@@ -216,6 +218,7 @@
<Content Include="Themes\Views\Web.config" />
</ItemGroup>
<ItemGroup>
<Content Include="HomePage\Module.txt" />
<Content Include="Navigation\Views\Admin\Index.ascx" />
<Content Include="Navigation\Views\EditorTemplates\Parts\Navigation.EditMenuPart.ascx" />
<Content Include="Navigation\Views\Web.config" />

View File

@@ -24,5 +24,9 @@ namespace Orchard.Core.Settings.Models {
get { return Record.SuperUser; }
set { Record.SuperUser = value; }
}
public string HomePage {
get { return Record.HomePage; }
set { Record.HomePage = value; }
}
}
}

View File

@@ -7,5 +7,6 @@ namespace Orchard.Core.Settings.Records {
public virtual string SiteName { get; set; }
public virtual string SuperUser { get; set; }
public virtual string PageTitleSeparator { get; set; }
public virtual string HomePage { get; set; }
}
}

View File

@@ -3,12 +3,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Localization;
using Orchard.ContentManagement;
using Orchard.Mvc.Results;
using Orchard.Pages.Models;
using Orchard.Pages.Services;
using Orchard.Pages.ViewModels;
using Orchard.Settings;
using Orchard.UI.Notify;
namespace Orchard.Pages.Controllers {
@@ -22,6 +24,7 @@ namespace Orchard.Pages.Controllers {
T = NullLocalizer.Instance;
}
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public IOrchardServices Services { get; private set; }
private Localizer T { get; set; }
@@ -189,6 +192,9 @@ namespace Orchard.Pages.Controllers {
case "PublishNow":
_pageService.Publish(model.Page.Item);
Services.Notifier.Information(T("Page has been published"));
if (model.PromoteToHomePage) {
CurrentSite.HomePage = "PagesHomePageProvider;" + model.Page.Item.Id;
}
break;
case "PublishLater":
_pageService.Publish(model.Page.Item, model.Page.Item.ScheduledPublishUtc.Value);

View File

@@ -77,6 +77,7 @@
<Compile Include="Security\Authorization.cs" />
<Compile Include="Services\IPageService.cs" />
<Compile Include="Services\PageService.cs" />
<Compile Include="Services\PagesHomePageProvider.cs" />
<Compile Include="Services\SlugConstraint.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -0,0 +1,51 @@
using System.Web.Mvc;
using Orchard.Localization;
using Orchard.Mvc.Results;
using Orchard.Pages.Models;
using Orchard.Pages.ViewModels;
using Orchard.Services;
namespace Orchard.Pages.Services {
public class PagesHomePageProvider : IHomePageProvider {
private readonly IPageService _pageService;
private readonly ISlugConstraint _slugConstraint;
public PagesHomePageProvider(IOrchardServices services, IPageService pageService, ISlugConstraint slugConstraint) {
Services = services;
_slugConstraint = slugConstraint;
_pageService = pageService;
T = NullLocalizer.Instance;
}
public IOrchardServices Services { get; private set; }
private Localizer T { get; set; }
#region Implementation of IHomePageProvider
public string GetProviderName() {
return "PagesHomePageProvider";
}
public ActionResult GetHomePage(int itemId) {
Page page = _pageService.Get(itemId);
var correctedSlug = _slugConstraint.LookupPublishedSlug(page.Slug);
if (correctedSlug == null)
return new NotFoundResult();
page = _pageService.Get(correctedSlug);
if (page == null)
return new NotFoundResult();
var model = new PageViewModel {
Page = Services.ContentManager.BuildDisplayModel(page, "Detail")
};
return new ViewResult {
ViewName = "~/Modules/Orchard.Pages/Views/Page/Item.ascx",
ViewData = new ViewDataDictionary<PageViewModel>(model)
};
}
#endregion
}
}

View File

@@ -4,5 +4,6 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.Pages.ViewModels {
public class PageEditViewModel : AdminViewModel {
public ContentItemViewModel<Page> Page { get; set; }
public bool PromoteToHomePage { get; set; }
}
}

View File

@@ -4,5 +4,8 @@
<h1><%=Html.TitleForPage(T("Edit Page").ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorForItem(m => m.Page) %><%
<%=Html.EditorForItem(m => m.Page) %>
<%=Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="PromoteToHomePage" class="forcheckbox"><%=_Encoded("Set as home page") %></label>
<%
} %>

View File

@@ -14,7 +14,6 @@ using Orchard.Security;
using Orchard.Settings;
using Orchard.Setup.ViewModels;
using Orchard.Localization;
using Orchard.UI.Navigation;
using Orchard.UI.Notify;
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
@@ -104,6 +103,7 @@ namespace Orchard.Setup.Controllers {
page.As<HasComments>().CommentsShown = false;
page.As<CommonAspect>().Owner = user;
contentManager.Publish(page);
siteSettings.Record.HomePage = "PagesHomePageProvider;" + page.Id;
// add a menu item for the shiny new home page
var menuItem = contentManager.Create("menuitem");

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
@@ -161,6 +162,11 @@ namespace Orchard.Environment.ShellBuilders {
public string SuperUser {
get { return ""; }
}
public string HomePage {
get { return ""; }
set { throw new NotImplementedException(); }
}
}
}

View File

@@ -154,6 +154,7 @@
<Compile Include="Security\IAuthorizationServiceEvents.cs" />
<Compile Include="Security\StandardPermissions.cs" />
<Compile Include="Security\OrchardSecurityException.cs" />
<Compile Include="Services\IHomePageProvider.cs" />
<Compile Include="Tasks\Scheduling\IPublishingTaskManager.cs" />
<Compile Include="Tasks\Scheduling\IScheduledTask.cs" />
<Compile Include="ContentManagement\ContentExtensions.cs" />

View File

@@ -0,0 +1,8 @@
using System.Web.Mvc;
namespace Orchard.Services {
public interface IHomePageProvider : IDependency {
string GetProviderName();
ActionResult GetHomePage(int itemId);
}
}

View File

@@ -10,5 +10,6 @@ namespace Orchard.Settings {
string SiteSalt { get; }
string SiteUrl { get; }
string SuperUser { get; }
string HomePage { get; set; }
}
}