QueueSongs.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class='columns is-mobile'>
  3. <div class='column is-8-desktop is-offset-2-desktop is-12-mobile'>
  4. <table class='table is-striped'>
  5. <thead>
  6. <tr>
  7. <td>Title</td>
  8. <td>YouTube ID</td>
  9. <td>Artists</td>
  10. <td>Genres</td>
  11. <td>Options</td>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr v-for='(index, song) in songs' track-by='$index'>
  16. <td>
  17. <p class='control'>
  18. <input class='input' type='text' v-model='song.title'>
  19. </p>
  20. </td>
  21. <td>
  22. <p class='control'>
  23. <input class='input' type='text' v-model='song._id'>
  24. </p>
  25. </td>
  26. <td>
  27. <div class='control'>
  28. <input v-for='artist in song.artists' track-by='$index' class='input' type='text' v-model='artist'>
  29. </div>
  30. </td>
  31. <td>
  32. <div class='control'>
  33. <input v-for='genre in song.genres' track-by='$index' class='input' type='text' v-model='genre'>
  34. </div>
  35. </td>
  36. <td>
  37. <a class='button is-primary' @click='edit(song, index)'>Edit</a>
  38. <a class='button is-success' @click='add(song)'>Add</a>
  39. <a class='button is-danger' @click='remove(song._id, index)'>Remove</a>
  40. </td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. </div>
  46. <div class='modal' :class="{ 'is-active': isEditActive }">
  47. <div class='modal-background'></div>
  48. <div class='modal-card'>
  49. <section class='modal-card-body'>
  50. <h5 class='has-text-centered'><strong>Thumbnail Preview</strong></h5>
  51. <img class='thumbnail-preview' :src='beingEdited.song.thumbnail'>
  52. <label class='label'>Thumbnail URL</label>
  53. <p class='control'>
  54. <input class='input' type='text' v-model='beingEdited.song.thumbnail'>
  55. </p>
  56. <h5 class='has-text-centered'><strong>Edit Info</strong></h5>
  57. <!--<label class='label'>Email</label>
  58. <p class='control'>
  59. <input class='input' type='text' placeholder='Email...' v-model='$parent.register.email'>
  60. </p>-->
  61. <label class='label'>Song ID</label>
  62. <p class='control'>
  63. <input class='input' type='text' v-model='beingEdited.song._id'>
  64. </p>
  65. <label class='label'>Song Title</label>
  66. <p class='control'>
  67. <input class='input' type='text' v-model='beingEdited.song.title'>
  68. </p>
  69. <label class='label'>Artists</label>
  70. <div class='control'>
  71. <input v-for='artist in beingEdited.song.artists' track-by='$index' class='input' type='text' v-model='artist'>
  72. </div>
  73. <label class='label'>Genres</label>
  74. <div class='control'>
  75. <input v-for='genre in beingEdited.song.genres' track-by='$index' class='input' type='text' v-model='genre'>
  76. </div>
  77. <label class='label'>Song Duration</label>
  78. <p class='control'>
  79. <input class='input' type='text' v-model='beingEdited.song.duration'>
  80. </p>
  81. <label class='label'>Skip Duration</label>
  82. <p class='control'>
  83. <input class='input' type='text' v-model='beingEdited.song.skipDuration'>
  84. </p>
  85. </section>
  86. <footer class='modal-card-foot'>
  87. <button class='delete' @click='toggleModal()'></button>
  88. </footer>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import { Toast } from 'vue-roaster';
  94. export default {
  95. data() {
  96. return {
  97. songs: [],
  98. isEditActive: false,
  99. beingEdited: {
  100. index: 0,
  101. song: {}
  102. }
  103. }
  104. },
  105. methods: {
  106. toggleModal: function () {
  107. this.isEditActive = !this.isEditActive;
  108. },
  109. edit: function (song, index) {
  110. this.beingEdited = { index, song };
  111. this.isEditActive = true;
  112. },
  113. add: function (song) {
  114. this.socket.emit('queueSongs.remove', song._id);
  115. this.socket.emit('songs.add', song, res => {
  116. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  117. });
  118. },
  119. remove: function (id, index) {
  120. this.songs.splice(index, 1);
  121. this.socket.emit('queueSongs.remove', id, res => {
  122. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  123. });
  124. }
  125. },
  126. ready: function () {
  127. let _this = this;
  128. let socketInterval = setInterval(() => {
  129. if (!!_this.$parent.$parent.socket) {
  130. _this.socket = _this.$parent.$parent.socket;
  131. _this.socket.emit('queueSongs.index', data => {
  132. _this.songs = data;
  133. });
  134. clearInterval(socketInterval);
  135. }
  136. }, 100);
  137. }
  138. }
  139. </script>
  140. <style lang='scss' scoped>
  141. .thumbnail-preview {
  142. display: flex;
  143. margin: 0 auto;
  144. padding: 10px 0 20px 0;
  145. }
  146. .modal-card-body, .modal-card-foot {
  147. border-top: 0;
  148. background-color: rgb(66, 165, 245);
  149. }
  150. .label, strong {
  151. color: #fff;
  152. }
  153. </style>