Skip to content

Commit

Permalink
feat: adds Go To File dialog (#1077)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas authored Mar 27, 2023
1 parent fa56a5b commit a6ff766
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 37 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ declare module 'vue' {
VToolbarItems: typeof import('vuetify/lib')['VToolbarItems']
VToolbarTitle: typeof import('vuetify/lib')['VToolbarTitle']
VTooltip: typeof import('vuetify/lib')['VTooltip']
VVirtualScroll: typeof import('vuetify/lib')['VVirtualScroll']
}
}
19 changes: 16 additions & 3 deletions src/components/widgets/filesystem/FileSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@add-dir="handleAddDirDialog"
@upload="handleUpload"
@filter="handleFilter"
@go-to-file="handleGoToFileDialog"
/>

<file-system-bulk-actions
Expand Down Expand Up @@ -120,9 +121,12 @@
@remove="handleRemove"
/>

<!-- <pre>roots: {{ availableRoots }}</pre>
<pre>currentRoot: {{ currentRoot }}<br />currentPath: {{ currentPath }}<br />visiblePath: {{ visiblePath }}</pre>
<pre>dragState: {{ dragState }}</pre> -->
<file-system-go-to-file-dialog
v-if="goToFileDialogOpen"
v-model="goToFileDialogOpen"
:root="currentRoot"
@path-change="loadFiles"
/>
</v-card>
</template>

