20
20
class =" mb-4"
21
21
></v-text-field >
22
22
23
- <v-subheader class =" pl -0" >
23
+ <v-subheader class =" px -0" >
24
24
{{ $t('extraVariables') }}
25
+
26
+ <v-tooltip bottom color =" black" open-delay =" 300" >
27
+ <template v-slot :activator =" { on , attrs } " >
28
+ <v-icon
29
+ class =" ml-1"
30
+ v-bind =" attrs"
31
+ v-on =" on"
32
+ >mdi-help-circle</v-icon >
33
+ </template >
34
+ <span >Variables passed via <code >--extra-vars</code >.</span >
35
+ </v-tooltip >
36
+
37
+ <v-spacer />
38
+
39
+ <v-btn-toggle
40
+ v-model =" extraVarsEditMode"
41
+ tile
42
+ group
43
+ >
44
+ <v-btn value =" json" small class =" mr-0" style =" border-radius : 4px ;" disabled >
45
+ JSON
46
+ </v-btn >
47
+ </v-btn-toggle >
25
48
</v-subheader >
26
49
27
50
<codemirror
31
54
:placeholder =" $t('enterExtraVariablesJson')"
32
55
/>
33
56
34
- <div class =" mt-4" >
35
- <div class =" d-flex flex-row justify-space-between" >
36
- <div >
37
- <div style =" line-height : 1.1 ;" class =" pl-1" >
38
- Avoid host key checking by the tools Ansible uses to connect to the host.
39
- </div >
40
- <code >"ANSIBLE_HOST_KEY_CHECKING": false</code >
41
- </div >
42
- <v-btn
43
- color =" primary"
44
- @click =" setExtraVar('ANSIBLE_HOST_KEY_CHECKING', false)"
45
- >Set variable</v-btn >
46
- </div >
47
- </div >
57
+ <div >
48
58
49
- <v-alert
50
- dense
51
- text
52
- type =" info"
53
- class =" mt-4"
54
- >
55
- {{ $t('environmentAndExtraVariablesMustBeValidJsonExample') }}
56
- <pre style =" font-size : 14px ;" >{
57
- "var_available_in_playbook_1": 1245,
58
- "var_available_in_playbook_2": "test"
59
- }</pre >
60
- </v-alert >
61
-
62
- <div class =" mt-4" v-if =" !advancedOptions" >
63
- <a @click =" advancedOptions = true" >
64
- {{ $t('advanced') }}
65
- <v-icon style =" transform : translateY (-1px )" >mdi-chevron-right</v-icon >
66
- </a >
67
- </div >
68
-
69
- <div class =" mt-4" v-else >
70
- <a @click =" advancedOptions = false" >
71
- {{ $t('hide') }}
72
- <v-icon style =" transform : translateY (-1px )" >mdi-chevron-up</v-icon >
73
- </a >
74
- </div >
75
-
76
- <div v-if =" advancedOptions" >
77
-
78
- <v-subheader class =" pl-0" >
59
+ <v-subheader class =" px-0 mt-4" >
79
60
{{ $t('environmentVariables') }}
61
+
62
+ <v-tooltip bottom color =" black" open-delay =" 300" >
63
+ <template v-slot :activator =" { on , attrs } " >
64
+ <v-icon
65
+ class =" ml-1"
66
+ v-bind =" attrs"
67
+ v-on =" on"
68
+ color =" lightgray"
69
+ >mdi-help-circle</v-icon >
70
+ </template >
71
+ <span >Variables passed as process environment variables.</span >
72
+ </v-tooltip >
80
73
</v-subheader >
81
74
82
- <codemirror
83
- :style =" { border: '1px solid lightgray' }"
84
- v-model =" env"
85
- :options =" cmOptions"
86
- :placeholder =" $t('enterEnvJson')"
87
- />
75
+ <v-chip-group
76
+ v-model =" predefinedEnvVars"
77
+ column
78
+ multiple
79
+ class =" EnvironmentForm__predefinedEnvVars"
80
+ >
81
+ <v-chip
82
+ filter
83
+ outlined
84
+ v-for =" item in PREDEFINED_ENV_VARS"
85
+ :key =" item.name"
86
+ >
87
+ <span class =" EnvironmentForm__predefinedEnvVarsValue" >
88
+ {{ item.name }}={{ item.value }}
89
+ </span >
90
+ <v-tooltip
91
+ bottom
92
+ color =" black"
93
+ :max-width =" 400"
94
+ open-delay =" 300"
95
+ >
96
+ <template v-slot :activator =" { on , attrs } " >
97
+ <v-icon
98
+ class =" ml-2"
99
+ v-bind =" attrs"
100
+ v-on =" on"
101
+ style =" margin-right : -6px ;"
102
+ >mdi-help-circle</v-icon >
103
+ </template >
104
+ <span >{{ item.description }}</span >
105
+ </v-tooltip >
106
+ </v-chip >
107
+ </v-chip-group >
108
+
109
+ <v-data-table
110
+ :items =" env"
111
+ :items-per-page =" -1"
112
+ class =" elevation-1"
113
+ hide-default-footer
114
+ no-data-text =" No values"
115
+ >
116
+ <template v-slot :item =" props " >
117
+ <tr >
118
+ <td class =" pa-1" >
119
+ <v-text-field
120
+ solo-inverted
121
+ flat
122
+ hide-details
123
+ v-model =" props.item.name"
124
+ class =" v-text-field--solo--no-min-height"
125
+ ></v-text-field >
126
+ </td >
127
+ <td class =" pa-1" >
128
+ <v-text-field
129
+ solo-inverted
130
+ flat
131
+ hide-details
132
+ v-model =" props.item.value"
133
+ class =" v-text-field--solo--no-min-height"
134
+ ></v-text-field >
135
+ </td >
136
+ <td style =" width : 38px ;" >
137
+ <v-icon
138
+ small
139
+ class =" pa-1"
140
+ @click =" removeEnvVar(props.item)"
141
+ >
142
+ mdi-delete
143
+ </v-icon >
144
+ </td >
145
+ </tr >
146
+ </template >
147
+ </v-data-table >
88
148
149
+ <div class =" text-right mt-2 mb-4" >
150
+ <v-btn
151
+ color =" primary"
152
+ @click =" addEnvVar()"
153
+ >New Variable</v-btn >
154
+ </div >
89
155
</div >
90
156
91
157
</v-form >
92
158
</template >
159
+
160
+ <style lang="scss">
161
+ .EnvironmentForm__predefinedEnvVars {
162
+ .EnvironmentForm__predefinedEnvVarsValue {
163
+ text-decoration : line-through ;
164
+ font-family : monospace ;
165
+ }
166
+ .v-chip--active {
167
+ .EnvironmentForm__predefinedEnvVarsValue {
168
+ text-decoration : none ;
169
+ }
170
+ }
171
+ }
172
+ </style >
173
+
93
174
<script >
94
175
/* eslint-disable import/no-extraneous-dependencies,import/extensions */
95
176
@@ -102,6 +183,12 @@ import 'codemirror/addon/display/placeholder.js';
102
183
import EventBus from ' @/event-bus' ;
103
184
import { getErrorMessage } from ' @/lib/error' ;
104
185
186
+ const PREDEFINED_ENV_VARS = [{
187
+ name: ' ANSIBLE_HOST_KEY_CHECKING' ,
188
+ value: ' False' ,
189
+ description: ' Avoid host key checking by the tools Ansible uses to connect to the host.' ,
190
+ }];
191
+
105
192
export default {
106
193
mixins: [ItemFormBase],
107
194
components: {
@@ -113,12 +200,13 @@ export default {
113
200
114
201
data () {
115
202
return {
203
+ PREDEFINED_ENV_VARS ,
116
204
images: [
117
205
' dind-runner:latest' ,
118
206
],
119
207
advancedOptions: false ,
120
208
json: ' {}' ,
121
- env: ' {} ' ,
209
+ env: [] ,
122
210
123
211
cmOptions: {
124
212
tabSize: 2 ,
@@ -128,10 +216,24 @@ export default {
128
216
lint: true ,
129
217
indentWithTabs: false ,
130
218
},
219
+
220
+ extraVarsEditMode: ' json' ,
221
+ predefinedEnvVars: [],
131
222
};
132
223
},
133
224
134
225
methods: {
226
+ addEnvVar (name = ' ' , value = ' ' ) {
227
+ this .env .push ({ name, value });
228
+ },
229
+
230
+ removeEnvVar (val ) {
231
+ const i = this .env .findIndex ((v ) => v .name === val .name );
232
+ if (i > - 1 ) {
233
+ this .env .splice (i, 1 );
234
+ }
235
+ },
236
+
135
237
setExtraVar (name , value ) {
136
238
try {
137
239
const obj = JSON .parse (this .json || ' {}' );
@@ -147,12 +249,41 @@ export default {
147
249
148
250
beforeSave () {
149
251
this .item .json = this .json ;
150
- this .item .env = this .env ;
252
+
253
+ const env = (this .env || []).reduce ((prev , curr ) => ({
254
+ ... prev,
255
+ [curr .name ]: curr .value ,
256
+ }), {});
257
+
258
+ this .predefinedEnvVars .forEach ((index ) => {
259
+ const predefinedVar = PREDEFINED_ENV_VARS [index];
260
+ env[predefinedVar .name ] = predefinedVar .value ;
261
+ });
262
+
263
+ this .item .env = JSON .stringify (env);
151
264
},
152
265
153
266
afterLoadData () {
154
267
this .json = this .item ? .json || ' {}' ;
155
- this .env = this .item ? .env || ' {}' ;
268
+
269
+ const env = JSON .parse (this .item ? .env || ' {}' );
270
+
271
+ this .env = Object .keys (env)
272
+ .filter ((x ) => {
273
+ const index = PREDEFINED_ENV_VARS .findIndex ((v ) => v .name === x);
274
+ return index === - 1 || PREDEFINED_ENV_VARS [index].value !== env[x];
275
+ })
276
+ .map ((x ) => ({
277
+ name: x,
278
+ value: env[x],
279
+ }));
280
+
281
+ Object .keys (env).forEach ((x ) => {
282
+ const index = PREDEFINED_ENV_VARS .findIndex ((v ) => v .name === x);
283
+ if (index !== - 1 && PREDEFINED_ENV_VARS [index].value === env[x]) {
284
+ this .predefinedEnvVars .push (index);
285
+ }
286
+ });
156
287
},
157
288
158
289
getItemsUrl () {
0 commit comments