Adding "set as homepage" functionality to the RoutePart

- Orchard.Pages was already gone and Orchard.Blogs is now gone (made redundant and less functional in a way)

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-07-23 14:30:22 -07:00
parent 877d49779e
commit 2077ab964b
14 changed files with 64 additions and 99 deletions

View File

@@ -1,4 +1,7 @@
using Orchard.ContentManagement; using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Core.ContentsLocation.Models; using Orchard.Core.ContentsLocation.Models;
@@ -6,22 +9,27 @@ using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.Services; using Orchard.Core.Routable.Services;
using Orchard.Core.Routable.ViewModels; using Orchard.Core.Routable.ViewModels;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Services;
using Orchard.Settings;
using Orchard.UI.Notify; using Orchard.UI.Notify;
namespace Orchard.Core.Routable.Drivers { namespace Orchard.Core.Routable.Drivers {
public class RoutePartDriver : ContentPartDriver<RoutePart> { public class RoutePartDriver : ContentPartDriver<RoutePart> {
private readonly IOrchardServices _services; private readonly IOrchardServices _services;
private readonly IRoutableService _routableService; private readonly IRoutableService _routableService;
private readonly IHomePageProvider _routableHomePageProvider;
public RoutePartDriver(IOrchardServices services, IRoutableService routableService) { public RoutePartDriver(IOrchardServices services, IRoutableService routableService, IEnumerable<IHomePageProvider> homePageProviders) {
_services = services; _services = services;
_routableService = routableService; _routableService = routableService;
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name); ;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
private const string TemplateName = "Parts/Routable.RoutePart"; private const string TemplateName = "Parts/Routable.RoutePart";
public Localizer T { get; set; } public Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
protected override string Prefix { protected override string Prefix {
get { return "Routable"; } get { return "Routable"; }
@@ -68,6 +76,7 @@ namespace Orchard.Core.Routable.Drivers {
} }
var location = part.GetLocation("Editor"); var location = part.GetLocation("Editor");
model.PromoteToHomePage = model.Id != 0 && _routableHomePageProvider != null && CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
return ContentPartTemplate(model, TemplateName, Prefix).Location(location); return ContentPartTemplate(model, TemplateName, Prefix).Location(location);
} }
@@ -97,8 +106,11 @@ namespace Orchard.Core.Routable.Drivers {
originalSlug, part.Slug, part.ContentItem.ContentType)); originalSlug, part.Slug, part.ContentItem.ContentType));
} }
return Editor(part); if (part.ContentItem.Id != 0 && model.PromoteToHomePage && _routableHomePageProvider != null) {
CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(part.ContentItem.Id);
} }
return Editor(part);
}
} }
} }

View File

