mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 19:36:00 +00:00
json view
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import _ from 'lodash';
|
||||||
import JSONTree from 'svelte-json-tree';
|
import JSONTree from 'svelte-json-tree';
|
||||||
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
|
|
||||||
@@ -8,7 +9,8 @@
|
|||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
$: try {
|
$: try {
|
||||||
json = JSON.parse(selection[0].value);
|
const value = selection[0].value;
|
||||||
|
json = _.isPlainObject(value) || _.isArray(value) ? value : JSON.parse(value);
|
||||||
error = null;
|
error = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = err.message;
|
error = err.message;
|
||||||
@@ -16,7 +18,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
<ErrorInfo message="Error parsing JSON" />
|
<ErrorInfo message="Error parsing JSON" alignTop />
|
||||||
{:else}
|
{:else}
|
||||||
<div class="outer">
|
<div class="outer">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
|
|||||||
@@ -59,8 +59,10 @@
|
|||||||
{#if hideContent}
|
{#if hideContent}
|
||||||
<slot />
|
<slot />
|
||||||
{:else}
|
{:else}
|
||||||
{#if value == null}
|
{#if value === null}
|
||||||
<span class="null">(NULL)</span>
|
<span class="null">(NULL)</span>
|
||||||
|
{:else if value === undefined}
|
||||||
|
<span class="null">(No field)</span>
|
||||||
{:else if _.isDate(value)}
|
{:else if _.isDate(value)}
|
||||||
{moment(value).format('YYYY-MM-DD HH:mm:ss')}
|
{moment(value).format('YYYY-MM-DD HH:mm:ss')}
|
||||||
{:else if value === true}
|
{:else if value === true}
|
||||||
@@ -79,16 +81,12 @@
|
|||||||
{:else}
|
{:else}
|
||||||
{highlightSpecialCharacters(value)}
|
{highlightSpecialCharacters(value)}
|
||||||
{/if}
|
{/if}
|
||||||
|
{:else if value.type == 'Buffer' && _.isArray(value.data)}
|
||||||
|
<span class="null">({value.data.length} bytes)</span>
|
||||||
{:else if _.isPlainObject(value)}
|
{:else if _.isPlainObject(value)}
|
||||||
{#if _.isArray(value.data)}
|
<span class="null">(JSON)</span>
|
||||||
{#if value.data.length == 1 && isTypeLogical(col.dataType)}
|
{:else if _.isArray(value)}
|
||||||
{value.data[0]}
|
<span class="null">[{value.length} items]</span>
|
||||||
{:else}
|
|
||||||
<span class="null">({value.data.length} bytes)</span>
|
|
||||||
{/if}
|
|
||||||
{:else}
|
|
||||||
<span class="null">(RAW)</span>
|
|
||||||
{/if}
|
|
||||||
{:else}
|
{:else}
|
||||||
{value.toString()}
|
{value.toString()}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -103,6 +101,15 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
<!-- {#if _.isArray(value.data)}
|
||||||
|
{#if value.data.length == 1 && isTypeLogical(col.dataType)}
|
||||||
|
{value.data[0]}
|
||||||
|
{:else}
|
||||||
|
<span class="null">({value.data.length} bytes)</span>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<span class="null">(RAW)</span>
|
||||||
|
{/if} -->
|
||||||
<style>
|
<style>
|
||||||
td {
|
td {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
export let message;
|
export let message;
|
||||||
export let icon = 'img error';
|
export let icon = 'img error';
|
||||||
export let isSmall = false;
|
export let isSmall = false;
|
||||||
|
export let alignTop = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if isSmall}
|
{#if isSmall}
|
||||||
@@ -11,6 +12,15 @@
|
|||||||
<FontIcon {icon} />
|
<FontIcon {icon} />
|
||||||
{message || 'Unknown error'}
|
{message || 'Unknown error'}
|
||||||
</div>
|
</div>
|
||||||
|
{:else if alignTop}
|
||||||
|
<div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="icon">
|
||||||
|
<FontIcon {icon} />
|
||||||
|
</div>
|
||||||
|
{message || 'Unknown error'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
@@ -23,8 +33,8 @@
|
|||||||
<style>
|
<style>
|
||||||
.container {
|
.container {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
.icon {
|
.icon {
|
||||||
font-size: 20pt;
|
font-size: 20pt;
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
if (_.isString(value)) {
|
if (_.isString(value)) {
|
||||||
if (value.startsWith('[') || value.startsWith('{')) return 'json';
|
if (value.startsWith('[') || value.startsWith('{')) return 'json';
|
||||||
}
|
}
|
||||||
|
if (_.isPlainObject(value) || _.isArray(value)) {
|
||||||
|
return 'json';
|
||||||
|
}
|
||||||
return 'textWrap';
|
return 'textWrap';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +78,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="data">
|
<div class="data">
|
||||||
{#if usedFormat.single && selection?.length != 1}
|
{#if usedFormat.single && selection?.length != 1}
|
||||||
<ErrorInfo message="Must be selected one cell" />
|
<ErrorInfo message="Must be selected one cell" alignTop />
|
||||||
{:else if usedFormat == null}
|
{:else if usedFormat == null}
|
||||||
<ErrorInfo message="Format not selected" />
|
<ErrorInfo message="Format not selected" alignTop />
|
||||||
{:else if !selection || selection.length == 0}
|
{:else if !selection || selection.length == 0}
|
||||||
<ErrorInfo message="No data selected" />
|
<ErrorInfo message="No data selected" alignTop />
|
||||||
{:else}
|
{:else}
|
||||||
<svelte:component this={usedFormat?.component} {selection} />
|
<svelte:component this={usedFormat?.component} {selection} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user