feature: add preheat & cooldown function in ToolsPanel.vue

Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
Stefan Dej committed 2021-01-17 01:32:26 +01:00
1 parent d1cb7f2def
commit c5999221bc
6 files changed
+295 -28

No files matched your search

@@ -0,0 +1,192 @@
<template>
<div>
<v-card>
<v-toolbar flat dense >
<v-toolbar-title>
<span class="subheading"><v-icon left>mdi-fire</v-icon>Preheat Presets</span>
</v-toolbar-title>
</v-toolbar>
<v-card-text class="py-3">
<v-container>
<v-row v-for="(preset, index) in this['gui/getPreheatPresets']" v-bind:key="index">
<v-col class="rounded transition-swing secondary py-2 px-2 mb-6" style="cursor: pointer;">
<v-row align="center">
<v-col class="pl-6">
<strong>{{ preset.name }}</strong>
</v-col>
<v-col>
<span class="d-block text-no-wrap" v-for="[key, value] in Object.entries(preset.values)" v-bind:key="key">{{ key }}: {{ value }}°C</span>
</v-col>
<v-col class="col-auto"><v-btn small class="minwidth-0" v-on:click.stop.prevent="editPreset(preset)"><v-icon small>mdi-pencil</v-icon></v-btn></v-col>
</v-row>
</v-col>
</v-row>
<v-row>
<v-col class="text-center mt-0">
<v-btn @click="createPreset">add preset</v-btn>
</v-col>
</v-row>
</v-container>
</v-card-text>
</v-card>
<v-dialog v-model="dialog.bool" persistent :width="300">
<v-card dark>
<v-toolbar flat dense color="primary">
<v-toolbar-title>
<span class="subheading">
<v-icon class="mdi mdi-fire" left></v-icon>
{{ dialog.index === null ? "Add" : "Edit" }} Preset
</span>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn small class="minwidth-0" @click="dialog.bool = false"><v-icon small>mdi-close-thick</v-icon></v-btn>
</v-toolbar>
<v-card-text class="pt-3">
<v-container class="pb-0">
<v-form
v-model="dialog.valid"
@submit.prevent="savePreset"
>
<v-row>
<v-col class="col-12">
<v-text-field
v-model="dialog.name"
label="Name"
hide-details="auto"
:rules="[rules.required, rules.unique]"
dense
></v-text-field>
</v-col>
</v-row>
<v-row class="mt-2" v-for="(heater) of this['printer/getHeaters']" v-bind:key="heater.name">
<v-col class="col-12">
<v-text-field
v-model="dialog.values[heater.name]"
:label="convertName(heater.name)"
hide-details="auto"
type="number"
suffix="°C"
dense
></v-text-field>
</v-col>
</v-row>
<v-row class="mt-2" v-for="(fan) of this['printer/getTemperatureFans']" v-bind:key="fan.name">
<v-col class="col-12">
<v-text-field
v-model="dialog.values[fan.name]"
:label="convertName(fan.name)"
hide-details
type="number"
suffix="°C"
dense
></v-text-field>
</v-col>
</v-row>
<v-row class="mt-3">
<v-col class="text-center">
<v-btn
color="red"
outlined
class="float-left minwidth-0"
@click="deletePreset"
v-if="this.dialog.index !== null"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
<v-btn
color="white"
outlined
:class="dialog.index !== null ? 'float-right' : '' "
type="submit"
>
{{ dialog.index === null ? "Add" : "Edit" }} preset
</v-btn>
</v-col>
</v-row>
</v-form>
</v-container>
</v-card-text>
</v-card>
</v-dialog>
</div>
</template>
<script>
import { mapState, mapGetters } from 'vuex';
export default {
components: {
},
data: function() {
return {
dialog: {
bool: false,
valid: false,
name: "",
index: null,
values: {},
},
rules: {
required: (value) => value !== '' || 'required',
unique: (value) => !this.existsPresetName(value) || 'Name already exists',
}
}
},
computed: {
...mapState({
orgState: state => state.gui.presets
}),
...mapGetters([
'printer/getHeaters',
'printer/getTemperatureFans',
'gui/getPreheatPresets',
])
},
methods: {
convertName(name) {
let output = ""
name = name.replaceAll("_", " ")
name.split(" ").forEach(split => {
output += " "+split.charAt(0).toUpperCase() + split.slice(1)
})
output = output.slice(1)
return output;
},
existsPresetName(name) {
return (this["gui/getPreheatPresets"].findIndex((preset) => preset.name === name && preset.index !== this.dialog.index) >= 0)
},
createPreset() {
this.clearDialog()
this.dialog.bool = true
},
clearDialog() {
this.dialog.bool = false
this.dialog.index = null
this.dialog.name = ""
this.dialog.values = {}
},
editPreset(preset) {
this.dialog.name = preset.name
this.dialog.index = preset.index
this.dialog.values = {...preset.values}
this.dialog.bool = true
},
savePreset() {
if (this.dialog.valid) {
if (this.dialog.index) {
this.$store.dispatch('gui/updatePreset', this.dialog )
} else this.$store.dispatch('gui/addPreset', this.dialog )
this.clearDialog()
}
},
deletePreset() {
this.$store.dispatch('gui/deletePreset', this.dialog )
this.clearDialog()
}
}
}
</script>
+2
View File
@@ -12,6 +12,7 @@ import RunoutPanel from "./RunoutPanel";
import LogfilesPanel from "./LogfilesPanel";
import UpdatePanel from "./UpdatePanel";
import RemotePrintersPanel from "./RemotePrintersPanel";
import PreheatsPanel from "./PreheatsPanel";
Vue.component('settings-general-panel', GeneralPanel);
Vue.component('settings-webcam-panel', WebcamPanel);
@@ -25,6 +26,7 @@ Vue.component('settings-logfiles-panel', LogfilesPanel);
Vue.component('settings-config-files-panel', ConfigFilesPanel);
Vue.component('settings-update-panel', UpdatePanel);
Vue.component('settings-remote-printers-panel', RemotePrintersPanel);
Vue.component('settings-preheats-panel', PreheatsPanel);
export default {
+56 -24
View File
@@ -14,6 +14,33 @@
<v-toolbar-title>
<span class="subheading"><v-icon left>mdi-thermometer-lines</v-icon>Temperatures</span>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-menu :offset-y="true" title="Preheat">
<template v-slot:activator="{ on, attrs }">
<v-btn small class="px-2 minwidth-0" color="primary" v-bind="attrs" v-on="on">Preheat <v-icon small>mdi-menu-down</v-icon></v-btn>
</template>
<v-list dense class="py-0">
<v-list-item v-for="preset of this['gui/getPreheatPresets']" v-bind:key="preset.index" link @click="preheat(preset)">
<v-list-item-icon class="mr-0">
<v-icon small>mdi-fire</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="preset.name"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
<v-divider v-if="this['gui/getPreheatPresets'].length"></v-divider>
<v-list dense class="py-0">
<v-list-item link @click="cooldown()">
<v-list-item-icon class="mr-0">
<v-icon small>mdi-snowflake</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>Cooldown</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</v-toolbar>
<v-card-text class="px-0 py-2 content">
<v-container class="px-0">
@@ -87,7 +114,7 @@
</template>
<script>
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import toolInput from '../../inputs/ToolInput'
import TempChart from '@/components/charts/TempChart'
@@ -107,6 +134,9 @@
boolTempchart: state => state.gui.dashboard.boolTempchart,
printer: state => state.printer,
}),
...mapGetters([
'gui/getPreheatPresets'
]),
heaters: {
get () {
return this.$store.getters["printer/getHeaters"]
@@ -127,30 +157,32 @@
},
methods: {
preheat(preset) {
window.console.log("preheat")
window.console.log(preset)
},
mounted () {
for (const [name, temp] of Object.entries(preset.values)) {
const heater = this.heaters.findIndex((heater) => heater.name === name)
if (heater !== -1) {
const gcode = "SET_HEATER_TEMPERATURE HEATER="+name+" TARGET="+temp
this.$store.commit('server/addEvent', { message: gcode, type: 'command' })
this.$socket.sendObj('printer.gcode.script', { script: gcode })
}
const temperatureFan = this.temperatureFans.findIndex((fan) => fan.name === name)
if (temperatureFan !== -1) {
const gcode = "SET_TEMPERATURE_FAN_TARGET temperature_fan="+name+" TARGET="+temp
this.$store.commit('server/addEvent', { message: gcode, type: 'command' })
this.$socket.sendObj('printer.gcode.script', { script: gcode })
}
}
},
cooldown() {
const gcode = "TURN_OFF_HEATERS"
this.$store.commit('server/addEvent', { message: gcode, type: 'command' })
this.$socket.sendObj('printer.gcode.script', { script: gcode })
}
},
}
</script>
<style scoped>
.equal-width {
flex-basis: 0;
}
.category-header {
flex: 0 0 100px;
}
a:not(:hover) {
color: inherit;
}
.content span,
.content strong {
padding-left: 8px;
padding-right: 8px;
white-space: pre-wrap;
}
</style>
</script>
+12 -1
View File
@@ -42,7 +42,18 @@ export default {
dispatch('upload')
},
addPreset({ commit }, payload) {
addPreset({ commit, dispatch }, payload) {
commit("addPreset", payload)
dispatch("upload")
},
updatePreset({ commit, dispatch }, payload) {
commit("updatePreset", payload)
dispatch("upload")
},
deletePreset({ commit, dispatch }, payload) {
commit("deletePreset", payload)
dispatch("upload")
}
}
+11
View File
@@ -1,3 +1,14 @@
import {caseInsensitiveNameSort} from "@/plugins/helpers";
export default {
getPreheatPresets:(state) => {
const output = []
for (const [key, preset] of Object.entries(state.presets)) {
output.push({ ...preset, index: key })
}
return output.sort(caseInsensitiveNameSort)
}
}
+22 -3
View File
@@ -45,8 +45,27 @@ export default {
Vue.set(state.gcodefiles, "showHiddenFiles", value)
},
addPreset(state, preload) {
window.console.log(state.presets)
window.console.log(preload)
addPreset(state, payload) {
state.presets.push({
name: payload.name,
values: payload.values
})
},
updatePreset(state, payload) {
if (state.presets[payload.index]) {
for (const [heaterName, temp] of Object.entries(payload.values)) {
if (temp === "") delete payload.values[heaterName]
}
Vue.set(state.presets[payload.index], 'name', payload.name)
Vue.set(state.presets[payload.index], 'values', payload.values)
}
},
deletePreset(state, payload) {
if (state.presets[payload.index]) {
state.presets.splice(payload.index, 1)
}
}
}