VerifiedSongs.vue 11 KB

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