0
0
mirror of https://github.com/dobin/lxd-webgui synced 2025-10-05 23:52:43 +02:00

container create can now select multiple profiles

fixes #12
This commit is contained in:
Dobin Rutishauser
2016-08-31 17:01:49 +02:00
parent 7eb999c24b
commit dea2e92b11
3 changed files with 34 additions and 23 deletions

View File

@@ -249,7 +249,7 @@ angular.module('myApp.container', ['ngRoute'])
})
.controller('containerCreateCtrl', function ($scope, $routeParams, $filter, $location,
.controller('containerCreateCtrl', function ($scope, $routeParams, $filter, $location, $interval,
ContainerServices, ImageServices, profiles, images) {
$scope.containerName = "";
@@ -271,17 +271,36 @@ angular.module('myApp.container', ['ngRoute'])
$scope.isSubmitted = true;
if (isValid) {
// convert from selected profiles with full information
// to an array
var profiles = [];
for(var n=0; n<$scope.selected.profile.length; n++) {
profiles.push($scope.selected.profile[n].name);
}
ContainerServices.create(
$scope.containerName,
$scope.selected.image.fingerprint,
$scope.selected.profile.name,
profiles,
$scope.selected.ephemeral)
.then(function(data) {
window.location = "#/containers";
}, function(error) {
var errorMsg = error.error;
console.log("Error: " + errorMsg);
});
var operationUrl = data.data.operation;
var refreshInterval;
// Try until operation is finished
refreshInterval = $interval(
function() {
ContainerServices.isOperationFinished(operationUrl).then(function(data) {
// I dont really care if the operation is still runnging
}, function(error) {
// Operation returned 404, so its finished
$interval.cancel(refreshInterval);
// TODO: check if successful
window.location = "#/containers";
});
}, 500
);
});
}
}

View File

@@ -47,10 +47,10 @@ angular.module('myApp.container')
// Create container:
obj.create = function (containerName, imageFingerprint, profileName, ephemeralState) {
obj.create = function (containerName, imageFingerprint, profiles, ephemeralState) {
var containerData = {
name: containerName,
profiles: [ profileName ],
profiles: profiles,
ephemeral: ephemeralState,
source: {
type: "image",
@@ -58,15 +58,7 @@ angular.module('myApp.container')
}
};
// Async
return $http.post(SettingServices.getLxdApiUrl() + '/containers', containerData).then(function(data) {
data = data.data;
if (data.status != "Success") {
return($q.reject(data.metadata));
}
data = data.metadata;
});
return $http.post(SettingServices.getLxdApiUrl() + '/containers', containerData)
};

View File

@@ -62,17 +62,17 @@
<div class="form-group" ng-class="{ 'has-error' : userForm.name.$invalid && (!userForm.name.$pristine || isSubmitted )}">
<div class="col-md-2">
<label>Profile</label>
<label>Profile(s)</label>
</div>
<div class="col-md-4">
<ui-select ng-model="selected.profile" required>
<ui-select multiple sortable="true" ng-model="selected.profile" required class="form-control">
<ui-select-match>
<span ng-bind="$select.selected.name"></span>
{{$item.name}}
</ui-select-match>
<ui-select-choices repeat="profile in (profiles | filter: $select.search)">
<span ng-bind="profile.name"></span>
<ui-select-choices repeat="profile in profiles | filter: $select.search">
<span ng-bind-html="profile.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>