index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div id="app">
  3. <h2 id="titolone" class="subtitle" style="background:beige;position:absolute;bottom:0">
  4. Second attempt at building a web interface for ESP8266
  5. </h2>
  6. <div style="margin-top:1em;margin-bottom:1em;display:flex;width:100%;height:3em;background:#3333333;align-items:center;justify-content:center">
  7. <div>
  8. <div class="icon-button" style="flex:1 1 auto" v-on:click="addLine()">
  9. <img style="margin:auto;" src="~/assets/img/add.png">
  10. </div>
  11. </div>
  12. </div>
  13. <div v-for="line in lines" :key='line.id'>
  14. <sequencer class="jsonSequencer" :id='line.id' :line='line'></sequencer>
  15. </div>
  16. <div class="icon-wrapper">
  17. <div class="icon-button">
  18. <img style="margin:auto;" src="~/assets/img/barrier.png">
  19. </div>
  20. <div class="icon-button">
  21. <img style="margin:auto;" src="~/assets/img/pixel.png">
  22. </div>
  23. <div class="icon-button">
  24. <img style="margin:auto;" src="~/assets/img/squares.png">
  25. </div>
  26. <div class="icon-button">
  27. <img style="margin:auto;" src="~/assets/img/bell.png">
  28. </div>
  29. <input type="submit" value="Send!" style="width:5em;height:2em;background:red;border:none;color:white;" v-on:click="getSequencerData()">
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import sequencer from '~/components/sequencer.vue'
  35. import sequencerDivided from '~/components/sequencerDivided.vue'
  36. import beatMenu from '~/components/beatMenu.vue'
  37. import moduleData from '~/assets/js/moduleData.json'
  38. export default {
  39. data() {
  40. return {
  41. lines: []
  42. // https://stackoverflow.com/questions/44869287/set-object-in-data-from-a-method-in-vue-js#44869373
  43. // creata object in data vue
  44. }
  45. },
  46. components: {
  47. sequencer,
  48. sequencerDivided,
  49. beatMenu
  50. },
  51. methods:
  52. {
  53. addLine: function (){
  54. this.lines.push({
  55. id: this.lines.length,
  56. slotSlider: 16,
  57. pulseSlider: 3,
  58. euclideanList: [],
  59. controlIsDisplayed: false });
  60. },
  61. getSequencerData: function(){
  62. var modelEsp = {
  63. 'millis_per_slot': 500, // bpm = 60000 / millis_per_slot
  64. 'lines': this.lines.map(function(line) {
  65. return line.euclideanList.reduce(function(acc, x) { return acc + x.toString(); }, '');
  66. })
  67. };
  68. var xhr = new XMLHttpRequest();
  69. xhr.open('POST', '/play.ws');
  70. xhr.onreadystatechange = function () {
  71. if(xhr.readyState === 4 && xhr.status === 200) {
  72. //self.commits = JSON.parse(xhr.responseText);
  73. console.log("Recv", xhr.responseText);
  74. }
  75. };
  76. xhr.setRequestHeader('Content-Type', 'application/json');
  77. xhr.send(JSON.stringify(modelEsp));
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. .icon-button{
  84. display:flex;
  85. background-color:red;
  86. width:3em;
  87. height:3em;
  88. border-radius:3em;
  89. margin:0.2em;
  90. }
  91. .icon-wrapper{
  92. display:flex;
  93. }
  94. </style>