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

#115 select cell between modes; pass record number

This commit is contained in:
lana-k
2023-10-29 20:01:51 +01:00
parent 735e4ec7f6
commit 5ee881432a
3 changed files with 66 additions and 42 deletions

View File

@@ -37,6 +37,7 @@
v-for="(col, colIndex) in columns" v-for="(col, colIndex) in columns"
:data-col="colIndex" :data-col="colIndex"
:data-row="rowIndex - 1" :data-row="rowIndex - 1"
:data-record="pageSize * (currentPage - 1) + rowIndex - 1"
:key="colIndex" :key="colIndex"
:aria-selected="false" :aria-selected="false"
@click="onCellClick" @click="onCellClick"
@@ -74,13 +75,18 @@ export default {
type: Number, type: Number,
default: 20 default: 20
}, },
preview: Boolean page: {
type: Number,
default: 1
},
preview: Boolean,
selectedCellCoordinates: Object
}, },
data () { data () {
return { return {
header: null, header: null,
tableWidth: null, tableWidth: null,
currentPage: 1, currentPage: this.page,
resizeObserver: null, resizeObserver: null,
selectedCellElement: null selectedCellElement: null
} }
@@ -112,6 +118,20 @@ export default {
} }
} }
}, },
mounted () {
this.resizeObserver = new ResizeObserver(this.calculateHeadersWidth)
this.resizeObserver.observe(this.$refs.table)
this.calculateHeadersWidth()
if (this.selectedCellCoordinates) {
const { row, col } = this.selectedCellCoordinates
const cell = this.$refs.table
.querySelector(`td[data-col="${col}"][data-row="${row}"]`)
if (cell) {
this.selectCell(cell)
}
}
},
methods: { methods: {
calculateHeadersWidth () { calculateHeadersWidth () {
this.tableWidth = this.$refs['table-container'].offsetWidth this.tableWidth = this.$refs['table-container'].offsetWidth
@@ -132,7 +152,10 @@ export default {
40: 'down' 40: 'down'
} }
if (!Object.keys(keyCodeMap).includes(e.keyCode.toString())) { if (
!this.selectedCellElement ||
!Object.keys(keyCodeMap).includes(e.keyCode.toString())
) {
return return
} }
e.preventDefault() e.preventDefault()
@@ -192,11 +215,6 @@ export default {
} }
} }
}, },
mounted () {
this.resizeObserver = new ResizeObserver(this.calculateHeadersWidth)
this.resizeObserver.observe(this.$refs.table)
this.calculateHeadersWidth()
},
beforeDestroy () { beforeDestroy () {
this.resizeObserver.unobserve(this.$refs.table) this.resizeObserver.unobserve(this.$refs.table)
}, },

View File

