Updating the RoutePart slug prefix display in the editor to cope with not being in a vdir.

Related to #16496 which was already fixed a w/ another bug a little earlier but a double '/' appears when the app is not in a vdir.

work item: 16496

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-29 16:07:12 -08:00
parent de949ccdfc
commit a30374780e
3 changed files with 14 additions and 9 deletions

View File

@@ -8,17 +8,24 @@ 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.Mvc;
using Orchard.Services; using Orchard.Services;
using Orchard.Utility.Extensions;
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 IHttpContextAccessor _httpContextAccessor;
private readonly IHomePageProvider _routableHomePageProvider; private readonly IHomePageProvider _routableHomePageProvider;
public RoutePartDriver(IOrchardServices services, IRoutableService routableService, IEnumerable<IHomePageProvider> homePageProviders) { public RoutePartDriver(IOrchardServices services,
IRoutableService routableService,
IEnumerable<IHomePageProvider> homePageProviders,
IHttpContextAccessor httpContextAccessor) {
_services = services; _services = services;
_routableService = routableService; _routableService = routableService;
_httpContextAccessor = httpContextAccessor;
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name); _routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
@@ -59,10 +66,9 @@ namespace Orchard.Core.Routable.Drivers {
ContainerId = GetContainerId(part), ContainerId = GetContainerId(part),
}; };
var containerPath = part.GetContainerPath(); var request = _httpContextAccessor.Current().Request;
model.DisplayLeadingPath = !string.IsNullOrWhiteSpace(containerPath) var containerUrl = new UriBuilder(request.ToRootUrlString()) { Path = (request.ApplicationPath ?? "").TrimEnd('/') + "/" + (part.GetContainerPath() ?? "") };
? string.Format("{0}/", containerPath) model.ContainerAbsoluteUrl = containerUrl.Uri.ToString().TrimEnd('/');
: "";
model.PromoteToHomePage = model.Id != 0 && part.Path != null && _routableHomePageProvider != null && _services.WorkContext.CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id); model.PromoteToHomePage = model.Id != 0 && part.Path != null && _routableHomePageProvider != null && _services.WorkContext.CurrentSite.HomePage == _routableHomePageProvider.GetSettingValue(model.Id);
return ContentShape("Parts_Routable_Edit", return ContentShape("Parts_Routable_Edit",

View File

@@ -1,5 +1,4 @@
using System; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
namespace Orchard.Core.Routable.ViewModels { namespace Orchard.Core.Routable.ViewModels {
public class RoutableEditorViewModel { public class RoutableEditorViewModel {
@@ -15,6 +14,6 @@ namespace Orchard.Core.Routable.ViewModels {
public int? ContainerId { get; set; } public int? ContainerId { get; set; }
public bool PromoteToHomePage { get; set; } public bool PromoteToHomePage { get; set; }
public string DisplayLeadingPath { get; set; } public string ContainerAbsoluteUrl { get; set; }
} }
} }

View File

@@ -7,7 +7,7 @@
@Html.TextBoxFor(m => m.Title, new { @class = "large text" }) @Html.TextBoxFor(m => m.Title, new { @class = "large text" })
</fieldset> </fieldset>
<fieldset class="permalink"> <fieldset class="permalink">
<label class="sub" for="Slug">@T("Permalink")<br /><span>@Request.ToApplicationRootUrlString()/@Model.DisplayLeadingPath</span></label> <label class="sub" for="Slug">@T("Permalink")<br /><span>@Model.ContainerAbsoluteUrl/</span></label>
<span>@Html.TextBoxFor(m => m.Slug, new { @class = "text" })</span> <span>@Html.TextBoxFor(m => m.Slug, new { @class = "text" })</span>
<span class="checkbox-and-label"> <span class="checkbox-and-label">
@Html.EditorFor(m => m.PromoteToHomePage) @Html.EditorFor(m => m.PromoteToHomePage)