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

Added setting to allow specification of new instance image

This commit is contained in:
Michael Irwin 2017-04-11 17:58:15 -04:00
parent 38c97cf100
commit 3b86c79c5b
No known key found for this signature in database
GPG Key ID: B9BD1E3E28BD2A14
2 changed files with 66 additions and 3 deletions

View File

@ -11,7 +11,7 @@
}, 500); }, 500);
}]); }]);
app.controller('PlayController', ['$scope', '$log', '$http', '$location', '$timeout', '$mdDialog', '$window', 'KeyboardShortcutService', function($scope, $log, $http, $location, $timeout, $mdDialog, $window, KeyboardShortcutService) { app.controller('PlayController', ['$scope', '$log', '$http', '$location', '$timeout', '$mdDialog', '$window', 'KeyboardShortcutService', 'InstanceService', function($scope, $log, $http, $location, $timeout, $mdDialog, $window, KeyboardShortcutService, InstanceService) {
$scope.sessionId = window.location.pathname.replace('/p/', ''); $scope.sessionId = window.location.pathname.replace('/p/', '');
$scope.instances = []; $scope.instances = [];
$scope.idx = {}; $scope.idx = {};
@ -75,6 +75,7 @@
$http({ $http({
method: 'POST', method: 'POST',
url: '/sessions/' + $scope.sessionId + '/instances', url: '/sessions/' + $scope.sessionId + '/instances',
data : { ImageName : InstanceService.getDesiredImage() }
}).then(function(response) { }).then(function(response) {
var i = $scope.upsertInstance(response.data); var i = $scope.upsertInstance(response.data);
$scope.showInstance(i); $scope.showInstance(i);
@ -325,12 +326,14 @@
}) })
.component("settingsDialog", { .component("settingsDialog", {
templateUrl : "settings-modal.html", templateUrl : "settings-modal.html",
controller : function($mdDialog, KeyboardShortcutService, $rootScope) { controller : function($mdDialog, KeyboardShortcutService, $rootScope, InstanceService) {
var $ctrl = this; var $ctrl = this;
$ctrl.$onInit = function() { $ctrl.$onInit = function() {
$ctrl.keyboardShortcutPresets = KeyboardShortcutService.getAvailablePresets(); $ctrl.keyboardShortcutPresets = KeyboardShortcutService.getAvailablePresets();
$ctrl.selectedShortcutPreset = KeyboardShortcutService.getCurrentShortcuts(); $ctrl.selectedShortcutPreset = KeyboardShortcutService.getCurrentShortcuts();
$ctrl.instanceImages = InstanceService.getAvailableImages();
$ctrl.selectedInstanceImage = InstanceService.getDesiredImage();
}; };
$ctrl.currentShortcutConfig = function(value) { $ctrl.currentShortcutConfig = function(value) {
@ -341,13 +344,58 @@
$rootScope.$broadcast('settings:shortcutsSelected', $ctrl.selectedShortcutPreset); $rootScope.$broadcast('settings:shortcutsSelected', $ctrl.selectedShortcutPreset);
} }
return JSON.stringify(KeyboardShortcutService.getCurrentShortcuts()); return JSON.stringify(KeyboardShortcutService.getCurrentShortcuts());
} };
$ctrl.currentDesiredInstanceImage = function(value) {
if (value !== undefined) {
InstanceService.setDesiredImage(value);
}
return InstanceService.getDesiredImage(value);
};
$ctrl.close = function() { $ctrl.close = function() {
$mdDialog.cancel(); $mdDialog.cancel();
} }
} }
}) })
.service("InstanceService", function($http) {
var instanceImages = [];
_prepopulateAvailableImages();
return {
getAvailableImages : getAvailableImages,
setDesiredImage : setDesiredImage,
getDesiredImage : getDesiredImage,
};
function getAvailableImages() {
return instanceImages;
}
function getDesiredImage() {
var image = localStorage.getItem("settings.desiredImage");
if (image == null)
return instanceImages[0];
return image;
}
function setDesiredImage(image) {
if (image === null)
localStorage.removeItem("settings.desiredImage");
else
localStorage.setItem("settings.desiredImage", image);
}
function _prepopulateAvailableImages() {
return $http
.get("/instances/images")
.then(function(response) {
instanceImages = response.data;
});
}
})
.run(function(InstanceService) { /* forcing pre-populating for now */ })
.service("KeyboardShortcutService", function() { .service("KeyboardShortcutService", function() {
return { return {
getAvailablePresets : getAvailablePresets, getAvailablePresets : getAvailablePresets,
@ -394,3 +442,5 @@
} }
}); });
})(); })();

View File

@ -149,6 +149,18 @@
</div> </div>
</div> </div>
</div> </div>
<div layout="row">
<div flex="50">
<md-input-container class="md-block" flex-gt-sm>
<label>Instance Image</label>
<md-select ng-model="$ctrl.currentDesiredInstanceImage" ng-model-options="{getterSetter: true}" placeholder="New Instance Image">
<md-option ng-repeat="image in $ctrl.instanceImages" value="{{image}}">
{{ image }}
</md-option>
</md-select>
</md-input-container>
</div>
</div>
</div> </div>
</md-dialog-content> </md-dialog-content>
@ -187,3 +199,4 @@
</script> </script>
</body> </body>
</html> </html>