Skip to content

Commit

Permalink
feat(FileSystem): bulk metadata or analysis refresh
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Feb 15, 2025
1 parent 8a92068 commit 086d3fb
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 29 deletions.
16 changes: 11 additions & 5 deletions src/api/socketActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,23 +573,27 @@ export const SocketActions = {
* Expects the full path including root.
* Optionally pass the just the filename and path.
*/
async serverFilesMetadata (filepath: string) {
async serverFilesMetadata (filename: string) {
const wait = `${Waits.onFileSystem}/gcodes/${filename}`
baseEmit(
'server.files.metadata', {
dispatch: 'files/onFileMetaData',
wait,
params: {
filename: filepath
filename
}
}
)
},

async serverFilesMetascan (filepath: string) {
async serverFilesMetascan (filename: string) {
const wait = `${Waits.onFileSystem}/gcodes/${filename}`
baseEmit(
'server.files.metascan', {
dispatch: 'files/onFileMetaData',
wait,
params: {
filename: filepath
filename
}
}
)
Expand Down Expand Up @@ -689,7 +693,7 @@ export const SocketActions = {
},

async serverFilesDeleteFile (path: string) {
const wait = `${Waits.onFileSystem}/${path}/`
const wait = `${Waits.onFileSystem}/${path}`
baseEmit(
'server.files.delete_file', {
dispatch: 'void',
Expand Down Expand Up @@ -789,13 +793,15 @@ export const SocketActions = {
},

async serverAnalysisEstimate (filename: string, estimator_config?: string, update_metadata?: boolean) {
const wait = `${Waits.onFileSystem}/gcodes/${filename}`
baseEmit(
'server.analysis.estimate', {
params: {
filename,
estimator_config,
update_metadata
},
wait,
dispatch: 'analysis/onAnalysisEstimate'
}
)
Expand Down
52 changes: 37 additions & 15 deletions src/components/widgets/filesystem/FileSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
v-if="selected.length > 0"
:root="currentRoot"
:path="visiblePath"
@remove="handleRemove(selected)"
@create-zip="handleCreateZip(selected)"
@enqueue="handleEnqueue(selected)"
:selected="selected"
@remove="handleRemove"
@create-zip="handleCreateZip"
@refresh-metadata="handleRefreshMetadata"
@perform-time-analysis="handlePerformTimeAnalysis"
@enqueue="handleEnqueue"
/>

<file-system-browser
Expand Down Expand Up @@ -797,16 +800,32 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
}
}
handleRefreshMetadata (file: AppFileWithMeta) {
const filename = file.path ? `${file.path}/${file.filename}` : file.filename
handleRefreshMetadata (file: FileBrowserEntry | FileBrowserEntry[]) {
if (this.disabled) return
const files = Array.isArray(file)
? file
: [file]
const filenames = files
.filter((item): item is AppFileWithMeta => item.type === 'file' && this.rootProperties.accepts.includes(item.extension))
.map(file => file.path ? `${file.path}/${file.filename}` : file.filename)
SocketActions.serverFilesMetadata(filename)
for (const filename of filenames) {
SocketActions.serverFilesMetascan(filename)
}
}
handlePerformTimeAnalysis (file: AppFileWithMeta) {
const filename = file.path ? `${file.path}/${file.filename}` : file.filename
handlePerformTimeAnalysis (file: FileBrowserEntry | FileBrowserEntry[]) {
const items = Array.isArray(file)
? file
: [file]
const filenames = items
.filter((item): item is AppFileWithMeta => item.type === 'file' && this.rootProperties.accepts.includes(item.extension))
.map(file => file.path ? `${file.path}/${file.filename}` : file.filename)
SocketActions.serverAnalysisEstimate(filename, undefined, true)
for (const filename of filenames) {
SocketActions.serverAnalysisEstimate(filename, undefined, true)
}
}
async handleViewThumbnail (file: AppFileWithMeta) {
Expand Down Expand Up @@ -887,13 +906,13 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
this.includeTimelapseThumbnailFiles(items)
}
items.forEach((item) => {
for (const item of items) {
const src = `${this.currentPath}/${item.name}`
const dest = destinationPath
? `${destinationPath}/${item.name}`
: `${item.name}`
SocketActions.serverFilesMove(src, dest)
})
}
}
handleDragStart (item: FileBrowserEntry, items: FileBrowserEntry[], dataTransfer: DataTransfer) {
Expand Down Expand Up @@ -954,10 +973,13 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
this.includeTimelapseThumbnailFiles(items)
}
items.forEach((item) => {
if (item.type === 'directory') SocketActions.serverFilesDeleteDirectory(`${this.currentPath}/${item.dirname}`, true)
if (item.type === 'file') SocketActions.serverFilesDeleteFile(`${this.currentPath}/${item.filename}`)
})
for (const item of items) {
if (item.type === 'file') {
SocketActions.serverFilesDeleteFile(`${this.currentPath}/${item.filename}`)
} else {
SocketActions.serverFilesDeleteDirectory(`${this.currentPath}/${item.dirname}`, true)
}
}
}
}
Expand Down
103 changes: 98 additions & 5 deletions src/components/widgets/filesystem/FileSystemBulkActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<v-spacer />

<v-tooltip
v-if="root === 'gcodes'"
v-if="canAddToQueue"
bottom
>
<template #activator="{ on, attrs }">
Expand All @@ -20,7 +20,7 @@
icon
text
v-on="on"
@click="$emit('enqueue')"
@click="$emit('enqueue', selected)"
>
<v-icon>
$enqueueJob
Expand All @@ -30,14 +30,57 @@
<span>{{ $t('app.general.btn.add_to_queue') }}</span>
</v-tooltip>

<v-tooltip bottom>
<v-tooltip
v-if="canRefreshMetadata"
bottom
>
<template #activator="{ on, attrs }">
<app-btn
v-bind="attrs"
icon
text
v-on="on"
@click="$emit('refresh-metadata', selected)"
>
<v-icon>
$sync
</v-icon>
</app-btn>
</template>
<span>{{ $t('app.general.btn.refresh_metadata') }}</span>
</v-tooltip>

<v-tooltip
v-if="canPerformTimeAnalysys"
bottom
>
<template #activator="{ on, attrs }">
<app-btn
v-bind="attrs"
icon
text
v-on="on"
@click="$emit('create-zip')"
@click="$emit('perform-time-analysis', selected)"
>
<v-icon>
$stopwatch
</v-icon>
</app-btn>
</template>
<span>{{ $t('app.general.btn.perform_time_analysis') }}</span>
</v-tooltip>

<v-tooltip
v-if="canCreateZip"
bottom
>
<template #activator="{ on, attrs }">
<app-btn
v-bind="attrs"
icon
text
v-on="on"
@click="$emit('create-zip', selected)"
>
<v-icon>
$fileZipAdd
Expand All @@ -54,7 +97,7 @@
icon
text
v-on="on"
@click="$emit('remove')"
@click="$emit('remove', selected)"
>
<v-icon>
$delete
Expand All @@ -69,6 +112,7 @@
<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StatesMixin from '@/mixins/state'
import type { FileBrowserEntry, RootProperties } from '@/store/files/types'
@Component({})
export default class FileSystemBulkActions extends Mixins(StatesMixin) {
Expand All @@ -78,5 +122,54 @@ export default class FileSystemBulkActions extends Mixins(StatesMixin) {
// The current path
@Prop({ type: String })
readonly path!: string
@Prop({ type: [Object, Array], required: true })
readonly selected!: FileBrowserEntry[]
get rootProperties (): RootProperties {
return this.$store.getters['files/getRootProperties'](this.root)
}
get canCreateZip (): boolean {
return (
(
this.selected.length > 1 ||
this.selected[0].type !== 'file' ||
this.selected[0].extension !== '.zip'
) &&
!this.rootProperties.readonly &&
this.$store.getters['server/getIsMinApiVersion']('1.1.0')
)
}
get isGcodesRootWithAcceptedFiles () {
return (
this.root === 'gcodes' &&
this.selected.some(x =>
x.type !== 'directory' &&
this.rootProperties.accepts.includes(x.extension)
)
)
}
get canAddToQueue (): boolean {
return (
this.isGcodesRootWithAcceptedFiles &&
this.$store.getters['server/componentSupport']('job_queue')
)
}
get canRefreshMetadata (): boolean {
return (
this.isGcodesRootWithAcceptedFiles
)
}
get canPerformTimeAnalysys (): boolean {
return (
this.isGcodesRootWithAcceptedFiles &&
this.$store.getters['server/componentSupport']('analysis')
)
}
}
</script>
20 changes: 16 additions & 4 deletions src/components/widgets/filesystem/FileSystemContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</v-list-item>

<v-list-item
v-if="canPrint"
v-if="canRefreshMetadata"
@click="$emit('refresh-metadata', file)"
>
<v-list-item-icon>
Expand Down Expand Up @@ -301,22 +301,34 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
)
}
get canAddToQueue (): boolean {
get isGcodesRootWithAcceptedFiles () {
const files = Array.isArray(this.file) ? this.file : [this.file]
return (
this.root === 'gcodes' &&
files.some(x =>
x.type !== 'directory' &&
this.rootProperties.accepts.includes(x.extension)
) &&
)
)
}
get canAddToQueue (): boolean {
return (
this.isGcodesRootWithAcceptedFiles &&
this.$store.getters['server/componentSupport']('job_queue')
)
}
get canRefreshMetadata (): boolean {
return (
this.isGcodesRootWithAcceptedFiles
)
}
get canPerformTimeAnalysys (): boolean {
return (
this.canPrint &&
this.isGcodesRootWithAcceptedFiles &&
this.$store.getters['server/componentSupport']('analysis')
)
}
Expand Down

0 comments on commit 086d3fb

Please sign in to comment.