koel/resources/assets/js/components/shared/album-item.vue

122 lines
3.2 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
2016-06-25 16:05:24 +00:00
<article class="item" v-if="album.songs.length" draggable="true" @dragstart="dragStart">
2017-04-23 16:01:02 +00:00
<span class="cover" :style="{ backgroundImage: `url(${album.cover})` }">
2016-06-25 16:05:24 +00:00
<a class="control" @click.prevent="play">
<i class="fa fa-play"></i>
</a>
</span>
<footer>
<div class="info">
2017-03-28 10:25:24 +00:00
<a class="name" :href="`/#!/album/${album.id}`">{{ album.name }}</a>
<span class="sep">by</span>
2017-03-28 10:25:24 +00:00
<a class="artist" v-if="isNormalArtist" :href="`/#!/artist/${album.artist.id}`">{{ album.artist.name }}</a>
<span class="artist nope" v-else>{{ album.artist.name }}</span>
</div>
2016-06-25 16:05:24 +00:00
<p class="meta">
<span class="left">
{{ album.songs.length | pluralize('song') }}
2017-04-23 16:01:02 +00:00
{{ fmtLength }}
2016-06-25 16:05:24 +00:00
{{ album.playCount | pluralize('play') }}
2015-12-13 04:42:28 +00:00
</span>
2016-06-25 16:05:24 +00:00
<span class="right">
2016-11-17 09:25:58 +00:00
<a href @click.prevent="shuffle" title="Shuffle" class="shuffle-album">
2016-06-25 16:05:24 +00:00
<i class="fa fa-random"></i>
</a>
2016-11-17 09:25:58 +00:00
<a href @click.prevent="download" v-if="sharedState.allowDownload"
class="download-album"
title="Download all songs in album">
2016-06-25 16:05:24 +00:00
<i class="fa fa-download"></i>
</a>
</span>
</p>
</footer>
</article>
2015-12-13 04:42:28 +00:00
</template>
<script>
2016-11-26 03:25:35 +00:00
import { pluralize } from '../../utils'
import { queueStore, artistStore, sharedStore } from '../../stores'
import { playback, download } from '../../services'
2017-04-23 16:01:02 +00:00
import albumAttributes from '../../mixins/album-attributes'
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
export default {
name: 'shared--album-item',
props: ['album'],
filters: { pluralize },
2017-04-23 16:01:02 +00:00
mixins: [albumAttributes],
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
data () {
2016-06-25 16:05:24 +00:00
return {
2016-11-26 03:25:35 +00:00
sharedState: sharedStore.state
}
2016-06-25 16:05:24 +00:00
},
2016-06-25 16:05:24 +00:00
computed: {
2016-11-26 03:25:35 +00:00
isNormalArtist () {
return !artistStore.isVariousArtists(this.album.artist) &&
!artistStore.isUnknownArtist(this.album.artist)
}
2016-06-25 16:05:24 +00:00
},
2016-04-17 15:38:06 +00:00
2016-06-25 16:05:24 +00:00
methods: {
/**
* Play all songs in the current album in track order,
* or queue them up if Ctrl/Cmd key is pressed.
*/
2016-11-26 03:25:35 +00:00
play (e) {
2016-06-25 16:05:24 +00:00
if (e.metaKey || e.ctrlKey) {
2016-11-26 03:25:35 +00:00
queueStore.queue(this.album.songs)
2016-06-25 16:05:24 +00:00
} else {
2016-11-26 03:25:35 +00:00
playback.playAllInAlbum(this.album, false)
2016-06-25 16:05:24 +00:00
}
},
2016-01-15 07:27:25 +00:00
2016-06-25 16:05:24 +00:00
/**
* Shuffle all songs in album.
*/
2016-11-26 03:25:35 +00:00
shuffle () {
playback.playAllInAlbum(this.album, true)
2016-06-25 16:05:24 +00:00
},
2016-06-25 16:05:24 +00:00
/**
* Download all songs in album.
*/
2016-11-26 03:25:35 +00:00
download () {
download.fromAlbum(this.album)
2016-06-25 16:05:24 +00:00
},
2016-06-25 16:05:24 +00:00
/**
* Allow dragging the album (actually, its songs).
*/
2016-11-26 03:25:35 +00:00
dragStart (e) {
2017-01-17 07:02:19 +00:00
const songIds = this.album.songs.map(song => song.id)
2016-11-26 03:25:35 +00:00
e.dataTransfer.setData('application/x-koel.text+plain', songIds)
e.dataTransfer.effectAllowed = 'move'
2016-06-25 16:05:24 +00:00
// Set a fancy drop image using our ghost element.
2016-12-20 15:44:47 +00:00
const ghost = document.getElementById('dragGhost')
ghost.innerText = `All ${pluralize(songIds.length, 'song')} in ${this.album.name}`
e.dataTransfer.setDragImage(ghost, 0, 0)
2016-11-26 03:25:35 +00:00
}
}
}
2015-12-13 04:42:28 +00:00
</script>
2017-02-14 06:53:02 +00:00
<style lang="scss">
2016-06-25 16:05:24 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2016-01-15 07:27:25 +00:00
2016-06-25 16:05:24 +00:00
@include artist-album-card();
2016-06-25 16:05:24 +00:00
.sep {
display: none;
color: $color2ndText;
2016-06-25 16:05:24 +00:00
.as-list & {
display: inline;
}
}
2015-12-13 04:42:28 +00:00
</style>