Adding core Containers module

Container part used for content types that group child items together
Containable part provides UI to select which item is ContainerId

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-11-08 15:33:56 -08:00
parent 7e9c27433b
commit 8d1b0a7be7
10 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
namespace Orchard.Core.Containers {
public interface IContainersPathConstraint : IRouteConstraint, ISingletonDependency {
void SetPaths(IEnumerable<string> paths);
string FindPath(string path);
void AddPath(string path);
}
public class ContainersPathConstraint : IContainersPathConstraint {
private IDictionary<string, string> _paths = new Dictionary<string, string>();
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
if (routeDirection == RouteDirection.UrlGeneration)
return true;
object value;
if (values.TryGetValue(parameterName, out value)) {
var parameterValue = Convert.ToString(value);
return _paths.ContainsKey(parameterValue);
}
return false;
}
public void SetPaths(IEnumerable<string> paths) {
// Note: this does not need to be synchronized as long as the dictionary itself is treated as immutable.
// do not add or remove to the dictionary instance once created. recreate and reassign instead.
_paths = paths.Distinct().ToDictionary(path => path, StringComparer.OrdinalIgnoreCase);
}
public string FindPath(string path) {
string actual;
return _paths.TryGetValue(path, out actual) ? actual : path;
}
public void AddPath(string path) {
SetPaths(_paths.Keys.Concat(new[] { path }));
}
}
}

View File

@@ -0,0 +1,11 @@
using System.Web.Mvc;
using Orchard.Themes;
namespace Orchard.Core.Containers.Controllers {
public class ItemController: Controller {
[Themed]
public ActionResult Display(string path, int? page) {
return View();
}
}
}

View File

@@ -0,0 +1,7 @@
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Containers.Models;
namespace Orchard.Core.Containers.Drivers {
public class ContainablePartDriver : ContentPartDriver<ContainablePart> {
}
}

View File

@@ -0,0 +1,7 @@
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Containers.Models;
namespace Orchard.Core.Containers.Drivers {
public class ContainerPartDriver : ContentPartDriver<ContainerPart>{
}
}

View File

@@ -0,0 +1,24 @@
using System;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
namespace Orchard.Core.Containers {
public class Migrations : DataMigrationImpl {
public int Create() {
SchemaBuilder.CreateTable("ContainerPartRecord",
table => table
.ContentPartRecord()
.Column<bool>("Paginated")
.Column<int>("PageSize")
.Column<string>("OrderByProperty")
.Column<int>("OrderByDirection"));
ContentDefinitionManager.AlterPartDefinition("ContainerPart", builder => builder.Attachable());
ContentDefinitionManager.AlterPartDefinition("ContainablePart", builder => builder.Attachable());
return 1;
}
}
}

View File

@@ -0,0 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.Core.Containers.Models {
public class ContainablePart : ContentPart {
}
}

View File

@@ -0,0 +1,19 @@
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
namespace Orchard.Core.Containers.Models {
public class ContainerPart : ContentPart<ContainerPartRecord> {
}
public class ContainerPartRecord : ContentPartRecord {
public virtual bool Paginated { get; set; }
public virtual int PageSize { get; set; }
public virtual string OrderByProperty { get; set; }
public virtual OrderByDirection OrderByDirection { get; set; }
}
public enum OrderByDirection {
Ascending,
Descending,
}
}

View File

@@ -0,0 +1,12 @@
Name: Containers
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 0.8.0
OrchardVersion: 0.8.0
Description: The common module introduces container and containable behaviors for content items
Features:
Containers:
Description: Container content parts.
Dependencies: Settings
Category: Content

View File

@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;
namespace Orchard.Core.Containers {
public class Routes : IRouteProvider {
private readonly IContainersPathConstraint _containersPathConstraint;
public Routes(IContainersPathConstraint containersPathConstraint) {
_containersPathConstraint = containersPathConstraint;
}
public void GetRoutes(ICollection<RouteDescriptor> routes) {
foreach (var routeDescriptor in GetRoutes())
routes.Add(routeDescriptor);
}
public IEnumerable<RouteDescriptor> GetRoutes() {
return new[] {
new RouteDescriptor {
Priority = 15,
Route = new Route(
"{*path}",
new RouteValueDictionary {
{"area", "Containers"},
{"controller", "Item"},
{"action", "Display"}
},
new RouteValueDictionary {
{"path", _containersPathConstraint}
},
new RouteValueDictionary {
{"area", "Containers"}
},
new MvcRouteHandler())
}
};
}
}
}

View File

@@ -66,12 +66,20 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Containers\Controllers\ItemController.cs" />
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />
<Compile Include="Containers\Drivers\ContainerPartDriver.cs" />
<Compile Include="Common\Migrations.cs" />
<Compile Include="Common\Drivers\BodyPartDriver.cs" />
<Compile Include="Common\Drivers\CommonPartDriver.cs" />
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
<Compile Include="Containers\ContainersPathConstraint.cs" />
<Compile Include="Containers\Migrations.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="Contents\Security\AuthorizationEventHandler.cs" />
<Compile Include="Common\Services\BbcodeFilter.cs" />
<Compile Include="Common\Services\ICommonService.cs" />
@@ -242,6 +250,7 @@
<Content Include="Common\Views\Parts\Common.Body.SummaryAdmin.cshtml" />
<Content Include="Common\Views\Parts\Common.Metadata.cshtml" />
<Content Include="Common\Views\Parts\Common.Metadata.SummaryAdmin.cshtml" />
<Content Include="Containers\Module.txt" />
<Content Include="Contents\Views\Admin\Create.cshtml" />
<Content Include="Contents\Views\Admin\Edit.cshtml" />
<Content Include="Contents\Views\Admin\List.cshtml" />