From 90844cb0309618a351d180a24fdf2b79b6b6416d Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Tue, 6 Jul 2021 20:09:08 +0200 Subject: [PATCH] Allow bulk deletion and list creation in file manager --- .../user_file_manager/DirectoryElement.svelte | 30 ++- .../src/user_file_manager/FileManager.svelte | 197 +++++++++++++++--- 2 files changed, 197 insertions(+), 30 deletions(-) diff --git a/svelte/src/user_file_manager/DirectoryElement.svelte b/svelte/src/user_file_manager/DirectoryElement.svelte index 5836e05..bdec067 100644 --- a/svelte/src/user_file_manager/DirectoryElement.svelte +++ b/svelte/src/user_file_manager/DirectoryElement.svelte @@ -18,8 +18,9 @@ export const reset = () => { allFiles = [] } -export const addFile = (icon, name, href, type, size, sizeLabel, dateCreated) => { +export const addFile = (id, icon, name, href, type, size, sizeLabel, dateCreated) => { allFiles.push({ + id: id, icon: icon, name: name, href: href, @@ -37,6 +38,18 @@ export const renderFiles = () => { search(lastSearchTerm) } +export const getSelectedFiles = () => { + let selectedFiles = [] + + for (let i in allFiles) { + if (allFiles[i].selected) { + selectedFiles.push(allFiles[i]) + } + } + + return selectedFiles +} + // search filters the allFiles array on a search term. All files which match the // search term will be put into visibleFiles. The visibleFiles array will then // be rendered by render_visible_files @@ -251,9 +264,18 @@ let last_selected_node = -1 const node_click = (index) => { if (selectionMode) { if (shift_pressed && last_selected_node != -1) { + let id_low = last_selected_node + let id_high = last_selected_node + if (last_selected_node < index) { + id_high = index + } else { + id_low = index + } - for (let i = last_selected_node; i <= index && !allFiles[i].filtered; i++) { - allFiles[i].selected = !allFiles[i].selected + for (let i = id_low; i <= id_high && !allFiles[i].filtered; i++) { + if (i != last_selected_node) { + allFiles[i].selected = !allFiles[i].selected + } } } else { allFiles[index].selected = !allFiles[index].selected @@ -390,7 +412,7 @@ const node_click = (index) => { text-decoration: none; } .node_selected { - background-color: var(--highlight_color); + background-color: var(--highlight_color_dark); color: var(--highlight_text_color); } .node > div { diff --git a/svelte/src/user_file_manager/FileManager.svelte b/svelte/src/user_file_manager/FileManager.svelte index 8a40d43..a56b32c 100644 --- a/svelte/src/user_file_manager/FileManager.svelte +++ b/svelte/src/user_file_manager/FileManager.svelte @@ -1,12 +1,16 @@ - +
{#if selecting} {/if} @@ -146,6 +266,37 @@ onMount(() => {
{/if} + + help_modal_visible = true} + on:hidden={() => help_modal_visible = false} + > +

+ In the file manager you can see the files you have uploaded and the + lists you have created. +

+

Searching

+

+ By clicking the search bar or pressing the / button you can search + through your files or lists. Only the entries matching your search + term will be shown. Pressing Enter will open the first search result + in a new tab. Pressing Escape will cancel the search and all files + will be shown again. +

+

Bulk actions

+

+ With the Select button you can click files to select them. Once you + have made a selection you can use the buttons on the toolbar to + either create a list containing the selected files or delete them. +

+

+ Holding Shift while selecting a file will select all the files + between the file you last selected and the file you just clicked. +

+