Skip to content

Commit

Permalink
✨ : editable variables
Browse files Browse the repository at this point in the history
Some variables could be made "unmodifiable" by module users.
To do so, add a switch or a checkbox in the module definition, next to each variables in the module edit view.
Then in the stack view, the variable MUST not be visible or editable by users.

resolves #5
  • Loading branch information
juwit committed Jun 10, 2019
1 parent 11b6dc6 commit 07a938d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/codeka/gaia/bo/TerraformVariable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.codeka.gaia.bo;

/**
* Represents a module variable
*/
public class TerraformVariable {

private String name;
Expand All @@ -8,6 +11,8 @@ public class TerraformVariable {

private String defaultValue;

private boolean editable;

public String getName() {
return name;
}
Expand All @@ -31,4 +36,12 @@ public String getDefaultValue() {
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

public boolean isEditable() {
return editable;
}

public void setEditable(boolean editable) {
this.editable = editable;
}
}
10 changes: 9 additions & 1 deletion src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3416,4 +3416,12 @@ pre[class*="language-"] {

code[class*="language-"] b {
font-weight: bold;
}
}

.form-check{
margin-bottom: 0.5rem;
}
.form-check-input{
margin-top: 0;
margin-left: -1.5rem;
}
18 changes: 13 additions & 5 deletions src/main/resources/templates/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,26 @@ <h2>Module {{name}}</h2>
<h2>Variables <button type="button" class="btn btn-success" @click="addVar()">+</button></h2>

<div class="form-row align-items-end" v-for="(modVar,modVarIdx) in variables">
<div class="form-group col-md-4" >
<div class="form-group col-md-3" >
<label for="var-name">Name: </label>
<input type="text" class="form-control" id="var-name" v-model="modVar.name">
</div>
<div class="form-group col-md-4" >
<div class="form-group col-md-3" >
<label for="var-description">Description: </label>
<input type="text" class="form-control" id="var-description" v-model="modVar.description">
</div>
<div class="form-group col-md-3" >
<div class="form-group col-md-2" >
<label for="var-defaultValue">Default value: </label>
<input type="text" class="form-control" id="var-defaultValue" v-model="modVar.defaultValue">
</div>
<div class="form-group col-md-1" >
<div class="form-group col-md-1">
<div class="form-check">
<input class="form-check-input" type="checkbox" :id="'check-' + modVarIdx" v-model="modVar.editable">
<label class="form-check-label" :for="'check-' + modVarIdx"
data-toggle="tooltip" data-placement="top" title="Set this variable as editable for module users">Editable</label>
</div>
</div>
<div class="form-group" >
<button type="button" class="form-control btn btn-danger" @click="removeVar(modVarIdx)">-</button>
</div>
</div>
Expand Down Expand Up @@ -132,7 +139,8 @@ <h2>Variables <button type="button" class="btn btn-success" @click="addVar()">+<
data.variables.push({});
}
}
})
});
$('[data-toggle="tooltip"]').tooltip();
});
</script>

Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/templates/stack.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,16 @@ <h2>Module variables values</h2>
<small>This is the configuration of your module's variables !</small>
</div>
<div class="block_content">
<div class="form-row align-items-end" v-for="(modVar,modVarIdx) in stack.module.variables">
<div class="form-group col-md-4" >
<div class="form-row align-items-end" v-for="(modVar,modVarIdx) in editableVars" v-if="editableVars.length > 0">
<div class="form-group col">
<label for="var-name">{{modVar.name}}: </label>
<input type="text" class="form-control" id="var-name" v-model="stack.variableValues[modVar.name]" @change="recomputeState">
<small id="emailHelp" class="form-text text-muted">{{modVar.description}}</small>
</div>
</div>
<div v-if="editableVars.length === 0">
<p>No editable variable defined for this module.</p>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -271,6 +274,11 @@ <h2><span><i class="fas fa-history"></i> Job history</span></h2>
stack.state = "TO_UPDATE";
}
}
},
computed: {
editableVars: function() {
return this.stack.module.variables.filter(variable => variable.editable);
}
}
});

Expand Down

0 comments on commit 07a938d

Please sign in to comment.