Skip to content

Commit

Permalink
feat: Use variable for step in internal: Button: Set current step #2294
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 13, 2023
1 parent f8b81f6 commit 03641ae
Showing 1 changed file with 45 additions and 31 deletions.
76 changes: 45 additions & 31 deletions lib/Internal/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ const CHOICES_BUTTON_WITH_VARIABLES = serializeIsVisibleFn([
},
])

const CHOICES_STEP_WITH_VARIABLES = serializeIsVisibleFn([
{
type: 'checkbox',
label: 'Use variables for step',
id: 'step_from_expression',
default: false,
},
{
type: 'number',
label: 'Step',
tooltip: 'Which Step?',
id: 'step',
default: 1,
min: 1,
isVisible: (options) => !options.step_from_expression,
},
{
type: 'textinput',
label: 'Step (expression)',
id: 'step_expression',
default: '1',
isVisible: (options) => !!options.step_from_expression,
useVariables: true,
},
])

const ButtonStylePropertiesExt = [
...ButtonStyleProperties,
{ id: 'show_topbar', label: 'Topbar' },
Expand Down Expand Up @@ -149,6 +175,16 @@ export default class Controls extends CoreBase {
}
}

#fetchStep(options) {
let theStep = options.step

if (options.step_from_expression) {
theStep = this.instance.variable.parseExpression(options.step_expression, 'number').value
}

return theStep
}

getActionDefinitions() {
return {
button_pressrelease: {
Expand Down Expand Up @@ -339,18 +375,7 @@ export default class Controls extends CoreBase {
bank_current_step: {
label: 'Button: Set current step',
previewControlIdFn: previewControlIdFn,
options: [
...CHOICES_PAGE_WITH_VARIABLES,
...CHOICES_BUTTON_WITH_VARIABLES,
{
type: 'number',
label: 'Step',
tooltip: 'Which Step?',
id: 'step',
default: 1,
min: 1,
},
],
options: [...CHOICES_PAGE_WITH_VARIABLES, ...CHOICES_BUTTON_WITH_VARIABLES, ...CHOICES_STEP_WITH_VARIABLES],
},
bank_current_step_condition: {
label: 'Button: Set current step if variable meets condition',
Expand Down Expand Up @@ -382,14 +407,7 @@ export default class Controls extends CoreBase {
},
...CHOICES_PAGE_WITH_VARIABLES,
...CHOICES_BUTTON_WITH_VARIABLES,
{
type: 'number',
label: 'Step',
tooltip: 'Which Step?',
id: 'step',
default: 1,
min: 1,
},
...CHOICES_STEP_WITH_VARIABLES,
],
},
bank_current_step_if_expression: {
Expand All @@ -405,14 +423,7 @@ export default class Controls extends CoreBase {
},
...CHOICES_PAGE_WITH_VARIABLES,
...CHOICES_BUTTON_WITH_VARIABLES,
{
type: 'number',
label: 'Step',
tooltip: 'Which Step?',
id: 'step',
default: 1,
min: 1,
},
...CHOICES_STEP_WITH_VARIABLES,
],
},
bank_current_step_delta: {
Expand Down Expand Up @@ -700,14 +711,16 @@ export default class Controls extends CoreBase {
return true
} else if (action.action == 'bank_current_step') {
const { theControlId } = this.#fetchPageAndButton(action.options, extras, true)
const theStep = this.#fetchStep(action.options)

const control = this.controls.getControl(theControlId)

if (control && typeof control.stepMakeCurrent === 'function') {
control.stepMakeCurrent(action.options.step)
control.stepMakeCurrent(theStep)
}
} else if (action.action == 'bank_current_step_condition') {
const { theControlId } = this.#fetchPageAndButton(action.options, extras, true)
const theStep = this.#fetchStep(action.options)

const control = this.controls.getControl(theControlId)

Expand Down Expand Up @@ -739,19 +752,20 @@ export default class Controls extends CoreBase {

if (pressIt) {
if (control && typeof control.stepMakeCurrent === 'function') {
control.stepMakeCurrent(action.options.step)
control.stepMakeCurrent(theStep)
}
}
} else if (action.action == 'bank_current_step_if_expression') {
const { theControlId } = this.#fetchPageAndButton(action.options, extras, true)
const theStep = this.#fetchStep(action.options)

const control = this.controls.getControl(theControlId)

const pressIt = !!this.instance.variable.parseExpression(action.options.expression, 'boolean').value

if (pressIt) {
if (control && typeof control.stepMakeCurrent === 'function') {
control.stepMakeCurrent(action.options.step)
control.stepMakeCurrent(theStep)
}
}
} else if (action.action == 'bank_current_step_delta') {
Expand Down

0 comments on commit 03641ae

Please sign in to comment.