Skip to content

Commit

Permalink
tidy up report view, improve Json change detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Dec 9, 2019
1 parent 67946ce commit 2349275
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 103 deletions.
85 changes: 44 additions & 41 deletions uSync8.BackOffice/App_Plugins/uSync8/changeDialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,68 @@
hide-description="true">
</umb-editor-header>
<umb-editor-container>
<umb-box>
<umb-box-content>
<strong>uSync Beta</strong> We are working on making the change report better, for now you might see blank change reports.
</umb-box-content>
</umb-box>
<umb-box>
<umb-box-header title="{{vm.item.Name}}"
description="{{vm.getTypeName(vm.item.ItemType)}}">
description="{{vm.getTypeName(vm.item.ItemType)}} {{vm.item.Message}}">
</umb-box-header>
<umb-box-container>
<umb-box-content>
<p>
{{vm.item.Message}}
</p>

<div class="usync-item-details">
<div class="umb-table">
<div class="umb-table-head">
<div class="umb-table-row">
<div class="umb-table-cell"></div>
<div class="umb-table-cell usync-detail-action-cell">Action</div>
<div class="umb-table-cell umb-table__name">Item</div>
<div class="umb-table-cell">Old Value</div>
<div class="umb-table-cell">New Value</div>
</div>
</div>
<div class="umb-table-body">
<div ng-repeat="detail in vm.item.Details" class="umb-table-row"
ng-class="{'usync-row-delete': detail.Change == 'Delete', 'usync-row-create' : detail.Change == 'Create'}">
<div class="umb-table-cell">
<i ng-if="detail.Change == 'Create'" class="icon icon-add color-green"></i>
<i ng-if="detail.Change == 'NoChange'" class="icon icon-check color-green"></i>
<i ng-if="detail.Change == 'Update'" class="icon icon-sync color-orange"></i>
<i ng-if="detail.Change == 'Delete'" class="icon icon-wrong color-red"></i>
</div>
<div class="umb-table-cell usync-detail-action-cell">
{{detail.Change}}
<div ng-if="vm.item.Details.length > 0">
<h5>Detected changes</h5>
<div class="usync-item-details">
<div class="umb-table">
<div class="umb-table-head">
<div class="umb-table-row">
<div class="umb-table-cell"></div>
<div class="umb-table-cell usync-detail-action-cell">Action</div>
<div class="umb-table-cell umb-table__name">Item</div>
<div class="umb-table-cell">Old Value</div>
<div class="umb-table-cell">New Value</div>
</div>
<div class="umb-table-cell umb-table__name">
{{detail.Name}}
</div>
<div class="umb-table-cell usync-old-value">
{{detail.OldValue}}
</div>
<div class="umb-table-cell usync-new-value">
{{detail.NewValue}}
</div>
<div class="umb-table-body">
<div ng-repeat="detail in vm.item.Details" class="umb-table-row"
ng-class="{'usync-row-delete': detail.Change == 'Delete', 'usync-row-create' : detail.Change == 'Create'}">
<div class="umb-table-cell">
<i ng-if="detail.Change == 'Create'" class="icon icon-add color-green"></i>
<i ng-if="detail.Change == 'NoChange'" class="icon icon-check color-green"></i>
<i ng-if="detail.Change == 'Update'" class="icon icon-sync color-orange"></i>
<i ng-if="detail.Change == 'Delete'" class="icon icon-wrong color-red"></i>
</div>
<div class="umb-table-cell usync-detail-action-cell">
{{detail.Change}}
</div>
<div class="umb-table-cell umb-table__name">
{{detail.Name}}
</div>
<div class="umb-table-cell usync-old-value">
{{detail.OldValue}}
</div>
<div class="umb-table-cell usync-new-value">
{{detail.NewValue}}
</div>
</div>
</div>
</div>
</div>
</div>

<div ng-if="vm.item.Details.length == 0 && vm.item.Change == 'Update'" class="alert alert-info">
<h4>No Changes detected</h4>
<p>
It is possible that the .config file is diffrent, because it contains extra information
(such as xml comments) but no properties or values on this item will change when the file
is processed.
</p>
</div>
</umb-box-content>
</umb-box-container>
</umb-box>
</umb-editor-container>
<umb-editor-footer>
<umb-editor-footer-content-right>
<umb-button type="button"
button-style="default"
button-style="link"
label-key="general_close"
action="vm.close()">
</umb-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="umb-table-cell">
<localize key="usync_tableMessage"></localize>
</div>
<div class="umb-table-cell"></div>
<div class="umb-table-cell usync-detail-link-cell"></div>
<div class="umb-table-cell"></div>
</div>
</div>
Expand All @@ -56,7 +56,7 @@
<div class="umb-table-cell">
{{result.Message}}
</div>
<div class="umb-table-cell">
<div class="umb-table-cell usync-detail-link-cell">
<umb-button type="button"
button-style="link"
label-key="usync_details"
Expand Down
8 changes: 8 additions & 0 deletions uSync8.BackOffice/App_Plugins/uSync8/usync.css
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,12 @@

.usync-handler-box .umb-box-header {
cursor: pointer;
}

