index.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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="https://unpkg.com/lodash@4.16.0"></script>
  8. <!-- Delete ".min" for console warnings in development -->
  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 }}
  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. update: function (event) {
  46. fetch('/log/'+this.lastID, {method: "GET"})
  47. .then((response) => {
  48. return response.json();
  49. })
  50. .then((myJson) => {
  51. console.log(JSON.stringify(myJson));
  52. this.$data.log=this.$data.log.concat(myJson.entries);
  53. this.$data.lastID=myJson.lastID;
  54. });
  55. }
  56. }
  57. })
  58. </script>
  59. </body>
  60. </html>