Adding Listable metadata

This commit is contained in:
Sebastien Ros
2014-07-28 12:32:28 -07:00
parent 87ee6980e6
commit c0b90bbe18
8 changed files with 62 additions and 4 deletions

View File

@@ -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);

View File

@@ -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());
}

View File

@@ -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; }

View 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;
}
}
}

View File

@@ -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" />

View File

@@ -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);

View File

@@ -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; }
}
}

View File

@@ -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>