Skip to content

Commit

Permalink
feat: add warnings in the print start dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Sep 19, 2023
1 parent bad9181 commit b4ef4a6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
60 changes: 51 additions & 9 deletions src/components/dialogs/StartPrintDialogSpoolman.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
<v-divider class="mt-3 mb-0" />
<v-card-text class="py-0 px-2">
<spoolman-panel-active-spool v-if="activeSpoolId !== null" :small="true" class="my-0" />
<v-alert v-for="alert in alerts" :key="alert.text" text :color="alert.warning" class="mt-4 mx-3">
<v-alert v-for="alert in alerts" :key="alert.text" text :color="alert.color" class="mt-4 mx-3">
{{ alert.text }}
</v-alert>
<div class="text-center">
<v-btn color="primary" small class="mx-auto" @click="showChangeSpoolDialog = true">
{{ buttonText }}
</v-btn>
</div>
</v-card-text>
<v-divider class="mt-0 mb-0" />
<v-divider :class="classSecondDivider" />
<spoolman-change-spool-dialog :show-dialog="showChangeSpoolDialog" @close="showChangeSpoolDialog = false" />
</div>
</template>

Expand All @@ -23,32 +29,68 @@ import { FileStateGcodefile } from '@/store/files/types'
export default class StartPrintDialogSpoolman extends Mixins(BaseMixin) {
@Prop({ required: true }) readonly file!: FileStateGcodefile
showChangeSpoolDialog = false
get activeSpoolId() {
return this.$store.state.server.spoolman?.active_spool_id ?? null
let spoolId = this.$store.state.server.spoolman?.active_spool_id ?? null
if (spoolId === 0) spoolId = null
return spoolId
}
get activeSpool() {
return this.$store.state.server.spoolman?.active_spool ?? null
}
get classSecondDivider() {
const classes = ['mt-4']
classes.push(this.moonrakerComponents.includes('spoolman') ? 'mb-2' : 'mb-0')
return classes
}
get buttonText() {
if (this.activeSpoolId === null) return this.$t('Panels.SpoolmanPanel.SelectSpool') as string
return this.$t('Panels.SpoolmanPanel.ChangeSpool') as string
}
get alerts() {
let alerts = []
if (this.activeSpoolId === null) {
alerts.push({
text: this.$t('Dialogs.StartPrint.NoSpoolSelected'),
color: 'warning',
text: this.$t('Panels.SpoolmanPanel.NoSpoolSelected'),
color: 'orange',
})
// No need to check for filament type mismatch if no spool is selected
return alerts
}
const gcodeFilamentType = (this.file.filament_type ?? '').toLowerCase()
const gcodeFilamentType = this.file.filament_type ?? ''
if (
this.activeSpoolId !== null &&
gcodeFilamentType !== '' &&
this.activeSpool?.filament?.material?.toLowerCase() !== gcodeFilamentType
this.activeSpool?.filament?.material?.toLowerCase() !== gcodeFilamentType.toLowerCase()
) {
alerts.push({
text: this.$t('Dialogs.StartPrint.FilamentTypeMismatch'),
text: this.$t('Panels.SpoolmanPanel.FilamentTypeMismatch', {
fileType: gcodeFilamentType,
spoolType: this.activeSpool?.filament?.material,
}),
color: 'warning',
})
}
const fileWeight = Math.round(this.file.filament_weight_total ?? 0)
const spoolWeight = Math.round(this.activeSpool?.remaining_weight ?? 0)
if (spoolWeight < fileWeight) {
alerts.push({
text: this.$t('Panels.SpoolmanPanel.TooLessFilament', {
fileWeight,
spoolWeight,
}),
color: 'warning',
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"DoYouWantToStartFilename": "Do you want to start {filename}?",
"DoYouWantToStartFilenameFilament": "Do you want to start {filename} with the following filament?",
"Headline": "Start Job",
"NoSpoolSelected": "No spool selected. Please select a spool or this print will not be tracked.",
"Print": "print",
"Timelapse": "Timelapse"
}
Expand Down Expand Up @@ -629,6 +628,7 @@
"EjectSpool": "Eject spool",
"EjectSpoolQuestion": "Are you sure to eject the filament spool?",
"Filament": "Filament",
"FilamentTypeMismatch": "The material of the active spool ({spoolType}) does not match the material of the G-Code ({fileType}).",
"FirstUsedOutput": "First used: {firstUsed}",
"Headline": "Spoolman",
"LastUsed": "Last Used",
Expand All @@ -638,11 +638,13 @@
"NoActiveSpool": "Filament tracking is inactive. To get started, please select a spool.",
"NoResults": "No spool found with the current search criteria.",
"NoSpools": "No spools available",
"NoSpoolSelected": "No spool selected. Please select a spool or this print will not be tracked.",
"OpenSpoolManager": "open Spool Manager",
"Refresh": "refresh",
"Search": "Search",
"SelectSpool": "Select Spool",
"Today": "Today",
"TooLessFilament": "The current spool may not have enough filament for this print. ({spoolWeight}g of {fileWeight}g)",
"Weight": "Weight",
"Yesterday": "Yesterday"
},
Expand Down

0 comments on commit b4ef4a6

Please sign in to comment.