VerifiedSongs.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <div>
  3. <page-metadata title="Admin | Songs" />
  4. <div class="container">
  5. <p>
  6. <span>Sets loaded: {{ setsLoaded }} / {{ maxSets }}</span>
  7. <br />
  8. <span>Loaded songs: {{ 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. <button class="button is-primary" @click="openModal('requestSong')">
  31. Request song
  32. </button>
  33. <button class="button is-primary" @click="openModal('importAlbum')">
  34. Import album
  35. </button>
  36. <confirm placement="bottom" @confirm="updateAllSongs()">
  37. <button
  38. class="button is-danger"
  39. content="Update all songs"
  40. v-tippy
  41. >
  42. Update all songs
  43. </button>
  44. </confirm>
  45. <br />
  46. <div>
  47. <input
  48. type="text"
  49. placeholder="Filter artist checkboxes"
  50. v-model="artistFilterQuery"
  51. />
  52. <label v-for="artist in filteredArtists" :key="artist">
  53. <input
  54. type="checkbox"
  55. :checked="artistFilterSelected.indexOf(artist) !== -1"
  56. @click="toggleArtistSelected(artist)"
  57. />
  58. <span>{{ artist }}</span>
  59. </label>
  60. </div>
  61. <div>
  62. <input
  63. type="text"
  64. placeholder="Filter genre checkboxes"
  65. v-model="genreFilterQuery"
  66. />
  67. <label v-for="genre in filteredGenres" :key="genre">
  68. <input
  69. type="checkbox"
  70. :checked="genreFilterSelected.indexOf(genre) !== -1"
  71. @click="toggleGenreSelected(genre)"
  72. />
  73. <span>{{ genre }}</span>
  74. </label>
  75. </div>
  76. <br />
  77. <table class="table is-striped">
  78. <thead>
  79. <tr>
  80. <td>Thumbnail</td>
  81. <td>Title</td>
  82. <td>Artists</td>
  83. <td>Genres</td>
  84. <td class="likesColumn">
  85. <i class="material-icons thumbLike">thumb_up</i>
  86. </td>
  87. <td class="dislikesColumn">
  88. <i class="material-icons thumbDislike"
  89. >thumb_down</i
  90. >
  91. </td>
  92. <td>ID / Youtube ID</td>
  93. <td>Requested By</td>
  94. <td>Options</td>
  95. </tr>
  96. </thead>
  97. <tbody>
  98. <tr v-for="song in filteredSongs" :key="song._id">
  99. <td>
  100. <img
  101. class="song-thumbnail"
  102. :src="song.thumbnail"
  103. onerror="this.src='/assets/notes-transparent.png'"
  104. />
  105. </td>
  106. <td>
  107. <strong>{{ song.title }}</strong>
  108. </td>
  109. <td>{{ song.artists.join(", ") }}</td>
  110. <td>{{ song.genres.join(", ") }}</td>
  111. <td>{{ song.likes }}</td>
  112. <td>{{ song.dislikes }}</td>
  113. <td>
  114. {{ song._id }}
  115. <br />
  116. <a
  117. :href="
  118. 'https://www.youtube.com/watch?v=' +
  119. `${song.youtubeId}`
  120. "
  121. target="_blank"
  122. >
  123. {{ song.youtubeId }}</a
  124. >
  125. </td>
  126. <td>
  127. <user-id-to-username
  128. :user-id="song.requestedBy"
  129. :link="true"
  130. />
  131. </td>
  132. <td class="optionsColumn">
  133. <div>
  134. <button
  135. class="button is-primary"
  136. @click="edit(song)"
  137. content="Edit Song"
  138. v-tippy
  139. >
  140. <i class="material-icons">edit</i>
  141. </button>
  142. <confirm
  143. placement="left"
  144. @confirm="unverify(song._id)"
  145. >
  146. <button
  147. class="button is-danger"
  148. content="Unverify Song"
  149. v-tippy
  150. >
  151. <i class="material-icons">cancel</i>
  152. </button>
  153. </confirm>
  154. </div>
  155. </td>
  156. </tr>
  157. </tbody>
  158. </table>
  159. </div>
  160. <import-album v-if="modals.importAlbum" />
  161. <edit-song v-if="modals.editSong" song-type="songs" :key="song._id" />
  162. <request-song v-if="modals.requestSong" />
  163. <floating-box
  164. id="keyboardShortcutsHelper"
  165. ref="keyboardShortcutsHelper"
  166. >
  167. <template #body>
  168. <div>
  169. <div>
  170. <span class="biggest"
  171. ><b>Keyboard shortcuts helper</b></span
  172. >
  173. <span
  174. ><b>Ctrl + /</b> - Toggles this keyboard shortcuts
  175. helper</span
  176. >
  177. <span
  178. ><b>Ctrl + Shift + /</b> - Resets the position of
  179. this keyboard shortcuts helper</span
  180. >
  181. <hr />
  182. </div>
  183. <div>
  184. <span class="biggest"><b>Edit song modal</b></span>
  185. <span class="bigger"><b>Navigation</b></span>
  186. <span><b>Home</b> - Edit</span>
  187. <span><b>End</b> - Edit</span>
  188. <hr />
  189. </div>
  190. <div>
  191. <span class="bigger"><b>Player controls</b></span>
  192. <span class="bigger"
  193. ><i>Don't forget to turn off numlock!</i></span
  194. >
  195. <span><b>Numpad up/down</b> - Volume up/down 10%</span>
  196. <span
  197. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  198. 1%</span
  199. >
  200. <span><b>Numpad center</b> - Pause/resume</span>
  201. <span><b>Ctrl + Numpad center</b> - Stop</span>
  202. <span
  203. ><b>Numpad Right</b> - Skip to last 10 seconds</span
  204. >
  205. <hr />
  206. </div>
  207. <div>
  208. <span class="bigger"><b>Form control</b></span>
  209. <span
  210. ><b>Enter</b> - Executes blue button in that
  211. input</span
  212. >
  213. <span
  214. ><b>Shift + Enter</b> - Executes purple/red button
  215. in that input</span
  216. >
  217. <span
  218. ><b>Ctrl + Alt + D</b> - Fill in all Discogs
  219. fields</span
  220. >
  221. <hr />
  222. </div>
  223. <div>
  224. <span class="bigger"><b>Modal control</b></span>
  225. <span><b>Ctrl + S</b> - Save</span>
  226. <span><b>Ctrl + Alt + S</b> - Save and close</span>
  227. <span
  228. ><b>Ctrl + Alt + V</b> - Save, verify and
  229. close</span
  230. >
  231. <span><b>F4</b> - Close without saving</span>
  232. <hr />
  233. </div>
  234. </div>
  235. </template>
  236. </floating-box>
  237. </div>
  238. </template>
  239. <script>
  240. import { mapState, mapActions, mapGetters } from "vuex";
  241. import { defineAsyncComponent } from "vue";
  242. import Toast from "toasters";
  243. import keyboardShortcuts from "@/keyboardShortcuts";
  244. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  245. import FloatingBox from "@/components/FloatingBox.vue";
  246. import Confirm from "@/components/Confirm.vue";
  247. import ScrollAndFetchHandler from "@/mixins/ScrollAndFetchHandler.vue";
  248. import ws from "@/ws";
  249. export default {
  250. components: {
  251. EditSong: defineAsyncComponent(() =>
  252. import("@/components/modals/EditSong")
  253. ),
  254. ImportAlbum: defineAsyncComponent(() =>
  255. import("@/components/modals/ImportAlbum.vue")
  256. ),
  257. RequestSong: defineAsyncComponent(() =>
  258. import("@/components/modals/RequestSong.vue")
  259. ),
  260. UserIdToUsername,
  261. FloatingBox,
  262. Confirm
  263. },
  264. mixins: [ScrollAndFetchHandler],
  265. data() {
  266. return {
  267. searchQuery: "",
  268. artistFilterQuery: "",
  269. artistFilterSelected: [],
  270. genreFilterQuery: "",
  271. genreFilterSelected: [],
  272. editing: {
  273. index: 0,
  274. song: {}
  275. }
  276. };
  277. },
  278. computed: {
  279. filteredSongs() {
  280. return this.songs.filter(
  281. song =>
  282. JSON.stringify(Object.values(song))
  283. .toLowerCase()
  284. .indexOf(this.searchQuery.toLowerCase()) !== -1 &&
  285. (this.artistFilterSelected.length === 0 ||
  286. song.artists.some(
  287. artist =>
  288. this.artistFilterSelected
  289. .map(artistFilterSelected =>
  290. artistFilterSelected.toLowerCase()
  291. )
  292. .indexOf(artist.toLowerCase()) !== -1
  293. )) &&
  294. (this.genreFilterSelected.length === 0 ||
  295. song.genres.some(
  296. genre =>
  297. this.genreFilterSelected
  298. .map(genreFilterSelected =>
  299. genreFilterSelected.toLowerCase()
  300. )
  301. .indexOf(genre.toLowerCase()) !== -1
  302. ))
  303. );
  304. },
  305. artists() {
  306. const artists = [];
  307. this.songs.forEach(song => {
  308. song.artists.forEach(artist => {
  309. if (artists.indexOf(artist) === -1) artists.push(artist);
  310. });
  311. });
  312. return artists.sort();
  313. },
  314. filteredArtists() {
  315. return this.artists
  316. .filter(
  317. artist =>
  318. this.artistFilterSelected.indexOf(artist) !== -1 ||
  319. artist
  320. .toLowerCase()
  321. .indexOf(this.artistFilterQuery.toLowerCase()) !==
  322. -1
  323. )
  324. .sort(
  325. (a, b) =>
  326. (this.artistFilterSelected.indexOf(a) === -1 ? 1 : 0) -
  327. (this.artistFilterSelected.indexOf(b) === -1 ? 1 : 0)
  328. );
  329. },
  330. genres() {
  331. const genres = [];
  332. this.songs.forEach(song => {
  333. song.genres.forEach(genre => {
  334. if (genres.indexOf(genre) === -1) genres.push(genre);
  335. });
  336. });
  337. return genres.sort();
  338. },
  339. filteredGenres() {
  340. return this.genres
  341. .filter(
  342. genre =>
  343. this.genreFilterSelected.indexOf(genre) !== -1 ||
  344. genre
  345. .toLowerCase()
  346. .indexOf(this.genreFilterQuery.toLowerCase()) !== -1
  347. )
  348. .sort(
  349. (a, b) =>
  350. (this.genreFilterSelected.indexOf(a) === -1 ? 1 : 0) -
  351. (this.genreFilterSelected.indexOf(b) === -1 ? 1 : 0)
  352. );
  353. },
  354. ...mapState("modalVisibility", {
  355. modals: state => state.modals
  356. }),
  357. ...mapState("admin/verifiedSongs", {
  358. songs: state => state.songs
  359. }),
  360. ...mapState("modals/editSong", {
  361. song: state => state.song
  362. }),
  363. ...mapGetters({
  364. socket: "websockets/getSocket"
  365. })
  366. },
  367. mounted() {
  368. this.socket.on("event:admin.verifiedSong.created", res =>
  369. this.addSong(res.data.song)
  370. );
  371. this.socket.on("event:admin.verifiedSong.deleted", res =>
  372. this.removeSong(res.data.songId)
  373. );
  374. this.socket.on("event:admin.verifiedSong.updated", res =>
  375. this.updateSong(res.data.song)
  376. );
  377. ws.onConnect(this.init);
  378. if (this.$route.query.songId) {
  379. this.socket.dispatch(
  380. "songs.getSongFromSongId",
  381. this.$route.query.songId,
  382. res => {
  383. if (res.status === "success") this.edit(res.data.song);
  384. else new Toast("Song with that ID not found");
  385. }
  386. );
  387. }
  388. keyboardShortcuts.registerShortcut(
  389. "verifiedSongs.toggleKeyboardShortcutsHelper",
  390. {
  391. keyCode: 191, // '/' key
  392. ctrl: true,
  393. preventDefault: true,
  394. handler: () => {
  395. this.toggleKeyboardShortcutsHelper();
  396. }
  397. }
  398. );
  399. keyboardShortcuts.registerShortcut(
  400. "verifiedSongs.resetKeyboardShortcutsHelper",
  401. {
  402. keyCode: 191, // '/' key
  403. ctrl: true,
  404. shift: true,
  405. preventDefault: true,
  406. handler: () => {
  407. this.resetKeyboardShortcutsHelper();
  408. }
  409. }
  410. );
  411. },
  412. beforeUnmount() {
  413. const shortcutNames = [
  414. "verifiedSongs.toggleKeyboardShortcutsHelper",
  415. "verifiedSongs.resetKeyboardShortcutsHelper"
  416. ];
  417. shortcutNames.forEach(shortcutName => {
  418. keyboardShortcuts.unregisterShortcut(shortcutName);
  419. });
  420. },
  421. methods: {
  422. edit(song) {
  423. this.editSong(song);
  424. this.openModal("editSong");
  425. },
  426. unverify(id) {
  427. this.socket.dispatch("songs.unverify", id, res => {
  428. new Toast(res.message);
  429. });
  430. },
  431. updateAllSongs() {
  432. new Toast("Updating all songs, this could take a very long time.");
  433. this.socket.dispatch("songs.updateAll", res => {
  434. if (res.status === "success") new Toast(res.message);
  435. else new Toast(res.message);
  436. });
  437. },
  438. getSet() {
  439. if (this.isGettingSet) return;
  440. if (this.position >= this.maxPosition) return;
  441. this.isGettingSet = true;
  442. this.socket.dispatch(
  443. "songs.getSet",
  444. this.position,
  445. "verified",
  446. res => {
  447. if (res.status === "success") {
  448. res.data.songs.forEach(song => {
  449. this.addSong(song);
  450. });
  451. this.position += 1;
  452. this.isGettingSet = false;
  453. }
  454. }
  455. );
  456. },
  457. toggleArtistSelected(artist) {
  458. if (this.artistFilterSelected.indexOf(artist) === -1)
  459. this.artistFilterSelected.push(artist);
  460. else
  461. this.artistFilterSelected.splice(
  462. this.artistFilterSelected.indexOf(artist),
  463. 1
  464. );
  465. },
  466. toggleGenreSelected(genre) {
  467. if (this.genreFilterSelected.indexOf(genre) === -1)
  468. this.genreFilterSelected.push(genre);
  469. else
  470. this.genreFilterSelected.splice(
  471. this.genreFilterSelected.indexOf(genre),
  472. 1
  473. );
  474. },
  475. toggleKeyboardShortcutsHelper() {
  476. this.$refs.keyboardShortcutsHelper.toggleBox();
  477. },
  478. resetKeyboardShortcutsHelper() {
  479. this.$refs.keyboardShortcutsHelper.resetBox();
  480. },
  481. init() {
  482. this.position = 1;
  483. this.maxPosition = 1;
  484. this.resetSongs();
  485. if (this.songs.length > 0)
  486. this.position = Math.ceil(this.songs.length / 15) + 1;
  487. this.socket.dispatch("songs.length", "verified", res => {
  488. if (res.status === "success") {
  489. this.maxPosition = Math.ceil(res.data.length / 15) + 1;
  490. this.getSet();
  491. }
  492. });
  493. this.socket.dispatch("apis.joinAdminRoom", "songs", () => {});
  494. },
  495. ...mapActions("admin/verifiedSongs", [
  496. "resetSongs",
  497. "addSong",
  498. "removeSong",
  499. "updateSong"
  500. ]),
  501. ...mapActions("modals/editSong", ["editSong"]),
  502. ...mapActions("modalVisibility", ["openModal", "closeModal"])
  503. }
  504. };
  505. </script>
  506. <style lang="scss" scoped>
  507. .night-mode {
  508. .table {
  509. color: var(--light-grey-2);
  510. background-color: var(--dark-grey-3);
  511. thead tr {
  512. background: var(--dark-grey-3);
  513. td {
  514. color: var(--white);
  515. }
  516. }
  517. tbody tr:hover {
  518. background-color: var(--dark-grey-4) !important;
  519. }
  520. tbody tr:nth-child(even) {
  521. background-color: var(--dark-grey-2);
  522. }
  523. strong {
  524. color: var(--light-grey-2);
  525. }
  526. }
  527. }
  528. body {
  529. font-family: "Hind", sans-serif;
  530. }
  531. .optionsColumn {
  532. width: 100px;
  533. div {
  534. button {
  535. width: 35px;
  536. &:not(:last-child) {
  537. margin-right: 5px;
  538. }
  539. }
  540. }
  541. }
  542. .likesColumn,
  543. .dislikesColumn {
  544. width: 40px;
  545. i {
  546. font-size: 20px;
  547. }
  548. .thumbLike {
  549. color: var(--green) !important;
  550. }
  551. .thumbDislike {
  552. color: var(--red) !important;
  553. }
  554. }
  555. .song-thumbnail {
  556. display: block;
  557. max-width: 50px;
  558. margin: 0 auto;
  559. }
  560. td {
  561. vertical-align: middle;
  562. & > div {
  563. display: inline-flex;
  564. }
  565. }
  566. #keyboardShortcutsHelper {
  567. .box-body {
  568. .biggest {
  569. font-size: 18px;
  570. }
  571. .bigger {
  572. font-size: 16px;
  573. }
  574. span {
  575. display: block;
  576. }
  577. }
  578. }
  579. .is-primary:focus {
  580. background-color: var(--primary-color) !important;
  581. }
  582. </style>