Browse Source

Ajoute de la gestion d’erreur avec la télecommande JOSM

master
vincent 1 day ago
parent
commit
42b682b9ce
4 changed files with 680 additions and 534 deletions
  1. +49
    -0
      assets/controllers/josm_controller.js
  2. +3
    -1
      assets/controllers/map_controller.js
  3. +627
    -532
      composer.lock
  4. +1
    -1
      templates/task/show.html.twig

+ 49
- 0
assets/controllers/josm_controller.js View File

@ -37,9 +37,29 @@ TODO Gérer le cas où il n’y a pas de JOSM en face pourrait être plus user-f
**/ **/
import { Controller } from '@hotwired/stimulus'; import { Controller } from '@hotwired/stimulus';
function until(conditionFunction, maximum, message) {
var current = maximum;
const poll = function (resolve) {
if (conditionFunction()) {
resolve();
} else {
current -= 1;
if (current > 0) {
setTimeout(function() {
return poll(resolve);
}, 400);
} else {
alert(message);
}
}
};
return new Promise(poll);
}
export default class extends Controller { export default class extends Controller {
static values = { static values = {
commands: String, commands: String,
ready: Boolean
} }
remoteControl() { remoteControl() {
@ -61,4 +81,33 @@ export default class extends Controller {
}); });
} }
} }
isReady() {
const url = 'http://localhost:8111/version';
const _this = this;
this.readyValue = false;
fetch(url)
.catch(function (error) {
_this.readyValue = false;
})
.then(function (response) {
if (typeof response === 'undefined') {
return;
}
return response.text();
})
.then(function (text) {
if (typeof response === 'undefined') {
_this.readyValue = false;
} else {
_this.readyValue = true;
}
});
}
remoteControlIfReady() {
const _this = this;
until(function () { return _this.isReady(); }, 10, 'JOSM n´est pas disponible pour le moment').then(function () { _this.remoteControl(); });
}
} }

+ 3
- 1
assets/controllers/map_controller.js View File

@ -177,7 +177,9 @@ export default class extends Controller {
// Zoome la carte pour que les données des tâches soient toutes // Zoome la carte pour que les données des tâches soient toutes
// visibles // visibles
map.fitBounds(taskLayer.getBounds());
try {
map.fitBounds(taskLayer.getBounds());
} catch (error) {} // TODO gérer l'erreur plus proprement quand il n'y a pas de GeoJSON
} }
openInOsm() { openInOsm() {


+ 627
- 532
composer.lock
File diff suppressed because it is too large
View File


+ 1
- 1
templates/task/show.html.twig View File

@ -86,7 +86,7 @@
class="btn btn-secondary" class="btn btn-secondary"
type="button" type="button"
data-controller="josm" data-controller="josm"
data-action="click->josm#remoteControl"
data-action="click->josm#remoteControlIfReady"
data-josm-commands-value="{{ josmCommands|escape('html_attr') }}" data-josm-commands-value="{{ josmCommands|escape('html_attr') }}"
title="{{ 'button.josm_remote_control'|trans }}" title="{{ 'button.josm_remote_control'|trans }}"
accesskey="J" accesskey="J"


Loading…
Cancel
Save