Songs.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 io from "../../../io";
  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.song.added", song => this.addSong(song));
  307. this.socket.on("event:admin.song.removed", songId =>
  308. this.removeSong(songId)
  309. );
  310. this.socket.on("event:admin.song.updated", updatedSong =>
  311. this.updateSong(updatedSong)
  312. );
  313. if (this.socket.readyState === 1) this.init();
  314. io.onConnect(() => this.init());
  315. if (this.$route.query.songId) {
  316. this.socket.dispatch(
  317. "songs.getSongFromMusareId",
  318. this.$route.query.songId,
  319. res => {
  320. if (res.status === "success") {
  321. this.edit(res.data.song);
  322. } else
  323. new Toast({
  324. content: "Song with that ID not found",
  325. timeout: 3000
  326. });
  327. }
  328. );
  329. }
  330. },
  331. methods: {
  332. edit(song) {
  333. // this.editSong({ song, type: "songs" });
  334. this.editingSongId = song._id;
  335. this.openModal({ sector: "admin", modal: "editSong" });
  336. },
  337. remove(id) {
  338. // eslint-disable-next-line
  339. const dialogResult = window.confirm(
  340. "Are you sure you want to delete this song?"
  341. );
  342. if (dialogResult !== true) return;
  343. this.socket.dispatch("songs.remove", id, res => {
  344. if (res.status === "success")
  345. new Toast({ content: res.message, timeout: 4000 });
  346. else new Toast({ content: res.message, timeout: 8000 });
  347. });
  348. },
  349. getSet() {
  350. if (this.isGettingSet) return;
  351. if (this.position >= this.maxPosition) return;
  352. this.isGettingSet = true;
  353. this.socket.dispatch("songs.getSet", this.position, data => {
  354. data.forEach(song => {
  355. this.addSong(song);
  356. });
  357. this.position += 1;
  358. this.isGettingSet = false;
  359. });
  360. },
  361. toggleArtistSelected(artist) {
  362. if (this.artistFilterSelected.indexOf(artist) === -1)
  363. this.artistFilterSelected.push(artist);
  364. else
  365. this.artistFilterSelected.splice(
  366. this.artistFilterSelected.indexOf(artist),
  367. 1
  368. );
  369. },
  370. toggleGenreSelected(genre) {
  371. if (this.genreFilterSelected.indexOf(genre) === -1)
  372. this.genreFilterSelected.push(genre);
  373. else
  374. this.genreFilterSelected.splice(
  375. this.genreFilterSelected.indexOf(genre),
  376. 1
  377. );
  378. },
  379. toggleKeyboardShortcutsHelper() {
  380. this.$refs.keyboardShortcutsHelper.toggleBox();
  381. },
  382. resetKeyboardShortcutsHelper() {
  383. this.$refs.keyboardShortcutsHelper.resetBox();
  384. },
  385. init() {
  386. if (this.songs.length > 0)
  387. this.position = Math.ceil(this.songs.length / 15) + 1;
  388. this.socket.dispatch("songs.length", length => {
  389. this.maxPosition = Math.ceil(length / 15) + 1;
  390. this.getSet();
  391. });
  392. this.socket.dispatch("apis.joinAdminRoom", "songs", () => {});
  393. },
  394. ...mapActions("admin/songs", [
  395. // "stopVideo",
  396. // "editSong",
  397. "addSong",
  398. "removeSong",
  399. "updateSong"
  400. ]),
  401. ...mapActions("modals/editSong", ["stopVideo"]),
  402. ...mapActions("modalVisibility", ["openModal", "closeModal"])
  403. }
  404. };
  405. </script>
  406. <style lang="scss" scoped>
  407. .night-mode {
  408. .table {
  409. color: var(--light-grey-2);
  410. background-color: var(--dark-grey-3);
  411. thead tr {
  412. background: var(--dark-grey-3);
  413. td {
  414. color: var(--white);
  415. }
  416. }
  417. tbody tr:hover {
  418. background-color: var(--dark-grey-4) !important;
  419. }
  420. tbody tr:nth-child(even) {
  421. background-color: var(--dark-grey-2);
  422. }
  423. strong {
  424. color: var(--light-grey-2);
  425. }
  426. }
  427. }
  428. body {
  429. font-family: "Hind", sans-serif;
  430. }
  431. .optionsColumn {
  432. width: 100px;
  433. button {
  434. width: 35px;
  435. }
  436. }
  437. .likesColumn,
  438. .dislikesColumn {
  439. width: 40px;
  440. i {
  441. font-size: 20px;
  442. }
  443. .thumbLike {
  444. color: var(--green) !important;
  445. }
  446. .thumbDislike {
  447. color: var(--red) !important;
  448. }
  449. }
  450. .song-thumbnail {
  451. display: block;
  452. max-width: 50px;
  453. margin: 0 auto;
  454. }
  455. td {
  456. vertical-align: middle;
  457. }
  458. #keyboardShortcutsHelper {
  459. .box-body {
  460. b {
  461. color: var(--black);
  462. }
  463. .biggest {
  464. font-size: 18px;
  465. }
  466. .bigger {
  467. font-size: 16px;
  468. }
  469. span {
  470. display: block;
  471. }
  472. }
  473. }
  474. .is-primary:focus {
  475. background-color: var(--primary-color) !important;
  476. }
  477. </style>