From c3b10c12bbf9dfc22a05a2b7703b17a86ad88ae9 Mon Sep 17 00:00:00 2001
From: Joseph Schorr <jschorr@gmail.com>
Date: Thu, 31 Oct 2013 15:04:07 -0400
Subject: [PATCH] Add check for existing repo with the same name

---
 endpoints/api.py              |  5 +++++
 static/css/quay.css           | 10 +++++++++-
 static/js/controllers.js      | 11 ++++++++---
 static/partials/new-repo.html |  4 ++--
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/endpoints/api.py b/endpoints/api.py
index 853c7498f..af08c7b45 100644
--- a/endpoints/api.py
+++ b/endpoints/api.py
@@ -187,6 +187,11 @@ def create_repo_api():
 
   namespace_name = owner.username
   repository_name = request.get_json()['repository']
+
+  existing = model.get_repository(namespace_name, repository_name)
+  if existing:
+    return make_response('Repository already exists', 400)
+
   visibility = request.get_json()['visibility']
 
   repo = model.create_repository(namespace_name, repository_name, owner,
diff --git a/static/css/quay.css b/static/css/quay.css
index 9f5001fc4..63cbe4fbd 100644
--- a/static/css/quay.css
+++ b/static/css/quay.css
@@ -179,10 +179,14 @@
   color: #444 !important;
 }
 
-.new-repo .new-header {
+.new-repo .new-header span {
   font-size: 22px;
 }
 
+.new-repo .new-header .popover {
+  font-size: 14px;
+}
+
 .new-repo .new-header .repo-circle {
    margin-right: 14px;
 }
@@ -366,6 +370,10 @@
   padding: 20px;
 }
 
+.landing .popover {
+  font-size: 14px;
+}
+
 .landing {
   color: white;
 
diff --git a/static/js/controllers.js b/static/js/controllers.js
index 0b7a8c3f4..939890838 100644
--- a/static/js/controllers.js
+++ b/static/js/controllers.js
@@ -953,7 +953,7 @@ function V1Ctrl($scope, $location, UserService) {
   }, true);
 }
 
-function NewRepoCtrl($scope, $location, $http, UserService, Restangular, PlanService) {
+function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangular, PlanService) {
   $scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
     $scope.user = currentUser;
   }, true);
@@ -1069,6 +1069,8 @@ function NewRepoCtrl($scope, $location, $http, UserService, Restangular, PlanSer
   };
 
   $scope.createNewRepo = function() {
+    $('#repoName').popover('hide');
+
     var uploader = $('#file-drop')[0];
     if ($scope.repo.initialize && uploader.files.length < 1) {
       $('#missingfileModal').modal();
@@ -1096,9 +1098,12 @@ function NewRepoCtrl($scope, $location, $http, UserService, Restangular, PlanSer
 
       // Otherwise, redirect to the repo page.
       $location.path('/repository/' + created.namespace + '/' + created.name);
-    }, function() {
-      $('#cannotcreateModal').modal();
+    }, function(result) {
       $scope.creating = false;
+      $scope.createError = result.data;
+      $timeout(function() {
+        $('#repoName').popover('show');
+      });
     });
   };
 
diff --git a/static/partials/new-repo.html b/static/partials/new-repo.html
index 30cdd2316..02ad53331 100644
--- a/static/partials/new-repo.html
+++ b/static/partials/new-repo.html
@@ -20,7 +20,7 @@
 </div>
 
 <div class="container new-repo" ng-show="!user.anonymous && !creating && !uploading && !building">
-  <form method="post" name="newRepoForm" ng-submit="createNewRepo()">
+  <form method="post" name="newRepoForm" id="newRepoForm" ng-submit="createNewRepo()">
 
   <!-- Header -->
   <div class="row">
@@ -29,7 +29,7 @@
       <div class="section">
         <div class="new-header">
           <span class="repo-circle no-background" repo="repo"></span>
-          <span style="color: #444;"> {{user.username}}</span> <span style="color: #ccc">/</span> <span class="name-container"><input id="repoName" name="repoName" type="text" class="form-control" placeholder="Repository Name" ng-model="repo.name" required autofocus></span>
+          <span style="color: #444;"> {{user.username}}</span> <span style="color: #ccc">/</span> <span class="name-container"><input id="repoName" name="repoName" type="text" class="form-control" placeholder="Repository Name" ng-model="repo.name" required autofocus data-trigger="manual" data-content="{{ createError }}" data-placement="right"></span>
         </div>
       </div>