mirror of
https://github.com/koel/koel
synced 2024-12-20 09:33:23 +00:00
99 lines
3 KiB
Vue
99 lines
3 KiB
Vue
<template>
|
|
<article
|
|
v-if="album.song_count"
|
|
:class="layout"
|
|
:title="`${album.name} by ${album.artist_name}`"
|
|
class="item"
|
|
data-testid="album-card"
|
|
draggable="true"
|
|
tabindex="0"
|
|
@dblclick="shuffle"
|
|
@dragstart="dragStart"
|
|
@contextmenu.prevent="requestContextMenu"
|
|
>
|
|
<span class="thumbnail-wrapper">
|
|
<AlbumThumbnail :entity="album"/>
|
|
</span>
|
|
|
|
<footer>
|
|
<div class="info">
|
|
<a :href="`#!/album/${album.id}`" class="name" data-testid="name">{{ album.name }}</a>
|
|
<span class="sep text-secondary"> by </span>
|
|
<a v-if="isNormalArtist" :href="`#!/artist/${album.artist_id}`" class="artist">{{ album.artist_name }}</a>
|
|
<span v-else class="artist nope">{{ album.artist_name }}</span>
|
|
</div>
|
|
<p class="meta">
|
|
<span class="left">
|
|
{{ pluralize(album.song_count, 'song') }}
|
|
•
|
|
{{ duration }}
|
|
•
|
|
{{ pluralize(album.play_count, 'play') }}
|
|
</span>
|
|
<span class="right">
|
|
<a
|
|
:title="`Shuffle all songs in the album ${album.name}`"
|
|
class="shuffle-album"
|
|
data-testid="shuffle-album"
|
|
href
|
|
role="button"
|
|
@click.prevent="shuffle"
|
|
>
|
|
<i class="fa fa-random"/>
|
|
</a>
|
|
<a
|
|
v-if="allowDownload"
|
|
:title="`Download all songs in the album ${album.name}`"
|
|
class="download-album"
|
|
data-testid="download-album"
|
|
href
|
|
role="button"
|
|
@click.prevent="download"
|
|
>
|
|
<i class="fa fa-download"/>
|
|
</a>
|
|
</span>
|
|
</p>
|
|
</footer>
|
|
</article>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { computed, defineAsyncComponent, toRef, toRefs } from 'vue'
|
|
import { eventBus, pluralize, secondsToHis, startDragging } from '@/utils'
|
|
import { artistStore, commonStore, songStore } from '@/stores'
|
|
import { downloadService, playbackService } from '@/services'
|
|
|
|
const AlbumThumbnail = defineAsyncComponent(() => import('@/components/ui/AlbumArtistThumbnail.vue'))
|
|
|
|
const props = withDefaults(defineProps<{ album: Album, layout?: ArtistAlbumCardLayout }>(), { layout: 'full' })
|
|
const { album, layout } = toRefs(props)
|
|
|
|
const allowDownload = toRef(commonStore.state, 'allow_download')
|
|
|
|
const duration = computed(() => secondsToHis(album.value.length))
|
|
|
|
const isNormalArtist = computed(() => {
|
|
return !artistStore.isVarious(album.value.artist_id) && !artistStore.isUnknown(album.value.artist_id)
|
|
})
|
|
|
|
const shuffle = async () => {
|
|
await playbackService.queueAndPlay(await songStore.fetchForAlbum(album.value), true /* shuffled */)
|
|
}
|
|
|
|
const download = () => downloadService.fromAlbum(album.value)
|
|
const dragStart = (event: DragEvent) => startDragging(event, album.value, 'Album')
|
|
const requestContextMenu = (event: MouseEvent) => eventBus.emit('ALBUM_CONTEXT_MENU_REQUESTED', event, album.value)
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.sep {
|
|
display: none;
|
|
|
|
.as-list & {
|
|
display: inline;
|
|
}
|
|
}
|
|
|
|
@include artist-album-card();
|
|
</style>
|