mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Getting the content container going. Still need to implement ordering and pagination.
--HG-- branch : dev
This commit is contained in:
@@ -7,6 +7,7 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Routable.Models;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Containers.Controllers {
|
||||
public class ItemController : Controller {
|
||||
@@ -22,7 +23,7 @@ namespace Orchard.Core.Containers.Controllers {
|
||||
dynamic New { get; set; }
|
||||
|
||||
[Themed]
|
||||
public ActionResult Display(string path, int? page) {
|
||||
public ActionResult Display(string path, Pager pager) {
|
||||
var matchedPath = _containersPathConstraint.FindPath(path);
|
||||
if (string.IsNullOrEmpty(matchedPath)) {
|
||||
throw new ApplicationException("404 - should not have passed path constraint");
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Containers.Models;
|
||||
using Orchard.Core.Containers.Settings;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Core.Containers.Drivers {
|
||||
@@ -25,8 +27,14 @@ namespace Orchard.Core.Containers.Drivers {
|
||||
public ContainerPartHandler(IRepository<ContainerPartRecord> repository, IOrchardServices orchardServices) {
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
OnInitializing<ContainerPart>((context, part) => {
|
||||
var containerSiteSettings = orchardServices.WorkContext.CurrentSite.As<ContainerSettingsPart>().Record;
|
||||
part.Record.PageSize = containerSiteSettings.DefaultPageSize;
|
||||
part.Record.PageSize = part.Settings.GetModel<ContainerTypePartSettings>().PageSizeDefault
|
||||
?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PageSizeDefault;
|
||||
part.Record.Paginated = part.Settings.GetModel<ContainerTypePartSettings>().PaginatedDefault
|
||||
?? part.PartDefinition.Settings.GetModel<ContainerPartSettings>().PaginatedDefault;
|
||||
|
||||
//hard-coded defaults for ordering
|
||||
part.Record.OrderByProperty = part.Is<CommonPart>() ? "CommonPart.PublishedUtc" : "";
|
||||
part.Record.OrderByDirection = (int)OrderByDirection.Descending;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,35 +0,0 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Containers.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Core.Containers.Drivers {
|
||||
public class ContainerSettingsPartDriver : ContentPartDriver<ContainerSettingsPart> {
|
||||
public ContainerSettingsPartDriver() {
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override string Prefix { get { return "ContainerSettings"; } }
|
||||
|
||||
protected override DriverResult Editor(ContainerSettingsPart part, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_Container_SiteSettings",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Container.SiteSettings", Model: part.Record, Prefix: Prefix));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(ContainerSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
updater.TryUpdateModel(part.Record, Prefix, null, null);
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
}
|
||||
|
||||
public class ContainerSettingsPartHandler : ContentHandler {
|
||||
public ContainerSettingsPartHandler(IRepository<ContainerSettingsPartRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<ContainerSettingsPart>("Site"));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,11 +13,6 @@ namespace Orchard.Core.Containers {
|
||||
.Column<string>("OrderByProperty")
|
||||
.Column<int>("OrderByDirection"));
|
||||
|
||||
SchemaBuilder.CreateTable("ContainerSettingsPartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<int>("DefaultPageSize", column => column.WithDefault(10))
|
||||
);
|
||||
|
||||
ContentDefinitionManager.AlterPartDefinition("ContainerPart", builder => builder.Attachable());
|
||||
ContentDefinitionManager.AlterPartDefinition("ContainablePart", builder => builder.Attachable());
|
||||
|
||||
|
@@ -6,7 +6,7 @@ namespace Orchard.Core.Containers.Models {
|
||||
}
|
||||
|
||||
public class ContainerPartRecord : ContentPartRecord {
|
||||
public virtual int Paginated { get; set; }
|
||||
public virtual bool Paginated { get; set; }
|
||||
public virtual int PageSize { get; set; }
|
||||
public virtual string OrderByProperty { get; set; }
|
||||
public virtual int OrderByDirection { get; set; }
|
||||
|
@@ -1,6 +1,15 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Core.Containers.Models {
|
||||
public class ContainerSettingsPart : ContentPart<ContainerSettingsPartRecord> {
|
||||
}
|
||||
|
||||
public class ContainerSettingsPartRecord : ContentPartRecord {
|
||||
private int _defaultPageSize = 10;
|
||||
public virtual int DefaultPageSize {
|
||||
get { return _defaultPageSize; }
|
||||
set { _defaultPageSize = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Core.Containers.Models {
|
||||
public class ContainerSettingsPartRecord : ContentPartRecord {
|
||||
private int _defaultPageSize = 10;
|
||||
public virtual int DefaultPageSize {
|
||||
get { return _defaultPageSize; }
|
||||
set { _defaultPageSize = value; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Containers.Settings {
|
||||
public class ContainerPartSettings {
|
||||
public const int PageSizeDefaultDefault = 10;
|
||||
public const bool PaginatedDefaultDefault = true;
|
||||
|
||||
private int? _pageSizeDefault;
|
||||
private bool? _paginiatedDefault;
|
||||
|
||||
public int PageSizeDefault {
|
||||
get {
|
||||
return _pageSizeDefault != null
|
||||
? (int)_pageSizeDefault
|
||||
: PageSizeDefaultDefault;
|
||||
}
|
||||
set { _pageSizeDefault = value; }
|
||||
}
|
||||
|
||||
public bool PaginatedDefault {
|
||||
get {
|
||||
return _paginiatedDefault != null
|
||||
? (bool)_paginiatedDefault
|
||||
: PaginatedDefaultDefault;
|
||||
}
|
||||
set { _paginiatedDefault = value; }
|
||||
}
|
||||
}
|
||||
|
||||
public class ContainerTypePartSettings {
|
||||
public int? PageSizeDefault { get; set; }
|
||||
public bool? PaginatedDefault { get; set; }
|
||||
}
|
||||
|
||||
public class ContainerSettingsHooks : ContentDefinitionEditorEventsBase {
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) {
|
||||
if (definition.PartDefinition.Name != "ContainerPart")
|
||||
yield break;
|
||||
|
||||
var model = definition.Settings.GetModel<ContainerTypePartSettings>();
|
||||
var partModel = definition.PartDefinition.Settings.GetModel<ContainerPartSettings>();
|
||||
|
||||
if (model.PageSizeDefault == null)
|
||||
model.PageSizeDefault = partModel.PageSizeDefault;
|
||||
|
||||
if (model.PaginatedDefault == null)
|
||||
model.PaginatedDefault = partModel.PaginatedDefault;
|
||||
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> PartEditor(ContentPartDefinition definition) {
|
||||
if (definition.Name != "ContainerPart")
|
||||
yield break;
|
||||
|
||||
var model = definition.Settings.GetModel<ContainerPartSettings>();
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
if (builder.Name != "ContainerPart")
|
||||
yield break;
|
||||
|
||||
var model = new ContainerTypePartSettings();
|
||||
updateModel.TryUpdateModel(model, "ContainerTypePartSettings", null, null);
|
||||
builder.WithSetting("ContainerTypePartSettings.PageSizeDefault", model.PageSizeDefault.ToString());
|
||||
builder.WithSetting("ContainerTypePartSettings.PaginatedDefault", model.PaginatedDefault.ToString());
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
|
||||
public override IEnumerable<TemplateViewModel> PartEditorUpdate(ContentPartDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
if (builder.Name != "ContainerPart")
|
||||
yield break;
|
||||
|
||||
var model = new ContainerPartSettings();
|
||||
updateModel.TryUpdateModel(model, "ContainerPartSettings", null, null);
|
||||
builder.WithSetting("ContainerPartSettings.PageSizeDefault", model.PageSizeDefault.ToString());
|
||||
builder.WithSetting("ContainerPartSettings.PaginatedDefault", model.PaginatedDefault.ToString());
|
||||
yield return DefinitionTemplate(model);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace Orchard.Core.Common.Settings {
|
||||
public class LocationSettings {
|
||||
public string Zone { get; set; }
|
||||
public string Position { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
@model Orchard.Core.Containers.Settings.ContainerPartSettings
|
||||
<fieldset>
|
||||
<label for="@Html.FieldIdFor(m => m.PageSizeDefault)">@T("Default Page Size")</label>
|
||||
@Html.EditorFor(m => m.PageSizeDefault)
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.EditorFor(m => m.PaginatedDefault)
|
||||
<label for="@Html.FieldIdFor( m => m.PaginatedDefault)" class="forcheckbox">@T("Show paging controls")</label>
|
||||
</fieldset>
|
@@ -0,0 +1,9 @@
|
||||
@model Orchard.Core.Containers.Settings.ContainerTypePartSettings
|
||||
<fieldset>
|
||||
<label for="@Html.FieldIdFor(m => m.PageSizeDefault)">@T("Default Page Size")</label>
|
||||
@Html.EditorFor(m => m.PageSizeDefault)
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="@Html.FieldIdFor( m => m.PaginatedDefault)">@T("Show paging controls")</label>
|
||||
@Html.EditorFor(m => m.PaginatedDefault)
|
||||
</fieldset>
|
@@ -1,11 +0,0 @@
|
||||
@model Orchard.Core.Containers.Models.ContainerSettingsPartRecord
|
||||
@using Orchard.Core.Containers.Models;
|
||||
|
||||
<fieldset>
|
||||
<legend>@T("Content Container")</legend>
|
||||
<div>
|
||||
<label for="@ViewData.TemplateInfo.GetFullHtmlFieldId("DefaultPageSize")">@T("Default page size")</label>
|
||||
@Html.EditorFor(m => m.DefaultPageSize)
|
||||
@Html.ValidationMessageFor(m => m.DefaultPageSize)
|
||||
</div>
|
||||
</fieldset>
|
@@ -1,21 +1,21 @@
|
||||
@model Orchard.Core.Containers.Models.ContainerPart
|
||||
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Record.PageSize, T("Page Size"))
|
||||
@Html.TextBoxFor(m => m.Record.PageSize)
|
||||
@using Orchard.Core.Containers.Models;
|
||||
<fieldset class="with-checkbox">
|
||||
<span>
|
||||
@Html.LabelFor(m => m.Record.PageSize, T("Page Size"))
|
||||
@Html.EditorFor(m => m.Record.PageSize)
|
||||
</span>
|
||||
<span class="checkbox-and-label">
|
||||
@Html.CheckBoxFor(m => m.Record.Paginated)
|
||||
<label for="@Html.FieldIdFor( m => m.Record.Paginated)" class="forcheckbox">@T("Show paging controls")</label>
|
||||
</span>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Record.Paginated, T("Paginated"))
|
||||
@Html.TextBoxFor(m => m.Record.Paginated)
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Record.OrderByProperty, T("OrderByProperty"))
|
||||
@Html.TextBoxFor(m => m.Record.OrderByProperty)
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Record.OrderByDirection, T("OrderByDirection"))
|
||||
@Html.TextBoxFor(m => m.Record.OrderByDirection)
|
||||
</fieldset>
|
||||
@Html.LabelFor(m => m.Record.OrderByProperty, T("Order By"))
|
||||
@Html.TextBoxFor(m => m.Record.OrderByProperty, new { @class = "textMedium" })
|
||||
<select id="@Html.FieldIdFor( m => m.Record.OrderByDirection)" name="@Html.FieldIdFor( m => m.Record.OrderByDirection)">
|
||||
@Html.SelectOption(Model.Record.OrderByDirection, (int)OrderByDirection.Ascending, T("Ascending").Text)
|
||||
@Html.SelectOption(Model.Record.OrderByDirection, (int)OrderByDirection.Descending, T("Descending").Text)
|
||||
</select>
|
||||
<span class="hint">Currently, only ordering by a content part property is supported (e.g. CommonPart.PublishedUtc).</span>
|
||||
</fieldset>
|
@@ -79,15 +79,14 @@
|
||||
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
||||
<Compile Include="Containers\ContainersPathConstraint.cs" />
|
||||
<Compile Include="Containers\Migrations.cs" />
|
||||
<Compile Include="Containers\Drivers\ContainerSettingsPartDriver.cs" />
|
||||
<Compile Include="Containers\Models\ContainerSettingsPart.cs" />
|
||||
<Compile Include="Containers\Models\ContainerSettingsPartRecord.cs" />
|
||||
<Compile Include="Containers\Models\ContainablePart.cs" />
|
||||
<Compile Include="Containers\Models\ContainerPart.cs" />
|
||||
<Compile Include="Common\Shapes.cs" />
|
||||
<Compile Include="Common\Fields\TextField.cs" />
|
||||
<Compile Include="Containers\Routes.cs" />
|
||||
<Compile Include="Containers\Services\ContainersPathConstraintUpdater.cs" />
|
||||
<Compile Include="Containers\Settings\ContainerSettings.cs" />
|
||||
<Compile Include="Containers\ViewModels\ContainableViewModel.cs" />
|
||||
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
|
||||
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
||||
@@ -402,7 +401,8 @@
|
||||
<Content Include="Containers\Views\EditorTemplates\Containable.cshtml" />
|
||||
<Content Include="Containers\Views\EditorTemplates\Container.cshtml" />
|
||||
<Content Include="Containers\Views\Item\Display.cshtml" />
|
||||
<Content Include="Containers\Views\EditorTemplates\Container.SiteSettings.cshtml" />
|
||||
<Content Include="Containers\Views\DefinitionTemplates\ContainerPartSettings.cshtml" />
|
||||
<Content Include="Containers\Views\DefinitionTemplates\ContainerTypePartSettings.cshtml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
@@ -833,7 +833,11 @@ table.items th, table.items td {
|
||||
border-color:#666d51;
|
||||
border-style:solid;
|
||||
}
|
||||
.permalink .checkbox-and-label {
|
||||
/* Routable and Containers (Core) */
|
||||
.with-checkbox .checkbox-and-label { /* todo: (heskew) routable should be changed to use this too */
|
||||
margin-left:10px;
|
||||
}
|
||||
.checkbox-and-label {
|
||||
white-space:nowrap;
|
||||
}
|
||||
/* Settings */
|
||||
|
Reference in New Issue
Block a user