1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 13:59:40 +02:00

feat(network-creation): add labels on network create (#408)

This commit is contained in:
Glowbal 2016-12-25 21:32:17 +01:00 committed by Anthony Lapenna
parent 986171ecfe
commit c9ba16ef10
2 changed files with 52 additions and 2 deletions

View file

@ -4,7 +4,8 @@ function ($scope, $state, Messages, Network) {
$scope.formValues = {
DriverOptions: [],
Subnet: '',
Gateway: ''
Gateway: '',
Labels: []
};
$scope.config = {
@ -16,7 +17,8 @@ function ($scope, $state, Messages, Network) {
IPAM: {
Driver: 'default',
Config: []
}
},
Labels: {}
};
$scope.addDriverOption = function() {
@ -27,6 +29,14 @@ function ($scope, $state, Messages, Network) {
$scope.formValues.DriverOptions.splice(index, 1);
};
$scope.addLabel = function() {
$scope.formValues.Labels.push({ name: '', value: ''});
};
$scope.removeLabel = function(index) {
$scope.formValues.Labels.splice(index, 1);
};
function createNetwork(config) {
$('#createNetworkSpinner').show();
Network.create(config, function (d) {
@ -63,10 +73,21 @@ function ($scope, $state, Messages, Network) {
config.Options = options;
}
function prepareLabelsConfig(config) {
var labels = {};
$scope.formValues.Labels.forEach(function (label) {
if (label.name && label.value) {
labels[label.name] = label.value;
}
});
config.Labels = labels;
}
function prepareConfiguration() {
var config = angular.copy($scope.config);
prepareIPAMConfiguration(config);
prepareDriverOptions(config);
prepareLabelsConfig(config);
return config;
}