From 9b6334a535401e780414cb800f73d69b3a32c6c1 Mon Sep 17 00:00:00 2001 From: robgha01 Date: Wed, 4 Jul 2018 15:07:09 +0200 Subject: [PATCH] This fixes issue 28 --- .../controllers/Settings.Controller.js | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Analytics/App_Plugins/Analytics/backOffice/AnalyticsTree/controllers/Settings.Controller.js b/Analytics/App_Plugins/Analytics/backOffice/AnalyticsTree/controllers/Settings.Controller.js index 8e4faea..9bf7542 100644 --- a/Analytics/App_Plugins/Analytics/backOffice/AnalyticsTree/controllers/Settings.Controller.js +++ b/Analytics/App_Plugins/Analytics/backOffice/AnalyticsTree/controllers/Settings.Controller.js @@ -1,16 +1,16 @@ angular.module("umbraco").controller("Analytics.SettingsController", - function ($scope, $routeParams, settingsResource, notificationsService, localizationService, navigationService) { + function ($scope, $timeout, $routeParams, analyticsSettingsResource, notificationsService, localizationService, navigationService) { //By default user has not authorised var hasUserAuthd = false; - //Get all settings via settingsResource - does WebAPI GET call - settingsResource.getall().then(function (response) { + //Get all settings via analyticsSettingsResource - does WebAPI GET call + analyticsSettingsResource.getall().then(function (response) { $scope.settings = response.data; }); //Get Account JSON & bind back to dropdown - settingsResource.getaccount().then(function (response) { + analyticsSettingsResource.getaccount().then(function (response) { if (response.data === "null") { $scope.selectedaccount = null; } @@ -20,7 +20,7 @@ }); //Get Profile JSON & bind back to dropdown - settingsResource.getprofile().then(function (response) { + analyticsSettingsResource.getprofile().then(function (response) { if (response.data === "null") { $scope.selectedprofile = null; } @@ -31,27 +31,29 @@ //Get oAuth Check - WebAPI GET (Basically checks if RefreshToken has a value) - settingsResource.checkauth().then(function (response) { + analyticsSettingsResource.checkauth().then(function (response) { //Show or hide the auth button (set on scope & local var for if check) hasUserAuthd = response.data === "true"; //Apply - $scope.$apply(function () { + $timeout(function(){ + // any code in here will automatically have an apply run afterwards + // source: https://stackoverflow.com/a/23102223 $scope.hasAuthd = hasUserAuthd; }); //Only load/fetch if showAuth is true if (hasUserAuthd === true) { - //Get all accounts via settingsResource - does WebAPI GET call - settingsResource.getaccounts().then(function (response) { + //Get all accounts via analyticsSettingsResource - does WebAPI GET call + analyticsSettingsResource.getaccounts().then(function (response) { $scope.accounts = response.data; if ($scope.selectedaccount != null) { $scope.selectedaccount = _.where($scope.accounts, { Id: $scope.selectedaccount.Id })[0]; - settingsResource.getprofiles($scope.selectedaccount.Id).then(function (response) { + analyticsSettingsResource.getprofiles($scope.selectedaccount.Id).then(function (response) { $scope.profiles = response.data; if ($scope.selectedprofile != null) { $scope.selectedprofile = _.where($scope.profiles, { Id: $scope.selectedprofile.Id })[0]; @@ -63,7 +65,7 @@ //When an account is selected $scope.accountSelected = function (selectedAccount) { - settingsResource.getprofiles(selectedAccount.Id).then(function (response) { + analyticsSettingsResource.getprofiles(selectedAccount.Id).then(function (response) { $scope.profiles = response.data; }); }; @@ -83,7 +85,7 @@ $scope.save = function (settings, account, profile) { //Save settings resource - does a WebAPI POST call - settingsResource.save(settings).then(function (response) { + analyticsSettingsResource.save(settings).then(function (response) { $scope.settings = response.data; //Display Success message @@ -91,7 +93,7 @@ }); //Save settings resource - does a WebAPI POST call - settingsResource.saveAccount(account).then(function (response) { + analyticsSettingsResource.saveAccount(account).then(function (response) { //Don't need anything from response.data back //Display Success message @@ -99,7 +101,7 @@ }); //Save settings resource - does a WebAPI POST call - settingsResource.saveProfile(profile).then(function (response) { + analyticsSettingsResource.saveProfile(profile).then(function (response) { //Don't need anything from response.data back //Display Success message @@ -111,5 +113,9 @@ }; - navigationService.syncTree({ tree: 'analyticsTree', path: ["-1", $routeParams.id], forceReload: false }); + $timeout(function(){ + // any code in here will automatically have an apply run afterwards + // source: https://stackoverflow.com/a/23102223 + navigationService.syncTree({ tree: 'analyticsTree', path: ["-1", $routeParams.id], forceReload: false }); + }); }); \ No newline at end of file