Use the new getSubscription API in main controller
This commit is contained in:
@@ -102,13 +102,13 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p ng-show="config.update.box">
|
||||
You can update to the next version once you have <a ng-href="{{ config.webServerOrigin + '/console.html#/userprofile?view=subscriptions&email=' + appstoreConfig.profile.emailEncoded + '&cloudronId=' + appstoreConfig.cloudronId }}" target="_blank">setup billing</a>.
|
||||
You can update to the next version once you have <a ng-href="{{ config.webServerOrigin + '/console.html#/userprofile?view=subscriptions&email=' + subscription.emailEncoded + '&cloudronId=' + subscription.cloudronId }}" target="_blank">setup billing</a>.
|
||||
</p>
|
||||
<p>
|
||||
Our paid plans allow you to install unlimited standard and premium apps.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-success" ng-click="waitForPlanSelection()" ng-href="{{ config.webServerOrigin + '/console.html#/userprofile?view=subscriptions&email=' + appstoreConfig.profile.emailEncoded + '&cloudronId=' + appstoreConfig.cloudronId }}" target="_blank" ng-disabled="waitingForPlanSelection"><i class="fa fa-circle-notch fa-spin" ng-show="waitingForPlanSelection"></i> Setup Subscription</a>
|
||||
<a class="btn btn-success" ng-click="waitForPlanSelection()" ng-href="{{ config.webServerOrigin + '/console.html#/userprofile?view=subscriptions&email=' + subscription.emailEncoded + '&cloudronId=' + subscription.cloudronId }}" target="_blank" ng-disabled="waitingForPlanSelection"><i class="fa fa-circle-notch fa-spin" ng-show="waitingForPlanSelection"></i> Setup Subscription</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -133,7 +133,7 @@
|
||||
|
||||
<div class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav navbar-right" ng-hide="hideNavBarActions">
|
||||
<li ng-show="ready && subscription.plan.id === 'free'">
|
||||
<li ng-show="subscription.plan && subscription.plan.id === 'free'">
|
||||
<a ng-href="" ng-click="showSubscriptionModal()" style="cursor: pointer">
|
||||
<span class="badge badge-success">Setup Subscription</span>
|
||||
</a>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user