2017-06-23 21:00:42 +00:00
|
|
|
<template>
|
|
|
|
<div :class="['ui', {'tiny': discrete}, 'buttons']">
|
2018-02-19 19:14:39 +00:00
|
|
|
<button title="Add to current queue" @click="add" :class="['ui', {'mini': discrete}, {disabled: playableTracks.length === 0}, 'button']">
|
2017-06-23 21:00:42 +00:00
|
|
|
<i class="ui play icon"></i>
|
|
|
|
<template v-if="!discrete"><slot>Play</slot></template>
|
|
|
|
</button>
|
|
|
|
<div v-if="!discrete" class="ui floating dropdown icon button">
|
|
|
|
<i class="dropdown icon"></i>
|
|
|
|
<div class="menu">
|
|
|
|
<div class="item"@click="add"><i class="plus icon"></i> Add to queue</div>
|
|
|
|
<div class="item"@click="addNext()"><i class="step forward icon"></i> Play next</div>
|
|
|
|
<div class="item"@click="addNext(true)"><i class="arrow down icon"></i> Play now</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import logger from '@/logging'
|
|
|
|
import jQuery from 'jquery'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
// we can either have a single or multiple tracks to play when clicked
|
|
|
|
tracks: {type: Array, required: false},
|
|
|
|
track: {type: Object, required: false},
|
|
|
|
discrete: {type: Boolean, default: false}
|
|
|
|
},
|
|
|
|
created () {
|
|
|
|
if (!this.track & !this.tracks) {
|
|
|
|
logger.default.error('You have to provide either a track or tracks property')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
if (!this.discrete) {
|
|
|
|
jQuery(this.$el).find('.ui.dropdown').dropdown()
|
|
|
|
}
|
|
|
|
},
|
2018-02-19 19:14:39 +00:00
|
|
|
computed: {
|
|
|
|
playableTracks () {
|
|
|
|
let tracks
|
2017-06-23 21:00:42 +00:00
|
|
|
if (this.track) {
|
2018-02-19 19:14:39 +00:00
|
|
|
tracks = [this.track]
|
2017-06-23 21:00:42 +00:00
|
|
|
} else {
|
2018-02-19 19:14:39 +00:00
|
|
|
tracks = this.tracks
|
2017-06-23 21:00:42 +00:00
|
|
|
}
|
2018-02-19 19:14:39 +00:00
|
|
|
return tracks.filter(e => {
|
|
|
|
return e.files.length > 0
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
add () {
|
|
|
|
this.$store.dispatch('queue/appendMany', {tracks: this.playableTracks})
|
2017-06-23 21:00:42 +00:00
|
|
|
},
|
|
|
|
addNext (next) {
|
2018-02-19 19:14:39 +00:00
|
|
|
this.$store.dispatch('queue/appendMany', {tracks: this.playableTracks, index: this.$store.state.queue.currentIndex + 1})
|
2017-06-23 21:00:42 +00:00
|
|
|
if (next) {
|
2017-12-23 15:41:19 +00:00
|
|
|
this.$store.dispatch('queue/next')
|
2017-06-23 21:00:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style scoped>
|
|
|
|
i {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
</style>
|