From e3f78fb693a13a7a6ee02cb2fc513ef3e2984833 Mon Sep 17 00:00:00 2001 From: simon987 Date: Fri, 12 Nov 2021 10:12:25 -0500 Subject: [PATCH] Shift click & select all/none in index picker --- sist2-vue/src/components/IndexPicker.vue | 80 ++++++++++++++++++++++-- sist2-vue/src/components/ResultsCard.vue | 2 +- sist2-vue/src/i18n/messages.ts | 9 ++- 3 files changed, 84 insertions(+), 7 deletions(-) diff --git a/sist2-vue/src/components/IndexPicker.vue b/sist2-vue/src/components/IndexPicker.vue index 96c4b4b..636f558 100644 --- a/sist2-vue/src/components/IndexPicker.vue +++ b/sist2-vue/src/components/IndexPicker.vue @@ -7,11 +7,28 @@ value-field="id">
- + + +
+ + {{ selectedIndices.length }} + {{ selectedIndices.length === 1 ? $t("indexPicker.selectedIndex") : $t("indexPicker.selectedIndices") }} + + +
+ {{ $t("indexPicker.selectAll") }} + {{ $t("indexPicker.selectNone") }} +
+
+ + + @click="toggleIndex(idx, $event)" + @click.shift="shiftClick(idx, $event)" + class="d-flex justify-content-between align-items-center list-group-item-action pointer" + :class="{active: lastClickIndex === idx}" + >
{{ idx.name }} @@ -36,6 +53,7 @@ export default Vue.extend({ data() { return { loading: true, + lastClickIndex: null } }, computed: { @@ -53,13 +71,50 @@ export default Vue.extend({ ...mapActions({ setSelectedIndices: "setSelectedIndices" }), + shiftClick(index, e) { + if (this.lastClickIndex === null) { + return; + } + + const select = this.isSelected(this.lastClickIndex); + + let leftBoundary = this.indices.indexOf(this.lastClickIndex); + let rightBoundary = this.indices.indexOf(index); + + if (rightBoundary < leftBoundary) { + let tmp = leftBoundary; + leftBoundary = rightBoundary; + rightBoundary = tmp; + } + + for (let i = leftBoundary; i <= rightBoundary; i++) { + if (select) { + if (!this.isSelected(this.indices[i])) { + this.setSelectedIndices([this.indices[i], ...this.selectedIndices]); + } + } else { + this.setSelectedIndices(this.selectedIndices.filter(idx => idx !== this.indices[i])); + } + } + }, + selectAll() { + this.setSelectedIndices(this.indices); + }, + selectNone() { + this.setSelectedIndices([]); + }, onSelect(value) { this.setSelectedIndices(this.indices.filter(idx => value.includes(idx.id))); }, formatIdxDate(timestamp: number): string { return format(new Date(timestamp * 1000), "yyyy-MM-dd"); }, - toggleIndex(index) { + toggleIndex(index, e) { + if (e.shiftKey) { + return; + } + + this.lastClickIndex = index; if (this.isSelected(index)) { this.setSelectedIndices(this.selectedIndices.filter(idx => idx.id != index.id)); } else { @@ -92,4 +147,21 @@ export default Vue.extend({ overflow-y: auto; max-height: 132px; } + +.btn-link:focus { + box-shadow: none; +} + +.unselectable { + user-select: none; + -ms-user-select: none; + -moz-user-select: none; + -webkit-user-select: none; +} + +.list-group-item.active { + z-index: 2; + background-color: inherit; + color: inherit; +} \ No newline at end of file diff --git a/sist2-vue/src/components/ResultsCard.vue b/sist2-vue/src/components/ResultsCard.vue index 42d1535..25ad174 100644 --- a/sist2-vue/src/components/ResultsCard.vue +++ b/sist2-vue/src/components/ResultsCard.vue @@ -23,7 +23,7 @@