UnverifiedSongs.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <div>
  3. <metadata title="Admin | Unverified 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. <br />
  32. <table class="table is-striped">
  33. <thead>
  34. <tr>
  35. <td>Thumbnail</td>
  36. <td>Title</td>
  37. <td>Artists</td>
  38. <td>Genres</td>
  39. <td>ID / YouTube ID</td>
  40. <td>Requested By</td>
  41. <td>Options</td>
  42. </tr>
  43. </thead>
  44. <tbody>
  45. <tr
  46. v-for="(song, index) in filteredSongs"
  47. :key="index"
  48. tabindex="0"
  49. @keydown.up.prevent
  50. @keydown.down.prevent
  51. @keyup.up="selectPrevious($event)"
  52. @keyup.down="selectNext($event)"
  53. @keyup.e="edit(song, index)"
  54. @keyup.a="add(song)"
  55. @keyup.x="remove(song._id, index)"
  56. >
  57. <td>
  58. <img
  59. class="song-thumbnail"
  60. :src="song.thumbnail"
  61. onerror="this.src='/assets/notes-transparent.png'"
  62. />
  63. </td>
  64. <td>
  65. <strong>{{ song.title }}</strong>
  66. </td>
  67. <td>{{ song.artists.join(", ") }}</td>
  68. <td>{{ song.genres.join(", ") }}</td>
  69. <td>
  70. {{ song._id }}
  71. <br />
  72. <a
  73. :href="
  74. 'https://www.youtube.com/watch?v=' +
  75. `${song.songId}`
  76. "
  77. target="_blank"
  78. >
  79. {{ song.songId }}</a
  80. >
  81. </td>
  82. <td>
  83. <user-id-to-username
  84. :user-id="song.requestedBy"
  85. :link="true"
  86. />
  87. </td>
  88. <td class="optionsColumn">
  89. <button
  90. class="button is-primary"
  91. @click="edit(song, index)"
  92. content="Edit Song"
  93. v-tippy
  94. >
  95. <i class="material-icons">edit</i>
  96. </button>
  97. <button
  98. class="button is-success"
  99. @click="verify(song)"
  100. content="Verify Song"
  101. v-tippy
  102. >
  103. <i class="material-icons">check_circle</i>
  104. </button>
  105. <tippy
  106. interactive="true"
  107. placement="top"
  108. theme="confirm"
  109. trigger="click"
  110. >
  111. <template #trigger>
  112. <button
  113. class="button is-danger"
  114. content="Hide Song"
  115. v-tippy
  116. >
  117. <i class="material-icons"
  118. >visibility_off</i
  119. >
  120. </button>
  121. </template>
  122. <a @click="hide(song._id, index)"> Confirm</a>
  123. </tippy>
  124. </td>
  125. </tr>
  126. </tbody>
  127. </table>
  128. </div>
  129. <edit-song v-if="modals.editSong" />
  130. <floating-box
  131. id="keyboardShortcutsHelper"
  132. ref="keyboardShortcutsHelper"
  133. >
  134. <template #body>
  135. <div>
  136. <div>
  137. <span class="biggest"
  138. ><b>Unverified songs page</b></span
  139. >
  140. <span
  141. ><b>Arrow keys up/down</b> - Moves between
  142. songs</span
  143. >
  144. <span><b>E</b> - Edit selected song</span>
  145. <span><b>A</b> - Add selected song</span>
  146. <span><b>X</b> - Delete selected song</span>
  147. </div>
  148. <hr />
  149. <div>
  150. <span class="biggest"><b>Edit song modal</b></span>
  151. <span class="bigger"><b>Navigation</b></span>
  152. <span><b>Home</b> - Edit</span>
  153. <span><b>End</b> - Edit</span>
  154. <hr />
  155. <span class="bigger"><b>Player controls</b></span>
  156. <span><b>Numpad up/down</b> - Volume up/down 10%</span>
  157. <span
  158. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  159. 1%</span
  160. >
  161. <span><b>Numpad center</b> - Pause/resume</span>
  162. <span><b>Ctrl + Numpad center</b> - Stop</span>
  163. <span
  164. ><b>Numpad Right</b> - Skip to last 10 seconds</span
  165. >
  166. <hr />
  167. <span class="bigger"><b>Form control</b></span>
  168. <span
  169. ><b>Ctrl + D</b> - Executes purple button in that
  170. input</span
  171. >
  172. <span
  173. ><b>Ctrl + Alt + D</b> - Fill in all Discogs
  174. fields</span
  175. >
  176. <span
  177. ><b>Ctrl + R</b> - Executes red button in that
  178. input</span
  179. >
  180. <span
  181. ><b>Ctrl + Alt + R</b> - Reset duration field</span
  182. >
  183. <hr />
  184. <span class="bigger"><b>Modal control</b></span>
  185. <span><b>Ctrl + S</b> - Save</span>
  186. <span><b>Ctrl + X</b> - Exit</span>
  187. </div>
  188. </div>
  189. </template>
  190. </floating-box>
  191. </div>
  192. </template>
  193. <script>
  194. import { mapState, mapActions, mapGetters } from "vuex";
  195. import Toast from "toasters";
  196. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  197. import FloatingBox from "@/components/FloatingBox.vue";
  198. import ScrollAndFetchHandler from "@/mixins/ScrollAndFetchHandler.vue";
  199. import ws from "@/ws";
  200. export default {
  201. components: {
  202. EditSong: () => import("@/components/modals/EditSong.vue"),
  203. UserIdToUsername,
  204. FloatingBox
  205. },
  206. mixins: [ScrollAndFetchHandler],
  207. data() {
  208. return {
  209. searchQuery: ""
  210. };
  211. },
  212. computed: {
  213. filteredSongs() {
  214. return this.songs.filter(
  215. song =>
  216. JSON.stringify(Object.values(song)).indexOf(
  217. this.searchQuery
  218. ) !== -1
  219. );
  220. },
  221. ...mapState("modalVisibility", {
  222. modals: state => state.modals.admin
  223. }),
  224. ...mapState("admin/unverifiedSongs", {
  225. songs: state => state.songs
  226. }),
  227. ...mapGetters({
  228. socket: "websockets/getSocket"
  229. })
  230. },
  231. watch: {
  232. // eslint-disable-next-line func-names
  233. "modals.editSong": function(value) {
  234. if (value === false) this.stopVideo();
  235. }
  236. },
  237. mounted() {
  238. this.socket.on("event:admin.unverifiedSong.added", song => {
  239. this.addSong(song);
  240. });
  241. this.socket.on("event:admin.unverifiedSong.removed", songId => {
  242. this.removeSong(songId);
  243. });
  244. this.socket.on("event:admin.unverifiedSong.updated", updatedSong => {
  245. this.updateSong(updatedSong);
  246. });
  247. if (this.socket.readyState === 1) this.init();
  248. ws.onConnect(() => this.init());
  249. },
  250. methods: {
  251. edit(song) {
  252. this.editSong(song);
  253. this.openModal({ sector: "admin", modal: "editSong" });
  254. },
  255. verify(song) {
  256. this.socket.dispatch("songs.verify", song.songId, res => {
  257. new Toast(res.message);
  258. });
  259. },
  260. hide(id) {
  261. // eslint-disable-next-line
  262. const dialogResult = window.confirm(
  263. "Are you sure you want to hide this song?"
  264. );
  265. if (dialogResult !== true) return;
  266. this.socket.dispatch("songs.hide", id, res => {
  267. new Toast(res.message);
  268. });
  269. },
  270. getSet() {
  271. if (this.isGettingSet) return;
  272. if (this.position >= this.maxPosition) return;
  273. this.isGettingSet = true;
  274. this.socket.dispatch(
  275. "songs.getSet",
  276. this.position,
  277. "unverified",
  278. data => {
  279. data.forEach(song => {
  280. this.addSong(song);
  281. });
  282. this.position += 1;
  283. this.isGettingSet = false;
  284. }
  285. );
  286. },
  287. selectPrevious(event) {
  288. if (event.srcElement.previousElementSibling)
  289. event.srcElement.previousElementSibling.focus();
  290. },
  291. selectNext(event) {
  292. if (event.srcElement.nextElementSibling)
  293. event.srcElement.nextElementSibling.focus();
  294. },
  295. toggleKeyboardShortcutsHelper() {
  296. this.$refs.keyboardShortcutsHelper.toggleBox();
  297. },
  298. resetKeyboardShortcutsHelper() {
  299. this.$refs.keyboardShortcutsHelper.resetBox();
  300. },
  301. init() {
  302. if (this.songs.length > 0)
  303. this.position = Math.ceil(this.songs.length / 15) + 1;
  304. this.socket.dispatch("songs.length", "unverified", length => {
  305. this.maxPosition = Math.ceil(length / 15) + 1;
  306. this.getSet();
  307. });
  308. this.socket.dispatch(
  309. "apis.joinAdminRoom",
  310. "unverifiedSongs",
  311. () => {}
  312. );
  313. },
  314. ...mapActions("admin/unverifiedSongs", [
  315. // "stopVideo",
  316. "addSong",
  317. "removeSong",
  318. "updateSong"
  319. ]),
  320. ...mapActions("modals/editSong", ["editSong", "stopVideo"]),
  321. ...mapActions("modalVisibility", ["openModal"])
  322. }
  323. };
  324. </script>
  325. <style lang="scss" scoped>
  326. .night-mode {
  327. .table {
  328. color: var(--light-grey-2);
  329. background-color: var(--dark-grey-3);
  330. thead tr {
  331. background: var(--dark-grey-3);
  332. td {
  333. color: var(--white);
  334. }
  335. }
  336. tbody tr:hover {
  337. background-color: var(--dark-grey-4) !important;
  338. }
  339. tbody tr:nth-child(even) {
  340. background-color: var(--dark-grey-2);
  341. }
  342. strong {
  343. color: var(--light-grey-2);
  344. }
  345. }
  346. }
  347. .optionsColumn {
  348. width: 140px;
  349. button {
  350. width: 35px;
  351. }
  352. }
  353. .song-thumbnail {
  354. display: block;
  355. max-width: 50px;
  356. margin: 0 auto;
  357. }
  358. td {
  359. vertical-align: middle;
  360. & > div {
  361. display: inline-flex;
  362. }
  363. }
  364. #keyboardShortcutsHelper {
  365. .box-body {
  366. b {
  367. color: var(--black);
  368. }
  369. .biggest {
  370. font-size: 18px;
  371. }
  372. .bigger {
  373. font-size: 16px;
  374. }
  375. span {
  376. display: block;
  377. }
  378. }
  379. }
  380. .is-primary:focus {
  381. background-color: var(--primary-color) !important;
  382. }
  383. </style>