Skip to content

Commit

Permalink
feat(Temperatures): add context menu to enter the Settings & turn off…
Browse files Browse the repository at this point in the history
… heaters

Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Dec 29, 2024
1 parent 976547e commit 248112f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
70 changes: 67 additions & 3 deletions src/components/panels/Temperature/TemperaturePanelListItem.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<tr>
<tr v-longpress:600="(e) => openContentMenu(e)" @contextmenu.prevent="openContentMenu($event)">
<td class="icon">
<v-icon :color="iconColor" :class="iconClass" tabindex="-1" @click="showEditDialog = true">
<v-icon :color="iconColor" :class="iconClass" tabindex="-1" @click="openEditDialog">
{{ icon }}
</v-icon>
</td>
<td class="name">
<span class="cursor-pointer" @click="showEditDialog = true">{{ formatName }}</span>
<span class="cursor-pointer" @click="openEditDialog">{{ formatName }}</span>
</td>
<td v-if="!isResponsiveMobile" class="state">
<v-tooltip v-if="state !== null" top>
Expand Down Expand Up @@ -57,6 +57,18 @@
:icon="icon"
:color="color"
@close-dialog="showEditDialog = false" />
<v-menu v-model="showContextMenu" :position-x="contextMenuX" :position-y="contextMenuY" absolute offset-y>
<v-list>
<v-list-item v-if="isHeater" :disabled="!isHeaterActive" @click="turnOffHeater">
<v-icon left>{{ mdiSnowflake }}</v-icon>
{{ $t('Panels.TemperaturePanel.TurnHeaterOff') }}
</v-list-item>
<v-list-item @click="openEditDialog">
<v-icon left>{{ mdiCog }}</v-icon>
{{ $t('Panels.TemperaturePanel.Settings') }}
</v-list-item>
</v-list>
</v-menu>
</tr>
</template>

Expand All @@ -66,23 +78,32 @@ import { Mixins, Prop } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { convertName } from '@/plugins/helpers'
import {
mdiCog,
mdiFan,
mdiFire,
mdiMemory,
mdiPrinter3dNozzle,
mdiPrinter3dNozzleAlert,
mdiRadiator,
mdiRadiatorDisabled,
mdiSnowflake,
mdiThermometer,
} from '@mdi/js'
import { additionalSensors, opacityHeaterActive, opacityHeaterInactive } from '@/store/variables'
import { EventBus } from '@/plugins/eventBus'
@Component
export default class TemperaturePanelListItem extends Mixins(BaseMixin) {
mdiCog = mdiCog
mdiSnowflake = mdiSnowflake
@Prop({ type: String, required: true }) readonly objectName!: string
@Prop({ type: Boolean, required: true }) readonly isResponsiveMobile!: boolean
showEditDialog = false
showContextMenu = false
contextMenuX = 0
contextMenuY = 0
get printerObject() {
if (!(this.objectName in this.$store.state.printer)) return {}
Expand Down Expand Up @@ -270,6 +291,49 @@ export default class TemperaturePanelListItem extends Mixins(BaseMixin) {
return ''
}
get availableHeaters() {
return this.$store.state.printer.heaters?.available_heaters ?? []
}
get isHeater() {
return this.availableHeaters.includes(this.objectName)
}
get isHeaterActive() {
return this.target > 0
}
mounted() {
EventBus.$on('close-temperature-context-menu', this.closeContextMenu)
}
beforeDestroy() {
EventBus.$off('close-temperature-context-menu', this.closeContextMenu)
}
openContentMenu(event: MouseEvent) {
EventBus.$emit('close-temperature-context-menu')
this.showContextMenu = true
this.contextMenuX = event?.clientX || event?.pageX || window.screenX / 2
this.contextMenuY = event?.clientY || event?.pageY || window.screenY / 2
}
closeContextMenu() {
this.showContextMenu = false
}
openEditDialog() {
this.closeContextMenu()
this.showEditDialog = true
}
turnOffHeater() {
const gcode = `SET_HEATER_TEMPERATURE HEATER=${this.name} TARGET=0`
this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' })
this.$socket.emit('printer.gcode.script', { script: gcode })
}
}
</script>

Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@
"Min": "min",
"Name": "Name",
"Presets": "Presets",
"Settings": "Settings",
"SetupTemperatures": "Setup Temperatures",
"ShowChart": "Show Chart",
"ShowNameInChart": "Show {name} in chart",
Expand All @@ -807,7 +808,8 @@
"Target": "Target",
"TemperaturesInChart": "Temperature [°C]",
"TempTooHigh": "Temperature too high for {name}! (max: {max})",
"TempTooLow": "Temperature too low for {name}! (min: {min})"
"TempTooLow": "Temperature too low for {name}! (min: {min})",
"TurnHeaterOff": "Turn Heater Off"
},
"ToolheadControlPanel": {
"Absolute": "absolute",
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/eventBus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Vue from 'vue'
export const EventBus = new Vue()

0 comments on commit 248112f

Please sign in to comment.