236 lines
No EOL
12 KiB
Text
236 lines
No EOL
12 KiB
Text
<script type="text/x-template" id="mediaitem-list-item">
|
|
<template>
|
|
<div v-observe-visibility="{callback: visibilityChanged}"
|
|
@contextmenu="contextMenu"
|
|
@click="select"
|
|
:data-id="item.attributes.playParams.id ?? item.id"
|
|
:data-type="item.attributes.playParams.kind ?? item.type"
|
|
:data-index="index"
|
|
:data-selectorder="selectedOrder"
|
|
class="cd-mediaitem-list-item"
|
|
:class="{'mediaitem-selected': app.select_hasMediaItem(item.attributes.playParams.id ?? item.id)}">
|
|
<template v-if="isVisible">
|
|
<div class="isLibrary" v-if="showLibraryStatus == true">
|
|
<button @click="addToLibrary()"
|
|
v-if="!app.isInLibrary(item.attributes.playParams) && !addedToLibrary">🖤
|
|
</button>
|
|
<button v-else>❤️</button>
|
|
</div>
|
|
<div class="artwork" v-if="showArtwork == true">
|
|
<mediaitem-artwork
|
|
:url="item.attributes.artwork ? item.attributes.artwork.url : ''"
|
|
size="50"
|
|
:type="item.type"></mediaitem-artwork>
|
|
<button class="overlay-play" @click="playTrack()"><%- include("../svg/play.svg") %></button>
|
|
</div>
|
|
<div class="info-rect" :style="{'padding-left': (showArtwork ? '' : '16px')}" @dblclick="playTrack()">
|
|
<div class="title text-overflow-elipsis" @dblclick="playTrack()">
|
|
{{ item.attributes.name }}
|
|
</div>
|
|
<div class="subtitle text-overflow-elipsis" style="-webkit-box-orient: horizontal;">
|
|
<template v-if="item.attributes.artistName">
|
|
<div class="artist item-navigate text-overflow-elipsis"
|
|
@click="app.searchAndNavigate(item,'artist')">
|
|
{{ item.attributes.artistName }}
|
|
</div>
|
|
<template v-if="item.attributes.albumName"> - </template>
|
|
<template v-if="item.attributes.albumName">
|
|
<div class="artist item-navigate text-overflow-elipsis"
|
|
@click="app.searchAndNavigate(item,'album')">
|
|
{{ item.attributes.albumName }}
|
|
</div>
|
|
</template>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
<div class="content-rating" v-if="item.attributes.contentRating" @click="playTrack()">
|
|
{{ item.attributes.contentRating }}
|
|
</div>
|
|
<template v-if="showMetaData == true" @click="playTrack()">
|
|
<div class="metainfo">
|
|
{{ item.attributes.releaseDate ? new Date(item.attributes.releaseDate).toLocaleDateString()
|
|
: "" }}
|
|
</div>
|
|
<div class="metainfo">
|
|
{{ item.attributes.genreNames[0] ?? "" }}
|
|
</div>
|
|
</template>
|
|
<div class="duration" v-if="showDuration" @click="playTrack()">
|
|
{{ msToMinSec(item.attributes.durationInMillis ?? 0) }}
|
|
</div>
|
|
</template>
|
|
</div>
|
|
</template>
|
|
</script>
|
|
|
|
<script>
|
|
Vue.component('mediaitem-list-item', {
|
|
template: '#mediaitem-list-item',
|
|
data: function () {
|
|
return {
|
|
isVisible: false,
|
|
addedToLibrary: false,
|
|
selected: false,
|
|
selectedOrder: -1
|
|
}
|
|
},
|
|
props: {
|
|
'item': {type: Object, required: true},
|
|
'parent': {type: Object, required: false},
|
|
'index': {type: Object, required: false, default: -1},
|
|
'show-artwork': {type: Boolean, default: true},
|
|
'show-library-status': {type: Boolean, default: true},
|
|
'show-meta-data': {type: Boolean, default: false},
|
|
'show-duration': {type: Boolean, default: true},
|
|
},
|
|
methods: {
|
|
deselect() {
|
|
this.selected = false;
|
|
this.selectedOrder = -1;
|
|
},
|
|
select(e) {
|
|
if (e.shiftKey) {
|
|
if (app.select_hasMediaItem(this.item.attributes.playParams.id ?? this.item.id)) {
|
|
app.select_removeMediaItem(this.item.attributes.playParams.id ?? this.item.id, this.item.attributes.playParams.kind ?? this.item.type)
|
|
} else {
|
|
app.select_selectMediaItem(this.item.attributes.playParams.id ?? this.item.id, this.item.attributes.playParams.kind ?? this.item.type)
|
|
}
|
|
} else if (e.ctrlKey) {
|
|
if (app.select_hasMediaItem(this.item.attributes.playParams.id ?? this.item.id)) {
|
|
app.select_removeMediaItem(this.item.attributes.playParams.id ?? this.item.id, this.item.attributes.playParams.kind ?? this.item.type)
|
|
} else {
|
|
app.select_selectMediaItem(this.item.attributes.playParams.id ?? this.item.id, this.item.attributes.playParams.kind ?? this.item.type)
|
|
}
|
|
} else {
|
|
if (app.select_hasMediaItem(this.item.attributes.playParams.id ?? this.item.id)) {
|
|
app.selectedMediaItems = []
|
|
} else {
|
|
app.selectedMediaItems = []
|
|
app.select_selectMediaItem(this.item.attributes.playParams.id ?? this.item.id, this.item.attributes.playParams.kind ?? this.item.type)
|
|
}
|
|
}
|
|
},
|
|
contextMenu(event) {
|
|
let self = this
|
|
let useMenu = "normal"
|
|
if (!app.select_hasMediaItem(this.item.attributes.playParams.id ?? this.item.id)) {
|
|
app.selectedMediaItems = []
|
|
app.select_selectMediaItem(this.item.attributes.playParams.id ?? this.item.id, this.item.attributes.playParams.kind ?? this.item.type)
|
|
} else {
|
|
useMenu = "multiple"
|
|
}
|
|
let menus = {
|
|
multiple: {
|
|
items: [
|
|
{
|
|
name: `Play ${app.selectedMediaItems.length} tracks next`,
|
|
action: () => {
|
|
let itemsToPlay = {}
|
|
app.selectedMediaItems.forEach(item => {
|
|
if (!itemsToPlay[item.kind]) {
|
|
itemsToPlay[item.kind] = []
|
|
}
|
|
itemsToPlay[item.kind].push(item.id)
|
|
})
|
|
// loop through itemsToPlay
|
|
for (let kind in itemsToPlay) {
|
|
let ids = itemsToPlay[kind]
|
|
if (ids.length > 0) {
|
|
app.mk.playNext({[kind + "s"]: itemsToPlay[kind]})
|
|
}
|
|
}
|
|
console.log(itemsToPlay)
|
|
app.selectedMediaItems = []
|
|
}
|
|
},
|
|
{
|
|
name: `Play ${app.selectedMediaItems.length} tracks later`,
|
|
action: () => {
|
|
let itemsToPlay = {}
|
|
app.selectedMediaItems.forEach(item => {
|
|
if (!itemsToPlay[item.kind]) {
|
|
itemsToPlay[item.kind] = []
|
|
}
|
|
itemsToPlay[item.kind].push(item.id)
|
|
})
|
|
// loop through itemsToPlay
|
|
for (let kind in itemsToPlay) {
|
|
let ids = itemsToPlay[kind]
|
|
if (ids.length > 0) {
|
|
app.mk.playLater({[kind + "s"]: itemsToPlay[kind]})
|
|
}
|
|
}
|
|
app.selectedMediaItems = []
|
|
}
|
|
},
|
|
]
|
|
},
|
|
normal: {
|
|
items: [
|
|
{
|
|
"name": "Start Radio",
|
|
"action": function () {
|
|
app.mk.setStationQueue({song: self.item.attributes.playParams.id ?? self.item.id}).then(() => {
|
|
app.mk.play()
|
|
})
|
|
}
|
|
},
|
|
{
|
|
"name": "Play Next",
|
|
"action": function () {
|
|
app.mk.playNext({[self.item.attributes.playParams.kind ?? self.item.type]: self.item.attributes.playParams.id ?? self.item.id})
|
|
app.mk.queue._reindex()
|
|
}
|
|
},
|
|
{
|
|
"name": "Play Later",
|
|
"action": function () {
|
|
app.mk.playLater({[self.item.attributes.playParams.kind ?? self.item.type]: self.item.attributes.playParams.id ?? self.item.id})
|
|
app.mk.queue._reindex()
|
|
}
|
|
},
|
|
{
|
|
"name": "Go to Artist",
|
|
"action": function () {
|
|
app.searchAndNavigate(self.item, 'artist')
|
|
}
|
|
},
|
|
{
|
|
"name": "Go to Album",
|
|
"action": function () {
|
|
app.searchAndNavigate(self.item, 'album')
|
|
}
|
|
},
|
|
]
|
|
}
|
|
}
|
|
CiderContextMenu.Create(event, menus[useMenu])
|
|
},
|
|
visibilityChanged: function (isVisible, entry) {
|
|
this.isVisible = isVisible
|
|
},
|
|
addToLibrary() {
|
|
let item = this.item
|
|
if (item.attributes.playParams.id) {
|
|
console.log('adding to library', item.attributes.playParams.id)
|
|
app.addToLibrary(item.attributes.playParams.id.toString())
|
|
this.addedToLibrary = true
|
|
} else if (item.id) {
|
|
console.log('adding to library', item.id)
|
|
app.addToLibrary(item.id.toString())
|
|
this.addedToLibrary = true
|
|
}
|
|
},
|
|
playTrack() {
|
|
let item = this.item
|
|
let parent = this.parent
|
|
let childIndex = this.index
|
|
if (parent != null && childIndex != null) {
|
|
app.queueParentandplayChild(parent, childIndex);
|
|
} else {
|
|
app.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url)
|
|
}
|
|
}
|
|
}
|
|
});
|
|
</script> |