mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding Listable metadata
This commit is contained in:
@@ -73,7 +73,7 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
break;
|
||||
}
|
||||
|
||||
var query = _contentManager.Query(versionOptions, GetCreatableTypes(false).Select(ctd => ctd.Name).ToArray());
|
||||
var query = _contentManager.Query(versionOptions, GetListableTypes(false).Select(ctd => ctd.Name).ToArray());
|
||||
|
||||
if (!string.IsNullOrEmpty(model.TypeName)) {
|
||||
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.TypeName);
|
||||
@@ -101,7 +101,7 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
}
|
||||
|
||||
model.Options.SelectedFilter = model.TypeName;
|
||||
model.Options.FilterOptions = GetCreatableTypes(false)
|
||||
model.Options.FilterOptions = GetListableTypes(false)
|
||||
.Select(ctd => new KeyValuePair<string, string>(ctd.Name, ctd.DisplayName))
|
||||
.ToList().OrderBy(kvp => kvp.Value);
|
||||
|
||||
@@ -128,6 +128,13 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
(!andContainable || ctd.Parts.Any(p => p.PartDefinition.Name == "ContainablePart")));
|
||||
}
|
||||
|
||||
private IEnumerable<ContentTypeDefinition> GetListableTypes(bool andContainable) {
|
||||
return _contentDefinitionManager.ListTypeDefinitions().Where(ctd =>
|
||||
Services.Authorizer.Authorize(Permissions.EditContent, _contentManager.New(ctd.Name)) &&
|
||||
ctd.Settings.GetModel<ContentTypeSettings>().Listable &&
|
||||
(!andContainable || ctd.Parts.Any(p => p.PartDefinition.Name == "ContainablePart")));
|
||||
}
|
||||
|
||||
[HttpPost, ActionName("List")]
|
||||
[Mvc.FormValueRequired("submit.Filter")]
|
||||
public ActionResult ListFilterPOST(ContentOptions options) {
|
||||
@@ -135,7 +142,7 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
if (options != null) {
|
||||
routeValues["Options.OrderBy"] = options.OrderBy; //todo: don't hard-code the key
|
||||
routeValues["Options.ContentsStatus"] = options.ContentsStatus; //todo: don't hard-code the key
|
||||
if (GetCreatableTypes(false).Any(ctd => string.Equals(ctd.Name, options.SelectedFilter, StringComparison.OrdinalIgnoreCase))) {
|
||||
if (GetListableTypes(false).Any(ctd => string.Equals(ctd.Name, options.SelectedFilter, StringComparison.OrdinalIgnoreCase))) {
|
||||
routeValues["id"] = options.SelectedFilter;
|
||||
}
|
||||
else {
|
||||
@@ -201,6 +208,12 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
return View("CreatableTypeList", viewModel);
|
||||
}
|
||||
|
||||
ActionResult ListableTypeList(int? containerId) {
|
||||
var viewModel = Shape.ViewModel(ContentTypes: GetListableTypes(containerId.HasValue), ContainerId: containerId);
|
||||
|
||||
return View("ListableTypeList", viewModel);
|
||||
}
|
||||
|
||||
public ActionResult Create(string id, int? containerId) {
|
||||
if (string.IsNullOrEmpty(id))
|
||||
return CreatableTypeList(containerId);
|
||||
|
@@ -7,6 +7,10 @@ namespace Orchard.Core.Contents.Extensions {
|
||||
return builder.WithSetting("ContentTypeSettings.Creatable", creatable.ToString());
|
||||
}
|
||||
|
||||
public static ContentTypeDefinitionBuilder Listable(this ContentTypeDefinitionBuilder builder, bool listable = true) {
|
||||
return builder.WithSetting("ContentTypeSettings.Listable", listable.ToString());
|
||||
}
|
||||
|
||||
public static ContentTypeDefinitionBuilder Draftable(this ContentTypeDefinitionBuilder builder, bool draftable = true) {
|
||||
return builder.WithSetting("ContentTypeSettings.Draftable", draftable.ToString());
|
||||
}
|
||||
|
@@ -5,6 +5,10 @@
|
||||
/// </summary>
|
||||
public bool Creatable { get; set; }
|
||||
/// <summary>
|
||||
/// Used to determine if an instance of this content type can be listed in the contents page
|
||||
/// </summary>
|
||||
public bool Listable { get; set; }
|
||||
/// <summary>
|
||||
/// Used to determine if this content type supports draft versions
|
||||
/// </summary>
|
||||
public bool Draftable { get; set; }
|
||||
|
26
src/Orchard.Web/Modules/Orchard.ContentTypes/Migrations.cs
Normal file
26
src/Orchard.Web/Modules/Orchard.ContentTypes/Migrations.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
namespace Orchard.ContentTypes {
|
||||
public class Migrations : DataMigrationImpl {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
|
||||
public Migrations(IContentDefinitionManager contentDefinitionManager) {
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
}
|
||||
|
||||
public int Create() {
|
||||
foreach (var typeDefinition in _contentDefinitionManager.ListTypeDefinitions()) {
|
||||
if (typeDefinition.Settings.ContainsKey("ContentTypeSettings.Creatable") && Convert.ToBoolean(typeDefinition.Settings["ContentTypeSettings.Creatable"], CultureInfo.InvariantCulture)) {
|
||||
typeDefinition.Settings["ContentTypeSettings.Listable"] = "True";
|
||||
_contentDefinitionManager.StoreTypeDefinition(typeDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -79,6 +79,7 @@
|
||||
<Compile Include="Events\ContentTypeRemovedContext.cs" />
|
||||
<Compile Include="Events\IContentDefinitionEventHandler.cs" />
|
||||
<Compile Include="Extensions\MetadataExtensions.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Services\ContentTypePlacementStrategy.cs" />
|
||||
|
@@ -16,6 +16,7 @@ namespace Orchard.ContentTypes.Settings {
|
||||
var settings = definition.Settings.GetModel<ContentTypeSettings>();
|
||||
var model = new ContentTypeSettingsViewModel {
|
||||
Creatable = settings.Creatable,
|
||||
Listable = settings.Listable,
|
||||
Draftable = settings.Draftable,
|
||||
};
|
||||
|
||||
@@ -31,6 +32,7 @@ namespace Orchard.ContentTypes.Settings {
|
||||
updateModel.TryUpdateModel(model, "ContentTypeSettingsViewModel", null, null);
|
||||
|
||||
builder.Creatable(model.Creatable);
|
||||
builder.Listable(model.Listable);
|
||||
builder.Draftable(model.Draftable);
|
||||
builder.WithSetting("Stereotype", model.Stereotype);
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
namespace Orchard.ContentTypes.ViewModels {
|
||||
public class ContentTypeSettingsViewModel {
|
||||
public bool Creatable { get; set; }
|
||||
public bool Draftable{ get; set; }
|
||||
public bool Listable { get; set; }
|
||||
public bool Draftable { get; set; }
|
||||
public string Stereotype { get; set; }
|
||||
}
|
||||
}
|
@@ -7,6 +7,13 @@
|
||||
<span class="hint">@T("Determines if an instance of this content type can be created through the UI.")</span>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.EditorFor(m => m.Listable)
|
||||
<label for="@Html.FieldIdFor(m => m.Listable)" class="forcheckbox">@T("Listable")</label>
|
||||
@Html.ValidationMessageFor(m => m.Listable)
|
||||
<span class="hint">@T("Determines if an instance of this content type can be listed through the UI.")</span>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.EditorFor(m => m.Draftable)
|
||||
<label for="@Html.FieldIdFor(m => m.Draftable)" class="forcheckbox">@T("Draftable")</label>
|
||||
|
Reference in New Issue
Block a user