Skip to content

Commit 90017e0

Browse files
authored
Merge pull request #2283 from OpenC3/feat/redis-pretty-print
Add pretty-print feature to redis tab
2 parents 11de389 + 1aefb03 commit 90017e0

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/RedisTab.vue

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,30 @@
3434
</v-card-subtitle>
3535
<v-card-text class="pb-0 ml-2">
3636
<v-text-field
37+
v-model="redisCommandText"
38+
hide-details
3739
label="Redis command"
3840
class="monospace"
39-
v-model="redisCommandText"
4041
@keydown="commandKeydown"
4142
/>
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>
4554
</v-card-text>
4655
<v-card-actions class="px-2">
4756
<v-btn
4857
:disabled="!redisCommandText.length"
49-
@click="executeRaw"
5058
color="success"
5159
variant="text"
60+
@click="executeRaw"
5261
>
5362
Execute
5463
</v-btn>
@@ -89,6 +98,7 @@ export default {
8998
redisCommandText: '',
9099
redisResponse: null,
91100
redisEndpoint: '/openc3-api/redis/exec',
101+
prettyPrint: false,
92102
headers: [
93103
{ text: 'Redis', value: 'redis', width: 150 },
94104
{ text: 'Command', value: 'command' },
@@ -97,6 +107,33 @@ export default {
97107
commands: [],
98108
}
99109
},
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+
},
100137
methods: {
101138
commandKeydown: function ($event) {
102139
$event.key === 'Enter' && this.executeRaw()
@@ -129,6 +166,6 @@ export default {
129166
<style scoped>
130167
.monospace {
131168
font-family: monospace;
132-
font-size: 20px;
169+
font-size: 14px;
133170
}
134171
</style>

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/scriptrunner/Dialogs/InformationDialog.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
<v-card>
2727
<v-toolbar height="24">
2828
<v-spacer />
29-
<span style="white-space: pre-line" v-text="title" />
29+
<span style="white-space: pre" v-text="title" />
3030
<v-spacer />
3131
</v-toolbar>
3232
<div class="pa-2">
3333
<v-card-text>
3434
<v-row no-gutters v-for="(line, index) in text" :key="index">
35-
<span style="white-space: pre-line" v-text="line" />
35+
<span style="white-space: pre" v-text="line" />
3636
</v-row>
3737
</v-card-text>
3838
</div>

0 commit comments

Comments
 (0)