2017-06-23 21:00:42 +00:00
|
|
|
<template>
|
|
|
|
<div :class="['ui', {'tiny': discrete}, 'buttons']">
|
2018-03-05 20:51:40 +00:00
|
|
|
<button
|
2018-04-14 17:28:41 +00:00
|
|
|
:title="$t('Add to current queue')"
|
2018-05-06 21:50:09 +00:00
|
|
|
@click="addNext(true)"
|
2018-03-21 10:58:26 +00:00
|
|
|
:class="['ui', {loading: isLoading}, {'mini': discrete}, {disabled: !playable}, 'button']">
|
2017-06-23 21:00:42 +00:00
|
|
|
<i class="ui play icon"></i>
|
2018-04-14 17:28:41 +00:00
|
|
|
<template v-if="!discrete"><slot><i18next path="Play"/></slot></template>
|
2017-06-23 21:00:42 +00:00
|
|
|
</button>
|
2018-03-21 10:58:26 +00:00
|
|
|
<div v-if="!discrete" :class="['ui', {disabled: !playable}, 'floating', 'dropdown', 'icon', 'button']">
|
2017-06-23 21:00:42 +00:00
|
|
|
<i class="dropdown icon"></i>
|
|
|
|
<div class="menu">
|
2018-04-14 17:28:41 +00:00
|
|
|
<div class="item"@click="add"><i class="plus icon"></i><i18next path="Add to queue"/></div>
|
|
|
|
<div class="item"@click="addNext()"><i class="step forward icon"></i><i18next path="Play next"/></div>
|
|
|
|
<div class="item"@click="addNext(true)"><i class="arrow down icon"></i><i18next path="Play now"/></div>
|
2017-06-23 21:00:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-03-21 10:58:26 +00:00
|
|
|
import axios from 'axios'
|
2017-06-23 21:00:42 +00:00
|
|
|
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},
|
2018-03-21 10:58:26 +00:00
|
|
|
playlist: {type: Object, required: false},
|
2017-06-23 21:00:42 +00:00
|
|
|
discrete: {type: Boolean, default: false}
|
|
|
|
},
|
2018-03-05 20:51:40 +00:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
isLoading: false
|
|
|
|
}
|
|
|
|
},
|
2017-06-23 21:00:42 +00:00
|
|
|
created () {
|
2018-03-21 10:58:26 +00:00
|
|
|
if (!this.playlist && !this.track && !this.tracks) {
|
|
|
|
logger.default.error('You have to provide either a track playlist or tracks property')
|
2017-06-23 21:00:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
2018-05-06 21:50:09 +00:00
|
|
|
jQuery(this.$el).find('.ui.dropdown').dropdown()
|
2017-06-23 21:00:42 +00:00
|
|
|
},
|
2018-02-19 19:14:39 +00:00
|
|
|
computed: {
|
2018-03-21 10:58:26 +00:00
|
|
|
playable () {
|
2017-06-23 21:00:42 +00:00
|
|
|
if (this.track) {
|
2018-03-21 10:58:26 +00:00
|
|
|
return true
|
|
|
|
} else if (this.tracks) {
|
|
|
|
return this.tracks.length > 0
|
|
|
|
} else if (this.playlist) {
|
|
|
|
return true
|
2017-06-23 21:00:42 +00:00
|
|
|
}
|
2018-03-21 10:58:26 +00:00
|
|
|
return false
|
2018-02-19 19:14:39 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2018-03-21 10:58:26 +00:00
|
|
|
getPlayableTracks () {
|
|
|
|
let self = this
|
|
|
|
let getTracks = new Promise((resolve, reject) => {
|
|
|
|
if (self.track) {
|
|
|
|
resolve([self.track])
|
|
|
|
} else if (self.tracks) {
|
|
|
|
resolve(self.tracks)
|
|
|
|
} else if (self.playlist) {
|
|
|
|
let url = 'playlists/' + self.playlist.id + '/'
|
|
|
|
axios.get(url + 'tracks').then((response) => {
|
|
|
|
resolve(response.data.results.map(plt => {
|
|
|
|
return plt.track
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return getTracks.then((tracks) => {
|
|
|
|
return tracks.filter(e => {
|
|
|
|
return e.files.length > 0
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2018-03-05 20:51:40 +00:00
|
|
|
triggerLoad () {
|
|
|
|
let self = this
|
|
|
|
this.isLoading = true
|
|
|
|
setTimeout(() => {
|
|
|
|
self.isLoading = false
|
|
|
|
}, 500)
|
|
|
|
},
|
2018-02-19 19:14:39 +00:00
|
|
|
add () {
|
2018-03-21 10:58:26 +00:00
|
|
|
let self = this
|
2018-03-05 20:51:40 +00:00
|
|
|
this.triggerLoad()
|
2018-03-21 10:58:26 +00:00
|
|
|
this.getPlayableTracks().then((tracks) => {
|
|
|
|
self.$store.dispatch('queue/appendMany', {tracks: tracks})
|
|
|
|
})
|
2017-06-23 21:00:42 +00:00
|
|
|
},
|
|
|
|
addNext (next) {
|
2018-03-21 10:58:26 +00:00
|
|
|
let self = this
|
2018-03-05 20:51:40 +00:00
|
|
|
this.triggerLoad()
|
2018-05-06 21:50:09 +00:00
|
|
|
let wasEmpty = this.$store.state.queue.tracks.length === 0
|
2018-03-21 10:58:26 +00:00
|
|
|
this.getPlayableTracks().then((tracks) => {
|
|
|
|
self.$store.dispatch('queue/appendMany', {tracks: tracks, index: self.$store.state.queue.currentIndex + 1})
|
2018-05-06 21:50:09 +00:00
|
|
|
let goNext = next && !wasEmpty
|
|
|
|
if (goNext) {
|
2018-03-21 10:58:26 +00:00
|
|
|
self.$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>
|