Skip to content

Commit

Permalink
Item manager asyncingess
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Aug 19, 2024
1 parent 1544a32 commit d47532d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 19 deletions.
4 changes: 3 additions & 1 deletion uSync.BackOffice/Models/OrderedNodeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.Json.Serialization;
using System.Xml.Linq;

using Umbraco.Extensions;
Expand Down Expand Up @@ -27,6 +28,7 @@ public OrderedNodeInfo(string filename, XElement node)
/// <summary>
/// set all the values of an ordered node.
/// </summary>
[JsonConstructor]
public OrderedNodeInfo(string filename, XElement node, int level, string path, bool isRoot)
: this(filename, node)
{
Expand All @@ -48,7 +50,7 @@ public Guid Key
/// <summary>
/// umbraco alias of the item
/// </summary>
public string Alias { get; }
public string Alias { get; }

/// <summary>
/// relative path of the item (so same in all 'folders')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public void Configure(SwaggerGenOptions options)
Version = "Latest",
Description = "Api access uSync operations"
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
</PropertyGroup>

<ItemGroup>
<Folder Include="usync-assets\pack\" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@jumoo/usync-assets",
"license": "MPL-2.0",
"type": "module",
"version": "14.0.1-preview001",
"version": "14.1.0-build.20240819.1",
"main": "./dist/usync.js",
"types": "./dist/index.d.ts",
"module": "./dist/usync.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../umbraco-package-schema.json",
"name": "uSync",
"id": "uSync",
"version": "14.0.1-preview001",
"version": "14.1.0-build.20240819.1",
"allowTelemetry": true,
"extensions": [
{
Expand Down
14 changes: 11 additions & 3 deletions uSync.Core/Sync/ISyncItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ISyncItemManager
/// Unless the item has some form of shared picker tree with the
/// core umbraco UI then answer is likely no (for now)
/// </remarks>
SyncEntityInfo GetSyncInfo(string entityType);
SyncEntityInfo? GetSyncInfo(string entityType);

/// <summary>
/// Which type of tree menu should be used.
Expand Down Expand Up @@ -52,10 +52,18 @@ public interface ISyncItemManager
/// the process should as a bare minimum return the item it is passed,
/// when the Include children flag is set - it should also return children.
/// </remarks>
IEnumerable<SyncItem> GetItems(SyncItem item);
Task<IEnumerable<SyncItem>> GetItemsAsync(SyncItem item);

/// <summary>
/// Get the underling Local item for something that was picked from the tree.
/// </summary>
SyncLocalItem GetEntity(SyncTreeItem treeItem);
Task<SyncLocalItem?> GetEntityAsync(SyncTreeItem treeItem);


/// <summary>
/// for a given key find the sync entity.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<SyncEntity?> GetSyncEntityAsync(string key);
}
25 changes: 21 additions & 4 deletions uSync.Core/Sync/SyncItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,37 @@
namespace uSync.Core.Sync;

/// <summary>
/// An item involved in a sync between servers. SyncItems are the start of any sync process
/// the base for a syncing item.
/// </summary>
public class SyncItem

public class SyncEntity
{
/// <summary>
/// Name (to display) of the item
/// </summary>
public string? Name { get; set; }
public required string Name { get; set; }

/// <summary>
/// optional icon to display.
/// </summary>
public string? Icon { get; set; }

/// <summary>
/// Umbraco UDI value to identify the item.
/// </summary>
public Udi? Udi { get; set; }
public required Udi Udi { get; set; }

/// <summary>
/// the entity type for the item.
/// </summary>
public string EntityType => Udi.EntityType;
}

/// <summary>
/// An item involved in a sync between servers. SyncItems are the start of any sync process
/// </summary>
public class SyncItem : SyncEntity
{
/// <summary>
/// Flags controlling what is to be included when this item is exported
/// </summary>
Expand Down
15 changes: 8 additions & 7 deletions uSync.Core/Sync/SyncItemManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ protected string EntityType
/// </summary>
/// <param name="treeItem"></param>
/// <returns></returns>
protected virtual SyncLocalItem GetRootItem(SyncTreeItem treeItem)
protected virtual SyncLocalItem? GetRootItem(SyncTreeItem treeItem)
=> new(Constants.System.RootString)
{
EntityType = EntityType,
Name = EntityType,
Udi = Udi.Create(EntityType)
};

protected abstract IEnumerable<SyncItem> GetDescendants(SyncItem item, DependencyFlags flags);
protected abstract Task<IEnumerable<SyncItem>> GetDescendantsAsync(SyncItem item, DependencyFlags flags);

/// <summary>
/// standard use case, if IncludeChildren flag is set, return this item and all its children.
/// if not just return this item.
/// </summary>
public virtual IEnumerable<SyncItem> GetItems(SyncItem item)
public virtual async Task<IEnumerable<SyncItem>> GetItemsAsync(SyncItem item)
{
if (item.Flags.HasFlag(DependencyFlags.IncludeChildren))
{
var items = new List<SyncItem> { item };
items.AddRange(GetDescendants(item, item.Flags & ~DependencyFlags.IncludeChildren));
items.AddRange(await GetDescendantsAsync(item, item.Flags & ~DependencyFlags.IncludeChildren));
return items;
}
else
Expand All @@ -100,15 +100,16 @@ public virtual IEnumerable<SyncItem> GetItems(SyncItem item)
/// </remarks>
public abstract class SyncItemManagerIndexBase<TIndexType> : SyncItemManagerBase
{
protected abstract SyncLocalItem GetLocalEntity(TIndexType id);
protected abstract Task<SyncLocalItem?> GetLocalEntityAsync(TIndexType id);

public virtual SyncLocalItem? GetEntity(SyncTreeItem treeItem)
/// <inheritdoc />
public virtual async Task<SyncLocalItem?> GetEntityAsync(SyncTreeItem treeItem)
{
if (treeItem.IsRoot()) return GetRootItem(treeItem);

var attempt = treeItem.Id.TryConvertTo<TIndexType>();
if (attempt.Success && attempt.Result is not null)
return GetLocalEntity(attempt.Result);
return await GetLocalEntityAsync(attempt.Result);

return null;
}
Expand Down

0 comments on commit d47532d

Please sign in to comment.