From c18f5a8076174805e6874a0f69f40ec10ff7c922 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Thu, 2 Nov 2017 00:38:30 +0100 Subject: [PATCH] Upgrade ui-router to 1.0.10 (#345) * Start upgrading to ui-router 1.0.0 * Remove ui-router event polyfill. --- package.json | 4 ++-- src/popup/app/app.js | 4 ++-- src/popup/app/config.js | 13 ++++++++++--- src/popup/app/global/mainController.js | 9 +++++---- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index ded3ed29..9d91626f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "angular-animate": "1.6.6", "angular-sweetalert": "1.1.2", "angular-toastr": "2.1.1", - "angular-ui-router": "0.4.2", "angulartics": "1.4.0", "angulartics-google-analytics": "0.4.0", "bootstrap": "3.3.7", @@ -66,6 +65,7 @@ "dependencies": { "@types/angular": "^1.6.34", "@types/chrome": "0.0.51", - "@types/jquery": "^3.2.16" + "@types/jquery": "^3.2.16", + "@uirouter/angularjs": "^1.0.10" } } diff --git a/src/popup/app/app.js b/src/popup/app/app.js index 8d677584..631ea0c7 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -6,7 +6,7 @@ require('clipboard'); require('angular'); require('angular-animate'); -require('angular-ui-router'); +const uiRouter = require('@uirouter/angularjs').default; require('angular-toastr'); require('ngclipboard'); @@ -65,7 +65,7 @@ import { SyncResponse } from '../../models/response/syncResponse'; angular .module('bit', [ - 'ui.router', + uiRouter, 'ngAnimate', 'toastr', 'angulartics', diff --git a/src/popup/app/config.js b/src/popup/app/config.js index 87b04802..301d27ee 100644 --- a/src/popup/app/config.js +++ b/src/popup/app/config.js @@ -265,20 +265,27 @@ params: { animation: null } }); }) - .run(function ($rootScope, userService, $state, constantsService, stateService) { + .run(function ($trace, $transitions, userService, $state, constantsService, stateService) { + $trace.enable('TRANSITION'); + stateService.init(); - $rootScope.$on('$stateChangeStart', function (event, toState, toParams) { + $transitions.onStart({}, function(trans) { + const $state = trans.router.stateService; + const toState = trans.to(); + if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) { stateService.removeState('vault'); stateService.removeState('viewFolder'); } + const userService = trans.injector().get('userService'); + if (!userService) { return; } - userService.isAuthenticated(function (isAuthenticated) { + userService.isAuthenticated((isAuthenticated) => { if (isAuthenticated) { var obj = {}; obj[constantsService.lastActiveKey] = (new Date()).getTime(); diff --git a/src/popup/app/global/mainController.js b/src/popup/app/global/mainController.js index 092673bc..b222448a 100644 --- a/src/popup/app/global/mainController.js +++ b/src/popup/app/global/mainController.js @@ -1,7 +1,7 @@ angular .module('bit.global') - .controller('mainController', function ($scope, $state, authService, toastr, i18nService, $analytics, utilsService, + .controller('mainController', function ($scope, $transitions, $state, authService, toastr, i18nService, $analytics, utilsService, $window) { var self = this; self.currentYear = new Date().getFullYear(); @@ -11,12 +11,13 @@ angular self.disableSearch = utilsService && utilsService.isEdge(); self.inSidebar = utilsService && utilsService.inSidebar($window); - $scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { + $transitions.onSuccess({}, function(transition) { + const toParams = transition.params("to"); + if (toParams.animation) { self.animation = toParams.animation; return; - } - else { + } else { self.animation = ''; } });