VerifiedSongs.vue 14 KB

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