mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Filtering the list of addable parts (when adding them to a type)
--HG-- branch : dev
This commit is contained in:
@@ -4,6 +4,7 @@ using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
namespace Orchard.Core.Common.DataMigrations {
|
||||
@@ -53,5 +54,11 @@ namespace Orchard.Core.Common.DataMigrations {
|
||||
}));
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom3() {
|
||||
ContentDefinitionManager.AlterPartDefinition("BodyPart", builder => builder.Attachable());
|
||||
ContentDefinitionManager.AlterPartDefinition("CommonPart", builder => builder.Attachable());
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,8 +2,12 @@
|
||||
|
||||
namespace Orchard.Core.Contents.Extensions {
|
||||
public static class MetaDataExtensions {
|
||||
//todo: revisit "creatable" and "attachable", other words by be more fitting
|
||||
public static ContentTypeDefinitionBuilder Creatable(this ContentTypeDefinitionBuilder builder, bool creatable = true) {
|
||||
return builder.WithSetting("ContentTypeSettings.Creatable", creatable.ToString());
|
||||
}
|
||||
public static ContentPartDefinitionBuilder Attachable(this ContentPartDefinitionBuilder builder, bool creatable = true) {
|
||||
return builder.WithSetting("ContentPartSettings.Attachable", creatable.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,8 @@
|
||||
namespace Orchard.Core.Contents.Settings {
|
||||
public class ContentPartSettings {
|
||||
/// <summary>
|
||||
/// This setting is used to display a Content Part in list of Parts to attach to a Content Type
|
||||
/// </summary>
|
||||
public bool Attachable { get; set; }
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Core.Localization.Models;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
@@ -26,5 +27,10 @@ namespace Orchard.Core.Localization.DataMigrations {
|
||||
}));
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom2() {
|
||||
ContentDefinitionManager.AlterPartDefinition("LocalizationPart", builder => builder.Attachable());
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
@@ -42,5 +43,10 @@ namespace Orchard.Core.Navigation.DataMigrations {
|
||||
}));
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom3() {
|
||||
ContentDefinitionManager.AlterPartDefinition("MenuPart", builder => builder.Attachable());
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
@@ -86,6 +86,7 @@
|
||||
<Compile Include="Contents\Permissions.cs" />
|
||||
<Compile Include="Contents\Routes.cs" />
|
||||
<Compile Include="Contents\Settings\ContentTypeSettings.cs" />
|
||||
<Compile Include="Contents\Settings\ContentPartSettings.cs" />
|
||||
<Compile Include="Contents\ViewModels\PublishContentViewModel.cs" />
|
||||
<Compile Include="Localization\ViewModels\EditLocalizationViewModel.cs" />
|
||||
<Compile Include="PublishLater\DataMigrations\PublishLaterDataMigration.cs" />
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Core.Routable.Models;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
@@ -28,5 +29,10 @@ namespace Orchard.Core.Routable.DataMigrations {
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom2() {
|
||||
ContentDefinitionManager.AlterPartDefinition("RoutePart", builder => builder.Attachable());
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
namespace Orchard.Comments.DataMigrations {
|
||||
@@ -82,5 +83,10 @@ namespace Orchard.Comments.DataMigrations {
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom3() {
|
||||
ContentDefinitionManager.AlterPartDefinition("CommentsPart", builder => builder.Attachable());
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentTypes.Services;
|
||||
using Orchard.ContentTypes.ViewModels;
|
||||
using Orchard.Core.Contents.Settings;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Results;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -113,7 +114,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
var viewModel = new AddPartsViewModel {
|
||||
Type = typeViewModel,
|
||||
PartSelections = _contentDefinitionService.GetParts()
|
||||
.Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name))
|
||||
.Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name) && cpd.Settings.GetModel<ContentPartSettings>().Attachable)
|
||||
.Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName })
|
||||
};
|
||||
|
||||
|
@@ -149,11 +149,11 @@ namespace Orchard.ContentTypes.Services {
|
||||
|
||||
public IEnumerable<EditPartViewModel> GetParts() {
|
||||
var typeNames = GetTypes().Select(ctd => ctd.Name);
|
||||
// user-defined parts
|
||||
var contentParts = _contentDefinitionManager.ListPartDefinitions().Select(cpd => new EditPartViewModel(cpd));
|
||||
// code-defined parts
|
||||
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));
|
||||
.SelectMany(d => d.GetPartInfo().Where(cpd => !contentParts.Any(m => m.Name == cpd.PartName)).Select(cpi => new EditPartViewModel { Name = cpi.PartName }));
|
||||
// all together now, except for those parts with the same name as a type (implicit type's part or a mistake)
|
||||
return contentParts.Where(m => !typeNames.Contains(m.Name)).Union(codeDefinedParts).OrderBy(m => m.Name);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Tags.Models;
|
||||
|
||||
@@ -32,5 +33,10 @@ namespace Orchard.Tags.DataMigrations {
|
||||
}));
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom2() {
|
||||
ContentDefinitionManager.AlterPartDefinition("TagsPart", builder => builder.Attachable());
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,6 +8,6 @@
|
||||
<% }
|
||||
else
|
||||
{ %>
|
||||
<li><%: Html.ActionLink(T("Login").ToString(), "LogOn", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl })%></li>
|
||||
<li><%: Html.ActionLink(T("Log On").ToString(), "LogOn", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl })%></li>
|
||||
<% } %>
|
||||
</ul>
|
Reference in New Issue
Block a user