refactor: use getter getDirectory in gcode files
Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
1 parent
8ed9f33dc0
commit
adf31153eb
5 files changed
+44
-67
No files matched your search
@@ -564,7 +564,6 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
|
||||
this.dialogImage.item.url = url
|
||||
}
|
||||
} else {
|
||||
window.console.log('openFile', item)
|
||||
this.$store.dispatch('editor/openFile', {
|
||||
root: this.root,
|
||||
path: this.currentPath,
|
||||
|
||||
+29
-51
@@ -351,7 +351,7 @@ import {Component, Mixins, Watch} from 'vue-property-decorator'
|
||||
import BaseMixin from '@/components/mixins/base'
|
||||
import axios from 'axios'
|
||||
import { validGcodeExtensions } from '@/store/variables'
|
||||
import {findDirectory, formatFilesize, formatDate, sortFiles} from '@/plugins/helpers'
|
||||
import {formatFilesize, formatDate, sortFiles} from '@/plugins/helpers'
|
||||
import {FileStateFile} from '@/store/files/types'
|
||||
import Panel from '@/components/ui/Panel.vue'
|
||||
|
||||
@@ -403,7 +403,6 @@ export default class PageFiles extends Mixins(BaseMixin) {
|
||||
}
|
||||
|
||||
private search = ''
|
||||
private files: FileStateFile[] | null = []
|
||||
private selected = []
|
||||
private hideHeaderColums = []
|
||||
private currentPath = 'gcodes'
|
||||
@@ -519,8 +518,34 @@ export default class PageFiles extends Mixins(BaseMixin) {
|
||||
return headers
|
||||
}
|
||||
|
||||
get filetree() {
|
||||
return this.$store.state.files.filetree ?? []
|
||||
get directory() {
|
||||
return this.$store.getters['files/getDirectory'](this.currentPath)
|
||||
}
|
||||
|
||||
get disk_usage() {
|
||||
return this.directory?.disk_usage ?? { used: 0, free: 0, total: 0}
|
||||
}
|
||||
|
||||
get files() {
|
||||
let files = [...this.directory?.childrens ?? []]
|
||||
|
||||
if (!this.showHiddenFiles) {
|
||||
files = files.filter(file => file.filename !== 'thumbs' && file.filename.substr(0, 1) !== '.')
|
||||
}
|
||||
|
||||
if (!this.showPrintedFiles) {
|
||||
files = files.filter(file => {
|
||||
if (file.isDirectory) return true
|
||||
else {
|
||||
return (this.$store.getters['server/history/getPrintStatusByFilename'](
|
||||
(this.currentPath+'/'+file.filename).substr(7),
|
||||
file.modified.getTime()
|
||||
) !== 'completed')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
get configHeaders() {
|
||||
@@ -555,10 +580,6 @@ export default class PageFiles extends Mixins(BaseMixin) {
|
||||
this.$store.dispatch('gui/saveSetting', { name: 'gcodefiles.showPrintedFiles', value: newVal })
|
||||
}
|
||||
|
||||
get disk_usage() {
|
||||
return this.$store.getters['files/getDiskUsage'](this.currentPath)
|
||||
}
|
||||
|
||||
get sortBy() {
|
||||
return this.$store.state.gui.gcodefiles.sortBy
|
||||
}
|
||||
@@ -787,38 +808,6 @@ export default class PageFiles extends Mixins(BaseMixin) {
|
||||
|
||||
created() {
|
||||
this.$socket.emit('server.files.get_directory', { path: this.currentPath }, { action: 'files/getDirectory' })
|
||||
this.loadPath()
|
||||
}
|
||||
|
||||
loadPath() {
|
||||
let dirArray = this.currentPath.split('/')
|
||||
this.files = findDirectory(this.filetree, dirArray)
|
||||
if (this.files !== null) {
|
||||
if (!this.showHiddenFiles) {
|
||||
this.files = this.files.filter(file => file.filename !== 'thumbs' && file.filename.substr(0, 1) !== '.')
|
||||
}
|
||||
if (!this.showPrintedFiles) {
|
||||
this.files = this.files.filter(file => {
|
||||
if (file.isDirectory) return true
|
||||
else {
|
||||
return (this.$store.getters['server/history/getPrintStatusByFilename'](
|
||||
(this.currentPath+'/'+file.filename).substr(7),
|
||||
file.modified.getTime()
|
||||
) !== 'completed')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Watch('filetree', { deep: true })
|
||||
filetreeChanged() {
|
||||
this.loadPath()
|
||||
}
|
||||
|
||||
@Watch('currentPath')
|
||||
currentPathChanged() {
|
||||
this.loadPath()
|
||||
}
|
||||
|
||||
formatPrintTime(totalSeconds: number) {
|
||||
@@ -890,7 +879,6 @@ export default class PageFiles extends Mixins(BaseMixin) {
|
||||
this.dialogPrintFile.item = item
|
||||
} else {
|
||||
this.currentPath += '/' + item.filename
|
||||
this.loadPath()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1034,16 +1022,6 @@ export default class PageFiles extends Mixins(BaseMixin) {
|
||||
}
|
||||
}
|
||||
|
||||
@Watch('showHiddenFiles')
|
||||
showHiddenFilesChanged() {
|
||||
this.loadPath()
|
||||
}
|
||||
|
||||
@Watch('showPrintedFiles')
|
||||
showPrintedFilesChanged() {
|
||||
this.loadPath()
|
||||
}
|
||||
|
||||
@Watch('hideMetadataColums')
|
||||
hideMetadataColumsCanged(newVal: string[]) {
|
||||
newVal.forEach((key) => {
|
||||
|
||||
@@ -29,10 +29,10 @@ export const actions: ActionTree<FileState, RootState> = {
|
||||
})
|
||||
},
|
||||
|
||||
getDirectory({ state, commit }, payload: ApiGetDirectoryReturn) {
|
||||
getDirectory({ state, commit, getters }, payload: ApiGetDirectoryReturn) {
|
||||
let root = ''
|
||||
let path = ''
|
||||
let parent: FileStateFile[] | null = state.filetree
|
||||
let directory: FileStateFile | null
|
||||
|
||||
if (payload.requestParams?.path) {
|
||||
const pathArray = payload.requestParams.path.split('/')
|
||||
@@ -40,11 +40,12 @@ export const actions: ActionTree<FileState, RootState> = {
|
||||
|
||||
const slashIndex = payload.requestParams.path.indexOf('/')
|
||||
path = slashIndex > 1 ? payload.requestParams.path.substr( slashIndex+ 1) : ''
|
||||
parent = findDirectory(state.filetree, pathArray)
|
||||
|
||||
directory = getters['getDirectory'](path)
|
||||
}
|
||||
|
||||
if (parent?.length) {
|
||||
parent?.forEach((item: FileStateFile) => {
|
||||
if (directory?.childrens?.length) {
|
||||
directory?.childrens.forEach((item: FileStateFile) => {
|
||||
if (item?.isDirectory && payload.dirs?.findIndex((element: ApiGetDirectoryReturnDir) => element.dirname === item.filename) < 0)
|
||||
commit('setDeleteDir', {
|
||||
item: {
|
||||
@@ -62,9 +63,9 @@ export const actions: ActionTree<FileState, RootState> = {
|
||||
})
|
||||
}
|
||||
|
||||
if (parent && payload.dirs?.length) {
|
||||
if (directory && payload.dirs?.length) {
|
||||
payload.dirs.forEach((dir: ApiGetDirectoryReturnDir) => {
|
||||
if (!parent?.find((element: FileStateFile) => (element.isDirectory && element.filename === dir.dirname))) {
|
||||
if (!directory?.childrens?.find((element: FileStateFile) => (element.isDirectory && element.filename === dir.dirname))) {
|
||||
commit('setCreateDir', {
|
||||
item: {
|
||||
path: path.length ? path+'/'+dir.dirname : dir.dirname,
|
||||
@@ -81,7 +82,7 @@ export const actions: ActionTree<FileState, RootState> = {
|
||||
|
||||
if (payload.files?.length) {
|
||||
payload.files.forEach((file: ApiGetDirectoryReturnFile) => {
|
||||
const existingFile = parent?.find((element: FileStateFile) => (!element.isDirectory && element.filename === file.filename))
|
||||
const existingFile = directory?.childrens?.find((element: FileStateFile) => (!element.isDirectory && element.filename === file.filename))
|
||||
|
||||
if (existingFile && (
|
||||
existingFile.size !== file.size ||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { findDirectory } from '@/plugins/helpers'
|
||||
import { themeDir } from '@/store/variables'
|
||||
import {GetterTree} from 'vuex'
|
||||
import {FileState, FileStateFile} from '@/store/files/types'
|
||||
@@ -26,9 +25,9 @@ export const getters: GetterTree<FileState, any> = {
|
||||
},
|
||||
|
||||
getThemeFileUrl: (state, getters, rootState, rootGetters) => (acceptName: string, acceptExtensions: string[]) => {
|
||||
const directory = findDirectory(state.filetree, ['config', themeDir])
|
||||
const directory = getters['getDirectory']('config/'+themeDir)
|
||||
|
||||
const file = directory?.find((element: FileStateFile) =>
|
||||
const file = directory?.childrens?.find((element: FileStateFile) =>
|
||||
element.filename !== undefined && (
|
||||
element.filename.substr(0, element.filename.lastIndexOf('.')) === acceptName &&
|
||||
acceptExtensions.includes(element.filename.substr(element.filename.lastIndexOf('.')+1))
|
||||
@@ -90,10 +89,10 @@ export const getters: GetterTree<FileState, any> = {
|
||||
return null
|
||||
},
|
||||
|
||||
checkConfigFile: (state) => (acceptName: string) => {
|
||||
const directory = findDirectory(state.filetree, ['config'])
|
||||
checkConfigFile: (state, getters) => (acceptName: string) => {
|
||||
const directory = getters['getDirectory']('config')
|
||||
|
||||
return directory?.findIndex((element: FileStateFile) =>
|
||||
return directory?.childrens?.findIndex((element: FileStateFile) =>
|
||||
element.filename !== undefined && element.filename === acceptName
|
||||
) !== -1
|
||||
},
|
||||
|
||||
@@ -35,7 +35,7 @@ export const mutations: MutationTree<FileState> = {
|
||||
const path = findDirectory(state.filetree, dirArray)
|
||||
|
||||
const fileIndex = path?.findIndex((element: FileStateFile) => element.filename === filename)
|
||||
if (path && fileIndex && fileIndex !== -1) {
|
||||
if (path && fileIndex !== -1) {
|
||||
// eslint-disable-next-line
|
||||
const currentFile = path[fileIndex] as any
|
||||
allowedMetadata.forEach((key: string) => {
|
||||
|
||||
Reference in new issue
Block a user