Show errors in UI

This commit is contained in:
Christian Georgi
2022-02-01 19:51:52 +01:00
parent 74f9d5cc1e
commit 37811381e7
3 changed files with 29 additions and 13 deletions

View File

@@ -8,7 +8,7 @@
"mocha": true "mocha": true
}, },
"parserOptions": { "parserOptions": {
"ecmaVersion": 2018 "ecmaVersion": 2020
}, },
"globals": { "globals": {
"SELECT": true, "SELECT": true,

View File

@@ -14,6 +14,7 @@ const vue = new Vue ({
el:'#app', el:'#app',
data: { data: {
error: undefined,
dataSource: storageGet('data-source', 'db'), dataSource: storageGet('data-source', 'db'),
skip: storageGet('skip', 0), skip: storageGet('skip', 0),
top: storageGet('top', 20), top: storageGet('top', 20),
@@ -61,8 +62,9 @@ const vue = new Vue ({
async fetchData () { async fetchData () {
let url = `/Data?entity=${vue.entity.name}&$skip=${vue.skip}&$top=${vue.top}` let url = `/Data?entity=${vue.entity.name}&$skip=${vue.skip}&$top=${vue.top}`
if (vue.dataSource === 'db') url += `&dataSource=db` if (vue.dataSource === 'db') url += `&dataSource=db`
const {data} = await GET(url)
try {
const {data} = await GET(url)
// sort data along column order // sort data along column order
const columnIndexes = {} const columnIndexes = {}
vue.columns.forEach((col, i) => columnIndexes[col.name] = i) vue.columns.forEach((col, i) => columnIndexes[col.name] = i)
@@ -70,10 +72,20 @@ const vue = new Vue ({
.sort((r1, r2) => columnIndexes[r1.column] - columnIndexes[r2.column]) .sort((r1, r2) => columnIndexes[r1.column] - columnIndexes[r2.column])
.map(r => r.data) .map(r => r.data)
) )
const row = vue.data.find(data => vue._makeRowKey(data) === vue.rowKey) const row = vue.data.find(data => vue._makeRowKey(data) === vue.rowKey)
if (row) vue._setRowDetails(row) if (row) vue._setRowDetails(row)
else vue.rowDetails = {} else vue.rowDetails = {}
vue.error = undefined
} catch (err) {
if (err.response?.data?.error) {
vue.error = err.response?.data?.error
} else {
vue.error = err
}
vue.data = []
vue.rowDetails = {}
}
}, },
inspectRow (eve) { inspectRow (eve) {

View File

@@ -25,6 +25,7 @@
.not-sidebar-sub { max-height: 40vh; overflow-y: scroll; } .not-sidebar-sub { max-height: 40vh; overflow-y: scroll; }
.horizontal label { display: inline; } .horizontal label { display: inline; }
.horizontal input { width: initial; display: inline; } .horizontal input { width: initial; display: inline; }
.error { color: red; }
</style> </style>
</head> </head>
@@ -61,7 +62,7 @@
<label for="top">Top:</label> <label for="top">Top:</label>
<input id="top" v-model.lazy="top" title="No. of entries to read" type="number" min="0"> <input id="top" v-model.lazy="top" title="No. of entries to read" type="number" min="0">
</div> </div>
<div v-if="entity" class="not-sidebar-main"> <div v-if="data" class="not-sidebar-main">
<table id='data' class="hovering striped-table condensed"> <table id='data' class="hovering striped-table condensed">
<thead> <thead>
<th v-for="col in columns" :title="col.type" :class="[col.isKey ? 'key' : 'not-key']">{{ col.name }} </th> <th v-for="col in columns" :title="col.type" :class="[col.isKey ? 'key' : 'not-key']">{{ col.name }} </th>
@@ -71,6 +72,9 @@
</tr> </tr>
</table> </table>
</div> </div>
<div v-if="error" class="not-sidebar-main error">
Error: {{ error.code }} &ndash; {{ error.message }}
</div>
<p></p> <p></p>
<div v-if="rowDetails" class="not-sidebar-sub"> <div v-if="rowDetails" class="not-sidebar-sub">
<table id='rowDetails'> <table id='rowDetails'>