EditSongs.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <div>
  3. <edit-song
  4. :modal-module-path="`modals/editSongs/${this.modalUuid}/editSong`"
  5. :modal-uuid="this.modalUuid"
  6. :bulk="true"
  7. :flagged="currentSongFlagged"
  8. v-if="currentSong"
  9. @savedSuccess="onSavedSuccess"
  10. @savedError="onSavedError"
  11. @saving="onSaving"
  12. @toggleFlag="toggleFlag"
  13. @nextSong="editNextSong"
  14. @close="onClose"
  15. >
  16. <template #toggleMobileSidebar>
  17. <i
  18. class="material-icons toggle-sidebar-icon"
  19. :content="`${
  20. sidebarMobileActive ? 'Close' : 'Open'
  21. } Edit Queue`"
  22. v-tippy
  23. @click="toggleMobileSidebar()"
  24. >expand_circle_down</i
  25. >
  26. </template>
  27. <template #sidebar>
  28. <div class="sidebar" :class="{ active: sidebarMobileActive }">
  29. <header class="sidebar-head">
  30. <h2 class="sidebar-title is-marginless">Edit Queue</h2>
  31. <i
  32. class="material-icons toggle-sidebar-icon"
  33. :content="`${
  34. sidebarMobileActive ? 'Close' : 'Open'
  35. } Edit Queue`"
  36. v-tippy
  37. @click="toggleMobileSidebar()"
  38. >expand_circle_down</i
  39. >
  40. </header>
  41. <section class="sidebar-body">
  42. <div
  43. class="item"
  44. v-for="(
  45. { status, flagged, song }, index
  46. ) in filteredItems"
  47. :key="song._id"
  48. :ref="`edit-songs-item-${song._id}`"
  49. >
  50. <song-item
  51. :song="song"
  52. :thumbnail="false"
  53. :duration="false"
  54. :disabled-actions="
  55. song.removed ? ['all'] : ['report', 'edit']
  56. "
  57. :class="{
  58. updated: song.updated,
  59. removed: song.removed
  60. }"
  61. >
  62. <template #leftIcon>
  63. <i
  64. v-if="currentSong._id === song._id"
  65. class="material-icons item-icon editing-icon"
  66. content="Currently editing song"
  67. v-tippy="{ theme: 'info' }"
  68. @click="toggleDone(index)"
  69. >edit</i
  70. >
  71. <i
  72. v-else-if="song.removed"
  73. class="material-icons item-icon removed-icon"
  74. content="Song removed"
  75. v-tippy="{ theme: 'info' }"
  76. >delete_forever</i
  77. >
  78. <i
  79. v-else-if="status === 'error'"
  80. class="material-icons item-icon error-icon"
  81. content="Error saving song"
  82. v-tippy="{ theme: 'info' }"
  83. @click="toggleDone(index)"
  84. >error</i
  85. >
  86. <i
  87. v-else-if="status === 'saving'"
  88. class="material-icons item-icon saving-icon"
  89. content="Currently saving song"
  90. v-tippy="{ theme: 'info' }"
  91. >pending</i
  92. >
  93. <i
  94. v-else-if="flagged"
  95. class="material-icons item-icon flag-icon"
  96. content="Song flagged"
  97. v-tippy="{ theme: 'info' }"
  98. @click="toggleDone(index)"
  99. >flag_circle</i
  100. >
  101. <i
  102. v-else-if="status === 'done'"
  103. class="material-icons item-icon done-icon"
  104. content="Song marked complete"
  105. v-tippy="{ theme: 'info' }"
  106. @click="toggleDone(index)"
  107. >check_circle</i
  108. >
  109. <i
  110. v-else-if="status === 'todo'"
  111. class="material-icons item-icon todo-icon"
  112. content="Song marked todo"
  113. v-tippy="{ theme: 'info' }"
  114. @click="toggleDone(index)"
  115. >cancel</i
  116. >
  117. </template>
  118. <template v-if="!song.removed" #actions>
  119. <i
  120. class="material-icons edit-icon"
  121. content="Edit Song"
  122. v-tippy
  123. @click="pickSong(song)"
  124. >
  125. edit
  126. </i>
  127. </template>
  128. <template #tippyActions>
  129. <i
  130. class="material-icons flag-icon"
  131. :class="{ flagged }"
  132. content="Toggle Flag"
  133. v-tippy
  134. @click="toggleFlag(index)"
  135. >
  136. flag_circle
  137. </i>
  138. </template>
  139. </song-item>
  140. </div>
  141. <p v-if="filteredItems.length === 0" class="no-items">
  142. {{
  143. flagFilter
  144. ? "No flagged songs queued"
  145. : "No songs queued"
  146. }}
  147. </p>
  148. </section>
  149. <footer class="sidebar-foot">
  150. <button
  151. @click="toggleFlagFilter()"
  152. class="button is-primary"
  153. >
  154. {{
  155. flagFilter
  156. ? "Show All Songs"
  157. : "Show Only Flagged Songs"
  158. }}
  159. </button>
  160. </footer>
  161. </div>
  162. <div
  163. v-if="sidebarMobileActive"
  164. class="sidebar-overlay"
  165. @click="toggleMobileSidebar()"
  166. ></div>
  167. </template>
  168. </edit-song>
  169. </div>
  170. </template>
  171. <script>
  172. import { mapActions, mapGetters } from "vuex";
  173. import { defineAsyncComponent } from "vue";
  174. import Toast from "toasters";
  175. import { mapModalState, mapModalActions } from "@/vuex_helpers";
  176. import SongItem from "@/components/SongItem.vue";
  177. import editSong from "@/store/modules/modals/editSong";
  178. export default {
  179. components: {
  180. EditSong: defineAsyncComponent(() =>
  181. import("@/components/modals/EditSong")
  182. ),
  183. SongItem
  184. },
  185. props: {
  186. modalUuid: { type: String, default: "" }
  187. },
  188. data() {
  189. return {
  190. items: [],
  191. currentSong: {},
  192. flagFilter: false,
  193. sidebarMobileActive: false
  194. };
  195. },
  196. computed: {
  197. editingItemIndex() {
  198. return this.items.findIndex(
  199. item => item.song._id === this.currentSong._id
  200. );
  201. },
  202. filteredEditingItemIndex() {
  203. return this.filteredItems.findIndex(
  204. item => item.song._id === this.currentSong._id
  205. );
  206. },
  207. filteredItems: {
  208. get() {
  209. return this.items.filter(item =>
  210. this.flagFilter ? item.flagged : true
  211. );
  212. },
  213. set(newItem) {
  214. const index = this.items.findIndex(
  215. item => item.song._id === newItem._id
  216. );
  217. this.item[index] = newItem;
  218. }
  219. },
  220. currentSongFlagged() {
  221. return this.items.find(
  222. item => item.song._id === this.currentSong._id
  223. )?.flagged;
  224. },
  225. ...mapModalState("modals/editSongs/MODAL_UUID", {
  226. songIds: state => state.songIds,
  227. songPrefillData: state => state.songPrefillData
  228. }),
  229. ...mapGetters({
  230. socket: "websockets/getSocket"
  231. })
  232. },
  233. async mounted() {
  234. this.socket.dispatch("apis.joinRoom", "edit-songs");
  235. this.$store.registerModule(
  236. ["modals", "editSongs", this.modalUuid, "editSong"],
  237. editSong
  238. );
  239. this.socket.dispatch("songs.getSongsFromSongIds", this.songIds, res => {
  240. res.data.songs.forEach(song => {
  241. this.items.push({
  242. status: "todo",
  243. flagged: false,
  244. song
  245. });
  246. });
  247. if (this.items.length === 0) {
  248. this.closeThisModal();
  249. new Toast("You can't edit 0 songs.");
  250. } else this.editNextSong();
  251. });
  252. this.socket.on(`event:admin.song.updated`, res => {
  253. const index = this.items
  254. .map(item => item.song._id)
  255. .indexOf(res.data.song._id);
  256. this.items[index].song = {
  257. ...this.items[index].song,
  258. ...res.data.song,
  259. updated: true
  260. };
  261. });
  262. this.socket.on(`event:admin.song.removed`, res => {
  263. const index = this.items
  264. .map(item => item.song._id)
  265. .indexOf(res.data.songId);
  266. this.items[index].song.removed = true;
  267. });
  268. },
  269. beforeUnmount() {
  270. this.socket.dispatch("apis.leaveRoom", "edit-songs");
  271. },
  272. unmounted() {
  273. // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
  274. this.$store.unregisterModule(["modals", "editSongs", this.modalUuid]);
  275. },
  276. methods: {
  277. pickSong(song) {
  278. this.editSong({
  279. songId: song._id,
  280. prefill: this.songPrefillData[song._id]
  281. });
  282. this.currentSong = song;
  283. if (
  284. this.$refs[`edit-songs-item-${song._id}`] &&
  285. this.$refs[`edit-songs-item-${song._id}`][0]
  286. )
  287. this.$refs[`edit-songs-item-${song._id}`][0].scrollIntoView();
  288. },
  289. editNextSong() {
  290. const currentlyEditingSongIndex = this.filteredEditingItemIndex;
  291. let newEditingSongIndex = -1;
  292. const index =
  293. currentlyEditingSongIndex + 1 === this.filteredItems.length
  294. ? 0
  295. : currentlyEditingSongIndex + 1;
  296. for (let i = index; i < this.filteredItems.length; i += 1) {
  297. if (!this.flagFilter || this.filteredItems[i].flagged) {
  298. newEditingSongIndex = i;
  299. break;
  300. }
  301. }
  302. if (newEditingSongIndex > -1) {
  303. const nextSong = this.filteredItems[newEditingSongIndex].song;
  304. this.pickSong(nextSong);
  305. }
  306. },
  307. toggleFlag(songIndex = null) {
  308. if (songIndex && songIndex > -1) {
  309. this.filteredItems[songIndex].flagged =
  310. !this.filteredItems[songIndex].flagged;
  311. new Toast(
  312. `Successfully ${
  313. this.filteredItems[songIndex].flagged
  314. ? "flagged"
  315. : "unflagged"
  316. } song.`
  317. );
  318. } else if (!songIndex && this.editingItemIndex > -1) {
  319. this.items[this.editingItemIndex].flagged =
  320. !this.items[this.editingItemIndex].flagged;
  321. new Toast(
  322. `Successfully ${
  323. this.items[this.editingItemIndex].flagged
  324. ? "flagged"
  325. : "unflagged"
  326. } song.`
  327. );
  328. }
  329. },
  330. onSavedSuccess(songId) {
  331. const itemIndex = this.items.findIndex(
  332. item => item.song._id === songId
  333. );
  334. if (itemIndex > -1) {
  335. this.items[itemIndex].status = "done";
  336. this.items[itemIndex].flagged = false;
  337. }
  338. },
  339. onSavedError(songId) {
  340. const itemIndex = this.items.findIndex(
  341. item => item.song._id === songId
  342. );
  343. if (itemIndex > -1) this.items[itemIndex].status = "error";
  344. },
  345. onSaving(songId) {
  346. const itemIndex = this.items.findIndex(
  347. item => item.song._id === songId
  348. );
  349. if (itemIndex > -1) this.items[itemIndex].status = "saving";
  350. },
  351. toggleDone(index, overwrite = null) {
  352. const { status } = this.filteredItems[index];
  353. if (status === "done" && overwrite !== "done")
  354. this.filteredItems[index].status = "todo";
  355. else {
  356. this.filteredItems[index].status = "done";
  357. this.filteredItems[index].flagged = false;
  358. }
  359. },
  360. toggleFlagFilter() {
  361. this.flagFilter = !this.flagFilter;
  362. },
  363. toggleMobileSidebar() {
  364. this.sidebarMobileActive = !this.sidebarMobileActive;
  365. },
  366. confirmAction({ message, action, params }) {
  367. this.openModal({
  368. modal: "confirm",
  369. data: {
  370. message,
  371. action,
  372. params,
  373. onCompleted: this.handleConfirmed
  374. }
  375. });
  376. },
  377. handleConfirmed({ action, params }) {
  378. if (typeof this[action] === "function") {
  379. if (params) this[action](params);
  380. else this[action]();
  381. }
  382. },
  383. onClose() {
  384. const doneItems = this.items.filter(
  385. item => item.status === "done"
  386. ).length;
  387. const flaggedItems = this.items.filter(item => item.flagged).length;
  388. const notDoneItems = this.items.length - doneItems;
  389. if (doneItems > 0 && notDoneItems > 0)
  390. this.confirmAction({
  391. message:
  392. "You have songs which are not done yet. Are you sure you want to stop editing songs?",
  393. action: "closeThisModal",
  394. params: null
  395. });
  396. else if (flaggedItems > 0)
  397. this.confirmAction({
  398. message:
  399. "You have songs which are flagged. Are you sure you want to stop editing songs?",
  400. action: "closeThisModal",
  401. params: null
  402. });
  403. else this.closeThisModal();
  404. },
  405. closeThisModal() {
  406. this.closeCurrentModal();
  407. },
  408. ...mapActions("modalVisibility", ["openModal", "closeCurrentModal"]),
  409. ...mapModalActions("modals/editSongs/MODAL_UUID/editSong", [
  410. "editSong"
  411. ]),
  412. ...mapModalActions("modals/editSongs/MODAL_UUID", ["resetSongs"])
  413. }
  414. };
  415. </script>
  416. <style lang="less" scoped>
  417. .night-mode .sidebar {
  418. .sidebar-head,
  419. .sidebar-foot {
  420. background-color: var(--dark-grey-3);
  421. border: none;
  422. }
  423. .sidebar-body {
  424. background-color: var(--dark-grey-4) !important;
  425. }
  426. .sidebar-head .toggle-sidebar-icon.material-icons,
  427. .sidebar-title {
  428. color: var(--white);
  429. }
  430. p,
  431. label,
  432. td,
  433. th {
  434. color: var(--light-grey-2) !important;
  435. }
  436. h1,
  437. h2,
  438. h3,
  439. h4,
  440. h5,
  441. h6 {
  442. color: var(--white) !important;
  443. }
  444. }
  445. .toggle-sidebar-icon {
  446. display: none;
  447. }
  448. .sidebar {
  449. width: 100%;
  450. max-width: 350px;
  451. z-index: 2000;
  452. display: flex;
  453. flex-direction: column;
  454. position: relative;
  455. height: 100%;
  456. max-height: calc(100vh - 40px);
  457. overflow: auto;
  458. margin-right: 8px;
  459. border-radius: @border-radius;
  460. .sidebar-head,
  461. .sidebar-foot {
  462. display: flex;
  463. flex-shrink: 0;
  464. position: relative;
  465. justify-content: flex-start;
  466. align-items: center;
  467. padding: 20px;
  468. background-color: var(--light-grey);
  469. }
  470. .sidebar-head {
  471. border-bottom: 1px solid var(--light-grey-2);
  472. border-radius: @border-radius @border-radius 0 0;
  473. .sidebar-title {
  474. display: flex;
  475. flex: 1;
  476. margin: 0;
  477. font-size: 26px;
  478. font-weight: 600;
  479. }
  480. }
  481. .sidebar-body {
  482. background-color: var(--white);
  483. display: flex;
  484. flex-direction: column;
  485. row-gap: 8px;
  486. flex: 1;
  487. overflow: auto;
  488. padding: 10px;
  489. .item {
  490. display: flex;
  491. flex-direction: row;
  492. align-items: center;
  493. column-gap: 8px;
  494. :deep(.song-item) {
  495. .item-icon {
  496. margin-right: 10px;
  497. cursor: pointer;
  498. }
  499. .removed-icon,
  500. .error-icon {
  501. color: var(--red);
  502. }
  503. .saving-icon,
  504. .todo-icon,
  505. .editing-icon {
  506. color: var(--primary-color);
  507. }
  508. .done-icon {
  509. color: var(--green);
  510. }
  511. .flag-icon {
  512. color: var(--orange);
  513. &.flagged {
  514. color: var(--grey);
  515. }
  516. }
  517. &.removed {
  518. filter: grayscale(100%);
  519. cursor: not-allowed;
  520. user-select: none;
  521. }
  522. }
  523. }
  524. .no-items {
  525. text-align: center;
  526. font-size: 18px;
  527. }
  528. }
  529. .sidebar-foot {
  530. border-top: 1px solid var(--light-grey-2);
  531. border-radius: 0 0 @border-radius @border-radius;
  532. .button {
  533. flex: 1;
  534. }
  535. }
  536. .sidebar-overlay {
  537. display: none;
  538. }
  539. }
  540. @media only screen and (max-width: 1580px) {
  541. .toggle-sidebar-icon {
  542. display: flex;
  543. margin-right: 5px;
  544. transform: rotate(90deg);
  545. cursor: pointer;
  546. }
  547. .sidebar {
  548. display: none;
  549. &.active {
  550. display: flex;
  551. position: absolute;
  552. z-index: 2010;
  553. top: 20px;
  554. left: 20px;
  555. .sidebar-head .toggle-sidebar-icon {
  556. display: flex;
  557. margin-left: 5px;
  558. transform: rotate(-90deg);
  559. }
  560. }
  561. }
  562. .sidebar-overlay {
  563. display: flex;
  564. position: absolute;
  565. z-index: 2009;
  566. top: 0;
  567. left: 0;
  568. right: 0;
  569. bottom: 0;
  570. background-color: rgba(10, 10, 10, 0.85);
  571. }
  572. }
  573. </style>