Fixes tree refreshing when changing users, fixes memory/event leak
This commit is contained in:
@@ -92,10 +92,6 @@ function umbTreeDirective($q, $rootScope, treeService, notificationsService, use
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This isn't used!?
|
||||
function clearCache(section) {
|
||||
treeService.clearCache({ section: section });
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-loads the tree with the updated parameters
|
||||
|
||||
@@ -349,7 +349,7 @@ function navigationService($routeParams, $location, $q, $injector, eventsService
|
||||
|
||||
reloadSection: function(sectionAlias) {
|
||||
return navReadyPromise.promise.then(function () {
|
||||
mainTreeApi.clearCache({ section: sectionAlias });
|
||||
treeService.clearCache({ section: sectionAlias });
|
||||
return mainTreeApi.load(sectionAlias);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
*
|
||||
*/
|
||||
function MainController($scope, $location, appState, treeService, notificationsService,
|
||||
userService, historyService, updateChecker, assetsService, eventsService,
|
||||
tmhDynamicLocale, localStorageService, editorService, overlayService, focusService) {
|
||||
userService, historyService, updateChecker, navigationService, eventsService,
|
||||
tmhDynamicLocale, localStorageService, editorService, overlayService) {
|
||||
|
||||
//the null is important because we do an explicit bool check on this in the view
|
||||
$scope.authenticated = null;
|
||||
@@ -105,6 +105,13 @@ function MainController($scope, $location, appState, treeService, notificationsS
|
||||
//if the user has changed we need to redirect to the root so they don't try to continue editing the
|
||||
//last item in the URL (NOTE: the user id can equal zero, so we cannot just do !data.lastUserId since that will resolve to true)
|
||||
if (data.lastUserId !== undefined && data.lastUserId !== null && data.lastUserId !== data.user.id) {
|
||||
|
||||
var section = appState.getSectionState("currentSection");
|
||||
if (section) {
|
||||
//if there's a section already assigned, reload it so the tree is cleared
|
||||
navigationService.reloadSection(section);
|
||||
}
|
||||
|
||||
$location.path("/").search("");
|
||||
historyService.removeAll();
|
||||
treeService.clearCache();
|
||||
|
||||
@@ -140,8 +140,9 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
|
||||
//// TODO: remove this it's not a thing
|
||||
//$scope.selectedId = navigationService.currentId;
|
||||
|
||||
var isInit = false;
|
||||
var evts = [];
|
||||
|
||||
|
||||
//Listen for global state changes
|
||||
evts.push(eventsService.on("appState.globalState.changed", function (e, args) {
|
||||
if (args.key === "showNavigation") {
|
||||
@@ -236,8 +237,10 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
|
||||
}));
|
||||
|
||||
//when the application is ready and the user is authorized, setup the data
|
||||
//this will occur anytime a new user logs in!
|
||||
evts.push(eventsService.on("app.ready", function (evt, data) {
|
||||
init();
|
||||
$scope.authenticated = true;
|
||||
ensureInit();
|
||||
}));
|
||||
|
||||
// event for infinite editors
|
||||
@@ -305,9 +308,14 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar
|
||||
/**
|
||||
* Called when the app is ready and sets up the navigation (should only be called once)
|
||||
*/
|
||||
function init() {
|
||||
function ensureInit() {
|
||||
|
||||
$scope.authenticated = true;
|
||||
//only run once ever!
|
||||
if (isInit) {
|
||||
return;
|
||||
}
|
||||
|
||||
isInit = true;
|
||||
|
||||
var navInit = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user