QueueSongs.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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>
  40. <user-id-to-username
  41. :userId="song.requestedBy"
  42. :link="true"
  43. />
  44. </td>
  45. <td>
  46. <button
  47. class="button is-primary"
  48. @click="edit(song, index)"
  49. >
  50. Edit
  51. </button>
  52. <button
  53. class="button is-success"
  54. @click="add(song)"
  55. >
  56. Add
  57. </button>
  58. <button
  59. class="button is-danger"
  60. @click="remove(song._id, index)"
  61. >
  62. Remove
  63. </button>
  64. </td>
  65. </tr>
  66. </tbody>
  67. </table>
  68. </div>
  69. <nav class="pagination">
  70. <a
  71. v-if="position > 1"
  72. class="button"
  73. href="#"
  74. @click="getSet(position - 1)"
  75. >
  76. <i class="material-icons">navigate_before</i>
  77. </a>
  78. <a
  79. v-if="maxPosition > position"
  80. class="button"
  81. href="#"
  82. @click="getSet(position + 1)"
  83. >
  84. <i class="material-icons">navigate_next</i>
  85. </a>
  86. </nav>
  87. <edit-song v-if="modals.editSong" />
  88. </div>
  89. </template>
  90. <script>
  91. import { mapState, mapActions } from "vuex";
  92. import { Toast } from "vue-roaster";
  93. import EditSong from "../Modals/EditSong.vue";
  94. import UserIdToUsername from "../UserIdToUsername.vue";
  95. import io from "../../io";
  96. export default {
  97. components: { EditSong, UserIdToUsername },
  98. data() {
  99. return {
  100. position: 1,
  101. maxPosition: 1,
  102. searchQuery: "",
  103. songs: []
  104. };
  105. },
  106. computed: {
  107. filteredSongs: function() {
  108. return this.songs;
  109. // return this.songs.filter(song => song.indexOf(song.searchQuery) !== -1);
  110. },
  111. ...mapState("modals", {
  112. modals: state => state.modals.admin
  113. })
  114. },
  115. // watch: {
  116. // "modals.editSong": function(value) {
  117. // console.log(value);
  118. // if (value === false) this.stopVideo();
  119. // }
  120. // },
  121. methods: {
  122. getSet: function(position) {
  123. let _this = this;
  124. this.socket.emit("queueSongs.getSet", position, data => {
  125. _this.songs = data;
  126. this.position = position;
  127. });
  128. },
  129. edit: function(song, index) {
  130. console.log(song, index);
  131. let newSong = {};
  132. for (let n in song) newSong[n] = song[n];
  133. this.editSong({ index, song: newSong, type: "queueSongs" });
  134. this.toggleModal({ sector: "admin", modal: "editSong" });
  135. },
  136. add: function(song) {
  137. this.socket.emit("songs.add", song, res => {
  138. if (res.status == "success")
  139. Toast.methods.addToast(res.message, 2000);
  140. else Toast.methods.addToast(res.message, 4000);
  141. });
  142. },
  143. remove: function(id) {
  144. console.log("Removing ", id);
  145. this.socket.emit("queueSongs.remove", id, res => {
  146. if (res.status == "success")
  147. Toast.methods.addToast(res.message, 2000);
  148. else Toast.methods.addToast(res.message, 4000);
  149. });
  150. },
  151. init: function() {
  152. let _this = this;
  153. _this.socket.emit("queueSongs.index", data => {
  154. _this.songs = data.songs;
  155. _this.maxPosition = Math.round(data.maxLength / 50);
  156. });
  157. _this.socket.emit("apis.joinAdminRoom", "queue", () => {});
  158. },
  159. ...mapActions("admin/songs", ["stopVideo", "editSong"]),
  160. ...mapActions("modals", ["toggleModal"])
  161. },
  162. mounted: function() {
  163. let _this = this;
  164. io.getSocket(socket => {
  165. _this.socket = socket;
  166. if (_this.socket.connected) {
  167. _this.init();
  168. _this.socket.on("event:admin.queueSong.added", queueSong => {
  169. _this.songs.push(queueSong);
  170. });
  171. _this.socket.on("event:admin.queueSong.removed", songId => {
  172. _this.songs = _this.songs.filter(function(song) {
  173. return song._id !== songId;
  174. });
  175. });
  176. _this.socket.on(
  177. "event:admin.queueSong.updated",
  178. updatedSong => {
  179. for (let i = 0; i < _this.songs.length; i++) {
  180. let song = _this.songs[i];
  181. if (song._id === updatedSong._id) {
  182. _this.songs.$set(i, updatedSong);
  183. }
  184. }
  185. }
  186. );
  187. }
  188. io.onConnect(() => {
  189. _this.init();
  190. });
  191. });
  192. }
  193. };
  194. </script>
  195. <style lang="scss" scoped>
  196. .song-thumbnail {
  197. display: block;
  198. max-width: 50px;
  199. margin: 0 auto;
  200. }
  201. td {
  202. vertical-align: middle;
  203. }
  204. .is-primary:focus {
  205. background-color: #029ce3 !important;
  206. }
  207. </style>