mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
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:
45
src/Orchard.Web/Core/Containers/ContainersPathConstraint.cs
Normal file
45
src/Orchard.Web/Core/Containers/ContainersPathConstraint.cs
Normal 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 }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Core.Containers.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Containers.Drivers {
|
||||||
|
public class ContainablePartDriver : ContentPartDriver<ContainablePart> {
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Core.Containers.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Containers.Drivers {
|
||||||
|
public class ContainerPartDriver : ContentPartDriver<ContainerPart>{
|
||||||
|
}
|
||||||
|
}
|
24
src/Orchard.Web/Core/Containers/Migrations.cs
Normal file
24
src/Orchard.Web/Core/Containers/Migrations.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Containers.Models {
|
||||||
|
public class ContainablePart : ContentPart {
|
||||||
|
}
|
||||||
|
}
|
19
src/Orchard.Web/Core/Containers/Models/ContainerPart.cs
Normal file
19
src/Orchard.Web/Core/Containers/Models/ContainerPart.cs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
12
src/Orchard.Web/Core/Containers/Module.txt
Normal file
12
src/Orchard.Web/Core/Containers/Module.txt
Normal 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
|
42
src/Orchard.Web/Core/Containers/Routes.cs
Normal file
42
src/Orchard.Web/Core/Containers/Routes.cs
Normal 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())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -66,12 +66,20 @@
|
|||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\Migrations.cs" />
|
||||||
<Compile Include="Common\Drivers\BodyPartDriver.cs" />
|
<Compile Include="Common\Drivers\BodyPartDriver.cs" />
|
||||||
<Compile Include="Common\Drivers\CommonPartDriver.cs" />
|
<Compile Include="Common\Drivers\CommonPartDriver.cs" />
|
||||||
<Compile Include="Common\Drivers\TextFieldDriver.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\Shapes.cs" />
|
||||||
<Compile Include="Common\Fields\TextField.cs" />
|
<Compile Include="Common\Fields\TextField.cs" />
|
||||||
|
<Compile Include="Containers\Routes.cs" />
|
||||||
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
|
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
|
||||||
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
<Compile Include="Common\Services\BbcodeFilter.cs" />
|
||||||
<Compile Include="Common\Services\ICommonService.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.Body.SummaryAdmin.cshtml" />
|
||||||
<Content Include="Common\Views\Parts\Common.Metadata.cshtml" />
|
<Content Include="Common\Views\Parts\Common.Metadata.cshtml" />
|
||||||
<Content Include="Common\Views\Parts\Common.Metadata.SummaryAdmin.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\Create.cshtml" />
|
||||||
<Content Include="Contents\Views\Admin\Edit.cshtml" />
|
<Content Include="Contents\Views\Admin\Edit.cshtml" />
|
||||||
<Content Include="Contents\Views\Admin\List.cshtml" />
|
<Content Include="Contents\Views\Admin\List.cshtml" />
|
||||||
|
Reference in New Issue
Block a user