Use the new getSubscription API in main controller

This commit is contained in:
Girish Ramakrishnan
2019-05-04 21:19:46 -07:00
parent ceb0770ea0
commit fec82d127e
2 changed files with 12 additions and 32 deletions

View File

@@ -10,10 +10,8 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
$scope.config = {};
$scope.status = {};
$scope.client = Client;
$scope.appstoreConfig = {};
$scope.subscription = {};
$scope.notifications = [];
$scope.ready = false;
$scope.hideNavBarActions = $location.path() === '/logs';
@@ -53,16 +51,16 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
function checkPlan() {
if (!$scope.waitingForPlanSelection) return;
AppStore.getSubscription($scope.appstoreConfig, function (error, result) {
Client.getSubscription(function (error, subscription) {
if (error) return console.error(error);
// check again to give more immediate feedback once a subscription was setup
if (result.plan.id === 'free') {
if (subscription.plan.id === 'free') {
$timeout(checkPlan, 5000);
} else {
$scope.waitingForPlanSelection = false;
$('#setupSubscriptionModal').modal('hide');
if ($scope.config.update && $scope.config.update.box) $('#updateModal').modal('show');
$scope.subscription = subscription;
}
});
}
@@ -83,26 +81,12 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
});
}
$scope.fetchAppstoreProfileAndSubscription = function (callback) {
Client.getAppstoreConfig(function (error, appstoreConfig) {
if (error) return callback(error);
if (!appstoreConfig.token) return callback();
// NOTE: this function is exported and called from the settings.js
$scope.updateSubscriptionStatus = function () {
Client.getSubscription(function (error, subscription) {
if (error) console.error(error);
AppStore.getProfile(appstoreConfig.token, function (error, result) {
if (error) return callback(error);
// assign late to avoid UI flicketing on update
appstoreConfig.profile = result;
$scope.appstoreConfig = appstoreConfig;
AppStore.getSubscription($scope.appstoreConfig, function (error, result) {
if (error) return callback(error);
$scope.subscription = result;
callback();
});
});
$scope.subscription = subscription;
});
};
@@ -170,11 +154,7 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
refreshNotifications();
if (!$scope.config.managed) {
$scope.fetchAppstoreProfileAndSubscription(function (error) {
if (error) console.error(error);
$scope.ready = true;
});
$scope.updateSubscriptionStatus();
}
});
});