index.html 2.0 KB

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