QueueSongs.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div class='container'>
  3. <input type='text' class='input' v-model='searchQuery' placeholder='Search for Songs'>
  4. <br /><br />
  5. <table class='table is-striped'>
  6. <thead>
  7. <tr>
  8. <td>Thumbnail</td>
  9. <td>Title</td>
  10. <td>YouTube ID</td>
  11. <td>Artists</td>
  12. <td>Genres</td>
  13. <td>Requested By</td>
  14. <td>Options</td>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <tr v-for='(index, song) in filteredSongs' track-by='$index'>
  19. <td>
  20. <img class='song-thumbnail' :src='song.thumbnail' onerror="this.src='/assets/notes-transparent.png'">
  21. </td>
  22. <td>
  23. <strong>{{ song.title }}</strong>
  24. </td>
  25. <td>{{ song.songId }}</td>
  26. <td>{{ song.artists.join(', ') }}</td>
  27. <td>{{ song.genres.join(', ') }}</td>
  28. <td>{{ song.requestedBy }}</td>
  29. <td>
  30. <button class='button is-primary' @click='edit(song, index)'>Edit</button>
  31. <button class='button is-success' @click='add(song)'>Add</button>
  32. <button class='button is-danger' @click='remove(song._id, index)'>Remove</button>
  33. </td>
  34. </tr>
  35. </tbody>
  36. </table>
  37. </div>
  38. <nav class="pagination">
  39. <a class="button" href='#' @click='getSet(position - 1)' v-if='position > 1'><i class="material-icons">navigate_before</i></a>
  40. <a class="button" href='#' @click='getSet(position + 1)' v-if='maxPosition > position'><i class="material-icons">navigate_next</i></a>
  41. </nav>
  42. <edit-song v-show='modals.editSong'></edit-song>
  43. </template>
  44. <script>
  45. import { Toast } from 'vue-roaster';
  46. import EditSong from '../Modals/EditSong.vue';
  47. import io from '../../io';
  48. export default {
  49. components: { EditSong },
  50. data() {
  51. return {
  52. position: 1,
  53. maxPosition: 1,
  54. searchQuery: '',
  55. songs: [],
  56. modals: { editSong: false }
  57. }
  58. },
  59. computed: {
  60. filteredSongs: function () {
  61. return this.$eval('songs | filterBy searchQuery');
  62. }
  63. },
  64. watch: {
  65. 'modals.editSong': function (value) {
  66. if (!value) this.$broadcast('stopVideo');
  67. }
  68. },
  69. methods: {
  70. toggleModal: function () {
  71. this.modals.editSong = !this.modals.editSong;
  72. },
  73. getSet: function (position) {
  74. let _this = this;
  75. this.socket.emit('queueSongs.getSet', position, data => {
  76. _this.songs = data;
  77. this.position = position;
  78. });
  79. },
  80. edit: function (song, index) {
  81. this.$broadcast('editSong', song, index, 'queueSongs');
  82. },
  83. add: function (song) {
  84. this.socket.emit('songs.add', song, res => {
  85. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  86. });
  87. },
  88. remove: function (id, index) {
  89. console.log("Removing ", id);
  90. this.socket.emit('queueSongs.remove', id, res => {
  91. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  92. });
  93. },
  94. init: function() {
  95. let _this = this;
  96. _this.socket.emit('queueSongs.index', data => {
  97. _this.songs = data.songs;
  98. _this.maxPosition = Math.round(data.maxLength / 50);
  99. });
  100. _this.socket.emit('apis.joinAdminRoom', 'queue', data => {});
  101. }
  102. },
  103. ready: function () {
  104. let _this = this;
  105. io.getSocket((socket) => {
  106. _this.socket = socket;
  107. if (_this.socket.connected) {
  108. _this.init();
  109. _this.socket.on('event:admin.queueSong.added', queueSong => {
  110. _this.songs.push(queueSong);
  111. });
  112. _this.socket.on('event:admin.queueSong.removed', songId => {
  113. _this.songs = _this.songs.filter(function(song) {
  114. return song._id !== songId;
  115. });
  116. });
  117. _this.socket.on('event:admin.queueSong.updated', updatedSong => {
  118. for (let i = 0; i < _this.songs.length; i++) {
  119. let song = _this.songs[i];
  120. if (song._id === updatedSong._id) {
  121. _this.songs.$set(i, updatedSong);
  122. }
  123. }
  124. });
  125. }
  126. io.onConnect(() => {
  127. _this.init();
  128. });
  129. });
  130. }
  131. }
  132. </script>
  133. <style lang='scss' scoped>
  134. .song-thumbnail {
  135. display: block;
  136. max-width: 50px;
  137. margin: 0 auto;
  138. }
  139. td { vertical-align: middle; }
  140. .is-primary:focus { background-color: #029ce3 !important; }
  141. </style>