mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
Refactoring Rules features
--HG-- branch : 1.x
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
4d1cc7eaae172f400159e64a747fac69d9608aa8 src/Orchard.Web/Modules/Orchard.Forms
|
30c41b905ee07be02fe134f72c7a2449d85d71b3 src/Orchard.Web/Modules/Orchard.Forms
|
||||||
19fadd2cddbac89051c0e6fa0c8f6a2bc8d67b24 src/Orchard.Web/Modules/Orchard.Rules
|
bdfbf617bbd125d3e76689fba17999c76b4b8ac0 src/Orchard.Web/Modules/Orchard.Rules
|
||||||
7b7a9141401137d855a5a33d1652aa51a5636bd8 src/Orchard.Web/Modules/Orchard.Tokens
|
6093698fc61157076a8c26653a07e27da5280cfd src/Orchard.Web/Modules/Orchard.Tokens
|
||||||
|
48
src/Orchard.Web/Core/Contents/Handlers/RulesHandler.cs
Normal file
48
src/Orchard.Web/Core/Contents/Handlers/RulesHandler.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Contents.Handlers {
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
OnPublished<ContentPart>(
|
||||||
|
(context, part) =>
|
||||||
|
rulesManager.TriggerEvent("Content", "Published",
|
||||||
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
||||||
|
|
||||||
|
OnPublished<ContentPart>(
|
||||||
|
(context, part) =>
|
||||||
|
rulesManager.TriggerEvent("Content", "Published",
|
||||||
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } } ));
|
||||||
|
|
||||||
|
OnRemoved<ContentPart>(
|
||||||
|
(context, part) =>
|
||||||
|
rulesManager.TriggerEvent("Content", "Removed",
|
||||||
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
||||||
|
|
||||||
|
OnVersioned<ContentPart>(
|
||||||
|
(context, part1, part2) =>
|
||||||
|
rulesManager.TriggerEvent("Content", "Versioned",
|
||||||
|
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
|
||||||
|
|
||||||
|
OnCreated<ContentPart>(
|
||||||
|
(context, part) =>
|
||||||
|
rulesManager.TriggerEvent("Content", "Created",
|
||||||
|
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -5,5 +5,13 @@ Website: http://orchardproject.net
|
|||||||
Version: 1.2.0
|
Version: 1.2.0
|
||||||
OrchardVersion: 1.2.0
|
OrchardVersion: 1.2.0
|
||||||
Description: The contents module enables the creation of custom content types.
|
Description: The contents module enables the creation of custom content types.
|
||||||
FeatureDescription: Default custom content type definition, creation and management.
|
Features:
|
||||||
Category: Core
|
Orchard.Core.Contents
|
||||||
|
Name: Contents
|
||||||
|
Description: Default custom content type definition, creation and management.
|
||||||
|
Category: Core
|
||||||
|
Orchard.Core.Contents.Rules:
|
||||||
|
Name: Contents Rules
|
||||||
|
Description: Rules for the Contents modules
|
||||||
|
Category: Rules
|
||||||
|
Dependency: Rules
|
||||||
|
64
src/Orchard.Web/Core/Contents/Rules/ContentEvents.cs
Normal file
64
src/Orchard.Web/Core/Contents/Rules/ContentEvents.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Contents.Rules
|
||||||
|
{
|
||||||
|
public interface IEventProvider : IEventHandler
|
||||||
|
{
|
||||||
|
void Describe(dynamic describe);
|
||||||
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Core.Contents.Rules")]
|
||||||
|
public class ContentEvents : IEventProvider
|
||||||
|
{
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FormatPartsList(dynamic context)
|
||||||
|
{
|
||||||
|
var contenttypes = context.Properties["contenttypes"];
|
||||||
|
|
||||||
|
if(String.IsNullOrEmpty(contenttypes))
|
||||||
|
{
|
||||||
|
return T("Any").Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return contenttypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool ContentHasPart(dynamic context)
|
||||||
|
{
|
||||||
|
string contenttypes = context.Properties["contenttypes"];
|
||||||
|
var content = context.Tokens["Content"] as IContent;
|
||||||
|
|
||||||
|
// "" means 'any'
|
||||||
|
if(String.IsNullOrEmpty(contenttypes))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(content == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var contentTypes = contenttypes.Split(new [] {','} );
|
||||||
|
|
||||||
|
return contentTypes.Any(contentType => content.ContentItem.TypeDefinition.Name == contentType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
src/Orchard.Web/Core/Contents/Rules/ContentForms.cs
Normal file
61
src/Orchard.Web/Core/Contents/Rules/ContentForms.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Contents.Rules
|
||||||
|
{
|
||||||
|
public interface IFormProvider : IEventHandler
|
||||||
|
{
|
||||||
|
void Describe(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
[OrchardFeature("Orchard.Core.Contents.Rules")]
|
||||||
|
public class ContentForms : IFormProvider
|
||||||
|
{
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public ContentForms(
|
||||||
|
IShapeFactory shapeFactory,
|
||||||
|
IContentDefinitionManager contentDefinitionManager)
|
||||||
|
{
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
|
Shape = shapeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Describe(dynamic context)
|
||||||
|
{
|
||||||
|
Func<IShapeFactory, dynamic> form =
|
||||||
|
shape => {
|
||||||
|
|
||||||
|
var f = Shape.Form(
|
||||||
|
Id: "AnyOfContentTypes",
|
||||||
|
_Parts: Shape.SelectList(
|
||||||
|
Id: "contenttypes", Name: "contenttypes",
|
||||||
|
Title: T("Content types"),
|
||||||
|
Description: T("Select some content types."),
|
||||||
|
Size: 10,
|
||||||
|
Multiple: true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text });
|
||||||
|
|
||||||
|
foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions())
|
||||||
|
{
|
||||||
|
f._Parts.Add(new SelectListItem { Value = contentType.Name, Text = contentType.DisplayName });
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Form("SelectContentTypes", form);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -103,6 +103,9 @@
|
|||||||
<Compile Include="Containers\ViewModels\ContainableViewModel.cs" />
|
<Compile Include="Containers\ViewModels\ContainableViewModel.cs" />
|
||||||
<Compile Include="Containers\ViewModels\ContainerWidgetViewModel.cs" />
|
<Compile Include="Containers\ViewModels\ContainerWidgetViewModel.cs" />
|
||||||
<Compile Include="Containers\ViewModels\ContainerViewModel.cs" />
|
<Compile Include="Containers\ViewModels\ContainerViewModel.cs" />
|
||||||
|
<Compile Include="Contents\Handlers\RulesHandler.cs" />
|
||||||
|
<Compile Include="Contents\Rules\ContentEvents.cs" />
|
||||||
|
<Compile Include="Contents\Rules\ContentForms.cs" />
|
||||||
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
|
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
|
||||||
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
||||||
<Compile Include="Common\Services\ICommonService.cs" />
|
<Compile Include="Common\Services\ICommonService.cs" />
|
||||||
|
@@ -14,5 +14,5 @@ Features:
|
|||||||
Orchard.Comments.Rules:
|
Orchard.Comments.Rules:
|
||||||
Name: Comments Rules
|
Name: Comments Rules
|
||||||
Description: Rules for the Comments modules
|
Description: Rules for the Comments modules
|
||||||
Dependencies: Orchard.Rules, Orchard.Forms
|
|
||||||
Category: Rules
|
Category: Rules
|
||||||
|
Dependency: Rules
|
@@ -117,14 +117,6 @@
|
|||||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||||
<Name>Orchard.Core</Name>
|
<Name>Orchard.Core</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Orchard.Forms\Orchard.Forms.csproj">
|
|
||||||
<Project>{642A49D7-8752-4177-80D6-BFBBCFAD3DE0}</Project>
|
|
||||||
<Name>Orchard.Forms</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\Orchard.Rules\Orchard.Rules.csproj">
|
|
||||||
<Project>{966EC390-3C7F-4D98-92A6-F0F30D02E9B1}</Project>
|
|
||||||
<Name>Orchard.Rules</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Admin\Edit.cshtml" />
|
<Content Include="Views\Admin\Edit.cshtml" />
|
||||||
|
@@ -32,3 +32,4 @@ using System.Security;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.2.0")]
|
[assembly: AssemblyVersion("1.2.0")]
|
||||||
[assembly: AssemblyFileVersion("1.2.0")]
|
[assembly: AssemblyFileVersion("1.2.0")]
|
||||||
|
[assembly:SecurityTransparent]
|
@@ -1,13 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using Orchard.Comments.Models;
|
using Orchard.Comments.Models;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Rules.Models;
|
using Orchard.Events;
|
||||||
using Orchard.Rules.Services;
|
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Comments.Rules
|
namespace Orchard.Comments.Rules
|
||||||
{
|
{
|
||||||
|
public interface IActionProvider : IEventHandler
|
||||||
|
{
|
||||||
|
void Describe(dynamic describe);
|
||||||
|
}
|
||||||
|
|
||||||
[OrchardFeature("Orchard.Comments.Rules")]
|
[OrchardFeature("Orchard.Comments.Rules")]
|
||||||
public class CommentsActions : IActionProvider
|
public class CommentsActions : IActionProvider
|
||||||
{
|
{
|
||||||
@@ -20,13 +24,18 @@ namespace Orchard.Comments.Rules
|
|||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public void Describe(DescribeActionContext context)
|
public void Describe(dynamic describe)
|
||||||
{
|
{
|
||||||
context.For("Comments", T("Comments"), T("Comments"))
|
Func<dynamic, LocalizedString> display = context => T("Close comments");
|
||||||
.Element("Close", T("Close Comments"), T("Closes comments on a content item."), Close, actionContext => T("Close comments"), "ActionCloseComments");
|
|
||||||
|
describe.For("Comments", T("Comments"), T("Comments"))
|
||||||
|
.Element("Close", T("Close Comments"), T("Closes comments on a content item."), (Action<dynamic>) Close, display, "ActionCloseComments");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Close(ActionContext context)
|
/// <summary>
|
||||||
|
/// Closes the comments on the content represented by "ContentId"
|
||||||
|
/// </summary>
|
||||||
|
private void Close(dynamic context)
|
||||||
{
|
{
|
||||||
var contentId = Convert.ToInt32(context.Properties["ContentId"]);
|
var contentId = Convert.ToInt32(context.Properties["ContentId"]);
|
||||||
var content = _contentManager.Get(contentId);
|
var content = _contentManager.Get(contentId);
|
||||||
|
@@ -1,10 +1,16 @@
|
|||||||
using Orchard.DisplayManagement;
|
using System;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Forms.Services;
|
using Orchard.Events;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Comments.Rules
|
namespace Orchard.Comments.Rules
|
||||||
{
|
{
|
||||||
|
public interface IFormProvider : IEventHandler
|
||||||
|
{
|
||||||
|
void Describe(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
[OrchardFeature("Orchard.Comments.Rules")]
|
[OrchardFeature("Orchard.Comments.Rules")]
|
||||||
public class CommentsForms : IFormProvider
|
public class CommentsForms : IFormProvider
|
||||||
{
|
{
|
||||||
@@ -16,17 +22,19 @@ namespace Orchard.Comments.Rules
|
|||||||
Shape = shapeFactory;
|
Shape = shapeFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Describe(DescribeContext context)
|
public void Describe(dynamic context)
|
||||||
{
|
{
|
||||||
context.Form("ActionCloseComments",
|
|
||||||
|
Func<IShapeFactory, dynamic> form =
|
||||||
shape => Shape.Form(
|
shape => Shape.Form(
|
||||||
Id: "ActionCloseComments",
|
Id: "ActionCloseComments",
|
||||||
_Type: Shape.Textbox(
|
_Type: Shape.Textbox(
|
||||||
Id: "ContentId", Name: "ContentId",
|
Id: "ContentId", Name: "ContentId",
|
||||||
Title: T("Content Item Id"),
|
Title: T("Content Item Id"),
|
||||||
Description: T("Content Item Id."))
|
Description: T("Content Item Id."))
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
context.Form("ActionCloseComments", form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user