diff --git a/handlers/new_instance.go b/handlers/new_instance.go index b25c728..5cfa7ee 100644 --- a/handlers/new_instance.go +++ b/handlers/new_instance.go @@ -13,6 +13,12 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) { sessionId := bone.GetValue(req, "sessionId") s := services.GetSession(sessionId) + + if len(s.Instances) >= 5 { + rw.WriteHeader(http.StatusConflict) + return + } + i, err := services.NewInstance(s) if err != nil { log.Println(err) diff --git a/www/assets/app.js b/www/assets/app.js index a82af41..7daf9c5 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -3,11 +3,22 @@ var app = angular.module('DockerPlay', ['ngMaterial']); - app.controller('PlayController', ['$scope', '$log', '$http', '$location', '$timeout', function($scope, $log, $http, $location, $timeout) { + app.controller('PlayController', ['$scope', '$log', '$http', '$location', '$timeout', '$mdDialog', function($scope, $log, $http, $location, $timeout, $mdDialog) { $scope.sessionId = window.location.pathname.replace('/p/', ''); $scope.instances = []; $scope.selectedInstance = null; + $scope.showAlert = function(title, content) { + $mdDialog.show( + $mdDialog.alert() + .parent(angular.element(document.querySelector('#popupContainer'))) + .clickOutsideToClose(true) + .title(title) + .textContent(content) + .ok('Got it!') + ); + } + $scope.newInstance = function() { $http({ method: 'POST', @@ -17,7 +28,9 @@ $scope.instances.push(i); $scope.showInstance(i); }, function(response) { - console.log('error', response); + if (response.status == 409) { + $scope.showAlert('Max instances reached', 'Maximum number of instances reached') + } }); } diff --git a/www/index.html b/www/index.html index 3b5d156..7bd6c30 100644 --- a/www/index.html +++ b/www/index.html @@ -7,7 +7,7 @@
-