mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Implementing content part field change events and audit trail provider.
This commit is contained in:
@@ -3,6 +3,11 @@ using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.AuditTrail.Helpers {
|
||||
public static class SettingsDictionaryExtensions {
|
||||
|
||||
public static string Get(this SettingsDictionary settings, string key) {
|
||||
return settings.ContainsKey(key) ? settings[key] : null;
|
||||
}
|
||||
|
||||
public static DiffDictionary<string, string> GetDiff(this SettingsDictionary oldSettings, SettingsDictionary newSettings) {
|
||||
var dictionary = new DiffDictionary<string, string>();
|
||||
|
||||
|
@@ -199,13 +199,13 @@
|
||||
<Compile Include="Services\Models\Filters.cs" />
|
||||
<Compile Include="Providers\Content\IDiffGramAnalyzer.cs" />
|
||||
<Compile Include="Services\AuditTrailTrimmingBackgroundTask.cs" />
|
||||
<Compile Include="Shapes\AuditTrailFilterShapes.cs" />
|
||||
<Compile Include="Providers\AuditTrail\AuditTrailFilterShapes.cs" />
|
||||
<Compile Include="Shapes\AuditTrailEventShapeAlteration.cs" />
|
||||
<Compile Include="Shapes\ContentTypeFieldSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Shapes\ContentPartSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Shapes\ContentTypePartSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Shapes\ContentTypeSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Shapes\AuditTrailSettingsEventShape.cs" />
|
||||
<Compile Include="Providers\ContentDefinition\Shapes\ContentTypeFieldSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Providers\ContentDefinition\Shapes\ContentPartSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Providers\ContentDefinition\Shapes\ContentTypePartSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Providers\ContentDefinition\Shapes\ContentTypeSettingsUpdatedEventShape.cs" />
|
||||
<Compile Include="Providers\AuditTrail\AuditTrailSettingsEventShape.cs" />
|
||||
<Compile Include="Services\Models\Diff.cs" />
|
||||
<Compile Include="Services\Models\DiffDictionary.cs" />
|
||||
<Compile Include="ViewModels\AuditTrailCategorySettingsViewModel.cs" />
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System.IO;
|
||||
using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
namespace Orchard.AuditTrail.Providers.AuditTrail {
|
||||
public class AuditTrailFilterShapes : IDependency {
|
||||
[Shape]
|
||||
public void AuditTrailFilterDisplay(dynamic Shape, dynamic Display, TextWriter Output) {
|
@@ -1,13 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.AuditTrail.Models;
|
||||
using Orchard.AuditTrail.Providers.AuditTrail;
|
||||
using Orchard.AuditTrail.Services;
|
||||
using Orchard.AuditTrail.Shapes;
|
||||
using Orchard.AuditTrail.ViewModels;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
namespace Orchard.AuditTrail.Providers.AuditTrail {
|
||||
public class AuditTrailSettingsEventShape : AuditTrailEventShapeAlteration<SettingsAuditTrailEventProvider> {
|
||||
private readonly Work<IAuditTrailManager> _auditTrailManager;
|
||||
public AuditTrailSettingsEventShape(Work<IAuditTrailManager> auditTrailManager) {
|
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Services;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
@@ -103,11 +104,10 @@ namespace Orchard.AuditTrail.Providers.ContentDefinition {
|
||||
var eventData = new Dictionary<string, object> {
|
||||
{"ContentFieldName", builder.Name},
|
||||
{"ContentPartName", builder.PartName},
|
||||
{"ContentTypeName", _currentContentType.Name},
|
||||
{"OldSettings", ToXml(_oldContentPartFieldSettings)},
|
||||
{"NewSettings", ToXml(newSettings)}
|
||||
};
|
||||
RecordContentTypeAuditTrail(ContentTypeAuditTrailEventProvider.FieldSettingsUpdated, eventData, _currentContentType.Name);
|
||||
RecordContentPartAuditTrail(ContentPartAuditTrailEventProvider.FieldSettingsUpdated, eventData, builder.PartName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Providers.ContentDefinition;
|
||||
using Orchard.AuditTrail.Shapes;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
namespace Orchard.AuditTrail.Providers.ContentDefinition.Shapes {
|
||||
public class ContentPartSettingsUpdatedEventShape : AuditTrailEventShapeAlteration<ContentPartAuditTrailEventProvider> {
|
||||
private readonly ISettingsFormatter _settingsFormatter;
|
||||
public ContentPartSettingsUpdatedEventShape(ISettingsFormatter settingsFormatter) {
|
@@ -1,18 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Providers.ContentDefinition;
|
||||
using Orchard.AuditTrail.Shapes;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
public class ContentTypeFieldSettingsUpdatedEventShape : AuditTrailEventShapeAlteration<ContentTypeAuditTrailEventProvider> {
|
||||
namespace Orchard.AuditTrail.Providers.ContentDefinition.Shapes {
|
||||
public class ContentTypeFieldSettingsUpdatedEventShape : AuditTrailEventShapeAlteration<ContentPartAuditTrailEventProvider> {
|
||||
private readonly ISettingsFormatter _settingsFormatter;
|
||||
public ContentTypeFieldSettingsUpdatedEventShape(ISettingsFormatter settingsFormatter) {
|
||||
_settingsFormatter = settingsFormatter;
|
||||
}
|
||||
|
||||
protected override string EventName {
|
||||
get { return ContentTypeAuditTrailEventProvider.FieldSettingsUpdated; }
|
||||
get { return ContentPartAuditTrailEventProvider.FieldSettingsUpdated; }
|
||||
}
|
||||
|
||||
protected override void OnAlterShape(ShapeDisplayingContext context) {
|
||||
@@ -22,7 +23,9 @@ namespace Orchard.AuditTrail.Shapes {
|
||||
var diff = oldSettings.GetDiff(newSettings);
|
||||
|
||||
context.Shape.OldSettings = oldSettings;
|
||||
context.Shape.OldDisplayName = oldSettings.Get(ContentPartFieldDefinition.DisplayNameKey);
|
||||
context.Shape.NewSettings = newSettings;
|
||||
context.Shape.NewDisplayName = newSettings.Get(ContentPartFieldDefinition.DisplayNameKey);
|
||||
context.Shape.Diff = diff;
|
||||
}
|
||||
}
|
@@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Providers.ContentDefinition;
|
||||
using Orchard.AuditTrail.Shapes;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
namespace Orchard.AuditTrail.Providers.ContentDefinition.Shapes {
|
||||
public class ContentTypePartSettingsUpdatedEventShape : AuditTrailEventShapeAlteration<ContentTypeAuditTrailEventProvider> {
|
||||
private readonly ISettingsFormatter _settingsFormatter;
|
||||
public ContentTypePartSettingsUpdatedEventShape(ISettingsFormatter settingsFormatter) {
|
@@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.AuditTrail.Helpers;
|
||||
using Orchard.AuditTrail.Providers.ContentDefinition;
|
||||
using Orchard.AuditTrail.Shapes;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
|
||||
namespace Orchard.AuditTrail.Shapes {
|
||||
namespace Orchard.AuditTrail.Providers.ContentDefinition.Shapes {
|
||||
public class ContentTypeSettingsUpdatedEventShape : AuditTrailEventShapeAlteration<ContentTypeAuditTrailEventProvider> {
|
||||
private readonly ISettingsFormatter _settingsFormatter;
|
||||
public ContentTypeSettingsUpdatedEventShape(ISettingsFormatter settingsFormatter) {
|
@@ -3,8 +3,10 @@
|
||||
var eventData = (IDictionary<string, object>) Model.EventData;
|
||||
var contentPartName = eventData.Get<string>("ContentPartName");
|
||||
var contentFieldName = eventData.Get<string>("ContentFieldName");
|
||||
var oldDisplayName = (string)Model.OldDisplayName;
|
||||
var newDisplayName = (string)Model.NewDisplayName;
|
||||
}
|
||||
|
||||
<section class="audittrail-contentpart-summary">
|
||||
@T("Settings for the <strong>{0}</strong> content field of the <strong>{1}</strong> content part were updated.", contentFieldName, contentPartName)
|
||||
@T("The <strong>{0}</strong> content field of the <strong>{1}</strong> content part was renamed from <strong>{2}</strong> to <strong>{3}</strong>.", contentFieldName, contentPartName, oldDisplayName, newDisplayName)
|
||||
</section>
|
@@ -621,14 +621,7 @@ namespace Orchard.ContentTypes.Controllers {
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
_contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder => {
|
||||
partBuilder.WithField(viewModel.Name, fieldBuilder => {
|
||||
fieldBuilder.WithDisplayName(viewModel.DisplayName);
|
||||
});
|
||||
});
|
||||
|
||||
//field.DisplayName = viewModel.DisplayName;
|
||||
//_contentDefinitionManager.StorePartDefinition(partViewModel._Definition);
|
||||
_contentDefinitionService.AlterField(partViewModel, viewModel);
|
||||
|
||||
Services.Notifier.Information(T("Display name changed to {0}.", viewModel.DisplayName));
|
||||
|
||||
|
@@ -294,6 +294,16 @@ namespace Orchard.ContentTypes.Services {
|
||||
});
|
||||
}
|
||||
|
||||
public void AlterField(EditPartViewModel partViewModel, EditFieldNameViewModel fieldViewModel) {
|
||||
_contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder => {
|
||||
partBuilder.WithField(fieldViewModel.Name, fieldBuilder => {
|
||||
_contentDefinitionEditorEvents.PartFieldEditorUpdating(fieldBuilder);
|
||||
fieldBuilder.WithDisplayName(fieldViewModel.DisplayName);
|
||||
_contentDefinitionEditorEvents.PartFieldEditorUpdated(fieldBuilder);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public string GenerateContentTypeNameFromDisplayName(string displayName) {
|
||||
displayName = displayName.ToSafeName();
|
||||
|
||||
|
@@ -26,5 +26,6 @@ namespace Orchard.ContentTypes.Services {
|
||||
void AddFieldToPart(string fieldName, string fieldTypeName, string partName);
|
||||
void AddFieldToPart(string fieldName, string displayName, string fieldTypeName, string partName);
|
||||
void RemoveFieldFromPart(string fieldName, string partName);
|
||||
void AlterField(EditPartViewModel partViewModel, EditFieldNameViewModel fieldViewModel);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user