Skip to content

Commit

Permalink
Added wait spinner around the loading of bucket information, as that …
Browse files Browse the repository at this point in the history
…can be slow for some users on Prod. Also changed the existing spinner code to remove a bunch of unnecessary duplicate code. Also changed spinner code to use finally() so it is always turned off after a call to the backend, regardless of whether there is an error or not.
  • Loading branch information
longdogz committed Apr 5, 2017
1 parent 8cc2848 commit 359e3a3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 56 deletions.
3 changes: 3 additions & 0 deletions modules/ui/app/scripts/controllers/BucketsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ angular.module('wasabi.controllers').

$scope.loadBuckets = function () {
if($scope.experiment.id) {
UtilitiesFactory.startSpin();
BucketsFactory.query({
experimentId: $scope.experiment.id
}).$promise.then(function (buckets) {
Expand All @@ -19,6 +20,8 @@ angular.module('wasabi.controllers').
function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of experiment buckets could not be retrieved.');
$scope.modalInstance.close();
}).finally(function() {
UtilitiesFactory.stopSpin();
});
}
};
Expand Down
12 changes: 12 additions & 0 deletions modules/ui/app/scripts/controllers/ExperimentDetailsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ angular.module('wasabi.controllers').

// load experiment from server
$scope.loadExperiment = function () {
UtilitiesFactory.startSpin();
ExperimentsFactory.show({id: $stateParams.experimentId}).$promise.then(function (experiment) {
$scope.experiment = experiment;
if ($scope.experiment.hypothesisIsCorrect === null) {
Expand Down Expand Up @@ -255,13 +256,16 @@ angular.module('wasabi.controllers').
$rootScope.$broadcast('experiment_created');
}, function(response) {
UtilitiesFactory.handleGlobalError(response, 'Your experiment could not be retrieved.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
};

$scope.hasControlBucket = false;

// load buckets from server
$scope.loadBuckets = function () {
UtilitiesFactory.startSpin();
BucketsFactory.query({
experimentId: $stateParams.experimentId
}).$promise.then(function (buckets) {
Expand All @@ -274,10 +278,13 @@ angular.module('wasabi.controllers').
},
function(response) {
UtilitiesFactory.handleGlobalError(response, 'Your buckets could not be loaded.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
};

$scope.getApplicationStatistics = function() {
UtilitiesFactory.startSpin();
ApplicationStatisticsFactory.query({
experimentId: $stateParams.experimentId
}).$promise.then(function (appInfo) {
Expand All @@ -296,6 +303,8 @@ angular.module('wasabi.controllers').
},
function(response) {
UtilitiesFactory.handleGlobalError(response, 'Your user count could not be loaded.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
};

Expand All @@ -305,6 +314,7 @@ angular.module('wasabi.controllers').

// load statistics from server
$scope.loadStatistics = function () {
UtilitiesFactory.startSpin();
ExperimentStatisticsFactory.query({experimentId: $stateParams.experimentId}).$promise.
then(function (statistics) {
$scope.experiment.statistics = statistics;
Expand All @@ -317,6 +327,8 @@ angular.module('wasabi.controllers').

}, function(response) {
UtilitiesFactory.handleGlobalError(response, 'Your statistics could not be retrieved.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
};

Expand Down
23 changes: 7 additions & 16 deletions modules/ui/app/scripts/controllers/ExperimentsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ angular.module('wasabi.controllers').
}
};

$scope.startSpin = function(){
UtilitiesFactory.startSpin();
}

$scope.stopSpin = function(){
UtilitiesFactory.stopSpin();
}

$scope.doFavorites = function(experimentsList, forceGet) {
function applyFavorites(experimentsList) {
if ($scope.favoritesObj.favorites && $scope.favoritesObj.favorites.length && experimentsList) {
Expand Down Expand Up @@ -148,7 +140,7 @@ angular.module('wasabi.controllers').
return existingFilter += newFilterValue;
}

$scope.startSpin();
UtilitiesFactory.startSpin();

var queryParams = {
perPage: pageSize,
Expand Down Expand Up @@ -194,15 +186,19 @@ angular.module('wasabi.controllers').
function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of experiments could not be retrieved.');
}
);
).finally(function() {
UtilitiesFactory.stopSpin();
});
}
else {
ExperimentStatisticsFactory.cardViewData(queryParams).$promise
.then(afterLoadFunction,
function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of experiments could not be retrieved.');
}
);
).finally(function() {
UtilitiesFactory.stopSpin();
});
}
};

Expand Down Expand Up @@ -279,7 +275,6 @@ angular.module('wasabi.controllers').
$scope.applicationsWithReadOrBetterAccess.length === 0);

$scope.applicationsLoaded = true;
$scope.stopSpin();
});
};

Expand Down Expand Up @@ -393,10 +388,6 @@ angular.module('wasabi.controllers').
else {
$scope.doFavorites($scope.cardViewExperiments, false);
}

$scope.stopSpin();

//$scope.loadGridDataIfNecessary()
});
};

