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
|
@ -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));
|
||||
|
|
Reference in a new issue