Copied to clipboard

Flag this post as spam?

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


  • Rickard Liljeberg 23 posts 114 karma points
    Aug 21, 2016 @ 23:27
    Rickard Liljeberg
    0

    Reload node in custom tree

    I have a custom section with a Tree in it, and I have a custom way of resorting some nodes on the page of each node.

    So my tree looks like this

    • Other thing 1
    • Other thing 2
    • Tags
      • Location tags
        • Location NY
        • Location LA
      • Other tag category

    I have that if you click for instance "Location NY" you get to the page to edit Location NY and once there you can resort it under Location tags... so you can make Location NY come after Location LA in the list.

    All of this works fantastically... that is as long as I reload the page... because the tree refuses to update the order unless i reload the page.

    I have tried to use navigationService.syncTree on the parent, that did not help (does not seem to be the correct thing).

    I want to use: navigationService.reloadNode($scope.currentNode.parent); But $scope.currentNode gives me undefined

    All my attempts at using navigationService.reloadNode gives me: Uncaught No childNodesUrl property found on the tree node, cannot load child nodes

    Probably because I can't get hold of the node I need to refresh. I am in a controller in a directive when i try to run this code.

    I also tried navigationService.reloadSection("XXXXX") and I have tried different things where it says XXXXX but either I clear the tree or completely remove it entirely.

    So questions

    • Can I reload the node from the path (like I use when I use syncTree?)
    • Or, is there another way for me to get the Id I need?
  • Ian 178 posts 752 karma points
    Aug 22, 2016 @ 09:45
    Ian
    101

    This is what I did, I was using a custom list view in my section so I don't think you will need the final route.reload I just used it to get my view back in sync after sorting. Note I was sorting from a menu action and so I had access to the node id from dialogOptions.

    'use strict';
    (function () {
        //create the controller
        function MySettingsSortSubTopicsController($scope, $routeParams, mySettingsResource, $q, navigationService, $route) {
            $scope.editSortView = Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + "/" + $routeParams.section + "/backoffice/Settings/edit-sort.html";
            var dialogOptions = $scope.dialogOptions;
            $scope.save = function (items) {
                if (!$scope.busy) {
                    $scope.busy = true;
                    var saveIds = [];
                    for (var i = 0; i < items.length; i++) {
                        saveIds.push(items[i].id);
                    }
                    mySettingsResource.saveSortOrder(saveIds, "subtopic").then(function (result) {
                        navigationService.syncTree({ tree: "mySettings", path: ["-1", "topics", $scope.contentId], forceReload: true }).then(function (syncArgs) {
                            $scope.busy = false;
                            $scope.currentNode = syncArgs.node;
                            if ($routeParams.id == $scope.currentNode.id) {
                                $route.reload();
                            }
    
                        });
                        deferred.resolve(result);
                    });
                    var deferred = $q.defer();
                }
                return deferred.promise;
            }
    
            function init() {
                $scope.contentId = dialogOptions.currentNode.id;
                $scope.loaded = true;
            };
    
            init();
    
        };
        //register the controller
        angular.module("umbraco").controller('MySettings.SortSubTopicsController', MySettingsSortSubTopicsController);
    
    })();
    
  • Rickard Liljeberg 23 posts 114 karma points
    Aug 22, 2016 @ 20:13
    Rickard Liljeberg
    0

    This part

    navigationService.syncTree({ tree: "mySettings", path: ["-1", "topics", $scope.contentId], forceReload: true }).then(function (syncArgs) {
                            $scope.busy = false;
                            $scope.currentNode = syncArgs.node;
                            if ($routeParams.id == $scope.currentNode.id) {
                                $route.reload();
                            }
    
                        });
    

    was exactly what I needed, thanks!!

  • Ian Grainger 71 posts 135 karma points
    Aug 24, 2017 @ 15:35
    Ian Grainger
    0

    This is nearly working for us - but we're trying to load a different tree - and the problem seems to be that we need to switch to the new section before reloading.

    The problem there is that the call to changeSection is not blocking and doesn't return a promise - so I think I need to add an event handler for when the treeService has finished switching to the new tree - is that even possible?

    We can get it to work with yukky timeouts. I want to know the correct way to deal with the non-blocking call to changeSection?

    (Umbraco 7.4.1)

Please Sign in or register to post replies

Write your reply to:

Draft