Skip to content

Commit

Permalink
Adds UI to the report to make it eaiser to spot sources. (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump authored Mar 10, 2024
1 parent ab5a306 commit 5d807d0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
5 changes: 5 additions & 0 deletions uSync.BackOffice/BackOfficeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static class Package
/// </summary>
public const string ReleaseSuffix = "";

/// <summary>
/// folder we say things are in when we have merged them.
/// </summary>
public const string MergedFolderName = "Combined";

/// <summary>
/// ordering of the handler items (what gets done when)
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions uSync.BackOffice/Services/SyncFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ public IEnumerable<OrderedNodeInfo> MergeFolders(string[] folders, string extens
{
// merge these files.
item.Value.SetNode(trackerBase.MergeFiles(elements[item.Key].Node, item.Value.Node));
item.Value.FileName = $"{uSyncConstants.MergedFolderName}/{Path.GetFileName(item.Value.FileName)}";
}

elements[item.Key] = item.Value;
Expand Down
25 changes: 21 additions & 4 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public IEnumerable<uSyncAction> ImportAll(string[] folders, HandlerSettings conf

options.Callbacks?.Update?.Invoke($"Importing {Path.GetFileNameWithoutExtension(item.Path)}", count, total);

var result = ImportElement(item.Node, item.Path, config, options);
var result = ImportElement(item.Node, item.FileName, config, options).ToList();

foreach (var attempt in result)
{
if (attempt.Success)
Expand Down Expand Up @@ -516,11 +517,13 @@ virtual public IEnumerable<uSyncAction> ImportElement(XElement node, string file
.AsEnumerableOfOne();
}

var shortFilename = Path.GetFileNameWithoutExtension(filename);

if (_mutexService.FireItemStartingEvent(new uSyncImportingItemNotification(node, (ISyncHandler)this)))
{
// blocked
return uSyncActionHelper<TObject>
.ReportAction(ChangeType.NoChange, node.GetAlias(), node.GetPath(), GetNameFromFileOrNode(filename, node), node.GetKey(), this.Alias, "Change stopped by delegate event")
.ReportAction(ChangeType.NoChange, node.GetAlias(), node.GetPath(), GetNameFromFileOrNode(shortFilename, node), node.GetKey(), this.Alias, "Change stopped by delegate event")
.AsEnumerableOfOne();
}

Expand All @@ -532,14 +535,16 @@ virtual public IEnumerable<uSyncAction> ImportElement(XElement node, string file

// get the item.
var attempt = DeserializeItem(node, serializerOptions);
var action = uSyncActionHelper<TObject>.SetAction(attempt, GetNameFromFileOrNode(filename, node), node.GetKey(), this.Alias, IsTwoPass);
var action = uSyncActionHelper<TObject>.SetAction(attempt, GetNameFromFileOrNode(shortFilename, node), node.GetKey(), this.Alias, IsTwoPass);

// add item if we have it.
if (attempt.Item != null) action.Item = attempt.Item;

// add details if we have them
if (attempt.Details != null && attempt.Details.Any()) action.Details = attempt.Details;

action.Path = GetRootFolder(filename.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));

// this might not be the place to do this because, two pass items are imported at another point too.
_mutexService.FireItemCompletedEvent(new uSyncImportedItemNotification(node, attempt.Change));

Expand All @@ -553,7 +558,19 @@ virtual public IEnumerable<uSyncAction> ImportElement(XElement node, string file
$"{this.Alias} Import Fail: {ex.Message}", new Exception(ex.Message))
.AsEnumerableOfOne();
}
}

private string GetRootFolder(string path)
{
if (path.StartsWith(uSyncConstants.MergedFolderName))
return Path.GetDirectoryName(path);

foreach(var folder in this.uSyncConfig.GetFolders())
{
if (path.Contains(folder) is true) return Path.GetFileName(folder.TrimEnd('/'));
}

return path;
}


Expand Down Expand Up @@ -1361,7 +1378,7 @@ public IEnumerable<uSyncAction> ReportElement(XElement node, string filename, Ha
var action = uSyncActionHelper<TObject>
.ReportAction(change.Change, node.GetAlias(), node.GetPath(), GetNameFromFileOrNode(filename, node), node.GetKey(), this.Alias, "");


action.Path = GetRootFolder(filename.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));

action.Message = "";

Expand Down
6 changes: 6 additions & 0 deletions uSync.Backoffice.Assets/App_Plugins/uSync/changedialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
</umb-box-header>
<umb-box-container>
<umb-box-content>
<div ng-if="vm.item.path != 'Combined'" class="usync-path-source-summary">
Update file from the <strong>{{vm.item.path}}</strong> folder.
</div>
<div ng-if="vm.item.path == 'Combined'" class="usync-path-source-summary">
Update is the result of combining two or more files from disk.
</div>
<div ng-if="vm.item.detailMessage.length > 0" class="usync-item-detail-message">
<div ng-bind-html="vm.item.detailMessage"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
<div class="umb-table-cell">
{{result._typename}}
</div>
<div class="umb-table-cell">
<em class="usync-path-name {{result.path}}">{{result.path}}</em>
</div>
<div class="umb-table-cell umb-table__name">
<div>
{{result.name}}
<div class="muted" ng-if="result.path.length > 0"> > {{result.itemType.substring(1)}}{{result.path}}</div>
</div>
{{result.name}}
</div>
<div class="umb-table-cell">
{{result.change}}
Expand Down
25 changes: 24 additions & 1 deletion uSync.Backoffice.Assets/App_Plugins/uSync/usync.css
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,27 @@ ul.usync-action-list {

.usync-summary-expand.active .icon {
transform: rotateX(180deg);
}
}

.usync-path-source-summary {
margin: 5px 0;
font-style: italic;
border: 1px solid #eee;
border-left: 4px solid #ddd;
padding: 5px 10px;
}

.usync-path-name {
padding: 3px 5px;
border-radius: 4px;
}

.usync-path-name.Combined {
background-color: #FF7043;
color: white;
}

.usync-path-name.Root {
background-color: #27b171;
color: white;
}

0 comments on commit 5d807d0

Please sign in to comment.