mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added Lists projection filter and sort criterion provider.
This commit is contained in:
committed by
Sebastien Ros
parent
5da0177c68
commit
129133f6ba
@@ -104,11 +104,11 @@
|
||||
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
||||
<Compile Include="Containers\Drivers\ContainerWidgetPartDriver.cs" />
|
||||
<Compile Include="Containers\Extensions\ContentDefinitionManagerExtensions.cs" />
|
||||
<Compile Include="Containers\Handlers\ContainerWidgetPartHandler.cs" />
|
||||
<Compile Include="Containers\Drivers\CustomPropertiesDriver.cs" />
|
||||
<Compile Include="Containers\Extensions\ContentQueryExtensions.cs" />
|
||||
<Compile Include="Containers\Handlers\ContainablePartHandler.cs" />
|
||||
<Compile Include="Containers\Handlers\ContainerPartHandler.cs" />
|
||||
<Compile Include="Containers\Handlers\ContainerWidgetPartHandler.cs" />
|
||||
<Compile Include="Containers\Migrations.cs" />
|
||||
<Compile Include="Containers\Models\ContainablePart.cs" />
|
||||
<Compile Include="Containers\Models\ContainerPart.cs" />
|
||||
@@ -123,9 +123,9 @@
|
||||
<Compile Include="Containers\Settings\ContainerSettings.cs" />
|
||||
<Compile Include="Containers\Settings\ContainableSettings.cs" />
|
||||
<Compile Include="Containers\ViewModels\ContainableViewModel.cs" />
|
||||
<Compile Include="Containers\ViewModels\ContainerWidgetViewModel.cs" />
|
||||
<Compile Include="Containers\ViewModels\ContainerViewModel.cs" />
|
||||
<Compile Include="Containers\ViewModels\ContainerTypePartSettingsViewModel.cs" />
|
||||
<Compile Include="Containers\ViewModels\ContainerWidgetViewModel.cs" />
|
||||
<Compile Include="Contents\ControlWrapper.cs" />
|
||||
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
|
||||
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
||||
@@ -398,12 +398,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="Containers\Placement.info" />
|
||||
<Content Include="Containers\Views\EditorTemplates\ContainerWidget.cshtml" />
|
||||
<Content Include="Containers\Views\EditorTemplates\Container.cshtml" />
|
||||
<Content Include="Containers\Views\DefinitionTemplates\ContainerPartSettings.cshtml" />
|
||||
<Content Include="Containers\Views\DefinitionTemplates\ContainerTypePartSettingsViewModel.cshtml" />
|
||||
<Content Include="Containers\Views\EditorTemplates\Containable.cshtml" />
|
||||
<Content Include="Containers\Views\Parts.ContainerWidget.cshtml" />
|
||||
<Content Include="Containers\Views\EditorTemplates\CustomProperties.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -556,6 +554,10 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Styles\Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Containers\Views\EditorTemplates\ContainerWidget.cshtml" />
|
||||
<Content Include="Containers\Views\Parts.ContainerWidget.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Containers.Models;
|
||||
using Orchard.Core.Containers.Services;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Lists.Services;
|
||||
|
||||
namespace Orchard.Lists.Forms {
|
||||
public class ListFilterForm : Component, IFormProvider {
|
||||
private readonly IContainerService _containerService;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public ListFilterForm(IShapeFactory shapeFactory, IContainerService containerService, IContentManager contentManager) {
|
||||
_containerService = containerService;
|
||||
_contentManager = contentManager;
|
||||
New = shapeFactory;
|
||||
}
|
||||
protected dynamic New { get; set; }
|
||||
|
||||
public void Describe(dynamic context) {
|
||||
Func<IShapeFactory, object> form =
|
||||
shape => {
|
||||
var f = New.Form(
|
||||
Id: "List",
|
||||
_Lists: New.SelectList(
|
||||
Id: "listId", Name: "ListId",
|
||||
Title: T("List"),
|
||||
Description: T("Select a list."),
|
||||
Multiple: false));
|
||||
|
||||
foreach (var list in _containerService.GetContainers(VersionOptions.Latest).OrderBy(GetListName)) {
|
||||
f._Lists.Add(new SelectListItem {Value = list.Id.ToString(CultureInfo.InvariantCulture), Text = GetListName(list)});
|
||||
}
|
||||
|
||||
return f;
|
||||
};
|
||||
|
||||
context.Form("ListFilter", form);
|
||||
}
|
||||
|
||||
private string GetListName(ContainerPart containerPart) {
|
||||
return _contentManager.GetItemMetadata(containerPart).DisplayText;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,10 +66,15 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Drivers\ContainerPartDriver.cs" />
|
||||
<Compile Include="Drivers\ContainablePartDriver.cs" />
|
||||
<Compile Include="Projections\ListSortCriteria.cs" />
|
||||
<Compile Include="Services\IFormProvider.cs" />
|
||||
<Compile Include="Forms\ListFilterForm.cs" />
|
||||
<Compile Include="Handlers\ContainerPartHandler.cs" />
|
||||
<Compile Include="Helpers\StringExtensions.cs" />
|
||||
<Compile Include="ListViews\CondensedListView.cs" />
|
||||
<Compile Include="ListViews\DefaultListView.cs" />
|
||||
<Compile Include="Services\IFilterProvider.cs" />
|
||||
<Compile Include="Projections\ListFilter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Routes.cs" />
|
||||
<Content Include="Scripts\common-admin.js" />
|
||||
@@ -89,6 +94,7 @@
|
||||
<Content Include="Styles\nprogress.css" />
|
||||
<Content Include="Scripts\nprogress.js" />
|
||||
<Content Include="Scripts\orchard-lists-admin.js" />
|
||||
<Compile Include="Services\ISortCriterionProvider.cs" />
|
||||
<Compile Include="Shapes.cs" />
|
||||
<Compile Include="ViewModels\ListContentsViewModel.cs" />
|
||||
<Content Include="Module.txt" />
|
||||
@@ -193,9 +199,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Content.SummaryAdminCondensed.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Content Include="Views\ListViewButtons.cshtml" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Containers.Models;
|
||||
using Orchard.Lists.Services;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Lists.Projections {
|
||||
public class ListFilter : Component, IFilterProvider {
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public ListFilter(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public void Describe(dynamic describe) {
|
||||
describe.For("Lists", T("Lists"), T("Lists"))
|
||||
.Element("List", T("List"), T("Specific list"),
|
||||
(Action<dynamic>)ApplyFilter,
|
||||
(Func<dynamic, LocalizedString>)DisplayFilter,
|
||||
"ListFilter"
|
||||
);
|
||||
}
|
||||
|
||||
public void ApplyFilter(dynamic context) {
|
||||
var selectedList = (string)context.State.ListId;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(selectedList))
|
||||
return;
|
||||
|
||||
var query = (IHqlQuery)context.Query;
|
||||
var listId = Int32.Parse(selectedList);
|
||||
context.Query = query.Where(alias => alias.ContentPartRecord<CommonPartRecord>(), item => item.Eq("Container", listId));
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(dynamic context) {
|
||||
var selectedList = (string)context.State.ListId;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(selectedList))
|
||||
return T("No list was selected");
|
||||
|
||||
var listId = Int32.Parse(selectedList);
|
||||
var list = _contentManager.Get<ContainerPart>(listId, VersionOptions.Latest, QueryHints.Empty);
|
||||
var listName = _contentManager.GetItemMetadata(list).DisplayText;
|
||||
return T("Show items from the following list: {0}", listName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Containers.Models;
|
||||
using Orchard.Lists.Services;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Lists.Projections {
|
||||
public class ListSortCriteria : Component, ISortCriterionProvider {
|
||||
|
||||
public void Describe(dynamic describe) {
|
||||
describe.For("List", new LocalizedString("List"), T("List item position"))
|
||||
.Element("Position", T("Position"), T("Sorts the results by position"),
|
||||
(Action<dynamic>)ApplySortCriterion,
|
||||
(Func<dynamic, LocalizedString>)DisplaySortCriterion,
|
||||
"SortOrder"
|
||||
);
|
||||
}
|
||||
|
||||
public void ApplySortCriterion(dynamic context) {
|
||||
bool ascending = Boolean.Parse(Convert.ToString(context.State.Sort));
|
||||
var query = (IHqlQuery)context.Query;
|
||||
query = ascending
|
||||
? query.OrderBy(alias => alias.ContentPartRecord<ContainablePartRecord>(), x => x.Asc("Position"))
|
||||
: query.OrderBy(alias => alias.ContentPartRecord<ContainablePartRecord>(), x => x.Desc("Position"));
|
||||
|
||||
context.Query = query;
|
||||
}
|
||||
|
||||
public LocalizedString DisplaySortCriterion(dynamic context) {
|
||||
bool ascending = Boolean.Parse(Convert.ToString(context.State.Sort));
|
||||
return T(@ascending ? "Ordered by {0}, ascending" : "Ordered by {0}, descending", T("Position"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Lists.Services {
|
||||
public interface IFilterProvider : IEventHandler {
|
||||
void Describe(dynamic describe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Lists.Services {
|
||||
public interface IFormProvider : IEventHandler {
|
||||
void Describe(dynamic context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Lists.Services {
|
||||
public interface ISortCriterionProvider : IEventHandler {
|
||||
void Describe(dynamic describe);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user