#194: Implemented the missing ContentPart.DescriptionChanged event.

This commit is contained in:
Daniel Stolt
2014-07-20 16:44:49 +02:00
parent 104c051783
commit 15bdcadd4f
4 changed files with 35 additions and 5 deletions

View File

@@ -139,6 +139,7 @@
<Content Include="Views\AuditTrailEvent-Role-Removed.cshtml" />
<Content Include="Views\AuditTrailEvent-Role-UserAdded.cshtml" />
<Content Include="Views\AuditTrailEvent-Role-UserRemoved.cshtml" />
<Content Include="Views\AuditTrailEvent-ContentPart-DescriptionChanged.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">

View File

@@ -15,6 +15,7 @@ using Orchard.Environment.Extensions;
namespace Orchard.AuditTrail.Providers.ContentDefinition {
[OrchardFeature("Orchard.AuditTrail.ContentDefinition")]
public class GlobalContentDefinitionEditorEvents : ContentDefinitionEditorEventsBase {
private const string _contentPartSettingsDescriptionName = "ContentPartSettings.Description";
private readonly IAuditTrailManager _auditTrailManager;
private readonly IWorkContextAccessor _wca;
private readonly IContentDefinitionService _contentDefinitionService;
@@ -118,13 +119,30 @@ namespace Orchard.AuditTrail.Providers.ContentDefinition {
public override void PartEditorUpdated(ContentPartDefinitionBuilder builder) {
var contentPartDefinition = builder.Build();
var newSettings = contentPartDefinition.Settings;
var newPartSettings = contentPartDefinition.Settings;
if (!AreEqual(newSettings, _oldPartSettings)) {
if (newPartSettings.ContainsKey(_contentPartSettingsDescriptionName)) {
var oldDescription = _oldPartSettings.Get(_contentPartSettingsDescriptionName);
var newDescription = newPartSettings.Get(_contentPartSettingsDescriptionName);
if (oldDescription != newDescription) {
var eventData = new Dictionary<string, object> {
{"ContentPartName", builder.Name},
{"OldDescription", oldDescription},
{"NewDescription", newDescription}
};
RecordContentPartAuditTrail(ContentPartAuditTrailEventProvider.DescriptionChanged, eventData, builder.Name);
}
}
// Description change should not be re-recorded as general settings change.
var remainingOldPartSettings = new SettingsDictionary(_oldPartSettings.Where(item => item.Key != _contentPartSettingsDescriptionName).ToDictionary(item => item.Key, item => item.Value));
var remainingNewPartSettings = new SettingsDictionary(newPartSettings.Where(item => item.Key != _contentPartSettingsDescriptionName).ToDictionary(item => item.Key, item => item.Value));
if (!AreEqual(remainingNewPartSettings, remainingOldPartSettings)) {
var eventData = new Dictionary<string, object> {
{"ContentPartName", builder.Name},
{"OldSettings", ToXml(_oldPartSettings)},
{"NewSettings", ToXml(newSettings)}
{"OldSettings", ToXml(remainingOldPartSettings)},
{"NewSettings", ToXml(remainingNewPartSettings)}
};
RecordContentPartAuditTrail(ContentPartAuditTrailEventProvider.PartSettingsUpdated, eventData, builder.Name);
}

View File

@@ -0,0 +1,11 @@
@using Orchard.AuditTrail.Helpers
@{
var eventData = (IDictionary<string, object>) Model.EventData;
var contentPartName = eventData.Get<string>("ContentPartName");
var oldDescription = eventData.Get<string>("OldDescription");
var newDescription = eventData.Get<string>("NewDescription");
}
<section class="audittrail-contentpart-summary">
@T("The description of content part <strong>{0}</strong> was changed from <strong>{1}</strong> to <strong>{2}</strong>.", contentPartName, oldDescription.OrIfEmpty(T("[Empty]")), newDescription.OrIfEmpty(T("[Empty]")))
</section>

View File

@@ -7,5 +7,5 @@
}
<section>
@T("The display name for the content type <strong>{0}</strong> was changed from <strong>{1}</strong> to <strong>{2}</strong>.", contentTypeName, oldDisplayName, newDisplayName)
@T("The display name for the content type <strong>{0}</strong> was changed from <strong>{1}</strong> to <strong>{2}</strong>.", contentTypeName, oldDisplayName.OrIfEmpty(T("[Empty]")), newDisplayName.OrIfEmpty(T("[Empty]")))
</section>