mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Switching body, title, slug common data over to version-aware records
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045007
This commit is contained in:
@@ -1,11 +1,6 @@
|
|||||||
using System;
|
using Orchard.ContentManagement;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Tests.ContentManagement.Records;
|
|
||||||
|
|
||||||
namespace Orchard.Tests.ContentManagement.Models {
|
namespace Orchard.Tests.ContentManagement.Models {
|
||||||
|
|
||||||
@@ -17,7 +12,7 @@ namespace Orchard.Tests.ContentManagement.Models {
|
|||||||
|
|
||||||
public EpsilonHandler(IRepository<EpsilonRecord> repository) {
|
public EpsilonHandler(IRepository<EpsilonRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<Epsilon>(x => x == "gamma"));
|
Filters.Add(new ActivatingFilter<Epsilon>(x => x == "gamma"));
|
||||||
Filters.Add(new StorageVersionFilter<EpsilonRecord>(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/Orchard.Web/Core/Common/Controllers/BodyDriver.cs
Normal file
29
src/Orchard.Web/Core/Common/Controllers/BodyDriver.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Common.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Common.Controllers {
|
||||||
|
public class BodyDriver : PartDriver<BodyAspect> {
|
||||||
|
private const string TemplateName = "Parts/Common.Body";
|
||||||
|
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
|
||||||
|
protected override string Prefix {
|
||||||
|
get {return "Body";}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Display(BodyAspect part, string displayType) {
|
||||||
|
var model = new BodyDisplayViewModel { BodyAspect = part };
|
||||||
|
return PartTemplate(model, TemplateName, Prefix).Location("body");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(BodyAspect part) {
|
||||||
|
var model = new BodyEditorViewModel { BodyAspect = part, TextEditorTemplate = DefaultTextEditorTemplate };
|
||||||
|
return PartTemplate(model, TemplateName, Prefix).Location("body");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(BodyAspect part, Orchard.ContentManagement.IUpdateModel updater) {
|
||||||
|
var model = new BodyEditorViewModel { BodyAspect = part, TextEditorTemplate = DefaultTextEditorTemplate };
|
||||||
|
updater.TryUpdateModel(model, Prefix, null, null);
|
||||||
|
return PartTemplate(model, TemplateName, Prefix).Location("body");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,11 @@
|
|||||||
using Orchard.Core.Common.Models;
|
|
||||||
using Orchard.Core.Common.Records;
|
using Orchard.Core.Common.Records;
|
||||||
using Orchard.Core.Common.ViewModels;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.ContentManagement.ViewModels;
|
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Providers {
|
namespace Orchard.Core.Common.Providers {
|
||||||
public class BodyAspectHandler : ContentHandler {
|
public class BodyAspectHandler : ContentHandler {
|
||||||
private const string TemplatePrefix = "Body";
|
|
||||||
private const string TemplateName = "Parts/Common.Body";
|
|
||||||
private const string DefaultTextEditorTemplate = "TinyMceTextEditor";
|
|
||||||
|
|
||||||
public BodyAspectHandler(IRepository<BodyRecord> bodyRepository) {
|
public BodyAspectHandler(IRepository<BodyRecord> bodyRepository) {
|
||||||
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(StorageFilter.For(bodyRepository));
|
||||||
|
|
||||||
OnGetDisplayViewModel<BodyAspect>((context, body) => {
|
|
||||||
var model = new BodyDisplayViewModel { BodyAspect = body };
|
|
||||||
context.AddDisplay(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary" });
|
|
||||||
});
|
|
||||||
|
|
||||||
OnGetEditorViewModel<BodyAspect>((context, body) => {
|
|
||||||
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
|
||||||
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary", Position = "5" });
|
|
||||||
});
|
|
||||||
|
|
||||||
OnUpdateEditorViewModel<BodyAspect>((context, body) => {
|
|
||||||
var model = new BodyEditorViewModel { BodyAspect = body, TextEditorTemplate = DefaultTextEditorTemplate };
|
|
||||||
context.Updater.TryUpdateModel(model, TemplatePrefix, null, null);
|
|
||||||
context.AddEditor(new TemplateViewModel(model, TemplatePrefix) { TemplateName = TemplateName, ZoneName = "primary", Position = "5" });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
|
|
||||||
Filters.Add(new StorageFilter<CommonRecord>(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
|
|
||||||
OnActivated<CommonAspect>(PropertySetHandlers);
|
OnActivated<CommonAspect>(PropertySetHandlers);
|
||||||
OnActivated<CommonAspect>(DefaultTimestampsAndOwner);
|
OnActivated<CommonAspect>(DefaultTimestampsAndOwner);
|
||||||
@@ -116,7 +116,7 @@ namespace Orchard.Core.Common.Providers {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel = new OwnerEditorViewModel ();
|
var viewModel = new OwnerEditorViewModel();
|
||||||
if (instance.Owner != null)
|
if (instance.Owner != null)
|
||||||
viewModel.Owner = instance.Owner.UserName;
|
viewModel.Owner = instance.Owner.UserName;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Orchard.ContentManagement.Handlers;
|
|||||||
namespace Orchard.Core.Common.Providers {
|
namespace Orchard.Core.Common.Providers {
|
||||||
public class RoutableAspectHandler : ContentHandler {
|
public class RoutableAspectHandler : ContentHandler {
|
||||||
public RoutableAspectHandler(IRepository<RoutableRecord> repository) {
|
public RoutableAspectHandler(IRepository<RoutableRecord> repository) {
|
||||||
Filters.Add(new StorageFilter<RoutableRecord>(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Records {
|
namespace Orchard.Core.Common.Records {
|
||||||
public class BodyRecord : ContentPartRecord {
|
public class BodyRecord : ContentPartVersionRecord {
|
||||||
public virtual string Text { get; set; }
|
public virtual string Text { get; set; }
|
||||||
public virtual string Format { get; set; }
|
public virtual string Format { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Records {
|
namespace Orchard.Core.Common.Records {
|
||||||
public class RoutableRecord : ContentPartRecord {
|
public class RoutableRecord : ContentPartVersionRecord {
|
||||||
public virtual string Title { get; set; }
|
public virtual string Title { get; set; }
|
||||||
public virtual string Slug { get; set; }
|
public virtual string Slug { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@
|
|||||||
<Reference Include="System.Web.Mobile" />
|
<Reference Include="System.Web.Mobile" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Common\Controllers\BodyDriver.cs" />
|
||||||
<Compile Include="Common\Permissions.cs" />
|
<Compile Include="Common\Permissions.cs" />
|
||||||
<Compile Include="Common\Utilities\LazyField.cs" />
|
<Compile Include="Common\Utilities\LazyField.cs" />
|
||||||
<Compile Include="Common\Providers\CommonAspectHandler.cs" />
|
<Compile Include="Common\Providers\CommonAspectHandler.cs" />
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Orchard.Core.Themes.Models {
|
|||||||
public ThemeSiteSettingsHandler(IRepository<ThemeSiteSettingsRecord> repository) {
|
public ThemeSiteSettingsHandler(IRepository<ThemeSiteSettingsRecord> repository) {
|
||||||
_themeSiteSettingsRepository = repository;
|
_themeSiteSettingsRepository = repository;
|
||||||
Filters.Add(new ActivatingFilter<ThemeSiteSettings>("site"));
|
Filters.Add(new ActivatingFilter<ThemeSiteSettings>("site"));
|
||||||
Filters.Add(new StorageFilter<ThemeSiteSettingsRecord>(_themeSiteSettingsRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<ThemeSiteSettingsRecord>(_themeSiteSettingsRepository));
|
||||||
Filters.Add(new TemplateFilterForRecord<ThemeSiteSettingsRecord>("ThemeSiteSettings", "Parts/Themes.SiteSettings"));
|
Filters.Add(new TemplateFilterForRecord<ThemeSiteSettingsRecord>("ThemeSiteSettings", "Parts/Themes.SiteSettings"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Orchard.Comments.Models {
|
|||||||
public CommentSettingsHandler(IRepository<CommentSettingsRecord> repository) {
|
public CommentSettingsHandler(IRepository<CommentSettingsRecord> repository) {
|
||||||
_commentSettingsRepository = repository;
|
_commentSettingsRepository = repository;
|
||||||
Filters.Add(new ActivatingFilter<CommentSettings>("site"));
|
Filters.Add(new ActivatingFilter<CommentSettings>("site"));
|
||||||
Filters.Add(new StorageFilter<CommentSettingsRecord>(_commentSettingsRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<CommentSettingsRecord>(_commentSettingsRepository));
|
||||||
Filters.Add(new TemplateFilterForRecord<CommentSettingsRecord>("CommentSettings", "Parts/Comments.SiteSettings"));
|
Filters.Add(new TemplateFilterForRecord<CommentSettingsRecord>("CommentSettings", "Parts/Comments.SiteSettings"));
|
||||||
OnActivated<CommentSettings>(DefaultSettings);
|
OnActivated<CommentSettings>(DefaultSettings);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Orchard.Comments.Models {
|
|||||||
|
|
||||||
Filters.Add(new ActivatingFilter<HasComments>("sandboxpage"));
|
Filters.Add(new ActivatingFilter<HasComments>("sandboxpage"));
|
||||||
Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
|
Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
|
||||||
Filters.Add(new StorageFilter<HasCommentsRecord>(hasCommentsRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<HasCommentsRecord>(hasCommentsRepository) );
|
||||||
|
|
||||||
OnActivated<HasComments>((ctx, x) => {
|
OnActivated<HasComments>((ctx, x) => {
|
||||||
x.CommentsActive = true;
|
x.CommentsActive = true;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Orchard.Media.Models {
|
|||||||
public class MediaSettingsHandler : ContentHandler {
|
public class MediaSettingsHandler : ContentHandler {
|
||||||
public MediaSettingsHandler(IRepository<MediaSettingsRecord> repository) {
|
public MediaSettingsHandler(IRepository<MediaSettingsRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<MediaSettings>("site"));
|
Filters.Add(new ActivatingFilter<MediaSettings>("site"));
|
||||||
Filters.Add(new StorageFilter<MediaSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<MediaSettingsRecord>(repository) );
|
||||||
OnActivated<MediaSettings>(DefaultSettings);
|
OnActivated<MediaSettings>(DefaultSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ namespace Orchard.Sandbox.Models {
|
|||||||
Filters.Add(new ActivatingFilter<CommonAspect>(SandboxPageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<CommonAspect>(SandboxPageDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<RoutableAspect>(SandboxPageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<RoutableAspect>(SandboxPageDriver.ContentType.Name));
|
||||||
Filters.Add(new ActivatingFilter<BodyAspect>(SandboxPageDriver.ContentType.Name));
|
Filters.Add(new ActivatingFilter<BodyAspect>(SandboxPageDriver.ContentType.Name));
|
||||||
Filters.Add(new StorageFilter<SandboxPageRecord>(pageRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<SandboxPageRecord>(pageRepository) );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// add settings to site, and simple record-template gui
|
// add settings to site, and simple record-template gui
|
||||||
Filters.Add(new ActivatingFilter<ContentPart<SandboxSettingsRecord>>("site"));
|
Filters.Add(new ActivatingFilter<ContentPart<SandboxSettingsRecord>>("site"));
|
||||||
Filters.Add(new StorageFilter<SandboxSettingsRecord>(settingsRepository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<SandboxSettingsRecord>(settingsRepository));
|
||||||
Filters.Add(new TemplateFilterForRecord<SandboxSettingsRecord>("SandboxSettings", "Parts/Sandbox.SiteSettings"));
|
Filters.Add(new TemplateFilterForRecord<SandboxSettingsRecord>("SandboxSettings", "Parts/Sandbox.SiteSettings"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Orchard.Tags.Models {
|
|||||||
public class TagSettingsHandler : ContentHandler {
|
public class TagSettingsHandler : ContentHandler {
|
||||||
public TagSettingsHandler(IRepository<TagSettingsRecord> repository) {
|
public TagSettingsHandler(IRepository<TagSettingsRecord> repository) {
|
||||||
Filters.Add(new ActivatingFilter<TagSettings>("site"));
|
Filters.Add(new ActivatingFilter<TagSettings>("site"));
|
||||||
Filters.Add(new StorageFilter<TagSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
Filters.Add(new StorageFilter<TagSettingsRecord>(repository));
|
||||||
Filters.Add(new TemplateFilterForRecord<TagSettingsRecord>("TagSettings", "Parts/Tags.SiteSettings"));
|
Filters.Add(new TemplateFilterForRecord<TagSettingsRecord>("TagSettings", "Parts/Tags.SiteSettings"));
|
||||||
OnActivated<TagSettings>(DefaultSettings);
|
OnActivated<TagSettings>(DefaultSettings);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
|
using System;
|
||||||
using Orchard.ContentManagement.Records;
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.Handlers {
|
namespace Orchard.ContentManagement.Handlers {
|
||||||
|
public static class StorageFilter {
|
||||||
|
public static StorageFilter<TRecord> For<TRecord>(IRepository<TRecord> repository) where TRecord : ContentPartRecord, new() {
|
||||||
|
if (typeof(TRecord).IsSubclassOf(typeof(ContentPartVersionRecord))) {
|
||||||
|
var filterType = typeof(StorageVersionFilter<>).MakeGenericType(typeof(TRecord));
|
||||||
|
return (StorageFilter<TRecord>)Activator.CreateInstance(filterType, repository);
|
||||||
|
}
|
||||||
|
return new StorageFilter<TRecord>(repository);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class StorageFilter<TRecord> : StorageFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
|
public class StorageFilter<TRecord> : StorageFilterBase<ContentPart<TRecord>> where TRecord : ContentPartRecord, new() {
|
||||||
private readonly IRepository<TRecord> _repository;
|
protected readonly IRepository<TRecord> _repository;
|
||||||
|
|
||||||
public StorageFilter(IRepository<TRecord> repository) {
|
public StorageFilter(IRepository<TRecord> repository) {
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AutomaticallyCreateMissingRecord { get; set; }
|
|
||||||
|
|
||||||
protected override void Activated(ActivatedContentContext context, ContentPart<TRecord> instance) {
|
protected override void Activated(ActivatedContentContext context, ContentPart<TRecord> instance) {
|
||||||
instance.Record = new TRecord();
|
instance.Record = new TRecord();
|
||||||
@@ -20,14 +30,24 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
_repository.Create(instance.Record);
|
_repository.Create(instance.Record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual TRecord GetRecord(LoadContentContext context) {
|
||||||
|
return _repository.Get(context.Id);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Loading(LoadContentContext context, ContentPart<TRecord> instance) {
|
protected override void Loading(LoadContentContext context, ContentPart<TRecord> instance) {
|
||||||
var record = _repository.Get(context.Id);
|
var record = GetRecord(context);
|
||||||
if (record != null) {
|
if (record != null) {
|
||||||
instance.Record = record;
|
instance.Record = record;
|
||||||
}
|
}
|
||||||
else if (AutomaticallyCreateMissingRecord) {
|
else {
|
||||||
instance.Record.ContentItemRecord = context.ContentItemRecord;
|
var createContext = new CreateContentContext {
|
||||||
_repository.Create(instance.Record);
|
ContentItem = context.ContentItem,
|
||||||
|
ContentItemRecord = context.ContentItemRecord,
|
||||||
|
ContentItemVersionRecord = context.ContentItemVersionRecord,
|
||||||
|
ContentType = context.ContentType,
|
||||||
|
Id = context.Id
|
||||||
|
};
|
||||||
|
Creating(createContext, instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,17 +56,13 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StorageVersionFilter<TRecord> : StorageFilterBase<ContentPart<TRecord>> where TRecord : ContentPartVersionRecord, new() {
|
public class StorageVersionFilter<TRecord> : StorageFilter<TRecord> where TRecord : ContentPartVersionRecord, new() {
|
||||||
private readonly IRepository<TRecord> _repository;
|
public StorageVersionFilter(IRepository<TRecord> repository)
|
||||||
|
: base(repository) {
|
||||||
public StorageVersionFilter(IRepository<TRecord> repository) {
|
|
||||||
_repository = repository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AutomaticallyCreateMissingRecord { get; set; }
|
protected override TRecord GetRecord(LoadContentContext context) {
|
||||||
|
return _repository.Get(context.ContentItemVersionRecord.Id);
|
||||||
protected override void Activated(ActivatedContentContext context, ContentPart<TRecord> instance) {
|
|
||||||
instance.Record = new TRecord();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Creating(CreateContentContext context, ContentPart<TRecord> instance) {
|
protected override void Creating(CreateContentContext context, ContentPart<TRecord> instance) {
|
||||||
@@ -55,18 +71,6 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
_repository.Create(instance.Record);
|
_repository.Create(instance.Record);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Loading(LoadContentContext context, ContentPart<TRecord> instance) {
|
|
||||||
var record = _repository.Get(context.ContentItemVersionRecord.Id);
|
|
||||||
if (record != null) {
|
|
||||||
instance.Record = record;
|
|
||||||
}
|
|
||||||
else if (AutomaticallyCreateMissingRecord) {
|
|
||||||
instance.Record.ContentItemRecord = context.ContentItemRecord;
|
|
||||||
instance.Record.ContentItemVersionRecord = context.ContentItemVersionRecord;
|
|
||||||
_repository.Create(instance.Record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Versioning(VersionContentContext context, ContentPart<TRecord> existing, ContentPart<TRecord> building) {
|
protected override void Versioning(VersionContentContext context, ContentPart<TRecord> existing, ContentPart<TRecord> building) {
|
||||||
// move known ORM values over
|
// move known ORM values over
|
||||||
_repository.Copy(existing.Record, building.Record);
|
_repository.Copy(existing.Record, building.Record);
|
||||||
|
|||||||
Reference in New Issue
Block a user