1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

MyQueries refactoring

This commit is contained in:
lana-k
2021-03-13 17:08:47 +01:00
parent 8decda51a4
commit aa63aa94ee

View File

@@ -2,17 +2,18 @@
<div> <div>
<div id="start-guide" v-if="showedQueries.length === 0"> <div id="start-guide" v-if="showedQueries.length === 0">
You don't have saved queries so far. You don't have saved queries so far.
<span class="link" @click="create">Create</span> <span class="link" @click="$root.$emit('createNewQuery')">Create</span>
the one from scratch or the one from scratch or
<label for="import-file" class="link">import</label> from a file. <span @click="importQueries" class="link">import</span> from a file.
</div> </div>
<div id="my-queries-content" ref="my-queries-content" v-show="showedQueries.length > 0"> <div id="my-queries-content" ref="my-queries-content" v-show="showedQueries.length > 0">
<div id="my-queries-toolbar"> <div id="my-queries-toolbar">
<div id="toolbar-buttons"> <div id="toolbar-buttons">
<button class="toolbar" @click="importQueries"> <button id="toolbar-btns-import" class="toolbar" @click="importQueries">
Import Import
</button> </button>
<button <button
id="toolbar-btns-export"
class="toolbar" class="toolbar"
v-show="selectedQueriesCount > 0" v-show="selectedQueriesCount > 0"
@click="exportSelectedQueries()" @click="exportSelectedQueries()"
@@ -20,6 +21,7 @@
Export Export
</button> </button>
<button <button
id="toolbar-btns-delete"
class="toolbar" class="toolbar"
v-show="selectedNotPredefinedCount > 0" v-show="selectedNotPredefinedCount > 0"
@click="showDeleteDialog(selectedQueriesIds)" @click="showDeleteDialog(selectedQueriesIds)"
@@ -49,7 +51,6 @@
<tr <tr
v-for="(query, index) in showedQueries" v-for="(query, index) in showedQueries"
:key="query.id" :key="query.id"
:class="{ 'predefined': query.isPredefined }"
@click="openQuery(index)" @click="openQuery(index)"
> >
<td ref="name-td"> <td ref="name-td">
@@ -61,6 +62,7 @@
/> />
<div class="name">{{ query.name }}</div> <div class="name">{{ query.name }}</div>
<div <div
v-if="query.isPredefined"
class="badge" class="badge"
@mouseover="showTooltip" @mouseover="showTooltip"
@mouseout="hideTooltip" @mouseout="hideTooltip"
@@ -80,7 +82,10 @@
<rename-icon v-if="!query.isPredefined" @click="showRenameDialog(query.id)" /> <rename-icon v-if="!query.isPredefined" @click="showRenameDialog(query.id)" />
<copy-icon @click="duplicateQuery(index)"/> <copy-icon @click="duplicateQuery(index)"/>
<export-icon @click="exportToFile([query], `${query.name}.json`)"/> <export-icon @click="exportToFile([query], `${query.name}.json`)"/>
<delete-icon v-if="!query.isPredefined" @click="showDeleteDialog(query.id)"/> <delete-icon
v-if="!query.isPredefined"
@click="showDeleteDialog((new Set()).add(query.id))"
/>
</div> </div>
</div> </div>
</td> </td>
@@ -117,21 +122,8 @@
Delete {{ deleteGroup ? 'queries' : 'query' }} Delete {{ deleteGroup ? 'queries' : 'query' }}
<close-icon @click="$modal.hide('delete')"/> <close-icon @click="$modal.hide('delete')"/>
</div> </div>
<div <div class="dialog-body">
v-if=" {{ deleteDialogMsg }}
deleteGroup || (
currentQueryIndex !== null
&& currentQueryIndex >= 0
&& currentQueryIndex < queries.length
)
"
class="dialog-body"
>
Are you sure you want to delete
{{ deleteGroup
? `${selectedNotPredefinedCount} ${selectedNotPredefinedCount > 1 ? 'queries' : 'query'}`
: `"${queries[currentQueryIndex].name}"`
}}?
<div v-show="selectedQueriesCount > selectedNotPredefinedCount" id="note"> <div v-show="selectedQueriesCount > selectedNotPredefinedCount" id="note">
<img :src="require('@/assets/images/info.svg')"> <img :src="require('@/assets/images/info.svg')">
Note: Predefined queries you've selected won't be deleted Note: Predefined queries you've selected won't be deleted
@@ -174,7 +166,7 @@ export default {
queries: [], queries: [],
filter: null, filter: null,
newName: null, newName: null,
currentQueryId: null, processedQueryId: null,
errorMsg: null, errorMsg: null,
selectedQueriesIds: new Set(), selectedQueriesIds: new Set(),
selectedQueriesCount: 0, selectedQueriesCount: 0,
@@ -207,8 +199,25 @@ export default {
allQueries () { allQueries () {
return this.predefinedQueries.concat(this.queries) return this.predefinedQueries.concat(this.queries)
}, },
currentQueryIndex () { processedQueryIndex () {
return this.queries.findIndex(query => query.id === this.currentQueryId) return this.queries.findIndex(query => query.id === this.processedQueryId)
},
deleteDialogMsg () {
if (!this.deleteGroup && (
this.processedQueryIndex === null ||
this.processedQueryIndex < 0 ||
this.processedQueryIndex > this.queries.length
)) {
return ''
}
const deleteItem = this.deleteGroup
? `${this.selectedNotPredefinedCount} ${this.selectedNotPredefinedCount > 1
? 'queries'
: 'query'}`
: `"${this.queries[this.processedQueryIndex].name}"`
return `Are you sure you want to delete ${deleteItem}?`
} }
}, },
created () { created () {
@@ -260,10 +269,6 @@ export default {
const freeSpace = this.$refs['my-queries-content'].offsetHeight - 200 const freeSpace = this.$refs['my-queries-content'].offsetHeight - 200
this.maxTableHeight = freeSpace - (freeSpace % 40) + 1 this.maxTableHeight = freeSpace - (freeSpace % 40) + 1
}, },
create () {
this.$root.$emit('createNewQuery')
this.$router.push('/editor')
},
openQuery (index) { openQuery (index) {
const tab = this.showedQueries[index] const tab = this.showedQueries[index]
this.$store.dispatch('addTab', tab).then(id => { this.$store.dispatch('addTab', tab).then(id => {
@@ -273,8 +278,8 @@ export default {
}, },
showRenameDialog (id) { showRenameDialog (id) {
this.errorMsg = null this.errorMsg = null
this.currentQueryId = id this.processedQueryId = id
this.newName = this.queries[this.currentQueryIndex].name this.newName = this.queries[this.processedQueryIndex].name
this.$modal.show('rename') this.$modal.show('rename')
}, },
renameQuery () { renameQuery () {
@@ -282,20 +287,20 @@ export default {
this.errorMsg = 'Query name can\'t be empty' this.errorMsg = 'Query name can\'t be empty'
return return
} }
const currentQuery = this.queries[this.currentQueryIndex] const processedQuery = this.queries[this.processedQueryIndex]
currentQuery.name = this.newName processedQuery.name = this.newName
this.$set(this.queries, this.currentQueryIndex, currentQuery) this.$set(this.queries, this.processedQueryIndex, processedQuery)
// update queries in local storage // update queries in local storage
storedQueries.updateStorage(this.queries) storedQueries.updateStorage(this.queries)
// update tab, if renamed query is opened // update tab, if renamed query is opened
const tabIndex = this.findTabIndex(currentQuery.id) const tabIndex = this.findTabIndex(processedQuery.id)
if (tabIndex >= 0) { if (tabIndex >= 0) {
this.$store.commit('updateTab', { this.$store.commit('updateTab', {
index: tabIndex, index: tabIndex,
name: this.newName, name: this.newName,
id: currentQuery.id id: processedQuery.id
}) })
} }
// hide dialog // hide dialog
@@ -310,27 +315,27 @@ export default {
this.queries.push(newQuery) this.queries.push(newQuery)
storedQueries.updateStorage(this.queries) storedQueries.updateStorage(this.queries)
}, },
showDeleteDialog (id) { showDeleteDialog (idsSet) {
this.deleteGroup = typeof id !== 'string' this.deleteGroup = idsSet.size > 1
if (!this.deleteGroup) { if (!this.deleteGroup) {
this.currentQueryId = id this.processedQueryId = idsSet.values().next().value
} }
this.$modal.show('delete') this.$modal.show('delete')
}, },
deleteQuery () { deleteQuery () {
this.$modal.hide('delete') this.$modal.hide('delete')
if (!this.deleteGroup) { if (!this.deleteGroup) {
this.queries.splice(this.currentQueryIndex, 1) this.queries.splice(this.processedQueryIndex, 1)
// Close deleted query tab if it was opened // Close deleted query tab if it was opened
const tabIndex = this.findTabIndex(this.currentQueryId) const tabIndex = this.findTabIndex(this.processedQueryId)
if (tabIndex >= 0) { if (tabIndex >= 0) {
this.$store.commit('deleteTab', tabIndex) this.$store.commit('deleteTab', tabIndex)
} }
// Clear checkboxes // Clear checkboxes
if (this.selectedQueriesIds.has(this.currentQueryId)) { if (this.selectedQueriesIds.has(this.processedQueryId)) {
this.selectedQueriesIds.delete(this.currentQueryId) this.selectedQueriesIds.delete(this.processedQueryId)
} }
} else { } else {
this.queries = this.selectAll this.queries = this.selectAll
@@ -363,7 +368,7 @@ export default {
? this.allQueries ? this.allQueries
: this.allQueries.filter(query => this.selectedQueriesIds.has(query.id)) : this.allQueries.filter(query => this.selectedQueriesIds.has(query.id))
this.exportToFile(queryList, 'My sqlitevis queries.json') this.exportToFile(queryList, 'My sqliteviz queries.json')
}, },
importQueries () { importQueries () {
storedQueries.importQueries() storedQueries.importQueries()
@@ -525,15 +530,6 @@ button.toolbar {
margin-right: 16px; margin-right: 16px;
} }
button label {
display: block;
line-height: 36px;
}
button label:hover {
cursor: pointer;
}
.badge { .badge {
display: none; display: none;
background-color: var(--color-gray-light-4); background-color: var(--color-gray-light-4);
@@ -545,7 +541,7 @@ button label:hover {
margin-left: 12px; margin-left: 12px;
} }
tbody tr.predefined:hover .badge { tbody tr:hover .badge {
display: block; display: block;
} }
#note { #note {