From 38417ab6619d1232d6c494559835391d2f025152 Mon Sep 17 00:00:00 2001 From: joshuaboud Date: Mon, 30 May 2022 14:31:12 -0300 Subject: [PATCH] only recurse on refresh --- navigator/src/components/DirectoryEntry.vue | 6 +-- .../src/components/DirectoryEntryList.vue | 50 +++++++++++-------- navigator/src/components/DirectoryView.vue | 6 +-- navigator/src/views/Browser.vue | 4 +- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/navigator/src/components/DirectoryEntry.vue b/navigator/src/components/DirectoryEntry.vue index 68254ab..ab811d8 100644 --- a/navigator/src/components/DirectoryEntry.vue +++ b/navigator/src/components/DirectoryEntry.vue @@ -136,8 +136,8 @@ export default { } } - const getEntries = () => { - return directoryViewRef.value?.getEntries?.(); + const refresh = () => { + return directoryViewRef.value?.refresh?.(); } const toggleShowEntries = () => { @@ -183,7 +183,7 @@ export default { showEntries, directoryViewRef, doubleClickCallback, - getEntries, + refresh, toggleShowEntries, getSelected, selectAll, diff --git a/navigator/src/components/DirectoryEntryList.vue b/navigator/src/components/DirectoryEntryList.vue index 67fd310..2c9fa41 100644 --- a/navigator/src/components/DirectoryEntryList.vue +++ b/navigator/src/components/DirectoryEntryList.vue @@ -25,7 +25,6 @@ import { notificationsInjectionKey, settingsInjectionKey } from '../keys'; import DirectoryEntry from './DirectoryEntry.vue'; import getDirListing from '../functions/getDirListing'; import getDirEntryObjects from '../functions/getDirEntryObjects'; -import { RECORD_SEPARATOR, UNIT_SEPARATOR } from '../constants'; import FileSystemWatcher from '../functions/fileSystemWatcher'; export default { @@ -48,7 +47,13 @@ export default { }, setup(props, { emit }) { const settings = inject(settingsInjectionKey); + /** + * @type {Ref} + */ const entries = ref([]); + /** + * @type {Ref} + */ const visibleEntries = ref([]); const notifications = inject(notificationsInjectionKey); const entryRefs = ref([]); @@ -146,8 +151,6 @@ export default { processingHandler.start(); try { const cwd = props.path; - const procs = []; - procs.push(...entryRefs.value.filter(entryRef => entryRef.showEntries).map(entryRef => entryRef.getEntries())); const entryNames = await getDirListing(cwd, props.host, (message) => notifications.value.constructNotification("Failed to parse file name", message, 'error')); const tmpEntries = ( await getDirEntryObjects( @@ -157,15 +160,9 @@ export default { (message) => notifications.value.constructNotification("Failed to parse file name", message, 'error') ) ); - processingHandler.start(); - return Promise.all(procs) - .then(() => { - if (props.path !== cwd) - return; - entries.value = [...tmpEntries.sort(sortCallbackComputed.value)].map(entry => reactive(entry)); - emitStats(); - }) - .finally(() => processingHandler.stop()); + if (props.path !== cwd) + return; // changed directory before could finish + entries.value = [...tmpEntries.sort(sortCallbackComputed.value)].map(entry => reactive(entry)); } catch (error) { entries.value = []; notifications.value.constructNotification("Error getting directory entries", errorStringHTML(error), 'error'); @@ -175,30 +172,36 @@ export default { } } + const refresh = async () => { + processingHandler.start(); + await Promise.all([ + getEntries(), + ...entryRefs.value.filter(entryRef => entryRef.showEntries).map(entryRef => entryRef.refresh()) + ]); + processingHandler.stop(); + } + const emitStats = () => { - emit('updateStats', entries.value.reduce((stats, entry) => { + emit('updateStats', visibleEntries.value.reduce((stats, entry) => { if (entry.type === 'directory' || (entry.type === 'symbolic link' && entry.target?.type === 'directory')) stats.dirs++; else stats.files++; + stats.size += entry.size; return stats; - }, { files: 0, dirs: 0 })); + }, { files: 0, dirs: 0, size: 0 })); } const sortEntries = () => { - if (processingHandler.count) { - setTimeout(sortEntries, 100); // poll until nothing processing - } else { - processingHandler.start(); - entries.value = [...entries.value].sort(sortCallbackComputed.value); - processingHandler.stop(); - } + processingHandler.start(); + entries.value = [...entries.value].sort(sortCallbackComputed.value); + processingHandler.stop(); } const entryFilterCallback = (entry) => (!/^\./.test(entry.name) || settings?.directoryView?.showHidden) && (props.searchFilterRegExp?.test(entry.name) ?? true); - + const host = undefined; @@ -255,6 +258,8 @@ export default { visibleEntries.value = entries.value.filter(entryFilterCallback); }) + watch(visibleEntries, emitStats); + watch(() => props.path, (current, old) => { if (current === old) return; @@ -268,6 +273,7 @@ export default { entryRefs, selection, getEntries, + refresh, emitStats, sortEntries, entryFilterCallback, diff --git a/navigator/src/components/DirectoryView.vue b/navigator/src/components/DirectoryView.vue index b87e1c2..3e5aa14 100644 --- a/navigator/src/components/DirectoryView.vue +++ b/navigator/src/components/DirectoryView.vue @@ -147,8 +147,8 @@ export default { } const sortCallback = ref(() => 0); - const getEntries = () => { - return directoryEntryListRef.value?.getEntries?.(); + const refresh = () => { + return directoryEntryListRef.value?.refresh?.(); } const getSelected = () => directoryEntryListRef.value?.selection.getSelected?.() ?? []; @@ -172,7 +172,7 @@ export default { directoryEntryListRef, sortCallbacks, sortCallback, - getEntries, + refresh, getSelected, keyHandler, } diff --git a/navigator/src/views/Browser.vue b/navigator/src/views/Browser.vue index 4ed2498..8757d69 100644 --- a/navigator/src/views/Browser.vue +++ b/navigator/src/views/Browser.vue @@ -60,7 +60,7 @@ > - @@ -91,7 +91,7 @@ :searchFilterRegExp="searchFilterRegExp" @cd="newPath => cd(newPath)" @edit="openEditor" - @updateStats="stats => $emit('updateFooterText', `${stats.files} file${stats.files === 1 ? '' : 's'}, ${stats.dirs} director${stats.dirs === 1 ? 'y' : 'ies'}`)" + @updateStats="stats => $emit('updateFooterText', `${stats.files} file${stats.files === 1 ? '' : 's'}, ${stats.dirs} director${stats.dirs === 1 ? 'y' : 'ies'} (${cockpit.format_bytes(stats.size, 1000).replace(/(?