Skip to content

Commit

Permalink
fix(ui): editing env
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed May 26, 2024
1 parent 2a45d1c commit e32ce6b
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions web/src/components/EnvironmentForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
</v-subheader>

<codemirror
:style="{ border: '1px solid lightgray' }"
v-model="item.json"
:options="cmOptions"
:placeholder="$t('enterExtraVariablesJson')"
:style="{ border: '1px solid lightgray' }"
v-model="json"
:options="cmOptions"
:placeholder="$t('enterExtraVariablesJson')"
/>

<div class="mt-4">
Expand All @@ -47,10 +47,10 @@
</div>

<v-alert
dense
text
type="info"
class="mt-4"
dense
text
type="info"
class="mt-4"
>
{{ $t('environmentAndExtraVariablesMustBeValidJsonExample') }}
<pre style="font-size: 14px;">{
Expand Down Expand Up @@ -81,7 +81,7 @@

<codemirror
:style="{ border: '1px solid lightgray' }"
v-model="item.env"
v-model="env"
:options="cmOptions"
:placeholder="$t('enterEnvJson')"
/>
Expand Down Expand Up @@ -109,17 +109,17 @@ export default {
},
created() {
if (!this.item.env) {
this.item.env = '{}';
}
if (!this.item.json) {
this.item.json = '{}';
}
},
data() {
return {
images: [
'dind-runner:latest',
],
advancedOptions: false,
json: '{}',
env: '{}',
cmOptions: {
tabSize: 2,
mode: 'application/json',
Expand All @@ -134,12 +134,9 @@ export default {
methods: {
setExtraVar(name, value) {
try {
const obj = JSON.parse(this.item.json);
const obj = JSON.parse(this.json || '{}');
obj[name] = value;
this.item = {
...this.item,
json: JSON.stringify(obj, null, 2),
};
this.json = JSON.stringify(obj, null, 2);
} catch (err) {
EventBus.$emit('i-snackbar', {
color: 'error',
Expand All @@ -148,6 +145,16 @@ export default {
}
},
beforeSave() {
this.item.json = this.json;
this.item.env = this.env;
},
afterLoadData() {
this.json = this.item?.json || '{}';
this.env = this.item?.env || '{}';
},
getItemsUrl() {
return `/api/project/${this.projectId}/environment`;
},
Expand Down

0 comments on commit e32ce6b

Please sign in to comment.