From f4bc343353158b3b51c67e422450feab987ede33 Mon Sep 17 00:00:00 2001 From: Robert Foster Date: Fri, 18 Mar 2022 15:20:04 +1100 Subject: [PATCH] fixes issues #2 #4 and an issue on startup with duplicate Dictionary keys --- .../ConfiguredPackagesCollection.cs | 5 ++++- Our.Iconic.Core/Helpers/HtmlExtensions.cs | 1 - .../ValueConverters/IconicValueConverter.cs | 21 +++++++------------ .../Iconic/js/src/iconic.controller.js | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Our.Iconic.Core/ConfiguredPackagesCollection.cs b/Our.Iconic.Core/ConfiguredPackagesCollection.cs index e8082e8..6aa8f34 100644 --- a/Our.Iconic.Core/ConfiguredPackagesCollection.cs +++ b/Our.Iconic.Core/ConfiguredPackagesCollection.cs @@ -35,7 +35,10 @@ public ConfiguredPackagesCollection(IDataTypeService dataTypeService) var editorConfig = ((JArray)configurationJson["packages"]).ToObject>(); - _packagesCache.Add(uniqueKey, editorConfig.ToDictionary(p => p.Id)); + if (!_packagesCache.ContainsKey(uniqueKey)) + { + _packagesCache.Add(uniqueKey, editorConfig.ToDictionary(p => p.Id)); + } } return _packagesCache[uniqueKey]; diff --git a/Our.Iconic.Core/Helpers/HtmlExtensions.cs b/Our.Iconic.Core/Helpers/HtmlExtensions.cs index e44662f..0edaac3 100644 --- a/Our.Iconic.Core/Helpers/HtmlExtensions.cs +++ b/Our.Iconic.Core/Helpers/HtmlExtensions.cs @@ -33,7 +33,6 @@ public static IHtmlString RenderIcon(this HtmlHelper helper, IHtmlString icon, o foreach (var item in htmlAttributesDict) { attributesString.Append($"{ConvertToJs(item.Key)}=\"{item.Value}\""); - } var modifiedTemplate = icon.ToString().Replace("{attributes}", attributesString.ToString()) diff --git a/Our.Iconic.Core/ValueConverters/IconicValueConverter.cs b/Our.Iconic.Core/ValueConverters/IconicValueConverter.cs index 4fd54c5..9741a55 100644 --- a/Our.Iconic.Core/ValueConverters/IconicValueConverter.cs +++ b/Our.Iconic.Core/ValueConverters/IconicValueConverter.cs @@ -23,7 +23,6 @@ public IconicValueConverter(IDataTypeService dataTypeService) { _configuredPackages = new ConfiguredPackagesCollection(dataTypeService); } - public bool IsConverter(IPublishedPropertyType propertyType) => propertyType.EditorAlias.Equals("our.iconic"); @@ -33,12 +32,11 @@ public Type GetPropertyValueType(IPublishedPropertyType propertyType) public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Elements; - public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview) { if (source == null) return null; - SelectedIcon icon = null; + SelectedIcon icon; if (source is JObject jObject) { icon = jObject.ToObject(); @@ -54,22 +52,20 @@ public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPro public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { if (inter == null) return new HtmlString(string.Empty); + string htmlString = string.Empty; var icon = (SelectedIcon)inter; var packages = _configuredPackages.GetConfiguratedPackages(propertyType); - var pckg = packages[icon.PackageId]; - - if (pckg == null) return string.Empty; - - var display = pckg.FrontendTemplate.Replace("{icon}", icon.Icon); - - return new HtmlString(display); + if (icon != null && packages.ContainsKey(icon.PackageId)) + { + var pckg = packages[icon.PackageId]; + htmlString = pckg?.FrontendTemplate.Replace("{icon}", icon.Icon) ?? string.Empty; + } + return new HtmlString(htmlString); } - - public bool? IsValue(object value, PropertyValueLevel level) { if (value is null) return null; @@ -82,7 +78,6 @@ public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPro return false; } - public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { return null; diff --git a/Our.Iconic/App_Plugins/Iconic/js/src/iconic.controller.js b/Our.Iconic/App_Plugins/Iconic/js/src/iconic.controller.js index 335fb1c..de02698 100644 --- a/Our.Iconic/App_Plugins/Iconic/js/src/iconic.controller.js +++ b/Our.Iconic/App_Plugins/Iconic/js/src/iconic.controller.js @@ -48,7 +48,7 @@ angular.module("umbraco") $scope.pckg = loadPackage(config.packages, $scope.model.value.packageId); if ($scope.pckg) { - assetsService.loadCss('~/' + $scope.pckg.cssfile); + assetsService.loadCss('~/' + $scope.pckg.cssfile.replace(/wwwroot\//i, '')); $scope.modelIsValid = true; } } else {