QueueSongs.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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._id }}</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. <edit-song v-show='modals.editSong'></edit-song>
  39. </template>
  40. <script>
  41. import { Toast } from 'vue-roaster';
  42. import EditSong from '../Modals/EditSong.vue';
  43. import io from '../../io';
  44. export default {
  45. components: { EditSong },
  46. data() {
  47. return {
  48. searchQuery: '',
  49. songs: [],
  50. modals: { editSong: false }
  51. }
  52. },
  53. computed: {
  54. filteredSongs: function () {
  55. return this.$eval('songs | filterBy searchQuery');
  56. }
  57. },
  58. methods: {
  59. toggleModal: function () {
  60. this.modals.editSong = !this.modals.editSong;
  61. },
  62. edit: function (song, index) {
  63. this.$broadcast('editSong', song, index, 'queueSongs');
  64. },
  65. add: function (song) {
  66. this.socket.emit('songs.add', song, res => {
  67. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  68. });
  69. },
  70. remove: function (id, index) {
  71. this.socket.emit('queueSongs.remove', id, res => {
  72. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  73. });
  74. },
  75. init: function() {
  76. let _this = this;
  77. _this.socket.emit('queueSongs.index', data => {
  78. _this.songs = data;
  79. });
  80. _this.socket.emit('apis.joinAdminRoom', 'queue', data => {});
  81. }
  82. },
  83. ready: function () {
  84. let _this = this;
  85. io.getSocket((socket) => {
  86. _this.socket = socket;
  87. if (_this.socket.connected) {
  88. _this.init();
  89. _this.socket.on('event:admin.queueSong.added', queueSong => {
  90. _this.songs.push(queueSong);
  91. });
  92. _this.socket.on('event:admin.queueSong.removed', songId => {
  93. _this.songs = _this.songs.filter(function(song) {
  94. return song._id !== songId;
  95. });
  96. });
  97. }
  98. io.onConnect(() => {
  99. _this.init();
  100. });
  101. });
  102. }
  103. }
  104. </script>
  105. <style lang='scss' scoped>
  106. .song-thumbnail {
  107. display: block;
  108. max-width: 50px;
  109. margin: 0 auto;
  110. }
  111. td { vertical-align: middle; }
  112. .is-primary:focus { background-color: #029ce3 !important; }
  113. </style>