2021-12-01 03:02:40 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
import LazyBookCard from '@/components/cards/LazyBookCard'
|
|
|
|
import LazySeriesCard from '@/components/cards/LazySeriesCard'
|
|
|
|
import LazyCollectionCard from '@/components/cards/LazyCollectionCard'
|
2022-11-27 00:24:46 +01:00
|
|
|
import LazyPlaylistCard from '@/components/cards/LazyPlaylistCard'
|
2023-01-03 01:02:04 +01:00
|
|
|
import LazyAlbumCard from '@/components/cards/LazyAlbumCard'
|
2021-12-01 03:02:40 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
cardsHelpers: {
|
|
|
|
mountEntityCard: this.mountEntityCard
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getComponentClass() {
|
|
|
|
if (this.entityName === 'series') return Vue.extend(LazySeriesCard)
|
|
|
|
if (this.entityName === 'collections') return Vue.extend(LazyCollectionCard)
|
2022-11-27 00:24:46 +01:00
|
|
|
if (this.entityName === 'playlists') return Vue.extend(LazyPlaylistCard)
|
2023-01-03 01:02:04 +01:00
|
|
|
if (this.entityName === 'albums') return Vue.extend(LazyAlbumCard)
|
2021-12-01 03:02:40 +01:00
|
|
|
return Vue.extend(LazyBookCard)
|
|
|
|
},
|
|
|
|
async mountEntityCard(index) {
|
|
|
|
var shelf = Math.floor(index / this.entitiesPerShelf)
|
|
|
|
var shelfEl = document.getElementById(`shelf-${shelf}`)
|
|
|
|
if (!shelfEl) {
|
|
|
|
console.error('invalid shelf', shelf, 'book index', index)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.entityIndexesMounted.push(index)
|
|
|
|
if (this.entityComponentRefs[index]) {
|
2023-01-03 01:02:04 +01:00
|
|
|
const bookComponent = this.entityComponentRefs[index]
|
2021-12-01 03:02:40 +01:00
|
|
|
shelfEl.appendChild(bookComponent.$el)
|
|
|
|
if (this.isSelectionMode) {
|
|
|
|
bookComponent.setSelectionMode(true)
|
2022-12-01 00:09:00 +01:00
|
|
|
if (this.selectedMediaItems.some(i => i.id === bookComponent.libraryItemId) || this.isSelectAll) {
|
2021-12-01 03:02:40 +01:00
|
|
|
bookComponent.selected = true
|
|
|
|
} else {
|
|
|
|
bookComponent.selected = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bookComponent.setSelectionMode(false)
|
|
|
|
}
|
|
|
|
bookComponent.isHovering = false
|
|
|
|
return
|
|
|
|
}
|
2023-01-03 01:02:04 +01:00
|
|
|
const shelfOffsetY = 16
|
|
|
|
const row = index % this.entitiesPerShelf
|
|
|
|
const shelfOffsetX = row * this.totalEntityCardWidth + this.bookshelfMarginLeft
|
2021-12-01 03:02:40 +01:00
|
|
|
|
2023-01-03 01:02:04 +01:00
|
|
|
const ComponentClass = this.getComponentClass()
|
2021-12-01 03:02:40 +01:00
|
|
|
|
2023-01-03 01:02:04 +01:00
|
|
|
const props = {
|
2021-12-02 22:49:03 +01:00
|
|
|
index,
|
|
|
|
width: this.entityWidth,
|
|
|
|
height: this.entityHeight,
|
2022-08-13 20:56:37 +02:00
|
|
|
bookCoverAspectRatio: this.coverAspectRatio,
|
2022-07-31 00:07:54 +02:00
|
|
|
bookshelfView: this.bookshelfView,
|
|
|
|
sortingIgnorePrefix: !!this.sortingIgnorePrefix
|
2021-12-02 22:49:03 +01:00
|
|
|
}
|
2022-04-30 19:24:48 +02:00
|
|
|
|
2023-01-04 01:00:01 +01:00
|
|
|
if (this.entityName === 'items') {
|
2022-02-14 23:01:53 +01:00
|
|
|
props.filterBy = this.filterBy
|
|
|
|
props.orderBy = this.orderBy
|
2022-10-29 18:17:51 +02:00
|
|
|
} else if (this.entityName === 'series') {
|
|
|
|
props.orderBy = this.seriesSortBy
|
2022-02-14 23:01:53 +01:00
|
|
|
}
|
2021-12-02 22:49:03 +01:00
|
|
|
|
2023-01-03 01:02:04 +01:00
|
|
|
const _this = this
|
|
|
|
const instance = new ComponentClass({
|
2021-12-02 22:49:03 +01:00
|
|
|
propsData: props,
|
2021-12-01 03:02:40 +01:00
|
|
|
created() {
|
|
|
|
this.$on('edit', (entity) => {
|
|
|
|
if (_this.editEntity) _this.editEntity(entity)
|
|
|
|
})
|
2022-10-16 00:17:40 +02:00
|
|
|
this.$on('select', ({ entity, shiftKey }) => {
|
|
|
|
if (_this.selectEntity) _this.selectEntity(entity, shiftKey)
|
2021-12-01 03:02:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.entityComponentRefs[index] = instance
|
|
|
|
|
|
|
|
instance.$mount()
|
|
|
|
instance.$el.style.transform = `translate3d(${shelfOffsetX}px, ${shelfOffsetY}px, 0px)`
|
2021-12-18 03:52:11 +01:00
|
|
|
instance.$el.classList.add('absolute', 'top-0', 'left-0')
|
2021-12-01 03:02:40 +01:00
|
|
|
shelfEl.appendChild(instance.$el)
|
|
|
|
|
|
|
|
if (this.entities[index]) {
|
|
|
|
instance.setEntity(this.entities[index])
|
|
|
|
}
|
|
|
|
if (this.isSelectionMode) {
|
|
|
|
instance.setSelectionMode(true)
|
2022-12-01 00:09:00 +01:00
|
|
|
if (instance.libraryItemId && this.selectedMediaItems.some(i => i.id === instance.libraryItemId) || this.isSelectAll) {
|
2021-12-01 03:02:40 +01:00
|
|
|
instance.selected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|