From f358a51e04a5a31c7bee2cf517141e27c46493df Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Sat, 23 Nov 2024 10:24:43 -0300 Subject: [PATCH 1/3] fix: order of actions Signed-off-by: Vitor Mattos --- src/views/FilesList/FileEntry/FileEntry.vue | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/views/FilesList/FileEntry/FileEntry.vue b/src/views/FilesList/FileEntry/FileEntry.vue index dc7512ba02..fd832d4fe8 100644 --- a/src/views/FilesList/FileEntry/FileEntry.vue +++ b/src/views/FilesList/FileEntry/FileEntry.vue @@ -13,6 +13,13 @@ :extension="'.pdf'" /> + + + @@ -26,13 +33,6 @@ @click="openDetailsIfAvailable"> - - - From 19b4095907e5eb221fd66de445146c35d27f94a3 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Sat, 23 Nov 2024 12:16:35 -0300 Subject: [PATCH 2/3] feat: make possible select multiple files Signed-off-by: Vitor Mattos --- src/store/files.js | 9 ++ src/store/keyboard.js | 47 ++++++ src/store/selection.js | 57 +++++++ src/views/FilesList/FileEntry/FileEntry.vue | 6 + .../FilesList/FileEntry/FileEntryCheckbox.vue | 113 ++++++++++++++ .../FilesList/FileEntry/FileEntryGrid.vue | 6 + src/views/FilesList/FilesListTableHeader.vue | 57 +++++++ .../FilesList/FilesListTableHeaderActions.vue | 146 ++++++++++++++++++ src/views/FilesList/FilesListVirtual.vue | 37 +++++ src/views/FilesList/VirtualList.vue | 6 +- 10 files changed, 483 insertions(+), 1 deletion(-) create mode 100644 src/store/keyboard.js create mode 100644 src/store/selection.js create mode 100644 src/views/FilesList/FileEntry/FileEntryCheckbox.vue create mode 100644 src/views/FilesList/FilesListTableHeaderActions.vue diff --git a/src/store/files.js b/src/store/files.js index b900382f68..4a5f270bea 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -231,6 +231,15 @@ export const useFilesStore = function(...args) { this.ordered.splice(index, 1) } }, + changeStatus(files, status) { + Object.entries(files).filter(([key, file]) => { + set( + this.files[file.nodeId], + 'status', + status, + ) + }) + }, async getAllFiles(filter) { if (this.loading || this.loadedAll) { if (!filter) { diff --git a/src/store/keyboard.js b/src/store/keyboard.js new file mode 100644 index 0000000000..20693a71d5 --- /dev/null +++ b/src/store/keyboard.js @@ -0,0 +1,47 @@ +/** + * SPDX-FileCopyrightText: 2024 LibreCode coop and contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { defineStore } from 'pinia' +import { set } from 'vue' + +/** + * Observe various events and save the current + * special keys states. Useful for checking the + * current status of a key when executing a method. + * @param {...any} args properties + */ +export const useKeyboardStore = function(...args) { + const store = defineStore('keyboard', { + state: () => ({ + altKey: false, + ctrlKey: false, + metaKey: false, + shiftKey: false, + }), + + actions: { + onEvent(event) { + if (!event) { + event = window.event + } + set(this, 'altKey', !!event.altKey) + set(this, 'ctrlKey', !!event.ctrlKey) + set(this, 'metaKey', !!event.metaKey) + set(this, 'shiftKey', !!event.shiftKey) + }, + }, + }) + + const keyboardStore = store(...args) + // Make sure we only register the listeners once + if (!keyboardStore._initialized) { + window.addEventListener('keydown', keyboardStore.onEvent) + window.addEventListener('keyup', keyboardStore.onEvent) + window.addEventListener('mousemove', keyboardStore.onEvent) + + keyboardStore._initialized = true + } + + return keyboardStore +} diff --git a/src/store/selection.js b/src/store/selection.js new file mode 100644 index 0000000000..a6e6ed3b1f --- /dev/null +++ b/src/store/selection.js @@ -0,0 +1,57 @@ +/** + * SPDX-FileCopyrightText: 2024 LibreCode coop and contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { defineStore } from 'pinia' +import { set } from 'vue' + +import { subscribe } from '@nextcloud/event-bus' + +export const useSelectionStore = function(...args) { + const store = defineStore('selection', { + state: () => ({ + selected: [], + lastSelection: [], + lastSelectedIndex: null, + }), + + actions: { + /** + * Set the selection of fileIds + * @param {Array} selection Selected files + */ + set(selection = []) { + set(this, 'selected', [...new Set(selection)]) + }, + + /** + * Set the last selected index + * @param {number | null} lastSelectedIndex Position of last selected file + */ + setLastIndex(lastSelectedIndex = null) { + // Update the last selection if we provided a new selection starting point + set(this, 'lastSelection', lastSelectedIndex ? this.selected : []) + set(this, 'lastSelectedIndex', lastSelectedIndex) + }, + + /** + * Reset the selection + */ + reset() { + set(this, 'selected', []) + set(this, 'lastSelection', []) + set(this, 'lastSelectedIndex', null) + }, + }, + }) + + const selectionStore = store(...args) + + // Make sure we only register the listeners once + if (!selectionStore._initialized) { + subscribe('libresign:filters:update', selectionStore.reset) + selectionStore._initialized = true + } + + return selectionStore +} diff --git a/src/views/FilesList/FileEntry/FileEntry.vue b/src/views/FilesList/FileEntry/FileEntry.vue index fd832d4fe8..69e4c57e2f 100644 --- a/src/views/FilesList/FileEntry/FileEntry.vue +++ b/src/views/FilesList/FileEntry/FileEntry.vue @@ -5,6 +5,10 @@