diff --git a/frontend/app/scripts/controllers/RootCtrl.js b/frontend/app/scripts/controllers/RootCtrl.js index 15c3f71ec2..891c2ead60 100644 --- a/frontend/app/scripts/controllers/RootCtrl.js +++ b/frontend/app/scripts/controllers/RootCtrl.js @@ -2,7 +2,7 @@ * Controller for main page */ angular.module('theHiveControllers').controller('RootCtrl', - function($scope, $rootScope, $uibModal, $location, $state, AuthenticationSrv, AlertingSrv, StreamSrv, StreamStatSrv, CaseSrv, CaseTemplateSrv, CustomFieldsSrv, NotificationSrv, AppLayoutSrv, VersionSrv, currentUser, appConfig) { + function($scope, $rootScope, $timeout, $uibModal, $location, $state, AuthenticationSrv, AlertingSrv, StreamSrv, StreamStatSrv, CaseSrv, CaseTemplateSrv, CustomFieldsSrv, NotificationSrv, AppLayoutSrv, VersionSrv, currentUser, appConfig) { 'use strict'; if(currentUser === 520) { @@ -145,24 +145,29 @@ angular.module('theHiveControllers').controller('RootCtrl', modal.result .then(function(organisation) { - console.log(organisation); - $rootScope.isLoading = true; - AuthenticationSrv.current(organisation) - .then(function(/*userData*/) { - $rootScope.isLoading = false; - $state.go('app.index'); - }) - .catch( function(err) { - NotificationSrv.error('App', err.data, err.status); - $rootScope.isLoading = false; + return AuthenticationSrv.current(organisation) + .then(function(userData) { + $scope.currentUser = userData; + StreamSrv.cancelPoll(); }); }) + .then(function() { + $state.go('app.index', {}, {reload:true}); + }) .catch(function(err) { if(err && !_.isString(err)) { NotificationSrv.error('Switch organisation', err.data, err.status); } + + NotificationSrv.error('App', err.data, err.status); + }) + .finally(function() { + $timeout(function() { + $rootScope.isLoading = false; + }, 500); + }); }; diff --git a/frontend/app/scripts/directives/user.js b/frontend/app/scripts/directives/user.js index 15c14a0fda..0736bfc454 100644 --- a/frontend/app/scripts/directives/user.js +++ b/frontend/app/scripts/directives/user.js @@ -30,9 +30,9 @@ scope.$watch('user', function(value) { if(!value) { return; - } + } scope.userInfo(value).then(function(userData) { - scope.userData = userData; + scope.userData = userData; }); }); } diff --git a/frontend/app/scripts/services/api/AuthenticationSrv.js b/frontend/app/scripts/services/api/AuthenticationSrv.js index 9fd29e3e71..4c12d0e015 100644 --- a/frontend/app/scripts/services/api/AuthenticationSrv.js +++ b/frontend/app/scripts/services/api/AuthenticationSrv.js @@ -2,7 +2,7 @@ 'use strict'; angular .module('theHiveServices') - .factory('AuthenticationSrv', function($http, $q, UtilsSrv, SecuritySrv) { + .factory('AuthenticationSrv', function($http, $q, UtilsSrv, SecuritySrv, UserSrv) { var self = { currentUser: null, login: function(username, password, code) { @@ -46,8 +46,11 @@ return $http .get('./api/v1/user/current', options) .then(function(response) { - self.currentUser = response.data; - UtilsSrv.shallowClearAndCopy(response.data, result); + var userData = response.data; + + self.currentUser = userData; + UserSrv.updateCache(userData.login, userData); + UtilsSrv.shallowClearAndCopy(userData, result); return $q.resolve(result); }) diff --git a/frontend/app/scripts/services/common/data/StreamSrv.js b/frontend/app/scripts/services/common/data/StreamSrv.js index 4426778dc1..bde90b37fc 100644 --- a/frontend/app/scripts/services/common/data/StreamSrv.js +++ b/frontend/app/scripts/services/common/data/StreamSrv.js @@ -1,13 +1,16 @@ (function() { 'use strict'; - angular.module('theHiveServices').factory('StreamSrv', function($rootScope, $http, $timeout, UserSrv, AuthenticationSrv, AfkSrv, NotificationSrv) { + angular.module('theHiveServices').factory('StreamSrv', function($q, $rootScope, $http, $timeout, UserSrv, AuthenticationSrv, AfkSrv, NotificationSrv) { var self = { isPolling: false, streamId: null, + httpRequestCanceller: $q.defer(), + disabled: true, init: function() { self.streamId = null; + self.disabled = false; self.requestStream(); }, @@ -82,6 +85,14 @@ self.runCallbacks('any', 'any', data); }, + cancelPoll: function() { + if(self.httpRequestCanceller) { + self.httpRequestCanceller.resolve('cancel'); + } + + self.disabled = true; + }, + poll: function() { // Skip polling is a poll is already running if (self.streamId === null || self.isPolling === true) { @@ -91,8 +102,13 @@ // Flag polling start self.isPolling = true; + // Initiate stream canceller + self.httpRequestCanceller = $q.defer(); + // Poll stream changes - $http.get('./api/stream/' + self.streamId).then(function(res) { + self.pollPromise = $http.get('./api/stream/' + self.streamId, { + timeout: self.httpRequestCanceller.promise + }).then(function(res) { // Flag polling end self.isPolling = false; @@ -116,6 +132,10 @@ // Initialize the stream; self.isPolling = false; + if(err && err.xhrStatus === 'abort') { + return; + } + if (err.status !== 404) { NotificationSrv.error('StreamSrv', err.data, err.status); @@ -160,9 +180,10 @@ var eventName = 'stream:' + config.rootId + '-' + config.objectType; config.scope.$on(eventName, function(event, data) { - config.callback(data); + if(!self.disabled) { + config.callback(data); + } }); - } }; diff --git a/frontend/app/views/components/header.component.html b/frontend/app/views/components/header.component.html index a47c51cfee..93aefb3a03 100644 --- a/frontend/app/views/components/header.component.html +++ b/frontend/app/views/components/header.component.html @@ -175,7 +175,7 @@ -
  • +
  • diff --git a/frontend/app/views/components/org/orgSwitch.modal.html b/frontend/app/views/components/org/orgSwitch.modal.html index 1c710a4f1e..1fb844b48a 100644 --- a/frontend/app/views/components/org/orgSwitch.modal.html +++ b/frontend/app/views/components/org/orgSwitch.modal.html @@ -18,7 +18,7 @@ -

    {{item.organisation}}

    +

    {{item.organisation}} (current)

    Profile: {{item.role}}