mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Making content part names a little more friendly in the UI
--HG-- branch : dev
This commit is contained in:
@@ -114,7 +114,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
Type = typeViewModel,
|
||||
PartSelections = _contentDefinitionService.GetParts()
|
||||
.Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name))
|
||||
.Select(cpd => new PartSelectionViewModel { PartName = cpd.Name })
|
||||
.Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName })
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
@@ -131,10 +131,8 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
return new NotFoundResult();
|
||||
|
||||
var viewModel = new AddPartsViewModel();
|
||||
if (!TryUpdateModel(viewModel)) {
|
||||
viewModel.Type = typeViewModel;
|
||||
return View(viewModel);
|
||||
}
|
||||
if (!TryUpdateModel(viewModel))
|
||||
return AddPartsTo(id);
|
||||
|
||||
var partsToAdd = viewModel.PartSelections.Where(ps => ps.IsSelected).Select(ps => ps.PartName);
|
||||
foreach (var partToAdd in partsToAdd) {
|
||||
@@ -144,8 +142,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
|
||||
if (!ModelState.IsValid) {
|
||||
Services.TransactionManager.Cancel(); ;
|
||||
viewModel.Type = typeViewModel;
|
||||
return View(viewModel);
|
||||
return AddPartsTo(id);
|
||||
}
|
||||
|
||||
return RedirectToAction("Edit", new {id});
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Orchard.ContentTypes.Extensions {
|
||||
public static class StrinExtensions {
|
||||
private static readonly Regex humps = new Regex("[A-Z][^A-Z]*");
|
||||
public static string CamelFriendly(this string camel) {
|
||||
return camel != null
|
||||
? humps.Matches(camel).OfType<Match>().Select(m => m.Value).Aggregate((a, b) => a + " " + b).TrimStart(' ')
|
||||
: null;
|
||||
}
|
||||
|
||||
public static string TrimEnd(this string rough, string trim = "") {
|
||||
if (rough == null)
|
||||
return null;
|
||||
|
||||
return rough.EndsWith(trim)
|
||||
? rough.Substring(0, rough.Length - 4)
|
||||
: rough;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="ViewModels\AddPartsViewModel.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
|
||||
@@ -6,6 +6,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentTypes.Extensions;
|
||||
using Orchard.ContentTypes.ViewModels;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Core.Contents.Settings;
|
||||
@@ -149,7 +150,8 @@ namespace Orchard.ContentTypes.Services {
|
||||
public IEnumerable<EditPartViewModel> GetParts() {
|
||||
var typeNames = GetTypes().Select(ctd => ctd.Name);
|
||||
// code-defined parts
|
||||
var codeDefinedParts = _contentPartDrivers.SelectMany(d => d.GetPartInfo().Select(cpi => new EditPartViewModel {Name = cpi.PartName}));
|
||||
var codeDefinedParts = _contentPartDrivers
|
||||
.SelectMany(d => d.GetPartInfo().Select(cpi => new EditPartViewModel { Name = cpi.PartName }));
|
||||
// user-defined parts
|
||||
var contentParts = _contentDefinitionManager.ListPartDefinitions().Where(cpd => !codeDefinedParts.Any(m => m.Name == cpd.Name)).Select(cpd => new EditPartViewModel(cpd));
|
||||
// all together now, except for those parts with the same name as a type (implicit type's part or a mistake)
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
|
||||
public class PartSelectionViewModel {
|
||||
public string PartName { get; set; }
|
||||
public string PartDisplayName { get; set; }
|
||||
public bool IsSelected { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
using Orchard.ContentTypes.Extensions;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
@@ -80,6 +81,11 @@ namespace Orchard.ContentTypes.ViewModels {
|
||||
|
||||
public string Prefix { get { return "PartDefinition"; } }
|
||||
public string Name { get; set; }
|
||||
private string _displayName;
|
||||
public string DisplayName {
|
||||
get { return !string.IsNullOrWhiteSpace(_displayName) ? _displayName : Name.TrimEnd("Part").CamelFriendly(); }
|
||||
set { _displayName = value; }
|
||||
}
|
||||
public IEnumerable<TemplateViewModel> Templates { get; set; }
|
||||
public IEnumerable<EditPartFieldViewModel> Fields { get; set; }
|
||||
public SettingsDictionary Settings { get; set; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.AddFieldViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Add a new field to \"{0}\"", Model.Part.Name).ToString())%></h1><%
|
||||
<h1><%:Html.TitleForPage(T("Add a new field to \"{0}\"", Model.Part.DisplayName).ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%:Html.ValidationSummary() %>
|
||||
<fieldset>
|
||||
|
||||
@@ -14,7 +14,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
"{0} <label for=\"{1}\" class=\"forcheckbox\">{2}</label>{3}",
|
||||
Html.CheckBox(fieldNameStart + "IsSelected"),
|
||||
ViewData.TemplateInfo.GetFullHtmlFieldId(fieldNameStart + "IsSelected"),
|
||||
partSelection.PartName,
|
||||
partSelection.PartDisplayName,
|
||||
Html.Hidden(fieldNameStart + "PartName", partSelection.PartName)));
|
||||
},
|
||||
"available-parts")%>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.RemoveFieldViewModel>" %>
|
||||
<%
|
||||
Html.RegisterStyle("admin.css"); %>
|
||||
<h1><%:Html.TitleForPage(T("Remove the \"{0}\" part from \"{1}\"", Model.Name, Model.Part.Name).ToString())%></h1><%
|
||||
<h1><%:Html.TitleForPage(T("Remove the \"{0}\" part from \"{1}\"", Model.Name, Model.Part.DisplayName).ToString())%></h1><%
|
||||
using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<p><%:T("Looks like you couldn't use the fancy way to remove the field. Try hitting the button below to force the issue.") %></p>
|
||||
<fieldset>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditPartViewModel>" %>
|
||||
<div class="summary">
|
||||
<div class="properties">
|
||||
<h3><%:Model.Name%></h3>
|
||||
<h3><%:Model.DisplayName %></h3>
|
||||
</div>
|
||||
<div class="related">
|
||||
<%:Html.ActionLink(T("Edit").ToString(), "EditPart", new {area = "Orchard.ContentTypes", id = Model.Name})%>
|
||||
<%:Html.ActionLink(T("Edit").ToString(), "EditPart", new {area = "Orchard.ContentTypes", id = Model.Name}) %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,6 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.ContentTypes.ViewModels.EditTypePartViewModel>" %>
|
||||
<fieldset class="manage-part" itemscope="itemscope" itemid="<%:Model.PartDefinition.Name %>" itemtype="http://orchardproject.net/data/ContentTypePart">
|
||||
<h3 itemprop="Name"><%:Model.PartDefinition.Name %></h3>
|
||||
<h3 itemprop="Name"><%:Model.PartDefinition.DisplayName %></h3>
|
||||
<div class="manage">
|
||||
<%:Html.ActionLink(T("Remove").Text, "RemovePartFrom", new { area = "Orchard.ContentTypes", id = Model.Type.Name, Model.PartDefinition.Name }, new { itemprop = "RemoveUrl UnsafeUrl" })%><%--// <- some experimentation--%>
|
||||
</div><%
|
||||
|
||||
Reference in New Issue
Block a user