Copied to clipboard

Flag this post as spam?

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


  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 11, 2015 @ 16:47
    Rusty Swayne
    0

    Back Office Tree first child tree sync

    I am having an issue getting the first child node in a tree to resync it's children after performing a sorting operation.

    Here is a screen cast demonstrating the problem.

    https://drive.google.com/file/d/0B0o-8ZqA1sebTm5mMVZJTHNWZzg/view?usp=sharing

    Methodology

    I have a tree action that opens a dialog to sort similar to the way Umbraco sorts content (drag/drop). When the save button is clicked, an API call is made to save the sort orders that need to be updated.

    I think I'm close as my code successfully saves the sort data correctly to the database and actually does update the tree UI for children other than the first child in the tree.

    If I delete the client dependency temp file the tree will refresh, albeit this is also true for tapping the web.config - which at first led me to believe I had a caching problem in my service layer. However, since the sub trees are acting as expected using the exact same service calls it seems like a less likely suspect.

    I've tried:

    • Completely clearing the treeCache using Umbraco's Angular treeService
    • Resyncing the tree using the treeService (using the parent node and path)

    The dialogs for creating and deleting these nodes work just fine, but they don't require refreshing more than a single child. Delete simply removes the node after the deletion and the way I implemented adding a node just adds one to the bottom of the list so treeService.loadNodeChildren({ node: $scope.currentNode }); did the trick.

    Here is my save method for the sort:

            /**
             * @ngdoc method
             * @name save
             * @function
             *
             * @description - Saves the newly sorted nodes and updates the tree UI.
             */
            function save() {
    
                // set the sorts here
                for(var i = 0; i < $scope.entityCollections.length; i++) {
                    $scope.entityCollections[i].sortOrder = i;
                }
                // save updated sort orders
                var promise = entityCollectionResource.updateSortOrders($scope.entityCollections);
                promise.then(function() {
    
                    // reload the children of the parent
                    var childPromise = treeService.loadNodeChildren({ node: $scope.currentNode });
                    childPromise.then(function(children) {
                        navigationService.hideNavigation();
                        notificationsService.success('Collections sorted success.');
                    }, function(reason) {
                        notificationsService.error('failed to load node children ' + reason)
                    });
                });
            }
    

    Anyone have any thoughts? I've been banging my head against the wall =)

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Aug 12, 2015 @ 18:42
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 12, 2015 @ 19:40
    Rusty Swayne
    0

    Thanks Shannon,

    That lead me in the right direction. I had already tried reloadNode which did not work either so I started focusing back in the tree controller.

    The problem turned out to be a result of the Guid? returning as an Empty Guid rather than null for items which were sorted.

    For anyone that is interested, I fixed this issue by creating an AutoMapper ValueResolver for the ParentKey to assert that both nulls and Guid.Empty would return as null.

    public class EntityCollectionNullableParentKeyResolver : ValueResolver<IEntityCollection, Guid?>
    {
        /// <summary>
        /// Asserts the ParentKey returns null when an empty GUID or null.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <returns>
        /// The nullable Guid.
        /// </returns>
        protected override Guid? ResolveCore(IEntityCollection source)
        {
            return source.ParentKey == null || source.ParentKey == Guid.Empty ? null : source.ParentKey;
        }
    }
    

    with and adjusted the CreateMap like:

      AutoMapper.Mapper.CreateMap<IEntityCollection, EntityCollectionDisplay>()
                .ForMember(
                    dest => dest.EntityTypeField,
                    opt =>
                    opt.ResolveUsing<EntityTypeFieldResolver>().ConstructedBy(() => new EntityTypeFieldResolver()))
                .ForMember(
                    dest => dest.ParentKey,
                    opt =>
                        opt.ResolveUsing<EntityCollectionNullableParentKeyResolver>().ConstructedBy(() => new EntityCollectionNullableParentKeyResolver()));
    

    Really appreciate the help. I was convinced I had blown something in the angular and needed the nudge.

Please Sign in or register to post replies

Write your reply to:

Draft