Skip to content

Commit

Permalink
feat: add warnings if gcodes/config root dirs don't exists (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteyou authored Aug 15, 2022
1 parent 157e099 commit 349372f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 40 deletions.
63 changes: 34 additions & 29 deletions src/components/TheTopbar.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
<style>
.topbar .v-toolbar__content {
padding-top: 0 !important;
padding-bottom: 0 !important;
}
</style>
<style scoped>
.button-min-width-auto {
min-width: auto !important;
}
.topbar .v-btn {
height: 100% !important;
max-height: none;
}
.topbar .v-btn.v-btn--icon {
width: var(--topbar-icon-btn-width) !important;
}
@media (min-width: 768px) {
header.topbar {
z-index: 8 !important;
}
}
</style>

<template>
<div>
<v-app-bar app elevate-on-scroll :height="topbarHeight" class="topbar pa-0" clipped-left>
Expand Down Expand Up @@ -67,11 +43,7 @@
<span class="d-none d-md-inline">{{ $t('App.TopBar.SAVE_CONFIG') }}</span>
</v-btn>
<v-btn
v-if="
klippyIsConnected &&
['standby', 'complete', 'cancelled'].includes(printer_state) &&
!boolHideUploadAndPrintButton
"
v-if="boolShowUploadAndPrint"
tile
:icon="$vuetify.breakpoint.smAndDown"
:text="$vuetify.breakpoint.mdAndUp"
Expand Down Expand Up @@ -248,6 +220,15 @@ export default class TheTopbar extends Mixins(BaseMixin) {
return this.$store.state.gui.uiSettings.logo
}
get boolShowUploadAndPrint() {
return (
this.klippyIsConnected &&
this.existGcodesRootDirectory &&
['standby', 'complete', 'cancelled'].includes(this.printer_state) &&
!this.boolHideUploadAndPrintButton
)
}
btnEmergencyStop() {
const confirmOnEmergencyStop = this.$store.state.gui.uiSettings.confirmOnEmergencyStop
if (confirmOnEmergencyStop) {
Expand Down Expand Up @@ -344,3 +325,27 @@ export default class TheTopbar extends Mixins(BaseMixin) {
}
}
</script>

<style>
.topbar .v-toolbar__content {
padding-top: 0 !important;
padding-bottom: 0 !important;
}
</style>
<style scoped>
.button-min-width-auto {
min-width: auto !important;
}
.topbar .v-btn {
height: 100% !important;
max-height: none;
}
.topbar .v-btn.v-btn--icon {
width: var(--topbar-icon-btn-width) !important;
}
@media (min-width: 768px) {
header.topbar {
z-index: 8 !important;
}
}
</style>
6 changes: 6 additions & 0 deletions src/components/mixins/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ export default class BaseMixin extends Vue {
get moonrakerComponents() {
return this.$store.state.server?.components ?? []
}

get existGcodesRootDirectory() {
const roots = this.$store.state.server.registered_directories

return roots.findIndex((root: string) => root === 'gcodes') >= 0
}
}
49 changes: 43 additions & 6 deletions src/components/panels/Machine/ConfigFilesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<v-select
v-model="root"
class="machine-configfiles-panel__root-select"
:items="registeredDirectories"
:items="registeredDirectoriesSelectItems"
:label="$t('Machine.ConfigFilesPanel.Root')"
outlined
hide-details
Expand Down Expand Up @@ -71,7 +71,7 @@
{{ absolutePath }}
</span>
<v-spacer></v-spacer>
<template v-if="disk_usage !== null">
<template v-if="disk_usage !== null && !showMissingConfigRootWarning">
<v-tooltip top>
<template #activator="{ on, attrs }">
<span v-bind="attrs" v-on="on">
Expand All @@ -84,7 +84,8 @@
<br />
{{ $t('Machine.ConfigFilesPanel.Free') }}: {{ formatFilesize(disk_usage.free) }}
<br />
{{ $t('Machine.ConfigFilesPanel.Total') }}: {{ formatFilesize(disk_usage.total) }}
{{ $t('Machine.ConfigFilesPanel.Total') }}:
{{ formatFilesize(disk_usage.total) }}
</span>
</v-tooltip>
</template>
Expand All @@ -93,6 +94,7 @@
</v-card-text>
<v-divider></v-divider>
<v-data-table
v-if="!showMissingConfigRootWarning"
v-model="selectedFiles"
:items="files"
class="files-table"
Expand Down Expand Up @@ -164,6 +166,22 @@
</tr>
</template>
</v-data-table>
<v-card-text v-else>
<v-row>
<v-col class="col-12 col-lg pr-lg-0">
<v-alert
dense
text
type="warning"
elevation="2"
class="mx-auto mt-6"
max-width="500"
:icon="mdiLockOutline">
{{ $t('Machine.ConfigFilesPanel.ConfigRootDirectoryDoesntExists') }}
</v-alert>
</v-col>
</v-row>
</v-card-text>
</panel>
<v-menu v-model="contextMenu.shown" :position-x="contextMenu.x" :position-y="contextMenu.y" absolute offset-y>
<v-list>
Expand Down Expand Up @@ -457,6 +475,7 @@ import {
mdiRenameBox,
mdiDelete,
mdiCloseThick,
mdiLockOutline,
} from '@mdi/js'
interface contextMenu {
Expand Down Expand Up @@ -522,6 +541,7 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
mdiRenameBox = mdiRenameBox
mdiDelete = mdiDelete
mdiCloseThick = mdiCloseThick
mdiLockOutline = mdiLockOutline
sortFiles = sortFiles
formatFilesize = formatFilesize
Expand Down Expand Up @@ -781,9 +801,26 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) {
}
get registeredDirectories() {
return this.$store.state.server.registered_directories
.filter((dir: string) => !hiddenRootDirectories.includes(dir))
.sort()
return this.$store.state.server.registered_directories ?? []
}
get existConfigRoot() {
return this.registeredDirectories.findIndex((root: string) => root === 'config') !== -1
}
get showMissingConfigRootWarning() {
return (
this.absolutePath.startsWith('/config') &&
!this.absolutePath.startsWith('/config_example') &&
!this.existConfigRoot
)
}
get registeredDirectoriesSelectItems() {
const items = this.registeredDirectories.filter((dir: string) => !hiddenRootDirectories.includes(dir)).sort()
if (!this.existConfigRoot) items.push('config')
return items
}
get root() {
Expand Down
2 changes: 2 additions & 0 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"Free": "Frei",
"FreeDisk": "Freier Speicherplatz",
"GCodeFiles": "G-Code Dateien",
"GcodesRootDirectoryDoesntExists": "Keinen G-Code Ordner gefunden. Bitte überprüfe die Option \"path\" im Abschnitt [virtual_sdcard] in der Klipper Konfiguration.",
"HiddenFiles": "Versteckte Dateien",
"LastEndTime": "Letzte Endzeit",
"LastFilamentUsed": "Letzter Filamentverbrauch",
Expand Down Expand Up @@ -363,6 +364,7 @@
"AllFiles": "Alle",
"Cancel": "Abbruch",
"ConfigFiles": "Konfigurationsdateien",
"ConfigRootDirectoryDoesntExists": "Keinen Konfigurations-Ordner gefunden. Bitte überprüfe die Option \"config_path\" im Abschnitt [file_manager] in der Moonraker Konfiguration.",
"Create": "Erstellen",
"CreateDirectory": "Verzeichnis erstellen",
"CreateFile": "Datei erstellen",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"Free": "Free",
"FreeDisk": "Free disk",
"GCodeFiles": "G-Code Files",
"GcodesRootDirectoryDoesntExists": "No G-Code directory found. Please check option \"path\" in the [virtual_sdcard] section of the Klipper configuration.",
"HiddenFiles": "Hidden files",
"LastEndTime": "Last End Time",
"LastFilamentUsed": "Last Filament Used",
Expand Down Expand Up @@ -363,6 +364,7 @@
"AllFiles": "All",
"Cancel": "Cancel",
"ConfigFiles": "Config Files",
"ConfigRootDirectoryDoesntExists": "No configuration directory found. Please check option \"config_path\" in the [file_manager] section of the Moonraker configuration.",
"Create": "Create",
"CreateDirectory": "Create Directory",
"CreateFile": "Create File",
Expand Down
10 changes: 9 additions & 1 deletion src/pages/Files.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
<template>
<v-row>
<v-row v-if="existGcodesRootDirectory">
<v-col :class="showJobQueue ? 'col-12 col-md-8 pt-0 pt-md-3 order-1 order-md-0' : 'col-12'">
<gcodefiles-panel></gcodefiles-panel>
</v-col>
<v-col v-if="showJobQueue" class="col-12 col-md-4 pb-0 pb-sm-3 order-0 order-md-1">
<jobqueue-panel></jobqueue-panel>
</v-col>
</v-row>
<v-row v-else>
<v-alert dense text type="warning" elevation="2" class="mx-auto mt-6" max-width="500" :icon="mdiLockOutline">
{{ $t('Files.GcodesRootDirectoryDoesntExists') }}
</v-alert>
</v-row>
</template>
<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import GcodefilesPanel from '@/components/panels/GcodefilesPanel.vue'
import JobqueuePanel from '@/components/panels/JobqueuePanel.vue'
import { mdiLockOutline } from '@mdi/js'
@Component({
components: { JobqueuePanel, GcodefilesPanel },
})
export default class PageFiles extends Mixins(BaseMixin) {
mdiLockOutline = mdiLockOutline
get queued_jobs() {
return this.$store.state.server.jobQueue.queued_jobs ?? []
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Heightmap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@
</v-row>
<v-row v-else>
<v-alert
border="left"
colored-border
dense
text
type="warning"
elevation="2"
class="mx-auto mt-6"
Expand Down
5 changes: 3 additions & 2 deletions src/store/files/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const getters: GetterTree<FileState, any> = {
getGcodeFiles:
(state, getters, rootState, rootGetters) =>
(path: string | null, boolShowHiddenFiles: boolean, boolShowPrintedFiles: boolean) => {
const rootGcodes = getters['getDirectory']('gcodes')
if (rootGcodes === null) return []

let baseURL = `${rootGetters['socket/getUrl']}/server/files/gcodes`
let files: FileStateFile[] = []

Expand All @@ -52,8 +55,6 @@ export const getters: GetterTree<FileState, any> = {
const directory = getters['getDirectory']('gcodes' + path)
files = directory?.childrens ?? []
} else {
const rootGcodes = getters['getDirectory']('gcodes')

const searchGcodes = (directory: FileStateFile, currentPath: string) => {
if (directory.isDirectory && directory.childrens?.length) {
directory.childrens?.forEach((file) => {
Expand Down

0 comments on commit 349372f

Please sign in to comment.