Skip to content

Commit

Permalink
Merge pull request #6 from robertjf/issue-fixes
Browse files Browse the repository at this point in the history
fixes issues #2 #4 and an issue on startup with duplicate Dictionary …
  • Loading branch information
skartknet committed Mar 19, 2022
2 parents 7fc0718 + f4bc343 commit 4eb0987
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
5 changes: 4 additions & 1 deletion Our.Iconic.Core/ConfiguredPackagesCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public ConfiguredPackagesCollection(IDataTypeService dataTypeService)

var editorConfig = ((JArray)configurationJson["packages"]).ToObject<IEnumerable<Package>>();

_packagesCache.Add(uniqueKey, editorConfig.ToDictionary(p => p.Id));
if (!_packagesCache.ContainsKey(uniqueKey))
{
_packagesCache.Add(uniqueKey, editorConfig.ToDictionary(p => p.Id));
}
}

return _packagesCache[uniqueKey];
Expand Down
1 change: 0 additions & 1 deletion Our.Iconic.Core/Helpers/HtmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
21 changes: 8 additions & 13 deletions Our.Iconic.Core/ValueConverters/IconicValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public IconicValueConverter(IDataTypeService dataTypeService)
{
_configuredPackages = new ConfiguredPackagesCollection(dataTypeService);
}

public bool IsConverter(IPublishedPropertyType propertyType)
=> propertyType.EditorAlias.Equals("our.iconic");

Expand All @@ -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<SelectedIcon>();
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Our.Iconic/App_Plugins/Iconic/js/src/iconic.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4eb0987

Please sign in to comment.