UnverifiedSongs.vue 8.7 KB

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