@@ -12,6 +12,7 @@ namespace Orchard.Core.Routable.Services {
[UsedImplicitly] [UsedImplicitly]
public class RoutableHomePageProvider : IHomePageProvider { public class RoutableHomePageProvider : IHomePageProvider {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
public const string Name = "RoutableHomePageProvider";
public RoutableHomePageProvider(IOrchardServices services, IContentManager contentManager) { public RoutableHomePageProvider(IOrchardServices services, IContentManager contentManager) {
_contentManager = contentManager; _contentManager = contentManager;
@@ -23,7 +24,11 @@ namespace Orchard.Core.Routable.Services {
public Localizer T { get; set; } public Localizer T { get; set; }
public string GetProviderName() { public string GetProviderName() {
return "RoutableHomePageProvider"; return Name;
}
public string GetSettingValue(int id) {
return GetProviderName() + ";" + id;
} }
public ActionResult GetHomePage(int itemId) { public ActionResult GetHomePage(int itemId) {

View File

@@ -11,6 +11,7 @@ namespace Orchard.Core.Routable.ViewModels {
public string Title { get; set; } public string Title { get; set; }
public string Slug { get; set; } public string Slug { get; set; }
public int? ContainerId { get; set; } public int? ContainerId { get; set; }
public bool PromoteToHomePage { get; set; }
public string DisplayLeadingPath { get; set; } public string DisplayLeadingPath { get; set; }
} }

View File

@@ -9,9 +9,9 @@
<fieldset class="permalink"> <fieldset class="permalink">
<label class="sub" for="Slug"><%: T("Permalink")%><br /><span><%: Request.ToRootUrlString()%>/<%: Model.DisplayLeadingPath %></span></label> <label class="sub" for="Slug"><%: T("Permalink")%><br /><span><%: Request.ToRootUrlString()%>/<%: Model.DisplayLeadingPath %></span></label>
<span><%: Html.TextBoxFor(m => m.Slug, new { @class = "text" })%></span> <span><%: Html.TextBoxFor(m => m.Slug, new { @class = "text" })%></span>
<%: Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="<%:ViewData.TemplateInfo.GetFullHtmlFieldId("PromoteToHomePage") %>" class="forcheckbox"><%: T("Set as home page") %></label>
</fieldset> </fieldset>
<% using (this.Capture("end-of-page-scripts")) { %> <% using (this.Capture("end-of-page-scripts")) { %>
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function(){

View File

@@ -4,9 +4,11 @@ using JetBrains.Annotations;
using Orchard.Blogs.Drivers; using Orchard.Blogs.Drivers;
using Orchard.Blogs.Extensions; using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.Blogs.Routing;
using Orchard.Blogs.Services; using Orchard.Blogs.Services;
using Orchard.Blogs.ViewModels; using Orchard.Blogs.ViewModels;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.Results; using Orchard.Mvc.Results;
using Orchard.Settings; using Orchard.Settings;
@@ -18,16 +20,26 @@ namespace Orchard.Blogs.Controllers {
public class BlogAdminController : Controller, IUpdateModel { public class BlogAdminController : Controller, IUpdateModel {
private readonly IBlogService _blogService; private readonly IBlogService _blogService;
private readonly IBlogPostService _blogPostService; private readonly IBlogPostService _blogPostService;
private readonly IContentManager _contentManager;
private readonly ITransactionManager _transactionManager;
private readonly IBlogSlugConstraint _blogSlugConstraint;
public BlogAdminController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService) { public BlogAdminController(IOrchardServices services,
IBlogService blogService,
IBlogPostService blogPostService,
IContentManager contentManager,
ITransactionManager transactionManager,
IBlogSlugConstraint blogSlugConstraint) {
Services = services; Services = services;
_blogService = blogService; _blogService = blogService;
_blogPostService = blogPostService; _blogPostService = blogPostService;
_contentManager = contentManager;
_transactionManager = transactionManager;
_blogSlugConstraint = blogSlugConstraint;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
public Localizer T { get; set; } public Localizer T { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public IOrchardServices Services { get; set; } public IOrchardServices Services { get; set; }
public ActionResult Create() { public ActionResult Create() {
@@ -47,20 +59,20 @@ namespace Orchard.Blogs.Controllers {
} }
[HttpPost] [HttpPost]
public ActionResult Create(CreateBlogViewModel model, bool PromoteToHomePage) { public ActionResult Create(CreateBlogViewModel model) {
//TODO: (erikpo) Might think about moving this to an ActionFilter/Attribute var blog = Services.ContentManager.New<BlogPart>(BlogPartDriver.ContentType.Name);
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
model.Blog = Services.ContentManager.UpdateEditorModel(Services.ContentManager.New<BlogPart>(BlogPartDriver.ContentType.Name), this); _blogService.Create(blog);
model.Blog = _contentManager.UpdateEditorModel(blog, this);
_blogSlugConstraint.AddSlug(model.Blog.Item.Slug);
if (!ModelState.IsValid) if (!ModelState.IsValid) {
_transactionManager.Cancel();
return View(model); return View(model);
}
_blogService.Create(model.Blog.Item);
if (PromoteToHomePage)
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug)); return Redirect(Url.BlogForAdmin(model.Blog.Item.Slug));
} }
@@ -77,14 +89,14 @@ namespace Orchard.Blogs.Controllers {
var model = new BlogEditViewModel { var model = new BlogEditViewModel {
Blog = Services.ContentManager.BuildEditorModel(blog), Blog = Services.ContentManager.BuildEditorModel(blog),
PromoteToHomePage = CurrentSite.HomePage == "BlogHomePageProvider;" + blog.Id //PromoteToHomePage = CurrentSite.HomePage == "BlogHomePageProvider;" + blog.Id
}; };
return View(model); return View(model);
} }
[HttpPost] [HttpPost, ActionName("Edit")]
public ActionResult Edit(string blogSlug, bool PromoteToHomePage) { public ActionResult EditPOST(string blogSlug) {
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't edit blog"))) if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't edit blog")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -100,8 +112,8 @@ namespace Orchard.Blogs.Controllers {
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(model); return View(model);
if (PromoteToHomePage) //if (PromoteToHomePage)
CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id; // CurrentSite.HomePage = "BlogHomePageProvider;" + model.Blog.Item.Id;
_blogService.Edit(model.Blog.Item); _blogService.Edit(model.Blog.Item);

View File

@@ -84,7 +84,6 @@
<Compile Include="Routing\IsArchiveConstraint.cs" /> <Compile Include="Routing\IsArchiveConstraint.cs" />
<Compile Include="Routing\BlogSlugConstraint.cs" /> <Compile Include="Routing\BlogSlugConstraint.cs" />
<Compile Include="Routing\BlogSlugConstraintUpdator.cs" /> <Compile Include="Routing\BlogSlugConstraintUpdator.cs" />
<Compile Include="Services\BlogHomePageProvider.cs" />
<Compile Include="Services\BlogService.cs" /> <Compile Include="Services\BlogService.cs" />
<Compile Include="Controllers\BlogController.cs" /> <Compile Include="Controllers\BlogController.cs" />
<Compile Include="Models\BlogPart.cs" /> <Compile Include="Models\BlogPart.cs" />

View File

@@ -1,56 +0,0 @@
using System.Linq;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Routing;
using Orchard.Blogs.ViewModels;
using Orchard.Mvc.Results;
using Orchard.Services;
using Orchard.Core.Feeds;
namespace Orchard.Blogs.Services {
[UsedImplicitly]
public class BlogHomePageProvider : IHomePageProvider {
private readonly IBlogService _blogService;
private readonly IBlogSlugConstraint _blogSlugConstraint;
private readonly IFeedManager _feedManager;
public BlogHomePageProvider(IOrchardServices services, IBlogService blogService, IBlogSlugConstraint blogSlugConstraint, IFeedManager feedManager) {
Services = services;
_blogService = blogService;
_blogSlugConstraint = blogSlugConstraint;
_feedManager = feedManager;
}
public IOrchardServices Services { get; private set; }
public string GetProviderName() {
return "BlogHomePageProvider";
}
public ActionResult GetHomePage(int itemId) {
var blog = _blogService.Get().Where(x => x.Id == itemId).FirstOrDefault();
if (blog == null)
return new NotFoundResult();
var correctedSlug = _blogSlugConstraint.FindSlug(blog.Slug);
if (correctedSlug == null)
return new NotFoundResult();
blog = _blogService.Get(correctedSlug);
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)
};
}
}
}

View File

@@ -33,7 +33,6 @@ namespace Orchard.Blogs.Services {
public void Create(BlogPart blogPart) { public void Create(BlogPart blogPart) {
_contentManager.Create(blogPart.ContentItem); _contentManager.Create(blogPart.ContentItem);
_blogSlugConstraint.AddSlug(blogPart.Slug);
} }
public void Edit(BlogPart blogPart) { public void Edit(BlogPart blogPart) {

View File

@@ -4,6 +4,6 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels { namespace Orchard.Blogs.ViewModels {
public class CreateBlogViewModel : BaseViewModel { public class CreateBlogViewModel : BaseViewModel {
public ContentItemViewModel<BlogPart> Blog { get; set; } public ContentItemViewModel<BlogPart> Blog { get; set; }
public bool PromoteToHomePage { get; set; } //public bool PromoteToHomePage { get; set; }
} }
} }

View File

@@ -1,12 +1,7 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<CreateBlogViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<CreateBlogViewModel>" %>
<%@ Import Namespace="Orchard.Blogs.ViewModels"%> <%@ Import Namespace="Orchard.Blogs.ViewModels"%>
<h1><%: Html.TitleForPage(T("Add Blog").ToString()) %></h1> <h1><%: Html.TitleForPage(T("Create Blog").ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %> <% using (Html.BeginFormAntiForgeryPost()) { %>
<%: Html.ValidationSummary() %> <%: Html.ValidationSummary() %>
<%: Html.EditorForItem(vm => vm.Blog) %> <%: Html.EditorForItem(vm => vm.Blog) %><%
<fieldset>
<%: Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="PromoteToHomePage" class="forcheckbox"><%: T("Set as home page") %></label>
</fieldset>
<fieldset><input class="button primaryAction" type="submit" value="<%: T("Add") %>" /></fieldset><%
} %> } %>

View File

@@ -3,10 +3,5 @@
<h1><%: Html.TitleForPage(T("Edit Blog").ToString()) %></h1> <h1><%: Html.TitleForPage(T("Edit Blog").ToString()) %></h1>
<% using (Html.BeginFormAntiForgeryPost()) { %> <% using (Html.BeginFormAntiForgeryPost()) { %>
<%: Html.ValidationSummary() %> <%: Html.ValidationSummary() %>
<%: Html.EditorForItem(m => m.Blog) %> <%: Html.EditorForItem(m => m.Blog) %><%
<fieldset>
<%: Html.EditorFor(m => m.PromoteToHomePage) %>
<label for="PromoteToHomePage" class="forcheckbox"><%: T("Set as home page") %></label>
</fieldset>
<fieldset><input class="button primaryAction" type="submit" value="<%: T("Save") %>" /></fieldset><%
} %> } %>

View File

@@ -1,6 +1,7 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ContentItemViewModel<BlogPart>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPart>>" %>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<% Html.AddTitleParts(Model.Item.Name); %> <% Html.AddTitleParts(Model.Item.Name); %>
<% Html.Zone("primary"); %> <% Html.Zone("primary"); %>
<% Html.ZonesAny(); %> <% Html.ZonesAny(); %>
<fieldset><input class="button primaryAction" type="submit" value="<%: T("Add") %>" /></fieldset>

View File

@@ -763,14 +763,15 @@ table .button {
/* Core Modules /* Core Modules
----------------------------------------------------------*/ ----------------------------------------------------------*/
/* Routable */ /* Routable */
.permalink input { .permalink input.text {
background:transparent; background:transparent;
border-color:#EAE9D9; border-color:#EAE9D9;
border-style:dashed; border-style:dashed;
margin-left:0; margin-left:0;
margin-right:2em;
width:350px; width:350px;
} }
.permalink input:focus { .permalink input.text:focus {
background:#FFF; background:#FFF;
border-color:#666d51; border-color:#666d51;
border-style:solid; border-style:solid;

View File

@@ -3,6 +3,7 @@
namespace Orchard.Services { namespace Orchard.Services {
public interface IHomePageProvider : IDependency { public interface IHomePageProvider : IDependency {
string GetProviderName(); string GetProviderName();
string GetSettingValue(int itemId);
ActionResult GetHomePage(int itemId); ActionResult GetHomePage(int itemId);
} }
} }