Last active
February 13, 2017 15:18
-
-
Save mattbrailsford/d7f512ca4a6f24ebe70ebed82eb163f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filter to take a node id and grab it's name instead | |
// Usage: {{ pickerAlias | ncNodeName }} | |
// Cache for node names so we don't make a ton of requests | |
var ncNodeNameCache = { | |
id: "", | |
keys: {} | |
} | |
angular.module("umbraco.filters").filter("ncNodeName", function (editorState, entityResource) { | |
return function(input) { | |
var currentNode = editorState.getCurrent(); | |
// Ensure a unique cache per editor instance | |
var key = "ncNodeName_" + currentNode.key; | |
if (ncNodeNameCache.id != key){ | |
ncNodeNameCache.id = key; | |
ncNodeNameCache.keys = {}; | |
} | |
// See if there is a value in the cache and use that | |
if (ncNodeNameCache.keys[input]){ | |
return ncNodeNameCache.keys[input]; | |
} | |
// No value, so go fetch one | |
// We'll put a temp value in the cache though so we don't | |
// make a load of requests while we wait for a response | |
ncNodeNameCache.keys[input] = "Loading..."; | |
entityResource.getById(input, "Document") | |
.then(function(ent) { | |
ncNodeNameCache.keys[input] = ent.name; | |
}); | |
// Return the current value for now | |
return ncNodeNameCache.keys[input]; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mattbrailsford if you add something like this in the beginning, it doesn't stick at "Loading..." if no content node has been selected, but fallback to the default
ncNodeName