fix: macro buttons with single char attribute (#903)

This commit is contained in:
Stefan Dej authored and GitHub committed 2022-06-15 07:55:47 +02:00
1 parent 21ad4c16e7
commit 8367f01bce
6 files changed
+42 -69

No files matched your search

+6 -3
View File
@@ -94,6 +94,10 @@ export default class MacroButton extends Mixins(BaseMixin) {
return this.$store.getters['printer/getMacro'](this.macro.name)
}
get isGcodeStyle() {
return this.macro.name.match(/[G|M]\d{1,3}/gm)
}
@Watch('klipperMacro')
klipperMacroChange() {
this.refreshParams()
@@ -103,7 +107,7 @@ export default class MacroButton extends Mixins(BaseMixin) {
this.paramArray.splice(0, this.paramArray.length)
this.params = {}
if (this.klipperMacro.params !== null) {
if (this.klipperMacro?.params !== null) {
Object.keys(this.klipperMacro.params).forEach((name: string) => {
if (!name.startsWith('_')) {
this.paramArray.push(name)
@@ -130,8 +134,7 @@ export default class MacroButton extends Mixins(BaseMixin) {
this.paramArray.forEach((paramname: string) => {
if (this.params[paramname].value !== null && this.params[paramname].value !== '') {
let tmp: string = paramname
if (paramname.length === 1) tmp += this.params[paramname].value
else tmp += '=' + this.params[paramname].value
tmp += this.isGcodeStyle ? this.params[paramname].value : `=${this.params[paramname].value}`
params.push(tmp)
}
+1 -1
View File
@@ -43,7 +43,7 @@ export default class MacrogroupPanel extends Mixins(BaseMixin) {
}
get allMacros() {
return this.$store.getters['printer/getAllMacros'] ?? []
return this.$store.getters['printer/getMacros'] ?? []
}
get macros() {
+8 -1
View File
@@ -26,14 +26,21 @@ import BaseMixin from '../mixins/base'
import Panel from '@/components/ui/Panel.vue'
import MacroButton from '@/components/inputs/MacroButton.vue'
import { mdiCodeTags } from '@mdi/js'
import { PrinterStateMacro } from '@/store/printer/types'
@Component({
components: { MacroButton, Panel },
})
export default class MacrosPanel extends Mixins(BaseMixin) {
mdiCodeTags = mdiCodeTags
get hiddenMacros() {
return (this.$store.state.gui?.macros?.hiddenMacros ?? []).map((name: string) => name.toLowerCase())
}
get macros() {
return this.$store.getters['printer/getMacros']
const macros = this.$store.getters['printer/getMacros']
return macros.filter((macro: PrinterStateMacro) => !this.hiddenMacros.includes(macro.name.toLowerCase()))
}
}
</script>
@@ -381,7 +381,7 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
}
get allMacros() {
return this.$store.getters['printer/getAllMacros'] ?? []
return this.$store.getters['printer/getMacros'] ?? []
}
get availableMacros() {
@@ -32,7 +32,7 @@ import SettingsRow from '@/components/settings/SettingsRow.vue'
})
export default class SettingsMacrosTabSimple extends Mixins(BaseMixin) {
get macros() {
return this.$store.getters['printer/getAllMacros'] ?? []
return this.$store.getters['printer/getMacros'] ?? []
}
get hiddenMacros() {
+25 -62
View File
@@ -55,38 +55,40 @@ export const getters: GetterTree<PrinterState, RootState> = {
return state.virtual_sdcard?.progress ?? 0
},
getMacros: (state, getters, rootState) => {
getMacros: (state) => {
const array: PrinterStateMacro[] = []
const hiddenMacros: string[] = []
const config = state.configfile?.config ?? {}
const settings = state.configfile?.settings ?? null
rootState.gui?.macros?.hiddenMacros.forEach((item: string, index: number) => {
hiddenMacros[index] = item.toLowerCase()
})
Object.keys(config)
.filter((prop) => prop.toLowerCase().startsWith('gcode_macro'))
.forEach((prop) => {
const name = prop.replace('gcode_macro ', '')
if (name.startsWith('_')) return
if (state.configfile?.config) {
Object.keys(state.configfile?.config).forEach((prop) => {
if (
prop.startsWith('gcode_macro') &&
!prop.startsWith('gcode_macro _') &&
!('rename_existing' in state.configfile.config[prop]) &&
!(hiddenMacros.indexOf(prop.replace('gcode_macro ', '').toLowerCase()) > -1)
) {
const variables = state[prop] ?? {}
const propLower = prop.toLowerCase()
const propSettings = settings[propLower]
if ('rename_existing' in propSettings) return
array.push({
name: prop.replace('gcode_macro ', ''),
description: state.configfile.config[prop].description ?? null,
prop: state.configfile.config[prop],
params: getMacroParams(state.configfile.config[prop]),
variables,
})
}
const variables = state[prop] ?? {}
array.push({
name,
description: settings[propLower].description ?? null,
prop: propSettings,
params: getMacroParams(propSettings),
variables,
})
})
}
return caseInsensitiveSort(array, 'name')
},
getMacro: (state, getters) => (name: string) => {
const nameLower = name.toLowerCase()
return getters['getMacros'].find((macro: PrinterStateMacro) => macro.name.toLowerCase() === nameLower)
},
getHeaters: (state, getters, rootState, rootGetters) => {
const heaters: PrinterStateHeater[] = []
const colorOff = 'grey darken-2'
@@ -461,45 +463,6 @@ export const getters: GetterTree<PrinterState, RootState> = {
return state.heaters?.available_sensors ?? []
},
getAllMacros: (state) => {
const array: PrinterStateMacro[] = []
Object.keys(state.configfile?.config ?? {}).forEach((prop) => {
if (
prop.startsWith('gcode_macro') &&
!prop.startsWith('gcode_macro _') &&
!Object.hasOwnProperty.call(state.configfile.config[prop], 'rename_existing')
) {
const variables = state[prop] ?? {}
array.push({
name: prop.replace('gcode_macro ', ''),
description: state.configfile.config[prop].description ?? null,
prop: state.configfile.config[prop],
params: getMacroParams(state.configfile.config[prop]),
variables,
})
}
})
return caseInsensitiveSort(array, 'name')
},
getMacro: (state) => (name: string) => {
if ('gcode_macro ' + name in state.configfile.config) {
const config = state.configfile.config['gcode_macro ' + name]
return {
name,
description: config.description ?? null,
prop: config,
params: getMacroParams(config),
}
}
return null
},
getFilamentSensors: (state) => {
const sensorObjectNames = ['filament_switch_sensor', 'filament_motion_sensor']
const sensors: PrinterStateFilamentSensors[] = []