From a2e59ac08acc9b2e6fae805b93c8dd1a55fbf5c7 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Fri, 12 Nov 2010 15:35:58 -0800 Subject: [PATCH 1/2] Wrapping up the initial implementation of the Container Widget --HG-- branch : dev --- .../Drivers/ContainerCustomPartDriver.cs | 30 +++++++ .../Drivers/ContainerWidgetPartDriver.cs | 43 ++++++++-- .../Extensions/ContentQueryExtensions.cs | 86 +++++++++++++++++++ src/Orchard.Web/Core/Containers/Migrations.cs | 21 ++++- .../Containers/Models/ContainerCustomPart.cs | 13 +++ .../Containers/Models/ContainerWidgetPart.cs | 8 +- .../Core/Containers/Placement.info | 2 + .../ViewModels/ContainerWidgetViewModel.cs | 10 +++ .../Views/EditorTemplates/Container.cshtml | 6 +- .../EditorTemplates/ContainerCustom.cshtml | 13 +++ .../EditorTemplates/ContainerWidget.cshtml | 69 ++++++++++----- .../Views/Parts/ContainerWidget.cshtml | 1 + src/Orchard.Web/Core/Orchard.Core.csproj | 6 ++ .../Views/Admin/EditWidget.cshtml | 1 - .../Parts/Widgets.WidgetPart.cshtml | 14 ++- 15 files changed, 280 insertions(+), 43 deletions(-) create mode 100644 src/Orchard.Web/Core/Containers/Drivers/ContainerCustomPartDriver.cs create mode 100644 src/Orchard.Web/Core/Containers/Extensions/ContentQueryExtensions.cs create mode 100644 src/Orchard.Web/Core/Containers/Models/ContainerCustomPart.cs create mode 100644 src/Orchard.Web/Core/Containers/ViewModels/ContainerWidgetViewModel.cs create mode 100644 src/Orchard.Web/Core/Containers/Views/EditorTemplates/ContainerCustom.cshtml create mode 100644 src/Orchard.Web/Core/Containers/Views/Parts/ContainerWidget.cshtml diff --git a/src/Orchard.Web/Core/Containers/Drivers/ContainerCustomPartDriver.cs b/src/Orchard.Web/Core/Containers/Drivers/ContainerCustomPartDriver.cs new file mode 100644 index 000000000..fb2ac6767 --- /dev/null +++ b/src/Orchard.Web/Core/Containers/Drivers/ContainerCustomPartDriver.cs @@ -0,0 +1,30 @@ +using Orchard.ContentManagement; +using Orchard.ContentManagement.Drivers; +using Orchard.ContentManagement.Handlers; +using Orchard.Core.Containers.Models; +using Orchard.Data; + +namespace Orchard.Core.Containers.Drivers { + public class ContainerCustomPartDriver : ContentPartDriver { + protected override DriverResult Editor(ContainerCustomPart part, dynamic shapeHelper) { + return Editor(part, null, shapeHelper); + } + + protected override DriverResult Editor(ContainerCustomPart part, IUpdateModel updater, dynamic shapeHelper) { + return ContentShape( + "Parts_ContainerCustom_Edit", + () => { + if (updater != null) + updater.TryUpdateModel(part, "ContainerCustom", null, null); + + return shapeHelper.EditorTemplate(TemplateName: "ContainerCustom", Model: part, Prefix: "ContainerCustom"); + }); + } + } + + public class ContainerCustomPartHandler : ContentHandler { + public ContainerCustomPartHandler(IRepository repository) { + Filters.Add(StorageFilter.For(repository)); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Containers/Drivers/ContainerWidgetPartDriver.cs b/src/Orchard.Web/Core/Containers/Drivers/ContainerWidgetPartDriver.cs index 6a5f5c805..d02f5f33a 100644 --- a/src/Orchard.Web/Core/Containers/Drivers/ContainerWidgetPartDriver.cs +++ b/src/Orchard.Web/Core/Containers/Drivers/ContainerWidgetPartDriver.cs @@ -6,7 +6,9 @@ using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Handlers; using Orchard.Core.Common.Models; +using Orchard.Core.Containers.Extensions; using Orchard.Core.Containers.Models; +using Orchard.Core.Containers.ViewModels; using Orchard.Data; using Orchard.Localization; @@ -21,6 +23,31 @@ namespace Orchard.Core.Containers.Drivers { public Localizer T { get; set; } + protected override DriverResult Display(ContainerWidgetPart part, string displayType, dynamic shapeHelper) { + return ContentShape( + "Parts_ContainerWidget", + () => { + var container = _contentManager.Get(part.Record.ContainerId); + + IContentQuery query = _contentManager + .Query(VersionOptions.Published) + .Join().Where(cr => cr.Container.Id == container.Id); + + var descendingOrder = part.Record.OrderByDirection == (int)OrderByDirection.Descending; + query = query.OrderBy(part.Record.OrderByProperty, descendingOrder); + + if (part.Record.ApplyFilter) + query = query.Where(part.Record.FilterByProperty, part.Record.FilterByOperator, part.Record.FilterByValue); + + var pageOfItems = query.Slice(0, part.Record.PageSize).ToList(); + + var list = shapeHelper.List(); + list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary"))); + + return shapeHelper.Parts_ContainerWidget(ContentItems: list); + }); + } + protected override DriverResult Editor(ContainerWidgetPart part, dynamic shapeHelper) { return Editor(part, null, shapeHelper); } @@ -29,22 +56,24 @@ namespace Orchard.Core.Containers.Drivers { return ContentShape( "Parts_ContainerWidget_Edit", () => { - if (updater != null) - updater.TryUpdateModel(part, "ContainerSelector", null, null); + var model = new ContainerWidgetViewModel {Part = part}; + + if (updater != null) { + updater.TryUpdateModel(model, "ContainerWidget", null, null); + } var containers = _contentManager.Query(VersionOptions.Latest).List(); - var listItems = containers.Count() < 1 ? new[] {new SelectListItem {Text = T("(None - create container enabled items first)").Text, Value = "0"}} : containers.Select(x => new SelectListItem { Value = Convert.ToString(x.Id), Text = x.ContentItem.TypeDefinition.DisplayName + ": " + x.As().Title, - Selected = x.Id == part.Record.ContainerId, + Selected = x.Id == model.Part.Record.ContainerId, }); - part.AvailableContainers = new SelectList(listItems, "Value", "Text", part.Record.ContainerId); + model.AvailableContainers = new SelectList(listItems, "Value", "Text", model.Part.Record.ContainerId); - return shapeHelper.EditorTemplate(TemplateName: "ContainerWidget", Model: part, Prefix: "ContainerWidget"); + return shapeHelper.EditorTemplate(TemplateName: "ContainerWidget", Model: model, Prefix: "ContainerWidget"); }); } } @@ -57,6 +86,8 @@ namespace Orchard.Core.Containers.Drivers { part.Record.PageSize = 5; part.Record.OrderByProperty = part.Is() ? "CommonPart.PublishedUtc" : ""; part.Record.OrderByDirection = (int)OrderByDirection.Descending; + part.Record.FilterByProperty = "ContainerCustomPart.CustomOne"; + part.Record.FilterByOperator = "="; }); } } diff --git a/src/Orchard.Web/Core/Containers/Extensions/ContentQueryExtensions.cs b/src/Orchard.Web/Core/Containers/Extensions/ContentQueryExtensions.cs new file mode 100644 index 000000000..d11e033ce --- /dev/null +++ b/src/Orchard.Web/Core/Containers/Extensions/ContentQueryExtensions.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using Orchard.ContentManagement; +using Orchard.Core.Common.Models; +using Orchard.Core.Containers.Models; +using Orchard.Core.Routable.Models; + +namespace Orchard.Core.Containers.Extensions +{ + public static class ContentQueryExtensions { + public static IContentQuery OrderBy(this IContentQuery query, string partAndProperty, bool descendingOrder) where T : IContent { + //todo: (heskew) order by custom part properties + switch (partAndProperty) { + case "RoutePart.Title": + query = descendingOrder + ? query.OrderByDescending(record => record.Title) + : query.OrderBy(record => record.Title); + break; + case "RoutePart.Slug": + query = descendingOrder + ? query.OrderByDescending(record => record.Slug) + : query.OrderBy(record => record.Slug); + break; + case "ContainerCustomPart.CustomOne": + query = descendingOrder + ? query.OrderByDescending(record => record.CustomOne) + : query.OrderBy(record => record.CustomOne); + break; + case "ContainerCustomPart.CustomTwo": + query = descendingOrder + ? query.OrderByDescending(record => record.CustomTwo) + : query.OrderBy(record => record.CustomTwo); + break; + case "ContainerCustomPart.CustomThree": + query = descendingOrder + ? query.OrderByDescending(record => record.CustomThree) + : query.OrderBy(record => record.CustomThree); + break; + default: // "CommonPart.PublishedUtc" + query = descendingOrder + ? query.OrderByDescending(record => record.PublishedUtc) + : query.OrderBy(record => record.PublishedUtc); + break; + } + + return query; + } + + public static IContentQuery Where(this IContentQuery query, string partAndProperty, string comparisonOperator, string comparisonValue) { + var filterKey = string.Format("{0}|{1}", partAndProperty, comparisonOperator); + if (!_filters.ContainsKey(filterKey)) + return query; + + return _filters[filterKey](query, comparisonValue); + } + + // convoluted: yes; quick and works for now: yes; technical debt: not much + private static readonly Dictionary, string, IContentQuery>> _filters = new Dictionary, string, IContentQuery>> { + {"RoutePart.Title|<", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.Title.CompareTo(s) == -1*/))}, + {"RoutePart.Title|>", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.Title.CompareTo(s) == 1*/))}, + {"RoutePart.Title|=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.Title.Equals(s, StringComparison.OrdinalIgnoreCase)))}, + {"RoutePart.Title|^=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.Title.StartsWith(s, StringComparison.OrdinalIgnoreCase)))}, + {"RoutePart.Slug|<", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.Slug.CompareTo(s) == -1*/))}, + {"RoutePart.Slug|>", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.Slug.CompareTo(s) == 1*/))}, + {"RoutePart.Slug|=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.Slug.Equals(s.Trim(), StringComparison.OrdinalIgnoreCase)))}, + {"RoutePart.Slug|^=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.Slug.StartsWith(s, StringComparison.OrdinalIgnoreCase)))}, + {"CommonPart.PublishedUtc|<", new Func, string, IContentQuery>((q, s) => q.Where(r => r.PublishedUtc < DateTime.Parse(s)))}, + {"CommonPart.PublishedUtc|>", new Func, string, IContentQuery>((q, s) => q.Where(r => r.PublishedUtc > DateTime.Parse(s)))}, + {"CommonPart.PublishedUtc|=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.PublishedUtc == DateTime.Parse(s)))}, // todo: (heskew) not practical as is. needs some sense of precision.... + {"CommonPart.PublishedUtc|^=", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* can't modified PublishedUtc for partial comparisons */))}, + // todo: (hesekw) this could benefit from a better filter implementation as this is currently very limited in functionality and I have no idea how the custom parts will be used by folks + {"ContainerCustomPart.CustomOne|<", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.CustomOne.CompareTo(s) == -1*/))}, + {"ContainerCustomPart.CustomOne|>", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.CustomOne.CompareTo(s) == 1*/))}, + {"ContainerCustomPart.CustomOne|=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.CustomOne.Equals(s, StringComparison.OrdinalIgnoreCase)))}, + {"ContainerCustomPart.CustomOne|^=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.CustomOne.StartsWith(s, StringComparison.OrdinalIgnoreCase)))}, + {"ContainerCustomPart.CustomTwo|<", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.CustomTwo.CompareTo(s) == -1*/))}, + {"ContainerCustomPart.CustomTwo|>", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.CustomTwo.CompareTo(s) == 1*/))}, + {"ContainerCustomPart.CustomTwo|=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.CustomTwo.Equals(s, StringComparison.OrdinalIgnoreCase)))}, + {"ContainerCustomPart.CustomTwo|^=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.CustomTwo.StartsWith(s, StringComparison.OrdinalIgnoreCase)))}, + {"ContainerCustomPart.CustomThree|<", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.CustomThree.CompareTo(s) == -1*/))}, + {"ContainerCustomPart.CustomThree|>", new Func, string, IContentQuery>((q, s) => q.Where(r => true /* CompareTo is not implemented - r.CustomThree.CompareTo(s) == 1*/))}, + {"ContainerCustomPart.CustomThree|=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.CustomThree.Equals(s, StringComparison.OrdinalIgnoreCase)))}, + {"ContainerCustomPart.CustomThree|^=", new Func, string, IContentQuery>((q, s) => q.Where(r => r.CustomThree.StartsWith(s, StringComparison.OrdinalIgnoreCase)))}, + }; + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Containers/Migrations.cs b/src/Orchard.Web/Core/Containers/Migrations.cs index dfea74290..decb6f714 100644 --- a/src/Orchard.Web/Core/Containers/Migrations.cs +++ b/src/Orchard.Web/Core/Containers/Migrations.cs @@ -13,6 +13,25 @@ namespace Orchard.Core.Containers { .Column("OrderByProperty") .Column("OrderByDirection")); + SchemaBuilder.CreateTable("ContainerWidgetPartRecord", + table => table + .ContentPartRecord() + .Column("ContainerId") + .Column("PageSize") + .Column("OrderByProperty") + .Column("OrderByDirection") + .Column("ApplyFilter") + .Column("FilterByProperty") + .Column("FilterByOperator") + .Column("FilterByValue")); + + SchemaBuilder.CreateTable("ContainerCustomPartRecord", + table => table + .ContentPartRecord() + .Column("CustomOne") + .Column("CustomTwo") + .Column("CustomThree")); + ContentDefinitionManager.AlterTypeDefinition("ContainerWidget", cfg => cfg .WithPart("CommonPart") @@ -22,9 +41,9 @@ namespace Orchard.Core.Containers { ContentDefinitionManager.AlterPartDefinition("ContainerPart", builder => builder.Attachable()); ContentDefinitionManager.AlterPartDefinition("ContainablePart", builder => builder.Attachable()); + ContentDefinitionManager.AlterPartDefinition("ContainerCustomPart", builder => builder.Attachable()); return 1; } - } } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Containers/Models/ContainerCustomPart.cs b/src/Orchard.Web/Core/Containers/Models/ContainerCustomPart.cs new file mode 100644 index 000000000..a6a33965c --- /dev/null +++ b/src/Orchard.Web/Core/Containers/Models/ContainerCustomPart.cs @@ -0,0 +1,13 @@ +using Orchard.ContentManagement; +using Orchard.ContentManagement.Records; + +namespace Orchard.Core.Containers.Models { + public class ContainerCustomPart : ContentPart { + } + + public class ContainerCustomPartRecord : ContentPartRecord { + public virtual string CustomOne { get; set; } + public virtual string CustomTwo { get; set; } + public virtual string CustomThree { get; set; } + } +} diff --git a/src/Orchard.Web/Core/Containers/Models/ContainerWidgetPart.cs b/src/Orchard.Web/Core/Containers/Models/ContainerWidgetPart.cs index 954985c72..c10b24f8c 100644 --- a/src/Orchard.Web/Core/Containers/Models/ContainerWidgetPart.cs +++ b/src/Orchard.Web/Core/Containers/Models/ContainerWidgetPart.cs @@ -1,10 +1,8 @@ -using System.Web.Mvc; -using Orchard.ContentManagement; +using Orchard.ContentManagement; using Orchard.ContentManagement.Records; namespace Orchard.Core.Containers.Models { public class ContainerWidgetPart : ContentPart { - public SelectList AvailableContainers { get; set; } } public class ContainerWidgetPartRecord : ContentPartRecord { @@ -12,5 +10,9 @@ namespace Orchard.Core.Containers.Models { public virtual int PageSize { get; set; } public virtual string OrderByProperty { get; set; } public virtual int OrderByDirection { get; set; } + public virtual bool ApplyFilter { get; set; } + public virtual string FilterByProperty { get; set; } + public virtual string FilterByOperator { get; set; } + public virtual string FilterByValue { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Containers/Placement.info b/src/Orchard.Web/Core/Containers/Placement.info index 37a3f3eb9..44a4aaa1b 100644 --- a/src/Orchard.Web/Core/Containers/Placement.info +++ b/src/Orchard.Web/Core/Containers/Placement.info @@ -1,6 +1,8 @@  + + diff --git a/src/Orchard.Web/Core/Containers/ViewModels/ContainerWidgetViewModel.cs b/src/Orchard.Web/Core/Containers/ViewModels/ContainerWidgetViewModel.cs new file mode 100644 index 000000000..0c7750d56 --- /dev/null +++ b/src/Orchard.Web/Core/Containers/ViewModels/ContainerWidgetViewModel.cs @@ -0,0 +1,10 @@ +using System.Web.Mvc; +using Orchard.Core.Containers.Models; + +namespace Orchard.Core.Containers.ViewModels { + public class ContainerWidgetViewModel { + public bool UseFilter { get; set; } + public SelectList AvailableContainers { get; set; } + public ContainerWidgetPart Part { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Core/Containers/Views/EditorTemplates/Container.cshtml b/src/Orchard.Web/Core/Containers/Views/EditorTemplates/Container.cshtml index 649dee1cf..e321e9841 100644 --- a/src/Orchard.Web/Core/Containers/Views/EditorTemplates/Container.cshtml +++ b/src/Orchard.Web/Core/Containers/Views/EditorTemplates/Container.cshtml @@ -6,9 +6,9 @@ @Html.SelectOption(Model.Record.OrderByProperty, "CommonPart.PublishedUtc", T("Date Published").Text) @Html.SelectOption(Model.Record.OrderByProperty, "RoutePart.Title", T("Title").Text) @Html.SelectOption(Model.Record.OrderByProperty, "RoutePart.Slug", T("Slug").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.Custom1", T("Custom 1").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.Custom2", T("Custom 2").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.Custom3", T("Custom 3").Text) + @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.CustomOne", T("Custom 1").Text) + @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.CustomTwo", T("Custom 2").Text) + @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.CustomThree", T("Custom 3").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "CommonPart.PublishedUtc", T("Date Published").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "RoutePart.Title", T("Title").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "RoutePart.Slug", T("Slug").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.Custom1", T("Custom 1").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.Custom2", T("Custom 2").Text) - @Html.SelectOption(Model.Record.OrderByProperty, "ContainerCustomPart.Custom3", T("Custom 3").Text) - - + @Html.LabelFor(m => m.Part.Record.ContainerId, T("Show items from")) + @Html.DropDownListFor(m => m.Part.Record.ContainerId, Model.AvailableContainers)
- @Html.LabelFor(m => m.Record.PageSize, T("Maximum number of items to display")) - @Html.TextBoxFor(m => m.Record.PageSize, new { @class = "text text-small" }) + @Html.LabelFor(m => m.Part.Record.PageSize, T("Maximum number of items to display")) + @Html.TextBoxFor(m => m.Part.Record.PageSize, new { @class = "text text-small" }) +
+
+ @Html.LabelFor(m => m.Part.Record.OrderByProperty, T("Order by")) + + +
+
+
+ @Html.EditorFor(m => m.Part.Record.ApplyFilter) + +
+
+ @Html.LabelFor(m => m.Part.Record.FilterByProperty, T("Filter where")) + + + + @Html.TextBoxFor(m => m.Part.Record.FilterByValue, new { @class = "text", title = T("Filter value") }) + +
\ No newline at end of file diff --git a/src/Orchard.Web/Core/Containers/Views/Parts/ContainerWidget.cshtml b/src/Orchard.Web/Core/Containers/Views/Parts/ContainerWidget.cshtml new file mode 100644 index 000000000..46e0c33a4 --- /dev/null +++ b/src/Orchard.Web/Core/Containers/Views/Parts/ContainerWidget.cshtml @@ -0,0 +1 @@ +@Display(Model.ContentItems) \ No newline at end of file diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 574db5b4a..cef144679 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -79,17 +79,21 @@ + + + + @@ -406,6 +410,8 @@ + + diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/EditWidget.cshtml b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/EditWidget.cshtml index a3b6aacf1..c94adb991 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/EditWidget.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/EditWidget.cshtml @@ -4,7 +4,6 @@ @Display(Model)
-
} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Views/EditorTemplates/Parts/Widgets.WidgetPart.cshtml b/src/Orchard.Web/Modules/Orchard.Widgets/Views/EditorTemplates/Parts/Widgets.WidgetPart.cshtml index a1fc3f1c7..3f73ecb3e 100644 --- a/src/Orchard.Web/Modules/Orchard.Widgets/Views/EditorTemplates/Parts/Widgets.WidgetPart.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Widgets/Views/EditorTemplates/Parts/Widgets.WidgetPart.cshtml @@ -1,21 +1,17 @@ @model Orchard.Widgets.Models.WidgetPart -
@Html.LabelFor(widget => widget.Zone, T("Zone")) @Html.DropDownListFor(widget => widget.Zone, new SelectList(Model.AvailableZones))
-
@Html.LabelFor(widget => widget.LayerId, T("Layer")) @Html.DropDownListFor(widget => widget.LayerId, new SelectList(Model.AvailableLayers, "Id", "Name"))
- -
- @Html.LabelFor(widget => widget.Title, T("Title")) - @Html.TextBoxFor(widget => widget.Title) -
-
@Html.LabelFor(widget => widget.Position, T("Position")) - @Html.TextBoxFor(widget => widget.Position) + @Html.TextBoxFor(widget => widget.Position, new { @class = "text text-small"}) +
+
+ @Html.LabelFor(widget => widget.Title, T("Title")) + @Html.EditorFor(widget => widget.Title)
\ No newline at end of file From 14a33aeb66dc2d26b1091fcdceec4bec14d9a3b5 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Fri, 12 Nov 2010 15:36:57 -0800 Subject: [PATCH 2/2] Updating the Container item display to respect the ContainerPart paging configuration --HG-- branch : dev --- .../Containers/Controllers/ItemController.cs | 30 +++++++------------ .../Core/Containers/Views/Item/Display.cshtml | 4 ++- src/Orchard/UI/Navigation/Pager.cs | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Orchard.Web/Core/Containers/Controllers/ItemController.cs b/src/Orchard.Web/Core/Containers/Controllers/ItemController.cs index d5684923a..433c57c39 100644 --- a/src/Orchard.Web/Core/Containers/Controllers/ItemController.cs +++ b/src/Orchard.Web/Core/Containers/Controllers/ItemController.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; using Orchard.Core.Common.Models; +using Orchard.Core.Containers.Extensions; using Orchard.Core.Containers.Models; using Orchard.Core.Routable.Models; using Orchard.DisplayManagement; @@ -48,34 +49,23 @@ namespace Orchard.Core.Containers.Controllers { .Join().Where(cr => cr.Container.Id == container.Id); var descendingOrder = container.As().Record.OrderByDirection == (int) OrderByDirection.Descending; - //todo: (heskew) order by custom part properties - switch (container.As().Record.OrderByProperty) { - case "RoutePart.Title": - query = descendingOrder - ? query.OrderByDescending(record => record.Title) - : query.OrderBy(record => record.Title); - break; - case "RoutePart.Slug": - query = descendingOrder - ? query.OrderByDescending(record => record.Slug) - : query.OrderBy(record => record.Slug); - break; - default: // "CommonPart.PublishedUtc" - query = descendingOrder - ? query.OrderByDescending(record => record.PublishedUtc) - : query.OrderBy(record => record.PublishedUtc); - break; - } + query = query.OrderBy(container.As().Record.OrderByProperty, descendingOrder); + pager.PageSize = pager.PageSize != Pager.PageSizeDefault && container.As().Record.Paginated + ? pager.PageSize + : container.As().Record.PageSize; var pagerShape = Shape.Pager(pager).TotalItemCount(query.Count()); - var pageOfItems = query.Slice(pager.GetStartIndex(), pager.PageSize).ToList(); + + var startIndex = container.As().Record.Paginated ? pager.GetStartIndex() : 0; + var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList(); var list = Shape.List(); list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary"))); var viewModel = Shape.ViewModel() .ContentItems(list) - .Pager(pagerShape); + .Pager(pagerShape) + .ShowPager(container.As().Record.Paginated); return View(viewModel); } diff --git a/src/Orchard.Web/Core/Containers/Views/Item/Display.cshtml b/src/Orchard.Web/Core/Containers/Views/Item/Display.cshtml index a4494f9a4..52d1f8ad9 100644 --- a/src/Orchard.Web/Core/Containers/Views/Item/Display.cshtml +++ b/src/Orchard.Web/Core/Containers/Views/Item/Display.cshtml @@ -1,2 +1,4 @@ @Display(Model.ContentItems) -@Display(Model.Pager) \ No newline at end of file +@if (Model.ShowPager) { + @Display(Model.Pager) +} \ No newline at end of file diff --git a/src/Orchard/UI/Navigation/Pager.cs b/src/Orchard/UI/Navigation/Pager.cs index 27aa646db..2adaef763 100644 --- a/src/Orchard/UI/Navigation/Pager.cs +++ b/src/Orchard/UI/Navigation/Pager.cs @@ -1,7 +1,7 @@ namespace Orchard.UI.Navigation { public class Pager { private const int PageDefault = 1; - private const int PageSizeDefault = 10; + public const int PageSizeDefault = 10; private int _pageSize; private int _size;