2022-04-15 14:24:30 +00:00
|
|
|
|
<template>
|
2022-07-19 08:19:57 +00:00
|
|
|
|
<ContextMenuBase ref="base" data-testid="song-context-menu" extra-class="song-menu">
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<template v-if="onlyOneSongSelected">
|
2022-09-15 09:07:25 +00:00
|
|
|
|
<li @click.stop.prevent="doPlayback">
|
2022-04-15 14:24:30 +00:00
|
|
|
|
<span v-if="firstSongPlaying">Pause</span>
|
|
|
|
|
<span v-else>Play</span>
|
|
|
|
|
</li>
|
2022-09-15 09:07:25 +00:00
|
|
|
|
<li @click="viewAlbumDetails(songs[0].album_id)">Go to Album</li>
|
|
|
|
|
<li @click="viewArtistDetails(songs[0].artist_id)">Go to Artist</li>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</template>
|
|
|
|
|
<li class="has-sub">
|
|
|
|
|
Add To
|
|
|
|
|
<ul class="menu submenu menu-add-to">
|
2022-04-30 20:57:04 +00:00
|
|
|
|
<template v-if="queue.length">
|
2022-09-15 09:07:25 +00:00
|
|
|
|
<li v-if="currentSong" @click="queueSongsAfterCurrent">After Current Song</li>
|
|
|
|
|
<li @click="queueSongsToBottom">Bottom of Queue</li>
|
|
|
|
|
<li @click="queueSongsToTop">Top of Queue</li>
|
2022-04-30 20:57:04 +00:00
|
|
|
|
</template>
|
|
|
|
|
<li v-else @click="queueSongsToBottom">Queue</li>
|
2022-10-24 15:27:17 +00:00
|
|
|
|
<template v-if="!isFavoritesScreen">
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li class="separator" />
|
2022-10-24 15:27:17 +00:00
|
|
|
|
<li @click="addSongsToFavorite">Favorites</li>
|
|
|
|
|
</template>
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li v-if="normalPlaylists.length" class="separator" />
|
2024-01-11 23:54:21 +00:00
|
|
|
|
<template class="d-block">
|
2024-03-19 22:48:12 +00:00
|
|
|
|
<ul v-if="normalPlaylists.length" v-koel-overflow-fade class="playlists">
|
2024-01-08 22:21:21 +00:00
|
|
|
|
<li v-for="p in normalPlaylists" :key="p.id" @click="addSongsToExistingPlaylist(p)">{{ p.name }}</li>
|
|
|
|
|
</ul>
|
2024-01-11 23:54:21 +00:00
|
|
|
|
</template>
|
2022-12-06 10:28:48 +00:00
|
|
|
|
<li class="separator" />
|
|
|
|
|
<li @click="addSongsToNewPlaylist">New Playlist…</li>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
2022-10-24 15:27:17 +00:00
|
|
|
|
|
|
|
|
|
<template v-if="isQueueScreen">
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li class="separator" />
|
2022-10-24 15:27:17 +00:00
|
|
|
|
<li @click="removeFromQueue">Remove from Queue</li>
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li class="separator" />
|
2022-10-24 15:27:17 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<template v-if="isFavoritesScreen">
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li class="separator" />
|
2022-10-24 15:27:17 +00:00
|
|
|
|
<li @click="removeFromFavorites">Remove from Favorites</li>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-01-08 22:21:21 +00:00
|
|
|
|
<template v-if="visibilityActions.length">
|
|
|
|
|
<li class="separator" />
|
|
|
|
|
<li v-for="action in visibilityActions" :key="action.label" @click="action.handler">{{ action.label }}</li>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-01-06 11:31:50 +00:00
|
|
|
|
<li v-if="canModify" @click="openEditForm">Edit…</li>
|
2024-01-04 11:35:36 +00:00
|
|
|
|
<li v-if="allowsDownload" @click="download">Download</li>
|
2024-01-22 23:27:31 +00:00
|
|
|
|
<li v-if="onlyOneSongSelected && canBeShared" @click="copyUrl">Copy Shareable URL</li>
|
2022-10-24 15:27:17 +00:00
|
|
|
|
|
|
|
|
|
<template v-if="canBeRemovedFromPlaylist">
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li class="separator" />
|
2022-10-24 15:27:17 +00:00
|
|
|
|
<li @click="removeFromPlaylist">Remove from Playlist</li>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-01-06 11:31:50 +00:00
|
|
|
|
<template v-if="canModify">
|
2022-12-02 16:17:37 +00:00
|
|
|
|
<li class="separator" />
|
2022-09-24 08:09:03 +00:00
|
|
|
|
<li @click="deleteFromFilesystem">Delete from Filesystem</li>
|
|
|
|
|
</template>
|
2022-04-24 08:29:14 +00:00
|
|
|
|
</ContextMenuBase>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-07-08 10:32:44 +00:00
|
|
|
|
import { computed, ref, toRef } from 'vue'
|
2022-11-18 18:44:20 +00:00
|
|
|
|
import { arrayify, copyText, eventBus, pluralize } from '@/utils'
|
2023-08-20 22:35:58 +00:00
|
|
|
|
import { commonStore, favoriteStore, playlistStore, queueStore, songStore } from '@/stores'
|
2022-04-24 08:50:45 +00:00
|
|
|
|
import { downloadService, playbackService } from '@/services'
|
2022-11-18 17:45:38 +00:00
|
|
|
|
import {
|
|
|
|
|
useAuthorization,
|
|
|
|
|
useContextMenu,
|
|
|
|
|
useDialogBox,
|
2024-01-08 16:59:05 +00:00
|
|
|
|
useKoelPlus,
|
2022-11-18 17:45:38 +00:00
|
|
|
|
useMessageToaster,
|
|
|
|
|
usePlaylistManagement,
|
2022-11-18 18:44:20 +00:00
|
|
|
|
useRouter,
|
2022-11-18 17:45:38 +00:00
|
|
|
|
useSongMenuMethods
|
|
|
|
|
} from '@/composables'
|
|
|
|
|
|
2024-01-25 16:21:26 +00:00
|
|
|
|
const { toastSuccess, toastError, toastWarning } = useMessageToaster()
|
2022-11-18 17:45:38 +00:00
|
|
|
|
const { showConfirmDialog } = useDialogBox()
|
2022-11-18 18:44:20 +00:00
|
|
|
|
const { go, getRouteParam, isCurrentScreen } = useRouter()
|
2024-01-06 11:31:50 +00:00
|
|
|
|
const { isAdmin, currentUser } = useAuthorization()
|
2022-12-02 16:17:37 +00:00
|
|
|
|
const { base, ContextMenuBase, open, close, trigger } = useContextMenu()
|
2022-10-24 15:27:17 +00:00
|
|
|
|
const { removeSongsFromPlaylist } = usePlaylistManagement()
|
2024-01-08 16:59:05 +00:00
|
|
|
|
const { isPlus } = useKoelPlus()
|
2022-10-24 15:27:17 +00:00
|
|
|
|
|
2022-11-18 19:30:43 +00:00
|
|
|
|
const songs = ref<Song[]>([])
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const {
|
|
|
|
|
queueSongsAfterCurrent,
|
|
|
|
|
queueSongsToBottom,
|
|
|
|
|
queueSongsToTop,
|
|
|
|
|
addSongsToFavorite,
|
2022-12-06 10:28:48 +00:00
|
|
|
|
addSongsToExistingPlaylist,
|
|
|
|
|
addSongsToNewPlaylist
|
2022-04-20 10:20:09 +00:00
|
|
|
|
} = useSongMenuMethods(songs, close)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-04-25 16:13:18 +00:00
|
|
|
|
const playlists = toRef(playlistStore.state, 'playlists')
|
2024-01-04 11:35:36 +00:00
|
|
|
|
const allowsDownload = toRef(commonStore.state, 'allows_download')
|
2022-04-30 20:57:04 +00:00
|
|
|
|
const queue = toRef(queueStore.state, 'songs')
|
2022-09-25 03:04:41 +00:00
|
|
|
|
const currentSong = toRef(queueStore, 'current')
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2024-01-06 11:31:50 +00:00
|
|
|
|
const canModify = computed(() => {
|
2024-01-24 22:39:47 +00:00
|
|
|
|
if (isPlus.value) return songs.value.every(({ owner_id }) => owner_id === currentUser.value?.id)
|
2024-01-06 11:31:50 +00:00
|
|
|
|
return isAdmin.value
|
|
|
|
|
})
|
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
|
const onlyOneSongSelected = computed(() => songs.value.length === 1)
|
2022-06-10 10:47:46 +00:00
|
|
|
|
const firstSongPlaying = computed(() => songs.value.length ? songs.value[0].playback_state === 'Playing' : false)
|
2024-01-24 22:39:47 +00:00
|
|
|
|
const normalPlaylists = computed(() => playlists.value.filter(({ is_smart }) => !is_smart))
|
2022-09-12 15:33:41 +00:00
|
|
|
|
|
2024-01-08 22:21:21 +00:00
|
|
|
|
const makePublic = () => trigger(async () => {
|
2024-01-16 21:45:29 +00:00
|
|
|
|
await songStore.publicize(songs.value)
|
2024-01-25 16:21:26 +00:00
|
|
|
|
toastSuccess(`Unmarked ${pluralize(songs.value, 'song')} as private.`)
|
2024-01-08 22:21:21 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const makePrivate = () => trigger(async () => {
|
2024-01-25 16:21:26 +00:00
|
|
|
|
const privatizedIds = await songStore.privatize(songs.value)
|
|
|
|
|
|
|
|
|
|
if (!privatizedIds.length) {
|
|
|
|
|
toastError('Songs cannot be marked as private if they’part of a collaborative playlist.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (privatizedIds.length < songs.value.length) {
|
|
|
|
|
toastWarning('Some songs cannot be marked as private as they’re part of a collaborative playlist.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toastSuccess(`Marked ${pluralize(songs.value, 'song')} as private.`)
|
2024-01-08 22:21:21 +00:00
|
|
|
|
})
|
|
|
|
|
|
2024-01-22 23:27:31 +00:00
|
|
|
|
const canBeShared = computed(() => !isPlus.value || songs.value[0].is_public)
|
|
|
|
|
|
2024-01-08 22:21:21 +00:00
|
|
|
|
const visibilityActions = computed(() => {
|
2024-01-16 21:45:29 +00:00
|
|
|
|
if (!isPlus.value) return []
|
2024-01-08 22:21:21 +00:00
|
|
|
|
|
|
|
|
|
// If some songs don't belong to the current user, no actions are available.
|
2024-01-24 22:39:47 +00:00
|
|
|
|
if (songs.value.some(({ owner_id }) => owner_id !== currentUser.value?.id)) return []
|
2024-01-08 22:21:21 +00:00
|
|
|
|
|
|
|
|
|
const visibilities = Array.from(new Set(songs.value.map(song => song.is_public)))
|
|
|
|
|
|
|
|
|
|
if (visibilities.length === 2) {
|
|
|
|
|
return [
|
|
|
|
|
{
|
2024-01-25 16:21:26 +00:00
|
|
|
|
label: 'Unmark as Private',
|
2024-01-08 22:21:21 +00:00
|
|
|
|
handler: makePublic
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-01-25 16:21:26 +00:00
|
|
|
|
label: 'Mark as Private',
|
2024-01-08 22:21:21 +00:00
|
|
|
|
handler: makePrivate
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return visibilities[0]
|
2024-01-25 16:21:26 +00:00
|
|
|
|
? [{ label: 'Mark as Private', handler: makePrivate }]
|
|
|
|
|
: [{ label: 'Unmark as Private', handler: makePublic }]
|
2024-01-08 22:21:21 +00:00
|
|
|
|
})
|
|
|
|
|
|
2022-10-24 15:27:17 +00:00
|
|
|
|
const canBeRemovedFromPlaylist = computed(() => {
|
2022-11-18 18:44:20 +00:00
|
|
|
|
if (!isCurrentScreen('Playlist')) return false
|
2024-01-18 11:13:05 +00:00
|
|
|
|
const playlist = playlistStore.byId(getRouteParam('id')!)
|
2022-10-24 15:27:17 +00:00
|
|
|
|
return playlist && !playlist.is_smart
|
|
|
|
|
})
|
|
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
|
const isQueueScreen = computed(() => isCurrentScreen('Queue'))
|
|
|
|
|
const isFavoritesScreen = computed(() => isCurrentScreen('Favorites'))
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
|
const doPlayback = () => trigger(() => {
|
2022-04-15 17:00:08 +00:00
|
|
|
|
if (!songs.value.length) return
|
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
|
switch (songs.value[0].playback_state) {
|
2022-04-15 17:00:08 +00:00
|
|
|
|
case 'Playing':
|
2022-04-24 08:50:45 +00:00
|
|
|
|
playbackService.pause()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'Paused':
|
2022-04-24 08:50:45 +00:00
|
|
|
|
playbackService.resume()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
2022-04-23 22:31:40 +00:00
|
|
|
|
queueStore.queueIfNotQueued(songs.value[0])
|
2022-04-24 08:50:45 +00:00
|
|
|
|
playbackService.play(songs.value[0])
|
2022-04-15 17:00:08 +00:00
|
|
|
|
break
|
2022-04-15 14:24:30 +00:00
|
|
|
|
}
|
2022-06-10 10:47:46 +00:00
|
|
|
|
})
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
|
const openEditForm = () => trigger(() => songs.value.length && eventBus.emit('MODAL_SHOW_EDIT_SONG_FORM', songs.value))
|
2022-11-18 18:44:20 +00:00
|
|
|
|
const viewAlbumDetails = (albumId: number) => trigger(() => go(`album/${albumId}`))
|
|
|
|
|
const viewArtistDetails = (artistId: number) => trigger(() => go(`artist/${artistId}`))
|
2022-06-10 10:47:46 +00:00
|
|
|
|
const download = () => trigger(() => downloadService.fromSongs(songs.value))
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-10-24 15:27:17 +00:00
|
|
|
|
const removeFromPlaylist = () => trigger(async () => {
|
2024-01-18 11:13:05 +00:00
|
|
|
|
const playlist = playlistStore.byId(getRouteParam('id')!)
|
2022-10-24 15:27:17 +00:00
|
|
|
|
if (!playlist) return
|
|
|
|
|
|
|
|
|
|
await removeSongsFromPlaylist(playlist, songs.value)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const removeFromQueue = () => trigger(() => queueStore.unqueue(songs.value))
|
|
|
|
|
const removeFromFavorites = () => trigger(() => favoriteStore.unlike(songs.value))
|
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
|
const copyUrl = () => trigger(async () => {
|
|
|
|
|
await copyText(songStore.getShareableUrl(songs.value[0]))
|
2022-11-18 17:45:38 +00:00
|
|
|
|
toastSuccess('URL copied to clipboard.')
|
2022-06-10 10:47:46 +00:00
|
|
|
|
})
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
2022-09-15 09:07:25 +00:00
|
|
|
|
const deleteFromFilesystem = () => trigger(async () => {
|
2022-11-18 17:45:38 +00:00
|
|
|
|
if (await showConfirmDialog('Delete selected song(s) from the filesystem? This action is NOT reversible!')) {
|
2022-09-15 09:07:25 +00:00
|
|
|
|
await songStore.deleteFromFilesystem(songs.value)
|
2022-11-18 17:45:38 +00:00
|
|
|
|
toastSuccess(`Deleted ${pluralize(songs.value, 'song')} from the filesystem.`)
|
2022-09-15 09:07:25 +00:00
|
|
|
|
eventBus.emit('SONGS_DELETED', songs.value)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-01-24 22:39:47 +00:00
|
|
|
|
eventBus.on('SONG_CONTEXT_MENU_REQUESTED', async ({ pageX, pageY }, _songs) => {
|
2022-07-08 10:32:44 +00:00
|
|
|
|
songs.value = arrayify(_songs)
|
2024-01-24 22:39:47 +00:00
|
|
|
|
await open(pageY, pageX)
|
2022-07-08 10:32:44 +00:00
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
</script>
|
2022-12-06 10:28:48 +00:00
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2022-12-06 12:14:45 +00:00
|
|
|
|
ul.playlists {
|
|
|
|
|
position: relative;
|
|
|
|
|
max-height: 192px;
|
2022-12-06 10:28:48 +00:00
|
|
|
|
overflow-y: auto;
|
|
|
|
|
}
|
|
|
|
|
</style>
|