Remove some code duplication by moving the robot and team creation dialogs to the create service
This commit is contained in:
parent
4b64236d8e
commit
7bdd7c5f82
4 changed files with 48 additions and 62 deletions
|
@ -62,9 +62,9 @@
|
||||||
<i class="fa fa-hdd-o"></i> New Repository
|
<i class="fa fa-hdd-o"></i> New Repository
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation" class="divider" ng-if="getNamespace(currentPageContext)"></li>
|
<li role="presentation" class="divider" ng-if="getNamespace(currentPageContext) && canAdmin(getNamespace(currentPageContext))"></li>
|
||||||
<li role="presentation" class="dropdown-header"
|
<li role="presentation" class="dropdown-header"
|
||||||
ng-if="getNamespace(currentPageContext)">
|
ng-if="getNamespace(currentPageContext) && canAdmin(getNamespace(currentPageContext))">
|
||||||
Namespace {{ getNamespace(currentPageContext) }}
|
Namespace {{ getNamespace(currentPageContext) }}
|
||||||
</li>
|
</li>
|
||||||
<li ng-if="isOrganization(getNamespace(currentPageContext)) && canAdmin(getNamespace(currentPageContext))">
|
<li ng-if="isOrganization(getNamespace(currentPageContext)) && canAdmin(getNamespace(currentPageContext))">
|
||||||
|
|
|
@ -92,40 +92,16 @@ angular.module('quay').directive('entitySearch', function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.createTeam = function() {
|
$scope.createTeam = function() {
|
||||||
if (!$scope.isAdmin) { return; }
|
CreateService.askCreateTeam($scope.namespace, function(created) {
|
||||||
|
$scope.setEntity(created.name, 'team', false, created.avatar);
|
||||||
bootbox.prompt('Enter the name of the new team', function(teamname) {
|
$scope.teams[teamname] = created;
|
||||||
if (!teamname) { return; }
|
|
||||||
|
|
||||||
var regex = new RegExp(TEAM_PATTERN);
|
|
||||||
if (!regex.test(teamname)) {
|
|
||||||
bootbox.alert('Invalid team name');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateService.createOrganizationTeam(ApiService, $scope.namespace, teamname, function(created) {
|
|
||||||
$scope.setEntity(created.name, 'team', false, created.avatar);
|
|
||||||
$scope.teams[teamname] = created;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.createRobot = function() {
|
$scope.createRobot = function() {
|
||||||
if (!$scope.isAdmin) { return; }
|
CreateService.askCreateRobot($scope.namespace, function(created) {
|
||||||
|
$scope.setEntity(created.name, 'user', true, created.avatar);
|
||||||
bootbox.prompt('Enter the name of the new robot account', function(robotname) {
|
$scope.robots.push(created);
|
||||||
if (!robotname) { return; }
|
|
||||||
|
|
||||||
var regex = new RegExp(ROBOT_PATTERN);
|
|
||||||
if (!regex.test(robotname)) {
|
|
||||||
bootbox.alert('Invalid robot account name');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateService.createRobotAccount(ApiService, $scope.isOrganization, $scope.namespace, robotname, function(created) {
|
|
||||||
$scope.setEntity(created.name, 'user', true, created.avatar);
|
|
||||||
$scope.robots.push(created);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -188,25 +188,12 @@ angular.module('quay').directive('headerBar', function () {
|
||||||
|
|
||||||
$scope.createRobot = function(context) {
|
$scope.createRobot = function(context) {
|
||||||
var namespace = $scope.getNamespace(context);
|
var namespace = $scope.getNamespace(context);
|
||||||
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
CreateService.askCreateRobot(function(created) {
|
||||||
|
if (isorg) {
|
||||||
var isorg = UserService.isOrganization(namespace);
|
$location.url('/organization/' + namespace + '?tab=robots');
|
||||||
bootbox.prompt('Enter the name of the new robot account', function(robotname) {
|
} else {
|
||||||
if (!robotname) { return; }
|
$location.url('/user/' + namespace + '?tab=robots');
|
||||||
|
|
||||||
var regex = new RegExp(ROBOT_PATTERN);
|
|
||||||
if (!regex.test(robotname)) {
|
|
||||||
bootbox.alert('Invalid robot account name');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateService.createRobotAccount(ApiService, isorg, namespace, robotname, function(created) {
|
|
||||||
if (isorg) {
|
|
||||||
$location.url('/organization/' + namespace + '?tab=robots');
|
|
||||||
} else {
|
|
||||||
$location.url('/user/' + namespace + '?tab=robots');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -214,18 +201,8 @@ angular.module('quay').directive('headerBar', function () {
|
||||||
var namespace = $scope.getNamespace(context);
|
var namespace = $scope.getNamespace(context);
|
||||||
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
||||||
|
|
||||||
bootbox.prompt('Enter the name of the new team', function(teamname) {
|
CreateService.askCreateTeam(function(created) {
|
||||||
if (!teamname) { return; }
|
|
||||||
|
|
||||||
var regex = new RegExp(TEAM_PATTERN);
|
|
||||||
if (!regex.test(teamname)) {
|
|
||||||
bootbox.alert('Invalid team name');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateService.createOrganizationTeam(ApiService, namespace, teamname, function(created) {
|
|
||||||
$location.url('/organization/' + namespace + '/teams/' + teamname);
|
$location.url('/organization/' + namespace + '/teams/' + teamname);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Service which exposes various methods for creating entities on the backend.
|
* Service which exposes various methods for creating entities on the backend.
|
||||||
*/
|
*/
|
||||||
angular.module('quay').factory('CreateService', ['ApiService', function(ApiService) {
|
angular.module('quay').factory('CreateService', ['ApiService', 'UserService', function(ApiService, UserService) {
|
||||||
var createService = {};
|
var createService = {};
|
||||||
|
|
||||||
createService.createRobotAccount = function(ApiService, is_org, orgname, name, callback) {
|
createService.createRobotAccount = function(ApiService, is_org, orgname, name, callback) {
|
||||||
|
@ -24,5 +24,38 @@ angular.module('quay').factory('CreateService', ['ApiService', function(ApiServi
|
||||||
.then(callback, ApiService.errorDisplay('Cannot create team'));
|
.then(callback, ApiService.errorDisplay('Cannot create team'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
createService.askCreateRobot = function(namespace, callback) {
|
||||||
|
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
||||||
|
|
||||||
|
var isorg = UserService.isOrganization(namespace);
|
||||||
|
bootbox.prompt('Enter the name of the new robot account', function(robotname) {
|
||||||
|
if (!robotname) { return; }
|
||||||
|
|
||||||
|
var regex = new RegExp(ROBOT_PATTERN);
|
||||||
|
if (!regex.test(robotname)) {
|
||||||
|
bootbox.alert('Invalid robot account name');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
createService.createRobotAccount(ApiService, isorg, namespace, robotname, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
createService.askCreateTeam = function(namespace, callback) {
|
||||||
|
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
||||||
|
|
||||||
|
bootbox.prompt('Enter the name of the new team', function(teamname) {
|
||||||
|
if (!teamname) { return; }
|
||||||
|
|
||||||
|
var regex = new RegExp(TEAM_PATTERN);
|
||||||
|
if (!regex.test(teamname)) {
|
||||||
|
bootbox.alert('Invalid team name');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateService.createOrganizationTeam(ApiService, namespace, teamname, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return createService;
|
return createService;
|
||||||
}]);
|
}]);
|
||||||
|
|
Reference in a new issue