1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 01:57:32 +08:00

Show alert if more than 5 instances are created

This commit is contained in:
Marcos Lilljedahl 2016-10-08 10:52:52 +02:00
parent 62936fcfc9
commit a0ffe28be9
3 changed files with 23 additions and 4 deletions

View File

@ -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)

View File

@ -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')
}
});
}

View File

@ -7,7 +7,7 @@
<link rel="stylesheet" href="/assets/style.css" />
</head>
<body>
<div layout="column" style="height:100%;" ng-cloak>
<div layout="column" style="height:100%;" ng-cloak>
<section layout="row" flex>
@ -44,7 +44,7 @@
<div flex></div>
</md-content>
<md-content flex layout-padding ng-repeat="instance in instances" ng-show="instance.name == selectedInstance.name">
<md-content id="popupContainer" flex layout-padding ng-repeat="instance in instances" ng-show="instance.name == selectedInstance.name">
<md-card md-theme="default" md-theme-watch>
<md-card-title>
<md-card-title-text>