From 98d63e00ee2569c3cd0982e1f7220eb2ea250575 Mon Sep 17 00:00:00 2001
From: Joseph Schorr <joseph.schorr@coreos.com>
Date: Wed, 4 Feb 2015 11:48:25 -0500
Subject: [PATCH] Some small fixes and start on handling SSL better

---
 static/css/core-ui.css         |  5 ++++-
 static/js/app.js               |  5 +++--
 static/js/controllers/setup.js | 12 +++++++++---
 static/js/core-config-setup.js |  2 +-
 static/partials/setup.html     |  7 ++++++-
 5 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/static/css/core-ui.css b/static/css/core-ui.css
index 1a4e34816..ebe86d595 100644
--- a/static/css/core-ui.css
+++ b/static/css/core-ui.css
@@ -280,7 +280,6 @@
 
 .config-file-field-element input {
   display: inline-block;
-  width: 78px;
   margin-left: 10px;
 }
 
@@ -552,6 +551,10 @@
   min-height: 100px;
 }
 
+.co-dialog .modal-body h4 {
+  margin-bottom: 20px;
+}
+
 .co-dialog .modal-content {
   border-radius: 0px;
 }
diff --git a/static/js/app.js b/static/js/app.js
index 0e40fd3e0..58f225172 100644
--- a/static/js/app.js
+++ b/static/js/app.js
@@ -1290,7 +1290,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
           }, 2000);
         };
 
-        containerService.checkStatus = function(callback) {
+        containerService.checkStatus = function(callback, force_ssl) {
           var errorHandler = function(resp) {
             if (resp.status == 404 || resp.status == 502) {
               // Container has not yet come back up, so we schedule another check.
@@ -1301,7 +1301,8 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
             return ApiService.errorDisplay('Cannot load status. Please report this to support')(resp);
           };
 
-          ApiService.scRegistryStatus(null, null).then(callback, errorHandler, /* background */true);
+          ApiService.scRegistryStatus(null, null)
+                    .then(callback, errorHandler, /* background */true, /* force ssl*/force_ssl);
         };
 
         return containerService;
diff --git a/static/js/controllers/setup.js b/static/js/controllers/setup.js
index 1c814203a..d156d7d9c 100644
--- a/static/js/controllers/setup.js
+++ b/static/js/controllers/setup.js
@@ -68,6 +68,8 @@ function SetupCtrl($scope, $timeout, ApiService, Features, UserService, Containe
   $scope.currentStep = $scope.States.LOADING;
   $scope.errors = {};
   $scope.stepProgress = [];
+  $scope.hasSSL = false;
+  $scope.hostname = null;
 
   $scope.$watch('currentStep', function(currentStep) {
     $scope.stepProgress = $scope.getProgress(currentStep);
@@ -111,10 +113,14 @@ function SetupCtrl($scope, $timeout, ApiService, Features, UserService, Containe
 
   $scope.showSuperuserPanel = function() {
     $('#setupModal').modal('hide');
-    window.location = '/superuser';
+    var prefix = scope.hasSSL ? 'https' : 'http';
+    var hostname = $scope.hostname;
+    window.location = prefix + '://' + hostname + '/superuser';
   };
 
-  $scope.configurationSaved = function() {
+  $scope.configurationSaved = function(config) {
+    $scope.hasSSL = config['PREFERRED_URL_SCHEME'] == 'https';
+    $scope.hostname = config['SERVER_HOSTNAME'];
     $scope.currentStep = $scope.States.VALID_CONFIG;
   };
 
@@ -255,7 +261,7 @@ function SetupCtrl($scope, $timeout, ApiService, Features, UserService, Containe
   $scope.checkStatus = function() {
     ContainerService.checkStatus(function(resp) {
       $scope.currentStep = resp['status'];
-    });
+    }, $scope.hasSSL);
   };
 
   // Load the initial status.
diff --git a/static/js/core-config-setup.js b/static/js/core-config-setup.js
index 7e312da44..cd7d9b356 100644
--- a/static/js/core-config-setup.js
+++ b/static/js/core-config-setup.js
@@ -180,7 +180,7 @@ angular.module("core-config-setup", ['angularFileUpload'])
             $scope.savingConfiguration = false;
             $scope.mapped.$hasChanges = false;
             $('#validateAndSaveModal').modal('hide');
-            $scope.configurationSaved({});
+            $scope.configurationSaved({'config': $scope.config});
           }, ApiService.errorDisplay('Could not save configuration. Please report this error.'));
         };
 
diff --git a/static/partials/setup.html b/static/partials/setup.html
index ca31d18ab..d36b172cd 100644
--- a/static/partials/setup.html
+++ b/static/partials/setup.html
@@ -24,7 +24,7 @@
       </div>
 
       <div class="config-setup-tool" is-active="isStep(currentStep, States.CONFIG)"
-           configuration-saved="configurationSaved()"></div>
+           configuration-saved="configurationSaved(config)"></div>
     </div>
   </div>
 </div>
@@ -107,6 +107,11 @@
            <h4>Installation and setup of <span class="registry-name"></span> is complete</h4>
            You can now invite users to join, create organizations and start pushing and pulling
            repositories.
+
+           <strong ng-if="hasSSL" style="margin-top: 20px;">
+            Note: SSL is enabled. Please make sure to visit with
+            an <u>https</u> prefix
+           </strong>
       </div>
 
      <!-- Content: VALID_CONFIG -->