2022-03-13 01:50:31 +01:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div id="page-wrapper" class="bg-bg page overflow-hidden relative" :class="streamLibraryItem ? 'streaming' : ''">
|
2022-03-13 01:50:31 +01:00
|
|
|
<div v-show="saving" class="absolute z-20 w-full h-full flex items-center justify-center">
|
|
|
|
<ui-loading-indicator />
|
|
|
|
</div>
|
|
|
|
<div class="w-full h-full overflow-y-auto p-8">
|
|
|
|
<div class="w-full flex justify-between items-center pb-6 pt-2">
|
2022-11-09 00:10:08 +01:00
|
|
|
<p class="text-lg">{{ $strings.MessageDragFilesIntoTrackOrder }}</p>
|
|
|
|
<ui-btn color="success" @click="saveTracklist">{{ $strings.ButtonSaveTracklist }}</ui-btn>
|
2022-03-13 01:50:31 +01:00
|
|
|
</div>
|
|
|
|
<div class="w-full flex items-center text-sm py-4 bg-primary border-l border-r border-t border-gray-600">
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="text-center px-4 w-12">{{ $strings.LabelNew }}</div>
|
|
|
|
<div class="text-center px-4 w-24 flex items-center cursor-pointer text-white text-opacity-40 hover:text-opacity-100" @click="sortByCurrent" @mousedown.prevent>
|
|
|
|
<span class="text-white">{{ $strings.LabelCurrent }}</span>
|
2022-03-13 01:50:31 +01:00
|
|
|
<span class="material-icons ml-1" :class="currentSort === 'current' ? 'text-white text-opacity-100 text-lg' : 'text-sm'">{{ currentSort === 'current' ? 'expand_more' : 'unfold_more' }}</span>
|
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="text-center px-4 w-32 flex items-center cursor-pointer text-white text-opacity-40 hover:text-opacity-100" @click="sortByFilenameTrack" @mousedown.prevent>
|
|
|
|
<span class="text-white">{{ $strings.LabelTrackFromFilename }}</span>
|
2022-03-13 01:50:31 +01:00
|
|
|
<span class="material-icons ml-1" :class="currentSort === 'track-filename' ? 'text-white text-opacity-100 text-lg' : 'text-sm'">{{ currentSort === 'track-filename' ? 'expand_more' : 'unfold_more' }}</span>
|
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="text-center px-4 w-32 flex items-center cursor-pointer text-white text-opacity-40 hover:text-opacity-100" @click="sortByMetadataTrack" @mousedown.prevent>
|
|
|
|
<span class="text-white">{{ $strings.LabelTrackFromMetadata }}</span>
|
2022-03-13 01:50:31 +01:00
|
|
|
<span class="material-icons ml-1" :class="currentSort === 'metadata' ? 'text-white text-opacity-100 text-lg' : 'text-sm'">{{ currentSort === 'metadata' ? 'expand_more' : 'unfold_more' }}</span>
|
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="w-20 text-center">{{ $strings.LabelDiscFromFilename }}</div>
|
|
|
|
<div class="w-20 text-center">{{ $strings.LabelDiscFromMetadata }}</div>
|
|
|
|
<div class="text-center px-4 flex-grow flex items-center cursor-pointer text-white text-opacity-40 hover:text-opacity-100" @click="sortByFilename" @mousedown.prevent>
|
|
|
|
<span class="text-white">{{ $strings.LabelFilename }}</span>
|
2022-03-13 01:50:31 +01:00
|
|
|
<span class="material-icons ml-1" :class="currentSort === 'filename' ? 'text-white text-opacity-100 text-lg' : 'text-sm'">{{ currentSort === 'filename' ? 'expand_more' : 'unfold_more' }}</span>
|
|
|
|
</div>
|
|
|
|
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="w-20 text-center">{{ $strings.LabelSize }}</div>
|
|
|
|
<div class="w-20 text-center">{{ $strings.LabelDuration }}</div>
|
|
|
|
<div class="w-56">{{ $strings.LabelNotes }}</div>
|
|
|
|
<div class="w-40">{{ $strings.LabelIncludeInTracklist }}</div>
|
2022-03-13 01:50:31 +01:00
|
|
|
</div>
|
|
|
|
<draggable v-model="files" v-bind="dragOptions" class="list-group border border-gray-600" draggable=".item" tag="ul" @start="drag = true" @end="drag = false" @update="draggableUpdate">
|
|
|
|
<transition-group type="transition" :name="!drag ? 'flip-list' : null">
|
2022-05-02 01:33:46 +02:00
|
|
|
<li v-for="(audio, index) in files" :key="audio.ino" :class="audio.include ? 'item' : 'exclude'" class="w-full list-group-item flex items-center relative">
|
2023-02-11 22:02:56 +01:00
|
|
|
<div class="text-center px-4 py-1 w-12 min-w-12">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ audio.include ? index - numExcluded + 1 : -1 }}
|
|
|
|
</div>
|
2023-02-11 22:02:56 +01:00
|
|
|
<div class="text-center px-4 w-24 min-w-24">{{ audio.index }}</div>
|
|
|
|
<div class="text-center px-2 w-32 min-w-32">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ audio.trackNumFromFilename }}
|
|
|
|
</div>
|
2023-02-11 22:02:56 +01:00
|
|
|
<div class="text-center w-32 min-w-32">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ audio.trackNumFromMeta }}
|
|
|
|
</div>
|
2023-02-11 22:02:56 +01:00
|
|
|
<div class="truncate px-4 w-20 min-w-20">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ audio.discNumFromFilename }}
|
|
|
|
</div>
|
2023-02-11 22:02:56 +01:00
|
|
|
<div class="truncate px-4 w-20 min-w-20">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ audio.discNumFromMeta }}
|
|
|
|
</div>
|
2023-02-11 22:02:56 +01:00
|
|
|
<div class="truncate px-4 flex-grow">
|
2022-03-14 01:34:31 +01:00
|
|
|
{{ audio.metadata.filename }}
|
2022-03-13 01:50:31 +01:00
|
|
|
</div>
|
|
|
|
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="font-mono w-20 min-w-20 text-center text-xs">
|
2022-03-14 01:34:31 +01:00
|
|
|
{{ $bytesPretty(audio.metadata.size) }}
|
2022-03-13 01:50:31 +01:00
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="font-mono w-20 min-w-20 text-center text-xs">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ $secondsToTimestamp(audio.duration) }}
|
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="font-sans text-xs font-normal w-56 min-w-[224px]">
|
2022-03-13 01:50:31 +01:00
|
|
|
{{ audio.error }}
|
|
|
|
</div>
|
2022-11-09 00:10:08 +01:00
|
|
|
<div class="font-sans text-xs font-normal w-40 min-w-[160px] flex items-center justify-center">
|
2022-05-03 01:48:00 +02:00
|
|
|
<ui-toggle-switch v-model="audio.include" :off-color="'error'" @input="includeToggled(audio)" />
|
2022-03-13 01:50:31 +01:00
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</transition-group>
|
|
|
|
</draggable>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
draggable
|
|
|
|
},
|
|
|
|
async asyncData({ store, params, app, redirect, route }) {
|
|
|
|
if (!store.getters['user/getUserCanUpdate']) {
|
|
|
|
return redirect('/?error=unauthorized')
|
|
|
|
}
|
2022-03-26 17:59:34 +01:00
|
|
|
var libraryItem = await app.$axios.$get(`/api/items/${params.id}?expanded=1`).catch((error) => {
|
2022-03-13 01:50:31 +01:00
|
|
|
console.error('Failed', error)
|
|
|
|
return false
|
|
|
|
})
|
2022-03-26 17:59:34 +01:00
|
|
|
if (!libraryItem) {
|
2022-03-17 18:25:12 +01:00
|
|
|
console.error('Not found...', params.id)
|
2022-03-13 01:50:31 +01:00
|
|
|
return redirect('/')
|
|
|
|
}
|
2022-03-26 17:59:34 +01:00
|
|
|
if (libraryItem.mediaType != 'book') {
|
|
|
|
console.error('Invalid media type')
|
|
|
|
return redirect('/')
|
|
|
|
}
|
2022-04-28 02:42:34 +02:00
|
|
|
if (libraryItem.isFile) {
|
|
|
|
console.error('No need to edit library item that is 1 file...')
|
|
|
|
return redirect('/')
|
|
|
|
}
|
2022-03-13 01:50:31 +01:00
|
|
|
return {
|
2022-03-26 17:59:34 +01:00
|
|
|
libraryItem,
|
|
|
|
files: libraryItem.media.audioFiles ? libraryItem.media.audioFiles.map((af) => ({ ...af, include: !af.exclude })) : []
|
2022-03-13 01:50:31 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
drag: false,
|
|
|
|
dragOptions: {
|
|
|
|
animation: 200,
|
|
|
|
group: 'description',
|
|
|
|
ghostClass: 'ghost'
|
|
|
|
},
|
|
|
|
saving: false,
|
2022-05-03 01:48:00 +02:00
|
|
|
currentSort: 'current'
|
2022-03-13 01:50:31 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-03-14 01:34:31 +01:00
|
|
|
media() {
|
|
|
|
return this.libraryItem.media || {}
|
|
|
|
},
|
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || []
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
audioFiles() {
|
2022-03-26 17:59:34 +01:00
|
|
|
return this.media.audioFiles || []
|
2022-03-13 01:50:31 +01:00
|
|
|
},
|
|
|
|
numExcluded() {
|
|
|
|
var count = 0
|
|
|
|
this.files.forEach((file) => {
|
|
|
|
if (!file.include) count++
|
|
|
|
})
|
|
|
|
return count
|
|
|
|
},
|
|
|
|
missingParts() {
|
2022-03-26 17:59:34 +01:00
|
|
|
return this.media.missingParts || []
|
2022-03-13 01:50:31 +01:00
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
libraryItemId() {
|
|
|
|
return this.libraryItem.id
|
2022-03-13 01:50:31 +01:00
|
|
|
},
|
|
|
|
title() {
|
2022-03-14 01:34:31 +01:00
|
|
|
return this.mediaMetadata.title || 'No Title'
|
2022-03-13 01:50:31 +01:00
|
|
|
},
|
|
|
|
author() {
|
2022-03-14 01:34:31 +01:00
|
|
|
return this.mediaMetadata.authorName || 'Unknown'
|
2022-03-13 01:50:31 +01:00
|
|
|
},
|
|
|
|
tracks() {
|
2022-03-26 17:59:34 +01:00
|
|
|
return this.media.tracks
|
2022-03-13 01:50:31 +01:00
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2022-03-13 01:50:31 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
draggableUpdate(e) {
|
|
|
|
this.currentSort = ''
|
|
|
|
},
|
|
|
|
sortByCurrent() {
|
|
|
|
this.files.sort((a, b) => {
|
|
|
|
if (a.index === null) return 1
|
|
|
|
return a.index - b.index
|
|
|
|
})
|
|
|
|
this.currentSort = 'current'
|
|
|
|
},
|
|
|
|
sortByMetadataTrack() {
|
|
|
|
this.files.sort((a, b) => {
|
|
|
|
if (a.trackNumFromMeta === null) return 1
|
|
|
|
return a.trackNumFromMeta - b.trackNumFromMeta
|
|
|
|
})
|
|
|
|
this.currentSort = 'metadata'
|
|
|
|
},
|
|
|
|
sortByFilenameTrack() {
|
|
|
|
this.files.sort((a, b) => {
|
|
|
|
if (a.trackNumFromFilename === null) return 1
|
|
|
|
return a.trackNumFromFilename - b.trackNumFromFilename
|
|
|
|
})
|
|
|
|
this.currentSort = 'track-filename'
|
|
|
|
},
|
|
|
|
sortByFilename() {
|
|
|
|
this.files.sort((a, b) => {
|
2022-03-14 01:34:31 +01:00
|
|
|
return (a.metadata.filename || '').toLowerCase().localeCompare((b.metadata.filename || '').toLowerCase())
|
2022-03-13 01:50:31 +01:00
|
|
|
})
|
|
|
|
this.currentSort = 'filename'
|
|
|
|
},
|
|
|
|
includeToggled(audio) {
|
|
|
|
var new_index = 0
|
|
|
|
if (audio.include) {
|
|
|
|
new_index = this.numExcluded
|
|
|
|
}
|
|
|
|
var old_index = this.files.findIndex((f) => f.ino === audio.ino)
|
|
|
|
if (new_index >= this.files.length) {
|
|
|
|
var k = new_index - this.files.length + 1
|
|
|
|
while (k--) {
|
|
|
|
this.files.push(undefined)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.files.splice(new_index, 0, this.files.splice(old_index, 1)[0])
|
|
|
|
},
|
|
|
|
saveTracklist() {
|
|
|
|
var orderedFileData = this.files.map((file) => {
|
|
|
|
return {
|
|
|
|
index: file.index,
|
2022-03-14 01:34:31 +01:00
|
|
|
filename: file.metadata.filename,
|
2022-03-13 01:50:31 +01:00
|
|
|
ino: file.ino,
|
|
|
|
exclude: !file.include
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
this.saving = true
|
|
|
|
this.$axios
|
2022-03-26 17:59:34 +01:00
|
|
|
.$patch(`/api/items/${this.libraryItem.id}/tracks`, { orderedFileData })
|
2022-03-13 01:50:31 +01:00
|
|
|
.then((data) => {
|
|
|
|
console.log('Finished patching files', data)
|
|
|
|
this.saving = false
|
|
|
|
this.$toast.success('Tracks Updated')
|
2022-03-14 01:34:31 +01:00
|
|
|
this.$router.push(`/item/${this.libraryItemId}`)
|
2022-03-13 01:50:31 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.saving = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|