.usync-detail-link-cell {
min-width: 120px;
}

.usync-detail-link-cell .btn {
padding: 6px;
}
3 changes: 2 additions & 1 deletion uSync8.BackOffice/Config/uSync8.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<UseGuidFilenames>False</UseGuidFilenames>
<BatchSave>False</BatchSave>

<!-- calls a rebuild cache when an import completes -->
<!-- calls a rebuild cache when an import completes
(for Umbraco 8.3+ recommended value is false) -->
<RebuildCacheOnCompleation>False</RebuildCacheOnCompleation>

<!-- handler sets -->
Expand Down
6 changes: 4 additions & 2 deletions uSync8.BackOffice/SyncHandlers/SyncHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,10 @@ private IEnumerable<uSyncAction> ReportElement(XElement node, string filename)
{
action.Message = "Change details cannot be calculated";
}

action.Message = $"{action.Change.ToString()}";
else
{
action.Message = $"{action.Change.ToString()}";
}
actions.Add(action);
}
else
Expand Down
59 changes: 45 additions & 14 deletions uSync8.Core/Tracking/SyncBaseTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models.Entities;
Expand Down Expand Up @@ -35,10 +37,11 @@ public virtual IEnumerable<uSyncChange> GetChanges(XElement node)
if (!serializer.IsValid(node))
{
// not valid
return new uSyncChange() {
Change = ChangeDetailType.Error,
Name = "Invalid File",
OldValue = node.Name.LocalName
return new uSyncChange()
{
Change = ChangeDetailType.Error,
Name = "Invalid File",
OldValue = node.Name.LocalName
}.AsEnumerableOfOne(); ;
}

Expand Down Expand Up @@ -77,15 +80,15 @@ private uSyncChange GetEmptyFileChanges(XElement node)

var action = node.Attribute("Change").ValueOrDefault<SyncActionType>(SyncActionType.None);

switch(action)
switch (action)
{
case SyncActionType.Delete:
return uSyncChange.Delete(node.GetAlias(), "Delete", node.GetAlias());
case SyncActionType.Rename:
return uSyncChange.Update(node.GetAlias(), "Rename", node.GetAlias(), "new name");
default:
return uSyncChange.NoChange("", node.GetAlias());
}
}
}

private IEnumerable<uSyncChange> CalculateChanges(TrackedItem change, XElement current, XElement target, string name, string path)
Expand Down Expand Up @@ -211,7 +214,7 @@ private IEnumerable<uSyncChange> CalculateRepeatingChanges(TrackedItem change, X
// if the value is diffrent in this case we will consider this a delete
targetNode = targetItems.FirstOrDefault(x => x.Value == currentNode.Value);
}

}
else
{
Expand Down Expand Up @@ -259,7 +262,7 @@ private IEnumerable<uSyncChange> CalculateRepeatingChanges(TrackedItem change, X
else
{
// if there are no children, they we are comparing the actual text of the nodes
updates.AddNotNull(Compare(currentNodePath, currentNodeName,
updates.AddNotNull(Compare(currentNodePath, currentNodeName,
currentNode.ValueOrDefault(string.Empty),
targetNode.ValueOrDefault(string.Empty),
change.MaskValue));
Expand All @@ -280,7 +283,7 @@ private IEnumerable<uSyncChange> CalculateRepeatingChanges(TrackedItem change, X
}
else
{
foreach(var targetItem in targetItems)
foreach (var targetItem in targetItems)
{
var targetNodePath = path;

Expand Down Expand Up @@ -362,7 +365,7 @@ private IEnumerable<uSyncChange> CalculatePropertyChanges(TrackedItem change, XE
}

// missing from current (so new)
foreach(var targetChild in targetNode.Elements())
foreach (var targetChild in targetNode.Elements())
{
var currentChildNode = currentNode.Element(targetChild.Name.LocalName);
if (currentChildNode == null)
Expand Down Expand Up @@ -390,10 +393,38 @@ private string GetElementValues(XElement node)

protected uSyncChange Compare(string path, string name, string current, string target, bool maskValue)
{
if (current.Equals(target)) return null;
return uSyncChange.Update(path, name,
maskValue ? "*******" : current,
maskValue ? "*******" : target);
if (current.DetectIsJson())
{
return JsonChange(current, target, path, name);
}
else
{
if (current.Equals(target)) return null;

return uSyncChange.Update(path, name,
maskValue ? "*******" : current,
maskValue ? "*******" : target);
}

}

private uSyncChange JsonChange(string current, string target, string path, string name)
{
try
{
// jsoncompare. for sanity, we serialize and deserialize into
var currentJson = JsonConvert.DeserializeObject<JToken>(current);
var targetJson = JsonConvert.DeserializeObject<JToken>(target);

if (JToken.DeepEquals(currentJson, targetJson)) return null;

return uSyncChange.Update(path, name, currentJson, targetJson);
}
catch
{
// malformed json etc, shouldn't make a details check fail.
return null;
}
}

private uSyncChange Compare<TValue>(string path, string name, TValue current, TValue target, bool maskValue)
Expand Down
Loading

0 comments on commit 2349275

Please sign in to comment.