Fixing feature name for RulesHandler

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-09-26 12:30:09 -07:00
parent e0aa1103be
commit d7c5127e96
5 changed files with 29 additions and 47 deletions

View File

@@ -7,16 +7,13 @@ using Orchard.Events;
namespace Orchard.Core.Contents.Handlers {
public interface IRulesManager : IEventHandler
{
public interface IRulesManager : IEventHandler {
void TriggerEvent(string category, string type, Func<Dictionary<string, object>> tokensContext);
}
[OrchardFeature("Orchard.Core.Contents.Rules")]
public class RulePartHandler : ContentHandler
{
public RulePartHandler(IRulesManager rulesManager)
{
[OrchardFeature("Contents.Rules")]
public class RulePartHandler : ContentHandler {
public RulePartHandler(IRulesManager rulesManager) {
OnPublished<ContentPart>(
(context, part) =>
@@ -26,7 +23,7 @@ namespace Orchard.Core.Contents.Handlers {
OnPublished<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Published",
() => new Dictionary<string, object> { { "Content", context.ContentItem } } ));
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
OnRemoved<ContentPart>(
(context, part) =>
@@ -35,7 +32,7 @@ namespace Orchard.Core.Contents.Handlers {
OnVersioned<ContentPart>(
(context, part1, part2) =>
rulesManager.TriggerEvent("Content", "Versioned",
rulesManager.TriggerEvent("Content", "Versioned",
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
OnCreated<ContentPart>(

View File

@@ -14,4 +14,4 @@ Features:
Name: Contents Rules
Description: Rules for the Contents modules
Category: Rules
Dependency: Rules
Dependency: Orchard.Rules, Contents

View File

@@ -5,58 +5,49 @@ using Orchard.Environment.Extensions;
using Orchard.Events;
using Orchard.Localization;
namespace Orchard.Core.Contents.Rules
{
public interface IEventProvider : IEventHandler
{
namespace Orchard.Core.Contents.Rules {
public interface IEventProvider : IEventHandler {
void Describe(dynamic describe);
}
[OrchardFeature("Contents.Rules")]
public class ContentEvents : IEventProvider
{
public class ContentEvents : IEventProvider {
public Localizer T { get; set; }
public void Describe(dynamic describe)
{
public void Describe(dynamic describe) {
Func<dynamic, bool> contentHasPart = ContentHasPart;
describe.For("Content", T("Content Items"), T("Content Items"))
.Element("Created", T("Content Created"), T("Content is actually created."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is created.", FormatPartsList(context))), "SelectContentTypes")
.Element("Versioned", T("Content Versioned"), T("Content is actually versioned."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is versioned.", FormatPartsList(context))), "SelectContentTypes")
.Element("Published", T("Content Published"), T("Content is actually published."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is published.", FormatPartsList(context))), "SelectContentTypes")
.Element("Removed", T("Content Removed"), T("Content is actually removed."), contentHasPart, (Func<dynamic, LocalizedString>) (context => T("When content with types ({0}) is removed.", FormatPartsList(context))), "SelectContentTypes");
.Element("Created", T("Content Created"), T("Content is actually created."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is created.", FormatPartsList(context))), "SelectContentTypes")
.Element("Versioned", T("Content Versioned"), T("Content is actually versioned."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is versioned.", FormatPartsList(context))), "SelectContentTypes")
.Element("Published", T("Content Published"), T("Content is actually published."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is published.", FormatPartsList(context))), "SelectContentTypes")
.Element("Removed", T("Content Removed"), T("Content is actually removed."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is removed.", FormatPartsList(context))), "SelectContentTypes");
}
private string FormatPartsList(dynamic context)
{
private string FormatPartsList(dynamic context) {
var contenttypes = context.Properties["contenttypes"];
if(String.IsNullOrEmpty(contenttypes))
{
if (String.IsNullOrEmpty(contenttypes)) {
return T("Any").Text;
}
return contenttypes;
}
private static bool ContentHasPart(dynamic context)
{
private static bool ContentHasPart(dynamic context) {
string contenttypes = context.Properties["contenttypes"];
var content = context.Tokens["Content"] as IContent;
// "" means 'any'
if(String.IsNullOrEmpty(contenttypes))
{
if (String.IsNullOrEmpty(contenttypes)) {
return true;
}
if(content == null)
{
if (content == null) {
return false;
}
var contentTypes = contenttypes.Split(new [] {','} );
var contentTypes = contenttypes.Split(new[] { ',' });
return contentTypes.Any(contentType => content.ContentItem.TypeDefinition.Name == contentType);
}

View File

@@ -6,31 +6,26 @@ using Orchard.Environment.Extensions;
using Orchard.Events;
using Orchard.Localization;
namespace Orchard.Core.Contents.Rules
{
public interface IFormProvider : IEventHandler
{
namespace Orchard.Core.Contents.Rules {
public interface IFormProvider : IEventHandler {
void Describe(dynamic context);
}
[OrchardFeature("Contents.Rules")]
public class ContentForms : IFormProvider
{
public class ContentForms : IFormProvider {
private readonly IContentDefinitionManager _contentDefinitionManager;
protected dynamic Shape { get; set; }
public Localizer T { get; set; }
public ContentForms(
IShapeFactory shapeFactory,
IContentDefinitionManager contentDefinitionManager)
{
IContentDefinitionManager contentDefinitionManager) {
_contentDefinitionManager = contentDefinitionManager;
Shape = shapeFactory;
}
public void Describe(dynamic context)
{
Func<IShapeFactory, dynamic> form =
public void Describe(dynamic context) {
Func<IShapeFactory, dynamic> form =
shape => {
var f = Shape.Form(
@@ -46,8 +41,7 @@ namespace Orchard.Core.Contents.Rules
f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text });
foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions())
{
foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions()) {
f._Parts.Add(new SelectListItem { Value = contentType.Name, Text = contentType.DisplayName });
}

View File

@@ -15,4 +15,4 @@ Features:
Name: Comments Rules
Description: Rules for the Comments modules
Category: Rules
Dependency: Rules
Dependency: Orchard.Comments, Orchard.Rules