You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
951 B

2 months ago
2 months ago
2 months ago
2 months ago
  1. import { Controller } from '@hotwired/stimulus';
  2. export default class extends Controller {
  3. static values = {
  4. commands: String,
  5. }
  6. remoteControl() {
  7. // cf <https://josm.openstreetmap.de/wiki/Help/RemoteControlCommands>
  8. const baseurl = 'http://localhost:8111';
  9. const _this = this, commands = JSON.parse(this.commandsValue);
  10. for (var command in commands) {
  11. var url = baseurl + '/' + command, params = new URLSearchParams();
  12. for (var name in commands[command]) {
  13. params.append(name, commands[command][name]);
  14. }
  15. if (Array.from(params.length > 0)) {
  16. url += '?' + params.toString();
  17. }
  18. fetch(url)
  19. .then(function (response) {
  20. return response.text();
  21. })
  22. .then(function (text) {
  23. });
  24. }
  25. }
  26. }