QueueSongs.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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>Thumbnail</td>
  8. <td>Title</td>
  9. <td>YouTube ID</td>
  10. <td>Artists</td>
  11. <td>Genres</td>
  12. <td>Requested By</td>
  13. <td>Options</td>
  14. </tr>
  15. </thead>
  16. <tbody>
  17. <tr v-for='(index, song) in songs' track-by='$index'>
  18. <td>
  19. <img class='song-thumbnail' :src='song.thumbnail'>
  20. </td>
  21. <td>
  22. <strong>{{ song.title }}</strong>
  23. </td>
  24. <td> {{ song._id }} </td>
  25. <td><span v-for='artist in song.artists'>{{ artist }}</span></td>
  26. <td><span v-for='genre in song.genres'>{{ genre }}</span></td>
  27. <td> {{ song.requestedBy }} </td>
  28. <td>
  29. <a class='button is-primary' @click='edit(song, index)'>Edit</a>
  30. <a class='button is-success' @click='add(song)'>Add</a>
  31. <a class='button is-danger' @click='remove(song._id, index)'>Remove</a>
  32. </td>
  33. </tr>
  34. </tbody>
  35. </table>
  36. </div>
  37. </div>
  38. <div class='modal' :class="{ 'is-active': isEditActive }">
  39. <div class='modal-background'></div>
  40. <div class='modal-card'>
  41. <section class='modal-card-body'>
  42. <h5 class='has-text-centered'>Video Preview</h5>
  43. <div class='video-container'>
  44. <div id='player'></div>
  45. <p class='control has-addons'>
  46. <a class='button'>
  47. <i class='material-icons' @click='video.settings("pause")' v-if='!video.paused'>pause</i>
  48. <i class='material-icons' @click='video.settings("play")' v-else>play_arrow</i>
  49. </a>
  50. <a class='button' @click='video.settings("stop")'>
  51. <i class='material-icons'>stop</i>
  52. </a>
  53. <a class='button' @click='video.settings("skipToLast10Secs")'>
  54. <i class='material-icons'>fast_forward</i>
  55. </a>
  56. </p>
  57. </div>
  58. <h5 class='has-text-centered'>Thumbnail Preview</h5>
  59. <img class='thumbnail-preview' :src='editing.song.thumbnail'>
  60. <label class='label'>Thumbnail URL</label>
  61. <p class='control'>
  62. <input class='input' type='text' v-model='editing.song.thumbnail'>
  63. </p>
  64. <h5 class='has-text-centered'>Edit Info</h5>
  65. <p class='control'>
  66. <label class='checkbox'>
  67. <input type='checkbox' v-model='editing.song.explicit'>
  68. Explicit
  69. </label>
  70. </p>
  71. <label class='label'>Song ID</label>
  72. <p class='control'>
  73. <input class='input' type='text' v-model='editing.song._id'>
  74. </p>
  75. <label class='label'>Song Title</label>
  76. <p class='control'>
  77. <input class='input' type='text' v-model='editing.song.title'>
  78. </p>
  79. <label class='label'>Artists</label>
  80. <div class='control'>
  81. <input v-repeat='editing.song.artists' class='input' type='text' v-model='editing.song.artists[$index]'>
  82. </div>
  83. <label class='label'>Genres</label>
  84. <div class='control'>
  85. <input v-repeat='editing.song.genres' class='input' type='text' v-model='editing.song.genres[$index]'>
  86. </div>
  87. <label class='label'>Song Duration</label>
  88. <p class='control'>
  89. <input class='input' type='text' v-model='editing.song.duration'>
  90. </p>
  91. <label class='label'>Skip Duration</label>
  92. <p class='control'>
  93. <input class='input' type='text' v-model='editing.song.skipDuration'>
  94. </p>
  95. </section>
  96. <footer class='modal-card-foot'>
  97. <a class='button is-success' @click='save(editing.song)'>
  98. <i class='material-icons save-changes'>done</i>
  99. <span>&nbsp;Save</span>
  100. </a>
  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, res => {
  160. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  161. });
  162. this.socket.emit('users.findBySession', res => {
  163. if (res.status == 'success') {
  164. song.acceptedBy = res.data.username;
  165. this.socket.emit('songs.add', song, res => {
  166. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  167. });
  168. }
  169. });
  170. },
  171. remove: function (id, index) {
  172. this.songs.splice(index, 1);
  173. this.socket.emit('queueSongs.remove', id, res => {
  174. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  175. });
  176. }
  177. },
  178. ready: function () {
  179. let _this = this;
  180. let socketInterval = setInterval(() => {
  181. if (!!_this.$parent.$parent.socket) {
  182. _this.socket = _this.$parent.$parent.socket;
  183. _this.socket.emit('queueSongs.index', data => {
  184. _this.songs = data;
  185. });
  186. clearInterval(socketInterval);
  187. }
  188. }, 100);
  189. this.video.player = new YT.Player('player', {
  190. height: 315,
  191. width: 560,
  192. videoId: this.editing.song._id,
  193. playerVars: { controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0 },
  194. events: {
  195. 'onStateChange': event => {
  196. if (event.data == 1) {
  197. let youtubeDuration = _this.video.player.getDuration();
  198. youtubeDuration -= _this.editing.song.skipDuration;
  199. if (_this.editing.song.duration > youtubeDuration) this.stopVideo();
  200. }
  201. }
  202. }
  203. });
  204. }
  205. }
  206. </script>
  207. <style lang='scss' scoped>
  208. body {
  209. font-family: 'Roboto', sans-serif;
  210. }
  211. .thumbnail-preview {
  212. display: flex;
  213. margin: 0 auto;
  214. padding: 10px 0 20px 0;
  215. }
  216. .modal-card-body, .modal-card-foot {
  217. border-top: 0;
  218. background-color: rgb(66, 165, 245);
  219. }
  220. .label, .checkbox, h5 {
  221. color: #fff;
  222. font-weight: normal;
  223. }
  224. .video-container {
  225. display: flex;
  226. flex-direction: column;
  227. align-items: center;
  228. padding: 10px;
  229. }
  230. .save-changes {
  231. color: #fff;
  232. }
  233. .song-thumbnail {
  234. display: block;
  235. max-width: 50px;
  236. margin: 0 auto;
  237. }
  238. td {
  239. vertical-align: middle;
  240. }
  241. </style>