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 =)
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.
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:
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:
Anyone have any thoughts? I've been banging my head against the wall =)
See method reloadNode
https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web.UI.Client/src/common/services/tree.service.js
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.
with and adjusted the CreateMap like:
Really appreciate the help. I was convinced I had blown something in the angular and needed the nudge.
is working on a reply...