--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-22 23:11:29 -07:00
11 changed files with 33 additions and 23 deletions

View File

@@ -0,0 +1,9 @@
using Orchard.ContentManagement.MetaData.Builders;
namespace Orchard.Core.Contents.Extensions {
public static class MetaDataExtensions {
public static ContentTypeDefinitionBuilder Creatable(this ContentTypeDefinitionBuilder builder, bool creatable = true) {
return builder.WithSetting("ContentTypeSettings.Creatable", creatable.ToString());
}
}
}

View File

@@ -81,6 +81,7 @@
<Compile Include="Common\ViewModels\TextContentFieldEditorViewModel.cs" />
<Compile Include="Contents\Controllers\ItemController.cs" />
<Compile Include="Contents\Drivers\ContentsDriver.cs" />
<Compile Include="Contents\Extensions\MetaDataExtensions.cs" />
<Compile Include="Contents\Handlers\ContentsHandler.cs" />
<Compile Include="Contents\Permissions.cs" />
<Compile Include="Contents\Routes.cs" />

View File

@@ -6,7 +6,7 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Common.Models;
using Orchard.Core.Common.Settings;
using Orchard.Core.Contents.Settings;
using Orchard.Core.Contents.Extensions;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Routable.Models;
using Orchard.Core.Settings.Descriptor.Records;
@@ -194,7 +194,7 @@ namespace Orchard.Setup.Services {
contentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg
.DisplayedAs("Blog Post")
.WithPart("CommentsPart")
.WithPart("HasTags")
.WithPart("TagsPart")
.WithPart("Localized")
.Creatable()
.Indexed());
@@ -205,7 +205,7 @@ namespace Orchard.Setup.Services {
.WithPart("IsRoutable")
.WithPart("BodyPart")
.WithPart("CommentsPart")
.WithPart("HasTags")
.WithPart("TagsPart")
.WithPart("Localized")
.Creatable()
.Indexed());

View File

@@ -25,7 +25,7 @@ namespace Orchard.Tags.DataMigrations {
return 1;
}
public int UpdateFrom1() {
ContentDefinitionManager.AlterPartDefinition(typeof(HasTags).Name, cfg => cfg
ContentDefinitionManager.AlterPartDefinition(typeof(TagsPart).Name, cfg => cfg
.WithLocation(new Dictionary<string, ContentLocation> {
{"Default", new ContentLocation { Zone = "primary", Position = "49" }},
{"Editor", new ContentLocation { Zone = "primary", Position = "9" }},

View File

@@ -11,11 +11,11 @@ using Orchard.Tags.ViewModels;
namespace Orchard.Tags.Drivers {
[UsedImplicitly]
public class HasTagsDriver : ContentPartDriver<HasTags> {
public class TagsPartDriver : ContentPartDriver<TagsPart> {
private readonly ITagService _tagService;
private readonly IAuthorizationService _authorizationService;
public HasTagsDriver(ITagService tagService,
public TagsPartDriver(ITagService tagService,
IAuthorizationService authorizationService) {
_tagService = tagService;
_authorizationService = authorizationService;
@@ -23,11 +23,11 @@ namespace Orchard.Tags.Drivers {
public virtual IUser CurrentUser { get; set; }
protected override DriverResult Display(HasTags part, string displayType) {
protected override DriverResult Display(TagsPart part, string displayType) {
return ContentPartTemplate(part, "Parts/Tags.ShowTags").Location(part.GetLocation(displayType));
}
protected override DriverResult Editor(HasTags part) {
protected override DriverResult Editor(TagsPart part) {
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, CurrentUser, part))
return null;
@@ -37,7 +37,7 @@ namespace Orchard.Tags.Drivers {
return ContentPartTemplate(model, "Parts/Tags.EditTags").Location(part.GetLocation("Editor"));
}
protected override DriverResult Editor(HasTags part, IUpdateModel updater) {
protected override DriverResult Editor(TagsPart part, IUpdateModel updater) {
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, CurrentUser, part))
return null;

View File

@@ -8,10 +8,10 @@ using Orchard.Tags.Models;
namespace Orchard.Tags.Handlers {
[UsedImplicitly]
public class HasTagsHandler : ContentHandler {
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) {
public class TagsPartHandler : ContentHandler {
public TagsPartHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) {
OnLoading<HasTags>((context, tags) => {
OnLoading<TagsPart>((context, tags) => {
// provide names of all tags on demand
tags._allTags.Loader(list => tagsRepository.Table.ToList());
@@ -28,11 +28,11 @@ namespace Orchard.Tags.Handlers {
});
OnRemoved<HasTags>((context, ht) => {
OnRemoved<TagsPart>((context, tags) => {
tagsContentItemsRepository.Flush();
HasTags tags = context.ContentItem.As<HasTags>();
foreach (var tag in tags.CurrentTags) {
TagsPart tagsPart = context.ContentItem.As<TagsPart>();
foreach (var tag in tagsPart.CurrentTags) {
if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) {
tagsRepository.Delete(tag);
}

View File

@@ -3,8 +3,8 @@ using Orchard.ContentManagement;
using Orchard.ContentManagement.Utilities;
namespace Orchard.Tags.Models {
public class HasTags : ContentPart {
public HasTags() {
public class TagsPart : ContentPart {
public TagsPart() {
AllTags = new List<Tag>();
CurrentTags = new List<Tag>();
}

View File

@@ -72,11 +72,11 @@
<Compile Include="Services\ITagService.cs" />
<Compile Include="ViewModels\EditTagsViewModel.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Drivers\HasTagsDriver.cs" />
<Compile Include="Drivers\TagsPartDriver.cs" />
<Compile Include="Helpers\TagHelpers.cs" />
<Compile Include="Models\HasTags.cs" />
<Compile Include="Models\TagsPart.cs" />
<Compile Include="Models\Tag.cs" />
<Compile Include="Handlers\HasTagsHandler.cs" />
<Compile Include="Handlers\TagsPartHandler.cs" />
<Compile Include="Permissions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Routes.cs" />

View File

@@ -1,4 +1,4 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<HasTags>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TagsPart>" %>
<%@ Import Namespace="Orchard.Tags.Models" %>
<% if (Model.CurrentTags.Count > 0) { %>
<p class="tags">

View File

@@ -1,4 +1,4 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<HasTags>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TagsPart>" %>
<%@ Import Namespace="Orchard.Tags.Models" %>
<% if (Model.CurrentTags.Count > 0) { %>
<p class="tags group">

View File

@@ -1,4 +1,4 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<HasTags>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TagsPart>" %>
<%@ Import Namespace="Orchard.Tags.Models" %>
<% if (Model.CurrentTags.Count > 0) { %>
<p class="tags group">