EditSongs.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <div>
  3. <edit-song
  4. :modal-module-path="`modals/editSongs/${modalUuid}/editSong`"
  5. :modal-uuid="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(
  253. `event:admin.song.updated`,
  254. res => {
  255. const index = this.items
  256. .map(item => item.song._id)
  257. .indexOf(res.data.song._id);
  258. this.items[index].song = {
  259. ...this.items[index].song,
  260. ...res.data.song,
  261. updated: true
  262. };
  263. },
  264. { modalUuid: this.modalUuid }
  265. );
  266. this.socket.on(
  267. `event:admin.song.removed`,
  268. res => {
  269. const index = this.items
  270. .map(item => item.song._id)
  271. .indexOf(res.data.songId);
  272. this.items[index].song.removed = true;
  273. },
  274. { modalUuid: this.modalUuid }
  275. );
  276. },
  277. beforeUnmount() {
  278. this.socket.dispatch("apis.leaveRoom", "edit-songs");
  279. },
  280. unmounted() {
  281. // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
  282. this.$store.unregisterModule(["modals", "editSongs", this.modalUuid]);
  283. },
  284. methods: {
  285. pickSong(song) {
  286. this.editSong({
  287. songId: song._id,
  288. prefill: this.songPrefillData[song._id]
  289. });
  290. this.currentSong = song;
  291. if (
  292. this.$refs[`edit-songs-item-${song._id}`] &&
  293. this.$refs[`edit-songs-item-${song._id}`][0]
  294. )
  295. this.$refs[`edit-songs-item-${song._id}`][0].scrollIntoView();
  296. },
  297. editNextSong() {
  298. const currentlyEditingSongIndex = this.filteredEditingItemIndex;
  299. let newEditingSongIndex = -1;
  300. const index =
  301. currentlyEditingSongIndex + 1 === this.filteredItems.length
  302. ? 0
  303. : currentlyEditingSongIndex + 1;
  304. for (let i = index; i < this.filteredItems.length; i += 1) {
  305. if (!this.flagFilter || this.filteredItems[i].flagged) {
  306. newEditingSongIndex = i;
  307. break;
  308. }
  309. }
  310. if (newEditingSongIndex > -1) {
  311. const nextSong = this.filteredItems[newEditingSongIndex].song;
  312. this.pickSong(nextSong);
  313. }
  314. },
  315. toggleFlag(songIndex = null) {
  316. if (songIndex && songIndex > -1) {
  317. this.filteredItems[songIndex].flagged =
  318. !this.filteredItems[songIndex].flagged;
  319. new Toast(
  320. `Successfully ${
  321. this.filteredItems[songIndex].flagged
  322. ? "flagged"
  323. : "unflagged"
  324. } song.`
  325. );
  326. } else if (!songIndex && this.editingItemIndex > -1) {
  327. this.items[this.editingItemIndex].flagged =
  328. !this.items[this.editingItemIndex].flagged;
  329. new Toast(
  330. `Successfully ${
  331. this.items[this.editingItemIndex].flagged
  332. ? "flagged"
  333. : "unflagged"
  334. } song.`
  335. );
  336. }
  337. },
  338. onSavedSuccess(songId) {
  339. const itemIndex = this.items.findIndex(
  340. item => item.song._id === songId
  341. );
  342. if (itemIndex > -1) {
  343. this.items[itemIndex].status = "done";
  344. this.items[itemIndex].flagged = false;
  345. }
  346. },
  347. onSavedError(songId) {
  348. const itemIndex = this.items.findIndex(
  349. item => item.song._id === songId
  350. );
  351. if (itemIndex > -1) this.items[itemIndex].status = "error";
  352. },
  353. onSaving(songId) {
  354. const itemIndex = this.items.findIndex(
  355. item => item.song._id === songId
  356. );
  357. if (itemIndex > -1) this.items[itemIndex].status = "saving";
  358. },
  359. toggleDone(index, overwrite = null) {
  360. const { status } = this.filteredItems[index];
  361. if (status === "done" && overwrite !== "done")
  362. this.filteredItems[index].status = "todo";
  363. else {
  364. this.filteredItems[index].status = "done";
  365. this.filteredItems[index].flagged = false;
  366. }
  367. },
  368. toggleFlagFilter() {
  369. this.flagFilter = !this.flagFilter;
  370. },
  371. toggleMobileSidebar() {
  372. this.sidebarMobileActive = !this.sidebarMobileActive;
  373. },
  374. confirmAction({ message, action, params }) {
  375. this.openModal({
  376. modal: "confirm",
  377. data: {
  378. message,
  379. action,
  380. params,
  381. onCompleted: this.handleConfirmed
  382. }
  383. });
  384. },
  385. handleConfirmed({ action, params }) {
  386. if (typeof this[action] === "function") {
  387. if (params) this[action](params);
  388. else this[action]();
  389. }
  390. },
  391. onClose() {
  392. const doneItems = this.items.filter(
  393. item => item.status === "done"
  394. ).length;
  395. const flaggedItems = this.items.filter(item => item.flagged).length;
  396. const notDoneItems = this.items.length - doneItems;
  397. if (doneItems > 0 && notDoneItems > 0)
  398. this.confirmAction({
  399. message:
  400. "You have songs which are not done yet. Are you sure you want to stop editing songs?",
  401. action: "closeThisModal",
  402. params: null
  403. });
  404. else if (flaggedItems > 0)
  405. this.confirmAction({
  406. message:
  407. "You have songs which are flagged. Are you sure you want to stop editing songs?",
  408. action: "closeThisModal",
  409. params: null
  410. });
  411. else this.closeThisModal();
  412. },
  413. closeThisModal() {
  414. this.closeCurrentModal();
  415. },
  416. ...mapActions("modalVisibility", ["openModal", "closeCurrentModal"]),
  417. ...mapModalActions("modals/editSongs/MODAL_UUID/editSong", [
  418. "editSong"
  419. ]),
  420. ...mapModalActions("modals/editSongs/MODAL_UUID", ["resetSongs"])
  421. }
  422. };
  423. </script>
  424. <style lang="less" scoped>
  425. .night-mode .sidebar {
  426. .sidebar-head,
  427. .sidebar-foot {
  428. background-color: var(--dark-grey-3);
  429. border: none;
  430. }
  431. .sidebar-body {
  432. background-color: var(--dark-grey-4) !important;
  433. }
  434. .sidebar-head .toggle-sidebar-icon.material-icons,
  435. .sidebar-title {
  436. color: var(--white);
  437. }
  438. p,
  439. label,
  440. td,
  441. th {
  442. color: var(--light-grey-2) !important;
  443. }
  444. h1,
  445. h2,
  446. h3,
  447. h4,
  448. h5,
  449. h6 {
  450. color: var(--white) !important;
  451. }
  452. }
  453. .toggle-sidebar-icon {
  454. display: none;
  455. }
  456. .sidebar {
  457. width: 100%;
  458. max-width: 350px;
  459. z-index: 2000;
  460. display: flex;
  461. flex-direction: column;
  462. position: relative;
  463. height: 100%;
  464. max-height: calc(100vh - 40px);
  465. overflow: auto;
  466. margin-right: 8px;
  467. border-radius: @border-radius;
  468. .sidebar-head,
  469. .sidebar-foot {
  470. display: flex;
  471. flex-shrink: 0;
  472. position: relative;
  473. justify-content: flex-start;
  474. align-items: center;
  475. padding: 20px;
  476. background-color: var(--light-grey);
  477. }
  478. .sidebar-head {
  479. border-bottom: 1px solid var(--light-grey-2);
  480. border-radius: @border-radius @border-radius 0 0;
  481. .sidebar-title {
  482. display: flex;
  483. flex: 1;
  484. margin: 0;
  485. font-size: 26px;
  486. font-weight: 600;
  487. }
  488. }
  489. .sidebar-body {
  490. background-color: var(--white);
  491. display: flex;
  492. flex-direction: column;
  493. row-gap: 8px;
  494. flex: 1;
  495. overflow: auto;
  496. padding: 10px;
  497. .item {
  498. display: flex;
  499. flex-direction: row;
  500. align-items: center;
  501. column-gap: 8px;
  502. :deep(.song-item) {
  503. .item-icon {
  504. margin-right: 10px;
  505. cursor: pointer;
  506. }
  507. .removed-icon,
  508. .error-icon {
  509. color: var(--red);
  510. }
  511. .saving-icon,
  512. .todo-icon,
  513. .editing-icon {
  514. color: var(--primary-color);
  515. }
  516. .done-icon {
  517. color: var(--green);
  518. }
  519. .flag-icon {
  520. color: var(--orange);
  521. &.flagged {
  522. color: var(--grey);
  523. }
  524. }
  525. &.removed {
  526. filter: grayscale(100%);
  527. cursor: not-allowed;
  528. user-select: none;
  529. }
  530. }
  531. }
  532. .no-items {
  533. text-align: center;
  534. font-size: 18px;
  535. }
  536. }
  537. .sidebar-foot {
  538. border-top: 1px solid var(--light-grey-2);
  539. border-radius: 0 0 @border-radius @border-radius;
  540. .button {
  541. flex: 1;
  542. }
  543. }
  544. .sidebar-overlay {
  545. display: none;
  546. }
  547. }
  548. @media only screen and (max-width: 1580px) {
  549. .toggle-sidebar-icon {
  550. display: flex;
  551. margin-right: 5px;
  552. transform: rotate(90deg);
  553. cursor: pointer;
  554. }
  555. .sidebar {
  556. display: none;
  557. &.active {
  558. display: flex;
  559. position: absolute;
  560. z-index: 2010;
  561. top: 20px;
  562. left: 20px;
  563. .sidebar-head .toggle-sidebar-icon {
  564. display: flex;
  565. margin-left: 5px;
  566. transform: rotate(-90deg);
  567. }
  568. }
  569. }
  570. .sidebar-overlay {
  571. display: flex;
  572. position: absolute;
  573. z-index: 2009;
  574. top: 0;
  575. left: 0;
  576. right: 0;
  577. bottom: 0;
  578. background-color: rgba(10, 10, 10, 0.85);
  579. }
  580. }
  581. </style>