Expand All @@ -149,6 +153,7 @@ import FileSystemContextMenu from './FileSystemContextMenu.vue'
import FileEditorDialog from './FileEditorDialog.vue'
import FileNameDialog from './FileNameDialog.vue'
import FileSystemUploadDialog from './FileSystemUploadDialog.vue'
import FileSystemGoToFileDialog from './FileSystemGoToFileDialog.vue'
import FilePreviewDialog from './FilePreviewDialog.vue'
import { AppTableHeader } from '@/types'
import { FileWithPath, getFilesFromDataTransfer } from '@/util/file-system-entry'
Expand All @@ -168,6 +173,7 @@ import { FileWithPath, getFilesFromDataTransfer } from '@/util/file-system-entry
FileEditorDialog,
FileNameDialog,
FileSystemUploadDialog,
FileSystemGoToFileDialog,
FilePreviewDialog
}
})
Expand Down Expand Up @@ -259,6 +265,8 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
src: ''
}
goToFileDialogOpen = false
@Watch('filePreviewState.open')
onFilePreviewStateChanged (value: boolean) {
if (!value && this.filePreviewState.src.startsWith('blob:')) {
Expand Down Expand Up @@ -626,6 +634,11 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
}
}
handleGoToFileDialog () {
if (this.disabled) return
this.goToFileDialogOpen = true
}
handleFileOpenDialog (file: AppFile) {
if (this.currentRoot === 'timelapse' && file.extension === 'zip') {
// don't download zipped frames before opening preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import { getFilesWithPathFromHTMLInputElement } from '@/util/file-system-entry'
import { Component, Vue, Prop, Ref } from 'vue-property-decorator'
@Component({})
export default class FileSystemMenu extends Vue {
export default class FileSystemAddMenu extends Vue {
@Prop({ type: String, required: true })
readonly root!: string
Expand Down
9 changes: 1 addition & 8 deletions src/components/widgets/filesystem/FileSystemBulkActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,8 @@
<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StatesMixin from '@/mixins/state'
import FileSystemMenu from './FileSystemMenu.vue'
import FileSystemFilterMenu from './FileSystemFilterMenu.vue'
@Component({
components: {
FileSystemMenu,
FileSystemFilterMenu
}
})
@Component({})
export default class FileSystemBulkActions extends Mixins(StatesMixin) {
@Prop({ type: String, required: true })
readonly root!: string
Expand Down
120 changes: 120 additions & 0 deletions src/components/widgets/filesystem/FileSystemGoToFileDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<app-dialog
v-model="open"
:title="$t('app.file_system.title.go_to_file')"
no-actions
max-width="800"
>
<v-card-actions>
<v-text-field
v-model="search"
:loading="loading"
outlined
hide-details
dense
autofocus
class="mx-2"
/>
</v-card-actions>

<v-divider />

<v-virtual-scroll
:items="matchedFiles"
bench="30"
item-height="40"
>
<template #default="{ item }">
<v-list-item
:key="item.path"
dense
class="v-list-item--link"
@click="handleFileClick(item)"
>
<v-list-item-content>
<v-list-item-title class="text-body-2 font-weight-regular">
{{ item.path }}
</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-divider />
</template>
</v-virtual-scroll>
</app-dialog>
</template>

<script lang="ts">
import { Component, Mixins, Prop, VModel, Watch } from 'vue-property-decorator'
import { SocketActions } from '@/api/socketActions'
import { RootFile } from '@/store/files/types'
import getFilePaths from '@/util/get-file-paths'
import StateMixin from '@/mixins/state'
type File = RootFile &{
filename: string
filepath: string
rootPath: string
}
@Component({})
export default class FileSystemGoToFileDialog extends Mixins(StateMixin) {
@VModel({ type: Boolean, required: true })
open!: boolean
@Prop({ type: String, required: true })
readonly root!: string
search = ''
loaded = false
get rootFiles (): RootFile[] {
return this.$store.getters['files/getRootFiles'](this.root) as RootFile[]
}
get matchedFiles (): File[] {
if (!this.loaded) {
return []
}
const search = this.search
.split('')
.join('.*')
const searchRegExp = new RegExp(search, 'i')
return this.rootFiles
.filter(rootFile => searchRegExp.exec(rootFile.path))
.map(rootFile => {
const { filename, rootPath, path: filepath } = getFilePaths(rootFile.path, this.root)
const file: File = ({
...rootFile,
filename,
filepath,
rootPath
})
return file
})
}
get loading (): boolean {
return this.hasWait(`${this.$waits.onFileSystem}${this.root}`) as boolean
}
@Watch('loading')
onLoading (value: boolean) {
this.loaded = !value
}
handleFileClick (file: File) {
this.$emit('path-change', file.rootPath)
this.open = false
}
mounted () {
this.loaded = false
SocketActions.serverFilesListRoot(this.root)
}
}
</script>
59 changes: 40 additions & 19 deletions src/components/widgets/filesystem/FileSystemToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,33 @@
:headers="headers"
/>

<div>
<v-tooltip bottom>
<template #activator="{ on, attrs }">
<v-btn
v-bind="attrs"
:disabled="disabled"
fab
small
text
@click="$emit('go-to-file')"
v-on="on"
>
<v-icon>$magnify</v-icon>
</v-btn>
</template>
<span>{{ $t('app.general.btn.go_to_file') }}</span>
</v-tooltip>
</div>

<file-system-filter-menu
v-if="hasFilterTypes"
:root="root"
:disabled="disabled"
@change="$emit('filter', $event)"
/>

<file-system-menu
<file-system-add-menu
v-if="!readonly || canCreateDirectory"
:root="root"
:disabled="disabled"
Expand All @@ -96,22 +115,24 @@
@upload="handleUpload"
/>

<v-tooltip bottom>
<template #activator="{ on, attrs }">
<v-btn
v-bind="attrs"
:disabled="disabled"
fab
small
text
@click="$emit('refresh')"
v-on="on"
>
<v-icon>$refresh</v-icon>
</v-btn>
</template>
<span>{{ $t('app.general.btn.refresh') }}</span>
</v-tooltip>
<div>
<v-tooltip bottom>
<template #activator="{ on, attrs }">
<v-btn
v-bind="attrs"
:disabled="disabled"
fab
small
text
@click="$emit('refresh')"
v-on="on"
>
<v-icon>$refresh</v-icon>
</v-btn>
</template>
<span>{{ $t('app.general.btn.refresh') }}</span>
</v-tooltip>
</div>

<div
style="max-width: 160px;"
Expand Down Expand Up @@ -149,13 +170,13 @@
<script lang="ts">
import { Component, Prop, Mixins } from 'vue-property-decorator'
import StatesMixin from '@/mixins/state'
import FileSystemMenu from './FileSystemMenu.vue'
import FileSystemAddMenu from './FileSystemAddMenu.vue'
import FileSystemFilterMenu from './FileSystemFilterMenu.vue'
import { AppTableHeader } from '@/types'
@Component({
components: {
FileSystemMenu,
FileSystemAddMenu,
FileSystemFilterMenu
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ app:
add_file: Add File
command_palette: Command Palette
download_file: Retrieving file
go_to_file: Go to file
rename_dir: Rename Directory
rename_file: Rename File
upload_file: Uploading file | Uploading files
Expand Down Expand Up @@ -155,6 +156,7 @@ app:
extrude: Extrude
filter: Filter
forgot_password: Forgotten your password?
go_to_file: Go to file
heaters_off: Heaters off
job_queue: Job Queue
load_all: Load all
Expand Down
12 changes: 6 additions & 6 deletions src/mixins/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ export default class StateMixin extends Vue {
* Indicates if we have a valid wait(s).
* Supports a single string or a list of.
*/
hasWait (wait: string | string[]) {
return this.$store.getters['wait/hasWait'](wait)
hasWait (wait: string | string[]): boolean {
return this.$store.getters['wait/hasWait'](wait) as boolean
}

/**
* Indicates if we have any waits.
*/
get hasWaits () {
return this.$store.getters['wait/hasWaits']
get hasWaits (): boolean {
return this.$store.getters['wait/hasWaits'] as boolean
}

/**
* Indicates if we have any waits prefixed by.
*/
hasWaitsBy (prefix: string) {
return this.$store.getters['wait/hasWaitsBy'](prefix)
hasWaitsBy (prefix: string): boolean {
return this.$store.getters['wait/hasWaitsBy'](prefix) as boolean
}

/**
Expand Down

0 comments on commit a6ff766

Please sign in to comment.