Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions uSync.BackOffice/Extensions/uSyncActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using Umbraco.Extensions;

using uSync.BackOffice.Models;
using uSync.BackOffice.SyncHandlers.Models;
using uSync.Core.Models;

Expand Down Expand Up @@ -135,4 +136,26 @@ public static void UpdateActions<TObject>(this List<uSyncAction> actions, Guid k
/// </remarks>
public static bool RequiresSave<TObject>(this SyncAttempt<TObject> attempt)
=> attempt.Success && attempt.Change > Core.ChangeType.NoChange && !attempt.Saved && attempt.Item != null;


public static uSyncActionView AsActionView(this uSyncAction action)
{
var msg = string.IsNullOrWhiteSpace(action.Message) is false
? action.Message
: string.IsNullOrWhiteSpace(action.Exception?.Message) is false
? action.Exception.Message
: "";

return new uSyncActionView
{
Key = action.Key,
Name = action.Name,
Handler = action.HandlerAlias ?? "",
ItemType = action.ItemType,
Change = action.Change,
Success = action.Success,
Details = action.Details?.ToList() ?? [],
Message = msg
};
}
}
15 changes: 14 additions & 1 deletion uSync.BackOffice/Services/SyncService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Microsoft.Extensions.Logging;

using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Tls;

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -152,6 +155,8 @@ public async Task<IEnumerable<uSyncAction>> ImportAsync(string[] folders, bool f
// if its blank, we just throw it back empty.
if (handlers == null || !handlers.Any()) return [];

Guid requestId = Guid.NewGuid();

var sw = Stopwatch.StartNew();

using (var pause = _mutexService.ImportPause(true))
Expand Down Expand Up @@ -218,11 +223,19 @@ public async Task<IEnumerable<uSyncAction>> ImportAsync(string[] folders, bool f

callbacks?.Update?.Invoke($"Processed {actions.Count} items in {sw.ElapsedMilliseconds}ms", 1, 1);

summary.Message = "Completed";
summary.Total = handlers.Count() + 1;
var finalActions = actions.Select(x => x.AsActionView()).ToList();

callbacks?.Callback?.Invoke(summary);
callbacks?.Complete?.Invoke(requestId, "Sync complete", true, finalActions);

return actions;
}

}



