34
34
</v-card-subtitle >
35
35
<v-card-text class =" pb-0 ml-2" >
36
36
<v-text-field
37
+ v-model =" redisCommandText"
38
+ hide-details
37
39
label =" Redis command"
38
40
class =" monospace"
39
- v-model =" redisCommandText"
40
41
@keydown =" commandKeydown"
41
42
/>
42
- <span v-if =" redisResponse" class =" monospace" >
43
- Response: {{ redisResponse }}
44
- </span >
43
+ <v-checkbox
44
+ v-model =" prettyPrint"
45
+ label =" Pretty print"
46
+ density =" compact"
47
+ hide-details
48
+ class =" mb-2"
49
+ />
50
+ <template v-if =" redisResponse " >
51
+ <pre v-if =" prettyPrint" v-text =" formattedResponse" />
52
+ <span v-else class =" monospace" > Response: {{ redisResponse }} </span >
53
+ </template >
45
54
</v-card-text >
46
55
<v-card-actions class =" px-2" >
47
56
<v-btn
48
57
:disabled =" !redisCommandText.length"
49
- @click =" executeRaw"
50
58
color =" success"
51
59
variant =" text"
60
+ @click =" executeRaw"
52
61
>
53
62
Execute
54
63
</v-btn >
@@ -89,6 +98,7 @@ export default {
89
98
redisCommandText: ' ' ,
90
99
redisResponse: null ,
91
100
redisEndpoint: ' /openc3-api/redis/exec' ,
101
+ prettyPrint: false ,
92
102
headers: [
93
103
{ text: ' Redis' , value: ' redis' , width: 150 },
94
104
{ text: ' Command' , value: ' command' },
@@ -97,6 +107,33 @@ export default {
97
107
commands: [],
98
108
}
99
109
},
110
+ computed: {
111
+ formattedResponse : function () {
112
+ let result = this .redisResponse
113
+ if (this .redisResponse && this .prettyPrint ) {
114
+ if (typeof result === ' string' ) {
115
+ try {
116
+ result = JSON .parse (result)
117
+ } catch (e) {
118
+ // Oh 🐋
119
+ }
120
+ }
121
+ if (Array .isArray (result)) {
122
+ for (let i = 0 ; i < result .length ; i++ ) {
123
+ if (typeof result[i] === ' string' ) {
124
+ try {
125
+ result[i] = JSON .parse (result[i])
126
+ } catch (e) {
127
+ // Oh 🐋
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ result = JSON .stringify (result, null , 2 )
134
+ return ` Response: ${ result} `
135
+ },
136
+ },
100
137
methods: {
101
138
commandKeydown : function ($event ) {
102
139
$event .key === ' Enter' && this .executeRaw ()
@@ -129,6 +166,6 @@ export default {
129
166
<style scoped>
130
167
.monospace {
131
168
font-family : monospace ;
132
- font-size : 20 px ;
169
+ font-size : 14 px ;
133
170
}
134
171
</style >
0 commit comments