From 322c98ce6ee453dea0e4fb0b566d0dd7f19fd03b Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 21 Dec 2017 12:33:58 +0100 Subject: [PATCH] remote control: add /SET method (issue #56) --- CHANGELOG.md | 1 + resources/docs/extras/remote-control.md | 16 +++++++++++++ src/browser/js/app/remote-control.js | 32 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd7a5662..5147325e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - renamed `/EDIT_SOFT` to `/EDIT/MERGE` - added `/EDIT/GET` (get a widget's data) - added `/GET` (get a widget's value) + - added `/SET` (set a widget's value as if it was interacted with from the interface) ## 0.21.3 diff --git a/resources/docs/extras/remote-control.md b/resources/docs/extras/remote-control.md index 48fe9d5d..d89b11ed 100644 --- a/resources/docs/extras/remote-control.md +++ b/resources/docs/extras/remote-control.md @@ -68,6 +68,22 @@ Returns `/GET address preArg1 preArg2 ... value` - `value`: `*` +## `/SET target id value` + +Set a widget's value as if it was interacted with from the interface. This is likely to make it send its value. + +- `id`: `string`, widget's `id` +- `value`: `*`, widget's new value + +## `/SET address preArg1 preArg2 ... value` + +Set a widget's value as if it was interacted with from the interface. This is likely to make it send its value. + +- `address`: `string`, widget's `address` +- `preArg[1...]`: `*`, widget's `preArgs` +- `value`: `*`, widget's new value + + ## `/TABS id id etc` Open the tabs designated by the `id` parameters. The target tab link must be accesible (opening a tab located in a disabled tab won't work unless you specify the parent tab's `id` before; the safest way to go is to pass the whole tab tree to enable). diff --git a/src/browser/js/app/remote-control.js b/src/browser/js/app/remote-control.js index 722a6285..94b170de 100644 --- a/src/browser/js/app/remote-control.js +++ b/src/browser/js/app/remote-control.js @@ -87,6 +87,38 @@ var callbacks = { } + }, + '/SET':function(args) { + + var [idOrAddress, ...preArgsOrValue] = args, + widgets = [], + value = null + + if (idOrAddress[0] == '/') { + + [widgets, value] = widgetManager.getWidgetByAddressAndArgs( + idOrAddress, + preArgsOrValue + ) + + } else { + + widgets = widgetManager.getWidgetById(idOrAddress) + value = preArgsOrValue + if (value.length == 0) value = null + else if (value.length == 1) value = value[0] + + } + + for (var i = widgets.length - 1; i >= 0; i--) { + + return widgets[i].setValue(value, { + sync: true, + send: true + }) + + } + }, '/TABS': function(args) {