UnverifiedSongs.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. <confirm @confirm="hide(song._id, index)">
  106. <button
  107. class="button is-danger"
  108. content="Hide Song"
  109. v-tippy
  110. >
  111. <i class="material-icons">visibility_off</i>
  112. </button>
  113. </confirm>
  114. </td>
  115. </tr>
  116. </tbody>
  117. </table>
  118. </div>
  119. <edit-song v-if="modals.editSong" />
  120. <floating-box
  121. id="keyboardShortcutsHelper"
  122. ref="keyboardShortcutsHelper"
  123. >
  124. <template #body>
  125. <div>
  126. <div>
  127. <span class="biggest"
  128. ><b>Unverified songs page</b></span
  129. >
  130. <span
  131. ><b>Arrow keys up/down</b> - Moves between
  132. songs</span
  133. >
  134. <span><b>E</b> - Edit selected song</span>
  135. <span><b>A</b> - Add selected song</span>
  136. <span><b>X</b> - Delete selected song</span>
  137. </div>
  138. <hr />
  139. <div>
  140. <span class="biggest"><b>Edit song modal</b></span>
  141. <span class="bigger"><b>Navigation</b></span>
  142. <span><b>Home</b> - Edit</span>
  143. <span><b>End</b> - Edit</span>
  144. <hr />
  145. <span class="bigger"><b>Player controls</b></span>
  146. <span><b>Numpad up/down</b> - Volume up/down 10%</span>
  147. <span
  148. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  149. 1%</span
  150. >
  151. <span><b>Numpad center</b> - Pause/resume</span>
  152. <span><b>Ctrl + Numpad center</b> - Stop</span>
  153. <span
  154. ><b>Numpad Right</b> - Skip to last 10 seconds</span
  155. >
  156. <hr />
  157. <span class="bigger"><b>Form control</b></span>
  158. <span
  159. ><b>Ctrl + D</b> - Executes purple button in that
  160. input</span
  161. >
  162. <span
  163. ><b>Ctrl + Alt + D</b> - Fill in all Discogs
  164. fields</span
  165. >
  166. <span
  167. ><b>Ctrl + R</b> - Executes red button in that
  168. input</span
  169. >
  170. <span
  171. ><b>Ctrl + Alt + R</b> - Reset duration field</span
  172. >
  173. <hr />
  174. <span class="bigger"><b>Modal control</b></span>
  175. <span><b>Ctrl + S</b> - Save</span>
  176. <span><b>Ctrl + X</b> - Exit</span>
  177. </div>
  178. </div>
  179. </template>
  180. </floating-box>
  181. </div>
  182. </template>
  183. <script>
  184. import { mapState, mapActions, mapGetters } from "vuex";
  185. import Toast from "toasters";
  186. import UserIdToUsername from "@/components/UserIdToUsername.vue";
  187. import FloatingBox from "@/components/FloatingBox.vue";
  188. import Confirm from "@/components/Confirm.vue";
  189. import ScrollAndFetchHandler from "@/mixins/ScrollAndFetchHandler.vue";
  190. import ws from "@/ws";
  191. export default {
  192. components: {
  193. EditSong: () => import("@/components/modals/EditSong.vue"),
  194. UserIdToUsername,
  195. FloatingBox,
  196. Confirm
  197. },
  198. mixins: [ScrollAndFetchHandler],
  199. data() {
  200. return {
  201. searchQuery: ""
  202. };
  203. },
  204. computed: {
  205. filteredSongs() {
  206. return this.songs.filter(
  207. song =>
  208. JSON.stringify(Object.values(song)).indexOf(
  209. this.searchQuery
  210. ) !== -1
  211. );
  212. },
  213. ...mapState("modalVisibility", {
  214. modals: state => state.modals.admin
  215. }),
  216. ...mapState("admin/unverifiedSongs", {
  217. songs: state => state.songs
  218. }),
  219. ...mapGetters({
  220. socket: "websockets/getSocket"
  221. })
  222. },
  223. watch: {
  224. // eslint-disable-next-line func-names
  225. "modals.editSong": function(value) {
  226. if (value === false) this.stopVideo();
  227. }
  228. },
  229. mounted() {
  230. this.socket.on("event:admin.unverifiedSong.added", song => {
  231. this.addSong(song);
  232. });
  233. this.socket.on("event:admin.unverifiedSong.removed", songId => {
  234. this.removeSong(songId);
  235. });
  236. this.socket.on("event:admin.unverifiedSong.updated", updatedSong => {
  237. this.updateSong(updatedSong);
  238. });
  239. if (this.socket.readyState === 1) this.init();
  240. ws.onConnect(() => this.init());
  241. },
  242. methods: {
  243. edit(song) {
  244. this.editSong(song);
  245. this.openModal({ sector: "admin", modal: "editSong" });
  246. },
  247. verify(song) {
  248. this.socket.dispatch("songs.verify", song.songId, res => {
  249. new Toast(res.message);
  250. });
  251. },
  252. hide(id) {
  253. // eslint-disable-next-line
  254. const dialogResult = window.confirm(
  255. "Are you sure you want to hide this song?"
  256. );
  257. if (dialogResult !== true) return;
  258. this.socket.dispatch("songs.hide", id, res => {
  259. new Toast(res.message);
  260. });
  261. },
  262. getSet() {
  263. if (this.isGettingSet) return;
  264. if (this.position >= this.maxPosition) return;
  265. this.isGettingSet = true;
  266. this.socket.dispatch(
  267. "songs.getSet",
  268. this.position,
  269. "unverified",
  270. data => {
  271. data.forEach(song => {
  272. this.addSong(song);
  273. });
  274. this.position += 1;
  275. this.isGettingSet = false;
  276. }
  277. );
  278. },
  279. selectPrevious(event) {
  280. if (event.srcElement.previousElementSibling)
  281. event.srcElement.previousElementSibling.focus();
  282. },
  283. selectNext(event) {
  284. if (event.srcElement.nextElementSibling)
  285. event.srcElement.nextElementSibling.focus();
  286. },
  287. toggleKeyboardShortcutsHelper() {
  288. this.$refs.keyboardShortcutsHelper.toggleBox();
  289. },
  290. resetKeyboardShortcutsHelper() {
  291. this.$refs.keyboardShortcutsHelper.resetBox();
  292. },
  293. init() {
  294. if (this.songs.length > 0)
  295. this.position = Math.ceil(this.songs.length / 15) + 1;
  296. this.socket.dispatch("songs.length", "unverified", length => {
  297. this.maxPosition = Math.ceil(length / 15) + 1;
  298. this.getSet();
  299. });
  300. this.socket.dispatch(
  301. "apis.joinAdminRoom",
  302. "unverifiedSongs",
  303. () => {}
  304. );
  305. },
  306. ...mapActions("admin/unverifiedSongs", [
  307. // "stopVideo",
  308. "addSong",
  309. "removeSong",
  310. "updateSong"
  311. ]),
  312. ...mapActions("modals/editSong", ["editSong", "stopVideo"]),
  313. ...mapActions("modalVisibility", ["openModal"])
  314. }
  315. };
  316. </script>
  317. <style lang="scss" scoped>
  318. .night-mode {
  319. .table {
  320. color: var(--light-grey-2);
  321. background-color: var(--dark-grey-3);
  322. thead tr {
  323. background: var(--dark-grey-3);
  324. td {
  325. color: var(--white);
  326. }
  327. }
  328. tbody tr:hover {
  329. background-color: var(--dark-grey-4) !important;
  330. }
  331. tbody tr:nth-child(even) {
  332. background-color: var(--dark-grey-2);
  333. }
  334. strong {
  335. color: var(--light-grey-2);
  336. }
  337. }
  338. }
  339. .optionsColumn {
  340. width: 140px;
  341. button {
  342. width: 35px;
  343. }
  344. }
  345. .song-thumbnail {
  346. display: block;
  347. max-width: 50px;
  348. margin: 0 auto;
  349. }
  350. td {
  351. vertical-align: middle;
  352. & > div {
  353. display: inline-flex;
  354. }
  355. }
  356. #keyboardShortcutsHelper {
  357. .box-body {
  358. b {
  359. color: var(--black);
  360. }
  361. .biggest {
  362. font-size: 18px;
  363. }
  364. .bigger {
  365. font-size: 16px;
  366. }
  367. span {
  368. display: block;
  369. }
  370. }
  371. }
  372. .is-primary:focus {
  373. background-color: var(--primary-color) !important;
  374. }
  375. </style>