Skip to content
Snippets Groups Projects
Verified Commit b5966866 authored by Kirill Stytsenko's avatar Kirill Stytsenko
Browse files

Unit Autosuggest

with preview of symbol, uri, etc.

Setting/saving value is still not implemented
parent b29e9ebd
No related branches found
No related tags found
4 merge requests!81New stable release,!43Merge dev to master,!40Misc,!39Column units
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
<thead> <thead>
<th>Column Name</th> <th>Column Name</th>
<th>Type</th> <th>Type</th>
<th>Unit</th>
<th>Primary Key</th> <th>Primary Key</th>
<th>Unique</th> <th>Unique</th>
<th>NULL Allowed</th> <th>NULL Allowed</th>
...@@ -113,6 +114,9 @@ ...@@ -113,6 +114,9 @@
<td> <td>
{{ col.column_type }} {{ col.column_type }}
</td> </td>
<td>
<DialogsColumnUnit :column="col" />
</td>
<td> <td>
<v-simple-checkbox v-model="col.is_primary_key" disabled aria-readonly="true" /> <v-simple-checkbox v-model="col.is_primary_key" disabled aria-readonly="true" />
</td> </td>
......
...@@ -3,11 +3,17 @@ ...@@ -3,11 +3,17 @@
v-model="dialog" v-model="dialog"
max-width="600px"> max-width="600px">
<template v-slot:activator="{ on, attrs }"> <template v-slot:activator="{ on, attrs }">
<i v-if="!name">unspecified</i>
<span v-else>{{ name }}</span>
<v-btn <v-btn
class="ml-2"
icon
small small
v-bind="attrs" v-bind="attrs"
v-on="on"> v-on="on">
Unit <v-icon>
mdi-pencil-outline
</v-icon>
</v-btn> </v-btn>
</template> </template>
<v-card> <v-card>
...@@ -15,16 +21,57 @@ ...@@ -15,16 +21,57 @@
<span class="text-h5">Column Unit</span> <span class="text-h5">Column Unit</span>
</v-card-title> </v-card-title>
<v-card-text> <v-card-text>
<div>
<i>
Autocomplete not working yet
</i>
</div>
<v-autocomplete <v-autocomplete
v-model="model"
solo
clearable
auto-select-first
:cache-items="false"
autofocus
:search-input.sync="search"
:items="items"
hide-no-data
hide-details hide-details
dense dense>
clearable /> <template
v-slot:item="{ item, attrs, on }">
<v-list-item v-bind="attrs" v-on="on">
<v-list-item-content>
<v-list-item-title>{{ item.value.name }}</v-list-item-title>
<v-list-item-subtitle>{{ item.value.comment }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</template>
</v-autocomplete>
</v-card-text> </v-card-text>
<v-expand-transition>
<v-list v-if="model" class="lighten-3" subheader three-line>
<v-list-item>
<v-list-item-content>
<v-list-item-title>Name</v-list-item-title>
<v-list-item-subtitle>{{ model.name }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-list-item-title>Symbol</v-list-item-title>
<v-list-item-subtitle>{{ model.symbol }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-list-item-title>Comment</v-list-item-title>
<v-list-item-subtitle>{{ model.comment }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item v-if="uri" three-line>
<v-list-item-content>
<v-list-item-title>URI</v-list-item-title>
<v-list-item-subtitle>{{ uri }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>
</v-expand-transition>
<v-card-actions> <v-card-actions>
<v-spacer /> <v-spacer />
<v-btn <v-btn
...@@ -54,42 +101,54 @@ export default { ...@@ -54,42 +101,54 @@ export default {
dialog: false, dialog: false,
isLoading: false, isLoading: false,
model: null, model: null,
uri: null,
search: null, search: null,
entries: [] entries: []
} }
}, },
computed: { computed: {
name () {
// TODO
return null
},
items () { items () {
return this.entries.map((entry) => { return this.entries && this.entries.map((entry) => {
const Description = entry.Description.length > this.descriptionLimit return {
? entry.Description.slice(0, this.descriptionLimit) + '...' // text: `${entry.name} [${entry.symbol}], ${entry.comment}`,
: entry.Description text: entry.name,
value: entry
return Object.assign({}, entry, { Description }) }
}) })
} }
}, },
watch: { watch: {
search (val) { async model (val) {
// Items have already been loaded this.uri = null
if (this.items.length > 0) { return } if (!val) { return }
try {
// Items have already been requested const res = await this.$axios.get(`/api/units/uri/${val.name}`)
this.uri = res.data.URI
} catch (err) {
this.$toast.error(`Could not load URI of unit "${val.name}"`)
console.log(err)
}
},
async search (val) {
if (this.isLoading) { return } if (this.isLoading) { return }
if (!val || !val.length) { return }
this.isLoading = true this.isLoading = true
try {
// Lazily load input items const res = await this.$axios.post('/api/units/suggest', {
this.$axios.get('/api/units/suggest') offset: 0,
.then((res) => { ustring: this.search
debugger
this.entries = res
}) })
.catch((err) => { this.entries = res.data
} catch (err) {
this.$toast.error('Could not load unit suggestions.')
console.log(err) console.log(err)
}) }
.finally(() => (this.isLoading = false)) this.isLoading = false
} }
}, },
mounted () { mounted () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment