VerifiedSongs.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <div>
  3. <metadata title="Admin | 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. <div>
  32. <input
  33. type="text"
  34. placeholder="Filter artist checkboxes"
  35. v-model="artistFilterQuery"
  36. />
  37. <label v-for="artist in filteredArtists" :key="artist">
  38. <input
  39. type="checkbox"
  40. :checked="artistFilterSelected.indexOf(artist) !== -1"
  41. @click="toggleArtistSelected(artist)"
  42. />
  43. <span>{{ artist }}</span>
  44. </label>
  45. </div>
  46. <div>
  47. <input
  48. type="text"
  49. placeholder="Filter genre checkboxes"
  50. v-model="genreFilterQuery"
  51. />
  52. <label v-for="genre in filteredGenres" :key="genre">
  53. <input
  54. type="checkbox"
  55. :checked="genreFilterSelected.indexOf(genre) !== -1"
  56. @click="toggleGenreSelected(genre)"
  57. />
  58. <span>{{ genre }}</span>
  59. </label>
  60. </div>
  61. <br />
  62. <table class="table is-striped">
  63. <thead>
  64. <tr>
  65. <td>Thumbnail</td>
  66. <td>Title</td>
  67. <td>Artists</td>
  68. <td>Genres</td>
  69. <td class="likesColumn">
  70. <i class="material-icons thumbLike">thumb_up</i>
  71. </td>
  72. <td class="dislikesColumn">
  73. <i class="material-icons thumbDislike"
  74. >thumb_down</i
  75. >
  76. </td>
  77. <td>ID / Youtube ID</td>
  78. <td>Requested By</td>
  79. <td>Options</td>
  80. </tr>
  81. </thead>
  82. <tbody>
  83. <tr v-for="(song, index) in filteredSongs" :key="index">
  84. <td>
  85. <img
  86. class="song-thumbnail"
  87. :src="song.thumbnail"
  88. onerror="this.src='/assets/notes-transparent.png'"
  89. />
  90. </td>
  91. <td>
  92. <strong>{{ song.title }}</strong>
  93. </td>
  94. <td>{{ song.artists.join(", ") }}</td>
  95. <td>{{ song.genres.join(", ") }}</td>
  96. <td>{{ song.likes }}</td>
  97. <td>{{ song.dislikes }}</td>
  98. <td>
  99. {{ song._id }}
  100. <br />
  101. <a
  102. :href="
  103. 'https://www.youtube.com/watch?v=' +
  104. `${song.youtubeId}`
  105. "
  106. target="_blank"
  107. >
  108. {{ song.youtubeId }}</a
  109. >
  110. </td>
  111. <td>
  112. <user-id-to-username
  113. :user-id="song.requestedBy"
  114. :link="true"
  115. />
  116. </td>
  117. <td class="optionsColumn">
  118. <button
  119. class="button is-primary"
  120. @click="edit(song)"
  121. content="Edit Song"
  122. v-tippy
  123. >
  124. <i class="material-icons">edit</i>
  125. </button>
  126. <confirm
  127. placement="left"
  128. @confirm="remove(song._id, index)"
  129. >
  130. <button
  131. class="button is-danger"
  132. content="Unverify Song"
  133. v-tippy
  134. >
  135. <i class="material-icons">cancel</i>
  136. </button>
  137. </confirm>
  138. </td>
  139. </tr>
  140. </tbody>
  141. </table>
  142. </div>
  143. <edit-song v-if="modals.editSong" song-type="songs" />
  144. <floating-box
  145. id="keyboardShortcutsHelper"
  146. ref="keyboardShortcutsHelper"
  147. >
  148. <template #body>
  149. <div>
  150. <div>
  151. <span class="biggest"><b>Songs page</b></span>
  152. <span
  153. ><b>Arrow keys up/down</b> - Moves between
  154. songs</span
  155. >
  156. <span><b>E</b> - Edit selected song</span>
  157. <span><b>A</b> - Add selected song</span>
  158. <span><b>X</b> - Delete selected song</span>
  159. </div>
  160. <hr />
  161. <div>
  162. <span class="biggest"><b>Edit song modal</b></span>
  163. <span class="bigger"><b>Navigation</b></span>
  164. <span><b>Home</b> - Edit</span>
  165. <span><b>End</b> - Edit</span>
  166. <hr />
  167. <span class="bigger"><b>Player controls</b></span>
  168. <span><b>Numpad up/down</b> - Volume up/down 10%</span>
  169. <span
  170. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  171. 1%</span
  172. >
  173. <span><b>Numpad center</b> - Pause/resume</span>
  174. <span><b>Ctrl + Numpad center</b> - Stop</span>
  175. <span
  176. ><b>Numpad Right</b> - Skip to last 10 seconds</span
  177. >
  178. <hr />
  179. <span class="bigger"><b>Form control</b></span>
  180. <span
  181. ><b>Ctrl + D</b> - Executes purple button in that
  182. input</span
  183. >
  184. <span
  185. ><b>Ctrl + Alt + D</b> - Fill in all Discogs
  186. fields</span
  187. >
  188. <span
  189. ><b>Ctrl + R</b> - Executes red button in that
  190. input</span
  191. >
  192. <span
  193. ><b>Ctrl + Alt + R</b> - Reset duration field</span
  194. >
  195. <hr />
  196. <span class="bigger"><b>Modal control</b></span>
  197. <span><b>Ctrl + S</b> - Save</span>
  198. <span><b>Ctrl + X</b> - Exit</span>
  199. </div>
  200. </div>
  201. </template>
  202. </floating-box>
  203. </div>
  204. </template>
  205. <script>
  206. import { mapState, mapActions, mapGetters } from "vuex";
  207. import Toast from "toasters";
  208. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  209. import FloatingBox from "@/components/FloatingBox.vue";
  210. import Confirm from "@/components/Confirm.vue";
  211. import ScrollAndFetchHandler from "@/mixins/ScrollAndFetchHandler.vue";
  212. import ws from "@/ws";
  213. export default {
  214. components: {
  215. EditSong: () => import("@/components/modals/EditSong.vue"),
  216. UserIdToUsername,
  217. FloatingBox,
  218. Confirm
  219. },
  220. mixins: [ScrollAndFetchHandler],
  221. data() {
  222. return {
  223. searchQuery: "",
  224. artistFilterQuery: "",
  225. artistFilterSelected: [],
  226. genreFilterQuery: "",
  227. genreFilterSelected: [],
  228. editing: {
  229. index: 0,
  230. song: {}
  231. }
  232. };
  233. },
  234. computed: {
  235. filteredSongs() {
  236. return this.songs.filter(
  237. song =>
  238. JSON.stringify(Object.values(song)).indexOf(
  239. this.searchQuery
  240. ) !== -1 &&
  241. (this.artistFilterSelected.length === 0 ||
  242. song.artists.some(
  243. artist =>
  244. this.artistFilterSelected.indexOf(artist) !== -1
  245. )) &&
  246. (this.genreFilterSelected.length === 0 ||
  247. song.genres.some(
  248. genre =>
  249. this.genreFilterSelected.indexOf(genre) !== -1
  250. ))
  251. );
  252. },
  253. artists() {
  254. const artists = [];
  255. this.songs.forEach(song => {
  256. song.artists.forEach(artist => {
  257. if (artists.indexOf(artist) === -1) artists.push(artist);
  258. });
  259. });
  260. return artists.sort();
  261. },
  262. filteredArtists() {
  263. return this.artists
  264. .filter(
  265. artist =>
  266. this.artistFilterSelected.indexOf(artist) !== -1 ||
  267. artist.indexOf(this.artistFilterQuery) !== -1
  268. )
  269. .sort(
  270. (a, b) =>
  271. (this.artistFilterSelected.indexOf(a) === -1 ? 1 : 0) -
  272. (this.artistFilterSelected.indexOf(b) === -1 ? 1 : 0)
  273. );
  274. },
  275. genres() {
  276. const genres = [];
  277. this.songs.forEach(song => {
  278. song.genres.forEach(genre => {
  279. if (genres.indexOf(genre) === -1) genres.push(genre);
  280. });
  281. });
  282. return genres.sort();
  283. },
  284. filteredGenres() {
  285. return this.genres
  286. .filter(
  287. genre =>
  288. this.genreFilterSelected.indexOf(genre) !== -1 ||
  289. genre.indexOf(this.genreFilterQuery) !== -1
  290. )
  291. .sort(
  292. (a, b) =>
  293. (this.genreFilterSelected.indexOf(a) === -1 ? 1 : 0) -
  294. (this.genreFilterSelected.indexOf(b) === -1 ? 1 : 0)
  295. );
  296. },
  297. ...mapState("modalVisibility", {
  298. modals: state => state.modals.admin
  299. }),
  300. ...mapState("admin/verifiedSongs", {
  301. songs: state => state.songs
  302. }),
  303. ...mapGetters({
  304. socket: "websockets/getSocket"
  305. })
  306. },
  307. watch: {
  308. // eslint-disable-next-line func-names
  309. "modals.editSong": function(val) {
  310. if (!val) this.stopVideo();
  311. }
  312. },
  313. mounted() {
  314. this.socket.on("event:admin.verifiedSong.added", res =>
  315. this.addSong(res.data.song)
  316. );
  317. this.socket.on("event:admin.verifiedSong.removed", res =>
  318. this.removeSong(res.data.youtubeId)
  319. );
  320. this.socket.on("event:admin.verifiedSong.updated", res =>
  321. this.updateSong(res.data.song)
  322. );
  323. if (this.socket.readyState === 1) this.init();
  324. ws.onConnect(() => this.init());
  325. if (this.$route.query.songId) {
  326. this.socket.dispatch(
  327. "songs.getSongFromSongId",
  328. this.$route.query.songId,
  329. res => {
  330. if (res.status === "success") {
  331. this.edit(res.data.song);
  332. } else new Toast("Song with that ID not found");
  333. }
  334. );
  335. }
  336. },
  337. methods: {
  338. edit(song) {
  339. this.editSong(song);
  340. this.openModal({ sector: "admin", modal: "editSong" });
  341. },
  342. remove(id) {
  343. // eslint-disable-next-line
  344. const dialogResult = window.confirm(
  345. "Are you sure you want to unverify this song?"
  346. );
  347. if (dialogResult !== true) return;
  348. this.socket.dispatch("songs.unverify", id, res => {
  349. if (res.status === "success") new Toast(res.message);
  350. else new Toast(res.message);
  351. });
  352. },
  353. getSet() {
  354. if (this.isGettingSet) return;
  355. if (this.position >= this.maxPosition) return;
  356. this.isGettingSet = true;
  357. this.socket.dispatch(
  358. "songs.getSet",
  359. this.position,
  360. "verified",
  361. res => {
  362. if (res.status === "success") {
  363. res.data.songs.forEach(song => {
  364. this.addSong(song);
  365. });
  366. this.position += 1;
  367. this.isGettingSet = false;
  368. }
  369. }
  370. );
  371. },
  372. toggleArtistSelected(artist) {
  373. if (this.artistFilterSelected.indexOf(artist) === -1)
  374. this.artistFilterSelected.push(artist);
  375. else
  376. this.artistFilterSelected.splice(
  377. this.artistFilterSelected.indexOf(artist),
  378. 1
  379. );
  380. },
  381. toggleGenreSelected(genre) {
  382. if (this.genreFilterSelected.indexOf(genre) === -1)
  383. this.genreFilterSelected.push(genre);
  384. else
  385. this.genreFilterSelected.splice(
  386. this.genreFilterSelected.indexOf(genre),
  387. 1
  388. );
  389. },
  390. toggleKeyboardShortcutsHelper() {
  391. this.$refs.keyboardShortcutsHelper.toggleBox();
  392. },
  393. resetKeyboardShortcutsHelper() {
  394. this.$refs.keyboardShortcutsHelper.resetBox();
  395. },
  396. init() {
  397. if (this.songs.length > 0)
  398. this.position = Math.ceil(this.songs.length / 15) + 1;
  399. this.socket.dispatch("songs.length", "verified", res => {
  400. if (res.status === "success") {
  401. this.maxPosition = Math.ceil(res.data.length / 15) + 1;
  402. this.getSet();
  403. }
  404. });
  405. this.socket.dispatch("apis.joinAdminRoom", "songs", () => {});
  406. },
  407. ...mapActions("admin/verifiedSongs", [
  408. // "stopVideo",
  409. "addSong",
  410. "removeSong",
  411. "updateSong"
  412. ]),
  413. ...mapActions("modals/editSong", ["editSong", "stopVideo"]),
  414. ...mapActions("modalVisibility", ["openModal", "closeModal"])
  415. }
  416. };
  417. </script>
  418. <style lang="scss" scoped>
  419. .night-mode {
  420. .table {
  421. color: var(--light-grey-2);
  422. background-color: var(--dark-grey-3);
  423. thead tr {
  424. background: var(--dark-grey-3);
  425. td {
  426. color: var(--white);
  427. }
  428. }
  429. tbody tr:hover {
  430. background-color: var(--dark-grey-4) !important;
  431. }
  432. tbody tr:nth-child(even) {
  433. background-color: var(--dark-grey-2);
  434. }
  435. strong {
  436. color: var(--light-grey-2);
  437. }
  438. }
  439. }
  440. body {
  441. font-family: "Hind", sans-serif;
  442. }
  443. .optionsColumn {
  444. width: 100px;
  445. button {
  446. width: 35px;
  447. }
  448. }
  449. .likesColumn,
  450. .dislikesColumn {
  451. width: 40px;
  452. i {
  453. font-size: 20px;
  454. }
  455. .thumbLike {
  456. color: var(--green) !important;
  457. }
  458. .thumbDislike {
  459. color: var(--red) !important;
  460. }
  461. }
  462. .song-thumbnail {
  463. display: block;
  464. max-width: 50px;
  465. margin: 0 auto;
  466. }
  467. td {
  468. vertical-align: middle;
  469. & > div {
  470. display: inline-flex;
  471. }
  472. }
  473. #keyboardShortcutsHelper {
  474. .box-body {
  475. b {
  476. color: var(--black);
  477. }
  478. .biggest {
  479. font-size: 18px;
  480. }
  481. .bigger {
  482. font-size: 16px;
  483. }
  484. span {
  485. display: block;
  486. }
  487. }
  488. }
  489. .is-primary:focus {
  490. background-color: var(--primary-color) !important;
  491. }
  492. </style>