@@ -54,15 +54,11 @@ export default {
props: { props: {
dataSet: Object, dataSet: Object,
time: String, time: String,
pageSize: { rowIndex: { type: Number, default: 0 },
type: Number, selectedColumnIndex: Number
default: 20
},
rowIndex: { type: Number, default: 0 }
}, },
data () { data () {
return { return {
currentPage: 1,
selectedCellElement: null, selectedCellElement: null,
currentRowIndex: this.rowIndex currentRowIndex: this.rowIndex
} }
@@ -73,21 +69,13 @@ export default {
}, },
rowCount () { rowCount () {
return this.dataSet.values[this.columns[0]].length return this.dataSet.values[this.columns[0]].length
}, }
pageCount () { },
return Math.ceil(this.rowCount / this.pageSize) mounted () {
}, const cell = this.$refs.table
currentPageData () { .querySelector(`td[data-col="1"][data-row="${this.selectedColumnIndex}"]`)
const start = (this.currentPage - 1) * this.pageSize if (cell) {
let end = start + this.pageSize this.selectCell(cell)
if (end > this.rowCount - 1) {
end = this.rowCount - 1
}
return {
start,
end,
count: end - start + 1
}
} }
}, },
methods: { methods: {
@@ -97,7 +85,10 @@ export default {
40: 'down' 40: 'down'
} }
if (!Object.keys(keyCodeMap).includes(e.keyCode.toString())) { if (
!this.selectedCellElement ||
!Object.keys(keyCodeMap).includes(e.keyCode.toString())
) {
return return
} }
e.preventDefault() e.preventDefault()
@@ -133,11 +124,6 @@ export default {
this.selectCell(newCell) this.selectCell(newCell)
} }
} }
},
watch: {
dataSet () {
this.currentPage = 1
}
} }
} }
</script> </script>
@@ -169,4 +155,8 @@ table.sqliteviz-table {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.table-footer {
align-items: center;
}
</style> </style>

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="run-result-panel"> <div class="run-result-panel" ref="runResultPanel">
<component <component
:is="viewValuePanelVisible ? 'splitpanes':'div'" :is="viewValuePanelVisible ? 'splitpanes':'div'"
:before="{ size: 50, max: 100 }" :before="{ size: 50, max: 100 }"
@@ -8,7 +8,7 @@
class="run-result-panel-content" class="run-result-panel-content"
> >
<template #left-pane> <template #left-pane>
<div :id="'run-result-left-pane-'+tab.id" class="result-set-container"/> <div :id="'run-result-left-pane-'+tab.id" class="result-set-container"/>
</template> </template>
<div :id="'run-result-result-set-'+tab.id" class="result-set-container"/> <div :id="'run-result-result-set-'+tab.id" class="result-set-container"/>
<template #right-pane v-if="viewValuePanelVisible"> <template #right-pane v-if="viewValuePanelVisible">
@@ -68,7 +68,7 @@
/> />
<teleport :to="resultSetTeleportTarget"> <teleport :to="resultSetTeleportTarget">
<div ref="runResultPanel"> <div>
<div <div
v-show="result === null && !isGettingResults && !error" v-show="result === null && !isGettingResults && !error"
class="table-preview result-before" class="table-preview result-before"
@@ -91,16 +91,19 @@
:data-set="result" :data-set="result"
:time="time" :time="time"
:pageSize="pageSize" :pageSize="pageSize"
:page="defaultPage"
:selected-cell-coordinates="defaultSelectedCell"
class="straight" class="straight"
@updateSelectedCell="onUpdateSelectedCell" @updateSelectedCell="onUpdateSelectedCell"
/> />
<record <record
ref="recordView"
v-if="result && viewRecord" v-if="result && viewRecord"
:data-set="result" :data-set="result"
:time="time" :time="time"
:pageSize="pageSize" :selected-column-index="selectedCell ? +selectedCell.dataset.col : 0"
class="straight" :rowIndex="selectedCell ? +selectedCell.dataset.record : 0"
@updateSelectedCell="onUpdateSelectedCell" @updateSelectedCell="onUpdateSelectedCell"
/> />
</div> </div>
@@ -145,7 +148,9 @@ export default {
viewValuePanelVisible: false, viewValuePanelVisible: false,
selectedCell: null, selectedCell: null,
selectedCellValue: '', selectedCellValue: '',
viewRecord: false viewRecord: false,
defaultPage: 1,
defaultSelectedCell: null
} }
}, },
components: { components: {
@@ -251,6 +256,16 @@ export default {
}, },
toggleViewRecord () { toggleViewRecord () {
if (this.viewRecord) {
this.defaultSelectedCell = {
row: (this.$refs.recordView.currentRowIndex + this.pageSize) % this.pageSize,
col: this.selectedCell ? +this.selectedCell.dataset.row : 0
}
this.defaultPage = Math.ceil(
(this.$refs.recordView.currentRowIndex + 1) / this.pageSize
)
}
this.viewRecord = !this.viewRecord this.viewRecord = !this.viewRecord
}, },
@@ -275,7 +290,8 @@ export default {
width: 0; width: 0;
} }
.result-set-container { .result-set-container,
.result-set-container > div {
position: relative; position: relative;
height: 100%; height: 100%;
width: 100%; width: 100%;