mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding content filters
This commit is contained in:
@@ -22,6 +22,7 @@ using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.Localization.Services;
|
||||
|
||||
namespace Orchard.Core.Contents.Controllers {
|
||||
[ValidateInput(false)]
|
||||
@@ -30,6 +31,8 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
private readonly ITransactionManager _transactionManager;
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly ICultureManager _cultureManager;
|
||||
private readonly ICultureFilter _cultureFilter;
|
||||
|
||||
public AdminController(
|
||||
IOrchardServices orchardServices,
|
||||
@@ -37,12 +40,17 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
IContentDefinitionManager contentDefinitionManager,
|
||||
ITransactionManager transactionManager,
|
||||
ISiteService siteService,
|
||||
IShapeFactory shapeFactory) {
|
||||
IShapeFactory shapeFactory,
|
||||
ICultureManager cultureManager,
|
||||
ICultureFilter cultureFilter) {
|
||||
Services = orchardServices;
|
||||
_contentManager = contentManager;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
_transactionManager = transactionManager;
|
||||
_siteService = siteService;
|
||||
_cultureManager = cultureManager;
|
||||
_cultureFilter = cultureFilter;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
Shape = shapeFactory;
|
||||
@@ -100,11 +108,17 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!String.IsNullOrWhiteSpace(model.Options.SelectedCulture)) {
|
||||
query = _cultureFilter.FilterCulture(query, model.Options.SelectedCulture);
|
||||
}
|
||||
|
||||
model.Options.SelectedFilter = model.TypeName;
|
||||
model.Options.FilterOptions = GetListableTypes(false)
|
||||
.Select(ctd => new KeyValuePair<string, string>(ctd.Name, ctd.DisplayName))
|
||||
.ToList().OrderBy(kvp => kvp.Value);
|
||||
|
||||
model.Options.Cultures = _cultureManager.ListCultures();
|
||||
|
||||
var maxPagedCount = _siteService.GetSiteSettings().MaxPagedCount;
|
||||
var pagerShape = Shape.Pager(pager).TotalItemCount(maxPagedCount > 0 ? maxPagedCount : query.Count());
|
||||
var pageOfContentItems = query.Slice(pager.GetStartIndex(), pager.PageSize).ToList();
|
||||
@@ -140,6 +154,7 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
public ActionResult ListFilterPOST(ContentOptions options) {
|
||||
var routeValues = ControllerContext.RouteData.Values;
|
||||
if (options != null) {
|
||||
routeValues["Options.SelectedCulture"] = options.SelectedCulture; //todo: don't hard-code the key
|
||||
routeValues["Options.OrderBy"] = options.OrderBy; //todo: don't hard-code the key
|
||||
routeValues["Options.ContentsStatus"] = options.ContentsStatus; //todo: don't hard-code the key
|
||||
if (GetListableTypes(false).Any(ctd => string.Equals(ctd.Name, options.SelectedFilter, StringComparison.OrdinalIgnoreCase))) {
|
||||
|
||||
@@ -35,10 +35,12 @@ namespace Orchard.Core.Contents.ViewModels {
|
||||
ContentsStatus = ContentsStatus.Latest;
|
||||
}
|
||||
public string SelectedFilter { get; set; }
|
||||
public string SelectedCulture { get; set; }
|
||||
public IEnumerable<KeyValuePair<string, string>> FilterOptions { get; set; }
|
||||
public ContentsOrder OrderBy { get; set; }
|
||||
public ContentsStatus ContentsStatus { get; set; }
|
||||
public ContentsBulkAction BulkAction { get; set; }
|
||||
public IEnumerable<string> Cultures { get; set; }
|
||||
}
|
||||
|
||||
public enum ContentsOrder {
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
@Html.SelectOption((string)Model.Options.SelectedFilter, (string)filterOption.Key, (string)filterOption.Value)
|
||||
}
|
||||
</select>
|
||||
<label for="filterCultures" class="bulk-culture">@T("Culture")</label>
|
||||
<select id="filterCultures" name="Options.SelectedCulture">
|
||||
@Html.SelectOption((string)Model.Options.SelectedCulture, "", T("any (show all)").ToString())
|
||||
@foreach (string culture in Model.Options.Cultures) {
|
||||
@Html.SelectOption((string)Model.Options.SelectedCulture, culture, System.Globalization.CultureInfo.GetCultureInfo(culture).DisplayName)
|
||||
}
|
||||
</select>
|
||||
<label for="orderResults" class="bulk-order">@T("Ordered by")</label>
|
||||
<select id="orderResults" name="Options.OrderBy">
|
||||
@Html.SelectOption((ContentsOrder)Model.Options.OrderBy, ContentsOrder.Created, T("recently created").ToString())
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Providers\CultureSelectorSelector.cs" />
|
||||
<Compile Include="Services\AdminDirectionalityFactory.cs" />
|
||||
<Compile Include="Services\CultureSelectorFactory.cs" />
|
||||
<Compile Include="Services\LocalizationCultureFilter.cs" />
|
||||
<Compile Include="Services\DefaultCultureStorageProvider.cs" />
|
||||
<Compile Include="Services\ICultureService.cs" />
|
||||
<Compile Include="Drivers\LocalizationPartDriver.cs" />
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization.Models;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
[OrchardSuppressDependency("Orchard.Localization.Services.DefaultCultureFilter")]
|
||||
public class LocalizationCultureFilter : ICultureFilter {
|
||||
private readonly ICultureManager _cultureManager;
|
||||
|
||||
public LocalizationCultureFilter(ICultureManager cultureManager) {
|
||||
_cultureManager = cultureManager;
|
||||
}
|
||||
|
||||
public IContentQuery<ContentItem> FilterCulture(IContentQuery<ContentItem> query, string cultureName) {
|
||||
var culture = _cultureManager.GetCultureByName(cultureName);
|
||||
|
||||
if (culture != null) {
|
||||
return query.Where<LocalizationPartRecord>(x => x.CultureId == culture.Id);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using Orchard.Widgets.Models;
|
||||
using Orchard.Widgets.Services;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Contents.Settings;
|
||||
using Orchard.Localization.Services;
|
||||
|
||||
namespace Orchard.Widgets.Controllers {
|
||||
|
||||
@@ -27,18 +28,21 @@ namespace Orchard.Widgets.Controllers {
|
||||
private readonly IWidgetsService _widgetsService;
|
||||
private readonly ISiteThemeService _siteThemeService;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
private readonly ICultureManager _cultureManager;
|
||||
|
||||
public AdminController(
|
||||
IOrchardServices services,
|
||||
IWidgetsService widgetsService,
|
||||
IShapeFactory shapeFactory,
|
||||
ISiteThemeService siteThemeService,
|
||||
IVirtualPathProvider virtualPathProvider) {
|
||||
IVirtualPathProvider virtualPathProvider,
|
||||
ICultureManager cultureManager) {
|
||||
|
||||
Services = services;
|
||||
_widgetsService = widgetsService;
|
||||
_siteThemeService = siteThemeService;
|
||||
_virtualPathProvider = virtualPathProvider;
|
||||
_cultureManager = cultureManager;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -50,7 +54,7 @@ namespace Orchard.Widgets.Controllers {
|
||||
public ILogger Logger { get; set; }
|
||||
dynamic Shape { get; set; }
|
||||
|
||||
public ActionResult Index(int? layerId) {
|
||||
public ActionResult Index(int? layerId, string culture) {
|
||||
ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();
|
||||
if (currentTheme == null) {
|
||||
Services.Notifier.Error(T("To manage widgets you must have a theme enabled."));
|
||||
@@ -79,12 +83,26 @@ namespace Orchard.Widgets.Controllers {
|
||||
string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
|
||||
string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;
|
||||
|
||||
var widgets = _widgetsService.GetWidgets();
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(culture)) {
|
||||
widgets = widgets.Where(x => {
|
||||
if(x.Has<ILocalizableAspect>()) {
|
||||
return String.Equals(x.As<ILocalizableAspect>().Culture, culture, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
return false;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
var viewModel = Shape.ViewModel()
|
||||
.CurrentTheme(currentTheme)
|
||||
.CurrentLayer(currentLayer)
|
||||
.CurrentCulture(culture)
|
||||
.Layers(layers)
|
||||
.Widgets(_widgetsService.GetWidgets())
|
||||
.Widgets(widgets)
|
||||
.Zones(currentThemesZones)
|
||||
.Cultures(_cultureManager.ListCultures())
|
||||
.OrphanZones(allZones.Except(currentThemesZones))
|
||||
.OrphanWidgets(_widgetsService.GetOrphanedWidgets())
|
||||
.ZonePreviewImage(zonePreviewImage);
|
||||
|
||||
@@ -172,7 +172,7 @@
|
||||
<Content Include="Views\Admin\ChooseWidget.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\WidgetLayersControl.cshtml" />
|
||||
<Content Include="Views\WidgetFiltersControl.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\WidgetPlacement.cshtml" />
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
}
|
||||
@Display.WidgetPlacement_Orphans(OrphanWidgets: Model.OrphanWidgets)
|
||||
<div id="widgets" class="group">
|
||||
@Display.WidgetLayersControl(Layers: Model.Layers, CurrentLayer: Model.CurrentLayer)
|
||||
@Display.WidgetFiltersControl(Layers: Model.Layers, CurrentLayer: Model.CurrentLayer, Cultures: Model.Cultures, CurrentCulture: Model.CurrentCulture)
|
||||
<div id="layout-widgets-placement">
|
||||
@Display.WidgetPlacement(Widgets: Model.Widgets, Zones: Model.Zones, OrphanZones: Model.OrphanZones, CurrentLayer: Model.CurrentLayer)
|
||||
</div>
|
||||
|
||||
@@ -1,36 +1,52 @@
|
||||
@using Orchard.Utility.Extensions;
|
||||
@using Orchard.Widgets.Models;
|
||||
@{
|
||||
Style.Require("WidgetsAdmin");
|
||||
Script.Require("Switchable").AtFoot();
|
||||
Style.Require("Switchable");
|
||||
IEnumerable<LayerPart> layers = Model.Layers;
|
||||
var returnUrl = Request.RawUrl;
|
||||
}
|
||||
<div id="widgets-layers-control" class="widgets-container">
|
||||
@if (layers.Any()) {
|
||||
using (Html.BeginForm("index", "admin", FormMethod.Get, new {area = "Orchard.Widgets"})) {
|
||||
<fieldset class="bulk-actions-auto">
|
||||
<label for="layerId">@T("Current Layer:")</label>
|
||||
<select id="layerId" name="layerId">
|
||||
@foreach (var layer in layers) {
|
||||
@Html.SelectOption((int)Model.CurrentLayer.Id, (int)layer.Id, (string)layer.Name)
|
||||
}
|
||||
</select>
|
||||
<button type="submit" class="apply-bulk-actions-auto">@T("Show")</button>
|
||||
@Html.Link(T("Edit").Text, Url.Action("EditLayer", "Admin", new { area = "Orchard.Widgets", id = Model.CurrentLayer.Id, returnUrl }), new { @class = "button" })
|
||||
</fieldset>
|
||||
}
|
||||
}
|
||||
<div id="widgets-layer-add">
|
||||
@Html.Link(T("Add a new layer...").Text, Url.Action("AddLayer", "Admin", new { area = "Orchard.Widgets", returnUrl }))
|
||||
</div>
|
||||
|
||||
@if (!String.IsNullOrEmpty(Model.CurrentLayer.Description)) {
|
||||
<div>
|
||||
<span class="hint" id="widgets-layer-description">@Model.CurrentLayer.Description</span>
|
||||
<br />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@using Orchard.Utility.Extensions;
|
||||
@using Orchard.Widgets.Models;
|
||||
@{
|
||||
Style.Require("WidgetsAdmin");
|
||||
Script.Require("Switchable").AtFoot();
|
||||
Style.Require("Switchable");
|
||||
IEnumerable<LayerPart> layers = Model.Layers;
|
||||
IEnumerable<string> cultures = Model.Cultures;
|
||||
var returnUrl = Request.RawUrl;
|
||||
}
|
||||
<div id="widgets-layers-control" class="widgets-container">
|
||||
@if (layers.Any()) {
|
||||
using (Html.BeginForm("index", "admin", FormMethod.Get, new { area = "Orchard.Widgets" })) {
|
||||
<fieldset class="bulk-actions-auto">
|
||||
<label for="layerId">@T("Current Layer:")</label>
|
||||
<select id="layerId" name="layerId">
|
||||
@foreach (var layer in layers) {
|
||||
@Html.SelectOption((int)Model.CurrentLayer.Id, (int)layer.Id, (string)layer.Name)
|
||||
}
|
||||
</select>
|
||||
<button type="submit" class="apply-bulk-actions-auto">@T("Show")</button>
|
||||
@Html.Link(T("Edit").Text, Url.Action("EditLayer", "Admin", new { area = "Orchard.Widgets", id = Model.CurrentLayer.Id, returnUrl }), new { @class = "button" })
|
||||
</fieldset>
|
||||
}
|
||||
}
|
||||
<div id="widgets-layer-add">
|
||||
@Html.Link(T("Add a new layer...").Text, Url.Action("AddLayer", "Admin", new { area = "Orchard.Widgets", returnUrl }))
|
||||
</div>
|
||||
|
||||
|
||||
@using (Html.BeginForm("index", "admin", FormMethod.Get, new { area = "Orchard.Widgets" })) {
|
||||
<fieldset class="bulk-actions-auto">
|
||||
<label for="culture">@T("Current Culture:")</label>
|
||||
<select id="culture" name="culture">
|
||||
@Html.SelectOption((string)Model.CurrentCulture, "", T("any (show all)").ToString())
|
||||
@foreach (var culture in cultures) {
|
||||
@Html.SelectOption((string)Model.CurrentCulture, (string)culture, System.Globalization.CultureInfo.GetCultureInfo(culture).DisplayName)
|
||||
}
|
||||
</select>
|
||||
<button type="submit" class="apply-bulk-actions-auto">@T("Show")</button>
|
||||
</fieldset>
|
||||
}
|
||||
|
||||
|
||||
|
||||
@if (!String.IsNullOrEmpty(Model.CurrentLayer.Description)) {
|
||||
<div>
|
||||
<span class="hint" id="widgets-layer-description">@Model.CurrentLayer.Description</span>
|
||||
<br />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -623,6 +623,9 @@ legend span {
|
||||
label.bulk-order {
|
||||
text-transform:lowercase;
|
||||
}
|
||||
label.bulk-culture {
|
||||
text-transform:lowercase;
|
||||
}
|
||||
label span {
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
10
src/Orchard/Localization/Services/DefaultCultureFilter.cs
Normal file
10
src/Orchard/Localization/Services/DefaultCultureFilter.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
public class DefaultCultureFilter : ICultureFilter {
|
||||
public IContentQuery<ContentItem> FilterCulture(IContentQuery<ContentItem> query, string cultureName) {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Orchard/Localization/Services/ICultureFilter.cs
Normal file
8
src/Orchard/Localization/Services/ICultureFilter.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Localization.Services {
|
||||
public interface ICultureFilter : IDependency {
|
||||
IContentQuery<ContentItem> FilterCulture(IContentQuery<ContentItem> query, string cultureName);
|
||||
}
|
||||
}
|
||||
@@ -275,6 +275,8 @@
|
||||
<Compile Include="Localization\Services\DefaultLocalizedStringManager.cs" />
|
||||
<Compile Include="Localization\Services\ICalendarSelector.cs" />
|
||||
<Compile Include="Localization\Services\ICalendarManager.cs" />
|
||||
<Compile Include="Localization\Services\DefaultCultureFilter.cs" />
|
||||
<Compile Include="Localization\Services\ICultureFilter.cs" />
|
||||
<Compile Include="Localization\Services\IDateLocalizationServices.cs" />
|
||||
<Compile Include="Localization\Services\IDateFormatter.cs" />
|
||||
<Compile Include="Localization\Services\IDateTimeFormatProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user