Ensure the main controller is aware of the newly setup subscription

This commit is contained in:
Johannes Zellner
2018-04-05 23:27:39 +02:00
parent a16bd7030a
commit 593bde9d92
2 changed files with 20 additions and 18 deletions

View File

@@ -97,19 +97,24 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
}
$scope.fetchAppstoreProfileAndSubscription = function (callback) {
if (!$scope.appstoreConfig.token) return callback();
AppStore.getProfile($scope.appstoreConfig.token, function (error, result) {
Client.getAppstoreConfig(function (error, result) {
if (error) return callback(error);
if (!result.token) return callback();
$scope.appstoreConfig.profile = result;
$scope.appstoreConfig = result;
AppStore.getSubscription($scope.appstoreConfig, function (error, result) {
AppStore.getProfile($scope.appstoreConfig.token, function (error, result) {
if (error) return callback(error);
$scope.subscription = result;
$scope.appstoreConfig.profile = result;
callback();
AppStore.getSubscription($scope.appstoreConfig, function (error, result) {
if (error) return callback(error);
$scope.subscription = result;
callback();
});
});
});
};
@@ -166,17 +171,10 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
if ($scope.user.admin) {
runConfigurationChecks();
Client.getAppstoreConfig(function (error, result) {
if (error) return console.error(error);
if (!result.token) return;
$scope.fetchAppstoreProfileAndSubscription(function (error) {
if (error) console.error(error);
$scope.appstoreConfig = result;
$scope.fetchAppstoreProfileAndSubscription(function (error) {
if (error) console.error(error);
$scope.ready = true;
});
$scope.ready = true;
});
}
});