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

170 lines
4.4 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
<tr
@dblclick.prevent="playRightAwayyyyyyy"
2015-12-13 04:42:28 +00:00
class="song-item"
:class="{ selected: selected, playing: song.playbackState === 'playing' || song.playbackState === 'paused' }"
2015-12-13 04:42:28 +00:00
>
2016-02-08 14:33:07 +00:00
<td class="title">
<span class="play-count" v-if="showPlayCount"
title="{{ song.playCount }} {{ song.playCount | pluralize 'play' }}"
:style="{ width: song.playCount * 100 / topPlayCount + '%' }"
>{{ song.title }}
</span>
<span v-else>{{ song.title }}</span>
</td>
2015-12-13 04:42:28 +00:00
<td class="artist">{{ song.album.artist.name }}</td>
<td class="album">{{ song.album.name }}</td>
<td class="time">{{ song.fmtLength }}</td>
<td class="play" @click.stop="doPlayback">
<i class="fa fa-pause-circle" v-show="song.playbackState === 'playing'"></i>
<i class="fa fa-play-circle" v-else></i>
2016-01-07 04:22:02 +00:00
</td>
2015-12-13 04:42:28 +00:00
</tr>
</template>
<script>
import playback from '../../services/playback';
2016-01-07 08:11:11 +00:00
import queueStore from '../../stores/queue';
2015-12-13 04:42:28 +00:00
export default {
2016-02-08 14:33:07 +00:00
props: [
'song',
/**
* Whether or not we should display the play count indicators.
*
* @type {boolean}
*/
'showPlayCount',
/**
* The play count of the most-played song, so that we can have some percentage-base comparison.
*
* @type {integer}
*/
'topPlayCount'
],
2015-12-13 04:42:28 +00:00
data() {
return {
selected: false,
2015-12-13 04:42:28 +00:00
};
},
methods: {
/**
2016-01-07 08:11:11 +00:00
* Play the song right away.
2015-12-13 04:42:28 +00:00
*/
2016-01-31 15:59:06 +00:00
playRightAwayyyyyyy() {
2016-01-07 08:11:11 +00:00
if (!queueStore.contains(this.song)) {
queueStore.queueAfterCurrent(this.song);
}
playback.play(this.song);
2015-12-13 04:42:28 +00:00
},
2016-01-06 16:41:59 +00:00
/**
* Take the right playback action based on the current playback state.
*/
doPlayback() {
switch (this.song.playbackState) {
case 'playing':
playback.pause();
break;
case 'paused':
playback.resume();
break;
default:
2016-01-31 15:59:06 +00:00
this.playRightAwayyyyyyy();
break;
}
2016-01-06 16:41:59 +00:00
},
/**
* Toggle the "selected" state of the current component.
*/
toggleSelectedState() {
this.selected = !this.selected;
},
/**
* Select the current component (apply a CSS class on its DOM).
*/
select() {
this.selected = true;
},
/**
* Deselect the current component.
*/
deselect() {
this.selected = false;
}
2015-12-13 04:42:28 +00:00
},
};
</script>
<style lang="sass">
@import "resources/assets/sass/partials/_vars.scss";
@import "resources/assets/sass/partials/_mixins.scss";
.song-item {
border-bottom: 1px solid $color2ndBgr;
2016-01-07 04:22:02 +00:00
html.no-touchevents &:hover {
2015-12-13 04:42:28 +00:00
background: rgba(255, 255, 255, .05);
}
.time {
color: $color2ndText;
}
.title {
min-width: 192px;
2016-02-08 14:33:07 +00:00
padding: 0;
span {
display: inline-block;
padding: 8px;
&.play-count {
background: rgba(255, 255, 255, 0.08);
white-space: nowrap;
}
}
2015-12-13 04:42:28 +00:00
}
2016-01-07 04:22:02 +00:00
.play {
2016-01-06 16:41:59 +00:00
max-width: 32px;
2016-01-07 04:22:02 +00:00
opacity: .5;
i {
font-size: 150%;
}
2016-01-06 16:41:59 +00:00
}
2015-12-13 04:42:28 +00:00
&.selected {
background-color: rgba(255, 255, 255, .08);
}
&.playing {
color: $colorHighlight;
}
2016-02-08 14:33:07 +00:00
@media only screen and (max-device-width : 768px) {
.title {
padding: 0;
span {
display: inline;
padding: 0;
&.play-count {
background: none;
}
}
}
}
2015-12-13 04:42:28 +00:00
}
</style>