QueueSongs.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div @scroll="handleScroll">
  3. <metadata title="Admin | Queue songs" />
  4. <div class="container">
  5. <p>
  6. <span>Sets loaded: {{ setsLoaded }} / {{ maxSets }}</span>
  7. <br />
  8. <span>Loaded songs: {{ this.songs.length }}</span>
  9. </p>
  10. <input
  11. v-model="searchQuery"
  12. type="text"
  13. class="input"
  14. placeholder="Search for Songs"
  15. />
  16. <button
  17. v-if="!loadAllSongs"
  18. class="button is-primary"
  19. @click="loadAll()"
  20. >
  21. Load all
  22. </button>
  23. <button
  24. class="button is-primary"
  25. @click="toggleKeyboardShortcutsHelper"
  26. @dblclick="resetKeyboardShortcutsHelper"
  27. >
  28. Keyboard shortcuts helper
  29. </button>
  30. <br />
  31. <br />
  32. <table class="table is-striped">
  33. <thead>
  34. <tr>
  35. <td>Thumbnail</td>
  36. <td>Title</td>
  37. <td>Artists</td>
  38. <td>Genres</td>
  39. <td>ID / YouTube ID</td>
  40. <td>Requested By</td>
  41. <td>Options</td>
  42. </tr>
  43. </thead>
  44. <tbody>
  45. <tr
  46. v-for="(song, index) in filteredSongs"
  47. :key="index"
  48. tabindex="0"
  49. @keydown.up.prevent
  50. @keydown.down.prevent
  51. @keyup.up="selectPrevious($event)"
  52. @keyup.down="selectNext($event)"
  53. @keyup.e="edit(song, index)"
  54. @keyup.a="add(song)"
  55. @keyup.x="remove(song._id, index)"
  56. >
  57. <td>
  58. <img
  59. class="song-thumbnail"
  60. :src="song.thumbnail"
  61. onerror="this.src='/assets/notes-transparent.png'"
  62. />
  63. </td>
  64. <td>
  65. <strong>{{ song.title }}</strong>
  66. </td>
  67. <td>{{ song.artists.join(", ") }}</td>
  68. <td>{{ song.genres.join(", ") }}</td>
  69. <td>
  70. {{ song._id }}
  71. <br />
  72. <a
  73. :href="
  74. 'https://www.youtube.com/watch?v=' +
  75. `${song.songId}`
  76. "
  77. target="_blank"
  78. >
  79. {{ song.songId }}</a
  80. >
  81. </td>
  82. <td>
  83. <user-id-to-username
  84. :user-id="song.requestedBy"
  85. :link="true"
  86. />
  87. </td>
  88. <td class="optionsColumn">
  89. <button
  90. class="button is-primary"
  91. @click="edit(song, index)"
  92. >
  93. <i class="material-icons">edit</i>
  94. </button>
  95. <button
  96. class="button is-success"
  97. @click="add(song)"
  98. >
  99. <i class="material-icons">add</i>
  100. </button>
  101. <button
  102. class="button is-danger"
  103. @click="remove(song._id, index)"
  104. >
  105. <i class="material-icons">cancel</i>
  106. </button>
  107. </td>
  108. </tr>
  109. </tbody>
  110. </table>
  111. </div>
  112. <edit-song
  113. v-if="modals.editSong"
  114. :song-id="editingSongId"
  115. song-type="queueSongs"
  116. />
  117. <floating-box
  118. id="keyboardShortcutsHelper"
  119. ref="keyboardShortcutsHelper"
  120. >
  121. <template #body>
  122. <div>
  123. <div>
  124. <span class="biggest"><b>Queue songs page</b></span>
  125. <span
  126. ><b>Arrow keys up/down</b> - Moves between
  127. songs</span
  128. >
  129. <span><b>E</b> - Edit selected song</span>
  130. <span><b>A</b> - Add selected song</span>
  131. <span><b>X</b> - Delete selected song</span>
  132. </div>
  133. <hr />
  134. <div>
  135. <span class="biggest"><b>Edit song modal</b></span>
  136. <span class="bigger"><b>Navigation</b></span>
  137. <span><b>Home</b> - Edit</span>
  138. <span><b>End</b> - Edit</span>
  139. <hr />
  140. <span class="bigger"><b>Player controls</b></span>
  141. <span><b>Numpad up/down</b> - Volume up/down 10%</span>
  142. <span
  143. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  144. 1%</span
  145. >
  146. <span><b>Numpad center</b> - Pause/resume</span>
  147. <span><b>Ctrl + Numpad center</b> - Stop</span>
  148. <span
  149. ><b>Numpad Right</b> - Skip to last 10 seconds</span
  150. >
  151. <hr />
  152. <span class="bigger"><b>Form control</b></span>
  153. <span
  154. ><b>Ctrl + D</b> - Executes purple button in that
  155. input</span
  156. >
  157. <span
  158. ><b>Ctrl + Alt + D</b> - Fill in all Discogs
  159. fields</span
  160. >
  161. <span
  162. ><b>Ctrl + R</b> - Executes red button in that
  163. input</span
  164. >
  165. <span
  166. ><b>Ctrl + Alt + R</b> - Reset duration field</span
  167. >
  168. <hr />
  169. <span class="bigger"><b>Modal control</b></span>
  170. <span><b>Ctrl + S</b> - Save</span>
  171. <span><b>Ctrl + X</b> - Exit</span>
  172. </div>
  173. </div>
  174. </template>
  175. </floating-box>
  176. </div>
  177. </template>
  178. <script>
  179. import { mapState, mapActions, mapGetters } from "vuex";
  180. import Toast from "toasters";
  181. import EditSong from "../../../components/modals/EditSong.vue";
  182. import UserIdToUsername from "../../../components/common/UserIdToUsername.vue";
  183. import FloatingBox from "../../../components/ui/FloatingBox.vue";
  184. import ScrollAndFetchHandler from "../../../mixins/ScrollAndFetchHandler.vue";
  185. import io from "../../../io";
  186. export default {
  187. components: { EditSong, UserIdToUsername, FloatingBox },
  188. mixins: [ScrollAndFetchHandler],
  189. data() {
  190. return {
  191. editingSongId: "",
  192. searchQuery: "",
  193. songs: []
  194. };
  195. },
  196. computed: {
  197. filteredSongs() {
  198. return this.songs.filter(
  199. song =>
  200. JSON.stringify(Object.values(song)).indexOf(
  201. this.searchQuery
  202. ) !== -1
  203. );
  204. },
  205. ...mapState("modalVisibility", {
  206. modals: state => state.modals.admin
  207. }),
  208. ...mapGetters({
  209. socket: "websockets/getSocket"
  210. })
  211. },
  212. watch: {
  213. // eslint-disable-next-line func-names
  214. "modals.editSong": function(value) {
  215. if (value === false) this.stopVideo();
  216. }
  217. },
  218. mounted() {
  219. this.socket.on("event:admin.queueSong.added", queueSong => {
  220. this.songs.push(queueSong);
  221. });
  222. this.socket.on("event:admin.queueSong.removed", songId => {
  223. this.songs = this.songs.filter(song => {
  224. return song._id !== songId;
  225. });
  226. });
  227. this.socket.on("event:admin.queueSong.updated", updatedSong => {
  228. for (let i = 0; i < this.songs.length; i += 1) {
  229. const song = this.songs[i];
  230. if (song._id === updatedSong._id) {
  231. this.$set(this.songs, i, updatedSong);
  232. }
  233. }
  234. });
  235. if (this.socket.readyState === 1) this.init();
  236. io.onConnect(() => this.init());
  237. },
  238. methods: {
  239. edit(song) {
  240. // const newSong = {};
  241. // Object.keys(song).forEach(n => {
  242. // newSong[n] = song[n];
  243. // });
  244. // this.editSong({ index, song: newSong, type: "queueSongs" });
  245. this.editingSongId = song._id;
  246. this.openModal({ sector: "admin", modal: "editSong" });
  247. },
  248. add(song) {
  249. this.socket.dispatch("songs.add", song, res => {
  250. if (res.status === "success")
  251. new Toast({ content: res.message, timeout: 2000 });
  252. else new Toast({ content: res.message, timeout: 4000 });
  253. });
  254. },
  255. remove(id) {
  256. // eslint-disable-next-line
  257. const dialogResult = window.confirm(
  258. "Are you sure you want to delete this song?"
  259. );
  260. if (dialogResult !== true) return;
  261. this.socket.dispatch("queueSongs.remove", id, res => {
  262. if (res.status === "success")
  263. new Toast({ content: res.message, timeout: 2000 });
  264. else new Toast({ content: res.message, timeout: 4000 });
  265. });
  266. },
  267. getSet() {
  268. if (this.isGettingSet) return;
  269. if (this.position >= this.maxPosition) return;
  270. this.isGettingSet = true;
  271. this.socket.dispatch("queueSongs.getSet", this.position, data => {
  272. data.forEach(song => this.songs.push(song));
  273. this.position += 1;
  274. this.isGettingSet = false;
  275. });
  276. },
  277. selectPrevious(event) {
  278. if (event.srcElement.previousElementSibling)
  279. event.srcElement.previousElementSibling.focus();
  280. },
  281. selectNext(event) {
  282. if (event.srcElement.nextElementSibling)
  283. event.srcElement.nextElementSibling.focus();
  284. },
  285. toggleKeyboardShortcutsHelper() {
  286. this.$refs.keyboardShortcutsHelper.toggleBox();
  287. },
  288. resetKeyboardShortcutsHelper() {
  289. this.$refs.keyboardShortcutsHelper.resetBox();
  290. },
  291. init() {
  292. if (this.songs.length > 0)
  293. this.position = Math.ceil(this.songs.length / 15) + 1;
  294. this.socket.dispatch("queueSongs.length", length => {
  295. this.maxPosition = Math.ceil(length / 15) + 1;
  296. this.getSet();
  297. });
  298. this.socket.dispatch("apis.joinAdminRoom", "queue", () => {});
  299. },
  300. // ...mapActions("admin/songs", ["editSong"]),
  301. ...mapActions("modals/editSong", ["stopVideo"]),
  302. ...mapActions("modalVisibility", ["openModal"])
  303. }
  304. };
  305. </script>
  306. <style lang="scss" scoped>
  307. .night-mode {
  308. .table {
  309. color: var(--light-grey-2);
  310. background-color: var(--dark-grey-3);
  311. thead tr {
  312. background: var(--dark-grey-3);
  313. td {
  314. color: var(--white);
  315. }
  316. }
  317. tbody tr:hover {
  318. background-color: var(--dark-grey-4) !important;
  319. }
  320. tbody tr:nth-child(even) {
  321. background-color: var(--dark-grey-2);
  322. }
  323. strong {
  324. color: var(--light-grey-2);
  325. }
  326. }
  327. }
  328. .optionsColumn {
  329. width: 140px;
  330. button {
  331. width: 35px;
  332. }
  333. }
  334. .song-thumbnail {
  335. display: block;
  336. max-width: 50px;
  337. margin: 0 auto;
  338. }
  339. td {
  340. vertical-align: middle;
  341. }
  342. #keyboardShortcutsHelper {
  343. .box-body {
  344. b {
  345. color: var(--black);
  346. }
  347. .biggest {
  348. font-size: 18px;
  349. }
  350. .bigger {
  351. font-size: 16px;
  352. }
  353. span {
  354. display: block;
  355. }
  356. }
  357. }
  358. .is-primary:focus {
  359. background-color: var(--primary-color) !important;
  360. }
  361. </style>