1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00

#115 add messages

This commit is contained in:
lana-k
2023-12-27 23:00:05 +01:00
parent b17040d3ef
commit f58b62eb0c
2 changed files with 26 additions and 4 deletions

View File

@@ -20,13 +20,18 @@
</div> </div>
<div class="value-body"> <div class="value-body">
<codemirror <codemirror
v-if="currentFormat === 'json'" v-if="currentFormat === 'json' && formattedJson"
:value="formattedJson" :value="formattedJson"
:options="cmOptions" :options="cmOptions"
/> />
<div v-else class="text-value"> <div v-if="currentFormat === 'text'" class="text-value">
{{ cellValue }} {{ cellValue }}
</div> </div>
<logs
v-if="messages && messages.length > 0"
:messages="messages"
class="messages"
/>
</div> </div>
</div> </div>
</template> </template>
@@ -41,10 +46,12 @@ import 'codemirror/addon/fold/foldgutter.css'
import 'codemirror/addon/fold/brace-fold.js' import 'codemirror/addon/fold/brace-fold.js'
import 'codemirror/theme/neo.css' import 'codemirror/theme/neo.css'
import cIo from '@/lib/utils/clipboardIo' import cIo from '@/lib/utils/clipboardIo'
import Logs from '@/components/Logs'
export default { export default {
components: { components: {
codemirror codemirror,
Logs
}, },
props: { props: {
cellValue: [String, Number] cellValue: [String, Number]
@@ -66,7 +73,8 @@ export default {
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
readOnly: true readOnly: true
}, },
formattedJson: '' formattedJson: '',
messages: []
} }
}, },
watch: { watch: {
@@ -84,12 +92,17 @@ export default {
}, },
methods: { methods: {
formatJson (jsonStr) { formatJson (jsonStr) {
this.messages = []
try { try {
this.formattedJson = JSON.stringify( this.formattedJson = JSON.stringify(
JSON.parse(jsonStr), null, 4 JSON.parse(jsonStr), null, 4
) )
} catch { } catch {
this.formattedJson = '' this.formattedJson = ''
this.messages = [{
type: 'error',
message: 'Can\'t parse JSON.'
}]
} }
}, },
copyToClipboard () { copyToClipboard () {
@@ -123,6 +136,10 @@ export default {
color: var(--color-text-base); color: var(--color-text-base);
} }
.messages {
margin: 8px;
}
.value-viewer-toolbar button { .value-viewer-toolbar button {
font-size: 10px; font-size: 10px;
height: 20px; height: 20px;

View File

@@ -17,6 +17,9 @@
v-show="selectedCell" v-show="selectedCell"
:cellValue="selectedCell ? selectedCell.innerText : ''" :cellValue="selectedCell ? selectedCell.innerText : ''"
/> />
<div v-show="!selectedCell" class="table-preview">
No cell selected to view
</div>
</div> </div>
</template> </template>
</component> </component>
@@ -314,6 +317,7 @@ export default {
height: 100%; height: 100%;
width: 100%; width: 100%;
background-color: var(--color-white); background-color: var(--color-white);
position: relative;
} }
.table-preview { .table-preview {
@@ -323,6 +327,7 @@ export default {
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
color: var(--color-text-base); color: var(--color-text-base);
font-size: 13px; font-size: 13px;
text-align: center;
} }
.result-in-progress { .result-in-progress {