--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-02-15 12:07:08 -08:00
51 changed files with 499 additions and 168 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
@@ -10,6 +12,7 @@ using Orchard.Data;
using Orchard.Localization;
using Orchard.Mvc.Results;
using Orchard.Security;
using Orchard.Settings;
using Orchard.UI.Notify;
namespace Orchard.Blogs.Controllers {
@@ -33,6 +36,7 @@ namespace Orchard.Blogs.Controllers {
}
private Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ActionResult Create() {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute
@@ -100,12 +104,17 @@ namespace Orchard.Blogs.Controllers {
return new NotFoundResult();
var model = new BlogEditViewModel {
Blog = _services.ContentManager.UpdateEditorModel(blog, this)
Blog = _services.ContentManager.UpdateEditorModel(blog, this),
};
if (!ModelState.IsValid)
return View(model);
string setAsHomePage = input["PromoteToHomePage"];
if (!String.IsNullOrEmpty(setAsHomePage) && !setAsHomePage.Equals("false")) {
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
}
_notifier.Information(T("Blog information updated"));
return Redirect(Url.BlogsForAdmin());

View File

@@ -85,6 +85,7 @@
<Compile Include="Permissions.cs" />
<Compile Include="Routing\IsArchiveConstraint.cs" />
<Compile Include="Routing\IsBlogConstraint.cs" />
<Compile Include="Services\BlogHomePageProvider.cs" />
<Compile Include="Services\BlogService.cs" />
<Compile Include="Controllers\BlogController.cs" />
<Compile Include="Models\Blog.cs" />

View File

@@ -0,0 +1,49 @@
using System.Linq;
using System.Web.Mvc;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
using Orchard.Blogs.ViewModels;
using Orchard.Mvc.Results;
using Orchard.Services;
using Orchard.Core.Feeds;
namespace Orchard.Blogs.Services {
public class BlogHomePageProvider : IHomePageProvider {
private readonly IBlogService _blogService;
private readonly IFeedManager _feedManager;
public BlogHomePageProvider(IOrchardServices services, IBlogService blogService, IFeedManager feedManager) {
Services = services;
_feedManager = feedManager;
_blogService = blogService;
}
public IOrchardServices Services { get; private set; }
#region Implementation of IHomePageProvider
public string GetProviderName() {
return "BlogHomePageProvider";
}
public ActionResult GetHomePage(int itemId) {
Blog blog = _blogService.Get().Where(x => x.Id == itemId).FirstOrDefault();
if (blog == null)
return new NotFoundResult();
var model = new BlogViewModel {
Blog = Services.ContentManager.BuildDisplayModel(blog, "Detail")
};
_feedManager.Register(blog);
return new ViewResult {
ViewName = "~/Modules/Orchard.Blogs/Views/Blog/Item.ascx",
ViewData = new ViewDataDictionary<BlogViewModel>(model)
};
}
#endregion
}
}

View File

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

View File

@@ -4,5 +4,7 @@
<% using (Html.BeginFormAntiForgeryPost()) { %>
<%=Html.ValidationSummary() %>
<%=Html.EditorForItem(m => m.Blog) %>
<%=Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="PromoteToHomePage" class="forcheckbox"><%=_Encoded("Set as home page") %></label>
<fieldset><input class="button" type="submit" value="<%=_Encoded("Save") %>" /></fieldset><%
} %>

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

@@ -1,4 +1,4 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PageViewModel>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.Pages.ViewModels"%>
<%=Html.DisplayForItem(m=>m.Page) %>
<%=Html.DisplayForItem(m=>m.Page) %>

View File

@@ -4,6 +4,7 @@ using System.Web.Mvc;
using Orchard.Comments.Models;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Settings.Models;
using Orchard.Data;
using Orchard.Data.Migrations;
@@ -14,6 +15,7 @@ using Orchard.Settings;
using Orchard.Setup.ViewModels;
using Orchard.Localization;
using Orchard.UI.Notify;
using MenuItem=Orchard.Core.Navigation.Models.MenuItem;
namespace Orchard.Setup.Controllers {
public class SetupController : Controller {
@@ -102,6 +104,23 @@ 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 homeMenuItem = contentManager.Create("menuitem");
homeMenuItem.As<MenuPart>().MenuPosition = "1";
homeMenuItem.As<MenuPart>().MenuText = T("Home").ToString();
homeMenuItem.As<MenuPart>().OnMainMenu = true;
homeMenuItem.As<MenuItem>().Url = Request.Url.AbsolutePath;
// add a menu item for the admin
var adminMenuItem = contentManager.Create("menuitem");
adminMenuItem.As<MenuPart>().MenuPosition = "2";
adminMenuItem.As<MenuPart>().MenuText = T("Admin").ToString();
adminMenuItem.As<MenuPart>().OnMainMenu = true;
//adminMenuItem.As<MenuItem>().Permissions = new [] {StandardPermissions.AccessAdminPanel};
//todo: (heskew) pull "/blogs" once the is a ~/admin
adminMenuItem.As<MenuItem>().Url = string.Format("{0}admin/blogs", Request.Url.AbsolutePath);
var authenticationService = finiteEnvironment.Resolve<IAuthenticationService>();
authenticationService.SignIn(user, true);