11<template >
22 <div >
33 <v-dialog
4- v-model =" envEditorDialog"
5- max-width = " 800 "
6- persistent
7- :transition =" false"
4+ v-model =" envEditorDialog"
5+ persistent
6+ :fullscreen = " true "
7+ :transition =" false"
88 >
9- <div style =" position : relative ;" >
9+ <div style =" position : relative ; height : 100 % ; " >
1010 <codemirror
11- v-if =" envEditorDialog"
12- class =" EnvironmentMaximizedEditor"
13- :style =" { border: '1px solid lightgray' }"
14- v-model =" text"
15- :options =" cmOptions"
16- :placeholder =" $t('enterExtraVariablesJson')"
11+ v-if =" envEditorDialog"
12+ class =" EnvironmentMaximizedEditor"
13+ :style =" { border: '1px solid lightgray' }"
14+ v-model =" text"
15+ :options =" cmOptions"
16+ :placeholder =" $t('enterExtraVariablesJson')"
1717 />
1818
1919 <v-btn
20- dark
21- fab
22- small
23- color =" success"
24- style ="
20+ v-if =" validatable"
21+ dark
22+ fab
23+ small
24+ color =" success"
25+ style ="
2526 position : absolute ;
26- right : 50 px ;
27+ right : 70 px ;
2728 top : 0 ;
2829 margin : 10px ;
2930 "
30- @click =" save ()"
31+ @click =" spellcheck ()"
3132 >
32- <v-icon >mdi-check </v-icon >
33+ <v-icon >mdi-spellcheck </v-icon >
3334 </v-btn >
3435
3536 <v-btn
36- dark
37- fab
38- small
39- color =" error "
40- style ="
37+ dark
38+ fab
39+ small
40+ color =" blue-grey "
41+ style ="
4142 position : absolute ;
42- right : 0 ;
43+ right : 20 px ;
4344 top : 0 ;
4445 margin : 10px ;
4546 "
46- @click =" cancel ()"
47+ @click =" save ()"
4748 >
48- <v-icon >mdi-close </v-icon >
49+ <v-icon >mdi-arrow-collapse </v-icon >
4950 </v-btn >
5051
5152 <v-alert
52- v-model =" hasError"
53- dismissible
54- style ="
53+ v-model =" showAlert"
54+ :color =" errorMessage ? 'error' : 'success'"
55+ dismissible
56+ style ="
5557 position : absolute ;
5658 bottom : 0 ;
5759 left : 50% ;
5860 transform : translateX (-50% );
5961 "
60- >{{ errorMessage }}</v-alert >
62+ >{{ errorMessage || validationSuccessMessage }}
63+ </v-alert >
6164 </div >
6265 </v-dialog >
6366
6467 <v-btn
65- dark
66- fab
67- small
68- color =" blue-grey"
69- @click =" envEditorDialog = true"
68+ dark
69+ fab
70+ small
71+ color =" blue-grey"
72+ @click =" envEditorDialog = true"
7073 >
7174 <v-icon >mdi-arrow-expand</v-icon >
7275 </v-btn >
@@ -80,7 +83,8 @@ import { codemirror } from 'vue-codemirror';
8083import ' codemirror/lib/codemirror.css' ;
8184import ' codemirror/mode/vue/vue.js' ;
8285import ' codemirror/addon/display/placeholder.js' ;
83- import { getErrorMessage } from ' @/lib/error' ;
86+ import { getErrorMessage } from ' ../lib/error' ;
87+ // import { getErrorMessage } from '@/lib/error';
8488
8589export default {
8690 props: {
@@ -113,20 +117,11 @@ export default {
113117 text: null ,
114118 envEditorDialog: false ,
115119 errorMessage: null ,
120+ showAlert: false ,
116121 };
117122 },
118123
119124 computed: {
120- hasError: {
121- get () {
122- return this .errorMessage != null ;
123- },
124- set (value ) {
125- if (! value) {
126- this .errorMessage = null ;
127- }
128- },
129- },
130125
131126 cmOptions () {
132127 return {
@@ -138,6 +133,21 @@ export default {
138133 indentWithTabs: false ,
139134 };
140135 },
136+
137+ validatable () {
138+ return [' json' , ' json_array' ].includes (this .type );
139+ },
140+
141+ validationSuccessMessage () {
142+ switch (this .type ) {
143+ case ' json' :
144+ return ' Valid JSON format.' ;
145+ case ' json_array' :
146+ return ' Valid JSON array format.' ;
147+ default :
148+ return ' Validation passed successfully.' ;
149+ }
150+ },
141151 },
142152
143153 methods: {
@@ -146,15 +156,14 @@ export default {
146156 this .text = this .value ;
147157 this .envEditorDialog = false ;
148158 },
149- save () {
159+ spellcheck () {
150160 this .errorMessage = null ;
151161 switch (this .type ) {
152162 case ' json' :
153163 try {
154164 JSON .parse (this .text );
155165 } catch (e) {
156166 this .errorMessage = getErrorMessage (e);
157- return ;
158167 }
159168 break ;
160169 case ' json_array' :
@@ -165,11 +174,36 @@ export default {
165174 }
166175 } catch (e) {
167176 this .errorMessage = getErrorMessage (e);
168- return ;
169177 }
170178 break ;
171179 default :
172180 }
181+ this .showAlert = true ;
182+ },
183+ save () {
184+ // this.errorMessage = null;
185+ // switch (this.type) {
186+ // case 'json':
187+ // try {
188+ // JSON.parse(this.text);
189+ // } catch (e) {
190+ // this.errorMessage = getErrorMessage(e);
191+ // return;
192+ // }
193+ // break;
194+ // case 'json_array':
195+ // try {
196+ // const res = JSON.parse(this.text);
197+ // if (!Array.isArray(res)) {
198+ // throw new Error('Must be JSON array');
199+ // }
200+ // } catch (e) {
201+ // this.errorMessage = getErrorMessage(e);
202+ // return;
203+ // }
204+ // break;
205+ // default:
206+ // }
173207 if (this .text !== this .value ) {
174208 this .$emit (' input' , this .text );
175209 }
@@ -179,10 +213,14 @@ export default {
179213};
180214 </script >
181215<style lang="scss">
182- .EnvironmentMaximizedEditor {
216+ .vue-codemirror.EnvironmentMaximizedEditor {
217+ height : 100% !important ;
218+ border-radius : 0 !important ;
219+
183220 .CodeMirror {
221+ height : 100% !important ;
184222 font-size : 14px ;
185- height : 600 px !important ;
223+ border-radius : 0 !important ;
186224 }
187225}
188226 </style >
0 commit comments