Songs.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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>Artists</td>
  18. <td>Genres</td>
  19. <td class="likesColumn">
  20. <i class="material-icons thumbLike">thumb_up</i>
  21. </td>
  22. <td class="dislikesColumn">
  23. <i class="material-icons thumbDislike"
  24. >thumb_down</i
  25. >
  26. </td>
  27. <td>ID / Youtube ID</td>
  28. <td>Requested By</td>
  29. <td>Options</td>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. <tr v-for="(song, index) in filteredSongs" :key="index">
  34. <td>
  35. <img
  36. class="song-thumbnail"
  37. :src="song.thumbnail"
  38. onerror="this.src='/assets/notes-transparent.png'"
  39. />
  40. </td>
  41. <td>
  42. <strong>{{ song.title }}</strong>
  43. </td>
  44. <td>{{ song.artists.join(", ") }}</td>
  45. <td>{{ song.genres.join(", ") }}</td>
  46. <td>{{ song.likes }}</td>
  47. <td>{{ song.dislikes }}</td>
  48. <td>
  49. {{ song._id }}
  50. <br />
  51. <a
  52. :href="
  53. 'https://www.youtube.com/watch?v=' +
  54. `${song.songId}`
  55. "
  56. target="_blank"
  57. >
  58. {{ song.songId }}</a
  59. >
  60. </td>
  61. <td>
  62. <user-id-to-username
  63. :userId="song.requestedBy"
  64. :link="true"
  65. />
  66. </td>
  67. <td class="optionsColumn">
  68. <button
  69. class="button is-primary"
  70. @click="edit(song)"
  71. >
  72. <i class="material-icons">edit</i>
  73. </button>
  74. <button
  75. class="button is-danger"
  76. @click="remove(song._id, index)"
  77. >
  78. <i class="material-icons">cancel</i>
  79. </button>
  80. </td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. </div>
  85. <edit-song v-if="modals.editSong" />
  86. </div>
  87. </template>
  88. <script>
  89. import { mapState, mapActions } from "vuex";
  90. import { Toast } from "vue-roaster";
  91. import EditSong from "../Modals/EditSong.vue";
  92. import UserIdToUsername from "../UserIdToUsername.vue";
  93. import io from "../../io";
  94. export default {
  95. components: { EditSong, UserIdToUsername },
  96. data() {
  97. return {
  98. position: 1,
  99. maxPosition: 1,
  100. searchQuery: "",
  101. editing: {
  102. index: 0,
  103. song: {}
  104. }
  105. };
  106. },
  107. computed: {
  108. filteredSongs() {
  109. return this.songs.filter(
  110. song =>
  111. JSON.stringify(Object.values(song)).indexOf(
  112. this.searchQuery
  113. ) !== -1
  114. );
  115. },
  116. ...mapState("modals", {
  117. modals: state => state.modals.admin
  118. }),
  119. ...mapState("admin/songs", {
  120. songs: state => state.songs
  121. })
  122. },
  123. watch: {
  124. "modals.editSong": val => {
  125. if (!val) this.stopVideo();
  126. }
  127. },
  128. methods: {
  129. edit(song) {
  130. this.editSong({ song, type: "songs" });
  131. this.openModal({ sector: "admin", modal: "editSong" });
  132. },
  133. remove(id) {
  134. this.socket.emit("songs.remove", id, res => {
  135. if (res.status === "success")
  136. Toast.methods.addToast(res.message, 4000);
  137. else Toast.methods.addToast(res.message, 8000);
  138. });
  139. },
  140. getSet() {
  141. this.socket.emit("songs.getSet", this.position, data => {
  142. data.forEach(song => {
  143. this.addSong(song);
  144. });
  145. this.position += 1;
  146. if (this.maxPosition > this.position - 1) this.getSet();
  147. });
  148. },
  149. init() {
  150. this.socket.emit("songs.length", length => {
  151. this.maxPosition = Math.ceil(length / 15);
  152. this.getSet();
  153. });
  154. this.socket.emit("apis.joinAdminRoom", "songs", () => {});
  155. },
  156. ...mapActions("admin/songs", [
  157. "stopVideo",
  158. "editSong",
  159. "addSong",
  160. "removeSong",
  161. "updateSong"
  162. ]),
  163. ...mapActions("modals", ["openModal", "closeModal"])
  164. },
  165. mounted() {
  166. io.getSocket(socket => {
  167. this.socket = socket;
  168. this.socket.on("event:admin.song.added", song => {
  169. this.addSong(song);
  170. });
  171. this.socket.on("event:admin.song.removed", songId => {
  172. this.removeSong(songId);
  173. });
  174. this.socket.on("event:admin.song.updated", updatedSong => {
  175. this.updateSong(updatedSong);
  176. });
  177. if (this.socket.connected) {
  178. this.init();
  179. }
  180. io.onConnect(() => {
  181. this.init();
  182. });
  183. });
  184. if (this.$route.query.id) {
  185. this.socket.emit("songs.getSong", this.$route.query.id, res => {
  186. if (res.status === "success") {
  187. this.edit(res.data);
  188. this.closeModal({ sector: "admin", modal: "viewReport" });
  189. } else
  190. Toast.methods.addToast("Song with that ID not found", 3000);
  191. });
  192. }
  193. }
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. @import "styles/global.scss";
  198. body {
  199. font-family: "Roboto", sans-serif;
  200. }
  201. .optionsColumn {
  202. width: 100px;
  203. button {
  204. width: 35px;
  205. }
  206. }
  207. .likesColumn,
  208. .dislikesColumn {
  209. width: 40px;
  210. i {
  211. font-size: 20px;
  212. }
  213. .thumbLike {
  214. color: $green !important;
  215. }
  216. .thumbDislike {
  217. color: $red !important;
  218. }
  219. }
  220. .song-thumbnail {
  221. display: block;
  222. max-width: 50px;
  223. margin: 0 auto;
  224. }
  225. td {
  226. vertical-align: middle;
  227. }
  228. .is-primary:focus {
  229. background-color: $primary-color !important;
  230. }
  231. </style>