mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Merge
--HG-- branch : 1.x
This commit is contained in:
35
src/Orchard.Tests/ContentManagement/ContentIdentityTests.cs
Normal file
35
src/Orchard.Tests/ContentManagement/ContentIdentityTests.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Tests.ContentManagement {
|
||||
[TestFixture]
|
||||
public class ContentIdentityTests {
|
||||
[Test]
|
||||
public void ContentIdentityParsesIdentities() {
|
||||
var identity1 = new ContentIdentity("/foo=bar");
|
||||
Assert.That(identity1.Get("foo"), Is.EqualTo("bar"));
|
||||
|
||||
var identity2 = new ContentIdentity("/foo=");
|
||||
Assert.That(identity2.Get("foo"), Is.EqualTo(String.Empty));
|
||||
|
||||
var identity3 = new ContentIdentity("foo");
|
||||
Assert.That(identity3.Get("foo"), Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContentIdentitiesAreEncodedWhenOutput() {
|
||||
var identity1 = new ContentIdentity("/foo=bar");
|
||||
Assert.That(identity1.ToString(), Is.EqualTo("/foo=bar"));
|
||||
|
||||
var identity2 = new ContentIdentity(@"/foo=bar/abaz=quux\/fr\\ed=foo/yarg=yiu=foo");
|
||||
Assert.That(identity2.Get("foo"), Is.EqualTo("bar"));
|
||||
Assert.That(identity2.Get("abaz"), Is.EqualTo(@"quux/fr\ed=foo"));
|
||||
Assert.That(identity2.Get("yarg"), Is.EqualTo("yiu=foo"));
|
||||
Assert.That(identity2.ToString(), Is.EqualTo(@"/foo=bar/abaz=quux\/fr\\ed=foo/yarg=yiu=foo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
|
||||
var contentHandler = _container.Resolve<IContentHandler>();
|
||||
|
||||
var contentItem = new ContentItem();
|
||||
var context = new BuildDisplayContext(null, contentItem, "", new Mock<IShapeFactory>().Object);
|
||||
var context = new BuildDisplayContext(null, contentItem, "", "", new Mock<IShapeFactory>().Object);
|
||||
|
||||
driver1.Verify(x => x.BuildDisplay(context), Times.Never());
|
||||
driver2.Verify(x => x.BuildDisplay(context), Times.Never());
|
||||
@@ -64,7 +64,7 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
|
||||
var contentItem = new ContentItem();
|
||||
contentItem.Weld(new StubPart { Foo = new[] { "a", "b", "c" } });
|
||||
|
||||
var ctx = new BuildDisplayContext(null, null, "", null);
|
||||
var ctx = new BuildDisplayContext(null, null, "", "", null);
|
||||
var context = shapeFactory.Context(ctx);
|
||||
Assert.That(context.TopMeta, Is.Null);
|
||||
contentHandler.BuildDisplay(ctx);
|
||||
|
||||
@@ -165,9 +165,10 @@
|
||||
<Compile Include="Commands\CommandHandlerDescriptorBuilderTests.cs" />
|
||||
<Compile Include="Commands\CommandHandlerTests.cs" />
|
||||
<Compile Include="Commands\CommandManagerTests.cs" />
|
||||
<Compile Include="ContentManagement\ContentQueryTests.cs">
|
||||
<Compile Include="ContentManagement\ContentIdentityTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\ContentQueryTests.cs" />
|
||||
<Compile Include="ContentManagement\DefaultContentManagerTests.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -14,20 +14,19 @@ namespace Orchard.Comments.Drivers {
|
||||
|
||||
protected override string Prefix { get { return "CommentSettings"; } }
|
||||
|
||||
protected override DriverResult Editor(CommentSettingsPart part, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "comments", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
return ContentShape("Parts_Comments_SiteSettings",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Comments.SiteSettings", Model: part.Record, Prefix: Prefix));
|
||||
protected override DriverResult Editor(CommentSettingsPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(CommentSettingsPart part, IUpdateModel updater, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "comments", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
protected override DriverResult Editor(CommentSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
|
||||
updater.TryUpdateModel(part.Record, Prefix, null, null);
|
||||
return Editor(part, shapeHelper);
|
||||
return ContentShape("Parts_Comments_SiteSettings", () => {
|
||||
if (updater != null) {
|
||||
updater.TryUpdateModel(part.Record, Prefix, null, null);
|
||||
}
|
||||
return shapeHelper.EditorTemplate(TemplateName: "Parts.Comments.SiteSettings", Model: part.Record, Prefix: Prefix);
|
||||
})
|
||||
.OnGroup("comments");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,28 +20,24 @@ namespace Orchard.Email.Drivers {
|
||||
|
||||
protected override string Prefix { get { return "SmtpSettings"; } }
|
||||
|
||||
protected override DriverResult Editor(SmtpSettingsPart part, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "email", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
protected override DriverResult Editor(SmtpSettingsPart part, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_SmtpSettings_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix));
|
||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix))
|
||||
.OnGroup("email");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(SmtpSettingsPart part, IUpdateModel updater, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "email", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
protected override DriverResult Editor(SmtpSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_SmtpSettings_Edit", () => {
|
||||
var previousPassword = part.Password;
|
||||
updater.TryUpdateModel(part, Prefix, null, null);
|
||||
|
||||
var previousPassword = part.Password;
|
||||
updater.TryUpdateModel(part, Prefix, null, null);
|
||||
|
||||
// restore password if the input is empty, meaning it has not been reseted
|
||||
if (string.IsNullOrEmpty(part.Password)) {
|
||||
part.Password = previousPassword;
|
||||
}
|
||||
|
||||
return ContentShape("Parts_SmtpSettings_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix));
|
||||
// restore password if the input is empty, meaning it has not been reseted
|
||||
if (string.IsNullOrEmpty(part.Password)) {
|
||||
part.Password = previousPassword;
|
||||
}
|
||||
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix);
|
||||
})
|
||||
.OnGroup("email");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,35 +23,33 @@ namespace Orchard.Search.Drivers {
|
||||
|
||||
protected override string Prefix { get { return "SearchSettings"; } }
|
||||
|
||||
protected override DriverResult Editor(SearchSettingsPart part, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "search", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
SearchSettingsViewModel model = new SearchSettingsViewModel();
|
||||
String [] searchedFields = part.SearchedFields;
|
||||
|
||||
if (_indexManager.HasIndexProvider()) {
|
||||
model.Entries = new List<SearchSettingsEntry>();
|
||||
foreach (var field in _indexManager.GetSearchIndexProvider().GetFields(SearchIndexName)) {
|
||||
model.Entries.Add(new SearchSettingsEntry { Field = field, Selected = searchedFields.Contains(field) });
|
||||
}
|
||||
}
|
||||
|
||||
return ContentShape("Parts_Search_SiteSettings",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts/Search.SiteSettings", Model: model, Prefix: Prefix));
|
||||
protected override DriverResult Editor(SearchSettingsPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(SearchSettingsPart part, IUpdateModel updater, string groupInfoId, dynamic shapeHelper) {
|
||||
if (!string.Equals(groupInfoId, "search", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
protected override DriverResult Editor(SearchSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
return ContentShape("Parts_Search_SiteSettings", () => {
|
||||
SearchSettingsViewModel model = new SearchSettingsViewModel();
|
||||
String[] searchedFields = part.SearchedFields;
|
||||
|
||||
SearchSettingsViewModel model = new SearchSettingsViewModel();
|
||||
if (updater != null) {
|
||||
// submitting: rebuild model from form data
|
||||
if (updater.TryUpdateModel(model, Prefix, null, null)) {
|
||||
// update part if successful
|
||||
part.SearchedFields = model.Entries.Where(e => e.Selected).Select(e => e.Field).ToArray();
|
||||
}
|
||||
}
|
||||
else if (_indexManager.HasIndexProvider()) {
|
||||
// viewing editor: build model from part
|
||||
model.Entries = new List<SearchSettingsEntry>();
|
||||
foreach (var field in _indexManager.GetSearchIndexProvider().GetFields(SearchIndexName)) {
|
||||
model.Entries.Add(new SearchSettingsEntry { Field = field, Selected = searchedFields.Contains(field) });
|
||||
}
|
||||
}
|
||||
|
||||
if (updater.TryUpdateModel(model, Prefix, null, null)) {
|
||||
part.SearchedFields = model.Entries.Where(e => e.Selected).Select(e => e.Field).ToArray();
|
||||
}
|
||||
|
||||
return Editor(part, shapeHelper);
|
||||
return shapeHelper.EditorTemplate(TemplateName: "Parts/Search.SiteSettings", Model: model, Prefix: Prefix);
|
||||
}).OnGroup("search");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,11 @@ namespace Orchard.ContentManagement {
|
||||
public ContentIdentity(string identity) {
|
||||
_dictionary = new Dictionary<string, string>();
|
||||
if (!String.IsNullOrEmpty(identity)) {
|
||||
var identityEntries = identity.Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var token in identityEntries) {
|
||||
var kv = token.Split(new[] {"="}, StringSplitOptions.None);
|
||||
if (kv.Length == 2) {
|
||||
_dictionary.Add(kv[0], kv[1]);
|
||||
var identityEntries = GetIdentityEntries(identity);
|
||||
foreach (var identityEntry in identityEntries) {
|
||||
var keyValuePair = GetIdentityKeyValue(identityEntry);
|
||||
if (keyValuePair != null) {
|
||||
_dictionary.Add(keyValuePair.Value.Key, UnencodeIdentityValue(keyValuePair.Value.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,101 @@ namespace Orchard.ContentManagement {
|
||||
public override string ToString() {
|
||||
var stringBuilder = new StringBuilder();
|
||||
foreach (var key in _dictionary.Keys) {
|
||||
stringBuilder.Append("/" + key + "=" + _dictionary[key]);
|
||||
var escapedIdentity = EncodeIdentityValue(_dictionary[key]);
|
||||
stringBuilder.Append("/" + key + "=" + escapedIdentity);
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static string EncodeIdentityValue(string identityValue) {
|
||||
var stringBuilder = new StringBuilder();
|
||||
foreach (var ch in identityValue.ToCharArray()) {
|
||||
switch (ch) {
|
||||
case '\\':
|
||||
stringBuilder.Append('\\');
|
||||
stringBuilder.Append('\\');
|
||||
break;
|
||||
case '/':
|
||||
stringBuilder.Append('\\');
|
||||
stringBuilder.Append('/');
|
||||
break;
|
||||
default:
|
||||
stringBuilder.Append(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static string UnencodeIdentityValue(string identityValue) {
|
||||
var stringBuilder = new StringBuilder();
|
||||
var identityChars = identityValue.ToCharArray();
|
||||
var length = identityChars.Length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
switch (identityChars[i]) {
|
||||
case '\\':
|
||||
if (i + 1 < length) {
|
||||
if (identityChars[i + 1] == '\\') {
|
||||
stringBuilder.Append('\\');
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
stringBuilder.Append('\\');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
stringBuilder.Append(identityChars[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetIdentityEntries(string identity) {
|
||||
var identityEntries = new List<string>();
|
||||
var stringBuilder = new StringBuilder();
|
||||
var escaping = false;
|
||||
foreach (var ch in identity.ToCharArray()) {
|
||||
if (escaping) {
|
||||
stringBuilder.Append(ch);
|
||||
escaping = false;
|
||||
}
|
||||
else {
|
||||
if (ch == '/') {
|
||||
if (stringBuilder.Length > 0) {
|
||||
identityEntries.Add(stringBuilder.ToString());
|
||||
stringBuilder.Clear();
|
||||
}
|
||||
stringBuilder.Append(ch);
|
||||
}
|
||||
else {
|
||||
if (ch == '\\') {
|
||||
escaping = true;
|
||||
}
|
||||
stringBuilder.Append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
identityEntries.Add(stringBuilder.ToString());
|
||||
|
||||
return identityEntries;
|
||||
}
|
||||
|
||||
private static KeyValuePair<string, string>? GetIdentityKeyValue(string identityEntry) {
|
||||
if (String.IsNullOrWhiteSpace(identityEntry)) return null;
|
||||
if (!identityEntry.StartsWith("/")) return null;
|
||||
var indexOfEquals = identityEntry.IndexOf("=");
|
||||
if (indexOfEquals < 0) return null;
|
||||
|
||||
var key = identityEntry.Substring(1, indexOfEquals - 1);
|
||||
var value = identityEntry.Substring(indexOfEquals + 1);
|
||||
|
||||
return new KeyValuePair<string, string>(key, value);
|
||||
}
|
||||
|
||||
|
||||
public class ContentIdentityEqualityComparer : IEqualityComparer<ContentIdentity> {
|
||||
public bool Equals(ContentIdentity contentIdentity1, ContentIdentity contentIdentity2) {
|
||||
if (contentIdentity1._dictionary.Keys.Count != contentIdentity2._dictionary.Keys.Count)
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public dynamic BuildDisplay(IContent content, string displayType) {
|
||||
public dynamic BuildDisplay(IContent content, string displayType, string groupId) {
|
||||
var contentTypeDefinition = content.ContentItem.TypeDefinition;
|
||||
string stereotype;
|
||||
if (!contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype))
|
||||
@@ -47,14 +47,14 @@ namespace Orchard.ContentManagement {
|
||||
itemShape.ContentItem = content.ContentItem;
|
||||
itemShape.Metadata.DisplayType = actualDisplayType;
|
||||
|
||||
var context = new BuildDisplayContext(itemShape, content, actualDisplayType, _shapeFactory);
|
||||
var context = new BuildDisplayContext(itemShape, content, actualDisplayType, groupId, _shapeFactory);
|
||||
BindPlacement(context, actualDisplayType, stereotype);
|
||||
|
||||
_handlers.Value.Invoke(handler => handler.BuildDisplay(context), Logger);
|
||||
return context.Shape;
|
||||
}
|
||||
|
||||
public dynamic BuildEditor(IContent content, string groupInfoId) {
|
||||
public dynamic BuildEditor(IContent content, string groupId) {
|
||||
var contentTypeDefinition = content.ContentItem.TypeDefinition;
|
||||
string stereotype;
|
||||
if (!contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype))
|
||||
@@ -65,7 +65,7 @@ namespace Orchard.ContentManagement {
|
||||
dynamic itemShape = CreateItemShape(actualShapeType);
|
||||
itemShape.ContentItem = content.ContentItem;
|
||||
|
||||
var context = new BuildEditorContext(itemShape, content, groupInfoId, _shapeFactory);
|
||||
var context = new BuildEditorContext(itemShape, content, groupId, _shapeFactory);
|
||||
BindPlacement(context, null, stereotype);
|
||||
|
||||
_handlers.Value.Invoke(handler => handler.BuildEditor(context), Logger);
|
||||
|
||||
@@ -386,16 +386,16 @@ namespace Orchard.ContentManagement {
|
||||
return GetDisplayGroupInfos(content).FirstOrDefault(gi => string.Equals(gi.Id, groupInfoId, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public dynamic BuildDisplay(IContent content, string displayType = "") {
|
||||
return _contentDisplay.Value.BuildDisplay(content, displayType);
|
||||
public dynamic BuildDisplay(IContent content, string displayType = "", string groupId = "") {
|
||||
return _contentDisplay.Value.BuildDisplay(content, displayType, groupId);
|
||||
}
|
||||
|
||||
public dynamic BuildEditor(IContent content, string groupInfoId = "") {
|
||||
return _contentDisplay.Value.BuildEditor(content, groupInfoId);
|
||||
public dynamic BuildEditor(IContent content, string groupId = "") {
|
||||
return _contentDisplay.Value.BuildEditor(content, groupId);
|
||||
}
|
||||
|
||||
public dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupInfoId = "") {
|
||||
return _contentDisplay.Value.UpdateEditor(content, updater, groupInfoId);
|
||||
public dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupId = "") {
|
||||
return _contentDisplay.Value.UpdateEditor(content, updater, groupId);
|
||||
}
|
||||
|
||||
public IContentQuery<ContentItem> Query() {
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
protected virtual string Prefix { get { return ""; } }
|
||||
protected virtual string Zone { get { return "Content"; } }
|
||||
|
||||
void IContentFieldDriver.GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
Process(context.ContentItem, (part, field) => GetContentItemMetadata(part, field, context.Metadata));
|
||||
}
|
||||
|
||||
DriverResult IContentFieldDriver.BuildDisplayShape(BuildDisplayContext context) {
|
||||
return Process(context.ContentItem, (part, field) => Display(part, field, context.DisplayType, context.New));
|
||||
}
|
||||
@@ -24,31 +28,26 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
}
|
||||
|
||||
void IContentFieldDriver.Importing(ImportContentContext context) {
|
||||
Process(context.ContentItem, (part, field) => {
|
||||
Importing(part, field, context);
|
||||
return null;
|
||||
});
|
||||
Process(context.ContentItem, (part, field) => Importing(part, field, context));
|
||||
}
|
||||
|
||||
void IContentFieldDriver.Imported(ImportContentContext context) {
|
||||
Process(context.ContentItem, (part, field) => {
|
||||
Imported(part, field, context);
|
||||
return null;
|
||||
});
|
||||
Process(context.ContentItem, (part, field) => Imported(part, field, context));
|
||||
}
|
||||
|
||||
void IContentFieldDriver.Exporting(ExportContentContext context) {
|
||||
Process(context.ContentItem, (part, field) => {
|
||||
Exporting(part, field, context);
|
||||
return null;
|
||||
});
|
||||
Process(context.ContentItem, (part, field) => Exporting(part, field, context));
|
||||
}
|
||||
|
||||
void IContentFieldDriver.Exported(ExportContentContext context) {
|
||||
Process(context.ContentItem, (part, field) => {
|
||||
Exported(part, field, context);
|
||||
return null;
|
||||
});
|
||||
Process(context.ContentItem, (part, field) => Exported(part, field, context));
|
||||
}
|
||||
|
||||
void Process(ContentItem item, Action<ContentPart, TField> effort) {
|
||||
var occurences = item.Parts.SelectMany(part => part.Fields.OfType<TField>().Select(field => new { part, field }));
|
||||
foreach (var occurence in occurences) {
|
||||
effort(occurence.part, occurence.field);
|
||||
}
|
||||
}
|
||||
|
||||
DriverResult Process(ContentItem item, Func<ContentPart, TField, DriverResult> effort) {
|
||||
@@ -72,9 +71,12 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
return contentFieldInfo;
|
||||
}
|
||||
|
||||
protected virtual void GetContentItemMetadata(ContentPart part, TField field, ContentItemMetadata metadata) { return; }
|
||||
|
||||
protected virtual DriverResult Display(ContentPart part, TField field, string displayType, dynamic shapeHelper) { return null; }
|
||||
protected virtual DriverResult Editor(ContentPart part, TField field, dynamic shapeHelper) { return null; }
|
||||
protected virtual DriverResult Editor(ContentPart part, TField field, IUpdateModel updater, dynamic shapeHelper) { return null; }
|
||||
|
||||
protected virtual void Importing(ContentPart part, TField field, ImportContentContext context) { }
|
||||
protected virtual void Imported(ContentPart part, TField field, ImportContentContext context) { }
|
||||
protected virtual void Exporting(ContentPart part, TField field, ExportContentContext context) { }
|
||||
|
||||
@@ -9,6 +9,12 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
public abstract class ContentPartDriver<TContent> : IContentPartDriver where TContent : ContentPart, new() {
|
||||
protected virtual string Prefix { get { return ""; } }
|
||||
|
||||
void IContentPartDriver.GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
var part = context.ContentItem.As<TContent>();
|
||||
if (part != null)
|
||||
GetContentItemMetadata(part, context.Metadata);
|
||||
}
|
||||
|
||||
DriverResult IContentPartDriver.BuildDisplay(BuildDisplayContext context) {
|
||||
var part = context.ContentItem.As<TContent>();
|
||||
return part == null ? null : Display(part, context.DisplayType, context.New);
|
||||
@@ -16,16 +22,12 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
|
||||
DriverResult IContentPartDriver.BuildEditor(BuildEditorContext context) {
|
||||
var part = context.ContentItem.As<TContent>();
|
||||
return part == null
|
||||
? null
|
||||
: !string.IsNullOrWhiteSpace(context.GroupInfoId) ? Editor(part, context.GroupInfoId, context.New) : Editor(part, context.New);
|
||||
return part == null ? null : Editor(part, context.New);
|
||||
}
|
||||
|
||||
DriverResult IContentPartDriver.UpdateEditor(UpdateEditorContext context) {
|
||||
var part = context.ContentItem.As<TContent>();
|
||||
return part == null
|
||||
? null
|
||||
: !string.IsNullOrWhiteSpace(context.GroupInfoId) ? Editor(part, context.Updater, context.GroupInfoId, context.New) : Editor(part, context.Updater, context.New);
|
||||
return part == null ? null : Editor(part, context.Updater, context.New);
|
||||
}
|
||||
|
||||
void IContentPartDriver.Importing(ImportContentContext context) {
|
||||
@@ -52,11 +54,12 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
Exported(part, context);
|
||||
}
|
||||
|
||||
protected virtual void GetContentItemMetadata(TContent context, ContentItemMetadata metadata) { return; }
|
||||
|
||||
protected virtual DriverResult Display(TContent part, string displayType, dynamic shapeHelper) { return null; }
|
||||
protected virtual DriverResult Editor(TContent part, dynamic shapeHelper) { return null; }
|
||||
protected virtual DriverResult Editor(TContent part, string groupInfoId, dynamic shapeHelper) { return null; }
|
||||
protected virtual DriverResult Editor(TContent part, IUpdateModel updater, dynamic shapeHelper) { return null; }
|
||||
protected virtual DriverResult Editor(TContent part, IUpdateModel updater, string groupInfoId, dynamic shapeHelper) { return null; }
|
||||
|
||||
protected virtual void Importing(TContent part, ImportContentContext context) { return; }
|
||||
protected virtual void Imported(TContent part, ImportContentContext context) { return; }
|
||||
protected virtual void Exporting(TContent part, ExportContentContext context) { return; }
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
private readonly string _shapeType;
|
||||
private readonly string _prefix;
|
||||
private readonly Func<BuildShapeContext, dynamic> _shapeBuilder;
|
||||
private string _groupId;
|
||||
|
||||
public ContentShapeResult(string shapeType, string prefix, Func<BuildShapeContext, dynamic> shapeBuilder) {
|
||||
_shapeType = shapeType;
|
||||
@@ -25,6 +26,9 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
}
|
||||
|
||||
private void ApplyImplementation(BuildShapeContext context, string displayType) {
|
||||
if (!string.Equals(context.GroupId ?? "", _groupId ?? "", StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
var placement = context.FindPlacement(_shapeType, _differentiator, _defaultLocation);
|
||||
if (string.IsNullOrEmpty(placement.Location) || placement.Location == "-")
|
||||
return;
|
||||
@@ -66,9 +70,15 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
_defaultLocation = zone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentShapeResult Differentiator(string differentiator) {
|
||||
_differentiator = differentiator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentShapeResult OnGroup(string groupId) {
|
||||
_groupId=groupId;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
_drivers.Invoke(driver => driver.GetContentItemMetadata(context), Logger);
|
||||
}
|
||||
|
||||
public override void BuildDisplay(BuildDisplayContext context) {
|
||||
_drivers.Invoke(driver => {
|
||||
var result = driver.BuildDisplayShape(context);
|
||||
|
||||
@@ -36,6 +36,10 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetContentItemMetadata(GetContentItemMetadataContext context) {
|
||||
_drivers.Invoke(driver => driver.GetContentItemMetadata(context), Logger);
|
||||
}
|
||||
|
||||
public override void BuildDisplay(BuildDisplayContext context) {
|
||||
_drivers.Invoke(driver => {
|
||||
var result = driver.BuildDisplay(context);
|
||||
|
||||
@@ -12,5 +12,6 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
void Exporting(ExportContentContext context);
|
||||
void Exported(ExportContentContext context);
|
||||
IEnumerable<ContentFieldInfo> GetFieldInfo();
|
||||
void GetContentItemMetadata(GetContentItemMetadataContext context);
|
||||
}
|
||||
}
|
||||
@@ -12,5 +12,6 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
void Exporting(ExportContentContext context);
|
||||
void Exported(ExportContentContext context);
|
||||
IEnumerable<ContentPartInfo> GetPartInfo();
|
||||
void GetContentItemMetadata(GetContentItemMetadataContext context);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.ContentManagement.Handlers {
|
||||
public class BuildDisplayContext : BuildShapeContext {
|
||||
public BuildDisplayContext(IShape model, IContent content, string displayType, IShapeFactory shapeFactory)
|
||||
: base(model, content, shapeFactory) {
|
||||
public BuildDisplayContext(IShape model, IContent content, string displayType, string groupId, IShapeFactory shapeFactory)
|
||||
: base(model, content, groupId, shapeFactory) {
|
||||
DisplayType = displayType;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,8 @@ using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.ContentManagement.Handlers {
|
||||
public class BuildEditorContext : BuildShapeContext {
|
||||
public BuildEditorContext(IShape model, IContent content, string groupInfoId, IShapeFactory shapeFactory)
|
||||
: base(model, content, shapeFactory) {
|
||||
GroupInfoId = groupInfoId;
|
||||
public BuildEditorContext(IShape model, IContent content, string groupId, IShapeFactory shapeFactory)
|
||||
: base(model, content, groupId, shapeFactory) {
|
||||
}
|
||||
|
||||
public string GroupInfoId { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,18 @@ using Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy;
|
||||
|
||||
namespace Orchard.ContentManagement.Handlers {
|
||||
public class BuildShapeContext {
|
||||
protected BuildShapeContext(IShape shape, IContent content, IShapeFactory shapeFactory) {
|
||||
protected BuildShapeContext(IShape shape, IContent content, string groupId, IShapeFactory shapeFactory) {
|
||||
Shape = shape;
|
||||
ContentItem = content.ContentItem;
|
||||
New = shapeFactory;
|
||||
GroupId = groupId;
|
||||
FindPlacement = (partType, differentiator, defaultLocation) => new PlacementInfo {Location = defaultLocation, Source = String.Empty};
|
||||
}
|
||||
|
||||
public dynamic Shape { get; private set; }
|
||||
public ContentItem ContentItem { get; private set; }
|
||||
public dynamic New { get; private set; }
|
||||
public string GroupId { get; private set; }
|
||||
|
||||
public Func<string, string, string, PlacementInfo> FindPlacement { get; set; }
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
}
|
||||
|
||||
protected override void BuildEditorShape(BuildEditorContext context, ContentPart<TRecord> part) {
|
||||
if (!string.IsNullOrWhiteSpace(_groupId) && !string.Equals(_groupId, context.GroupInfoId, StringComparison.OrdinalIgnoreCase))
|
||||
if (!string.Equals(_groupId, context.GroupId, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
var templateShape = context.New.EditorTemplate(TemplateName: _templateName, Model: part.Record, Prefix: _prefix);
|
||||
@@ -44,7 +44,7 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
}
|
||||
|
||||
protected override void UpdateEditorShape(UpdateEditorContext context, ContentPart<TRecord> part) {
|
||||
if (!string.IsNullOrWhiteSpace(_groupId) && !string.Equals(_groupId, context.GroupInfoId, StringComparison.OrdinalIgnoreCase))
|
||||
if (!string.Equals(_groupId, context.GroupId, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
context.Updater.TryUpdateModel(part.Record, _prefix, null, null);
|
||||
|
||||
@@ -33,15 +33,15 @@ namespace Orchard.ContentManagement {
|
||||
GroupInfo GetEditorGroupInfo(IContent contentItem, string groupInfoId);
|
||||
GroupInfo GetDisplayGroupInfo(IContent contentItem, string groupInfoId);
|
||||
|
||||
dynamic BuildDisplay(IContent content, string displayType = "");
|
||||
dynamic BuildEditor(IContent content, string groupInfoId = "");
|
||||
dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupInfoId = "");
|
||||
dynamic BuildDisplay(IContent content, string displayType = "", string groupId = "");
|
||||
dynamic BuildEditor(IContent content, string groupId = "");
|
||||
dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupId = "");
|
||||
}
|
||||
|
||||
public interface IContentDisplay : IDependency {
|
||||
dynamic BuildDisplay(IContent content, string displayType = "");
|
||||
dynamic BuildEditor(IContent content, string groupInfoId = "");
|
||||
dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupInfoId = "");
|
||||
dynamic BuildDisplay(IContent content, string displayType = "", string groupId = "");
|
||||
dynamic BuildEditor(IContent content, string groupId = "");
|
||||
dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupId = "");
|
||||
}
|
||||
|
||||
public class VersionOptions {
|
||||
|
||||
Reference in New Issue
Block a user