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

70 lines
2.3 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
<article class="item" v-if="artist.songCount" draggable="true" @dragstart="dragStart">
2016-01-16 18:11:24 +00:00
<span class="cover" :style="{ backgroundImage: 'url(' + artist.image + ')' }">
2015-12-13 04:42:28 +00:00
<a class="control" @click.prevent="play">
<i class="fa fa-play"></i>
</a>
</span>
<footer>
2016-01-15 07:27:25 +00:00
<a class="name" @click.prevent="viewDetails">{{ artist.name }}</a>
2015-12-13 04:42:28 +00:00
<p class="meta">
2016-01-15 10:05:54 +00:00
{{ artist.albums.length }} {{ artist.albums.length | pluralize 'album' }}
2016-01-15 07:27:25 +00:00
2016-01-15 10:05:54 +00:00
{{ artist.songCount }} {{ artist.songCount | pluralize 'song' }}
{{ artist.playCount }} {{ artist.playCount | pluralize 'play' }}
2015-12-13 04:42:28 +00:00
</p>
</footer>
</article>
</template>
<script>
2016-03-31 08:58:46 +00:00
import { map } from 'lodash';
import $ from 'jquery';
2015-12-13 04:42:28 +00:00
import playback from '../../services/playback';
import artistStore from '../../stores/artist';
import queueStore from '../../stores/queue';
2015-12-13 04:42:28 +00:00
export default {
props: ['artist'],
methods: {
/**
* Play all songs by the current artist, or queue them up if Ctrl/Cmd key is pressed.
2015-12-13 04:42:28 +00:00
*/
play(e) {
if (e.metaKey || e.ctrlKey) {
queueStore.queue(artistStore.getSongsByArtist(this.artist));
} else {
playback.playAllByArtist(this.artist);
}
2015-12-13 04:42:28 +00:00
},
2016-01-15 07:27:25 +00:00
viewDetails() {
this.$root.loadArtist(this.artist);
},
/**
* Allow dragging the artist (actually, their songs).
*/
dragStart(e) {
2016-03-31 08:58:46 +00:00
const songIds = map(artistStore.getSongsByArtist(this.artist), 'id');
e.dataTransfer.setData('text/plain', songIds);
e.dataTransfer.effectAllowed = 'move';
// Set a fancy drop image using our ghost element.
2016-03-28 13:38:14 +00:00
const $ghost = $('#dragGhost').text(`All ${songIds.length} song${songIds.length === 1 ? '' : 's'} by ${this.artist.name}`);
e.dataTransfer.setDragImage($ghost[0], 0, 0);
},
2015-12-13 04:42:28 +00:00
},
};
</script>
<style lang="sass">
2016-03-13 17:00:32 +00:00
@import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss";
2016-01-15 07:27:25 +00:00
@include artist-album-card();
2015-12-13 04:42:28 +00:00
</style>