Expand Down
13 changes: 3 additions & 10 deletions modules/ui/app/scripts/controllers/LogsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ angular.module('wasabi.controllers').
UtilitiesFactory.hideHeading(false);
UtilitiesFactory.selectTopLevelTab('Tools');

$scope.startSpin = function(){
UtilitiesFactory.startSpin();
}

$scope.stopSpin = function(){
UtilitiesFactory.stopSpin();
}

$scope.changePage = function(destinationApp) {
if (destinationApp !== undefined) {
$scope.data.applicationName = destinationApp;
Expand Down Expand Up @@ -85,9 +77,8 @@ angular.module('wasabi.controllers').
sort: ($scope.reverseSort ? '-' : '') + $scope.orderByField.replace('_', '.'),
filter: $scope.data.query
};
$scope.startSpin();
UtilitiesFactory.startSpin();
LogsFactory.query(options).$promise.then(function (data) {
$scope.stopSpin();
$scope.logs = data.logEntries;
$scope.totalItems = data.totalEntries;

Expand All @@ -98,6 +89,8 @@ angular.module('wasabi.controllers').
{key: 'application_name', value: selectedApp});
}, function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of logs could not be retrieved.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
}
};
Expand Down
13 changes: 3 additions & 10 deletions modules/ui/app/scripts/controllers/PrioritiesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ angular.module('wasabi.controllers').
UtilitiesFactory.hideHeading(false);
UtilitiesFactory.selectTopLevelTab('Priority');

$scope.startSpin = function(){
UtilitiesFactory.startSpin();
}

$scope.stopSpin = function(){
UtilitiesFactory.stopSpin();
}

$scope.changePage = function(destinationApp) {
if (destinationApp !== undefined) {
$scope.data.applicationName = destinationApp;
Expand Down Expand Up @@ -129,10 +121,9 @@ angular.module('wasabi.controllers').
if (selectedApp) {
$scope.applicationName = $cookies.wasabiDefaultApplication = selectedApp;
$scope.noDrag = $scope.readOnly = !$scope.hasUpdatePermission(selectedApp);
$scope.startSpin();
UtilitiesFactory.startSpin();
PrioritiesFactory.query({applicationName: selectedApp}).$promise.then(function (priorities) {
$scope.experiments = priorities;
$scope.stopSpin();
$scope.doFavorites();

UtilitiesFactory.doTrackingInit();
Expand All @@ -142,6 +133,8 @@ angular.module('wasabi.controllers').
{key: 'application_name', value: selectedApp});
}, function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of priorities could not be retrieved.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
}
};
Expand Down
13 changes: 3 additions & 10 deletions modules/ui/app/scripts/controllers/SuperadminsTableCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,20 @@ angular.module('wasabi.controllers').

$scope.superadmins = [];

$scope.startSpin = function(){
UtilitiesFactory.startSpin();
}

$scope.stopSpin = function(){
UtilitiesFactory.stopSpin();
}

// load superadmins from server
$scope.loadSuperadmins = function () {
$scope.superadmins = [];
$scope.startSpin();
UtilitiesFactory.startSpin();
SuperadminsFactory.query().$promise.then(function(superadmins) {
$scope.stopSpin();
$scope.superadmins = superadmins;
for (var i = 0; i < $scope.superadmins.length; i++) {
$scope.superadmins[i].doNotShow = (Session.userID === $scope.superadmins[i].userID);
}
},
function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of superadmins could not be retrieved.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});
};

Expand Down
13 changes: 3 additions & 10 deletions modules/ui/app/scripts/controllers/UsersCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ angular.module('wasabi.controllers').
$scope.administeredApplications = [];
$scope.appNames = [];

$scope.startSpin = function(){
UtilitiesFactory.startSpin();
}

$scope.stopSpin = function(){
UtilitiesFactory.stopSpin();
}

// Load the list of applications the currently logged in user is an admin for.
$scope.loadAdministeredApplications = function () {
$scope.administeredApplications = UtilitiesFactory.getAdministeredApplications();
Expand All @@ -48,9 +40,8 @@ angular.module('wasabi.controllers').
$scope.loadUsers = function (orderByField) {

var users = [];
$scope.startSpin();
UtilitiesFactory.startSpin();
AuthzFactory.getUsersRoles().$promise.then(function(results) {
$scope.stopSpin();
if (results && results.length > 0) {
for (var i = 0; i < results.length; i++) {
// Go through each object, which represents the access for one application.
Expand Down Expand Up @@ -101,6 +92,8 @@ angular.module('wasabi.controllers').
},
function(response) {
UtilitiesFactory.handleGlobalError(response, 'The list of user roles could not be retrieved.');
}).finally(function() {
UtilitiesFactory.stopSpin();
});

};
Expand Down

0 comments on commit 359e3a3

Please sign in to comment.