Skip to content

Commit

Permalink
fix: macro entry no longer produces duplicate params
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Bassett <[email protected]>
  • Loading branch information
cadriel committed Jul 7, 2021
1 parent 6a3ca62 commit 668586c
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions src/components/ui/AppMacroBtn.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<app-btn
v-if="params.length === 0 || !enableParams"
v-if="paramList.length === 0 || !enableParams"
:disabled="macro.disabledWhilePrinting && printerPrinting"
@click="$emit('click', macro.name)"
:style="borderStyle"
>
<div class="color-accent" :style="`background-color: ${color};`"></div>
<slot></slot>
</app-btn>
<app-btn-group
Expand All @@ -14,8 +14,8 @@
<app-btn
:disabled="macro.disabledWhilePrinting && printerPrinting"
@click="$emit('click', macro.name)"
:style="borderStyle"
>
<div class="color-accent" :style="`background-color: ${color};`"></div>
<slot></slot>
</app-btn>
<v-menu
Expand All @@ -26,7 +26,7 @@
>
<template v-slot:activator="{ on, attrs, value }">
<app-btn
v-if="params.length > 0"
v-if="paramList.length > 0"
v-on="on"
v-bind="attrs"
:min-width="24"
Expand All @@ -41,19 +41,19 @@
<v-layout wrap style="max-width: 150px;">

<v-text-field
v-for="(param, i) in params"
:key="param.name"
:label="param.name"
v-for="(param, i) in paramList"
:key="param"
:label="param"
outlined
dense
hide-details="auto"
v-model="param.value"
v-model="params[param].value"
class=""
:class="{ 'mb-3': (i < params.length - 1) }">
:class="{ 'mb-3': (i < paramList.length - 1) }">

<template v-slot:append>
<app-btn
@click="param.value = param.reset"
@click="params[param].value = params[param].reset"
style="margin-top: -4px; margin-right: -6px;"
color=""
icon
Expand Down Expand Up @@ -95,27 +95,30 @@ export default class AppMacroBtn extends Mixins(StateMixin) {
@Prop({ type: Boolean, default: false })
enableParams!: boolean;
params: { name: string; value: any; reset: any }[] = []
params: { [index: string]: { value: string | number; reset: string | number }} = {}
get paramList () {
return Object.keys(this.params)
}
/**
* The formatted run command for a macro.
*/
get runCommand () {
let s = this.macro.name
if (this.params) {
this.params.forEach((param) => {
s += ` ${param.name}=${param.value}`
})
for (const param of Object.keys(this.params)) {
s += ` ${param}=${this.params[param].value}`
}
}
return s
}
get color () {
get borderStyle () {
if (this.macro && this.macro.color !== '') {
return this.macro.color
return `border-color: ${this.macro.color} !important; border-left: solid 4px ${this.macro.color} !important;`
}
const theme = this.$store.getters['config/getTheme']
return theme.currentTheme.btncolor
return ''
}
mounted () {
Expand All @@ -124,11 +127,12 @@ export default class AppMacroBtn extends Mixins(StateMixin) {
const regex = /params\.(\w*)\|?(default\('?(\w*)'?\))?/gmi
let match = regex.exec(this.macro.config.gcode)
do {
// console.log(match)
if (match && match[1]) {
const name = match[1]
const value = match[3] || ''
this.params.push({ name, value, reset: value })
if (!this.params[name]) {
this.$set(this.params, name, { value, reset: value })
}
}
} while (
(match = regex.exec(this.macro.config.gcode)) !== null
Expand All @@ -139,17 +143,6 @@ export default class AppMacroBtn extends Mixins(StateMixin) {
</script>

<style lang="scss" scoped>
.color-accent {
border-radius: 4px 0 0 4px;
content: "";
top: -10px;
left: -16px;
position: absolute;
width: 4px;
height: 36px;
opacity: 1;
}
.macro-params {
height: 160px;
display: flex;
Expand Down

0 comments on commit 668586c

Please sign in to comment.