fix(templates): set var to default value if no value selected (#2323)

* fix(templates): set preset to true iff var type is preset

* 

* fix(templates): add env var value when changing type
pull/2472/head
Chaim Lev-Ari 2018-12-03 22:52:59 +02:00 committed by Anthony Lapenna
parent 5fa4403d20
commit acce5e0023
2 changed files with 15 additions and 13 deletions

View File

@ -41,6 +41,7 @@ angular.module('portainer.app').component('templateForm', {
};
this.addEnvVarValue = function(env) {
env.select = env.select || [];
env.select.push({ name: '', value: '' });
};
@ -49,11 +50,7 @@ angular.module('portainer.app').component('templateForm', {
};
this.changeEnvVarType = function(env) {
if (env.type === 1) {
env.preset = true;
} else if (env.type === 2) {
env.preset = false;
}
env.preset = env.type === 1;
};
},
bindings: {

View File

@ -125,13 +125,18 @@ function ($scope, $q, $state, $transition$, $anchorScroll, ContainerService, Ima
function createStackFromTemplate(template, userId, accessControlData) {
var stackName = $scope.formValues.name;
for (var i = 0; i < template.Env.length; i++) {
var envvar = template.Env[i];
if (envvar.preset) {
envvar.value = envvar.default;
}
}
var env =_.filter(
_.map(template.Env, function transformEnvVar(envvar) {
return {
name: envvar.name,
value:
envvar.preset || !envvar.value ? envvar.default : envvar.value
};
}),
function removeUndefinedVars(envvar) {
return envvar.value && envvar.name;
}
);
var repositoryOptions = {
RepositoryURL: template.Repository.url,
@ -139,7 +144,7 @@ function ($scope, $q, $state, $transition$, $anchorScroll, ContainerService, Ima
};
var endpointId = EndpointProvider.endpointID();
StackService.createSwarmStackFromGitRepository(stackName, repositoryOptions, template.Env, endpointId)
StackService.createSwarmStackFromGitRepository(stackName, repositoryOptions, env, endpointId)
.then(function success() {
return ResourceControlService.applyResourceControl('stack', stackName, userId, accessControlData, []);
})