Redo user admin page to match the style of the org admin page
This commit is contained in:
parent
dba806fd97
commit
10db2884ac
7 changed files with 91 additions and 176 deletions
|
@ -557,12 +557,13 @@ quayApp.directive('planManager', function () {
|
|||
$scope.planUsagePercent = sub.usedPrivateRepos * 100 / $scope.subscribedPlan.privateRepos;
|
||||
|
||||
if (sub.usedPrivateRepos > $scope.subscribedPlan.privateRepos) {
|
||||
$scope.overLimit = true;
|
||||
$scope.limit = 'over';
|
||||
} else if (sub.usedPrivateRepos == $scope.subscribedPlan.privateRepos) {
|
||||
$scope.limit = 'at';
|
||||
} else if (sub.usedPrivateRepos >= $scope.subscribedPlan.privateRepos * 0.7) {
|
||||
$scope.nearLimit = true;
|
||||
$scope.limit = 'near';
|
||||
} else {
|
||||
$scope.overLimit = false;
|
||||
$scope.nearLimit = false;
|
||||
$scope.limit = 'none';
|
||||
}
|
||||
|
||||
if (!$scope.chart) {
|
||||
|
@ -588,9 +589,7 @@ quayApp.directive('planManager', function () {
|
|||
|
||||
var update = function() {
|
||||
$scope.planLoading = true;
|
||||
|
||||
if (!$scope.plans) { return; }
|
||||
if (!$scope.user && !$scope.organization) { return; }
|
||||
|
||||
PlanService.getSubscription($scope.organization, subscribedToPlan, function() {
|
||||
// User/Organization has no subscription.
|
||||
|
@ -599,6 +598,7 @@ quayApp.directive('planManager', function () {
|
|||
};
|
||||
|
||||
var loadPlans = function() {
|
||||
if (!$scope.user && !$scope.organization) { return; }
|
||||
PlanService.getPlans(function(plans) {
|
||||
$scope.plans = plans[$scope.organization ? 'business' : 'user'];
|
||||
update();
|
||||
|
@ -606,15 +606,15 @@ quayApp.directive('planManager', function () {
|
|||
};
|
||||
|
||||
// Start the initial download.
|
||||
loadPlans();
|
||||
update();
|
||||
$scope.planLoading = true;
|
||||
loadPlans();
|
||||
|
||||
$scope.$watch('organization', function() {
|
||||
update();
|
||||
loadPlans();
|
||||
});
|
||||
|
||||
$scope.$watch('user', function() {
|
||||
update();
|
||||
loadPlans();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -667,91 +667,24 @@ function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) {
|
|||
}
|
||||
|
||||
function UserAdminCtrl($scope, $timeout, Restangular, PlanService, UserService, KeyService, $routeParams) {
|
||||
// Load the list of plans.
|
||||
PlanService.getPlans(function(plans) {
|
||||
$scope.plans = plans.user;
|
||||
});
|
||||
|
||||
$scope.$watch(function () { return UserService.currentUser(); }, function (currentUser) {
|
||||
$scope.askForPassword = currentUser.askForPassword;
|
||||
if (!currentUser.anonymous) {
|
||||
$scope.user = currentUser;
|
||||
}
|
||||
$scope.loading = false;
|
||||
}, true);
|
||||
|
||||
var subscribedToPlan = function(sub) {
|
||||
$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.errorMessage = 'You are using more private repositories than your plan allows, please upgrade your subscription to avoid disruptions in your service.';
|
||||
} else {
|
||||
$scope.errorMessage = null;
|
||||
}
|
||||
|
||||
$scope.planLoading = false;
|
||||
$scope.planChanging = false;
|
||||
|
||||
mixpanel.people.set({
|
||||
'plan': sub.plan
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.planLoading = true;
|
||||
UserService.getCurrentSubscription(subscribedToPlan, function() {
|
||||
// User has no subscription
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
|
||||
$scope.planChanging = false;
|
||||
$scope.subscribe = function(planId) {
|
||||
PlanService.showSubscribeDialog($scope, planId, null, function() {
|
||||
// Subscribing.
|
||||
$scope.planChanging = true;
|
||||
}, function(plan) {
|
||||
// Subscribed.
|
||||
UserService.resetCurrentSubscription();
|
||||
subscribedToPlan(plan);
|
||||
}, function() {
|
||||
// Failure.
|
||||
$scope.errorMessage = 'Unable to subscribe.';
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeSubscription = function(planId) {
|
||||
$scope.planChanging = true;
|
||||
$scope.errorMessage = undefined;
|
||||
|
||||
var subscriptionDetails = {
|
||||
plan: planId,
|
||||
};
|
||||
|
||||
UserService.resetCurrentSubscription();
|
||||
var changeSubscriptionRequest = Restangular.one('user/plan');
|
||||
changeSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
|
||||
// Failure
|
||||
$scope.errorMessage = 'Unable to change subscription.';
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cancelSubscription = function() {
|
||||
$scope.changeSubscription('free');
|
||||
};
|
||||
|
||||
// Show the subscribe dialog if a plan was requested.
|
||||
var requested = $routeParams['plan']
|
||||
if (requested !== undefined && requested !== 'free') {
|
||||
PlanService.getPlan(requested, function(found) {
|
||||
if (found) {
|
||||
$scope.subscribe(requested);
|
||||
}
|
||||
});
|
||||
// TODO: this.
|
||||
}
|
||||
|
||||
$scope.loading = true;
|
||||
$scope.updatingUser = false;
|
||||
$scope.changePasswordSuccess = false;
|
||||
|
||||
$('.form-change-pw').popover();
|
||||
|
||||
$scope.changePassword = function() {
|
||||
|
@ -768,6 +701,7 @@ function UserAdminCtrl($scope, $timeout, Restangular, PlanService, UserService,
|
|||
$scope.user.repeatPassword = '';
|
||||
$scope.changePasswordForm.$setPristine();
|
||||
|
||||
// Reload the user.
|
||||
UserService.load();
|
||||
}, function(result) {
|
||||
$scope.updatingUser = false;
|
||||
|
@ -1176,6 +1110,7 @@ function OrgAdminCtrl($rootScope, $scope, Restangular, $routeParams, UserService
|
|||
});
|
||||
|
||||
var orgname = $routeParams.orgname;
|
||||
$scope.orgname = orgname;
|
||||
|
||||
var loadOrganization = function() {
|
||||
var getOrganization = Restangular.one(getRestUrl('organization', orgname));
|
||||
|
|
|
@ -1175,18 +1175,6 @@ RepositoryUsageChart.prototype.drawInternal_ = function() {
|
|||
|
||||
var data = [count, Math.max(0, total - count)];
|
||||
|
||||
var getClass = function(i) {
|
||||
if (total > 0 && (count / total) >= 0.7) {
|
||||
return 'warning-' + i;
|
||||
}
|
||||
|
||||
if (count >= total) {
|
||||
return 'error-' + i;
|
||||
}
|
||||
|
||||
return 'normal';
|
||||
};
|
||||
|
||||
var arcTween = function(a) {
|
||||
var i = d3.interpolate(this._current, a);
|
||||
this._current = i(0);
|
||||
|
@ -1208,7 +1196,7 @@ RepositoryUsageChart.prototype.drawInternal_ = function() {
|
|||
.data(pie)
|
||||
.enter().append("path")
|
||||
.attr("fill", function(d, i) { return color(i); })
|
||||
.attr("class", function(d, i) { return getClass(i); })
|
||||
.attr("class", function(d, i) { return 'arc-' + i; })
|
||||
.attr("d", arc)
|
||||
.each(function(d) { this._current = d; }); // store the initial angles
|
||||
|
||||
|
@ -1217,9 +1205,7 @@ RepositoryUsageChart.prototype.drawInternal_ = function() {
|
|||
} else {
|
||||
pie.value(function(d, i) { return data[i]; }); // change the value function
|
||||
this.path_ = this.path_.data(pie); // compute the new angles
|
||||
|
||||
this.path_.transition().duration(duration).attrTween("d", arcTween); // redraw the arcs
|
||||
this.path_.attr("class", function(d, i) { return getClass(i); });
|
||||
|
||||
// Update the text.
|
||||
this.text_.text(this.count_ + ' / ' + this.total_);
|
||||
|
|
Reference in a new issue