Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/store/files/getters.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue'
import type { GetterTree } from 'vuex'
import type { AppDirectory, AppFile, AppFileMeta, AppFileWithMeta, FileBrowserEntry, FilesState, MoonrakerFileMeta, RootProperties } from './types'
import type { AppDirectory, AppFile, AppFileMeta, AppFileWithMeta, FileBrowserEntry, FilesState, RootProperties } from './types'
import type { RootState } from '../types'
import type { HistoryItem } from '../history/types'
import { SupportedImageFormats, SupportedMarkdownFormats, SupportedVideoFormats } from '@/globals'
Expand All @@ -16,9 +16,9 @@ export const getters: GetterTree<FilesState, RootState> = {
const items: FileBrowserEntry[] = []

const [root, ...restOfPath] = path.split('/')
const pathNoRoot = restOfPath.join('/')
const pathFilename = restOfPath.join('/')

if (pathNoRoot !== '') {
if (pathFilename !== '') {
const item: AppDirectory = {
type: 'directory',
name: '..',
Expand Down Expand Up @@ -91,7 +91,7 @@ export const getters: GetterTree<FilesState, RootState> = {
type: 'file',
name: file.filename,
extension,
path: pathNoRoot,
path: pathFilename,
modified: new Date(file.modified).getTime()
}

Expand Down Expand Up @@ -192,16 +192,24 @@ export const getters: GetterTree<FilesState, RootState> = {
const file = pathContent?.files.find(file => file.filename === filename)

if (file) {
const metadata: Partial<MoonrakerFileMeta> & Pick<AppFileWithMeta, 'history'> = {}
const metadata: Partial<AppFileMeta> & Pick<AppFileWithMeta, 'history'> = {}

if ('job_id' in file && file.job_id) {
const history: HistoryItem | undefined = rootGetters['history/getHistoryById'](file.job_id)

metadata.history = history
}

if ('filament_name' in file && file.filament_name) {
metadata.filament_name = Vue.$filters.getStringArray(file.filament_name)
}

if ('filament_type' in file && file.filament_type) {
metadata.filament_type = Vue.$filters.getStringArray(file.filament_type)
}

const [, ...restOfPath] = path.split('/')
const pathNoRoot = restOfPath.join('/')
const pathFilename = restOfPath.join('/')

const extensionIndex = filename.lastIndexOf('.')
const extension = extensionIndex > -1 ? filename.substring(extensionIndex) : ''
Expand All @@ -212,7 +220,7 @@ export const getters: GetterTree<FilesState, RootState> = {
type: 'file',
name: file.filename,
extension,
path: pathNoRoot,
path: pathFilename,
modified: new Date(file.modified).getDate()
}

Expand Down