index.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Vue.js markdown editor example</title>
  6. <link rel="stylesheet" href="css/style.css">
  7. <script src="js/util.js"></script>
  8. <script src="js/moment.js"></script>
  9. <script src="js/vue.js"></script>
  10. </head>
  11. <body>
  12. <div id="app">
  13. <textarea v-model="input" cols="80" rows="20"></textarea>
  14. <button v-on:click="send">send</button>
  15. <ul id="loglist">
  16. <li v-for="(item, index) in log.slice().reverse()">
  17. {{ index }} - {{ item.entry.message }} - {{ ts2txt(item.ts) }}
  18. </li>
  19. </ul>
  20. </div>
  21. <script type="application/javascript">
  22. new Vue({
  23. el: '#app',
  24. data: {
  25. input: '// rde.writeCmd("set_digital_out(2,True)");\n' +
  26. '// rde.writeCmd("movej([-1.95,-1.58,-1.16,-1.15,-1.55,1.25], a=1.0, v=0.1)");\n' +
  27. '//rde.writeCmd("freedrive_mode()");\n'+
  28. 'def asdf():\n' +
  29. ' set_digital_out(3, True) \n' +
  30. ' set_digital_out(4, True) \n' +
  31. 'end',
  32. log: [],
  33. lastID: -1
  34. },
  35. created: function() {
  36. setInterval(this.update, 200);
  37. },
  38. methods: {
  39. send: function (event) {
  40. fetch('/cmd', {method: "POST", body: this.input})
  41. .then(function(response) {
  42. return response;
  43. });
  44. },
  45. ts2txt: function (ts) {
  46. return moment(ts).format('YYYY-MM-DD [at] hh:mm')
  47. },
  48. update: function (event) {
  49. fetch('/log/'+this.lastID, {method: "GET"})
  50. .then(handleErrors)
  51. .then((response) => {
  52. return response.json();
  53. })
  54. .then((myJson) => {
  55. console.log(JSON.stringify(myJson));
  56. this.$data.log=this.$data.log.concat(myJson.entries);
  57. this.$data.lastID=myJson.lastID;
  58. })
  59. .catch(error => {
  60. this.$data.lastID=0;3
  61. this.$data.log=[];
  62. console.log(error)
  63. } );
  64. }
  65. }
  66. })
  67. </script>
  68. </body>
  69. </html>