|
@ -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(); }); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |