QueueSongs.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div>
  3. <div class="container">
  4. <input
  5. v-model="searchQuery"
  6. type="text"
  7. class="input"
  8. placeholder="Search for Songs"
  9. />
  10. <br />
  11. <br />
  12. <table class="table is-striped">
  13. <thead>
  14. <tr>
  15. <td>Thumbnail</td>
  16. <td>Title</td>
  17. <td>YouTube ID</td>
  18. <td>Artists</td>
  19. <td>Genres</td>
  20. <td>Requested By</td>
  21. <td>Options</td>
  22. </tr>
  23. </thead>
  24. <tbody>
  25. <tr v-for="(song, index) in filteredSongs" :key="index">
  26. <td>
  27. <img
  28. class="song-thumbnail"
  29. :src="song.thumbnail"
  30. onerror="this.src='/assets/notes-transparent.png'"
  31. />
  32. </td>
  33. <td>
  34. <strong>{{ song.title }}</strong>
  35. </td>
  36. <td>{{ song.songId }}</td>
  37. <td>{{ song.artists.join(", ") }}</td>
  38. <td>{{ song.genres.join(", ") }}</td>
  39. <td>{{ song.requestedBy }}</td>
  40. <td>
  41. <button
  42. class="button is-primary"
  43. @click="edit(song, index)"
  44. >
  45. Edit
  46. </button>
  47. <button
  48. class="button is-success"
  49. @click="add(song)"
  50. >
  51. Add
  52. </button>
  53. <button
  54. class="button is-danger"
  55. @click="remove(song._id, index)"
  56. >
  57. Remove
  58. </button>
  59. </td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. <nav class="pagination">
  65. <a
  66. v-if="position > 1"
  67. class="button"
  68. href="#"
  69. @click="getSet(position - 1)"
  70. >
  71. <i class="material-icons">navigate_before</i>
  72. </a>
  73. <a
  74. v-if="maxPosition > position"
  75. class="button"
  76. href="#"
  77. @click="getSet(position + 1)"
  78. >
  79. <i class="material-icons">navigate_next</i>
  80. </a>
  81. </nav>
  82. <edit-song v-if="modals.editSong" />
  83. </div>
  84. </template>
  85. <script>
  86. import { mapState, mapActions } from "vuex";
  87. import { Toast } from "vue-roaster";
  88. import EditSong from "../Modals/EditSong.vue";
  89. import io from "../../io";
  90. export default {
  91. components: { EditSong },
  92. data() {
  93. return {
  94. position: 1,
  95. maxPosition: 1,
  96. searchQuery: "",
  97. songs: []
  98. };
  99. },
  100. computed: {
  101. filteredSongs: function() {
  102. return this.songs;
  103. // return this.songs.filter(song => song.indexOf(song.searchQuery) !== -1);
  104. },
  105. ...mapState("modals", {
  106. modals: state => state.modals.admin
  107. })
  108. },
  109. // watch: {
  110. // "modals.editSong": function(value) {
  111. // console.log(value);
  112. // if (value === false) this.stopVideo();
  113. // }
  114. // },
  115. methods: {
  116. getSet: function(position) {
  117. let _this = this;
  118. this.socket.emit("queueSongs.getSet", position, data => {
  119. _this.songs = data;
  120. this.position = position;
  121. });
  122. },
  123. edit: function(song, index) {
  124. console.log(song, index);
  125. let newSong = {};
  126. for (let n in song) newSong[n] = song[n];
  127. this.editSong({ index, song: newSong, type: "queueSongs" });
  128. this.toggleModal({ sector: "admin", modal: "editSong" });
  129. },
  130. add: function(song) {
  131. this.socket.emit("songs.add", song, res => {
  132. if (res.status == "success")
  133. Toast.methods.addToast(res.message, 2000);
  134. else Toast.methods.addToast(res.message, 4000);
  135. });
  136. },
  137. remove: function(id) {
  138. console.log("Removing ", id);
  139. this.socket.emit("queueSongs.remove", id, res => {
  140. if (res.status == "success")
  141. Toast.methods.addToast(res.message, 2000);
  142. else Toast.methods.addToast(res.message, 4000);
  143. });
  144. },
  145. init: function() {
  146. let _this = this;
  147. _this.socket.emit("queueSongs.index", data => {
  148. _this.songs = data.songs;
  149. _this.maxPosition = Math.round(data.maxLength / 50);
  150. });
  151. _this.socket.emit("apis.joinAdminRoom", "queue", () => {});
  152. },
  153. ...mapActions("admin/songs", ["stopVideo", "editSong"]),
  154. ...mapActions("modals", ["toggleModal"])
  155. },
  156. mounted: function() {
  157. let _this = this;
  158. io.getSocket(socket => {
  159. _this.socket = socket;
  160. if (_this.socket.connected) {
  161. _this.init();
  162. _this.socket.on("event:admin.queueSong.added", queueSong => {
  163. _this.songs.push(queueSong);
  164. });
  165. _this.socket.on("event:admin.queueSong.removed", songId => {
  166. _this.songs = _this.songs.filter(function(song) {
  167. return song._id !== songId;
  168. });
  169. });
  170. _this.socket.on(
  171. "event:admin.queueSong.updated",
  172. updatedSong => {
  173. for (let i = 0; i < _this.songs.length; i++) {
  174. let song = _this.songs[i];
  175. if (song._id === updatedSong._id) {
  176. _this.songs.$set(i, updatedSong);
  177. }
  178. }
  179. }
  180. );
  181. }
  182. io.onConnect(() => {
  183. _this.init();
  184. });
  185. });
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .song-thumbnail {
  191. display: block;
  192. max-width: 50px;
  193. margin: 0 auto;
  194. }
  195. td {
  196. vertical-align: middle;
  197. }
  198. .is-primary:focus {
  199. background-color: #029ce3 !important;
  200. }
  201. </style>