1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-08 02:58:54 +08:00
Files
sqliteviz/src/components/Schema.vue
2021-01-30 20:20:51 +01:00

119 lines
2.4 KiB
Vue

<template>
<div id="schema-container">
<div id="schema-filter">
<text-field placeholder="Search table" width="100%" v-model="filter"/>
</div>
<div id="db">
<div @click="schemaVisible = !schemaVisible" class="db-name">
<tree-chevron :expanded="schemaVisible"/>
{{ dbName }}
</div>
<div id="db-edit" @click="changeDb">
<change-db-icon />
</div>
</div>
<div v-show="schemaVisible" class="schema">
<table-description
v-for="table in schema"
:key="table.name"
:name="table.name"
:columns="table.columns"
/>
</div>
</div>
</template>
<script>
import TableDescription from '@/components/TableDescription'
import TextField from '@/components/TextField'
import ChangeDbIcon from '@/components/svg/changeDb'
import TreeChevron from '@/components/svg/treeChevron'
import fu from '@/fileUtils'
export default {
name: 'Schema',
components: {
TableDescription,
TextField,
ChangeDbIcon,
TreeChevron
},
data () {
return {
schemaVisible: true,
filter: null
}
},
computed: {
schema () {
if (!this.$store.state.schema) {
return []
}
return !this.filter
? this.$store.state.schema
: this.$store.state.schema.filter(
table => table.name.toUpperCase().indexOf(this.filter.toUpperCase()) !== -1
)
},
dbName () {
return this.$store.state.dbName
}
},
methods: {
changeDb () {
fu.getFileFromUser('.db,.sqlite,.sqlite3')
.then(file => {
return this.$db.loadDb(file)
})
.then((schema) => {
this.$store.commit('saveSchema', schema)
})
}
}
}
</script>
<style scoped>
#schema-container {
position: relative;
padding-bottom: 24px;
}
.schema {
margin-left: 12px;
padding: 0 12px;
}
#schema-filter {
padding: 32px 12px;
position: sticky;
position: -webkit-sticky;
top: 0;
width: 100%;
height: 100px;
box-sizing: border-box;
background-image: linear-gradient(white 73%, transparent);;
z-index: 2;
}
.schema, .db-name {
color: var(--color-text-base);
font-size: 13px;
white-space: nowrap;
}
#db {
display: flex;
align-items: center;
margin-top: -5px;
padding: 0 12px;
}
.db-name {
cursor: pointer;
}
.db-name:hover .chevron-icon path,
>>> .table-name:hover .chevron-icon path {
fill: var(--color-gray-dark);
}
</style>