2021-10-05 05:11:42 +02:00
|
|
|
<template>
|
2022-11-26 06:08:54 +01:00
|
|
|
<div id="librariesTable">
|
2022-07-19 00:44:01 +02:00
|
|
|
<draggable v-if="libraryCopies.length" :list="libraryCopies" v-bind="dragOptions" class="list-group" handle=".drag-handle" draggable=".item" tag="div" @start="startDrag" @end="endDrag">
|
2021-10-13 03:07:42 +02:00
|
|
|
<template v-for="library in libraryCopies">
|
2021-12-05 16:52:23 +01:00
|
|
|
<div :key="library.id" class="item">
|
2022-07-02 16:10:47 +02:00
|
|
|
<tables-library-item :library="library" :selected="currentLibraryId === library.id" :dragging="drag" @edit="editLibrary" @click="setLibrary" />
|
2021-12-05 16:52:23 +01:00
|
|
|
</div>
|
2021-10-13 03:07:42 +02:00
|
|
|
</template>
|
|
|
|
</draggable>
|
2022-05-15 00:23:22 +02:00
|
|
|
<div v-if="!libraries.length" class="pb-4">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-btn @click="clickAddLibrary">{{ $strings.ButtonAddYourFirstLibrary }}</ui-btn>
|
2022-05-15 00:23:22 +02:00
|
|
|
</div>
|
2021-12-06 02:21:06 +01:00
|
|
|
|
2022-11-08 01:27:17 +01:00
|
|
|
<p v-if="libraries.length" class="text-xs mt-4 text-gray-200">
|
|
|
|
*<strong>{{ $strings.ButtonForceReScan }}</strong> {{ $strings.MessageForceReScanDescription }}
|
|
|
|
</p>
|
2022-02-16 01:33:33 +01:00
|
|
|
|
2022-11-08 01:27:17 +01:00
|
|
|
<p v-if="libraries.length && libraries.some((li) => li.mediaType === 'book')" class="text-xs mt-4 text-gray-200">
|
|
|
|
**<strong>{{ $strings.ButtonMatchBooks }}</strong> {{ $strings.MessageMatchBooksDescription }}
|
|
|
|
</p>
|
2021-10-05 05:11:42 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-10-13 03:07:42 +02:00
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
2021-10-05 05:11:42 +02:00
|
|
|
export default {
|
2021-10-13 03:07:42 +02:00
|
|
|
components: {
|
|
|
|
draggable
|
|
|
|
},
|
2021-10-05 05:11:42 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2021-10-13 03:07:42 +02:00
|
|
|
libraryCopies: [],
|
|
|
|
currentOrder: [],
|
|
|
|
drag: false,
|
|
|
|
dragOptions: {
|
|
|
|
animation: 200,
|
|
|
|
group: 'description',
|
|
|
|
ghostClass: 'ghost'
|
|
|
|
},
|
|
|
|
orderTimeout: null
|
2021-10-05 05:11:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
currentLibrary() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibrary']
|
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.currentLibrary ? this.currentLibrary.id : null
|
|
|
|
},
|
|
|
|
libraries() {
|
2021-10-13 03:07:42 +02:00
|
|
|
return this.$store.getters['libraries/getSortedLibraries']()
|
2021-12-05 16:52:23 +01:00
|
|
|
},
|
|
|
|
libraryScans() {
|
|
|
|
return this.$store.state.scanners.libraryScans
|
2021-10-05 05:11:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-13 03:07:42 +02:00
|
|
|
startDrag() {
|
|
|
|
this.drag = true
|
|
|
|
clearTimeout(this.orderTimeout)
|
|
|
|
},
|
2021-12-05 16:52:23 +01:00
|
|
|
endDrag(e) {
|
2021-10-13 03:07:42 +02:00
|
|
|
this.drag = false
|
|
|
|
this.checkOrder()
|
|
|
|
},
|
|
|
|
checkOrder() {
|
|
|
|
clearTimeout(this.orderTimeout)
|
|
|
|
this.orderTimeout = setTimeout(() => {
|
|
|
|
this.saveOrder()
|
|
|
|
}, 500)
|
|
|
|
},
|
|
|
|
saveOrder() {
|
|
|
|
var _newOrder = 1
|
|
|
|
var currOrder = this.libraries.map((lib) => lib.id).join(',')
|
|
|
|
var libraryOrderData = this.libraryCopies.map((library) => {
|
|
|
|
return {
|
|
|
|
newOrder: _newOrder++,
|
|
|
|
oldOrder: library.displayOrder,
|
|
|
|
id: library.id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
var newOrder = libraryOrderData.map((lib) => lib.id).join(',')
|
|
|
|
if (currOrder !== newOrder) {
|
2022-12-13 00:33:59 +01:00
|
|
|
this.$axios.$post('/api/libraries/order', libraryOrderData).then((response) => {
|
|
|
|
if (response.libraries && response.libraries.length) {
|
2021-10-13 03:07:42 +02:00
|
|
|
this.$toast.success('Library order saved', { timeout: 1500 })
|
2022-12-13 00:33:59 +01:00
|
|
|
this.$store.commit('libraries/set', response.libraries)
|
2021-10-13 03:07:42 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async setLibrary(library) {
|
2021-10-05 05:11:42 +02:00
|
|
|
await this.$store.dispatch('libraries/fetch', library.id)
|
|
|
|
this.$router.push(`/library/${library.id}`)
|
|
|
|
},
|
|
|
|
clickAddLibrary() {
|
2022-05-15 00:23:22 +02:00
|
|
|
this.$emit('showLibraryModal', null)
|
2021-10-05 05:11:42 +02:00
|
|
|
},
|
|
|
|
editLibrary(library) {
|
2022-05-15 00:23:22 +02:00
|
|
|
this.$emit('showLibraryModal', library)
|
2021-10-05 05:11:42 +02:00
|
|
|
},
|
2021-10-13 03:07:42 +02:00
|
|
|
init() {
|
|
|
|
this.libraryCopies = this.libraries.map((lib) => {
|
|
|
|
return { ...lib }
|
|
|
|
})
|
2021-10-23 23:49:34 +02:00
|
|
|
},
|
|
|
|
librariesUpdated() {
|
|
|
|
this.init()
|
2021-10-13 03:07:42 +02:00
|
|
|
}
|
2021-10-05 05:11:42 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
2021-10-23 23:49:34 +02:00
|
|
|
this.$store.commit('libraries/addListener', { id: 'libraries-table', meth: this.librariesUpdated })
|
2021-10-05 05:11:42 +02:00
|
|
|
this.init()
|
|
|
|
},
|
2021-10-23 23:49:34 +02:00
|
|
|
beforeDestroy() {
|
|
|
|
this.$store.commit('libraries/removeListener', 'libraries-table')
|
|
|
|
}
|
2021-10-05 05:11:42 +02:00
|
|
|
}
|
|
|
|
</script>
|