mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
add group delete feature
This commit is contained in:
@@ -17,12 +17,18 @@
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="toolbar"
|
class="toolbar"
|
||||||
v-show="hasSelectedRows"
|
v-show="selectedQueriesCount > 0"
|
||||||
@click="exportQuery(selectedQueries)"
|
@click="exportQuery(selectedQueriesIds)"
|
||||||
>
|
>
|
||||||
Export
|
Export
|
||||||
</button>
|
</button>
|
||||||
<button class="toolbar" v-show="hasSelectedRows" @click="groupDelete">Delete</button>
|
<button
|
||||||
|
class="toolbar"
|
||||||
|
v-show="selectedQueriesCount > 0"
|
||||||
|
@click="showDeleteDialog(selectedQueriesIds)"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="toolbar-search">
|
<div id="toolbar-search">
|
||||||
<text-field placeholder="Search query by name" width="300px" v-model="filter"/>
|
<text-field placeholder="Search query by name" width="300px" v-model="filter"/>
|
||||||
@@ -51,7 +57,7 @@
|
|||||||
<div class="cell-data">
|
<div class="cell-data">
|
||||||
<check-box
|
<check-box
|
||||||
ref="rowCheckBox"
|
ref="rowCheckBox"
|
||||||
:init="selectAll || selectedQueries.has(query.id)"
|
:init="selectAll || selectedQueriesIds.has(query.id)"
|
||||||
@change="toggleRow($event, query.id)"
|
@change="toggleRow($event, query.id)"
|
||||||
/>
|
/>
|
||||||
<div class="name">{{ query.name }}</div>
|
<div class="name">{{ query.name }}</div>
|
||||||
@@ -98,19 +104,24 @@
|
|||||||
<!--Delete Query dialog -->
|
<!--Delete Query dialog -->
|
||||||
<modal name="delete" classes="dialog" height="auto">
|
<modal name="delete" classes="dialog" height="auto">
|
||||||
<div class="dialog-header">
|
<div class="dialog-header">
|
||||||
Delete query
|
Delete {{ deleteGroup ? 'queries' : 'query' }}
|
||||||
<close-icon @click="$modal.hide('delete')"/>
|
<close-icon @click="$modal.hide('delete')"/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="
|
v-if="
|
||||||
currentQueryIndex !== null
|
deleteGroup || (
|
||||||
&& currentQueryIndex >= 0
|
currentQueryIndex !== null
|
||||||
&& currentQueryIndex < queries.length
|
&& currentQueryIndex >= 0
|
||||||
|
&& currentQueryIndex < queries.length
|
||||||
|
)
|
||||||
"
|
"
|
||||||
class="dialog-body"
|
class="dialog-body"
|
||||||
>
|
>
|
||||||
Are you sure you want to delete
|
Are you sure you want to delete
|
||||||
"{{ queries[currentQueryIndex].name }}"?
|
{{ deleteGroup
|
||||||
|
? `${selectedQueriesCount} ${selectedQueriesCount > 1 ? 'queries' : 'query'}`
|
||||||
|
: `"${queries[currentQueryIndex].name}"`
|
||||||
|
}}?
|
||||||
</div>
|
</div>
|
||||||
<div class="dialog-buttons-container">
|
<div class="dialog-buttons-container">
|
||||||
<button class="secondary" @click="$modal.hide('delete')">Cancel</button>
|
<button class="secondary" @click="$modal.hide('delete')">Cancel</button>
|
||||||
@@ -149,9 +160,10 @@ export default {
|
|||||||
newName: null,
|
newName: null,
|
||||||
currentQueryId: null,
|
currentQueryId: null,
|
||||||
errorMsg: null,
|
errorMsg: null,
|
||||||
selectedQueries: new Set(),
|
selectedQueriesIds: new Set(),
|
||||||
|
selectedQueriesCount: 0,
|
||||||
selectAll: false,
|
selectAll: false,
|
||||||
hasSelectedRows: false
|
deleteGroup: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -226,20 +238,44 @@ export default {
|
|||||||
newQuery.id = nanoid()
|
newQuery.id = nanoid()
|
||||||
newQuery.createdAt = new Date()
|
newQuery.createdAt = new Date()
|
||||||
this.queries.push(newQuery)
|
this.queries.push(newQuery)
|
||||||
|
if (this.selectAll) {
|
||||||
|
this.selectedQueriesIds.add(newQuery.id)
|
||||||
|
this.selectedQueriesCount = this.selectedQueriesIds.size
|
||||||
|
}
|
||||||
this.saveQueriesInLocalStorage()
|
this.saveQueriesInLocalStorage()
|
||||||
},
|
},
|
||||||
showDeleteDialog (id) {
|
showDeleteDialog (id) {
|
||||||
this.currentQueryId = id
|
this.deleteGroup = typeof id !== 'string'
|
||||||
|
if (!this.deleteGroup) {
|
||||||
|
this.currentQueryId = id
|
||||||
|
}
|
||||||
this.$modal.show('delete')
|
this.$modal.show('delete')
|
||||||
},
|
},
|
||||||
deleteQuery () {
|
deleteQuery () {
|
||||||
this.$modal.hide('delete')
|
this.$modal.hide('delete')
|
||||||
this.queries.splice(this.currentQueryIndex, 1)
|
if (!this.deleteGroup) {
|
||||||
this.saveQueriesInLocalStorage()
|
this.queries.splice(this.currentQueryIndex, 1)
|
||||||
const tabIndex = this.findTabIndex(this.currentQueryId)
|
const tabIndex = this.findTabIndex(this.currentQueryId)
|
||||||
if (tabIndex >= 0) {
|
if (tabIndex >= 0) {
|
||||||
this.$store.commit('deleteTab', tabIndex)
|
this.$store.commit('deleteTab', tabIndex)
|
||||||
|
}
|
||||||
|
if (this.selectedQueriesIds.has(this.currentQueryId)) {
|
||||||
|
this.selectedQueriesIds.delete(this.currentQueryId)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.queries = this.selectAll
|
||||||
|
? []
|
||||||
|
: this.queries.filter(query => !this.selectedQueriesIds.has(query.id))
|
||||||
|
const tabs = this.$store.state.tabs
|
||||||
|
for (let i = tabs.length - 1; i >= 0; i--) {
|
||||||
|
if (this.selectedQueriesIds.has(tabs[i].id)) {
|
||||||
|
this.$store.commit('deleteTab', i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.selectedQueriesIds.clear()
|
||||||
}
|
}
|
||||||
|
this.selectedQueriesCount = this.selectedQueriesIds.size
|
||||||
|
this.saveQueriesInLocalStorage()
|
||||||
},
|
},
|
||||||
findTabIndex (id) {
|
findTabIndex (id) {
|
||||||
return this.$store.state.tabs.findIndex(tab => tab.id === id)
|
return this.$store.state.tabs.findIndex(tab => tab.id === id)
|
||||||
@@ -257,10 +293,9 @@ export default {
|
|||||||
delete data.createdAt
|
delete data.createdAt
|
||||||
} else {
|
} else {
|
||||||
// group operation
|
// group operation
|
||||||
console.log(this.queries.filter(query => this.selectedQueries.has(query.id)))
|
|
||||||
data = this.selectAll
|
data = this.selectAll
|
||||||
? JSON.parse(JSON.stringify(this.queries))
|
? JSON.parse(JSON.stringify(this.queries))
|
||||||
: this.queries.filter(query => this.selectedQueries.has(query.id))
|
: this.queries.filter(query => this.selectedQueriesIds.has(query.id))
|
||||||
name = 'My sqliteviz queries'
|
name = 'My sqliteviz queries'
|
||||||
data.forEach(query => {
|
data.forEach(query => {
|
||||||
delete query.id
|
delete query.id
|
||||||
@@ -290,6 +325,10 @@ export default {
|
|||||||
importedQueries.forEach(query => {
|
importedQueries.forEach(query => {
|
||||||
query.id = nanoid()
|
query.id = nanoid()
|
||||||
query.createdAt = new Date()
|
query.createdAt = new Date()
|
||||||
|
if (this.selectAll) {
|
||||||
|
this.selectedQueriesIds.add(query.id)
|
||||||
|
this.selectedQueriesCount = this.selectedQueriesIds.size
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.queries = this.queries.concat(importedQueries)
|
this.queries = this.queries.concat(importedQueries)
|
||||||
@@ -304,22 +343,21 @@ export default {
|
|||||||
toggleSelectAll (checked) {
|
toggleSelectAll (checked) {
|
||||||
this.selectAll = checked
|
this.selectAll = checked
|
||||||
this.$refs.rowCheckBox.forEach(item => { item.checked = checked })
|
this.$refs.rowCheckBox.forEach(item => { item.checked = checked })
|
||||||
this.selectedQueries = checked ? new Set(this.queries.map(query => query.id)) : new Set()
|
this.selectedQueriesIds = checked ? new Set(this.queries.map(query => query.id)) : new Set()
|
||||||
this.hasSelectedRows = checked
|
this.selectedQueriesCount = this.selectedQueriesIds.size
|
||||||
},
|
},
|
||||||
toggleRow (checked, id) {
|
toggleRow (checked, id) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
this.selectedQueries.add(id)
|
this.selectedQueriesIds.add(id)
|
||||||
} else {
|
} else {
|
||||||
if (this.selectedQueries.size === this.queries.length) {
|
if (this.selectedQueriesIds.size === this.queries.length) {
|
||||||
this.$refs.mainCheckBox.checked = false
|
this.$refs.mainCheckBox.checked = false
|
||||||
this.selectAll = false
|
this.selectAll = false
|
||||||
}
|
}
|
||||||
this.selectedQueries.delete(id)
|
this.selectedQueriesIds.delete(id)
|
||||||
}
|
}
|
||||||
this.hasSelectedRows = this.selectedQueries.size > 0
|
this.selectedQueriesCount = this.selectedQueriesIds.size
|
||||||
},
|
}
|
||||||
groupDelete () {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user