HiddenSongs.vue 14 KB

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