private static async Task<List<uSyncAction>> PerformPostImportAsync(IEnumerable<HandlerConfigPair> handlers, IEnumerable<uSyncAction> actions)
{
var postImportActions = actions.Where(x => x.Success && x.Change > Core.ChangeType.NoChange && x.RequiresPostProcessing).ToList();
Expand Down
5 changes: 3 additions & 2 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,9 @@ virtual protected async Task<IEnumerable<uSyncAction>> ImportSingleElementAsync(
}
catch (Exception ex)
{
logger.LogWarning("[{alias}] ImportElement Failed : {exception}", this.Alias, ex.ToString());
return [uSyncAction.Fail(Path.GetFileName(filename), this.Alias, this.ItemType, ChangeType.Fail,
var fileWithoutPath = Path.GetFileName(filename);
logger.LogWarning("[{alias}] ({filename}) ImportElement Failed : {exception}", this.Alias, fileWithoutPath, ex.ToString());
return [uSyncAction.Fail(fileWithoutPath, this.Alias, this.ItemType, ChangeType.Fail,
$"{this.Alias} Import Fail: {ex.Message}", new Exception(ex.Message))];
}

Expand Down
2 changes: 1 addition & 1 deletion uSync.BackOffice/uSyncBackOffice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace uSync.BackOffice;
/// </summary>
public class uSync
{
internal static Version Version => typeof(uSync).Assembly.GetName().Version ?? new Version(15, 0, 0);
public static Version Version => typeof(uSync).Assembly.GetName().Version ?? new Version(15, 0, 0);

/// <summary>
/// name of the app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace uSync.Backoffice.Management.Api.Extensions;

public static class uSyncActionExtensions
{
[Obsolete("This is for backwards compatibility, use AsActionView instead - will be removed in v19")]
public static uSyncActionView ToActionView(this uSyncAction action)
{
var msg = string.IsNullOrWhiteSpace(action.Message) is false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ await _syncActionService.StartProcessAsync(new SyncStartActionRequest
return new PerformActionResponse
{
RequestId = requestId.ToString(),
Actions = allActions.Where(x => x.Change != Core.ChangeType.Hidden).Select(x => x.ToActionView()),
Actions = allActions.Where(x => x.Change != Core.ChangeType.Hidden).Select(x => x.AsActionView()),
Status = summaries,
Complete = false
};
Expand All @@ -293,7 +293,7 @@ await _syncActionService.StartProcessAsync(new SyncStartActionRequest
private static PerformActionResponse SummerizeCompleteProcess(PerformActionRequest actionRequest, HandlerActions action, List<SyncHandlerView> handlers, Guid requestId, uSyncCallbacks callbacks, List<uSyncAction> actions)
{
var finalSummary = GetSummaries(action, handlers, actionRequest.StepNumber + 1, actions);
var actionViews = actions.Select(x => x.ToActionView());
var actionViews = actions.Select(x => x.AsActionView());

callbacks?.Callback?.Invoke(new SyncProgressSummary(finalSummary, "Completed", handlers.Count));
callbacks?.Complete?.Invoke(requestId, "Sync complete", true, actionViews);
Expand Down
4 changes: 3 additions & 1 deletion uSync.Backoffice.Management.Client/uSyncManifestReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public Task<IEnumerable<PackageManifest>> ReadPackageManifestsAsync()
Imports = new Dictionary<string, string>
{
{ "@jumoo/uSync", script },
{ "@jumoo/uSync/external/signalr", script }
{ "@jumoo/uSync/external/signalr", script },
{ "@jumoo/usync", script },
{ "@jumoo/usync/external/signalr", script }
}
}
}
Expand Down

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 @@ -8,7 +8,7 @@
"homepage": "https://jumoo.co.uk/uSync",
"license": "MPL-2.0",
"type": "module",
"version": "17.0.4",
"version": "17.1.0",
"main": "./dist/usync.js",
"types": "./dist/index.d.ts",
"module": "./dist/usync.js",
Expand Down
31 changes: 31 additions & 0 deletions uSync.Core/DataTypes/ConfigurationSerializerBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System.Collections.Immutable;

using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Extensions;

using uSync.Core.Mapping;

namespace uSync.Core.DataTypes;

public abstract class ConfigurationSerializerBase
Expand All @@ -10,6 +15,11 @@ public virtual IDictionary<string, object> GetConfigurationExport(IDictionary<st
public virtual IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration)
=> configuration;

public virtual Task<IDictionary<string, object>> GetConfigurationExportAsync(string name, IDictionary<string, object> configuration)
=> Task.FromResult(GetConfigurationExport(configuration));

public virtual Task<IDictionary<string, object>> GetConfigurationImportAsync(string name, IDictionary<string, object> configuration)
=> Task.FromResult(GetConfigurationImport(configuration));
/// <summary>
/// renames properties that might exist in a json string (if it is one).
/// </summary>
Expand All @@ -27,5 +37,26 @@ protected static IDictionary<string, object> MigratePropertyNames(IDictionary<st

return sort ? source.ToImmutableSortedDictionary() : source;
}
}

public abstract class ConfigurationDependenantSerializerBase : ConfigurationSerializerBase
{
private readonly PropertyEditorCollection _propertyEditors;
public abstract string[] Editors { get; }
private string? _requires { get; }

protected ConfigurationDependenantSerializerBase(PropertyEditorCollection propertyEditors)
{
_propertyEditors = propertyEditors;
var requires = GetType().GetCustomAttribute<RequiresPropertyEditorAttribute>(false);
if (requires != null)
_requires = requires.Editor;
}

public bool IsSerializer(string propertyName)
{
return Editors.InvariantContains(propertyName)
&& (_requires is null ? true : _propertyEditors.Any(x => x.Alias.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace uSync.Core.DataTypes;

public class ConfigurationSerializerCollectionBuilder
: LazyCollectionBuilderBase<ConfigurationSerializerCollectionBuilder, ConfigurationSerializerCollection, IConfigurationSerializer>
: WeightedCollectionBuilderBase<ConfigurationSerializerCollectionBuilder, ConfigurationSerializerCollection, IConfigurationSerializer>
{
protected override ConfigurationSerializerCollectionBuilder This => this;
}
Expand All @@ -19,10 +19,10 @@ public ConfigurationSerializerCollection(Func<IEnumerable<IConfigurationSerializ
}

public IConfigurationSerializer? GetSerializer(string editorAlias)
=> this.FirstOrDefault(x => x.Editors.InvariantContains(editorAlias));
=> this.FirstOrDefault(x => x.IsSerializer(editorAlias));

public IEnumerable<IConfigurationSerializer> GetSerializers(string editorAlias)
=> this.Where(x => x.Editors.InvariantContains(editorAlias));
=> this.Where(x => x.IsSerializer(editorAlias));

/// <summary>
/// find the first serializer that returns a non-null UI alias.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public override IDictionary<string, object> GetConfigurationImport(IDictionary<s
private static string? GetTreeType(IDictionary<string, object> configuration)
{
if (configuration.TryGetValue("treeSource", out var treeSourceValue) is false || treeSourceValue is null)
return null;
return "content";

if (treeSourceValue.TryConvertToJsonObject(out var treeSource) is false)
return null;
return "content";

if (treeSource.TryGetPropertyValue("type", out var typeValue) is false)
return null;
return "content";

return typeValue?.GetValueAs<string>();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Extensions;

using uSync.Core.Extensions;
Expand Down Expand Up @@ -88,23 +89,34 @@ private IDictionary<string, object> MigrateToTipTap(IDictionary<string, object>
if (configuration.TryGetValue("toolbar", out var toolbar) is false
&& TryGetToolbarArray(toolbar, out toolbarList) is false)
{
toolbarList = _defaultToolbar.ToList();
toolbarList = [.. _defaultToolbar];
}

if (toolbarList.Count == 0)
toolbarList = [.. _defaultToolbar];

configuration.Remove("mode");
configuration.Remove("hideLabel");

_logger.LogDebug("Original toolbar items: {ToolbarItems}", string.Join(", ", toolbarList));

var newToolbar = toolbarList.Select(MapToolbarItem).WhereNotNull().ToList();
configuration["toolbar"] = new List<List<List<string>>> { new() { newToolbar } };

var extensions = _defaultExtensions.ToList();
_logger.LogDebug("Mapped toolbar items: {ToolbarItems}", string.Join(", ", newToolbar));

var extensions = _defaultExtensions.ToList();
if (configuration.TryGetValue("blocks", out var blocks) && blocks is not null)
{
// if there are blocks, we need to add the block extension
newToolbar.Add("Umb.Tiptap.Toolbar.BlockPicker");
extensions.Add("Umb.Tiptap.Block");
}

if (configuration.ContainsKey("toolbar"))
configuration.Remove("toolbar");

configuration["toolbar"] = new List<List<List<string>>> { new() { newToolbar } };

configuration["extensions"] = extensions.ToArray();

return configuration;
Expand Down
15 changes: 14 additions & 1 deletion uSync.Core/DataTypes/IConfigurationSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace uSync.Core.DataTypes;
using Umbraco.Extensions;

namespace uSync.Core.DataTypes;

public interface IConfigurationSerializer
{
Expand All @@ -12,13 +14,24 @@ public interface IConfigurationSerializer
/// </summary>
string[] Editors { get; }

[Obsolete("Use GetConfigurationExport(string alias, IDictionary<string, object> configuration) instead will be removed in v19")]
IDictionary<string, object> GetConfigurationExport(IDictionary<string, object> configuration)
=> configuration;

Task<IDictionary<string, object>> GetConfigurationExportAsync(string name, IDictionary<string, object> configuration)
=> Task.FromResult(configuration);

[Obsolete("Use GetConfigurationExport(string alias, IDictionary<string, object> configuration) instead will be removed in v19")]
IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration)
=> configuration;

Task<IDictionary<string, object>> GetConfigurationImportAsync(string name, IDictionary<string, object> configuration)
=> Task.FromResult(configuration);

string? GetEditorAlias() => null;

string? GetEditorUIAlias() => null;

bool IsSerializer(string propertyName)
=> Editors.InvariantContains(propertyName);
}
4 changes: 4 additions & 0 deletions uSync.Core/Mapping/ISyncMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public interface ISyncMapper
Task<string?> GetImportValueAsync(string value, string editorAlias);

Task<IEnumerable<uSyncDependency>> GetDependenciesAsync(object value, string editorAlias, DependencyFlags flags);
}

public interface ISyncPropertyMapper : ISyncMapper
{
Task<string?> GetImportValueAsync(string value, IPropertyType propertyType);

}
Loading
Loading