mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Refactoring Tags filter
--HG-- branch : 1.x
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
<Compile Include="Projections\TagsFilter.cs">
|
<Compile Include="Projections\TagsFilter.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Projections\TagsFilterForms.cs" />
|
||||||
<Compile Include="ResourceManifest.cs" />
|
<Compile Include="ResourceManifest.cs" />
|
||||||
<Compile Include="Services\ITagService.cs" />
|
<Compile Include="Services\ITagService.cs" />
|
||||||
<Compile Include="Services\XmlRpcHandler.cs" />
|
<Compile Include="Services\XmlRpcHandler.cs" />
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.DisplayManagement;
|
|
||||||
using Orchard.Environment.Extensions;
|
|
||||||
using Orchard.Events;
|
using Orchard.Events;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Tags.Models;
|
using Orchard.Tags.Models;
|
||||||
@@ -54,48 +51,4 @@ namespace Orchard.Tags.Projections {
|
|||||||
return T("Tagged with {0}", String.Join(", ", tagNames));
|
return T("Tagged with {0}", String.Join(", ", tagNames));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFormProvider : IEventHandler {
|
|
||||||
void Describe(dynamic context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TagsFilterForms : IFormProvider {
|
|
||||||
private readonly ITagService _tagService;
|
|
||||||
protected dynamic Shape { get; set; }
|
|
||||||
public Localizer T { get; set; }
|
|
||||||
|
|
||||||
public TagsFilterForms(
|
|
||||||
IShapeFactory shapeFactory,
|
|
||||||
ITagService tagService) {
|
|
||||||
_tagService = tagService;
|
|
||||||
Shape = shapeFactory;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Describe(dynamic context) {
|
|
||||||
Func<IShapeFactory, dynamic> form =
|
|
||||||
shape => {
|
|
||||||
|
|
||||||
var f = Shape.Form(
|
|
||||||
Id: "SelectTags",
|
|
||||||
_Tags: Shape.SelectList(
|
|
||||||
Id: "tagids", Name: "TagIds",
|
|
||||||
Title: T("Tags"),
|
|
||||||
Description: T("Select some tags."),
|
|
||||||
Size: 10,
|
|
||||||
Multiple: true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach (var tag in _tagService.GetTags()) {
|
|
||||||
f._Tags.Add(new SelectListItem { Value = tag.Id.ToString(), Text = tag.TagName });
|
|
||||||
}
|
|
||||||
|
|
||||||
return f;
|
|
||||||
};
|
|
||||||
|
|
||||||
context.Form("SelectTags", form);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
|
using Orchard.Events;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Tags.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Tags.Projections {
|
||||||
|
public interface IFormProvider : IEventHandler {
|
||||||
|
void Describe(dynamic context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TagsFilterForms : IFormProvider {
|
||||||
|
private readonly ITagService _tagService;
|
||||||
|
protected dynamic Shape { get; set; }
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public TagsFilterForms(
|
||||||
|
IShapeFactory shapeFactory,
|
||||||
|
ITagService tagService) {
|
||||||
|
_tagService = tagService;
|
||||||
|
Shape = shapeFactory;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Describe(dynamic context) {
|
||||||
|
Func<IShapeFactory, dynamic> form =
|
||||||
|
shape => {
|
||||||
|
|
||||||
|
var f = Shape.Form(
|
||||||
|
Id: "SelectTags",
|
||||||
|
_Tags: Shape.SelectList(
|
||||||
|
Id: "tagids", Name: "TagIds",
|
||||||
|
Title: T("Tags"),
|
||||||
|
Description: T("Select some tags."),
|
||||||
|
Size: 10,
|
||||||
|
Multiple: true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (var tag in _tagService.GetTags()) {
|
||||||
|
f._Tags.Add(new SelectListItem { Value = tag.Id.ToString(), Text = tag.TagName });
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Form("SelectTags", form);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user