Check in all new plan manager directive and add a nice donut chart for the repository usage by the user/org

This commit is contained in:
Joseph Schorr 2013-11-06 17:30:20 -05:00
parent 934acce6d4
commit a6a225dd5f
6 changed files with 377 additions and 167 deletions

View file

@ -1191,75 +1191,6 @@ function OrgAdminCtrl($rootScope, $scope, Restangular, $routeParams, UserService
});
};
var subscribedToPlan = function(sub) {
$scope.planChanging = false;
$scope.subscription = sub;
PlanService.getPlan(sub.plan, function(subscribedPlan) {
$scope.subscribedPlan = subscribedPlan;
$scope.planUsagePercent = sub.usedPrivateRepos * 100 / $scope.subscribedPlan.privateRepos;
if (sub.usedPrivateRepos > $scope.subscribedPlan.privateRepos) {
$scope.overLimit = true;
} else if (sub.usedPrivateRepos >= $scope.subscribedPlan.privateRepos * 0.7) {
$scope.nearLimit = true;
} else {
$scope.overLimit = false;
$scope.nearLimit = false;
}
$scope.planLoading = false;
});
};
var loadSubscription = function() {
$scope.planLoading = true;
var getSubscription = Restangular.one(getRestUrl('organization', orgname, 'plan'));
getSubscription.get().then(subscribedToPlan, function() {
// Organization has no subscription.
subscribedToPlan({'plan': 'bus-free'});
});
};
$scope.getActiveSubClass = function() {
if ($scope.overLimit) { return 'danger'; }
if ($scope.nearLimit) { return 'warning'; }
return 'success';
};
$scope.subscribe = function(planId) {
$scope.planChanging = true;
PlanService.showSubscribeDialog($scope, planId, orgname, function() {
// Subscribing.
}, function(plan) {
// Subscribed.
subscribedToPlan(plan);
}, function() {
// Failure.
$scope.planChanging = false;
});
};
$scope.changeSubscription = function(planId) {
$scope.planChanging = true;
$scope.errorMessage = undefined;
var subscriptionDetails = {
plan: planId,
};
var changeSubscriptionRequest = Restangular.one(getRestUrl('organization', orgname, 'plan'));
changeSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
// Failure
$scope.planChanging = false;
});
};
$scope.cancelSubscription = function() {
$scope.changeSubscription('bus-free');
};
loadSubscription();
loadOrganization();
}