HiddenSongs.vue 8.0 KB

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