Fixes tree refreshing when changing users, fixes memory/event leak

This commit is contained in:
Shannon
2019-07-02 13:37:40 +10:00
parent c270d8ecac
commit 4ed746e4ef
4 changed files with 22 additions and 11 deletions

View File

@@ -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

View File

@@ -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);
});
},

View File

@@ -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();

View File

@@ -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;