QueueSongs.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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'>Video Preview</h5>
  51. <div class='video-container'>
  52. <div id='player'></div>
  53. <p class='control has-addons'>
  54. <a class='button'>
  55. <i class='material-icons' @click='video.settings("pause")' v-if='!video.paused'>pause</i>
  56. <i class='material-icons' @click='video.settings("play")' v-else>play_arrow</i>
  57. </a>
  58. <a class='button' @click='video.settings("stop")'>
  59. <i class='material-icons'>stop</i>
  60. </a>
  61. <a class='button' @click='video.settings("skipToLast10Secs")'>
  62. <i class='material-icons'>fast_forward</i>
  63. </a>
  64. </p>
  65. </div>
  66. <h5 class='has-text-centered'>Thumbnail Preview</h5>
  67. <img class='thumbnail-preview' :src='editing.song.thumbnail'>
  68. <label class='label'>Thumbnail URL</label>
  69. <p class='control'>
  70. <input class='input' type='text' v-model='editing.song.thumbnail'>
  71. </p>
  72. <h5 class='has-text-centered'>Edit Info</h5>
  73. <label class='label'>Song ID</label>
  74. <p class='control'>
  75. <input class='input' type='text' v-model='editing.song._id'>
  76. </p>
  77. <label class='label'>Song Title</label>
  78. <p class='control'>
  79. <input class='input' type='text' v-model='editing.song.title'>
  80. </p>
  81. <label class='label'>Artists</label>
  82. <div class='control'>
  83. <input v-for='artist in editing.song.artists' track-by='$index' class='input' type='text' v-model='artist'>
  84. </div>
  85. <label class='label'>Genres</label>
  86. <div class='control'>
  87. <input v-for='genre in editing.song.genres' track-by='$index' class='input' type='text' v-model='genre'>
  88. </div>
  89. <label class='label'>Song Duration</label>
  90. <p class='control'>
  91. <input class='input' type='text' v-model='editing.song.duration'>
  92. </p>
  93. <label class='label'>Skip Duration</label>
  94. <p class='control'>
  95. <input class='input' type='text' v-model='editing.song.skipDuration'>
  96. </p>
  97. </section>
  98. <footer class='modal-card-foot'>
  99. <i class='material-icons save-changes' @click='save(editing.song)'>save</i>
  100. <button class='delete' @click='toggleModal()'></button>
  101. </footer>
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import { Toast } from 'vue-roaster';
  107. export default {
  108. data() {
  109. return {
  110. songs: [],
  111. isEditActive: false,
  112. editing: {
  113. index: 0,
  114. song: {}
  115. },
  116. video: {
  117. player: null,
  118. paused: false,
  119. settings: function (type) {
  120. switch(type) {
  121. case 'stop':
  122. this.player.stopVideo();
  123. this.paused = true;
  124. break;
  125. case 'pause':
  126. this.player.pauseVideo();
  127. this.paused = true;
  128. break;
  129. case 'play':
  130. this.player.playVideo();
  131. this.paused = false;
  132. break;
  133. case 'skipToLast10Secs':
  134. this.player.seekTo(this.player.getDuration() - 10);
  135. break;
  136. }
  137. }
  138. }
  139. }
  140. },
  141. methods: {
  142. toggleModal: function () {
  143. this.isEditActive = !this.isEditActive;
  144. this.video.settings('stop');
  145. },
  146. edit: function (song, index) {
  147. this.editing = { index, song };
  148. this.video.player.loadVideoById(song._id);
  149. this.isEditActive = true;
  150. },
  151. save: function (song) {
  152. let _this = this;
  153. this.socket.emit('queueSongs.update', song._id, song, function (res) {
  154. if (res.status == 'success' || res.status == 'error') Toast.methods.addToast(res.message, 2000);
  155. _this.toggleModal();
  156. });
  157. },
  158. add: function (song) {
  159. this.socket.emit('queueSongs.remove', song._id);
  160. this.socket.emit('songs.add', song, res => {
  161. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  162. });
  163. },
  164. remove: function (id, index) {
  165. this.songs.splice(index, 1);
  166. this.socket.emit('queueSongs.remove', id, res => {
  167. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  168. });
  169. }
  170. },
  171. ready: function () {
  172. let _this = this;
  173. let socketInterval = setInterval(() => {
  174. if (!!_this.$parent.$parent.socket) {
  175. _this.socket = _this.$parent.$parent.socket;
  176. _this.socket.emit('queueSongs.index', data => {
  177. _this.songs = data;
  178. });
  179. clearInterval(socketInterval);
  180. }
  181. }, 100);
  182. this.video.player = new YT.Player('player', {
  183. height: 315,
  184. width: 560,
  185. videoId: this.editing.song._id,
  186. playerVars: { controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0 },
  187. events: {
  188. 'onStateChange': event => {
  189. if (event.data == 1) {
  190. let youtubeDuration = _this.video.player.getDuration();
  191. youtubeDuration -= _this.editing.song.skipDuration;
  192. if (_this.editing.song.duration > youtubeDuration) this.stopVideo();
  193. }
  194. }
  195. }
  196. });
  197. }
  198. }
  199. </script>
  200. <style lang='scss' scoped>
  201. body {
  202. font-family: 'Roboto', sans-serif;
  203. }
  204. .thumbnail-preview {
  205. display: flex;
  206. margin: 0 auto;
  207. padding: 10px 0 20px 0;
  208. }
  209. .modal-card-body, .modal-card-foot {
  210. border-top: 0;
  211. background-color: rgb(66, 165, 245);
  212. }
  213. .label, h5 {
  214. color: #fff;
  215. font-weight: normal;
  216. }
  217. .video-container {
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. padding: 10px;
  222. }
  223. .save-changes {
  224. color: #fff;
  225. margin-right: 5px;
  226. cursor: pointer;
  227. }
  228. </style>