Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bert Detailleur 21 posts 122 karma points
    May 29, 2018 @ 08:56
    Bert Detailleur
    0

    Problem with finding PropertyTypes in api, replacing id's with prevalue names -angularjs filter

    Hi all

    Is there an angular resource of some sort inside the api that can get prevalues from PropertyTypes?

    I noticed the umbraco api has an angular filter called ncNodeName (in umbraco.filters.js). it takes a nodeId and returns the name of the node.

    Awesome stuff & easy to use. especially with nested content. Now I want to do the same thing with propertyTypes, only to display the selected prevalue. The related filter does not exist as far as I now, so I attempted to construct it myself. The filter is based on the ncNodeNameFilter. I got the following result:

    // Filter to take a propertytype id and grab it's prevalues instead
    // Usage: {{ propertyTypeAlias | ncResolveId: aliasName }}
    
    // Cache for node names so we don't make a ton of requests
    var ncPropertyTypeCache = {
        prevalues: {}
    }
    
    angular.module("umbraco.filters").filter("ncPropertyType", function (dataTypeResource) {
    
        return function (input, alias) {
            // Check we have a value at all
            if (input === '' || input.toString() === '0') {
                return '';
            }
    
            // See if there is a value in the cache and use that
            if (ncPropertyTypeCache.prevalues[input]) {
                return ncPropertyTypeCache.prevalues[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
            ncPropertyTypeCache.keys[input] = 'Loading...';
            dataTypeResource.getPreValues(alias, null).then(function (prevalues) {
                console.log(prevalues);
                ncPropertyTypeCache.prevalue[input] = prevalues;
            });        
    
            // Return the current value for now
            return ncPropertyTypeCache.prevalues[input];
        };
    
    });
    

    The issue here is that dataTypeResource does not return the propertytype. I can only pass things over like 'umbraco.dropdown.flexible', not the ones I created. The returned values are kinda useless. I need to go a level deeper, but at first glance there is no resource available? Am I overlooking something?

    Thanks in advance

    Bert

Please Sign in or register to post replies

Write your reply to:

Draft