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

View File

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