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

102 lines
2.7 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="showing" draggable="true" @dragstart="dragStart">
2016-10-31 04:55:07 +00:00
<span class="cover" :style="{ backgroundImage: `url(${artist.image})` }">
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">
2016-10-31 04:55:07 +00:00
<a class="name" :href="`/#!/artist/${artist.id}`">{{ artist.name }}</a>
</div>
2016-06-25 16:05:24 +00:00
<p class="meta">
<span class="left">
{{ artist.albums.length | pluralize('album') }}
{{ artist.songCount | pluralize('song') }}
{{ artist.playCount | pluralize('play') }}
2015-12-13 04:42:28 +00:00
</span>
2016-06-25 16:05:24 +00:00
<span class="right">
2016-10-31 04:28:12 +00:00
<a href @click.prevent="download" v-if="sharedState.allowDownload" title="Download all songs by artist">
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-06-25 16:05:24 +00:00
import { map } from 'lodash';
import $ from 'jquery';
2016-06-25 16:05:24 +00:00
import { pluralize } from '../../utils';
import { artistStore, queueStore, sharedStore } from '../../stores';
import { playback, download } from '../../services';
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
export default {
name: 'shared--artist-item',
props: ['artist'],
filters: { pluralize },
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
data() {
return {
sharedState: sharedStore.state,
};
},
2016-06-04 11:57:27 +00:00
2016-06-25 16:05:24 +00:00
computed: {
/**
* Determine if the artist item should be shown.
* We're not showing those without any songs, or the special "Various Artists".
*
* @return {Boolean}
*/
showing() {
return this.artist.songCount && !artistStore.isVariousArtists(this.artist);
}
},
2016-04-17 15:38:06 +00:00
2016-06-25 16:05:24 +00:00
methods: {
/**
* Play all songs by the current artist, or queue them up if Ctrl/Cmd key is pressed.
*/
play(e) {
if (e.metaKey || e.ctrlKey) {
queueStore.queue(this.artist.songs);
} else {
playback.playAllByArtist(this.artist);
}
},
2016-01-15 07:27:25 +00:00
2016-06-25 16:05:24 +00:00
/**
* Download all songs by artist.
*/
download() {
download.fromArtist(this.artist);
},
2016-06-04 11:57:27 +00:00
2016-06-25 16:05:24 +00:00
/**
* Allow dragging the artist (actually, their songs).
*/
dragStart(e) {
const songIds = map(this.artist.songs, 'id');
e.dataTransfer.setData('application/x-koel.text+plain', songIds);
2016-06-25 16:05:24 +00:00
e.dataTransfer.effectAllowed = 'move';
2016-06-25 16:05:24 +00:00
// Set a fancy drop image using our ghost element.
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-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();
2015-12-13 04:42:28 +00:00
</style>