got legacy tree icons showing up now, added a couple of filters for this to work.

This commit is contained in:
Shannon Deminick
2013-06-02 17:09:16 -10:00
parent c60cc5d10d
commit 575b5b71ab
9 changed files with 120 additions and 41 deletions

View File

@@ -4,33 +4,6 @@ using Newtonsoft.Json.Linq;
namespace Umbraco.Core.Serialization
{
/// <summary>
/// This is used in order to deserialize a json object on a property into a json string since the property's type is 'string'
/// </summary>
internal class JsonToStringConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.ValueType == typeof(string))
{
return reader.Value;
}
// Load JObject from stream
JObject jObject = JObject.Load(reader);
return jObject.ToString();
}
public override bool CanConvert(Type objectType)
{
return typeof(string).IsAssignableFrom(objectType);
}
}
internal abstract class JsonCreationConverter<T> : JsonConverter
{
/// <summary>

View File

@@ -691,6 +691,7 @@
<Compile Include="Serialization\IStreamedResult.cs" />
<Compile Include="Serialization\JsonCreationConverter.cs" />
<Compile Include="Serialization\JsonNetSerializer.cs" />
<Compile Include="Serialization\JsonToStringConverter.cs" />
<Compile Include="Serialization\SerializationExtensions.cs" />
<Compile Include="Serialization\SerializationService.cs" />
<Compile Include="Serialization\StreamedResult.cs" />

View File

@@ -0,0 +1,21 @@
'use strict';
define(['angular'], function (angular) {
/**
* @ngdoc filter
* @name umbraco.filters:umbTreeIconClass
* @restrict E
* @description This will properly render the tree icon class based on the tree icon set on the server
**/
function treeIconClassFilter() {
return function (treeNode, standardClasses) {
if (treeNode.iconIsClass) {
return standardClasses + " " + treeNode.icon;
}
return standardClasses;
};
};
angular.module('umbraco.filters').filter("umbTreeIconClass", treeIconClassFilter);
});

View File

@@ -0,0 +1,21 @@
'use strict';
define(['angular'], function (angular) {
/**
* @ngdoc filter
* @name umbraco.filters:umbTreeIconImage
* @restrict E
* @description This will properly render the tree icon image based on the tree icon set on the server
**/
function treeIconImageFilter() {
return function (treeNode) {
if (treeNode.iconIsClass) {
return "";
}
return "<img src='" + treeNode.iconFilePath + "'></img>";
};
};
angular.module('umbraco.filters').filter("umbTreeIconImage", treeIconImageFilter);
});

View File

@@ -13,7 +13,8 @@
ng-class="{'icon-caret-right': !node.expanded, 'icon-caret-down': node.expanded}"
ng-click="getTreeChildren(node)"></ins>
<i class="icon umb-tree-icon sprTree {{node.icon}}"></i>
<i class="{{node|umbTreeIconClass:'icon umb-tree-icon sprTree'}}" ng-bind-html-unsafe="node|umbTreeIconImage">
</i>
<a ng-href="#{{node.view}}">{{node.name}}</a>
<i class="umb-options" ng-click="showContextMenu(node, $event)"><i></i><i></i><i></i></i>

View File

@@ -4,19 +4,51 @@
* Licensed MIT
*/
'use strict';
define([ 'app','angular'], function (app,angular) {
angular.module('umbraco.filters', [])
.filter('interpolate', ['version', function(version) {
return function(text) {
define(['app', 'angular'], function (app, angular) {
angular.module('umbraco.filters', [])
.filter('interpolate', ['version', function (version) {
return function (text) {
return String(text).replace(/\%VERSION\%/mg, version);
};
}])
.filter('propertyEditor', function() {
return function(input) {
.filter('propertyEditor', function () {
return function (input) {
return "views/propertyeditors/" + String(input).replace('.', '/') + "/editor.html";
};
});
/**
* @ngdoc filter
* @name umbraco.filters:umbTreeIconImage
* @restrict E
* @description This will properly render the tree icon image based on the tree icon set on the server
**/
function treeIconImageFilter() {
return function (treeNode) {
if (treeNode.iconIsClass) {
return "";
}
return "<img src='" + treeNode.iconFilePath + "'></img>";
};
};
angular.module('umbraco.filters').filter("umbTreeIconImage", treeIconImageFilter);
return app;
/**
* @ngdoc filter
* @name umbraco.filters:umbTreeIconClass
* @restrict E
* @description This will properly render the tree icon class based on the tree icon set on the server
**/
function treeIconClassFilter() {
return function (treeNode, standardClasses) {
if (treeNode.iconIsClass) {
return standardClasses + " " + treeNode.icon;
}
return standardClasses;
};
};
angular.module('umbraco.filters').filter("umbTreeIconClass", treeIconClassFilter);
return app;
});

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Umbraco.Core.IO;
namespace Umbraco.Web.Trees
{
@@ -65,6 +66,33 @@ namespace Umbraco.Web.Trees
[DataMember(Name = "icon")]
public string Icon { get; set; }
/// <summary>
/// Returns true if the icon represents a CSS class instead of a file path
/// </summary>
[DataMember(Name = "iconIsClass")]
public bool IconIsClass
{
get
{
//if it starts with a '.' or doesn't contain a '.' at all then it is a class
return Icon.StartsWith(".") || Icon.Contains(".") == false;
}
}
/// <summary>
/// Returns the icon file path if the icon is not a class, otherwise returns an empty string
/// </summary>
[DataMember(Name = "iconFilePath")]
public string IconFilePath
{
get
{
return IconIsClass
? string.Empty
: IOHelper.ResolveUrl("~/umbraco/images/umbraco/" + Icon);
}
}
/// <summary>
/// The URL path for the editor for this model
/// </summary>

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json.Linq;
namespace Umbraco.Web.Trees
{

View File

@@ -303,6 +303,7 @@
<Compile Include="Trees\ApplicationTreeExtensions.cs" />
<Compile Include="Trees\TreeNode.cs" />
<Compile Include="Trees\TreeNodeCollection.cs" />
<Compile Include="Trees\TreeNodeSerializer.cs" />
<Compile Include="Trees\TreeQueryStringParameters.cs" />
<Compile Include="Trees\ApplicationTreeApiController.cs" />
<Compile Include="Editors\BackOfficeController.cs" />