123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622 |
- <template>
- <div>
- <edit-song
- :modal-module-path="`modals/editSongs/${modalUuid}/editSong`"
- :modal-uuid="modalUuid"
- :bulk="true"
- :flagged="currentSongFlagged"
- v-if="currentSong"
- @savedSuccess="onSavedSuccess"
- @savedError="onSavedError"
- @saving="onSaving"
- @toggleFlag="toggleFlag"
- @nextSong="editNextSong"
- @close="onClose"
- >
- <template #toggleMobileSidebar>
- <i
- class="material-icons toggle-sidebar-icon"
- :content="`${
- sidebarMobileActive ? 'Close' : 'Open'
- } Edit Queue`"
- v-tippy
- @click="toggleMobileSidebar()"
- >expand_circle_down</i
- >
- </template>
- <template #sidebar>
- <div class="sidebar" :class="{ active: sidebarMobileActive }">
- <header class="sidebar-head">
- <h2 class="sidebar-title is-marginless">Edit Queue</h2>
- <i
- class="material-icons toggle-sidebar-icon"
- :content="`${
- sidebarMobileActive ? 'Close' : 'Open'
- } Edit Queue`"
- v-tippy
- @click="toggleMobileSidebar()"
- >expand_circle_down</i
- >
- </header>
- <section class="sidebar-body">
- <div
- class="item"
- v-for="(
- { status, flagged, song }, index
- ) in filteredItems"
- :key="song._id"
- :ref="`edit-songs-item-${song._id}`"
- >
- <song-item
- :song="song"
- :thumbnail="false"
- :duration="false"
- :disabled-actions="
- song.removed ? ['all'] : ['report', 'edit']
- "
- :class="{
- updated: song.updated,
- removed: song.removed
- }"
- >
- <template #leftIcon>
- <i
- v-if="currentSong._id === song._id"
- class="material-icons item-icon editing-icon"
- content="Currently editing song"
- v-tippy="{ theme: 'info' }"
- @click="toggleDone(index)"
- >edit</i
- >
- <i
- v-else-if="song.removed"
- class="material-icons item-icon removed-icon"
- content="Song removed"
- v-tippy="{ theme: 'info' }"
- >delete_forever</i
- >
- <i
- v-else-if="status === 'error'"
- class="material-icons item-icon error-icon"
- content="Error saving song"
- v-tippy="{ theme: 'info' }"
- @click="toggleDone(index)"
- >error</i
- >
- <i
- v-else-if="status === 'saving'"
- class="material-icons item-icon saving-icon"
- content="Currently saving song"
- v-tippy="{ theme: 'info' }"
- >pending</i
- >
- <i
- v-else-if="flagged"
- class="material-icons item-icon flag-icon"
- content="Song flagged"
- v-tippy="{ theme: 'info' }"
- @click="toggleDone(index)"
- >flag_circle</i
- >
- <i
- v-else-if="status === 'done'"
- class="material-icons item-icon done-icon"
- content="Song marked complete"
- v-tippy="{ theme: 'info' }"
- @click="toggleDone(index)"
- >check_circle</i
- >
- <i
- v-else-if="status === 'todo'"
- class="material-icons item-icon todo-icon"
- content="Song marked todo"
- v-tippy="{ theme: 'info' }"
- @click="toggleDone(index)"
- >cancel</i
- >
- </template>
- <template v-if="!song.removed" #actions>
- <i
- class="material-icons edit-icon"
- content="Edit Song"
- v-tippy
- @click="pickSong(song)"
- >
- edit
- </i>
- </template>
- <template #tippyActions>
- <i
- class="material-icons flag-icon"
- :class="{ flagged }"
- content="Toggle Flag"
- v-tippy
- @click="toggleFlag(index)"
- >
- flag_circle
- </i>
- </template>
- </song-item>
- </div>
- <p v-if="filteredItems.length === 0" class="no-items">
- {{
- flagFilter
- ? "No flagged songs queued"
- : "No songs queued"
- }}
- </p>
- </section>
- <footer class="sidebar-foot">
- <button
- @click="toggleFlagFilter()"
- class="button is-primary"
- >
- {{
- flagFilter
- ? "Show All Songs"
- : "Show Only Flagged Songs"
- }}
- </button>
- </footer>
- </div>
- <div
- v-if="sidebarMobileActive"
- class="sidebar-overlay"
- @click="toggleMobileSidebar()"
- ></div>
- </template>
- </edit-song>
- </div>
- </template>
- <script>
- import { mapActions, mapGetters } from "vuex";
- import { defineAsyncComponent } from "vue";
- import Toast from "toasters";
- import { mapModalState, mapModalActions } from "@/vuex_helpers";
- import SongItem from "@/components/SongItem.vue";
- import editSong from "@/store/modules/modals/editSong";
- export default {
- components: {
- EditSong: defineAsyncComponent(() =>
- import("@/components/modals/EditSong")
- ),
- SongItem
- },
- props: {
- modalUuid: { type: String, default: "" }
- },
- data() {
- return {
- items: [],
- currentSong: {},
- flagFilter: false,
- sidebarMobileActive: false
- };
- },
- computed: {
- editingItemIndex() {
- return this.items.findIndex(
- item => item.song._id === this.currentSong._id
- );
- },
- filteredEditingItemIndex() {
- return this.filteredItems.findIndex(
- item => item.song._id === this.currentSong._id
- );
- },
- filteredItems: {
- get() {
- return this.items.filter(item =>
- this.flagFilter ? item.flagged : true
- );
- },
- set(newItem) {
- const index = this.items.findIndex(
- item => item.song._id === newItem._id
- );
- this.item[index] = newItem;
- }
- },
- currentSongFlagged() {
- return this.items.find(
- item => item.song._id === this.currentSong._id
- )?.flagged;
- },
- ...mapModalState("modals/editSongs/MODAL_UUID", {
- songIds: state => state.songIds,
- songPrefillData: state => state.songPrefillData
- }),
- ...mapGetters({
- socket: "websockets/getSocket"
- })
- },
- async mounted() {
- this.socket.dispatch("apis.joinRoom", "edit-songs");
- this.$store.registerModule(
- ["modals", "editSongs", this.modalUuid, "editSong"],
- editSong
- );
- this.socket.dispatch("songs.getSongsFromSongIds", this.songIds, res => {
- res.data.songs.forEach(song => {
- this.items.push({
- status: "todo",
- flagged: false,
- song
- });
- });
- if (this.items.length === 0) {
- this.closeThisModal();
- new Toast("You can't edit 0 songs.");
- } else this.editNextSong();
- });
- this.socket.on(
- `event:admin.song.updated`,
- res => {
- const index = this.items
- .map(item => item.song._id)
- .indexOf(res.data.song._id);
- this.items[index].song = {
- ...this.items[index].song,
- ...res.data.song,
- updated: true
- };
- },
- { modalUuid: this.modalUuid }
- );
- this.socket.on(
- `event:admin.song.removed`,
- res => {
- const index = this.items
- .map(item => item.song._id)
- .indexOf(res.data.songId);
- this.items[index].song.removed = true;
- },
- { modalUuid: this.modalUuid }
- );
- },
- beforeUnmount() {
- this.socket.dispatch("apis.leaveRoom", "edit-songs");
- },
- unmounted() {
- // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
- this.$store.unregisterModule(["modals", "editSongs", this.modalUuid]);
- },
- methods: {
- pickSong(song) {
- this.editSong({
- songId: song._id,
- prefill: this.songPrefillData[song._id]
- });
- this.currentSong = song;
- if (
- this.$refs[`edit-songs-item-${song._id}`] &&
- this.$refs[`edit-songs-item-${song._id}`][0]
- )
- this.$refs[`edit-songs-item-${song._id}`][0].scrollIntoView();
- },
- editNextSong() {
- const currentlyEditingSongIndex = this.filteredEditingItemIndex;
- let newEditingSongIndex = -1;
- const index =
- currentlyEditingSongIndex + 1 === this.filteredItems.length
- ? 0
- : currentlyEditingSongIndex + 1;
- for (let i = index; i < this.filteredItems.length; i += 1) {
- if (!this.flagFilter || this.filteredItems[i].flagged) {
- newEditingSongIndex = i;
- break;
- }
- }
- if (newEditingSongIndex > -1) {
- const nextSong = this.filteredItems[newEditingSongIndex].song;
- this.pickSong(nextSong);
- }
- },
- toggleFlag(songIndex = null) {
- if (songIndex && songIndex > -1) {
- this.filteredItems[songIndex].flagged =
- !this.filteredItems[songIndex].flagged;
- new Toast(
- `Successfully ${
- this.filteredItems[songIndex].flagged
- ? "flagged"
- : "unflagged"
- } song.`
- );
- } else if (!songIndex && this.editingItemIndex > -1) {
- this.items[this.editingItemIndex].flagged =
- !this.items[this.editingItemIndex].flagged;
- new Toast(
- `Successfully ${
- this.items[this.editingItemIndex].flagged
- ? "flagged"
- : "unflagged"
- } song.`
- );
- }
- },
- onSavedSuccess(songId) {
- const itemIndex = this.items.findIndex(
- item => item.song._id === songId
- );
- if (itemIndex > -1) {
- this.items[itemIndex].status = "done";
- this.items[itemIndex].flagged = false;
- }
- },
- onSavedError(songId) {
- const itemIndex = this.items.findIndex(
- item => item.song._id === songId
- );
- if (itemIndex > -1) this.items[itemIndex].status = "error";
- },
- onSaving(songId) {
- const itemIndex = this.items.findIndex(
- item => item.song._id === songId
- );
- if (itemIndex > -1) this.items[itemIndex].status = "saving";
- },
- toggleDone(index, overwrite = null) {
- const { status } = this.filteredItems[index];
- if (status === "done" && overwrite !== "done")
- this.filteredItems[index].status = "todo";
- else {
- this.filteredItems[index].status = "done";
- this.filteredItems[index].flagged = false;
- }
- },
- toggleFlagFilter() {
- this.flagFilter = !this.flagFilter;
- },
- toggleMobileSidebar() {
- this.sidebarMobileActive = !this.sidebarMobileActive;
- },
- confirmAction({ message, action, params }) {
- this.openModal({
- modal: "confirm",
- data: {
- message,
- action,
- params,
- onCompleted: this.handleConfirmed
- }
- });
- },
- handleConfirmed({ action, params }) {
- if (typeof this[action] === "function") {
- if (params) this[action](params);
- else this[action]();
- }
- },
- onClose() {
- const doneItems = this.items.filter(
- item => item.status === "done"
- ).length;
- const flaggedItems = this.items.filter(item => item.flagged).length;
- const notDoneItems = this.items.length - doneItems;
- if (doneItems > 0 && notDoneItems > 0)
- this.confirmAction({
- message:
- "You have songs which are not done yet. Are you sure you want to stop editing songs?",
- action: "closeThisModal",
- params: null
- });
- else if (flaggedItems > 0)
- this.confirmAction({
- message:
- "You have songs which are flagged. Are you sure you want to stop editing songs?",
- action: "closeThisModal",
- params: null
- });
- else this.closeThisModal();
- },
- closeThisModal() {
- this.closeCurrentModal();
- },
- ...mapActions("modalVisibility", ["openModal", "closeCurrentModal"]),
- ...mapModalActions("modals/editSongs/MODAL_UUID/editSong", [
- "editSong"
- ]),
- ...mapModalActions("modals/editSongs/MODAL_UUID", ["resetSongs"])
- }
- };
- </script>
- <style lang="less" scoped>
- .night-mode .sidebar {
- .sidebar-head,
- .sidebar-foot {
- background-color: var(--dark-grey-3);
- border: none;
- }
- .sidebar-body {
- background-color: var(--dark-grey-4) !important;
- }
- .sidebar-head .toggle-sidebar-icon.material-icons,
- .sidebar-title {
- color: var(--white);
- }
- p,
- label,
- td,
- th {
- color: var(--light-grey-2) !important;
- }
- h1,
- h2,
- h3,
- h4,
- h5,
- h6 {
- color: var(--white) !important;
- }
- }
- .toggle-sidebar-icon {
- display: none;
- }
- .sidebar {
- width: 100%;
- max-width: 350px;
- z-index: 2000;
- display: flex;
- flex-direction: column;
- position: relative;
- height: 100%;
- max-height: calc(100vh - 40px);
- overflow: auto;
- margin-right: 8px;
- border-radius: @border-radius;
- .sidebar-head,
- .sidebar-foot {
- display: flex;
- flex-shrink: 0;
- position: relative;
- justify-content: flex-start;
- align-items: center;
- padding: 20px;
- background-color: var(--light-grey);
- }
- .sidebar-head {
- border-bottom: 1px solid var(--light-grey-2);
- border-radius: @border-radius @border-radius 0 0;
- .sidebar-title {
- display: flex;
- flex: 1;
- margin: 0;
- font-size: 26px;
- font-weight: 600;
- }
- }
- .sidebar-body {
- background-color: var(--white);
- display: flex;
- flex-direction: column;
- row-gap: 8px;
- flex: 1;
- overflow: auto;
- padding: 10px;
- .item {
- display: flex;
- flex-direction: row;
- align-items: center;
- column-gap: 8px;
- :deep(.song-item) {
- .item-icon {
- margin-right: 10px;
- cursor: pointer;
- }
- .removed-icon,
- .error-icon {
- color: var(--red);
- }
- .saving-icon,
- .todo-icon,
- .editing-icon {
- color: var(--primary-color);
- }
- .done-icon {
- color: var(--green);
- }
- .flag-icon {
- color: var(--orange);
- &.flagged {
- color: var(--grey);
- }
- }
- &.removed {
- filter: grayscale(100%);
- cursor: not-allowed;
- user-select: none;
- }
- }
- }
- .no-items {
- text-align: center;
- font-size: 18px;
- }
- }
- .sidebar-foot {
- border-top: 1px solid var(--light-grey-2);
- border-radius: 0 0 @border-radius @border-radius;
- .button {
- flex: 1;
- }
- }
- .sidebar-overlay {
- display: none;
- }
- }
- @media only screen and (max-width: 1580px) {
- .toggle-sidebar-icon {
- display: flex;
- margin-right: 5px;
- transform: rotate(90deg);
- cursor: pointer;
- }
- .sidebar {
- display: none;
- &.active {
- display: flex;
- position: absolute;
- z-index: 2010;
- top: 20px;
- left: 20px;
- .sidebar-head .toggle-sidebar-icon {
- display: flex;
- margin-left: 5px;
- transform: rotate(-90deg);
- }
- }
- }
- .sidebar-overlay {
- display: flex;
- position: absolute;
- z-index: 2009;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(10, 10, 10, 0.85);
- }
- }
- </style>
|