From 328aacbc601718158f101a4a9038678126a69275 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 16 Oct 2015 13:34:10 -0400 Subject: [PATCH] Fix small UI bugs around uploading dockerfiles Fixes #606 - Raises an error when a non-200 code is returned - Resets the dialog when reopened - Has a nicer error message for 413 errors --- .../directives/ui/dockerfile-build-dialog.js | 1 + .../js/directives/ui/dockerfile-build-form.js | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/static/js/directives/ui/dockerfile-build-dialog.js b/static/js/directives/ui/dockerfile-build-dialog.js index 524f0bacd..fb6408914 100644 --- a/static/js/directives/ui/dockerfile-build-dialog.js +++ b/static/js/directives/ui/dockerfile-build-dialog.js @@ -52,6 +52,7 @@ angular.module('quay').directive('dockerfileBuildDialog', function () { if (sn && $scope.repository) { $scope.viewTriggers = false; $scope.startTrigger = null; + $scope.errorMessage = null; $element.find('.dockerfilebuildModal').modal({}); diff --git a/static/js/directives/ui/dockerfile-build-form.js b/static/js/directives/ui/dockerfile-build-form.js index 6d35474a9..28d1a26ed 100644 --- a/static/js/directives/ui/dockerfile-build-form.js +++ b/static/js/directives/ui/dockerfile-build-form.js @@ -196,21 +196,36 @@ angular.module('quay').directive('dockerfileBuildForm', function () { } }); }; + request.onerror = function() { $scope.$apply(function() { handleUploadFailed(); }); }; + request.onreadystatechange = function() { var state = request.readyState; + var status = request.status; + if (state == 4) { - $scope.$apply(function() { - startBuild(fileId); - $scope.uploading = false; - }); - return; + if (Math.floor(status / 100) == 2) { + $scope.$apply(function() { + startBuild(fileId); + $scope.uploading = false; + }); + } else { + var message = request.statusText; + if (status == 413) { + message = 'Selected file too large to upload'; + } + + $scope.$apply(function() { + handleUploadFailed(message); + }); + } } }; + request.send(file); };