Skip to content

Commit

Permalink
adds block grid support - can backport to v10 as property alias exist…
Browse files Browse the repository at this point in the history
…s in 10
  • Loading branch information
nathanwoulfe committed Jan 9, 2023
1 parent 6c7e02e commit 12030c4
Show file tree
Hide file tree
Showing 27 changed files with 107 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export class PreflightController {
'Umbraco.NestedContent',
];

blockListEditorAlias = 'Umbraco.BlockList';
blockProperties = [
'Umbraco.BlockList',
'Umbraco.BlockGrid',
];

noTests = false;
notCreated = false;
Expand Down Expand Up @@ -209,10 +212,10 @@ export class PreflightController {

let currentValue = property.value;

if (prop.editor === this.blockListEditorAlias) {
if (this.blockProperties.includes(prop.editor)) {
currentValue = JSON.stringify(currentValue.contentData);
} else {
currentValue = this.jsonProperties.includes(prop.editor) ? JSON.stringify(currentValue) : currentValue;
} else if (this.jsonProperties.includes(prop.editor)) {
currentValue = JSON.stringify(currentValue);
}

const hash = this.getHash(currentValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export class SettingsController {
this.settingsSyncModel.forEach(v => {
if (v.view.includes(constants.multipletextbox) && v.value) {
for (let [key, value] of Object.entries(v.value)) {
v.value[key] = value.split(',').map(val => ({ value: val })).sort((a, b) => a < b ? -1 : 1);
v.value[key] = value ? value.split(',').map(val => ({ value: val })).sort((a, b) => a < b ? -1 : 1) : { value: null };
}
} else if (v.view.includes(constants.checkboxlist) && v.value) {
for (let [key, value] of Object.entries(v.value)) {
v.value[key] = value.split(',');
v.value[key] = value ? value.split(',') : [];
}
}
})
Expand Down
1 change: 1 addition & 0 deletions src/Preflight/Constants/KnownPropertyAlias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class KnownPropertyAlias
public const string Textbox = UmbConstants.PropertyEditors.Aliases.TextBox;
public const string NestedContent = UmbConstants.PropertyEditors.Aliases.NestedContent;
public const string BlockList = UmbConstants.PropertyEditors.Aliases.BlockList;
public const string BlockGrid = UmbConstants.PropertyEditors.Aliases.BlockGrid;

public static IEnumerable<string?> All => typeof(KnownPropertyAlias).GetFields()
.Where(x => x.IsLiteral).Select(x => x.GetRawConstantValue()?.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Controllers/PreflightApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public IActionResult CheckDirty(DirtyProperties data)
}

/// <summary>
///
///
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
Expand Down
14 changes: 7 additions & 7 deletions src/Preflight/Extensions/ContentBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace Preflight.Extensions;

public static class ContentBaseExtensions
{
public static IEnumerable<IProperty> GetPreflightProperties(this IContentBase content) => content.Properties
.Where(p => p.PropertyType.PropertyEditorAlias == KnownPropertyAlias.Grid ||
p.PropertyType.PropertyEditorAlias == KnownPropertyAlias.BlockList ||
p.PropertyType.PropertyEditorAlias == KnownPropertyAlias.NestedContent ||
p.PropertyType.PropertyEditorAlias == KnownPropertyAlias.Textbox ||
p.PropertyType.PropertyEditorAlias == KnownPropertyAlias.Textarea ||
p.PropertyType.PropertyEditorAlias == KnownPropertyAlias.Rte);
public static IEnumerable<IProperty> GetPreflightProperties(this IContentBase content)
{
IEnumerable<string?> propertyAliases = KnownPropertyAlias.All;

return content.Properties
.Where(p => propertyAliases.Contains(p.PropertyType.PropertyEditorAlias));
}
}
2 changes: 1 addition & 1 deletion src/Preflight/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Preflight.Extensions;
public static class EnumExtensions
{
/// <summary>
///
///
/// </summary>
/// <typeparam name="TAttribute"></typeparam>
/// <param name="value"></param>
Expand Down
20 changes: 17 additions & 3 deletions src/Preflight/Extensions/SettingsModelListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ public static class SettingsModelListExtensions
public static T? GetValue<T>(this IEnumerable<SettingsModel> settings, string guid, string culture)
where T : IConvertible
{
var guidGuid = new Guid(guid);
string? stringValue = settings.FirstOrDefault(x => x.Guid == guidGuid)?.Value?[culture]?.ToString();
if (Guid.TryParse(guid, out Guid guidGuid) == false)
{
return default;
}

SettingsModel? setting = settings.FirstOrDefault(x => x.Guid == guidGuid);

if (setting?.Value is null)
{
return default;
}

if (setting.Value.TryGetValue(culture, out object? value))
{
return ConvertObject<T>(value?.ToString());
}

return ConvertObject<T>(stringValue);
return default;
}

private static T? ConvertObject<T>(object? obj)
Expand Down
9 changes: 8 additions & 1 deletion src/Preflight/Handlers/SendingContentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public SendingContentHandler(ISendingContentModelExecutor executor)
_executor = executor ?? throw new ArgumentNullException(nameof(executor));
}

public void Handle(SendingContentNotification notification) =>
public void Handle(SendingContentNotification notification)
{
if (notification.Content.Id == 0)
{
return;
}

_executor.Execute(notification.Content);
}
}
2 changes: 1 addition & 1 deletion src/Preflight/Models/PreflightPluginResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Preflight.Models;

/// <summary>
///
///
/// </summary>
public class PreflightPluginResponseModel
{
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Models/Settings/DisabledSettingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Preflight.Models.Settings;

/// <summary>
/// Defines the Preflight setting for the disable/enable setting
/// Defines the Preflight setting for the disable/enable setting
/// </summary>
internal class DisabledSettingModel : SettingsModel
{
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Models/Settings/OnSaveOnlySettingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Preflight.Models.Settings;

/// <summary>
/// Defines the Preflight setting for the on-save-only setting
/// Defines the Preflight setting for the on-save-only setting
/// </summary>
internal class OnSaveOnlySettingModel : SettingsModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Preflight.Models.Settings;

/// <summary>
///
///
/// </summary>
internal class PropertiesToTestSettingModel : SettingsModel
{
Expand Down
4 changes: 2 additions & 2 deletions src/Preflight/Models/Settings/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Preflight.Models.Settings;
public class SettingsModel
{
/// <summary>
///
///
/// </summary>
[JsonProperty("guid")]
public Guid Guid { get; set; }
Expand All @@ -20,7 +20,7 @@ public class SettingsModel
public int Id { get; set; }

/// <summary>
///
///
/// </summary>
[JsonProperty("core")]
public bool Core { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Models/Settings/SettingsTabModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SettingsTabModel
public string Name { get; set; } = string.Empty;

/// <summary>
/// This must be explicitly set whenever a tab is created, it can't be lazy as it
/// This must be explicitly set whenever a tab is created, it can't be lazy as it
/// would then change when localizing, which we don't wany
/// </summary>
[JsonProperty("alias")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

namespace Preflight.Parsers;

public class BlockListValueParser : PreflightValueParserBase, IPreflightValueParser
public class BlockValueParser : PreflightValueParserBase, IPreflightValueParser
{
private readonly IContentTypeService _contentTypeService;

public BlockListValueParser(IContentTypeService contentTypeService, IPluginExecutor pluginExecutor, IMessenger messenger)
public BlockValueParser(IContentTypeService contentTypeService, IPluginExecutor pluginExecutor, IMessenger messenger)
: base(messenger, pluginExecutor)
{
_contentTypeService = contentTypeService;
}

public List<PreflightPropertyResponseModel> Parse(ContentParserParams parserParams)
{
Dictionary<Guid, IContentType> cache = new Dictionary<Guid, IContentType>();
List<PreflightPropertyResponseModel> response = new List<PreflightPropertyResponseModel>();
Dictionary<Guid, IContentType> cache = new();
List<PreflightPropertyResponseModel> response = new();

BlockValue? blockValue = JsonConvert.DeserializeObject<BlockValue>(parserParams.PropertyValue);
int index = 1;
Expand All @@ -35,7 +35,7 @@ public List<PreflightPropertyResponseModel> Parse(ContentParserParams parserPara
foreach (BlockItemData blockItem in blockValue.ContentData)
{
Guid typeAlias = blockItem.ContentTypeKey;
IContentType? type = cache.ContainsKey(typeAlias) ? cache[typeAlias] : _contentTypeService.Get(typeAlias);
IContentType? type = cache.TryGetValue(typeAlias, out IContentType? value) ? value : _contentTypeService.Get(typeAlias);

if (type is null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Preflight/Parsers/GridValueParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public List<PreflightPropertyResponseModel> Parse(ContentParserParams parserPara
}

/// <summary>
///
///
/// </summary>
/// <param name="label"></param>
/// <param name="labelDictionary"></param>
Expand All @@ -121,7 +121,7 @@ private static string AddLabelCount(string label, Dictionary<string, int> labelD
}

/// <summary>
///
///
/// </summary>
/// <param name="gridEditorView"></param>
/// <returns></returns>
Expand Down
15 changes: 7 additions & 8 deletions src/Preflight/Parsers/ParserComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ namespace Preflight.Parsers;

public class PreflightParserComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
_ = builder.Services.AddTransient<NestedContentValueParser>();
_ = builder.Services.AddTransient<GridValueParser>();
_ = builder.Services.AddTransient<BlockListValueParser>();
_ = builder.Services.AddTransient<StringValueParser>();
_ = builder.Services.AddTransient<Func<ParserType, IPreflightValueParser>>(serviceProvider => key => GetServiceInstance(serviceProvider, key));
}
public void Compose(IUmbracoBuilder builder) =>
_ = builder.Services
.AddTransient<NestedContentValueParser>()
.AddTransient<GridValueParser>()
.AddTransient<BlockValueParser>()
.AddTransient<StringValueParser>()
.AddTransient<Func<ParserType, IPreflightValueParser>>(serviceProvider => key => GetServiceInstance(serviceProvider, key));

public IPreflightValueParser GetServiceInstance(IServiceProvider serviceProvider, ParserType key)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Preflight/Parsers/ParserTypeInfoAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Preflight.Parsers;

public class ParserTypeInfoAttribute : Attribute
{
internal ParserTypeInfoAttribute(string[] parsableProperties, Type serviceType)
{
ParsableProperties = parsableProperties;
ServiceType = serviceType;
}

public string[] ParsableProperties { get; private set; }

public Type ServiceType { get; private set; }
}
15 changes: 1 addition & 14 deletions src/Preflight/Parsers/ParserTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public enum ParserType
[ParserTypeInfo(new[] { KnownPropertyAlias.NestedContent }, typeof(NestedContentValueParser))]
NestedContent = 1,

[ParserTypeInfo(new[] { KnownPropertyAlias.BlockList }, typeof(BlockListValueParser))]
[ParserTypeInfo(new[] { KnownPropertyAlias.BlockList, KnownPropertyAlias.BlockGrid }, typeof(BlockValueParser))]
BlockList = 2,

[ParserTypeInfo(new[] { KnownPropertyAlias.Grid }, typeof(GridValueParser))]
Expand All @@ -14,16 +14,3 @@ public enum ParserType
[ParserTypeInfo(new[] { KnownPropertyAlias.Rte, KnownPropertyAlias.Textarea, KnownPropertyAlias.Textbox }, typeof(StringValueParser))]
String = 4,
}

public class ParserTypeInfoAttribute : Attribute
{
internal ParserTypeInfoAttribute(string[] parsableProperties, Type serviceType)
{
ParsableProperties = parsableProperties;
ServiceType = serviceType;
}

public string[] ParsableProperties { get; private set; }

public Type ServiceType { get; private set; }
}
6 changes: 3 additions & 3 deletions src/Preflight/Parsers/PreflightValueParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public PreflightValueParserBase(IMessenger messenger, IPluginExecutor pluginExec
}

/// <summary>
///
///
/// </summary>
/// <param name="propertyName"></param>
/// <param name="innerPropertyName"></param>
Expand All @@ -28,7 +28,7 @@ public string GetLabel(string propertyName, string innerPropertyName, string row
$"{propertyName} ({rowName} - {innerPropertyName})";

/// <summary>
///
///
/// </summary>
/// <param name="name"></param>
/// <param name="label"></param>
Expand All @@ -40,7 +40,7 @@ public void SendRemoveResponse(string name, string label) => _messenger.SendTest
});

/// <summary>
///
///
/// </summary>
/// <param name="parserParams"></param>
/// <param name="label"></param>
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Plugins/AutoCorrect/AutocorrectPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AutocorrectPlugin : IPreflightCorePlugin
public int TotalTests => 1;

/// <summary>
///
///
/// </summary>
public AutocorrectPlugin() => this.GenerateDefaultSettings(
false,
Expand Down
4 changes: 2 additions & 2 deletions src/Preflight/Plugins/LinkHealth/Services/LinksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<BrokenLinkModel> Check(string text, List<BrokenLinkModel> safeBrowsi
}

/// <summary>
///
///
/// </summary>
/// <param name="href"></param>
/// <param name="responseItem"></param>
Expand Down Expand Up @@ -112,7 +112,7 @@ private void SetResponseStatusWhenHrefExists(string href, BrokenLinkModel respon
}

/// <summary>
///
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SafeBrowsingService : ISafeBrowsingService
public SafeBrowsingService(ICacheManager cacheManager) => _cacheManager = cacheManager;

/// <summary>
///
///
/// </summary>
/// <param name="text"></param>
/// <param name="apiKey"></param>
Expand Down Expand Up @@ -84,7 +84,7 @@ public List<BrokenLinkModel> Check(string text, string apiKey)
}

/// <summary>
///
///
/// </summary>
/// <param name="urls"></param>
/// <param name="apiKey"></param>
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Plugins/Readability/ReadabilityPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ReadabilityPlugin : IPreflightCorePlugin
public string ViewPath => "/App_Plugins/Preflight/Backoffice/plugins/readability/readability.html";

/// <summary>
///
///
/// </summary>
/// <param name="readabilityService"></param>
public ReadabilityPlugin(IReadabilityService readabilityService)
Expand Down
Loading

0 comments on commit 12030c4

Please sign in to comment.